fusermount changes
authorMiklos Szeredi <miklos@szeredi.hu>
Tue, 20 Nov 2001 19:12:28 +0000 (19:12 +0000)
committerMiklos Szeredi <miklos@szeredi.hu>
Tue, 20 Nov 2001 19:12:28 +0000 (19:12 +0000)
example/fusexmp.c
example/null.c
lib/fuse.c
util/fusermount.c

index 1f1f2a32ee5f069ad60e6144abd9f848d02a3d72..dc2a5690961f43c5ee01acabb122791a3f95edc8 100644 (file)
@@ -24,8 +24,6 @@
 #include <utime.h>
 #include <fcntl.h>
 
-static char *unmount_cmd;
-
 static int xmp_getattr(const char *path, struct stat *stbuf)
 {
     int res;
@@ -260,11 +258,14 @@ static struct fuse_operations xmp_oper = {
     write:     xmp_write,
 };
 
+static void cleanup()
+{
+    close(0);
+    system(getenv("FUSE_UNMOUNT_CMD"));
+}
 
 static void exit_handler()
 {
-    close(0);
-    system(unmount_cmd);    
     exit(0);
 }
 
@@ -299,19 +300,9 @@ int main(int argc, char *argv[])
     int multithreaded;
     struct fuse *fuse;
 
-    if(argc < 2) {
-        fprintf(stderr,
-                "usage: %s unmount_cmd [options] \n"
-                "Options:\n"
-                "    -d      enable debug output\n"
-                "    -s      disable multithreaded operation\n",
-                argv[0]);
-        exit(1);
-    }
-
     argctr = 1;
-    unmount_cmd = argv[argctr++];
 
+    atexit(cleanup);
     set_signal_handlers();
 
     flags = 0;
@@ -326,6 +317,17 @@ int main(int argc, char *argv[])
             multithreaded = 0;
             break;
 
+        case 'h':
+            fprintf(stderr,
+                    "usage: %s [options] \n"
+                    "Options:\n"
+                    "    -d      enable debug output\n"
+                    "    -s      disable multithreaded operation\n"
+                    "    -h      print help\n",
+                    argv[0]);
+            exit(1);
+            break;
+            
         default:
             fprintf(stderr, "invalid option: %s\n", argv[argctr]);
             exit(1);
index 379ba7a3d75bddd546a4f2e43cbeee17f111bbb3..c9816f135d18506fbc4569b2764ac0828f74fdd4 100644 (file)
@@ -17,8 +17,6 @@
 
 #define UNUSED __attribute__((unused))
 
-static char *unmount_cmd;
-
 static int null_getattr(const char *path, struct stat *stbuf)
 {
     if(strcmp(path, "/") != 0)
@@ -90,11 +88,14 @@ static struct fuse_operations null_oper = {
     write:     null_write,
 };
 
+static void cleanup()
+{
+    close(0);
+    system(getenv("FUSE_UNMOUNT_CMD"));
+}
 
 static void exit_handler()
 {
-    close(0);
-    system(unmount_cmd);    
     exit(0);
 }
 
@@ -129,19 +130,9 @@ int main(int argc, char *argv[])
     int multithreaded;
     struct fuse *fuse;
 
-    if(argc < 2) {
-        fprintf(stderr,
-                "usage: %s unmount_cmd [options] \n"
-                "Options:\n"
-                "    -d      enable debug output\n"
-                "    -s      disable multithreaded operation\n",
-                argv[0]);
-        exit(1);
-    }
-
     argctr = 1;
-    unmount_cmd = argv[argctr++];
 
+    atexit(cleanup);
     set_signal_handlers();
 
     flags = 0;
@@ -156,6 +147,17 @@ int main(int argc, char *argv[])
             multithreaded = 0;
             break;
 
+        case 'h':
+            fprintf(stderr,
+                    "usage: %s [options] \n"
+                    "Options:\n"
+                    "    -d      enable debug output\n"
+                    "    -s      disable multithreaded operation\n"
+                    "    -h      print help\n",
+                    argv[0]);
+            exit(1);
+            break;
+
         default:
             fprintf(stderr, "invalid option: %s\n", argv[argctr]);
             exit(1);
index b1b074903c18f903f065aa53793b26c98d2a633e..35a02ad61c8257df6f5101969a6708f070c5df6d 100644 (file)
@@ -783,6 +783,10 @@ void __fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd)
         do_lookup(f, in, (char *) inarg);
         break;
 
+    case FUSE_FORGET:
+        do_forget(f, in, (struct fuse_forget_in *) inarg);
+        break;
+
     case FUSE_GETATTR:
         do_getattr(f, in);
         break;
@@ -854,31 +858,20 @@ struct fuse_cmd *__fuse_read_cmd(struct fuse *f)
     cmd = (struct fuse_cmd *) malloc(sizeof(struct fuse_cmd));
     cmd->buf = (char *) malloc(FUSE_MAX_IN);
 
-    do {
-        res = read(f->fd, cmd->buf, FUSE_MAX_IN);
-        if(res == -1) {
-            perror("reading fuse device");
-            /* BAD... This will happen again */
-            free_cmd(cmd);
-            return NULL;
-        }
-        if((size_t) res < sizeof(struct fuse_in_header)) {
-            fprintf(stderr, "short read on fuse device\n");
-            /* Cannot happen */
-            free_cmd(cmd);
-            return NULL;
-        }
-        cmd->buflen = res;
-
-        /* FORGET is special: it can be done without calling filesystem
-           methods. */
-        in = (struct fuse_in_header *) cmd->buf;
-        if(in->opcode == FUSE_FORGET) {
-            void *inarg = cmd->buf + sizeof(struct fuse_in_header);
-            do_forget(f, in, (struct fuse_forget_in *) inarg);
-        }
-    } while(in->opcode == FUSE_FORGET);
-
+    res = read(f->fd, cmd->buf, FUSE_MAX_IN);
+    if(res == -1) {
+        perror("reading fuse device");
+        /* BAD... This will happen again */
+        free_cmd(cmd);
+        return NULL;
+    }
+    if((size_t) res < sizeof(struct fuse_in_header)) {
+        fprintf(stderr, "short read on fuse device\n");
+        /* Cannot happen */
+        free_cmd(cmd);
+        return NULL;
+    }
+    cmd->buflen = res;
     return cmd;
 }
 
