diff --git a/fs_interface/Dir.h b/fs_interface/Dir.h index bcbdce2f..2183b073 100644 --- a/fs_interface/Dir.h +++ b/fs_interface/Dir.h @@ -25,8 +25,8 @@ public: std::string name; }; - virtual std::unique_ptr createAndOpenFile(const std::string &name, mode_t mode) = 0; - virtual void createDir(const std::string &name, mode_t mode) = 0; + virtual std::unique_ptr createAndOpenFile(const std::string &name, mode_t mode, uid_t uid, gid_t gid) = 0; + virtual void createDir(const std::string &name, mode_t mode, uid_t uid, gid_t gid) = 0; //TODO Allow alternative implementation returning only children names without more information //virtual std::unique_ptr> children() const = 0; diff --git a/fuse/Filesystem.h b/fuse/Filesystem.h index 09419521..f1083fe2 100644 --- a/fuse/Filesystem.h +++ b/fuse/Filesystem.h @@ -14,7 +14,7 @@ class Filesystem { public: virtual ~Filesystem() {} - virtual int createAndOpenFile(const boost::filesystem::path &path, mode_t mode) = 0; + virtual int createAndOpenFile(const boost::filesystem::path &path, mode_t mode, uid_t uid, gid_t gid) = 0; virtual int openFile(const boost::filesystem::path &path, int flags) = 0; virtual void flush(int descriptor) = 0; virtual void closeFile(int descriptor) = 0; @@ -29,7 +29,7 @@ public: virtual void fsync(int descriptor) = 0; virtual void fdatasync(int descriptor) = 0; virtual void access(const boost::filesystem::path &path, int mask) = 0; - virtual void mkdir(const boost::filesystem::path &path, mode_t mode) = 0; + virtual void mkdir(const boost::filesystem::path &path, mode_t mode, uid_t uid, gid_t gid) = 0; virtual void rmdir(const boost::filesystem::path &path) = 0; virtual void unlink(const boost::filesystem::path &path) = 0; virtual void rename(const boost::filesystem::path &from, const boost::filesystem::path &to) = 0; diff --git a/fuse/Fuse.cpp b/fuse/Fuse.cpp index 14250856..b057bdce 100644 --- a/fuse/Fuse.cpp +++ b/fuse/Fuse.cpp @@ -268,7 +268,8 @@ int Fuse::mknod(const bf::path &path, mode_t mode, dev_t rdev) { int Fuse::mkdir(const bf::path &path, mode_t mode) { //printf("mkdir(%s, %d)\n", path.c_str(), mode); try { - _fs->mkdir(path, mode); + auto context = fuse_get_context(); + _fs->mkdir(path, mode, context->uid, context->gid); return 0; } catch(fspp::fuse::FuseErrnoException &e) { return -e.getErrno(); @@ -530,7 +531,8 @@ int Fuse::access(const bf::path &path, int mask) { int Fuse::create(const bf::path &path, mode_t mode, fuse_file_info *fileinfo) { //printf("create(%s, %d, _)\n", path.c_str(), mode); try { - fileinfo->fh = _fs->createAndOpenFile(path, mode); + auto context = fuse_get_context(); + fileinfo->fh = _fs->createAndOpenFile(path, mode, context->uid, context->gid); return 0; } catch (FuseErrnoException &e) { return -e.getErrno(); diff --git a/impl/FilesystemImpl.cpp b/impl/FilesystemImpl.cpp index 4c0d43b1..ee7631cd 100644 --- a/impl/FilesystemImpl.cpp +++ b/impl/FilesystemImpl.cpp @@ -107,17 +107,17 @@ void FilesystemImpl::access(const bf::path &path, int mask) { _device->Load(path)->access(mask); } -int FilesystemImpl::createAndOpenFile(const bf::path &path, mode_t mode) { +int FilesystemImpl::createAndOpenFile(const bf::path &path, mode_t mode, uid_t uid, gid_t gid) { //TODO Creating the file opens and closes it. We then reopen it afterwards. // This is slow. Improve! auto dir = LoadDir(path.parent_path()); - auto file = dir->createAndOpenFile(path.filename().native(), mode); + auto file = dir->createAndOpenFile(path.filename().native(), mode, uid, gid); return _open_files.open(std::move(file)); } -void FilesystemImpl::mkdir(const bf::path &path, mode_t mode) { +void FilesystemImpl::mkdir(const bf::path &path, mode_t mode, uid_t uid, gid_t gid) { auto dir = LoadDir(path.parent_path()); - dir->createDir(path.filename().native(), mode); + dir->createDir(path.filename().native(), mode, uid, gid); } void FilesystemImpl::rmdir(const bf::path &path) { diff --git a/impl/FilesystemImpl.h b/impl/FilesystemImpl.h index 6b6ae151..c896fbae 100644 --- a/impl/FilesystemImpl.h +++ b/impl/FilesystemImpl.h @@ -31,8 +31,8 @@ public: void fsync(int descriptor) override; void fdatasync(int descriptor) override; void access(const boost::filesystem::path &path, int mask) override; - int createAndOpenFile(const boost::filesystem::path &path, mode_t mode) override; - void mkdir(const boost::filesystem::path &path, mode_t mode) override; + int createAndOpenFile(const boost::filesystem::path &path, mode_t mode, uid_t uid, gid_t gid) override; + void mkdir(const boost::filesystem::path &path, mode_t mode, uid_t uid, gid_t gid) override; void rmdir(const boost::filesystem::path &path) override; void unlink(const boost::filesystem::path &path) override; void rename(const boost::filesystem::path &from, const boost::filesystem::path &to) override;