]> git.sesse.net Git - bcachefs-tools-debian/blob - bcachectl.c
bcacheadm: format bug fixes
[bcachefs-tools-debian] / bcachectl.c
1 #include <errno.h>
2 #include <fcntl.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <sys/ioctl.h>
7
8 #define __KERNEL__
9 #include <linux/bcache-ioctl.h>
10 #undef __KERNEL__
11
12 int bcachefd;
13
14 static int register_devices(int argc, char *argv[])
15 {
16         int ret;
17         ret = ioctl(bcachefd, BCH_IOCTL_REGISTER, argv);
18         if (ret < 0) {
19                 fprintf(stderr, "ioctl error %d", ret);
20                 exit(EXIT_FAILURE);
21         }
22         return 0;
23 }
24
25 int main(int argc, char *argv[])
26 {
27         char *ioctl = argv[1];
28
29         if (argc < 3) {
30                 fprintf(stderr, " <Usage> %s <action> <space separated list of devices>", argv[0]);
31                 fprintf(stderr, "\n <Help>  Possible actions are: \n");
32                 fprintf(stderr, "          \t 1. register_devices\n");
33                 exit(EXIT_FAILURE);
34         }
35
36         bcachefd = open("/dev/bcache", O_RDWR);
37         if (bcachefd < 0) {
38                 perror("Can't open bcache device");
39                 exit(EXIT_FAILURE);
40         }
41
42         argc -= 2;
43         argv += 2;
44
45         if (!strcmp(ioctl, "register"))
46                 return register_devices(argc, argv);
47         else {
48                 fprintf(stderr, "Unknown ioctl\n");
49                 exit(EXIT_FAILURE);
50         }
51         return 0;
52 }