zfs: get: only accept whole column for -o, not col[=whatever]
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #12996
This commit is contained in:
parent
c79787845d
commit
7c17e82cbe
|
@ -2038,11 +2038,17 @@ zfs_do_get(int argc, char **argv)
|
|||
* the structure to give us a blank slate.
|
||||
*/
|
||||
memset(&cb.cb_columns, 0, sizeof (cb.cb_columns));
|
||||
|
||||
i = 0;
|
||||
while (*optarg != '\0') {
|
||||
static char *col_subopts[] =
|
||||
{ "name", "property", "value", "received",
|
||||
"source", "all", NULL };
|
||||
for (char *tok; (tok = strsep(&optarg, ",")); ) {
|
||||
static const char *const col_subopts[] =
|
||||
{ "name", "property", "value",
|
||||
"received", "source", "all" };
|
||||
static const zfs_get_column_t col_subopt_col[] =
|
||||
{ GET_COL_NAME, GET_COL_PROPERTY, GET_COL_VALUE,
|
||||
GET_COL_RECVD, GET_COL_SOURCE };
|
||||
static const int col_subopt_flags[] =
|
||||
{ 0, 0, 0, ZFS_ITER_RECVD_PROPS, 0 };
|
||||
|
||||
if (i == ZFS_GET_NCOLS) {
|
||||
(void) fprintf(stderr, gettext("too "
|
||||
|
@ -2051,25 +2057,16 @@ zfs_do_get(int argc, char **argv)
|
|||
usage(B_FALSE);
|
||||
}
|
||||
|
||||
switch (getsubopt(&optarg, col_subopts,
|
||||
&value)) {
|
||||
case 0:
|
||||
cb.cb_columns[i++] = GET_COL_NAME;
|
||||
break;
|
||||
case 1:
|
||||
cb.cb_columns[i++] = GET_COL_PROPERTY;
|
||||
break;
|
||||
case 2:
|
||||
cb.cb_columns[i++] = GET_COL_VALUE;
|
||||
break;
|
||||
case 3:
|
||||
cb.cb_columns[i++] = GET_COL_RECVD;
|
||||
flags |= ZFS_ITER_RECVD_PROPS;
|
||||
break;
|
||||
case 4:
|
||||
cb.cb_columns[i++] = GET_COL_SOURCE;
|
||||
break;
|
||||
case 5:
|
||||
for (c = 0; c < ARRAY_SIZE(col_subopts); ++c)
|
||||
if (strcmp(tok, col_subopts[c]) == 0)
|
||||
goto found;
|
||||
|
||||
(void) fprintf(stderr,
|
||||
gettext("invalid column name '%s'\n"), tok);
|
||||
usage(B_FALSE);
|
||||
|
||||
found:
|
||||
if (c >= 5) {
|
||||
if (i > 0) {
|
||||
(void) fprintf(stderr,
|
||||
gettext("\"all\" conflicts "
|
||||
|
@ -2077,19 +2074,14 @@ zfs_do_get(int argc, char **argv)
|
|||
"given to -o option\n"));
|
||||
usage(B_FALSE);
|
||||
}
|
||||
cb.cb_columns[0] = GET_COL_NAME;
|
||||
cb.cb_columns[1] = GET_COL_PROPERTY;
|
||||
cb.cb_columns[2] = GET_COL_VALUE;
|
||||
cb.cb_columns[3] = GET_COL_RECVD;
|
||||
cb.cb_columns[4] = GET_COL_SOURCE;
|
||||
|
||||
memcpy(cb.cb_columns, col_subopt_col,
|
||||
sizeof (col_subopt_col));
|
||||
flags |= ZFS_ITER_RECVD_PROPS;
|
||||
i = ZFS_GET_NCOLS;
|
||||
break;
|
||||
default:
|
||||
(void) fprintf(stderr,
|
||||
gettext("invalid column name "
|
||||
"'%s'\n"), value);
|
||||
usage(B_FALSE);
|
||||
} else {
|
||||
cb.cb_columns[i++] = col_subopt_col[c];
|
||||
flags |= col_subopt_flags[c];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue