From 90c61f66909affa269dfb396f0e5cc67f4e4de44 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Sun, 21 Feb 2016 20:14:05 -0500 Subject: Implement mkdir/rmdir --- src/operations.cc | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'src/operations.cc') diff --git a/src/operations.cc b/src/operations.cc index b62fdf0..382974e 100644 --- a/src/operations.cc +++ b/src/operations.cc @@ -123,8 +123,7 @@ int Mknod(const char* const c_path, const mode_t mode, try { const std::string path(c_path); if (path == "/") { - // They're asking to create the mount point. Huh? - return -EEXIST; + return -EISDIR; } else { root_->MkNod(EncodePath(path).c_str(), mode, dev); return 0; @@ -208,6 +207,24 @@ int Unlink(const char* c_path) noexcept { } } +int Mkdir(const char* const c_path, const mode_t mode) noexcept { + try { + const std::string path(c_path); + if (path == "/") { + // They're asking to create the mount point. Huh? + return -EEXIST; + } else { + root_->MkDir(EncodePath(path).c_str(), mode); + return 0; + } + } catch (const std::system_error& e) { + return -e.code().value(); + } catch (...) { + LOG(ERROR) << "mknod: caught unexpected value"; + return -ENOTRECOVERABLE; + } +} + int Opendir(const char* const path, fuse_file_info* const file_info) noexcept { return OpenResource(path, O_DIRECTORY, &file_info->fh); } @@ -248,6 +265,24 @@ int Releasedir(const char*, fuse_file_info* const file_info) noexcept { return ReleaseResource(file_info->fh); } +int Rmdir(const char* c_path) noexcept { + try { + const std::string path(c_path); + if (path == "/") { + // Removing the root is probably a bad idea. + return -EPERM; + } else { + root_->RmDirAt(EncodePath(path).c_str()); + return 0; + } + } catch (const std::system_error& e) { + return -e.code().value(); + } catch (...) { + LOG(ERROR) << "unlink: caught unexpected value"; + return -ENOTRECOVERABLE; + } +} + } // namespace fuse_operations FuseOperations(File* const root) { @@ -274,9 +309,11 @@ fuse_operations FuseOperations(File* const root) { result.release = &Release; result.unlink = &Unlink; + result.mkdir = &Mkdir; result.opendir = &Opendir; result.readdir = &Readdir; result.releasedir = &Releasedir; + result.rmdir = &Rmdir; return result; } -- cgit v1.2.3