diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2016-10-06 07:19:55 -0800 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2016-10-06 07:19:55 -0800 |
commit | f4eba6559b202547a7cf4be3e852ddaf9abcd9a7 (patch) | |
tree | fd1f4d5bfa5ef599a8fee1e89c6713271342229a | |
parent | f3a8d548376295279d2d27fda5764adbe377c55b (diff) |
finish ripping out libnih
-rw-r--r-- | INSTALL | 3 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | bcache-device.c | 69 | ||||
-rw-r--r-- | bcache-fs.c | 22 | ||||
-rw-r--r-- | bcache-key.c | 11 | ||||
-rw-r--r-- | bcache-run.c | 16 | ||||
-rw-r--r-- | debian/control | 2 | ||||
-rw-r--r-- | util.c | 18 | ||||
-rw-r--r-- | util.h | 3 |
9 files changed, 53 insertions, 93 deletions
@@ -3,12 +3,11 @@ Dependencies: * libblkid * libuuid - * libnih * libscrypt * libsodium * libkeyutils On debian, you can install these with - apt install -y libblkid-dev uuid-dev libnih-dev libscrypt-dev libsodium-dev libkeyutils-dev + apt install -y libblkid-dev uuid-dev libscrypt-dev libsodium-dev libkeyutils-dev Then, just make && make install @@ -4,7 +4,7 @@ INSTALL=install CFLAGS+=-std=gnu99 -O2 -Wall -g -D_FILE_OFFSET_BITS=64 -I. LDFLAGS+=-static -PKGCONFIG_LIBS="blkid uuid libnih" +PKGCONFIG_LIBS="blkid uuid" CFLAGS+=`pkg-config --cflags ${PKGCONFIG_LIBS}` LDLIBS+=`pkg-config --libs ${PKGCONFIG_LIBS}` -lscrypt -lsodium -lkeyutils -lm diff --git a/bcache-device.c b/bcache-device.c index a349e79..bb79a92 100644 --- a/bcache-device.c +++ b/bcache-device.c @@ -1,7 +1,7 @@ - #include <dirent.h> #include <errno.h> #include <fcntl.h> +#include <getopt.h> #include <libgen.h> #include <stdbool.h> #include <stdint.h> @@ -13,8 +13,6 @@ #include <sys/types.h> #include <unistd.h> -#include <nih/option.h> - #include "bcache.h" #include "libbcache.h" @@ -183,20 +181,14 @@ int cmd_device_show(int argc, char *argv[]) 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)) @@ -206,28 +198,51 @@ int cmd_device_add(int argc, char *argv[]) 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) diff --git a/bcache-fs.c b/bcache-fs.c index f06ca37..57dc47a 100644 --- a/bcache-fs.c +++ b/bcache-fs.c @@ -1,6 +1,4 @@ -#include <nih/option.h> - #include "bcache.h" struct bcache_fs { @@ -20,32 +18,20 @@ static struct bcache_fs fill_fs(struct bcache_handle fs) int cmd_fs_show(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) != 1) + if (argc != 2) die("Please supply a filesystem"); - struct bcache_handle fs = bcache_fs_open(args[0]); + struct bcache_handle fs = bcache_fs_open(argv[1]); return 0; } int cmd_fs_set(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) < 1) + if (argc != 2) die("Please supply a filesystem"); - struct bcache_handle fs = bcache_fs_open(args[0]); + struct bcache_handle fs = bcache_fs_open(argv[1]); return 0; } diff --git a/bcache-key.c b/bcache-key.c index cac0948..3cd6d09 100644 --- a/bcache-key.c +++ b/bcache-key.c @@ -2,8 +2,6 @@ #include <unistd.h> #include <keyutils.h> #include <uuid/uuid.h> -#include <nih/command.h> -#include <nih/option.h> #include "bcache.h" #include "libbcache.h" @@ -11,11 +9,6 @@ int cmd_unlock(int argc, char *argv[]) { - NihOption opts[] = { - NIH_OPTION_LAST - }; - char **args = bch_nih_init(argc, argv, opts); - struct bcache_disk_key disk_key; struct bcache_key key; struct cache_sb *sb; @@ -23,10 +16,10 @@ int cmd_unlock(int argc, char *argv[]) char uuid[40]; char description[60]; - if (!args[0] || args[1]) + if (argc != 2) die("please supply a single device"); - sb = bcache_super_read(args[0]); + sb = bcache_super_read(argv[1]); if (!CACHE_SET_ENCRYPTION_KEY(sb)) die("filesystem is not encrypted"); diff --git a/bcache-run.c b/bcache-run.c index 09af583..8a8bc05 100644 --- a/bcache-run.c +++ b/bcache-run.c @@ -9,33 +9,21 @@ #include <sys/ioctl.h> #include <unistd.h> -#include <nih/option.h> - #include <uuid/uuid.h> #include "bcache.h" int cmd_run(int argc, char *argv[]) { - NihOption opts[] = { - NIH_OPTION_LAST - }; - bch_nih_init(argc, argv, opts); - return 0; } int cmd_stop(int argc, char *argv[]) { - NihOption opts[] = { - NIH_OPTION_LAST - }; - char **args = bch_nih_init(argc, argv, opts); - - if (nr_args(args) != 1) + if (argc != 2) die("Please supply a filesystem"); - struct bcache_handle fs = bcache_fs_open(args[0]); + struct bcache_handle fs = bcache_fs_open(argv[1]); if (ioctl(fs.fd, BCH_IOCTL_STOP)) die("BCH_IOCTL_STOP error: %s", strerror(errno)); diff --git a/debian/control b/debian/control index 3e9b294..13622a6 100644 --- a/debian/control +++ b/debian/control @@ -4,7 +4,7 @@ Uploaders: Robie Basak <robie@justgohome.co.uk> Section: utils Priority: optional Standards-Version: 3.9.5 -Build-Depends: debhelper (>= 9), pkg-config, libblkid-dev, uuid-dev, libnih-dev, +Build-Depends: debhelper (>= 9), pkg-config, libblkid-dev, uuid-dev, libscrypt-dev, libsodium-dev, libkeyutils-dev Vcs-Browser: http://anonscm.debian.org/gitweb/?p=collab-maint/bcache-tools.git Vcs-Git: git://anonscm.debian.org/collab-maint/bcache-tools.git @@ -513,21 +513,3 @@ void memzero_explicit(void *buf, size_t len) void *(* volatile memset_s)(void *s, int c, size_t n) = memset; memset_s(buf, 0, len); } - -/* libnih options: */ - -#include <nih/option.h> -#include <nih/main.h> - -#define PACKAGE_NAME "bcache" -#define PACKAGE_VERSION "1.0" -#define PACKAGE_BUGREPORT "linux-bcache@vger.kernel.org" - -char **bch_nih_init(int argc, char *argv[], NihOption *options) -{ - nih_main_init(argv[0]); - nih_option_set_synopsis(_("Manage bcache devices")); - nih_option_set_help( _("Helps you manage bcache devices")); - - return nih_option_parser(NULL, argc, argv, options, 0); -} @@ -135,7 +135,4 @@ bool ask_proceed(void); void memzero_explicit(void *, size_t); -struct nih_option; -char **bch_nih_init(int argc, char *argv[], struct nih_option *options); - #endif /* _UTIL_H */ |