Fix minor compiler warnings
[zfs.git] / cmd / zfs / zfs_main.c
index f694ee1..e2c39a8 100644 (file)
@@ -318,6 +318,7 @@ safe_malloc(size_t size)
        return (data);
 }
 
+#ifdef HAVE_ZPL
 static char *
 safe_strdup(char *str)
 {
@@ -328,6 +329,7 @@ safe_strdup(char *str)
 
        return (dupstr);
 }
+#endif /* HAVE_ZPL */
 
 /*
  * Callback routine that will print out information for each of
@@ -495,6 +497,7 @@ parse_depth(char *opt, int *flags)
 
 #define        PROGRESS_DELAY 2                /* seconds */
 
+#ifdef HAVE_ZPL
 static char *pt_reverse = "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b";
 static time_t pt_begin;
 static char *pt_header = NULL;
@@ -546,6 +549,8 @@ finish_progress(char *done)
        free(pt_header);
        pt_header = NULL;
 }
+#endif /* HAVE_ZPL */
+
 /*
  * zfs clone [-p] [-o prop=value] ... <snap> <fs | vol>
  *
@@ -626,6 +631,7 @@ zfs_do_clone(int argc, char **argv)
        ret = zfs_clone(zhp, argv[1], props);
 
        /* create the mountpoint if necessary */
+#ifdef HAVE_ZPL
        if (ret == 0) {
                zfs_handle_t *clone;
 
@@ -637,6 +643,7 @@ zfs_do_clone(int argc, char **argv)
                        zfs_close(clone);
                }
        }
+#endif /* HAVE_ZPL */
 
        zfs_close(zhp);
        nvlist_free(props);
@@ -671,7 +678,7 @@ zfs_do_create(int argc, char **argv)
 {
        zfs_type_t type = ZFS_TYPE_FILESYSTEM;
        zfs_handle_t *zhp = NULL;
-       uint64_t volsize;
+       uint64_t volsize = 0;
        int c;
        boolean_t noreserve = B_FALSE;
        boolean_t bflag = B_FALSE;
@@ -764,7 +771,7 @@ zfs_do_create(int argc, char **argv)
                zfs_prop_t resv_prop;
                char *strval;
 
-               if (p = strchr(argv[0], '/'))
+               if ((p = strchr(argv[0], '/')))
                        *p = '\0';
                zpool_handle = zpool_open(g_zfs, argv[0]);
                if (p != NULL)
@@ -824,6 +831,7 @@ zfs_do_create(int argc, char **argv)
         * verbose error message to let the user know that their filesystem was
         * in fact created, even if we failed to mount or share it.
         */
+#ifdef HAVE_ZPL
        if (canmount == ZFS_CANMOUNT_ON) {
                if (zfs_mount(zhp, NULL, 0) != 0) {
                        (void) fprintf(stderr, gettext("filesystem "
@@ -835,6 +843,7 @@ zfs_do_create(int argc, char **argv)
                        ret = 1;
                }
        }
+#endif /* HAVE_ZPL */
 
 error:
        if (zhp)
@@ -1682,7 +1691,7 @@ upgrade_set_callback(zfs_handle_t *zhp, void *data)
        if (version < cb->cb_version) {
                char verstr[16];
                (void) snprintf(verstr, sizeof (verstr),
-                   "%llu", cb->cb_version);
+                   "%llu", (u_longlong_t)cb->cb_version);
                if (cb->cb_lastfs[0] && !same_pool(zhp, cb->cb_lastfs)) {
                        /*
                         * If they did "zfs upgrade -a", then we could
@@ -1720,7 +1729,7 @@ zfs_do_upgrade(int argc, char **argv)
        boolean_t showversions = B_FALSE;
        int ret;
        upgrade_cbdata_t cb = { 0 };
-       char c;
+       signed char c;
        int flags = ZFS_ITER_ARGS_CAN_BE_PATHS;
 
        /* check options */
@@ -1789,11 +1798,11 @@ zfs_do_upgrade(int argc, char **argv)
                ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_FILESYSTEM,
                    NULL, NULL, 0, upgrade_set_callback, &cb);
                (void) printf(gettext("%llu filesystems upgraded\n"),
-                   cb.cb_numupgraded);
+                   (u_longlong_t)cb.cb_numupgraded);
                if (cb.cb_numsamegraded) {
                        (void) printf(gettext("%llu filesystems already at "
                            "this version\n"),
-                           cb.cb_numsamegraded);
+                           (u_longlong_t)cb.cb_numsamegraded);
                }
                if (cb.cb_numfailed != 0)
                        ret = 1;
@@ -1957,9 +1966,9 @@ print_header(zprop_list_t *pl)
                if (pl->pl_next == NULL && !right_justify)
                        (void) printf("%s", header);
                else if (right_justify)
-                       (void) printf("%*s", pl->pl_width, header);
+                       (void) printf("%*s", (int)pl->pl_width, header);
                else
-                       (void) printf("%-*s", pl->pl_width, header);
+                       (void) printf("%-*s", (int)pl->pl_width, header);
        }
 
        (void) printf("\n");
