+2002-01-07 Mark Glines <mark@glines.org>
+
+ * Added statfs() support to kernel, lib, examples, and perl!
+
2001-12-20 Miklos Szeredi <mszeredi@inf.bme.hu>
* Added function fuse_get_context() to library API (inspired by
- Integrate (parts of) fusermount into mount(8)
- - Statfs operation
-
- Etc, etc...
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
+#include <sys/statfs.h>
static int xmp_getattr(const char *path, struct stat *stbuf)
{
return res;
}
+static int xmp_statfs(struct statfs *fst)
+{
+ struct statfs st;
+ int rv = statfs("/",&st);
+ if(!rv)
+ memcpy(fst,&st,sizeof(st));
+ return rv;
+}
+
static struct fuse_operations xmp_oper = {
getattr: xmp_getattr,
readlink: xmp_readlink,
open: xmp_open,
read: xmp_read,
write: xmp_write,
+ statfs: xmp_statfs,
};
int main(int argc, char *argv[])
open: hello_open,
read: hello_read,
write: NULL,
+ statfs: NULL,
};
int main(int argc, char *argv[])
return size;
}
+static int null_statfs(struct statfs *st)
+{
+ return st->f_blocks = st->f_bavail = st->f_bsize = st->f_files =
+ st->f_ffree = st->f_namelen = 0;
+}
static struct fuse_operations null_oper = {
getattr: null_getattr,
open: null_open,
read: null_read,
write: null_write,
+ statfs: null_statfs,
};
int main(int argc, char *argv[])
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/statfs.h>
#include <utime.h>
/* ----------------------------------------------------------- *
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 *);
};
/** Extra context that may be needed by some filesystems */
FUSE_OPEN = 14,
FUSE_READ = 15,
FUSE_WRITE = 16,
+ FUSE_STATFS = 17,
};
/* Conservative buffer size for the client */
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;
+};
+
struct fuse_in_header {
int unique;
enum fuse_opcode opcode;
spin_unlock(&fuse_lock);
}
+static void convert_fuse_statfs(struct statfs *stbuf, struct fuse_statfs *attr)
+{
+ stbuf->f_type = FUSE_SUPER_MAGIC;
+ stbuf->f_bsize = attr->block_size;
+ stbuf->f_blocks = attr->blocks;
+ stbuf->f_bfree = stbuf->f_bavail = attr->blocks_free;
+ 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_namelen = attr->namelen;
+}
+
+static int fuse_statfs(struct super_block *sb, struct statfs *st)
+{
+ struct fuse_conn *fc = sb->u.generic_sbp;
+ struct fuse_in in = FUSE_IN_INIT;
+ struct fuse_out out = FUSE_OUT_INIT;
+ struct fuse_statfs_out outarg;
+
+ in.numargs = 0;
+ in.h.opcode = FUSE_STATFS;
+ out.numargs = 1;
+ out.args[0].size = sizeof(outarg);
+ out.args[0].value = &outarg;
+ request_send(fc, &in, &out);
+ if(!out.h.error)
+ convert_fuse_statfs(st,&outarg.st);
+
+ return out.h.error;
+}
+
static struct super_operations fuse_super_operations = {
read_inode: fuse_read_inode,
clear_inode: fuse_clear_inode,
put_super: fuse_put_super,
+ statfs: fuse_statfs,
};
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;
send_reply(f, in, res, NULL, 0);
}
+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)
+ convert_statfs(&sbuf,&arg.st);
+ send_reply(f, in, res, &arg, sizeof(arg));
+}
+
static void free_cmd(struct fuse_cmd *cmd)
{
free(cmd->buf);
do_write(f, in, (struct fuse_write_in *) inarg);
break;
+ case FUSE_STATFS:
+ do_statfs(f, in);
+ break;
+
default:
fprintf(stderr, "Operation %i not implemented\n", in->opcode);
send_reply(f, in, -ENOSYS, NULL, 0);
--- /dev/null
+Fuse.bs Fuse.c Makefile blib pm_to_blib
bootstrap Fuse $VERSION;
sub main {
- my (@subs) = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
- my (@names) = qw(getattr readlink getdir mknod mkdir unlink rmdir symlink rename link chmod chown truncate utime open read write);
+ my (@subs) = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
+ my (@names) = qw(getattr readlink getdir mknod mkdir unlink rmdir symlink rename link chmod chown truncate utime open read write statfs);
my ($tmp) = 0;
my (%mapping) = map { $_ => $tmp++ } (@names);
my (%otherargs) = (debug=>0, threaded=>1, mountpoint=>"");
etc) can be imported either from POSIX or from Fcntl, often both.
See their respective documentations, for more information.
+=head2 EXPORT
+
+None by default.
+
+=head2 EXPORTABLE CONSTANTS
+
+None.
+
=head2 FUNCTIONS YOUR FILESYSTEM MAY IMPLEMENT
=head3 getattr
Called in an attempt to write (or overwrite) a portion of the file. Be prepared because $buffer could contain random binary data with NULLs and all sorts of other wonderful stuff.
-=head2 EXPORT
+=head3 statfs
-None by default.
+Arguments: none
+Returns any of the following:
-=head2 Exportable constants
+-ENOANO()
-None.
+or
+
+$namelen, $files, $files_free, $blocks, $blocks_avail, $blocksize
+
+or
+
+-ENOANO(), $namelen, $files, $files_free, $blocks, $blocks_avail, $blocksize
=head1 AUTHOR
return 0;
}
-SV *_PLfuse_callbacks[17];
+SV *_PLfuse_callbacks[18];
int _PLfuse_getattr(const char *file, struct stat *result) {
dSP;
return rv;
}
+int _PLfuse_statfs (struct statfs *st) {
+ int rv;
+ char *rvstr;
+ dSP;
+ DEBUGf("statfs begin\n");
+ ENTER;
+ SAVETMPS;
+ PUSHMARK(SP);
+ PUTBACK;
+ 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;
+ if(rv > 6)
+ rv = POPi;
+ else
+ rv = 0;
+ } else
+ if(rv > 1)
+ croak("inappropriate number of returned values from statfs");
+ else
+ if(rv)
+ rv = POPi;
+ else
+ rv = -ENOSYS;
+ FREETMPS;
+ LEAVE;
+ DEBUGf("statfs end\n");
+ return rv;
+}
+
struct fuse_operations _available_ops = {
getattr: _PLfuse_getattr,
_PLfuse_readlink,
_PLfuse_utime,
_PLfuse_open,
_PLfuse_read,
- _PLfuse_write
+ _PLfuse_write,
+ _PLfuse_statfs
};
MODULE = Fuse PACKAGE = Fuse
void
perl_fuse_main(...)
PREINIT:
- struct fuse_operations fops = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
+ struct fuse_operations fops = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
int i, varnum = 0, threads, debug, argc;
char **argv;
STRLEN n_a;
STRLEN l;
INIT:
- if(items != 21) {
+ if(items != 22) {
fprintf(stderr,"Perl<->C inconsistency or internal error\n");
XSRETURN_UNDEF;
}
else
argc--;
- for(i=0;i<17;i++) {
+ for(i=0;i<18;i++) {
SV *var = ST(i+4);
if((var != &PL_sv_undef) && SvROK(var)) {
if(SvTYPE(SvRV(var)) == SVt_PVCV) {
return substr($files{$file}{cont},$off,$buf);
}
+sub e_statfs { return 255, 1, 1, 1, 1, 2 }
+
# If you run the script directly, it will run fusermount, which will in turn
# re-run this script. Hence the funky semantics.
my ($mountpoint) = "";
getattr=>\&e_getattr,
getdir=>\&e_getdir,
open=>\&e_open,
+ statfs=>\&e_statfs,
#read=>\&e_read,
#debug=>1, threaded=>0
);