diff options
author | Benjamin Barenblat <bbaren@mit.edu> | 2016-02-21 22:48:21 -0500 |
---|---|---|
committer | Benjamin Barenblat <bbaren@mit.edu> | 2016-02-21 22:48:54 -0500 |
commit | 13643137642c5000924e20de56856c909b05769e (patch) | |
tree | 3513a10b4a5918e5faa3b6b657cb4247b7573913 | |
parent | b5c9c8540a29babf990ff72b1eb5904424f1abb0 (diff) |
Implement creat
Turns out FUSE needs it after all (for operations with O_EXCL).
-rw-r--r-- | src/operations.cc | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/operations.cc b/src/operations.cc index a82ad99..79d2d07 100644 --- a/src/operations.cc +++ b/src/operations.cc @@ -79,11 +79,12 @@ int Fgetattr(const char*, struct stat* const output, template <typename T> int OpenResource(const char* const c_path, const int flags, - uint64_t* const handle) { + uint64_t* const handle, const mode_t mode = 0) { try { const std::string path(c_path); - std::unique_ptr<T> t(new T( - path == "/" ? *root_ : root_->OpenAt(EncodePath(path).c_str(), flags))); + std::unique_ptr<T> t( + new T(path == "/" ? *root_ : root_->OpenAt(EncodePath(path).c_str(), + flags, mode))); static_assert(sizeof(*handle) == sizeof(std::uintptr_t), "FUSE file handles are a different size than pointers"); *handle = reinterpret_cast<std::uintptr_t>(t.release()); @@ -126,6 +127,12 @@ int Rename(const char* const c_old_path, const char* const c_new_path) { } } +int Create(const char* const path, const mode_t mode, + fuse_file_info* const file_info) { + return OpenResource<File>(path, file_info->flags | O_CREAT, &file_info->fh, + mode); +} + int Open(const char* const path, fuse_file_info* const file_info) { return OpenResource<File>(path, file_info->flags, &file_info->fh); } @@ -275,6 +282,7 @@ fuse_operations FuseOperations(File* const root) { result.mknod = CATCH_AND_RETURN_EXCEPTIONS(Mknod); result.chmod = CATCH_AND_RETURN_EXCEPTIONS(Chmod); result.rename = CATCH_AND_RETURN_EXCEPTIONS(Rename); + result.create = CATCH_AND_RETURN_EXCEPTIONS(Create); result.open = CATCH_AND_RETURN_EXCEPTIONS(Open); result.read = CATCH_AND_RETURN_EXCEPTIONS(Read); result.write = CATCH_AND_RETURN_EXCEPTIONS(Write); |