aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/operations.cc14
-rw-r--r--src/posix_extras.cc7
-rw-r--r--src/posix_extras.h5
3 files changed, 26 insertions, 0 deletions
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 <fcntl.h>
#include <glog/logging.h>
#include <sys/stat.h>
+#include <sys/statvfs.h>
#include <sys/types.h>
#include <time.h>
@@ -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 <glog/logging.h>
#include <stdio.h>
#include <sys/stat.h>
+#include <sys/statvfs.h>
#include <sys/types.h>
#include <unistd.h>
@@ -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 <dirent.h>
#include <sys/stat.h>
+#include <sys/statvfs.h>
#include <sys/types.h>
#include <time.h>
@@ -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 '/').