aboutsummaryrefslogtreecommitdiffstats
path: root/lufis/lufis.c
diff options
context:
space:
mode:
authorMiklos Szeredi <miklos@szeredi.hu>2004-03-12 15:22:16 +0000
committerMiklos Szeredi <miklos@szeredi.hu>2004-03-12 15:22:16 +0000
commita5f7fb595deb74d31e703da8048d6e90c0ef2ae0 (patch)
treeb97cef416c9475596bdd9915a278a3e50e693030 /lufis/lufis.c
parentf79d899eb4e88c3a857b835ff82bb354c6448afd (diff)
downloadlibfuse-a5f7fb595deb74d31e703da8048d6e90c0ef2ae0.tar.gz
lufis 0.2
Diffstat (limited to 'lufis/lufis.c')
-rw-r--r--lufis/lufis.c66
1 files changed, 64 insertions, 2 deletions
diff --git a/lufis/lufis.c b/lufis/lufis.c
index 24b9a84..38bc60a 100644
--- a/lufis/lufis.c
+++ b/lufis/lufis.c
@@ -13,6 +13,15 @@
#include <unistd.h>
#include <errno.h>
+/* statfs extension for captivefs */
+struct lufs_sbattr_ { /* struct statfs64 */
+ unsigned long long sb_bytes;
+ unsigned long long sb_bytes_free;
+ unsigned long long sb_bytes_available;
+ unsigned long long sb_files;
+ unsigned long long sb_ffree;
+};
+
struct fs_operations {
void *(*init)(struct list_head*, struct dir_cache*, struct credentials*, void**);
void (*free)(void*);
@@ -33,6 +42,7 @@ struct fs_operations {
int (*link)(void*, char*, char*);
int (*symlink)(void*, char*, char*);
int (*setattr)(void*, char*, struct lufs_fattr*);
+ int (*statfs)(void*, struct lufs_sbattr_*);
};
static struct fs_operations lu_fops;
@@ -227,6 +237,8 @@ static int get_filesystem(const char *fs)
sprintf(buf, "%s_setattr", fs);
if(!(lu_fops.setattr = (int(*)(void*, char*, struct lufs_fattr*))dlsym(dlhandle, buf)))
ERROR(dlerror());
+ sprintf(buf, "%s_statfs", fs);
+ lu_fops.statfs = (int(*)(void*, struct lufs_sbattr_*))dlsym(dlhandle, buf);
lu_dlhandle = dlhandle;
free(buf);
@@ -497,7 +509,7 @@ static int lu_open(const char *path, int flags)
if(!lu_fops.open)
return -ENOSYS;
- if(lu_fops.open(lu_context, (char *) path, flags) < 0)
+ if(lu_fops.open(lu_context, (char *) path, flags & O_ACCMODE) < 0)
return -EPERM;
return 0;
@@ -539,6 +551,40 @@ static int lu_release(const char *path, int flags)
return 0;
}
+#if FUSE_MAJOR_VERSION < 2
+static int lu_statfs(struct fuse_statfs *stbuf)
+#else
+static int lu_statfs(const char *path, struct statfs *stbuf)
+#endif
+{
+ struct lufs_sbattr_ sbattr;
+
+ if(!lu_fops.statfs)
+ return -ENOSYS;
+
+ memset(&sbattr, 0, sizeof(sbattr));
+ if(lu_fops.statfs(lu_context, &sbattr) < 0)
+ return -EPERM;
+
+#if FUSE_MAJOR_VERSION < 2
+ stbuf->blocks = sbattr.sb_bytes / 512;
+ stbuf->blocks_free = sbattr.sb_bytes_available / 512;
+ stbuf->files = sbattr.sb_files;
+ stbuf->files_free = sbattr.sb_ffree;
+ stbuf->namelen = 255;
+#else
+ (void) path;
+ stbuf->f_bsize = 512;
+ stbuf->f_blocks = sbattr.sb_bytes / 512;
+ stbuf->f_bfree = sbattr.sb_bytes_free / 512;
+ stbuf->f_bavail = sbattr.sb_bytes_available / 512;
+ stbuf->f_files = sbattr.sb_files;
+ stbuf->f_ffree = sbattr.sb_ffree;
+ stbuf->f_namelen = 255;
+#endif
+ return 0;
+}
+
static int load_credentials(void)
{
static char buf[BUF_SIZE];
@@ -708,6 +754,13 @@ static int lufis_init(int *argcp, char **argvp[])
return 0;
}
+static void lufis_cleanup(void)
+{
+ if(lu_fops.umount)
+ lu_fops.umount(lu_context);
+ lu_fops.free(lu_context);
+}
+
static struct fuse_operations lu_oper = {
.getattr = lu_getattr,
.readlink = lu_readlink,
@@ -727,16 +780,25 @@ static struct fuse_operations lu_oper = {
.read = lu_read,
.write = lu_write,
.release = lu_release,
+ .statfs = lu_statfs,
};
int main(int argc, char *argv[])
{
int res;
+ int pid;
res = lufis_init(&argc, &argv);
if(res == -1)
exit(1);
- fuse_main(argc, argv, &lu_oper);
+ pid = fork();
+ if(pid == -1)
+ exit(1);
+ if(pid == 0) {
+ fuse_main(argc, argv, &lu_oper);
+ lufis_cleanup();
+ }
+
return 0;
}