'struct statfs' changes size, and entries within it change position, depending
authorMark Glines <mark@glines.org>
Sun, 17 Mar 2002 06:58:33 +0000 (06:58 +0000)
committerMark Glines <mark@glines.org>
Sun, 17 Mar 2002 06:58:33 +0000 (06:58 +0000)
on which headerfiles are included and which macros are defined.  Because its
unreliable, we now use struct fuse_statfs everywhere except in the kernel.

Also fixed some perl fuse_main semantics - it now works much better when
multithreading is disabled.

example/fusexmp.c
example/null.c
include/fuse.h
include/fusestat.h [new file with mode: 0644]
include/linux/fuse.h
lib/fuse.c
perl/Fuse.xs
perl/loopback.pl

index f2376672def199e7e8bf122922b3c189f576cc05..8b48af663919e51a9657f1b7ae5371ca1329098d 100644 (file)
@@ -233,12 +233,18 @@ static int xmp_write(const char *path, const char *buf, size_t size,
     return res;
 }
 
-static int xmp_statfs(struct statfs *fst)
+static int xmp_statfs(struct fuse_statfs *fst)
 {
     struct statfs st;
     int rv = statfs("/",&st);
-    if(!rv)
-       memcpy(fst,&st,sizeof(st));
+    if(!rv) {
+       fst->block_size  = st.f_bsize;
+       fst->blocks      = st.f_blocks;
+       fst->blocks_free = st.f_bavail;
+       fst->files       = st.f_files;
+       fst->files_free  = st.f_ffree;
+       fst->namelen     = st.f_namelen;
+    }
     return rv;
 }
 
index 3a948f25d5478eaa6b130e3511453ee8a244d4f9..6b2c1b65f6daca53b3cf15e7982c1e8cbbe0c60f 100644 (file)
@@ -64,10 +64,10 @@ static int null_write(const char *path, const char *UNUSED(buf), size_t size,
     return size;
 }
 
-static int null_statfs(struct statfs *st)
+static int null_statfs(struct fuse_statfs *st)
 {
-    return st->f_blocks = st->f_bavail = st->f_bsize = st->f_files =
-       st->f_ffree = st->f_namelen = 0;
+    return st->block_size = st->blocks = st->blocks_free = st->files =
+       st->files_free = st->namelen = 0;
 }
 
 static struct fuse_operations null_oper = {
index 46fc87b83d67a7e5915600250726ff046ab6fe97..451e16384dc347fcb801d0533df59f3a8e1cd668 100644 (file)
@@ -13,9 +13,9 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/statfs.h>
 #include <utime.h>
 
+#include "fusestat.h"
 /* ----------------------------------------------------------- *
  * Basic FUSE API                                              *
  * ----------------------------------------------------------- */
@@ -82,7 +82,7 @@ struct fuse_operations {
     int (*open)     (const char *, int);
     int (*read)     (const char *, char *, size_t, off_t);
     int (*write)    (const char *, const char *, size_t, off_t);
-    int (*statfs)   (struct statfs *);
+    int (*statfs)   (struct fuse_statfs *);
 };
 
 /** Extra context that may be needed by some filesystems */
diff --git a/include/fusestat.h b/include/fusestat.h
new file mode 100644 (file)
index 0000000..a18509c
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef __FUSESTAT_H_
+#define __FUSESTAT_H_
+/* this is seperated out into its own file because both
+ * kernel and lib use it, but neither can #include the
+ * other's headerfile */
+typedef struct fuse_statfs {
+    long block_size;
+    long blocks;
+    long blocks_free;
+    long files;
+    long files_free;
+    long namelen;
+} fuse_statfs_t;
+#endif
index 40f395043ef0cf08cdf9300ba11749cf3f64230d..539ebce54c1893ca270b314c2d825d964d484349 100644 (file)
@@ -8,6 +8,7 @@
 
 /* This file defines the kernel interface of FUSE */
 
+#include "fusestat.h"
 /** Version number of this interface */
 #define FUSE_KERNEL_VERSION 2
 
@@ -157,15 +158,6 @@ struct fuse_write_in {
        char buf[0];
 };
 
-typedef struct fuse_statfs {
-       long block_size;
-       long blocks;
-       long blocks_free;
-       long files;
-       long files_free;
-       long namelen;
-} fuse_statfs_t;
-
 struct fuse_statfs_out {
        struct fuse_statfs st;
 };
index 63dadf55e0f47c97fb60efa18b59f66540e4c639..2ac7386731faef613b0fb45334f9a5075947fe55 100644 (file)
@@ -306,16 +306,6 @@ static void convert_stat(struct stat *stbuf, struct fuse_attr *attr)
     attr->_dummy  = 4096;
 }
 
