]> git.sesse.net Git - bcachefs-tools-debian/blob - bcachefs.c
Add manpage for mount command
[bcachefs-tools-debian] / bcachefs.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 <raid/raid.h>
25
26 #include "cmds.h"
27
28 static void usage(void)
29 {
30         puts("bcachefs - tool for managing bcachefs filesystems\n"
31              "usage: bcachefs <command> [<args>]\n"
32              "\n"
33              "Superblock commands:\n"
34              "  format                   Format a new filesystem\n"
35              "  show-super               Dump superblock information to stdout\n"
36              "  set-option               Set a filesystem option\n"
37              "\n"
38              "Mount:\n"
39              "  mount                    Mount a filesystem\n"
40              "\n"
41              "Repair:\n"
42              "  fsck                     Check an existing filesystem for errors\n"
43              "\n"
44 #if 0
45              "Startup/shutdown, assembly of multi device filesystems:\n"
46              "  assemble                 Assemble an existing multi device filesystem\n"
47              "  incremental              Incrementally assemble an existing multi device filesystem\n"
48              "  run                      Start a partially assembled filesystem\n"
49              "  stop                     Stop a running filesystem\n"
50              "\n"
51 #endif
52              "Commands for managing a running filesystem:\n"
53              "  fs usage                 Show disk usage\n"
54              "\n"
55              "Commands for managing devices within a running filesystem:\n"
56              "  device add               Add a new device to an existing filesystem\n"
57              "  device remove            Remove a device from an existing filesystem\n"
58              "  device online            Re-add an existing member to a filesystem\n"
59              "  device offline           Take a device offline, without removing it\n"
60              "  device evacuate          Migrate data off of a specific device\n"
61              "  device set-state         Mark a device as failed\n"
62              "  device resize            Resize filesystem on a device\n"
63              "  device resize-journal    Resize journal on a device\n"
64              "\n"
65              "Commands for managing subvolumes and snapshots:\n"
66              "  subvolume create         Create a new subvolume\n"
67              "  subvolume delete         Delete an existing subvolume\n"
68              "  subvolume snapshot       Create a snapshot\n"
69              "\n"
70              "Commands for managing filesystem data:\n"
71              "  data rereplicate         Rereplicate degraded data\n"
72              "  data job                 Kick off low level data jobs\n"
73              "\n"
74              "Encryption:\n"
75              "  unlock                   Unlock an encrypted filesystem prior to running/mounting\n"
76              "  set-passphrase           Change passphrase on an existing (unmounted) filesystem\n"
77              "  remove-passphrase        Remove passphrase on an existing (unmounted) filesystem\n"
78              "\n"
79              "Migrate:\n"
80              "  migrate                  Migrate an existing filesystem to bcachefs, in place\n"
81              "  migrate-superblock       Add default superblock, after bcachefs migrate\n"
82              "\n"
83              "Commands for operating on files in a bcachefs filesystem:\n"
84              "  setattr                  Set various per file attributes\n"
85              "Debug:\n"
86              "These commands work on offline, unmounted filesystems\n"
87              "  dump                     Dump filesystem metadata to a qcow2 image\n"
88              "  list                     List filesystem metadata in textual form\n"
89              "  list_journal             List contents of journal\n"
90              "\n"
91              "Miscellaneous:\n"
92              "  version                  Display the version of the invoked bcachefs tool\n");
93 }
94
95 static char *full_cmd;
96
97 static char *pop_cmd(int *argc, char *argv[])
98 {
99         char *cmd = argv[1];
100         if (!(*argc < 2))
101                 memmove(&argv[1], &argv[2], *argc * sizeof(argv[0]));
102         (*argc)--;
103
104         full_cmd = mprintf("%s %s", full_cmd, cmd);
105         return cmd;
106 }
107
108 static int fs_cmds(int argc, char *argv[])
109 {
110         char *cmd = pop_cmd(&argc, argv);
111
112         if (argc < 1)
113                 return fs_usage();
114         if (!strcmp(cmd, "usage"))
115                 return cmd_fs_usage(argc, argv);
116
117         return 0;
118 }
119
120 static int device_cmds(int argc, char *argv[])
121 {
122         char *cmd = pop_cmd(&argc, argv);
123
124         if (argc < 1)
125                 return device_usage();
126         if (!strcmp(cmd, "add"))
127                 return cmd_device_add(argc, argv);
128         if (!strcmp(cmd, "remove"))
129                 return cmd_device_remove(argc, argv);
130         if (!strcmp(cmd, "online"))
131                 return cmd_device_online(argc, argv);
132         if (!strcmp(cmd, "offline"))
133                 return cmd_device_offline(argc, argv);
134         if (!strcmp(cmd, "evacuate"))
135                 return cmd_device_evacuate(argc, argv);
136         if (!strcmp(cmd, "set-state"))
137                 return cmd_device_set_state(argc, argv);
138         if (!strcmp(cmd, "resize"))
139                 return cmd_device_resize(argc, argv);
140         if (!strcmp(cmd, "resize-journal"))
141                 return cmd_device_resize_journal(argc, argv);
142
143         return 0;
144 }
145
146 static int data_cmds(int argc, char *argv[])
147 {
148         char *cmd = pop_cmd(&argc, argv);
149
150         if (argc < 1)
151                 return data_usage();
152         if (!strcmp(cmd, "rereplicate"))
153                 return cmd_data_rereplicate(argc, argv);
154         if (!strcmp(cmd, "job"))
155                 return cmd_data_job(argc, argv);
156
157         return 0;
158 }
159
160 static int subvolume_cmds(int argc, char *argv[])
161 {
162         char *cmd = pop_cmd(&argc, argv);
163         if (argc < 1)
164                 return subvolume_usage();
165         if (!strcmp(cmd, "create"))
166                 return cmd_subvolume_create(argc, argv);
167         if (!strcmp(cmd, "delete"))
168                 return cmd_subvolume_delete(argc, argv);
169         if (!strcmp(cmd, "snapshot"))
170                 return cmd_subvolume_snapshot(argc, argv);
171
172         return 0;
173 }
174
175 int main(int argc, char *argv[])
176 {
177         raid_init();
178
179         full_cmd = argv[0];
180
181         setvbuf(stdout, NULL, _IOLBF, 0);
182
183         char *cmd = pop_cmd(&argc, argv);
184         if (!cmd) {
185                 puts("missing command\n");
186                 goto usage;
187         }
188
189         /* these subcommands display usage when argc < 2 */
190         if (!strcmp(cmd, "device"))
191                 return device_cmds(argc, argv);
192         if (!strcmp(cmd, "fs"))
193                 return fs_cmds(argc, argv);
194         if (!strcmp(cmd, "data"))
195                 return data_cmds(argc, argv);
196         if (!strcmp(cmd, "subvolume"))
197                 return subvolume_cmds(argc, argv);
198         if (!strcmp(cmd, "format"))
199                 return cmd_format(argc, argv);
200         if (!strcmp(cmd, "fsck"))
201                 return cmd_fsck(argc, argv);
202         if (!strcmp(cmd, "version"))
203                 return cmd_version(argc, argv);
204         if (!strcmp(cmd, "show-super"))
205                 return cmd_show_super(argc, argv);
206         if (!strcmp(cmd, "set-option"))
207                 return cmd_set_option(argc, argv);
208
209 #if 0
210         if (!strcmp(cmd, "assemble"))
211                 return cmd_assemble(argc, argv);
212         if (!strcmp(cmd, "incremental"))
213                 return cmd_incremental(argc, argv);
214         if (!strcmp(cmd, "run"))
215                 return cmd_run(argc, argv);
216         if (!strcmp(cmd, "stop"))
217                 return cmd_stop(argc, argv);
218 #endif
219
220         if (!strcmp(cmd, "unlock"))
221                 return cmd_unlock(argc, argv);
222         if (!strcmp(cmd, "set-passphrase"))
223                 return cmd_set_passphrase(argc, argv);
224         if (!strcmp(cmd, "remove-passphrase"))
225                 return cmd_remove_passphrase(argc, argv);
226
227         if (!strcmp(cmd, "migrate"))
228                 return cmd_migrate(argc, argv);
229         if (!strcmp(cmd, "migrate-superblock"))
230                 return cmd_migrate_superblock(argc, argv);
231
232         if (!strcmp(cmd, "dump"))
233                 return cmd_dump(argc, argv);
234         if (!strcmp(cmd, "list"))
235                 return cmd_list(argc, argv);
236         if (!strcmp(cmd, "list_journal"))
237                 return cmd_list_journal(argc, argv);
238         if (!strcmp(cmd, "kill_btree_node"))
239                 return cmd_kill_btree_node(argc, argv);
240
241         if (!strcmp(cmd, "setattr"))
242                 return cmd_setattr(argc, argv);
243
244         if (!strcmp(cmd, "mount")) {
245                 cmd_mount(argc, argv);
246                 return 0;
247         }
248
249 #ifdef BCACHEFS_FUSE
250         if (!strcmp(cmd, "fusemount"))
251                 return cmd_fusemount(argc, argv);
252 #endif
253
254         if (!strcmp(cmd, "--help")) {
255                 usage();
256                 return 0;
257         }
258
259         printf("Unknown command %s\n", cmd);
260 usage:
261         usage();
262         exit(EXIT_FAILURE);
263 }