-
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
+#include <getopt.h>
#include <libgen.h>
#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
#include <unistd.h>
-#include <nih/option.h>
-
#include "bcache.h"
#include "libbcache.h"
int cmd_device_add(int argc, char *argv[])
{
- NihOption opts[] = {
- // { int shortoption, char *longoption, char *help, NihOptionGroup, char *argname, void *value, NihOptionSetter}
- NIH_OPTION_LAST
- };
- char **args = bch_nih_init(argc, argv, opts);
-
- if (nr_args(args) < 2)
+ if (argc < 3)
die("Please supply a filesystem and at least one device to add");
- struct bcache_handle fs = bcache_fs_open(args[0]);
+ struct bcache_handle fs = bcache_fs_open(argv[1]);
- for (unsigned i = 1; args[i]; i++) {
+ for (unsigned i = 2; i < argc; i++) {
struct bch_ioctl_disk_add ia = {
- .dev = (__u64) args[i],
+ .dev = (__u64) argv[i],
};
if (ioctl(fs.fd, BCH_IOCTL_DISK_ADD, &ia))
return 0;
}
-int cmd_device_remove(int argc, char *argv[])
+static void usage(void)
{
- int force_data = 0, force_metadata = 0;
- NihOption opts[] = {
- // { int shortoption, char *longoption, char *help, NihOptionGroup, char *argname, void *value, NihOptionSetter}
+ puts("bcache device_remove - remove one or more devices from a filesystem\n"
+ "Usage: bcache device_remove filesystem [devices]\n"
+ "\n"
+ "Options:\n"
+ " -f, --force Force removal, even if some data\n"
+ " couldn't be migrated\n"
+ " --force-metadata Force removal, even if some metadata\n"
+ " couldn't be migrated\n"
+ " -h, --help display this help and exit\n"
+ "Report bugs to <linux-bcache@vger.kernel.org>");
+ exit(EXIT_SUCCESS);
+}
- { 'f', "force", N_("force if data present"),
- NULL, NULL, &force_data, NULL },
- { '\0', "force-metadata", N_("force if metadata present"),
- NULL, NULL, &force_metadata, NULL},
- NIH_OPTION_LAST
+int cmd_device_remove(int argc, char *argv[])
+{
+ static const struct option longopts[] = {
+ { "force", 0, NULL, 'f' },
+ { "force-metadata", 0, NULL, 'F' },
+ { "help", 0, NULL, 'h' },
+ { NULL }
};
- char **args = bch_nih_init(argc, argv, opts);
+ int opt, force_data = 0, force_metadata = 0;
+
+ while ((opt = getopt_long(argc, argv, "fh", longopts, NULL)) != -1)
+ switch (opt) {
+ case 'f':
+ force_data = 1;
+ break;
+ case 'F':
+ force_metadata = 1;
+ break;
+ case 'h':
+ usage();
+ }
- if (nr_args(args) < 2)
+ if (argc < 3)
die("Please supply a filesystem and at least one device to add");
- struct bcache_handle fs = bcache_fs_open(args[0]);
+ struct bcache_handle fs = bcache_fs_open(argv[1]);
- for (unsigned i = 1; args[i]; i++) {
+ for (unsigned i = 2; i < argc; i++) {
struct bch_ioctl_disk_remove ir = {
- .dev = (__u64) args[0],
+ .dev = (__u64) argv[i],
};
if (force_data)