From 05cafc5002360015a79484e6ee40c159b1c80958 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Sun, 21 Feb 2016 19:22:01 -0500 Subject: Replace creat with mknod+open Performance is not an immediate concern, so replace creat with mknod to compact code. --- src/operations.cc | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/operations.cc') diff --git a/src/operations.cc b/src/operations.cc index 2bded60..df12738 100644 --- a/src/operations.cc +++ b/src/operations.cc @@ -75,7 +75,7 @@ int Getattr(const char* const path, struct stat* output) noexcept { } template -int OpenResource(const char* const path, const int flags, const mode_t mode, +int OpenResource(const char* const path, const int flags, uint64_t* const handle) noexcept { try { std::unique_ptr t(new T( @@ -85,7 +85,7 @@ int OpenResource(const char* const path, const int flags, const mode_t mode, *root_ : // Trim the leading slash so OpenAt will treat it relative to root_. - root_->OpenAt(path + 1, flags, mode))); + root_->OpenAt(path + 1, flags))); static_assert(sizeof(*handle) == sizeof(std::uintptr_t), "FUSE file handles are a different size than pointers"); @@ -107,29 +107,29 @@ int ReleaseResource(const uint64_t handle) noexcept { return 0; } -int Open(const char* const path, fuse_file_info* const file_info) noexcept { - return OpenResource(path, file_info->flags, 0777, &file_info->fh); -} - -int Create(const char* const path, const mode_t mode, - fuse_file_info* const file_info) noexcept { +int Mknod(const char* const c_path, const mode_t mode, + const dev_t dev) noexcept { try { if (std::strcmp(path, "/") == 0) { // They're asking to create the mount point. Huh? return -EEXIST; } - return OpenResource(path, - file_info->flags | O_CREAT | O_WRONLY | O_EXCL, - mode, &file_info->fh); + // Trim the leading slash so OpenAt will treat it relative to root_. + root_->MkNod(path + 1, mode, dev); + return 0; } catch (const std::system_error& e) { return -e.code().value(); } catch (...) { - LOG(ERROR) << "create: caught unexpected value"; + LOG(ERROR) << "mknod: caught unexpected value"; return -ENOTRECOVERABLE; } } +int Open(const char* const path, fuse_file_info* const file_info) noexcept { + return OpenResource(path, file_info->flags, &file_info->fh); +} + int Release(const char*, fuse_file_info* const file_info) noexcept { return ReleaseResource(file_info->fh); } @@ -153,7 +153,7 @@ int Unlink(const char* c_path) noexcept { } int Opendir(const char* const path, fuse_file_info* const file_info) noexcept { - return OpenResource(path, O_DIRECTORY, 0777, &file_info->fh); + return OpenResource(path, O_DIRECTORY, &file_info->fh); } int Readdir(const char*, void* const buffer, fuse_fill_dir_t filler, @@ -209,8 +209,8 @@ fuse_operations FuseOperations(File* const root) { result.getattr = &Getattr; + result.mknod = &Mknod; result.open = &Open; - result.create = &Create; result.release = &Release; result.unlink = &Unlink; -- cgit v1.2.3