zfs: list: only accept whole type for -t, not tp[=whatever]

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #12996
This commit is contained in:
наб 2022-01-22 23:44:33 +01:00 committed by Brian Behlendorf
parent 539d16c35e
commit 40f09cb0f4

View File

@ -498,7 +498,7 @@ usage_prop_cb(int prop, void *cb)
* that command. Otherwise, iterate over the entire command table and display * that command. Otherwise, iterate over the entire command table and display
* a complete usage message. * a complete usage message.
*/ */
static void static _Noreturn void
usage(boolean_t requested) usage(boolean_t requested)
{ {
int i; int i;
@ -3551,13 +3551,12 @@ static int
zfs_do_list(int argc, char **argv) zfs_do_list(int argc, char **argv)
{ {
int c; int c;
static char default_fields[] = char default_fields[] =
"name,used,available,referenced,mountpoint"; "name,used,available,referenced,mountpoint";
int types = ZFS_TYPE_DATASET; int types = ZFS_TYPE_DATASET;
boolean_t types_specified = B_FALSE; boolean_t types_specified = B_FALSE;
char *fields = NULL; char *fields = default_fields;
list_cbdata_t cb = { 0 }; list_cbdata_t cb = { 0 };
char *value;
int limit = 0; int limit = 0;
int ret = 0; int ret = 0;
zfs_sort_column_t *sortcol = NULL; zfs_sort_column_t *sortcol = NULL;
@ -3602,36 +3601,29 @@ zfs_do_list(int argc, char **argv)
types = 0; types = 0;
types_specified = B_TRUE; types_specified = B_TRUE;
flags &= ~ZFS_ITER_PROP_LISTSNAPS; flags &= ~ZFS_ITER_PROP_LISTSNAPS;
while (*optarg != '\0') {
static char *type_subopts[] = { "filesystem",
"volume", "snapshot", "snap", "bookmark",
"all", NULL };
switch (getsubopt(&optarg, type_subopts, for (char *tok; (tok = strsep(&optarg, ",")); ) {
&value)) { static const char *const type_subopts[] = {
case 0: "filesystem", "volume",
types |= ZFS_TYPE_FILESYSTEM; "snapshot", "snap",
break; "bookmark",
case 1: "all" };
types |= ZFS_TYPE_VOLUME; static const int type_types[] = {
break; ZFS_TYPE_FILESYSTEM, ZFS_TYPE_VOLUME,
case 2: ZFS_TYPE_SNAPSHOT, ZFS_TYPE_SNAPSHOT,
case 3: ZFS_TYPE_BOOKMARK,
types |= ZFS_TYPE_SNAPSHOT; ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK };
break;
case 4: for (c = 0; c < ARRAY_SIZE(type_subopts); ++c)
types |= ZFS_TYPE_BOOKMARK; if (strcmp(tok, type_subopts[c]) == 0) {
break; types |= type_types[c];
case 5: goto found3;
types = ZFS_TYPE_DATASET | }
ZFS_TYPE_BOOKMARK;
break; (void) fprintf(stderr,
default: gettext("invalid type '%s'\n"), tok);
(void) fprintf(stderr, usage(B_FALSE);
gettext("invalid type '%s'\n"), found3:;
value);
usage(B_FALSE);
}
} }
break; break;
case ':': case ':':
@ -3649,9 +3641,6 @@ zfs_do_list(int argc, char **argv)
argc -= optind; argc -= optind;
argv += optind; argv += optind;
if (fields == NULL)
fields = default_fields;
/* /*
* If we are only going to list snapshot names and sort by name, * If we are only going to list snapshot names and sort by name,
* then we can use faster version. * then we can use faster version.