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 <idryomov@gmail.com>
This commit is contained in:
Ilya Dryomov 2013-02-12 21:24:50 +02:00 committed by David Sterba
parent 2f4e4e448f
commit d5d2046ae3

26
btrfs.c
View file

@ -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);