summaryrefslogtreecommitdiff
path: root/cmds-property.c
diff options
context:
space:
mode:
authorSatoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>2016-03-16 11:11:07 +0900
committerDavid Sterba <dsterba@suse.com>2016-03-16 10:19:42 +0100
commitc742debab11fb01b5f14743f06485c5f773655bc (patch)
tree519481a4a9c38b6ebdc941f0ac31a465ad3f43fd /cmds-property.c
parent4b80569b58352361509eb951c9c478353420ea09 (diff)
btrfs-progs: fix a regression that "property" with -t option doesn't work
"property" is considered as working without any options from the following commit. commit 176aeca9a148 ("btrfs-progs: add getopt stubs where needed") However, we can pass -t option to this command. * actual result ================================================== $ ./btrfs prop list -t f /btrfs btrfs property list: invalid option -- 't' usage: btrfs property list [-t <type>] <object> Lists available properties with their descriptions for the given object. Please see the help of 'btrfs property get' for a description of objects and object types. ================================================== * expected result ================================================== $ ./btrfs prop list -t f /btrfs label Set/get label of device. ================================================== Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-property.c')
-rw-r--r--cmds-property.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/cmds-property.c b/cmds-property.c
index 5b4da26a..eed5f4aa 100644
--- a/cmds-property.c
+++ b/cmds-property.c
@@ -294,10 +294,11 @@ out:
static void parse_args(int argc, char **argv,
const char * const *usage_str,
int *types, char **object,
- char **name, char **value)
+ char **name, char **value, int min_nonopt_args)
{
int ret;
char *type_str = NULL;
+ int max_nonopt_args = 0;
optind = 1;
while (1) {
@@ -314,6 +315,17 @@ static void parse_args(int argc, char **argv,
}
}
+ if (object)
+ max_nonopt_args++;
+ if (name)
+ max_nonopt_args++;
+ if (value)
+ max_nonopt_args++;
+
+ if (check_argc_min(argc - optind, min_nonopt_args) ||
+ check_argc_max(argc - optind, max_nonopt_args))
+ usage(usage_str);
+
*types = 0;
if (type_str) {
if (!strcmp(type_str, "s") || !strcmp(type_str, "subvol")) {
@@ -379,13 +391,8 @@ static int cmd_property_get(int argc, char **argv)
char *name = NULL;
int types = 0;
- clean_args_no_options(argc, argv, cmd_property_get_usage);
-
- if (check_argc_min(argc, 2) || check_argc_max(argc, 5))
- usage(cmd_property_get_usage);
-
parse_args(argc, argv, cmd_property_get_usage, &types, &object, &name,
- NULL);
+ NULL, 1);
if (!object) {
error("invalid arguments");
usage(cmd_property_get_usage);
@@ -415,13 +422,8 @@ static int cmd_property_set(int argc, char **argv)
char *value = NULL;
int types = 0;
- clean_args_no_options(argc, argv, cmd_property_set_usage);
-
- if (check_argc_min(argc, 4) || check_argc_max(argc, 6))
- usage(cmd_property_set_usage);
-
parse_args(argc, argv, cmd_property_set_usage, &types,
- &object, &name, &value);
+ &object, &name, &value, 3);
if (!object || !name || !value) {
error("invalid arguments");
usage(cmd_property_set_usage);
@@ -446,13 +448,8 @@ static int cmd_property_list(int argc, char **argv)
char *object = NULL;
int types = 0;
- clean_args_no_options(argc, argv, cmd_property_list_usage);
-
- if (check_argc_min(argc, 2) || check_argc_max(argc, 4))
- usage(cmd_property_list_usage);
-
parse_args(argc, argv, cmd_property_list_usage,
- &types, &object, NULL, NULL);
+ &types, &object, NULL, NULL, 1);
if (!object) {
error("invalid arguments");
usage(cmd_property_list_usage);