aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@mit.edu>2016-02-21 20:32:29 -0500
committerGravatar Benjamin Barenblat <bbaren@mit.edu>2016-02-21 20:38:12 -0500
commitfa0cb2cf4e0b52e57f50b2b8cc25228d481abc31 (patch)
tree9f1945429ff6ca0c4168b6c6d9c24577addfbafa
parent4f9c17ee5044c68a358a92e90772eea5b3966e3c (diff)
Implement chmod
-rw-r--r--src/operations.cc1
-rw-r--r--src/posix_extras.cc9
-rw-r--r--src/posix_extras.h4
3 files changed, 14 insertions, 0 deletions
diff --git a/src/operations.cc b/src/operations.cc
index 697f901..4433809 100644
--- a/src/operations.cc
+++ b/src/operations.cc
@@ -335,6 +335,7 @@ fuse_operations FuseOperations(File* const root) {
result.fgetattr = &Fgetattr;
result.mknod = &Mknod;
+ result.chmod = &Chmod;
result.rename = &Rename;
result.open = &Open;
result.read = &Read;
diff --git a/src/posix_extras.cc b/src/posix_extras.cc
index 17fe275..8a63d11 100644
--- a/src/posix_extras.cc
+++ b/src/posix_extras.cc
@@ -67,6 +67,15 @@ struct stat File::Stat() const {
return result;
}
+void File::ChModAt(const char* const path, const mode_t mode) const {
+ if (path[0] == '/') {
+ throw std::invalid_argument("absolute path");
+ }
+ if (fchmodat(fd_, path, mode, 0) == -1) {
+ throw SystemError();
+ }
+}
+
struct stat File::LinkStatAt(const char* const path) const {
if (path[0] == '/') {
throw std::invalid_argument("absolute path");
diff --git a/src/posix_extras.h b/src/posix_extras.h
index b9e9da6..2976016 100644
--- a/src/posix_extras.h
+++ b/src/posix_extras.h
@@ -65,6 +65,10 @@ class File {
// Calls fstat(2) on the file descriptor.
struct stat Stat() const;
+ // Changes the file mode of the path relative to the file descriptor. The
+ // path must indeed be relative (i.e., it must not start with '/').
+ void ChModAt(const char* path, mode_t) const;
+
// Calls lstat(2) on the path relative to the file descriptor. The path must
// indeed be relative (i.e., it must not start with '/').
struct stat LinkStatAt(const char* path) const;