btrfs-progs: better option/error handling for btrfs-vol
authorEric Sandeen <sandeen@redhat.com>
Mon, 4 Mar 2013 22:40:03 +0000 (16:40 -0600)
committerDavid Sterba <dsterba@suse.cz>
Sun, 10 Mar 2013 15:06:37 +0000 (16:06 +0100)
Today wrong cmdlines give odd results:

# ./btrfs-vol /dev/sdb1
Unable to open device (null)
# ./btrfs-vol -a /dev/sdb1
usage: btrfs-vol [options] mount_point ...

Make it a bit more informative:

# ./btrfs-vol /dev/sdb1
No command specified
usage: btrfs-vol [options] mount_point ...
# ./btrfs-vol -a /dev/sdb1
No mountpoint specified
usage: btrfs-vol [options] mount_point ...

(even though it's deprecated ...)

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
btrfs-vol.c

index 3cc1c32..e37b41a 100644 (file)
@@ -106,8 +106,13 @@ int main(int ac, char **av)
                }
        }
        ac = ac - optind;
-       if (ac == 0)
+       if (ac == 0 || !cmd) {
+               if (!ac)
+                       fprintf(stderr, "No mountpoint specified\n");
+               else
+                       fprintf(stderr, "No command specified\n");
                print_usage();
+       }
        mnt = av[optind];
 
        if (device && strcmp(device, "missing") == 0 &&