2 * Authors: Kent Overstreet <kent.overstreet@gmail.com>
3 * Gabriel de Perthuis <g2p.code@gmail.com>
4 * Jacob Malevich <jam@datera.io>
20 #include <sys/ioctl.h>
21 #include <sys/types.h>
24 #include <raid/raid.h>
28 void bcachefs_usage(void)
30 puts("bcachefs - tool for managing bcachefs filesystems\n"
31 "usage: bcachefs <command> [<args>]\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 " reset-counters Reset all counters on an unmounted device\n"
40 " mount Mount a filesystem\n"
43 " fsck Check an existing filesystem for errors\n"
46 "Startup/shutdown, assembly of multi device filesystems:\n"
47 " assemble Assemble an existing multi device filesystem\n"
48 " incremental Incrementally assemble an existing multi device filesystem\n"
49 " run Start a partially assembled filesystem\n"
50 " stop Stop a running filesystem\n"
53 "Commands for managing a running filesystem:\n"
54 " fs usage Show disk usage\n"
56 "Commands for managing devices within a running filesystem:\n"
57 " device add Add a new device to an existing filesystem\n"
58 " device remove Remove a device from an existing filesystem\n"
59 " device online Re-add an existing member to a filesystem\n"
60 " device offline Take a device offline, without removing it\n"
61 " device evacuate Migrate data off of a specific device\n"
62 " device set-state Mark a device as failed\n"
63 " device resize Resize filesystem on a device\n"
64 " device resize-journal Resize journal on a device\n"
66 "Commands for managing subvolumes and snapshots:\n"
67 " subvolume create Create a new subvolume\n"
68 " subvolume delete Delete an existing subvolume\n"
69 " subvolume snapshot Create a snapshot\n"
71 "Commands for managing filesystem data:\n"
72 " data rereplicate Rereplicate degraded data\n"
73 " data job Kick off low level data jobs\n"
76 " unlock Unlock an encrypted filesystem prior to running/mounting\n"
77 " set-passphrase Change passphrase on an existing (unmounted) filesystem\n"
78 " remove-passphrase Remove passphrase on an existing (unmounted) filesystem\n"
81 " migrate Migrate an existing filesystem to bcachefs, in place\n"
82 " migrate-superblock Add default superblock, after bcachefs migrate\n"
84 "Commands for operating on files in a bcachefs filesystem:\n"
85 " setattr Set various per file attributes\n"
88 "These commands work on offline, unmounted filesystems\n"
89 " dump Dump filesystem metadata to a qcow2 image\n"
90 " list List filesystem metadata in textual form\n"
91 " list_journal List contents of journal\n"
94 " fusemount Mount a filesystem via FUSE\n"
97 " completions Generate shell completions\n"
98 " version Display the version of the invoked bcachefs tool\n");
101 static char *pop_cmd(int *argc, char *argv[])
105 memmove(&argv[1], &argv[2], (*argc - 2) * sizeof(argv[0]));
112 int fs_cmds(int argc, char *argv[])
114 char *cmd = pop_cmd(&argc, argv);
120 if (!strcmp(cmd, "usage"))
121 return cmd_fs_usage(argc, argv);
126 int device_cmds(int argc, char *argv[])
128 char *cmd = pop_cmd(&argc, argv);
131 return device_usage();
132 if (!strcmp(cmd, "add"))
133 return cmd_device_add(argc, argv);
134 if (!strcmp(cmd, "remove"))
135 return cmd_device_remove(argc, argv);
136 if (!strcmp(cmd, "online"))
137 return cmd_device_online(argc, argv);
138 if (!strcmp(cmd, "offline"))
139 return cmd_device_offline(argc, argv);
140 if (!strcmp(cmd, "evacuate"))
141 return cmd_device_evacuate(argc, argv);
142 if (!strcmp(cmd, "set-state"))
143 return cmd_device_set_state(argc, argv);
144 if (!strcmp(cmd, "resize"))
145 return cmd_device_resize(argc, argv);
146 if (!strcmp(cmd, "resize-journal"))
147 return cmd_device_resize_journal(argc, argv);
152 int data_cmds(int argc, char *argv[])
154 char *cmd = pop_cmd(&argc, argv);
158 if (!strcmp(cmd, "rereplicate"))
159 return cmd_data_rereplicate(argc, argv);
160 if (!strcmp(cmd, "job"))
161 return cmd_data_job(argc, argv);