@@ -898,6 +891,17 @@ struct fuse *fuse_new(int fd, int flags)
 {
     struct fuse *f;
     struct node *root;
+    char verstr[128];
+    char *realver = getenv("FUSE_KERNEL_VERSION");
+    
+    if(realver != NULL) {
+        sprintf(verstr, "%i", FUSE_KERNEL_VERSION);
+        if(strcmp(verstr, realver) != 0) {
+            fprintf(stderr,
+                    "Warning: FUSE version mismatch: using %s, kernel is %s\n",
+                    realver, verstr);
+        }
+    }
 
     f = (struct fuse *) calloc(1, sizeof(struct fuse));
 
index ac30c653a485f61b2224c160c8436a94b26f565f..0e256e5fb5f5acb8f5b0a8712ac16d155272a094 100644 (file)
  * NOTE: This program should be part of (or be called from) /bin/mount
  * 
  * Unless that is done, operations on /etc/mtab are not under lock, and so
- * data in it may be lost. (I will _not_ reimplement that locking, and
- * anyway that should be done in libc, if possible.  But probably it is
- * not).
- *
+ * data in this file may be lost. (I will _not_ reimplement that locking,
+ * and anyway that should be done in libc, if possible.  But probably it
+ * isn't).  
  */
 
 #include <stdio.h>
@@ -186,6 +185,10 @@ static int remove_mount(const char *mnt)
     return 0;
 }
 
+/* Until there is a nice interface for capabilities in _libc_, this will
+remain here.  I don't think it is fair to expect users to compile libcap
+for this program.  And anyway what's all this fuss about versioning the
+kernel interface?  It is quite good as is.  */
 #define _LINUX_CAPABILITY_VERSION  0x19980330
 
 typedef struct __user_cap_header_struct {
@@ -409,9 +412,9 @@ int main(int argc, char *argv[])
     int unmount = 0;
     char **userprog;
     int numargs;
-    char **newargv;
     char mypath[PATH_MAX];
     char *unmount_cmd;
+    char verstr[128];
 
     progname = argv[0];
     
@@ -494,15 +497,11 @@ int main(int argc, char *argv[])
 
     unmount_cmd = (char *) malloc(strlen(mypath) + strlen(mnt) + 64);
     sprintf(unmount_cmd, "%s -u %s", mypath, mnt);
+    setenv("FUSE_UNMOUNT_CMD", unmount_cmd, 1);
+    sprintf(verstr, "%i", FUSE_KERNEL_VERSION);
+    setenv("FUSE_KERNEL_VERSION", verstr, 1);
 
-    newargv = (char **) malloc(sizeof(char *) * (numargs + 2));
-    newargv[0] = userprog[0];
-    newargv[1] = unmount_cmd;
-    for(a = 1; a < numargs; a++)
-        newargv[a+1] = userprog[a];
-    newargv[numargs+1] = NULL;
-
-    execvp(userprog[0], newargv);
+    execvp(userprog[0], userprog);
     fprintf(stderr, "%s: failed to exec %s: %s\n", progname, userprog[0],
             strerror(errno));