+2004-02-19 Miklos Szeredi <mszeredi@inf.bme.hu>
+
+ * statfs library API changed to match other methods. Since this
+ is not backward compatible FUSE_MAJOR_VERSION is changed to 2
+
+ * statfs kernel interface changed to 64 bits, added 'bavail' field
+
2004-02-18 Miklos Szeredi <mszeredi@inf.bme.hu>
* user-mount upgraded for 2.6.3 kernel
return res;
}
-static int xmp_statfs(struct fuse_statfs *fst)
+static int xmp_statfs(const char *path, struct statfs *stbuf)
{
- struct statfs st;
- int rv = statfs("/",&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;
+ int res;
+
+ res = statfs(path, stbuf);
+ if(res == -1)
+ return -errno;
+
+ return 0;
}
static int xmp_release(const char *path, int flags)
return size;
}
-static int null_statfs(struct fuse_statfs *st)
-{
- return st->block_size = st->blocks = st->blocks_free = st->files =
- st->files_free = st->namelen = 0;
-}
-
static struct fuse_operations null_oper = {
.getattr = null_getattr,
.truncate = null_truncate,
.open = null_open,
.read = null_read,
.write = null_write,
- .statfs = null_statfs,
};
int main(int argc, char *argv[])
/* This file defines the library interface of FUSE */
/** Major version of FUSE library interface */
-#define FUSE_MAJOR_VERSION 1
+#define FUSE_MAJOR_VERSION 2
/** Minor version of FUSE library interface */
#define FUSE_MINOR_VERSION 1
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/statfs.h>
#include <utime.h>
/* ----------------------------------------------------------- *
/** Handle for a FUSE filesystem */
struct fuse;
-/* Statfs structure used by FUSE */
-struct fuse_statfs {
- long block_size;
- long blocks;
- long blocks_free;
- long files;
- long files_free;
- long namelen;
-};
-
/** Handle for a getdir() operation */
typedef struct fuse_dirhandle *fuse_dirh_t;
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 fuse_statfs *);
+ int (*statfs) (const char *, struct statfs *);
int (*release) (const char *, int);
int (*fsync) (const char *, int);
};
/* This file defines the kernel interface of FUSE */
/** Version number of this interface */
-#define FUSE_KERNEL_VERSION 2
+#define FUSE_KERNEL_VERSION 3
/** Minor version number of this interface */
-#define FUSE_KERNEL_MINOR_VERSION 2
+#define FUSE_KERNEL_MINOR_VERSION 1
/** The inode number of the root indode */
#define FUSE_ROOT_INO 1
};
struct fuse_kstatfs {
- long block_size;
- long blocks;
- long blocks_free;
- long files;
- long files_free;
- long namelen;
+ unsigned int bsize;
+ unsigned long long blocks;
+ unsigned long long bfree;
+ unsigned long long bavail;
+ unsigned long long files;
+ unsigned long long ffree;
+ unsigned int namelen;
};
#define FATTR_MODE (1 << 0)
static void convert_fuse_statfs(struct kstatfs *stbuf, struct fuse_kstatfs *attr)
{
stbuf->f_type = FUSE_SUPER_MAGIC;
- stbuf->f_bsize = attr->block_size;
+ stbuf->f_bsize = attr->bsize;
stbuf->f_blocks = attr->blocks;
- stbuf->f_bfree = stbuf->f_bavail = attr->blocks_free;
+ stbuf->f_bfree = attr->bfree;
+ stbuf->f_bavail = attr->bavail;
stbuf->f_files = attr->files;
- stbuf->f_ffree = attr->files_free;
- /* Is this field necessary? Most filesystems ignore it...
- stbuf->f_fsid.val[0] = (FUSE_SUPER_MAGIC>>16)&0xffff;
- stbuf->f_fsid.val[1] = FUSE_SUPER_MAGIC &0xffff; */
+ stbuf->f_ffree = attr->ffree;
stbuf->f_namelen = attr->namelen;
+ /* fsid is left zero */
}
static int fuse_statfs(struct super_block *sb, struct kstatfs *buf)
send_reply(f, in, res, NULL, 0);
}
+static void convert_statfs(struct statfs *statfs, struct fuse_kstatfs *kstatfs)
+{
+ kstatfs->bsize = statfs->f_bsize;
+ kstatfs->blocks = statfs->f_blocks;
+ kstatfs->bfree = statfs->f_bfree;
+ kstatfs->bavail = statfs->f_bavail;
+ kstatfs->files = statfs->f_files;
+ kstatfs->ffree = statfs->f_ffree;
+ kstatfs->namelen = statfs->f_namelen;
+}
+
static void do_statfs(struct fuse *f, struct fuse_in_header *in)
{
int res;
struct fuse_statfs_out arg;
+ struct statfs buf;
res = -ENOSYS;
if(f->op.statfs) {
- memset(&arg, 0, sizeof(struct fuse_statfs_out));
- res = f->op.statfs((struct fuse_statfs *) &arg.st);
+ res = f->op.statfs("/", &buf);
+ if(res == 0) {
+ memset(&arg, 0, sizeof(struct fuse_statfs_out));
+ convert_statfs(&buf, &arg.st);
+ }
}
send_reply(f, in, res, &arg, sizeof(arg));