diff mbox

Fix broken 'device scan' arguments parsing

Message ID 1457486380-4051-1-git-send-email-yauhen.kharuzhy@zavadatar.com (mailing list archive)
State Accepted
Headers show

Commit Message

Yauhen Kharuzhy March 9, 2016, 1:19 a.m. UTC
commit 52179e4fea41e55f31c92cd033a0b53a5107b4f4 'btrfs-progs: unify argc
min/max checking' brokes 'btrfs device scan' command when no argument
was given. Fix this.

Signed-off-by: Yauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com>
---
 cmds-device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Satoru Takeuchi March 9, 2016, 8:24 a.m. UTC | #1
On 2016/03/09 10:19, Yauhen Kharuzhy wrote:
> commit 52179e4fea41e55f31c92cd033a0b53a5107b4f4 'btrfs-progs: unify argc
> min/max checking' brokes 'btrfs device scan' command when no argument
> was given. Fix this.
> 
> Signed-off-by: Yauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com>
> ---
>   cmds-device.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/cmds-device.c b/cmds-device.c
> index cb470af..94ffdc5 100644
> --- a/cmds-device.c
> +++ b/cmds-device.c
> @@ -273,7 +273,7 @@ static int cmd_device_scan(int argc, char **argv)
>   	if (all && check_argc_max(argc - optind, 1))

It's better to the above line as follows.

========
	if (all && check_argc_exact(argc - optind, 0))
========

>   		usage(cmd_device_scan_usage);
>   
> -	if (all || argc - optind == 1) {
> +	if (all || argc - optind == 0) {
>   		printf("Scanning for Btrfs filesystems\n");
>   		ret = btrfs_scan_lblkid();
>   		error_on(ret, "error %d while scanning", ret);
> 

Here is the test result.

* v4.4.1

======================
# ./btrfs device scan
Scanning for Btrfs filesystems
# ./btrfs device scan -d
Scanning for Btrfs filesystems
# ./btrfs device scan -d foo
btrfs device scan: too many arguments
usage: btrfs device scan [(-d|--all-devices)|<device> [<device>...]]

    Scan devices for a btrfs filesystem

     -d|--all-devices (deprecated)

==========================

* devel branch with this patch.

==========================
# ./btrfs device scan
Scanning for Btrfs filesystems
# ./btrfs device scan -d
Scanning for Btrfs filesystems
# ./btrfs device scan -d foo
Scanning for Btrfs filesystems
===========================

* devel branch without this patch.

==================
# ./btrfs device scan
# ./btrfs device scan -d
Scanning for Btrfs filesystems
# ./btrfs device scan -d foo
Scanning for Btrfs filesystems
===================

* devel branch with this patch and my patch.

=========================
# ./btrfs device scan
Scanning for Btrfs filesystems
# ./btrfs device scan -d
Scanning for Btrfs filesystems
# ./btrfs device scan -d foo
btrfs device scan: too many arguments
usage: btrfs device scan [(-d|--all-devices)|<device> [<device>...]]

    Scan devices for a btrfs filesystem

     -d|--all-devices (deprecated)

===========================

Thanks,
Satoru
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Sterba March 9, 2016, 1:19 p.m. UTC | #2
On Wed, Mar 09, 2016 at 05:24:16PM +0900, Satoru Takeuchi wrote:
> > --- a/cmds-device.c
> > +++ b/cmds-device.c
> > @@ -273,7 +273,7 @@ static int cmd_device_scan(int argc, char **argv)
> >   	if (all && check_argc_max(argc - optind, 1))
> 
> It's better to the above line as follows.
> 
> ========
> 	if (all && check_argc_exact(argc - optind, 0))

check_argc_exact prints error messages, and is usually followed by
the usage() call that exits. In the condition it's supposed to check if
there are no arguments (ie. scan all) or if the -d option was given
(scan all). The validity of the option combinations should be done
before that, so the patch is IMO correct.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Sterba March 9, 2016, 1:35 p.m. UTC | #3
On Tue, Mar 08, 2016 at 05:19:40PM -0800, Yauhen Kharuzhy wrote:
> commit 52179e4fea41e55f31c92cd033a0b53a5107b4f4 'btrfs-progs: unify argc
> min/max checking' brokes 'btrfs device scan' command when no argument
> was given. Fix this.
> 
> Signed-off-by: Yauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com>

Applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/cmds-device.c b/cmds-device.c
index cb470af..94ffdc5 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -273,7 +273,7 @@  static int cmd_device_scan(int argc, char **argv)
 	if (all && check_argc_max(argc - optind, 1))
 		usage(cmd_device_scan_usage);
 
-	if (all || argc - optind == 1) {
+	if (all || argc - optind == 0) {
 		printf("Scanning for Btrfs filesystems\n");
 		ret = btrfs_scan_lblkid();
 		error_on(ret, "error %d while scanning", ret);