-static void convert_statfs(struct statfs *st, struct fuse_statfs *fst)
-{
-    fst->block_size  = st->f_bsize;
-    fst->blocks      = st->f_blocks;
-    fst->blocks_free = st->f_bavail;
-    fst->files       = st->f_files;
-    fst->files_free  = st->f_ffree;
-    fst->namelen     = st->f_namelen;
-}
-
 static int fill_dir(struct fuse_dirhandle *dh, char *name, int type)
 {
     struct fuse_dirent dirent;
@@ -806,14 +796,11 @@ static void do_write(struct fuse *f, struct fuse_in_header *in,
 static void do_statfs(struct fuse *f, struct fuse_in_header *in)
 {
     int res;
-    struct statfs sbuf;
     struct fuse_statfs_out arg;
 
     res = -ENOSYS;
     if(f->op.statfs)
-        res = f->op.statfs(&sbuf);
-    if(res == 0)
-        convert_statfs(&sbuf,&arg.st);
+        res = f->op.statfs(&arg.st);
 
     send_reply(f, in, res, &arg, sizeof(arg));
 }
index f197449222218c6d749f7f17d897b802b54c7c3f..6e8a5c6835da0e67db1d81dd562ab13285d7b0e8 100644 (file)
@@ -32,6 +32,7 @@ int _PLfuse_getattr(const char *file, struct stat *result) {
                else
                        rv = -ENOENT;
        } else {
+               DEBUGf("populating\n");
                result->st_blocks = POPi;
                result->st_blksize = POPi;
                result->st_ctime = POPi;
@@ -50,6 +51,7 @@ int _PLfuse_getattr(const char *file, struct stat *result) {
        FREETMPS;
        LEAVE;
        PUTBACK;
+       DEBUGf("getattr end %i %o\n",rv,result->st_mode);
        return rv;
 }
 
@@ -473,7 +475,7 @@ int _PLfuse_write (const char *file, const char *buf, size_t buflen, off_t off)
        return rv;
 }
 
-int _PLfuse_statfs (struct statfs *st) {
+int _PLfuse_statfs (struct fuse_statfs *st) {
        int rv;
        char *rvstr;
        dSP;
@@ -485,12 +487,12 @@ int _PLfuse_statfs (struct statfs *st) {
        rv = call_sv(_PLfuse_callbacks[17],G_ARRAY);
        SPAGAIN;
        if(rv > 5) {
-               st->f_bsize   = POPi;
-               st->f_bavail  = st->f_bfree = POPi;
-               st->f_blocks  = POPi;
-               st->f_ffree   = POPi;
-               st->f_files   = POPi;
-               st->f_namelen = POPi;
+               st->block_size  = POPi;
+               st->blocks_free = POPi;
+               st->blocks      = POPi;
+               st->files_free  = POPi;
+               st->files       = POPi;
+               st->namelen     = POPi;
                if(rv > 6)
                        rv = POPi;
                else
index c055db58fd6e8f2af70135acad564d326723998e..e58d90a18bbb0420ee48cf46f82068e2343f4e4f 100644 (file)
@@ -14,8 +14,9 @@ sub fixup { return "/tmp/test" . shift }
 
 sub x_getattr {
        my ($file) = fixup(shift);
-       return -ENOENT() unless -e $file;
-       return (lstat($file));
+       my (@list) = lstat($file);
+       return -$! unless @list;
+       return @list;
 }
 
 sub x_getdir {
@@ -53,7 +54,7 @@ sub x_read {
 
 sub x_write {
        my ($file,$buf,$off) = @_;
-       debug("write",@_);
+       debug("write",$file,length($buf),$off);
        my ($rv);
        return -ENOENT() unless -e ($file = fixup($file));
        return -ENOSYS() unless sysopen(FILE,$file,O_RDWR()|O_APPEND()|O_CREAT());
@@ -67,16 +68,36 @@ sub x_write {
 sub err { return (-shift || -$!) }
 
 sub x_readlink { return readlink(fixup(shift)                 ); }
-sub x_unlink   { return unlink(fixup(shift)) ? 0 : -$!;          }
-sub x_rmdir    { return err(rmdir(fixup(shift))               ); }
-sub x_symlink  { return err(symlink(fixup(shift),fixup(shift))); }
-sub x_rename   { return err(rename(fixup(shift),fixup(shift)) ); }
-sub x_link     { return err(link(fixup(shift),fixup(shift))   ); }
-sub x_chmod    { return err(chmod(fixup(shift),shift)         ); }
-sub x_chown    { return err(chown(fixup(shift),shift,shift)   ); }
-sub x_chmod    { return err(chmod(fixup(shift),shift)         ); }
+sub x_unlink { return unlink(fixup(shift)) ? 0 : -$!;          }
+sub x_rmdir { return err(rmdir(fixup(shift))               ); }
+sub x_symlink { return err(symlink(fixup(shift),fixup(shift))); }
+sub x_rename {
+       debug("rename",@_);
+       my ($old) = fixup(shift);
+       my ($new) = fixup(shift);
+       my ($err) = rename($old,$new) ? 0 : -ENOENT();
+       debug("old=$old,new=$new,err=$err");
+       return $err;
+}
+sub x_link { return err(link(fixup(shift),fixup(shift))   ); }
+sub x_chown {
+       debug("chown",@_);
+       my ($fn) = fixup(shift);
+       my ($uid,$gid) = @_;
+       my ($err) = chown($uid,$gid,$fn) ? 0 : -$!;
+       debug("fn=$fn,uid=$uid,gid=$gid,err=$err");
+       return $err;
+}
+sub x_chmod {
+       debug("chmod",@_);
+       my ($fn) = fixup(shift);
+       my ($mode) = shift;
+       my ($err) = chmod($mode,$fn) ? 0 : -$!;
+       debug("fn=$fn,mode=$mode,err=$err");
+       return $err;
+}
 sub x_truncate { return truncate(fixup(shift),shift) ? 0 : -$! ; }
-sub x_utime    { return utime($_[1],$_[2],fixup($_[0])) ? 0:-$!; }
+sub x_utime { return utime($_[1],$_[2],fixup($_[0])) ? 0:-$!; }
 
 sub x_mkdir { my ($name, $perm) = @_; return 0 if mkdir(fixup($name),$perm); return -$!; }
 sub x_rmdir { return 0 if rmdir fixup(shift); return -$!; }
@@ -102,11 +123,12 @@ sub x_mknod {
        }
 }
 
+# kludge
+sub x_statfs {return 255,1000000,500000,1000000,500000,4096}
 my ($mountpoint) = "";
 $mountpoint = shift(@ARGV) if @ARGV;
 Fuse::main(
        unthreaded=>1,
-       debug=>1,
        mountpoint=>$mountpoint,
        getattr=>\&x_getattr,
        readlink=>\&x_readlink,
@@ -124,5 +146,6 @@ Fuse::main(
        utime=>\&x_utime,
        open=>\&x_open,
        read=>\&x_read,
-       write=>\&x_write
+       write=>\&x_write,
+       statfs=>\&x_statfs
 );