lufis 0.2
authorMiklos Szeredi <miklos@szeredi.hu>
Fri, 12 Mar 2004 15:22:16 +0000 (15:22 +0000)
committerMiklos Szeredi <miklos@szeredi.hu>
Fri, 12 Mar 2004 15:22:16 +0000 (15:22 +0000)
lufis/ChangeLog [new file with mode: 0644]
lufis/README
lufis/lufis.c
lufis/options.c

diff --git a/lufis/ChangeLog b/lufis/ChangeLog
new file mode 100644 (file)
index 0000000..238fc38
--- /dev/null
@@ -0,0 +1,4 @@
+2004-03-09  Miklos Szeredi <mszeredi@inf.bme.hu>
+
+       * Make it possible to mount captivefs filesystem
+
index bd648fa455dbf25857c2de7d7269ffbe182641b5..4e580233d857d8eaa05fcfb6ed0da5f69b4ea98f 100644 (file)
@@ -35,3 +35,16 @@ and
 
 For LUFS specific options (can only be specified in the first
 argument) see the README in the LUFS distribution
+
+
+Captivefs:
+
+from version 0.2 lufis supports mounting the captivefs.  Command line
+should be something like this:
+
+lufis "fs=captivefs,dir_cache_entries=0,image=/store/ntfs/ntfs.img,captive_options=--rw;--load-module=/var/lib/captive/ntoskrnl.exe;--filesystem=/var/lib/captive/ntfs.sys;--sandbox-server=/usr/sbin/captive-sandbox-server;" /mnt/ntfs -s
+
+It may work without the '-s' option, but this is untested.
+
+umounting should be done with 'umount' as root or 'fusermount -u' as
+non-root.
index 24b9a844d9186141b26cb7fea57c3fd516a2459b..38bc60ab82f2267b23544177829d01fe8ca0196f 100644 (file)
 #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;
 }
index 44f36630b42f97beb6752a5e2d0a2544fb2b5f80..b8b7b3a49f5916e1ed3dbf477f701b237ceb6ef0 100644 (file)
@@ -266,7 +266,7 @@ lu_opt_parse(struct list_head *conf, char *domain, char *opts){
        if(sep){
            TRACE("option with parameter");
 
-           if((strlen(sep + 1) >= MAX_LEN) || !(prop->value = malloc(strlen(sep + 1) + 1))){
+           if(!(prop->value = malloc(strlen(sep + 1) + 1))){
                WARN("out of mem!");
                free(prop->key);
                free(prop);