]> git.sesse.net Git - bcachefs-tools-debian/blob - c_src/bcachefs.c
Disable pristine-tar option in gbp.conf, since there is no pristine-tar branch.
[bcachefs-tools-debian] / c_src / 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 void bcachefs_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              "  reset-counters           Reset all counters on an unmounted device\n"
38              "\n"
39              "Mount:\n"
40              "  mount                    Mount a filesystem\n"
41              "\n"
42              "Repair:\n"
43              "  fsck                     Check an existing filesystem for errors\n"
44              "\n"
45 #if 0
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"
51              "\n"
52 #endif
53              "Commands for managing a running filesystem:\n"
54              "  fs usage                 Show disk usage\n"
55              "\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"
65              "\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"
70              "\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"
74              "\n"
75              "Encryption:\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"
79              "\n"
80              "Migrate:\n"
81              "  migrate                  Migrate an existing filesystem to bcachefs, in place\n"
82              "  migrate-superblock       Add default superblock, after bcachefs migrate\n"
83              "\n"
84              "Commands for operating on files in a bcachefs filesystem:\n"
85              "  setattr                  Set various per file attributes\n"
86              "\n"
87              "Debug:\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"
92              "\n"
93              "FUSE:\n"
94              "  fusemount                Mount a filesystem via FUSE\n"
95              "\n"
96              "Miscellaneous:\n"
97          "  completions              Generate shell completions\n"
98              "  version                  Display the version of the invoked bcachefs tool\n");
99 }
100
101 static char *pop_cmd(int *argc, char *argv[])
102 {
103         char *cmd = argv[1];
104         if (!(*argc < 2))
105                 memmove(&argv[1], &argv[2], (*argc - 2) * sizeof(argv[0]));
106         (*argc)--;
107         argv[*argc] = NULL;
108
109         return cmd;
110 }
111
112 int fs_cmds(int argc, char *argv[])
113 {
114         char *cmd = pop_cmd(&argc, argv);
115
116         if (argc < 1) {
117                 bcachefs_usage();
118                 exit(EXIT_FAILURE);
119         }
120         if (!strcmp(cmd, "usage"))
121                 return cmd_fs_usage(argc, argv);
122
123         return 0;
124 }
125
126 int device_cmds(int argc, char *argv[])
127 {
128         char *cmd = pop_cmd(&argc, argv);
129
130         if (argc < 1)
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);
148
149         return 0;
150 }
151
152 int data_cmds(int argc, char *argv[])
153 {
154         char *cmd = pop_cmd(&argc, argv);
155
156         if (argc < 1)
157                 return data_usage();
158         if (!strcmp(cmd, "rereplicate"))
159                 return cmd_data_rereplicate(argc, argv);
160         if (!strcmp(cmd, "job"))
161                 return cmd_data_job(argc, argv);
162
163         return 0;
164 }