summaryrefslogtreecommitdiff
path: root/bcache-register.c
diff options
context:
space:
mode:
Diffstat (limited to 'bcache-register.c')
-rw-r--r--bcache-register.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/bcache-register.c b/bcache-register.c
new file mode 100644
index 0000000..e22d80b
--- /dev/null
+++ b/bcache-register.c
@@ -0,0 +1,37 @@
+/*
+ * Author: Simon Gomizelj <simongmzlj@gmail.com>
+ *
+ * GPLv2
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+int main(int argc, char *argv[])
+{
+ int fd;
+
+ if (argc != 2)
+ {
+ fprintf(stderr, "bcache-register takes exactly one argument\n");
+ return 1;
+ }
+
+ fd = open("/sys/fs/bcache/register_quiet", O_WRONLY);
+ if (fd < 0)
+ {
+ perror("Error opening /sys/fs/bcache/register_quiet");
+ fprintf(stderr, "The bcache kernel module must be loaded\n");
+ return 1;
+ }
+
+ if (dprintf(fd, "%s\n", argv[1]) < 0)
+ {
+ fprintf(stderr, "Error registering %s with bcache: %m\n", argv[1]);
+ return 1;
+ }
+
+ return 0;
+}
+