From bdab511d954a849d06e34f6d801cc374f867213b Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Sun, 21 Feb 2016 23:05:22 -0500 Subject: Implement statfs --- src/operations.cc | 14 ++++++++++++++ src/posix_extras.cc | 7 +++++++ src/posix_extras.h | 5 +++++ 3 files changed, 26 insertions(+) diff --git a/src/operations.cc b/src/operations.cc index 79d2d07..cf53b05 100644 --- a/src/operations.cc +++ b/src/operations.cc @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -61,6 +62,17 @@ void* Initialize(fuse_conn_info*) noexcept { return nullptr; } void Destroy(void*) noexcept {} +int Statfs(const char* const c_path, struct statvfs* const output) { + const std::string path(c_path); + if (path == "/") { + *output = root_->StatVFs(); + } else { + *output = + root_->OpenAt(EncodePath(path).c_str(), O_RDONLY | O_PATH).StatVFs(); + } + return 0; +} + int Getattr(const char* const c_path, struct stat* output) { const std::string path(c_path); if (path == "/") { @@ -276,6 +288,8 @@ fuse_operations FuseOperations(File* const root) { result.init = Initialize; result.destroy = Destroy; + result.statfs = CATCH_AND_RETURN_EXCEPTIONS(Statfs); + result.getattr = CATCH_AND_RETURN_EXCEPTIONS(Getattr); result.fgetattr = CATCH_AND_RETURN_EXCEPTIONS(Fgetattr); diff --git a/src/posix_extras.cc b/src/posix_extras.cc index c0a5234..3e916ad 100644 --- a/src/posix_extras.cc +++ b/src/posix_extras.cc @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -149,6 +150,12 @@ void File::RmDirAt(const char* const path) const { CheckSyscall(unlinkat(fd_, path, AT_REMOVEDIR)); } +struct statvfs File::StatVFs() const { + struct statvfs result; + CheckSyscall(fstatvfs(fd_, &result)); + return result; +} + void File::SymLinkAt(const char* const target, const char* const source) const { ValidatePath(source); CheckSyscall(symlinkat(target, fd_, source)); diff --git a/src/posix_extras.h b/src/posix_extras.h index b67e2b4..9dec22d 100644 --- a/src/posix_extras.h +++ b/src/posix_extras.h @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -107,6 +108,10 @@ class File { // path must indeed be relative (i.e., it must not start with '/'). void RmDirAt(const char* path) const; + // Retrieves information about the file system containing the referent of the + // file descriptor. + struct statvfs StatVFs() const; + // Creates a symlink at source pointing to target. target is unvalidated. // source is interpreted as a path relative to the file descriptor and must // indeed be relative (i.e., it must not start with '/'). -- cgit v1.2.3