fix up statfs interface
authorMiklos Szeredi <miklos@szeredi.hu>
Mon, 7 Nov 2005 11:59:00 +0000 (11:59 +0000)
committerMiklos Szeredi <miklos@szeredi.hu>
Mon, 7 Nov 2005 11:59:00 +0000 (11:59 +0000)
ChangeLog
example/fusexmp.c
example/fusexmp_fh.c
include/fuse.h
include/fuse_compat.h
include/fuse_lowlevel.h
kernel/dir.c
kernel/fuse_i.h
lib/fuse.c
lib/fuse_lowlevel.c

index c361a4e7aadad1ad6a2f26bd21c9916bce6391fc..17f24c7c011ab14971cbba72665fe734a7eb8204 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-11-06  Miklos Szeredi <miklos@szeredi.hu>
+
+       * Change ->statfs() method to use 'struct statvfs' instead of
+       'struct statfs'.  This makes the API more portable since statvfs()
+       is defined by POSIX.
+
 2005-10-28  Miklos Szeredi <miklos@szeredi.hu>
 
        * Add fgetattr() method, which currently will only be called after
index 173255679642348d1a1e56991c3ea575b0f1bea7..5a2e9a0f6d4bf5c8c06821cd8c9f60d2fb7e3e09 100644 (file)
@@ -20,7 +20,6 @@
 #include <fcntl.h>
 #include <dirent.h>
 #include <errno.h>
-#include <sys/statfs.h>
 #ifdef HAVE_SETXATTR
 #include <sys/xattr.h>
 #endif
@@ -258,11 +257,11 @@ static int xmp_write(const char *path, const char *buf, size_t size,
     return res;
 }
 
