[haiku-development] Re: bfs_fuse: added statfs and added unmount

  • From: Jens Arm <Jens.Arm@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Thu, 23 Jul 2009 10:22:38 +0200

Hi


Little cleanup to my previous patch


cu
      Jens



> Hi Haiku-Team
> 
> 
> I have looked some more into the bfs_fuse:
> 
> 1. If you unmount the mounted FS with "fusermount -u" the BFS only get synced 
> in fuse_destroy
>    and not unmounted. I have added the umount code after fuse_main.
>    I hope this is correct.
> 
> 2. I have added statfs and it gives me a working df.
> 
> I have attached a patch against the current svn.
> 
> Please review the marked TODOs and specially the return values of the new 
> added code.
> 
> cu
>       Jens
> 
Index: fuse.cpp
===================================================================
--- fuse.cpp    (Revision 31707)
+++ fuse.cpp    (Arbeitskopie)
@@ -346,13 +346,46 @@
        _kern_sync();
 }
 
+static fssh_dev_t
+get_volume_id()
+{
+       struct fssh_stat st;
+       fssh_status_t error = _kern_read_stat(-1, kMountPoint, false, &st, 
sizeof(st));
+       if (error != FSSH_B_OK) {
+               return error;
+       }
+       return st.fssh_st_dev;
+}
 
+static int
+fuse_statfs(const char *path __attribute__((unused)), struct statvfs *sfs)
+{
+       PRINTD("##statfs\n");
+
+    fssh_dev_t volumeID = get_volume_id();
+    if (volumeID < 0) {
+               // TODO: what must I return?
+               return 1;
+       }
+
+    fssh_fs_info info;
+    fssh_status_t status = _kern_read_fs_info(volumeID, &info);
+    if (status != FSSH_B_OK) {
+               // TODO: what I have to return here?
+               return 1;
+       }
+
+       sfs->f_bsize = sfs->f_frsize = info.block_size;
+       sfs->f_blocks = info.total_blocks;
+       sfs->f_bavail = sfs->f_bfree = info.free_blocks;
+
+       return 0;
+}
+
 //} // extern "C" {
 
-
 struct fuse_operations fuse_cmds;
 
-
 static void
 initialiseFuseOps(struct fuse_operations* fuse_cmds)
 {
@@ -374,7 +407,7 @@
        fuse_cmds->open         = fuse_open;
        fuse_cmds->read         = fuse_read;
        fuse_cmds->write        = fuse_write;
-       fuse_cmds->statfs       = NULL;
+       fuse_cmds->statfs       = fuse_statfs;
        fuse_cmds->release      = NULL;
        fuse_cmds->fsync        = NULL;
        fuse_cmds->destroy      = fuse_destroy;
@@ -396,7 +429,19 @@
        argv[2] = (const char*)"-d";
        argv[3] = (const char*)"-s";
        initialiseFuseOps(&fuse_cmds);
-       return fuse_main(4, (char**)argv, &fuse_cmds, NULL);
+       
+       int ret =  fuse_main(4, (char**)argv, &fuse_cmds, NULL);
+
+       // TODO: can someone of the Haiku-Team check, if this is correct or 
must go into fuse_destroy:
+       _kern_setcwd(-1, "/");  // avoid a "busy" vnode
+    fssh_status_t error = _kern_unmount(kMountPoint, 0);
+    if (error != FSSH_B_OK) {
+       fprintf(stderr, "Error: Unmounting FS failed: %s\n",
+               fssh_strerror(error));
+        return 1;
+    }
+
+       return ret;
 }
 
 

Other related posts: