On file/dir creation, the owner is passed in
This commit is contained in:
parent
8165ca39bc
commit
f41939f443
@ -25,8 +25,8 @@ public:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
virtual std::unique_ptr<OpenFile> createAndOpenFile(const std::string &name, mode_t mode) = 0;
|
||||
virtual void createDir(const std::string &name, mode_t mode) = 0;
|
||||
virtual std::unique_ptr<OpenFile> 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<std::vector<std::string>> children() const = 0;
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user