From: Jens Axboe Date: Thu, 7 Oct 2010 13:00:30 +0000 (+0200) Subject: Add setup/teardown tools X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=5e9c3f76092fe673a7dc4f1c67dfa312870673a2;p=binject.git Add setup/teardown tools Signed-off-by: Jens Axboe --- diff --git a/tools/Makefile b/tools/Makefile new file mode 100644 index 0000000..873ae83 --- /dev/null +++ b/tools/Makefile @@ -0,0 +1,13 @@ +CC = gcc +OPTFLAGS= -O2 -g $(EXTFLAGS) +CFLAGS = -Wall -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 $(OPTFLAGS) +PROGS = bbind bdel + +all: $(PROGS) + +bbind: bbind.o + +bdel: bdel.o + +clean: + -rm -f .depend *.o $(PROGS) core.* core diff --git a/tools/bbind.c b/tools/bbind.c new file mode 100644 index 0000000..271354d --- /dev/null +++ b/tools/bbind.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include + +#define B_NAME_LEN 32 + +struct b_ioctl_cmd { + int fd; + char name[B_NAME_LEN]; +}; + +int main(int argc, char *argv[]) +{ + struct b_ioctl_cmd bic; + int fd, fdb; + + if (argc < 2) { + printf("%s: \n", argv[0]); + return 1; + } + + fd = open(argv[1], O_RDWR); + if (fd < 0) { + perror("open dev"); + return 1; + } + fdb = open("/dev/binject-ctl", O_RDWR); + if (fdb < 0) { + perror("open binject"); + return 1; + } + + bic.fd = fd; + strcpy(bic.name, argv[1]); + + if (ioctl(fdb, 0, &bic) < 0) + perror("ioctl"); + + return 0; +} diff --git a/tools/bdel.c b/tools/bdel.c new file mode 100644 index 0000000..4a84728 --- /dev/null +++ b/tools/bdel.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include +#include + +struct b_ioctl_cmd { + int fd; + int minor; +}; + +int main(int argc, char *argv[]) +{ + struct b_ioctl_cmd bic; + struct stat sb; + int fd; + + if (argc < 2) { + printf("%s: \n", argv[0]); + return 1; + } + + if (stat(argv[1], &sb) < 0) { + perror("stat"); + return 1; + } + + fd = open("/dev/binject-ctl", O_RDWR); + if (fd < 0) { + perror("open binject"); + return 1; + } + + bic.minor = minor(sb.st_rdev); + printf("will delete minor %d\n", bic.minor); + + if (ioctl(fd, 1, &bic) < 0) + perror("ioctl"); + + close(fd); + return 0; +}