getattr: Make use of FUSE_GETATTR_FH in lowlevel examples
authorBernd Schubert <bschubert@ddn.com>
Mon, 26 Aug 2024 17:33:47 +0000 (19:33 +0200)
committerBernd Schubert <bernd.schubert@fastmail.fm>
Thu, 12 Sep 2024 16:21:25 +0000 (18:21 +0200)
High level examples were already using it, but not
lowlevel. Also update the documentation.

example/passthrough_hp.cc
example/passthrough_ll.c
include/fuse_lowlevel.h

index 4dab544d5f2f7801651e96e89c1a5fcac6e82455..e75c749bece12b10c5d2650ece0dd6c096f00b55 100644 (file)
@@ -226,12 +226,12 @@ static void sfs_init(void *userdata, fuse_conn_info *conn) {
 }
 
 
-static void sfs_getattr(fuse_req_t req, fuse_ino_t ino, fuse_file_info *fi) {
-    (void)fi;
-    Inode& inode = get_inode(ino);
+static void sfs_getattr(fuse_req_t req, fuse_ino_t ino, fuse_file_info *fi)
+{
     struct stat attr;
-    auto res = fstatat(inode.fd, "", &attr,
-                       AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
+    int fd = fi ? fi->fh : get_inode(ino).fd;
+
+    auto res = fstatat(fd, "", &attr, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
     if (res == -1) {
         fuse_reply_err(req, errno);
         return;
index 87c18a28ebd7342bc8031806b2a84cc22ae85249..62a42f466f448e01fd26dd6a1b88df9071017a1d 100644 (file)
@@ -204,10 +204,11 @@ static void lo_getattr(fuse_req_t req, fuse_ino_t ino,
        int res;
        struct stat buf;
        struct lo_data *lo = lo_data(req);
+       int fd = fi ? fi->fh : lo_fd(req, ino);
 
        (void) fi;
 
-       res = fstatat(lo_fd(req, ino), "", &buf, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
+       res = fstatat(fd, "", &buf, AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW);
        if (res == -1)
                return (void) fuse_reply_err(req, errno);
 
index e62e24cf994496d620fa59cca7cf2ca02757a437..e5c308c4550195763261652009045c4de1f453b3 100644 (file)
@@ -303,7 +303,7 @@ struct fuse_lowlevel_ops {
         *
         * @param req request handle
         * @param ino the inode number
-        * @param fi for future use, currently always NULL
+        * @param fi file information, or NULL
         */
        void (*getattr) (fuse_req_t req, fuse_ino_t ino,
                         struct fuse_file_info *fi);