@@ -2331,6 +2340,7 @@ typedef struct rollback_cbdata {
  * 'cb_dependent' is set, then this is a dependent and we should report it
  * without checking the transaction group.
  */
+#ifdef HAVE_ZPL
 static int
 rollback_check(zfs_handle_t *zhp, void *data)
 {
@@ -2390,10 +2400,12 @@ rollback_check(zfs_handle_t *zhp, void *data)
        zfs_close(zhp);
        return (0);
 }
+#endif /* HAVE_ZPL */
 
 static int
 zfs_do_rollback(int argc, char **argv)
 {
+#ifdef HAVE_ZPL
        int ret;
        int c;
        boolean_t force = B_FALSE;
@@ -2475,6 +2487,9 @@ out:
                return (0);
        else
                return (1);
+#else
+       return ENOSYS;
+#endif /*HAVE_ZPL*/
 }
 
 /*
@@ -2550,7 +2565,7 @@ zfs_do_set(int argc, char **argv)
                usage(B_FALSE);
        }
 
-       ret = zfs_for_each(argc - 2, argv + 2, NULL,
+       ret = zfs_for_each(argc - 2, argv + 2, 0,
            ZFS_TYPE_DATASET, NULL, NULL, 0, set_callback, &cb);
 
        return (ret);
@@ -2567,7 +2582,7 @@ zfs_do_snapshot(int argc, char **argv)
 {
        boolean_t recursive = B_FALSE;
        int ret;
-       char c;
+       signed char c;
        nvlist_t *props;
 
        if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0)
@@ -2940,6 +2955,7 @@ zfs_do_release(int argc, char **argv)
 #define        SPINNER_TIME 3          /* seconds */
 #define        MOUNT_TIME 5            /* seconds */
 
+#ifdef HAVE_ZPL
 static int
 get_one_dataset(zfs_handle_t *zhp, void *data)
 {
@@ -3137,11 +3153,11 @@ share_mount_one(zfs_handle_t *zhp, int op, int flags, char *protocol,
                shared_nfs = zfs_is_shared_nfs(zhp, NULL);
                shared_smb = zfs_is_shared_smb(zhp, NULL);
 
-               if (shared_nfs && shared_smb ||
-                   (shared_nfs && strcmp(shareopts, "on") == 0 &&
-                   strcmp(smbshareopts, "off") == 0) ||
-                   (shared_smb && strcmp(smbshareopts, "on") == 0 &&
-                   strcmp(shareopts, "off") == 0)) {
+               if ((shared_nfs && shared_smb) ||
+                   ((shared_nfs && strcmp(shareopts, "on") == 0) &&
+                   (strcmp(smbshareopts, "off") == 0)) ||
+                   ((shared_smb && strcmp(smbshareopts, "on") == 0) &&
+                   (strcmp(shareopts, "off") == 0))) {
                        if (!explicit)
                                return (0);
 
@@ -3387,6 +3403,7 @@ share_mount(int op, int argc, char **argv)
 
        return (ret);
 }
+#endif  /* HAVE_ZPL */
 
 /*
  * zfs mount -a [nfs]
@@ -3397,7 +3414,11 @@ share_mount(int op, int argc, char **argv)
 static int
 zfs_do_mount(int argc, char **argv)
 {
+#ifdef HAVE_ZPL
        return (share_mount(OP_MOUNT, argc, argv));
+#else
+       return ENOSYS;
+#endif  /* HAVE_ZPL */
 }
 
 /*
@@ -3409,9 +3430,14 @@ zfs_do_mount(int argc, char **argv)
 static int
 zfs_do_share(int argc, char **argv)
 {
+#ifdef HAVE_ZPL
        return (share_mount(OP_SHARE, argc, argv));
+#else
+       return ENOSYS;
+#endif  /* HAVE_ZPL */
 }
 
+#ifdef HAVE_ZPL
 typedef struct unshare_unmount_node {
        zfs_handle_t    *un_zhp;
        char            *un_mountp;
@@ -3596,7 +3622,7 @@ unshare_unmount(int op, int argc, char **argv)
                 */
                struct mnttab entry;
                uu_avl_pool_t *pool;
-               uu_avl_t *tree;
+               uu_avl_t *tree = NULL;
                unshare_unmount_node_t *node;
                uu_avl_index_t idx;
                uu_avl_walk_t *walk;
@@ -3795,6 +3821,7 @@ unshare_unmount(int op, int argc, char **argv)
 
        return (ret);
 }
+#endif  /* HAVE_ZPL */
 
 /*
  * zfs unmount -a
@@ -3805,7 +3832,11 @@ unshare_unmount(int op, int argc, char **argv)
 static int
 zfs_do_unmount(int argc, char **argv)
 {
+#ifdef HAVE_ZPL
        return (unshare_unmount(OP_MOUNT, argc, argv));
+#else
+       return ENOSYS;
+#endif  /* HAVE_ZPL */
 }
 
 /*
@@ -3817,7 +3848,11 @@ zfs_do_unmount(int argc, char **argv)
 static int
 zfs_do_unshare(int argc, char **argv)
 {
+#ifdef HAVE_ZPL
        return (unshare_unmount(OP_SHARE, argc, argv));
+#else
+       return ENOSYS;
+#endif  /* HAVE_ZPL */
 }
 
 /* ARGSUSED */
