Add setup/teardown tools
authorJens Axboe <jaxboe@fusionio.com>
Thu, 7 Oct 2010 13:00:30 +0000 (15:00 +0200)
committerJens Axboe <jaxboe@fusionio.com>
Thu, 7 Oct 2010 13:00:30 +0000 (15:00 +0200)
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
tools/Makefile [new file with mode: 0644]
tools/bbind.c [new file with mode: 0644]
tools/bdel.c [new file with mode: 0644]

diff --git a/tools/Makefile b/tools/Makefile
new file mode 100644 (file)
index 0000000..873ae83
--- /dev/null
@@ -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 (file)
index 0000000..271354d
--- /dev/null
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/ioctl.h>
+
+#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: <dev>\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 (file)
index 0000000..4a84728
--- /dev/null
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+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: <dev>\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;
+}