aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@mit.edu>2016-02-13 22:26:42 -0500
committerGravatar Benjamin Barenblat <bbaren@mit.edu>2016-02-13 22:26:42 -0500
commitf92ffae9707904749858eeb5fae3ef750875c8fb (patch)
tree84f42462e7fbba1349a5c4148b1de30383298d3c
parentfbcdf864613bfeb84edfa945304c065f6a29b44e (diff)
Rewrite getattr to query underlying file system
-rw-r--r--src/operations.cc25
1 files 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) {