fix
authorMiklos Szeredi <miklos@szeredi.hu>
Sat, 7 Jan 2006 10:14:34 +0000 (10:14 +0000)
committerMiklos Szeredi <miklos@szeredi.hu>
Sat, 7 Jan 2006 10:14:34 +0000 (10:14 +0000)
ChangeLog
lib/fuse.c
lib/fuse_lowlevel.c
lib/helper.c
lib/mount.c
util/fusermount.c

index 89610fcc34cddb95d2b9dfb1770825e400691a31..a82a13946fa2d8611575017c0024493c60b25121 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2006-01-07  Miklos Szeredi <miklos@szeredi.hu>
+
+       * Improved help reporting and added version reporting to library
+
 2006-01-06  Miklos Szeredi <miklos@szeredi.hu>
 
        * Change working directory to "/" even if running in the
index d68ca5da4628f669aa226fac233cef3d53b4cb86..7d66a7d689b6510f5e34432dc20fa84bf8165488 100644 (file)
@@ -1806,11 +1806,18 @@ void fuse_set_getcontext_func(struct fuse_context *(*func)(void))
     fuse_getcontext = func;
 }
 
+enum {
+    KEY_HELP,
+    KEY_KEEP
+};
+
 #define FUSE_LIB_OPT(t, p, v) { t, offsetof(struct fuse_config, p), v }
 
 static const struct fuse_opt fuse_lib_opts[] = {
-    FUSE_OPT_KEY("debug", 0),
-    FUSE_OPT_KEY("-d", 0),
+    FUSE_OPT_KEY("-h",                    KEY_HELP),
+    FUSE_OPT_KEY("--help",                KEY_HELP),
+    FUSE_OPT_KEY("debug",                 KEY_KEEP),
+    FUSE_OPT_KEY("-d",                    KEY_KEEP),
     FUSE_LIB_OPT("debug",                 debug, 1),
     FUSE_LIB_OPT("-d",                    debug, 1),
     FUSE_LIB_OPT("hard_remove",           hard_remove, 1),
@@ -1830,6 +1837,35 @@ static const struct fuse_opt fuse_lib_opts[] = {
     FUSE_OPT_END
 };
 
+static void fuse_lib_help(void)
+{
+    fprintf(stderr,
+            "    -o hard_remove         immediate removal (don't hide files)\n"
+            "    -o use_ino             let filesystem set inode numbers\n"
+            "    -o readdir_ino         try to fill in d_ino in readdir\n"
+            "    -o direct_io           use direct I/O\n"
+            "    -o kernel_cache        cache files in kernel\n"
+            "    -o umask=M             set file permissions (octal)\n"
+            "    -o uid=N               set file owner\n"
+            "    -o gid=N               set file group\n"
+            "    -o entry_timeout=T     cache timeout for names (1.0s)\n"
+            "    -o negative_timeout=T  cache timeout for deleted names (0.0s)\n"
+            "    -o attr_timeout=T      cache timeout for attributes (1.0s)\n"
+            "\n");
+}
+
+static int fuse_lib_opt_proc(void *data, const char *arg, int key,
+                             struct fuse_args *outargs)
+{
+    (void) data; (void) arg; (void) outargs;
+
+    if (key == KEY_HELP)
+        fuse_lib_help();
+
+    return 1;
+}
+
+
 int fuse_is_lib_option(const char *opt)
 {
     return fuse_lowlevel_is_lib_option(opt) ||
@@ -1859,7 +1895,7 @@ struct fuse *fuse_new_common(int fd, struct fuse_args *args,
     f->conf.attr_timeout = 1.0;
     f->conf.negative_timeout = 0.0;
 
-    if (fuse_opt_parse(args, &f->conf, fuse_lib_opts, NULL) == -1)
+    if (fuse_opt_parse(args, &f->conf, fuse_lib_opts, fuse_lib_opt_proc) == -1)
             goto out_free;
 
 #ifdef __FreeBSD__
index d1b4b362c965487a7c86f7b6737a5729f4bc73a1..2018c94dca395f1024dfdf1bc05b120eae7a407d 100644 (file)
@@ -893,20 +893,45 @@ static void fuse_ll_process(void *data, const char *buf, size_t len,
     }
 }
 
+enum {
+    KEY_HELP,
+    KEY_VERSION,
+};
+
 static struct fuse_opt fuse_ll_opts[] = {
     { "debug", offsetof(struct fuse_ll, debug), 1 },
     { "-d", offsetof(struct fuse_ll, debug), 1 },
     { "allow_root", offsetof(struct fuse_ll, allow_root), 1 },
+    FUSE_OPT_KEY("-h", KEY_HELP),
+    FUSE_OPT_KEY("--help", KEY_HELP),
+    FUSE_OPT_KEY("-V", KEY_VERSION),
+    FUSE_OPT_KEY("--version", KEY_VERSION),
     FUSE_OPT_END
 };
 
+static void fuse_ll_version(void)
+{
+    fprintf(stderr, "using FUSE kernel interface version %i.%i\n",
+            FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION);
+}
+
 static int fuse_ll_opt_proc(void *data, const char *arg, int key,
                             struct fuse_args *outargs)
 {
-    (void) data;
-    (void) key;
-    (void) outargs;
-    fprintf(stderr, "fuse: unknown option `%s'\n", arg);
+    (void) data; (void) outargs;
+    
+    switch (key) {
+    case KEY_HELP:
+        break;
+        
+    case KEY_VERSION:
+        fuse_ll_version();
+        break;
+
+    default:
+        fprintf(stderr, "fuse: unknown option `%s'\n", arg);
+    }
+    
     return -1;
 }
 
index 0387dc784f3f1cb11de06271ad034a6e65b748a9..b7f77be91f7aa2cde0bb50a702940a580570d8c2 100644 (file)
@@ -6,6 +6,7 @@
     See the file COPYING.LIB.
 */
 
+#include "config.h"
 #include "fuse_i.h"
 #include "fuse_opt.h"
 #include "fuse_lowlevel.h"
 #include <string.h>
 #include <limits.h>
 
-static void usage(const char *progname)
-{
-    if (progname)
-        fprintf(stderr,
-                "usage: %s mountpoint [FUSE options]\n\n", progname);
-
-    fprintf(stderr,
-            "FUSE options:\n"
-            "    -d                     enable debug output (implies -f)\n"
-            "    -f                     foreground operation\n"
-            "    -s                     disable multi-threaded operation\n"
-            "    -r                     mount read only (equivalent to '-o ro')\n"
-            "    -o opt,[opt...]        mount options\n"
-            "    -h                     print help\n"
-            "\n"
-            "Mount options:\n"
-            "    default_permissions    enable permission checking\n"
-            "    allow_other            allow access to other users\n"
-            "    allow_root             allow access to root\n"
-            "    kernel_cache           cache files in kernel\n"
-            "    large_read             issue large read requests (2.4 only)\n"
-            "    direct_io              use direct I/O\n"
-            "    max_read=N             set maximum size of read requests\n"
-            "    hard_remove            immediate removal (don't hide files)\n"
-            "    debug                  enable debug output\n"
-            "    fsname=NAME            set filesystem name in mtab\n"
-            "    use_ino                let filesystem set inode numbers\n"
-            "    readdir_ino            try to fill in d_ino in readdir\n"
-            "    nonempty               allow mounts over non-empty file/dir\n"
-            "    umask=M                set file permissions (octal)\n"
-            "    uid=N                  set file owner\n"
-            "    gid=N                  set file group\n"
-            );
-}
-
 enum  {
     KEY_HELP,
     KEY_HELP_NOHEADER,
+    KEY_VERSION,
     KEY_KEEP,
 };
 
@@ -70,18 +37,48 @@ struct helper_opts {
 static const struct fuse_opt fuse_helper_opts[] = {
     FUSE_HELPER_OPT("-d",          foreground),
     FUSE_HELPER_OPT("debug",       foreground),
-    FUSE_HELPER_OPT("-f",         foreground),
-    FUSE_HELPER_OPT("-s",         singlethread),
+    FUSE_HELPER_OPT("-f",          foreground),
+    FUSE_HELPER_OPT("-s",          singlethread),
     FUSE_HELPER_OPT("fsname=",     fsname),
 
     FUSE_OPT_KEY("-h",          KEY_HELP),
     FUSE_OPT_KEY("--help",      KEY_HELP),
     FUSE_OPT_KEY("-ho",         KEY_HELP_NOHEADER),
+    FUSE_OPT_KEY("-V",          KEY_VERSION),
+    FUSE_OPT_KEY("--version",   KEY_VERSION),
     FUSE_OPT_KEY("-d",          KEY_KEEP),
     FUSE_OPT_KEY("debug",       KEY_KEEP),
     FUSE_OPT_END
 };
 
+static void usage(const char *progname)
+{
+    fprintf(stderr,
+            "usage: %s mountpoint [options]\n\n", progname);
+    fprintf(stderr,
+            "general options:\n"
+            "    -o opt,[opt...]        mount options\n"
+            "    -h   --help            print help\n"
+            "    -V   --version         print version\n"
+            "\n");
+}
+
+static void helper_help(void)
+{
+    fprintf(stderr,
+            "FUSE options:\n"
+            "    -d   -o debug          enable debug output (implies -f)\n"
+            "    -f                     foreground operation\n"
+            "    -s                     disable multi-threaded operation\n"
+            "\n"
+            );
+}
+
+static void helper_version(void)
+{
+    fprintf(stderr, "FUSE library version: %s\n", PACKAGE_VERSION);
+}
+
 static int fuse_helper_opt_proc(void *data, const char *arg, int key,
                                 struct fuse_args *outargs)
 {
@@ -89,9 +86,16 @@ static int fuse_helper_opt_proc(void *data, const char *arg, int key,
 
     switch (key) {
     case KEY_HELP:
+        usage(outargs->argv[0]);
+        /* fall through */
+
     case KEY_HELP_NOHEADER:
-        usage(key == KEY_HELP ? outargs->argv[0] : NULL);
-        exit(1);
+        helper_help();
+        return fuse_opt_add_arg(outargs, "-h");
+
+    case KEY_VERSION:
+        helper_version();
+        return 1;
 
     case FUSE_OPT_KEY_NONOPT:
         if (!hopts->mountpoint)
index b53889d96e10c7b923ef8fa541925830e5ab4d24..91d96f48db0e3d4d9dcd6f10ffc48dffa4d8815a 100644 (file)
@@ -27,11 +27,14 @@ enum {
     KEY_KERN,
     KEY_ALLOW_ROOT,
     KEY_RO,
+    KEY_HELP,
+    KEY_VERSION,
 };
 
 struct mount_opts {
     int allow_other;
     int allow_root;
+    int ishelp;
     char *kernel_opts;
 };
 
@@ -58,9 +61,32 @@ static const struct fuse_opt fuse_mount_opts[] = {
     FUSE_OPT_KEY("sync",                KEY_KERN),
     FUSE_OPT_KEY("atime",               KEY_KERN),
     FUSE_OPT_KEY("noatime",             KEY_KERN),
+    FUSE_OPT_KEY("-h",                  KEY_HELP),
+    FUSE_OPT_KEY("--help",              KEY_HELP),
+    FUSE_OPT_KEY("-V",                  KEY_VERSION),
+    FUSE_OPT_KEY("--version",           KEY_VERSION),
     FUSE_OPT_END
 };
 
+static void mount_help(void)
+{
+    fprintf(stderr,
+            "    -o allow_other         allow access to other users\n"
+            "    -o allow_root          allow access to root\n"
+            "    -o nonempty            allow mounts over non-empty file/dir\n"
+            "    -o default_permissions enable permission checking by kernel\n"
+            "    -o fsname=NAME         set filesystem name\n"
+            "    -o large_read          issue large read requests (2.4 only)\n"
+            "    -o max_read=N          set maximum size of read requests\n"
+            "\n"
+            );
+}
+
+static void mount_version(void)
+{
+    system(FUSERMOUNT_PROG " --version");
+}
+
 static int fuse_mount_opt_proc(void *data, const char *arg, int key,
                                struct fuse_args *outargs)
 {
@@ -79,6 +105,16 @@ static int fuse_mount_opt_proc(void *data, const char *arg, int key,
 
     case KEY_KERN:
         return fuse_opt_add_opt(&mo->kernel_opts, arg);
+
+    case KEY_HELP:
+        mount_help();
+        mo->ishelp = 1;
+        break;
+
+    case KEY_VERSION:
+        mount_version();
+        mo->ishelp = 1;
+        break;
     }
     return 1;
 }
@@ -133,6 +169,9 @@ void fuse_unmount(const char *mountpoint)
     const char *mountprog = FUSERMOUNT_PROG;
     int pid;
 
+    if (!mountpoint)
+        return;
+
 #ifdef HAVE_FORK
     pid = fork();
 #else
@@ -235,6 +274,8 @@ int fuse_mount(const char *mountpoint, struct fuse_args *args)
         fprintf(stderr, "fuse: 'allow_other' and 'allow_root' options are mutually exclusive\n");
         goto out;
     }
+    if (mo.ishelp)
+        return 0;
 
     res = fuse_mount_compat22(mountpoint, mo.kernel_opts);
  out:
index 63a6068ba69226dd313a9cca8a4c9eea95e82592..abe78b91ae1e6bdd4db990fb1d5c46e3f063ef16 100644 (file)
@@ -1018,7 +1018,7 @@ static void usage(void)
             "%s: [options] mountpoint\n"
             "Options:\n"
             " -h                print help\n"
-            " -v                print version\n"
+            " -V                print version\n"
             " -o opt[,opt...]   mount options\n"
             " -u                unmount\n"
             " -q                quiet\n"
@@ -1029,7 +1029,7 @@ static void usage(void)
 
 static void show_version(void)
 {
-    printf("%s\n", PACKAGE_STRING);
+    printf("fusermount version: %s\n", PACKAGE_VERSION);
     exit(0);
 }
 
@@ -1052,7 +1052,7 @@ int main(int argc, char *argv[])
         {"lazy",    no_argument, NULL, 'z'},
         {"quiet",   no_argument, NULL, 'q'},
         {"help",    no_argument, NULL, 'h'},
-        {"version", no_argument, NULL, 'v'},
+        {"version", no_argument, NULL, 'V'},
         {0, 0, 0, 0}};
 
     progname = strdup(argv[0]);
@@ -1061,13 +1061,13 @@ int main(int argc, char *argv[])
         exit(1);
     }
 
-    while ((ch = getopt_long(argc, argv, "hvo:uzq", long_opts, NULL)) != -1) {
+    while ((ch = getopt_long(argc, argv, "hVo:uzq", long_opts, NULL)) != -1) {
         switch (ch) {
         case 'h':
             usage();
             break;
 
-        case 'v':
+        case 'V':
             show_version();
             break;