Simplify and fix FreeBSD fsname handling
authorNikolaus Rath <Nikolaus@rath.org>
Thu, 3 Aug 2017 15:19:22 +0000 (17:19 +0200)
committerNikolaus Rath <Nikolaus@rath.org>
Thu, 3 Aug 2017 15:21:06 +0000 (17:21 +0200)
This should simplify the code a lot. It also corrects a bug in
that the (former) add_default_fsname() function actually set
the -osubtype option.

include/fuse_lowlevel.h
lib/helper.c

index f3568048417c8fd0e3b36620683b9d608181e464..8e036f5b8e029a4b3f4a74747b18d2730d96dccc 100644 (file)
@@ -1727,11 +1727,7 @@ struct fuse_cmdline_opts {
        int singlethread;
        int foreground;
        int debug;
-#ifdef __FreeBSD__
-       int fsname;
-#else
        int nodefault_subtype;
-#endif
        char *mountpoint;
        int show_version;
        int show_help;
index c562c434a26eeca99408159258bdfbf482c9ef61..9abc6dda41110a119f90931d9a06891e60a21691 100644 (file)
@@ -41,14 +41,10 @@ static const struct fuse_opt fuse_helper_opts[] = {
        FUSE_OPT_KEY("debug",           FUSE_OPT_KEY_KEEP),
        FUSE_HELPER_OPT("-f",           foreground),
        FUSE_HELPER_OPT("-s",           singlethread),
-#ifdef __FreeBSD__
-       FUSE_HELPER_OPT("fsname=",      fsname),
-#else
        FUSE_HELPER_OPT("fsname=",      nodefault_subtype),
-       FUSE_HELPER_OPT("subtype=",     nodefault_subtype),
-#endif
        FUSE_OPT_KEY("fsname=",         FUSE_OPT_KEY_KEEP),
 #ifndef __FreeBSD__
+       FUSE_HELPER_OPT("subtype=",     nodefault_subtype),
        FUSE_OPT_KEY("subtype=",        FUSE_OPT_KEY_KEEP),
 #endif
        FUSE_HELPER_OPT("clone_fd",     clone_fd),
@@ -167,43 +163,31 @@ static int fuse_helper_opt_proc(void *data, const char *arg, int key,
        }
 }
 
-#ifdef __FreeBSD__
-static int add_default_fsname(const char *progname, struct fuse_args *args)
-#else
+/* Under FreeBSD, there is no subtype option so this
+   function actually sets the fsname */
 static int add_default_subtype(const char *progname, struct fuse_args *args)
-#endif
 {
        int res;
-#ifdef __FreeBSD__
-       char *fsname_opt;
-#else
        char *subtype_opt;
-#endif
+
        const char *basename = strrchr(progname, '/');
        if (basename == NULL)
                basename = progname;
        else if (basename[1] != '\0')
                basename++;
 
-#ifdef __FreeBSD__
-       fsname_opt = (char *) malloc(strlen(basename) + 64);
-       if (fsname_opt == NULL) {
-#else
        subtype_opt = (char *) malloc(strlen(basename) + 64);
        if (subtype_opt == NULL) {
-#endif
                fprintf(stderr, "fuse: memory allocation failed\n");
                return -1;
        }
 #ifdef __FreeBSD__
-       sprintf(fsname_opt, "-osubtype=%s", basename);
-       res = fuse_opt_add_arg(args, fsname_opt);
-       free(fsname_opt);
+       sprintf(subtype_opt, "-ofsname=%s", basename);
 #else
        sprintf(subtype_opt, "-osubtype=%s", basename);
+#endif
        res = fuse_opt_add_arg(args, subtype_opt);
        free(subtype_opt);
-#endif
        return res;
 }
 
@@ -215,15 +199,12 @@ int fuse_parse_cmdline(struct fuse_args *args,
                           fuse_helper_opt_proc) == -1)
                return -1;
 
-       /* If neither -o subtype nor -o fsname are specified,
-          set subtype to program's basename */
-#ifdef __FreeBSD__
-       if (!opts->fsname)
-               if (add_default_fsname(args->argv[0], args) == -1)
-#else
+       /* *Linux*: if neither -o subtype nor -o fsname are specified,
+          set subtype to program's basename.
+          *FreeBSD*: if fsname is not specified, set to program's
+          basename. */
        if (!opts->nodefault_subtype)
                if (add_default_subtype(args->argv[0], args) == -1)
-#endif
                        return -1;
 
        return 0;