From f8b26d31e3993efe55d405535b33336187887fa6 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Tue, 21 Apr 2015 21:08:23 +0200 Subject: [PATCH] Added chmod/chown --- fs_interface/Node.h | 2 ++ fuse/Filesystem.h | 2 ++ fuse/Fuse.cpp | 26 +++++++++++++------------- impl/FilesystemImpl.cpp | 9 ++++++++- impl/FilesystemImpl.h | 2 ++ 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/fs_interface/Node.h b/fs_interface/Node.h index 40ed8bb9..7216181a 100644 --- a/fs_interface/Node.h +++ b/fs_interface/Node.h @@ -13,6 +13,8 @@ public: virtual ~Node() {} virtual void stat(struct ::stat *result) const = 0; + virtual void chmod(mode_t mode) = 0; + virtual void chown(uid_t uid, gid_t gid) = 0; virtual void access(int mask) const = 0; virtual void rename(const boost::filesystem::path &to) = 0; virtual void utimens(const timespec times[2]) = 0; diff --git a/fuse/Filesystem.h b/fuse/Filesystem.h index 91a62135..09419521 100644 --- a/fuse/Filesystem.h +++ b/fuse/Filesystem.h @@ -20,6 +20,8 @@ public: virtual void closeFile(int descriptor) = 0; virtual void lstat(const boost::filesystem::path &path, struct ::stat *stbuf) = 0; virtual void fstat(int descriptor, struct ::stat *stbuf) = 0; + virtual void chmod(const boost::filesystem::path &path, mode_t mode) = 0; + virtual void chown(const boost::filesystem::path &path, uid_t uid, gid_t gid) = 0; virtual void truncate(const boost::filesystem::path &path, off_t size) = 0; virtual void ftruncate(int descriptor, off_t size) = 0; virtual int read(int descriptor, void *buf, size_t count, off_t offset) = 0; diff --git a/fuse/Fuse.cpp b/fuse/Fuse.cpp index 240fa372..b58ad546 100644 --- a/fuse/Fuse.cpp +++ b/fuse/Fuse.cpp @@ -241,7 +241,7 @@ int Fuse::fgetattr(const bf::path &path, struct stat *stbuf, fuse_file_info *fil } try { - _fs->fstat(fileinfo->fh, stbuf); + _fs->fstat(fileinfo->fh, stbuf); return 0; } catch(fspp::fuse::FuseErrnoException &e) { return -e.getErrno(); @@ -324,22 +324,22 @@ int Fuse::link(const bf::path &from, const bf::path &to) { return ENOSYS; } -//TODO int Fuse::chmod(const bf::path &path, mode_t mode) { - printf("NOT IMPLEMENTED: chmod(%s, %d)\n", path.c_str(), mode); - //auto real_path = _impl->RootDir() / path; - //int retstat = ::chmod(real_path.c_str(), mode); - //return errcode_map(retstat); - return ENOSYS; + try { + _fs->chmod(path, mode); + return 0; + } catch (fspp::fuse::FuseErrnoException &e) { + return -e.getErrno(); + } } -//TODO int Fuse::chown(const bf::path &path, uid_t uid, gid_t gid) { - printf("NOT IMPLEMENTED: chown(%s, %d, %d)\n", path.c_str(), uid, gid); - //auto real_path = _impl->RootDir() / path; - //int retstat = ::chown(real_path.c_str(), uid, gid); - //return errcode_map(retstat); - return ENOSYS; + try { + _fs->chown(path, uid, gid); + return 0; + } catch (fspp::fuse::FuseErrnoException &e) { + return -e.getErrno(); + } } int Fuse::truncate(const bf::path &path, off_t size) { diff --git a/impl/FilesystemImpl.cpp b/impl/FilesystemImpl.cpp index 9405e0e2..4c0d43b1 100644 --- a/impl/FilesystemImpl.cpp +++ b/impl/FilesystemImpl.cpp @@ -71,6 +71,14 @@ void FilesystemImpl::fstat(int descriptor, struct ::stat *stbuf) { _open_files.get(descriptor)->stat(stbuf); } +void FilesystemImpl::chmod(const boost::filesystem::path &path, mode_t mode) { + _device->Load(path)->chmod(mode); +} + +void FilesystemImpl::chown(const boost::filesystem::path &path, uid_t uid, gid_t gid) { + _device->Load(path)->chown(uid, gid); +} + void FilesystemImpl::truncate(const bf::path &path, off_t size) { LoadFile(path)->truncate(size); } @@ -84,7 +92,6 @@ int FilesystemImpl::read(int descriptor, void *buf, size_t count, off_t offset) } void FilesystemImpl::write(int descriptor, const void *buf, size_t count, off_t offset) { - //printf("Write %d bytes to offset %d\n", count, offset);fflush(stdout); _open_files.get(descriptor)->write(buf, count, offset); } diff --git a/impl/FilesystemImpl.h b/impl/FilesystemImpl.h index 85c55d5b..6b6ae151 100644 --- a/impl/FilesystemImpl.h +++ b/impl/FilesystemImpl.h @@ -22,6 +22,8 @@ public: void closeFile(int descriptor) override; void lstat(const boost::filesystem::path &path, struct ::stat *stbuf) override; void fstat(int descriptor, struct ::stat *stbuf) override; + void chmod(const boost::filesystem::path &path, mode_t mode) override; + void chown(const boost::filesystem::path &path, uid_t uid, gid_t gid) override; void truncate(const boost::filesystem::path &path, off_t size) override; void ftruncate(int descriptor, off_t size) override; int read(int descriptor, void *buf, size_t count, off_t offset) override;