@@ -3833,6 +3868,7 @@ zfs_do_python(int argc, char **argv)
  * Called when invoked as /etc/fs/zfs/mount.  Do the mount if the mountpoint is
  * 'legacy'.  Otherwise, complain that use should be using 'zfs mount'.
  */
+#ifdef HAVE_ZPL
 static int
 manual_mount(int argc, char **argv)
 {
@@ -3963,6 +3999,7 @@ manual_unmount(int argc, char **argv)
 
        return (unshare_unmount_path(OP_MOUNT, argv[0], flags, B_TRUE));
 }
+#endif /* HAVE_ZPL */
 
 static int
 find_command_idx(char *command, int *idx)
@@ -4035,7 +4072,7 @@ zfs_do_diff(int argc, char **argv)
        if (copy == NULL)
                usage(B_FALSE);
 
-       if (atp = strchr(copy, '@'))
+       if ((atp = strchr(copy, '@')))
                *atp = '\0';
 
        if ((zhp = zfs_open(g_zfs, copy, ZFS_TYPE_FILESYSTEM)) == NULL)
@@ -4060,8 +4097,10 @@ int
 main(int argc, char **argv)
 {
        int ret;
-       int i;
+       int i = 0;
+#ifdef HAVE_ZPL
        char *progname;
+#endif
        char *cmdname;
 
        (void) setlocale(LC_ALL, "");
@@ -4069,23 +4108,13 @@ main(int argc, char **argv)
 
        opterr = 0;
 
-       if ((g_zfs = libzfs_init()) == NULL) {
-               (void) fprintf(stderr, gettext("internal error: failed to "
-                   "initialize ZFS library\n"));
-               return (1);
-       }
-
-       zpool_set_history_str("zfs", argc, argv, history_str);
-       verify(zpool_stage_history(g_zfs, history_str) == 0);
-
-       libzfs_print_on_error(g_zfs, B_TRUE);
-
        if ((mnttab_file = fopen(MNTTAB, "r")) == NULL) {
                (void) fprintf(stderr, gettext("internal error: unable to "
                    "open %s\n"), MNTTAB);
                return (1);
        }
 
+#ifdef HAVE_ZPL
        /*
         * This command also doubles as the /etc/fs mount and unmount program.
         * Determine if we should take this behavior based on argv[0].
@@ -4096,6 +4125,9 @@ main(int argc, char **argv)
        } else if (strcmp(progname, "umount") == 0) {
                ret = manual_unmount(argc, argv);
        } else {
+#else
+       {
+#endif /* HAVE_ZPL */
                /*
                 * Make sure the user has specified some command.
                 */
@@ -4121,9 +4153,18 @@ main(int argc, char **argv)
                /*
                 * Special case '-?'
                 */
-               if (strcmp(cmdname, "-?") == 0)
+               if ((strcmp(cmdname, "-?") == 0) ||
+                   (strcmp(cmdname, "--help") == 0))
                        usage(B_TRUE);
 
+               if ((g_zfs = libzfs_init()) == NULL)
+                       return (1);
+
+               zpool_set_history_str("zfs", argc, argv, history_str);
+               verify(zpool_stage_history(g_zfs, history_str) == 0);
+
+               libzfs_print_on_error(g_zfs, B_TRUE);
+
                /*
                 * Run the appropriate command.
                 */
@@ -4139,6 +4180,7 @@ main(int argc, char **argv)
                        (void) fprintf(stderr, gettext("unrecognized "
                            "command '%s'\n"), cmdname);
                        usage(B_FALSE);
+                       ret = 1;
                }
                libzfs_mnttab_cache(g_zfs, B_FALSE);
        }