-static int xmp_statfs(const char *path, struct statfs *stbuf)
+static int xmp_statfs(const char *path, struct statvfs *stbuf)
 {
     int res;
 
-    res = statfs(path, stbuf);
+    res = statvfs(path, stbuf);
     if(res == -1)
         return -errno;
 
index 764ba914f21849232f2388cda1fe3f89838720d5..93bd8432cb3186b4d0e3f9c44ad1d6c1523bbe90 100644 (file)
@@ -17,7 +17,6 @@
 #include <fcntl.h>
 #include <dirent.h>
 #include <errno.h>
-#include <sys/statfs.h>
 #ifdef HAVE_SETXATTR
 #include <sys/xattr.h>
 #endif
@@ -293,11 +292,11 @@ static int xmp_write(const char *path, const char *buf, size_t size,
     return res;
 }
 
-static int xmp_statfs(const char *path, struct statfs *stbuf)
+static int xmp_statfs(const char *path, struct statvfs *stbuf)
 {
     int res;
 
-    res = statfs(path, stbuf);
+    res = statvfs(path, stbuf);
     if(res == -1)
         return -errno;
 
index 329fd5eed27281f411611bd459b052b5677822a9..831dbff01997e50fd72c6e6ab32838985e908acc 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/statfs.h>
+#include <sys/statvfs.h>
 #include <utime.h>
 
 #ifdef __cplusplus
@@ -162,11 +162,8 @@ struct fuse_operations {
     int (*write) (const char *, const char *, size_t, off_t,
                   struct fuse_file_info *);
 
-    /** Get file system statistics
-     *
-     * The 'f_type' and 'f_fsid' fields are ignored
-     */
-    int (*statfs) (const char *, struct statfs *);
+    /** Old statfs interface, deprecated */
+    int (*statfs_old) (const char *, void *stbuf);
 
     /** Possibly flush cached data
      *
@@ -352,6 +349,15 @@ struct fuse_operations {
      * Introduced in version 2.5
      */
     int (*fgetattr) (const char *, struct stat *, struct fuse_file_info *);
+
+    /** Get file system statistics
+     *
+     * The 'f_frsize', 'f_favail', 'f_fsid' and 'f_flag' fields are ignored
+     *
+     * Replaced 'struct statfs' parameter with 'struct statvfs' in
+     * version 2.5
+     */
+    int (*statfs) (const char *, struct statvfs *stbuf);
 };
 
 /** Extra context that may be needed by some filesystems
index af7aecf7df7d229f0280c8eb8e211dca1588a618..08d391ac675b47f9837c775ff8e7dfa71ecb0c36 100644 (file)
@@ -9,6 +9,8 @@
 /* these definitions provide source compatibility to prior versions.
    Do not include this file directly! */
 
+#include <sys/statfs.h>
+
 typedef int (*fuse_dirfil_t_compat) (fuse_dirh_t h, const char *name, int type);
 struct fuse_operations_compat2 {
     int (*getattr)     (const char *, struct stat *);
index a02716311ca9a898d487a08b2b31b3f234e679b0..f90d0210d202c6686320dfcc6fcd2d47889ea0c8 100644 (file)
@@ -18,7 +18,7 @@
 #include <utime.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/statfs.h>
+#include <sys/statvfs.h>
 #include <sys/uio.h>
 
 #ifdef __cplusplus
@@ -840,7 +840,7 @@ int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size);
  * @param stbuf filesystem statistics
  * @return zero for success, -errno for failure to send reply
  */
-int fuse_reply_statfs(fuse_req_t req, const struct statfs *stbuf);
+int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf);
 
 /**
  * Reply with needed buffer size
index 48df469c119f2b617c254220b39e54690315e923..bfec2880963bbffc2f047327a76d82f7953c5689 100644 (file)
@@ -659,9 +659,11 @@ static int fuse_permission(struct inode *inode, int mask, struct nameidata *nd)
                return err;
        } else {
                int mode = inode->i_mode;
+#ifndef KERNEL_2_6_11_PLUS
                if ((mask & MAY_WRITE) && IS_RDONLY(inode) &&
                     (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
                         return -EROFS;
+#endif
                if ((mask & MAY_EXEC) && !S_ISDIR(mode) && !(mode & S_IXUGO))
                        return -EACCES;
 
index dced4491d16243a95b17f2e57a44f0d7e965f560..fbebe7f16392f8df3b7d2fc19b9f6cb07578be98 100644 (file)
@@ -31,6 +31,9 @@
 #  if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
 #    define KERNEL_2_6_10_PLUS
 #  endif
+#  if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
+#    define KERNEL_2_6_11_PLUS
+#  endif
 #  if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
 #    define KERNEL_2_6_12_PLUS
 #  endif
index 9cc70288e8f28d6b69721a491e689af28039f0cb..3557c3b870b7760fd21f1cf3d446ed35835f5765 100644 (file)
@@ -77,9 +77,9 @@ struct fuse {
     pthread_mutex_t lock;
     pthread_rwlock_t tree_lock;
     void *user_data;
-    uid_t uid;
-    gid_t gid;
-    mode_t umask;
+    unsigned int uid;
+    unsigned int gid;
+    unsigned int  umask;
     double entry_timeout;
     double attr_timeout;
 };
@@ -1527,15 +1527,15 @@ static void fuse_fsyncdir(fuse_req_t req, fuse_ino_t ino, int datasync,
     reply_err(req, err);
 }
 
-static int default_statfs(struct statfs *buf)
+static int default_statfs(struct statvfs *buf)
 {
-    buf->f_namelen = 255;
+    buf->f_namemax = 255;
     buf->f_bsize = 512;
     return 0;
 }
 
 static void convert_statfs_compat(struct fuse_statfs_compat1 *compatbuf,
-                                  struct statfs *stbuf)
+                                  struct statvfs *stbuf)
 {
     stbuf->f_bsize   = compatbuf->block_size;
     stbuf->f_blocks  = compatbuf->blocks;
@@ -1543,28 +1543,43 @@ static void convert_statfs_compat(struct fuse_statfs_compat1 *compatbuf,
     stbuf->f_bavail  = compatbuf->blocks_free;
     stbuf->f_files   = compatbuf->files;
     stbuf->f_ffree   = compatbuf->files_free;
-    stbuf->f_namelen = compatbuf->namelen;
+    stbuf->f_namemax = compatbuf->namelen;
+}
+
+static void convert_statfs_old(struct statfs *oldbuf, struct statvfs *stbuf)
+{
+    stbuf->f_bsize   = oldbuf->f_bsize;
+    stbuf->f_blocks  = oldbuf->f_blocks;
+    stbuf->f_bfree   = oldbuf->f_bfree;
+    stbuf->f_bavail  = oldbuf->f_bavail;
+    stbuf->f_files   = oldbuf->f_files;
+    stbuf->f_ffree   = oldbuf->f_ffree;
+    stbuf->f_namemax = oldbuf->f_namelen;
 }
 
 static void fuse_statfs(fuse_req_t req)
 {
     struct fuse *f = req_fuse_prepare(req);
-    struct statfs buf;
+    struct statvfs buf;
     int err;
 
-    memset(&buf, 0, sizeof(struct statfs));
+    memset(&buf, 0, sizeof(buf));
     if (f->op.statfs) {
-        if (!f->compat || f->compat > 11)
-            err = f->op.statfs("/", &buf);
-        else {
+        err = f->op.statfs("/", &buf);
+    } else if (f->op.statfs_old) {
+        if (!f->compat || f->compat > 11) {
+            struct statfs oldbuf;
+            err = f->op.statfs_old("/", &oldbuf);
+            if (!err)
+                convert_statfs_old(&oldbuf, &buf);
+        } else {
             struct fuse_statfs_compat1 compatbuf;
             memset(&compatbuf, 0, sizeof(struct fuse_statfs_compat1));
             err = ((struct fuse_operations_compat1 *) &f->op)->statfs(&compatbuf);
             if (!err)
                 convert_statfs_compat(&compatbuf, &buf);
-        }
-    }
-    else
+        }        
+    } else
         err = default_statfs(&buf);
 
     if (!err)
index b54631261a5104821b9a1d72fe34820e50e0de50..9edef54d4c7e897ec2493c8761846831472c22bb 100644 (file)
@@ -185,7 +185,7 @@ char *fuse_add_dirent(char *buf, const char *name, const struct stat *stbuf,
     return buf + entsize;
 }
 
-static void convert_statfs(const struct statfs *stbuf,
+static void convert_statfs(const struct statvfs *stbuf,
                            struct fuse_kstatfs *kstatfs)
 {
     kstatfs->bsize     = stbuf->f_bsize;
@@ -194,7 +194,7 @@ static void convert_statfs(const struct statfs *stbuf,
     kstatfs->bavail    = stbuf->f_bavail;
     kstatfs->files     = stbuf->f_files;
     kstatfs->ffree     = stbuf->f_ffree;
-    kstatfs->namelen   = stbuf->f_namelen;
+    kstatfs->namelen   = stbuf->f_namemax;
 }
 
 static int send_reply_ok(fuse_req_t req, const void *arg, size_t argsize)
@@ -320,7 +320,7 @@ int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size)
     return send_reply_ok(req, buf, size);
 }
 
-int fuse_reply_statfs(fuse_req_t req, const struct statfs *stbuf)
+int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf)
 {
     struct fuse_statfs_out arg;