btrfs-progs: alias btrfs device delete to btrfs device remove
[platform/upstream/btrfs-progs.git] / cmds-device.c
index 4fa6b4a..0e60500 100644 (file)
@@ -52,7 +52,6 @@ static int cmd_add_dev(int argc, char **argv)
        DIR     *dirstream = NULL;
        int discard = 1;
        int force = 0;
-       char estr[100];
 
        while (1) {
                int c;
@@ -97,9 +96,8 @@ static int cmd_add_dev(int argc, char **argv)
                int mixed = 0;
                char *path;
 
-               res = test_dev_for_mkfs(argv[i], force, estr);
+               res = test_dev_for_mkfs(argv[i], force);
                if (res) {
-                       fprintf(stderr, "%s", estr);
                        ret++;
                        continue;
                }
@@ -128,6 +126,7 @@ static int cmd_add_dev(int argc, char **argv)
                        goto error_out;
                }
 
+               memset(&ioctl_args, 0, sizeof(ioctl_args));
                strncpy_null(ioctl_args.name, path);
                res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args);
                e = errno;
@@ -144,20 +143,14 @@ error_out:
        return !!ret;
 }
 
-static const char * const cmd_rm_dev_usage[] = {
-       "btrfs device delete <device> [<device>...] <path>",
-       "Remove a device from a filesystem",
-       NULL
-};
-
-static int cmd_rm_dev(int argc, char **argv)
+static int _cmd_rm_dev(int argc, char **argv, const char * const *usagestr)
 {
        char    *mntpnt;
        int     i, fdmnt, ret=0, e;
        DIR     *dirstream = NULL;
 
        if (check_argc_min(argc, 3))
-               usage(cmd_rm_dev_usage);
+               usage(usagestr);
 
        mntpnt = argv[argc - 1];
 
@@ -177,6 +170,7 @@ static int cmd_rm_dev(int argc, char **argv)
                        ret++;
                        continue;
                }
+               memset(&arg, 0, sizeof(arg));
                strncpy_null(arg.name, argv[i]);
                res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg);
                e = errno;
@@ -198,6 +192,28 @@ static int cmd_rm_dev(int argc, char **argv)
        return !!ret;
 }
 
+static const char * const cmd_rm_dev_usage[] = {
+       "btrfs device remove <device> [<device>...] <path>",
+       "Remove a device from a filesystem",
+       NULL
+};
+
+static int cmd_rm_dev(int argc, char **argv)
+{
+       return _cmd_rm_dev(argc, argv, cmd_rm_dev_usage);
+}
+
+static const char * const cmd_del_dev_usage[] = {
+       "btrfs device delete <device> [<device>...] <path>",
+       "Remove a device from a filesystem",
+       NULL
+};
+
+static int cmd_del_dev(int argc, char **argv)
+{
+       return _cmd_rm_dev(argc, argv, cmd_del_dev_usage);
+}
+
 static const char * const cmd_scan_dev_usage[] = {
        "btrfs device scan [(-d|--all-devices)|<device> [<device>...]]",
        "Scan devices for a btrfs filesystem",
@@ -314,7 +330,8 @@ static int cmd_ready_dev(int argc, char **argv)
                goto out;
        }
 
-       strncpy(args.name, path, BTRFS_PATH_NAME_MAX);
+       memset(&args, 0, sizeof(args));
+       strncpy_null(args.name, path);
        ret = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args);
        if (ret < 0) {
                fprintf(stderr, "ERROR: unable to determine if the device '%s'"
@@ -589,7 +606,8 @@ static const char device_cmd_group_info[] =
 const struct cmd_group device_cmd_group = {
        device_cmd_group_usage, device_cmd_group_info, {
                { "add", cmd_add_dev, cmd_add_dev_usage, NULL, 0 },
-               { "delete", cmd_rm_dev, cmd_rm_dev_usage, NULL, 0 },
+               { "delete", cmd_del_dev, cmd_del_dev_usage, NULL, CMD_ALIAS },
+               { "remove", cmd_rm_dev, cmd_rm_dev_usage, NULL, 0 },
                { "scan", cmd_scan_dev, cmd_scan_dev_usage, NULL, 0 },
                { "ready", cmd_ready_dev, cmd_ready_dev_usage, NULL, 0 },
                { "stats", cmd_dev_stats, cmd_dev_stats_usage, NULL, 0 },