diff --git a/Makefile b/Makefile index 4f9f7c54..e7d94e6e 100644 --- a/Makefile +++ b/Makefile @@ -5,10 +5,10 @@ DRACUTLIBDIR=/lib/dracut INSTALL=install CFLAGS+=-O2 -Wall -g -all: make-bcache probe-bcache bcache-super-show +all: make-bcache probe-bcache bcache-super-show bcachectl install: make-bcache probe-bcache bcache-super-show - $(INSTALL) -m0755 make-bcache bcache-super-show $(DESTDIR)${PREFIX}/sbin/ + $(INSTALL) -m0755 make-bcache bcache-super-show bcachectl $(DESTDIR)${PREFIX}/sbin/ $(INSTALL) -m0755 probe-bcache bcache-register $(DESTDIR)$(UDEVLIBDIR)/ $(INSTALL) -m0644 69-bcache.rules $(DESTDIR)$(UDEVLIBDIR)/rules.d/ -$(INSTALL) -T -m0755 initramfs/hook $(DESTDIR)/usr/share/initramfs-tools/hooks/bcache @@ -19,7 +19,7 @@ install: make-bcache probe-bcache bcache-super-show # $(INSTALL) -m0755 bcache-test $(DESTDIR)${PREFIX}/sbin/ clean: - $(RM) -f make-bcache probe-bcache bcache-super-show bcache-test *.o + $(RM) -f make-bcache probe-bcache bcache-super-show bcache-test bcachectl *.o bcache-test: LDLIBS += `pkg-config --libs openssl` make-bcache: LDLIBS += `pkg-config --libs uuid blkid` @@ -30,3 +30,4 @@ probe-bcache: CFLAGS += `pkg-config --cflags uuid blkid` bcache-super-show: LDLIBS += `pkg-config --libs uuid` bcache-super-show: CFLAGS += -std=gnu99 bcache-super-show: bcache.o +bcachectl: bcachectl.o diff --git a/Makefile.am b/Makefile.am index c3626739..fdfe1a53 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,7 +7,8 @@ AM_CFLAGS=-O2 -Wall -g -std=gnu99 bin_PROGRAMS=make-bcache \ probe-bcache \ - bcache-super-show + bcache-super-show \ + bcachectl noinst_PROGRAMS=bcache-test @@ -23,6 +24,8 @@ bcache_super_show_SOURCES=bcache-super-show.c bcache.c bcache_super_show_LDFLAGS=`pkg-config --libs uuid` bcache_super_show_CFLAGS=$(AM_CFLAGS) `pkg-config --cflags uuid` +bcachectl_SOURCES=bcachectl.c + bcache_test_SOURCE=bcache-test.c bcache_test_LDFLAGS=-lm `pkg-config --libs openssl` bcache_test_CFLAGS=$(AM_CFLAGS) `pkg-config --cflags openssl` diff --git a/bcachectl.c b/bcachectl.c new file mode 100644 index 00000000..2325cb50 --- /dev/null +++ b/bcachectl.c @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include +#include + +#define __KERNEL__ +#include +#undef __KERNEL__ + +int bcachefd; + +static int register_devices(int argc, char *argv[]) +{ + int ret; + + ret = ioctl(bcachefd, BCH_IOCTL_REGISTER, argv); + if (ret < 0) { + fprintf(stderr, "ioctl error %d", ret); + exit(EXIT_FAILURE); + } + return 0; +} + +int main(int argc, char *argv[]) +{ + char *ioctl = argv[2]; + + if (argc < 3) { + fprintf(stderr, "Enter bcache device and an ioctl to issue\n"); + exit(EXIT_FAILURE); + } + + bcachefd = open(argv[1], O_RDWR); + if (bcachefd < 0) { + perror("Can't open bcache device"); + exit(EXIT_FAILURE); + } + + argc -= 3; + argv += 3; + + if (!strcmp(ioctl, "register_devices")) + return register_devices(argc, argv); + else { + fprintf(stderr, "Unknown ioctl\n"); + exit(EXIT_FAILURE); + } +} +