mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-23 00:00:02 +03:00
finish ripping out libnih
This commit is contained in:
parent
f3a8d54837
commit
f4eba6559b
3
INSTALL
3
INSTALL
@ -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
|
||||
|
2
Makefile
2
Makefile
@ -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
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
int cmd_device_remove(int argc, char *argv[])
|
||||
{
|
||||
int force_data = 0, force_metadata = 0;
|
||||
NihOption opts[] = {
|
||||
// { int shortoption, char *longoption, char *help, NihOptionGroup, char *argname, void *value, NihOptionSetter}
|
||||
|
||||
{ '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
|
||||
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;
|
||||
|
||||
if (nr_args(args) < 2)
|
||||
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 (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)
|
||||
|
22
bcache-fs.c
22
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;
|
||||
}
|
||||
|
11
bcache-key.c
11
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");
|
||||
|
16
bcache-run.c
16
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));
|
||||
|
2
debian/control
vendored
2
debian/control
vendored
@ -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
|
||||
|
18
util.c
18
util.c
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user