From f92ffae9707904749858eeb5fae3ef750875c8fb Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Sat, 13 Feb 2016 22:26:42 -0500 Subject: Rewrite getattr to query underlying file system --- src/operations.cc | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/operations.cc b/src/operations.cc index d22a1e2..2eb326a 100644 --- a/src/operations.cc +++ b/src/operations.cc @@ -72,6 +72,13 @@ mode_t DirectoryTypeToFileType(const unsigned char type) { } } +#define RETURN_ON_ERROR(call) \ + if ((call) == -1) { \ + return -errno; \ + } \ + do { \ + } while (false) + void* Initialize(fuse_conn_info*) { LOG(INFO) << "initialize"; return nullptr; @@ -85,9 +92,21 @@ void Destroy(void*) { int Getattr(const char* const path, struct stat* output) { LOG(INFO) << "getattr(" << path << ")"; - if (lstat(path, output) == -1) { - return -errno; + + if (path[0] == '\0') { + LOG(ERROR) << "getattr called on path not starting with /"; + return -ENOENT; } + + if (strcmp(path, "/") == 0) { + // They're asking for information about the mount point. + RETURN_ON_ERROR(fstat(root_fd_, output)); + return 0; + } + + // Trim the leading slash so fstatat will treat it relative to root_fd_. + LOG(INFO) << "getattr: trimming leading slash"; + RETURN_ON_ERROR(fstatat(root_fd_, path + 1, output, AT_SYMLINK_NOFOLLOW)); return 0; } @@ -157,6 +176,8 @@ int Releasedir(const char*, fuse_file_info* const file_info) { return 0; } +#undef RETURN_ON_ERROR + } // namespace fuse_operations FuseOperations(const int root_fd) { -- cgit v1.2.3