From 13643137642c5000924e20de56856c909b05769e Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Sun, 21 Feb 2016 22:48:21 -0500 Subject: Implement creat Turns out FUSE needs it after all (for operations with O_EXCL). --- src/operations.cc | 14 +++++++++++--- 1 file 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 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(new T( - path == "/" ? *root_ : root_->OpenAt(EncodePath(path).c_str(), flags))); + std::unique_ptr 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(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(path, file_info->flags | O_CREAT, &file_info->fh, + mode); +} + int Open(const char* const path, fuse_file_info* const file_info) { return OpenResource(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); -- cgit v1.2.3