]> git.sesse.net Git - bcachefs-tools-debian/blob - bcache.c
bcache in userspace; userspace fsck
[bcachefs-tools-debian] / bcache.c
1 /*
2  * Authors: Kent Overstreet <kent.overstreet@gmail.com>
3  *          Gabriel de Perthuis <g2p.code@gmail.com>
4  *          Jacob Malevich <jam@datera.io>
5  *
6  * GPLv2
7  */
8
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <ctype.h>
12 #include <errno.h>
13 #include <inttypes.h>
14 #include <limits.h>
15 #include <fcntl.h>
16 #include <unistd.h>
17 #include <stdbool.h>
18 #include <stdint.h>
19 #include <string.h>
20 #include <sys/ioctl.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23
24 #include "bcache-cmds.h"
25
26 static void usage(void)
27 {
28         puts("bcache - tool for managing bcache volumes/filesystems\n"
29              "usage: bcache <command> [<args>]\n"
30              "\n"
31              "Commands for formatting, startup and shutdown:\n"
32              "  format         Format a new filesystem\n"
33              "  assemble       Assemble an existing multi device filesystem\n"
34              "  incremental    Incrementally assemble an existing multi device filesystem\n"
35              "  run            Start a partially assembled filesystem\n"
36              "  stop           Stop a running filesystem\n"
37              "\n"
38              "Commands for managing a running filesystem:\n"
39              "  fs_show        Show various information about a filesystem\n"
40              "  fs_set         Modify filesystem options\n"
41              "\n"
42              "Commands for managing a specific device in a filesystem:\n"
43              "  device_show    Show information about a formatted device\n"
44              "  device_add     Add a device to an existing (running) filesystem\n"
45              "  device_remove  Remove a device from an existing (running) filesystem\n"
46              "\n"
47              "Repair:\n"
48              "  bcache fsck    Check an existing filesystem for errors\n");
49 }
50
51 int main(int argc, char *argv[])
52 {
53         char *cmd;
54
55         setvbuf(stdout, NULL, _IOLBF, 0);
56
57         if (argc < 2) {
58                 printf("%s: missing command\n", argv[0]);
59                 usage();
60                 exit(EXIT_FAILURE);
61         }
62
63         cmd = argv[1];
64
65         memmove(&argv[1], &argv[2], argc * sizeof(argv[0]));
66         argc--;
67
68         if (!strcmp(cmd, "format"))
69                 return cmd_format(argc, argv);
70         if (!strcmp(cmd, "assemble"))
71                 return cmd_assemble(argc, argv);
72         if (!strcmp(cmd, "incremental"))
73                 return cmd_incremental(argc, argv);
74         if (!strcmp(cmd, "run"))
75                 return cmd_run(argc, argv);
76         if (!strcmp(cmd, "stop"))
77                 return cmd_stop(argc, argv);
78
79         if (!strcmp(cmd, "fs_show"))
80                 return cmd_fs_show(argc, argv);
81         if (!strcmp(cmd, "fs_set"))
82                 return cmd_fs_set(argc, argv);
83
84         if (!strcmp(cmd, "device_show"))
85                 return cmd_device_show(argc, argv);
86         if (!strcmp(cmd, "device_add"))
87                 return cmd_device_add(argc, argv);
88         if (!strcmp(cmd, "device_remove"))
89                 return cmd_device_remove(argc, argv);
90
91         if (!strcmp(cmd, "fsck"))
92                 return cmd_fsck(argc, argv);
93
94         usage();
95         return 0;
96 }