Btrfs-progs: add btrfsck name detection to btrfs
authorIlya Dryomov <idryomov@gmail.com>
Tue, 12 Feb 2013 19:24:50 +0000 (21:24 +0200)
committerDavid Sterba <dsterba@suse.cz>
Tue, 12 Feb 2013 21:55:28 +0000 (22:55 +0100)
This patch adds a busybox-style name detection for the name "btrfsck" to
btrfs utility.  The idea is to maintain backwards compatibility by
linking btrfsck to btrfs and have btrfs invoke the check sub-command
when called through the btrfsck link.  This has been suggested on the
mailing list and approved by Dave and Chris.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
btrfs.c

diff --git a/btrfs.c b/btrfs.c
index 062bc51..a7dc50d 100644 (file)
--- a/btrfs.c
+++ b/btrfs.c
@@ -262,16 +262,26 @@ const struct cmd_group btrfs_cmd_group = {
 int main(int argc, char **argv)
 {
        const struct cmd_struct *cmd;
+       const char *bname;
 
-       argc--;
-       argv++;
-       handle_options(&argc, &argv);
-       if (argc > 0) {
-               if (!prefixcmp(argv[0], "--"))
-                       argv[0] += 2;
+       if ((bname = strrchr(argv[0], '/')) != NULL)
+               bname++;
+       else
+               bname = argv[0];
+
+       if (!strcmp(bname, "btrfsck")) {
+               argv[0] = "check";
        } else {
-               usage_command_group(&btrfs_cmd_group, 0, 0);
-               exit(1);
+               argc--;
+               argv++;
+               handle_options(&argc, &argv);
+               if (argc > 0) {
+                       if (!prefixcmp(argv[0], "--"))
+                               argv[0] += 2;
+               } else {
+                       usage_command_group(&btrfs_cmd_group, 0, 0);
+                       exit(1);
+               }
        }
 
        cmd = parse_command_token(argv[0], &btrfs_cmd_group);