Skip to content

Commit

Permalink
zfs: list: only accept whole type for -t, not tp[=whatever]
Browse files Browse the repository at this point in the history
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
  • Loading branch information
nabijaczleweli committed Jan 23, 2022
1 parent a5a9249 commit ad8ad29
Showing 1 changed file with 26 additions and 37 deletions.
63 changes: 26 additions & 37 deletions cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ usage_prop_cb(int prop, void *cb)
* that command. Otherwise, iterate over the entire command table and display
* a complete usage message.
*/
static void
static void __attribute__((noreturn))
usage(boolean_t requested)
{
int i;
Expand Down Expand Up @@ -3576,13 +3576,12 @@ static int
zfs_do_list(int argc, char **argv)
{
int c;
static char default_fields[] =
char default_fields[] =
"name,used,available,referenced,mountpoint";
int types = ZFS_TYPE_DATASET;
boolean_t types_specified = B_FALSE;
char *fields = NULL;
char *fields = default_fields;
list_cbdata_t cb = { 0 };
char *value;
int limit = 0;
int ret = 0;
zfs_sort_column_t *sortcol = NULL;
Expand Down Expand Up @@ -3627,36 +3626,29 @@ zfs_do_list(int argc, char **argv)
types = 0;
types_specified = B_TRUE;
flags &= ~ZFS_ITER_PROP_LISTSNAPS;
while (*optarg != '\0') {
static char *type_subopts[] = { "filesystem",
"volume", "snapshot", "snap", "bookmark",
"all", NULL };

switch (getsubopt(&optarg, type_subopts,
&value)) {
case 0:
types |= ZFS_TYPE_FILESYSTEM;
break;
case 1:
types |= ZFS_TYPE_VOLUME;
break;
case 2:
case 3:
types |= ZFS_TYPE_SNAPSHOT;
break;
case 4:
types |= ZFS_TYPE_BOOKMARK;
break;
case 5:
types = ZFS_TYPE_DATASET |
ZFS_TYPE_BOOKMARK;
break;
default:
(void) fprintf(stderr,
gettext("invalid type '%s'\n"),
value);
usage(B_FALSE);
}

for (char *tok; (tok = strsep(&optarg, ",")); ) {
static const char *const type_subopts[] = {
"filesystem", "volume",
"snapshot", "snap",
"bookmark",
"all" };
static const int type_types[] = {
ZFS_TYPE_FILESYSTEM, ZFS_TYPE_VOLUME,
ZFS_TYPE_SNAPSHOT, ZFS_TYPE_SNAPSHOT,
ZFS_TYPE_BOOKMARK,
ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK };

for (c = 0; c < ARRAY_SIZE(type_subopts); ++c)
if (strcmp(tok, type_subopts[c]) == 0) {
types |= type_types[c];
goto found3;
}

(void) fprintf(stderr,
gettext("invalid type '%s'\n"), tok);
usage(B_FALSE);
found3:;
}
break;
case ':':
Expand All @@ -3674,9 +3666,6 @@ zfs_do_list(int argc, char **argv)
argc -= optind;
argv += optind;

if (fields == NULL)
fields = default_fields;

/*
* If we are only going to list snapshot names and sort by name,
* then we can use faster version.
Expand Down

0 comments on commit ad8ad29

Please sign in to comment.