From d5d2046ae3b216af22a8a37c940f2412ba519b6e Mon Sep 17 00:00:00 2001 From: Ilya Dryomov Date: Tue, 12 Feb 2013 21:24:50 +0200 Subject: Btrfs-progs: add btrfsck name detection to btrfs 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 --- btrfs.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'btrfs.c') diff --git a/btrfs.c b/btrfs.c index 062bc515..a7dc50d8 100644 --- 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); -- cgit v1.2.3