10 #include <sys/ioctl.h>
12 #include <sys/types.h>
15 #include "libbcachefs/bcachefs.h"
16 #include "libbcachefs/bcachefs_ioctl.h"
18 #include "libbcachefs.h"
19 #include "libbcachefs/opts.h"
20 #include "tools-util.h"
22 int subvolume_usage(void)
24 puts("bcachefs subvolume - manage subvolumes and snapshots\n"
25 "Usage: bcachefs subvolume <CMD> [OPTION]\n"
28 " create create a subvolume\n"
29 " delete delete a subvolume\n"
30 " snapshot create a snapshot\n"
32 "Report bugs to <linux-bcachefs@vger.kernel.org>");
36 static void subvolume_create_usage(void)
38 puts("bcachefs subvolume create - create a new subvolume\n"
39 "Usage: bcachefs subvolume create [OPTION]... path\n"
42 " -h, --help Display this help and exit\n"
44 "Report bugs to <linux-bcachefs@vger.kernel.org>");
47 int cmd_subvolume_create(int argc, char *argv[])
49 static const struct option longopts[] = {
50 { "help", no_argument, NULL, 'h' },
56 while ((opt = getopt_long(argc, argv, "h", longopts, NULL)) != -1)
59 subvolume_create_usage();
64 while ((path = arg_pop())) {
65 char *dir = dirname(strdup(path));
67 struct bchfs_handle fs = bcache_fs_open(dir);
69 struct bch_ioctl_subvolume i = {
72 .dst_ptr = (unsigned long)path,
75 xioctl(fs.ioctl_fd, BCH_IOCTL_SUBVOLUME_CREATE, &i);
82 static void subvolume_delete_usage(void)
84 puts("bcachefs subvolume delete - delete an existing subvolume\n"
85 "Usage: bcachefs subvolume delete [OPTION]... path\n"
88 " -h, --help Display this help and exit\n"
90 "Report bugs to <linux-bcachefs@vger.kernel.org>");
93 int cmd_subvolume_delete(int argc, char *argv[])
95 static const struct option longopts[] = {
96 { "help", no_argument, NULL, 'h' },
102 while ((opt = getopt_long(argc, argv, "h", longopts, NULL)) != -1)
105 subvolume_delete_usage();
110 while ((path = arg_pop())) {
111 char *dir = dirname(strdup(path));
113 struct bchfs_handle fs = bcache_fs_open(dir);
115 struct bch_ioctl_subvolume i = {
118 .dst_ptr = (unsigned long)path,
121 xioctl(fs.ioctl_fd, BCH_IOCTL_SUBVOLUME_DESTROY, &i);
128 static void snapshot_create_usage(void)
130 puts("bcachefs subvolume snapshot - create a snapshot \n"
131 "Usage: bcachefs subvolume snapshot [OPTION]... <source> <dest>\n"
133 "Create a snapshot of <source> at <dest>. If specified, <source> must be a subvolume;\n"
134 "if not specified the snapshot will be of the subvolme containing <dest>.\n"
136 " -r Make snapshot read only\n"
137 " -h, --help Display this help and exit\n"
139 "Report bugs to <linux-bcachefs@vger.kernel.org>");
142 int cmd_subvolume_snapshot(int argc, char *argv[])
144 static const struct option longopts[] = {
145 { "help", no_argument, NULL, 'h' },
148 unsigned flags = BCH_SUBVOL_SNAPSHOT_CREATE;
151 while ((opt = getopt_long(argc, argv, "rh", longopts, NULL)) != -1)
154 flags |= BCH_SUBVOL_SNAPSHOT_RO;
157 snapshot_create_usage();
162 char *src = arg_pop();
163 char *dst = arg_pop();
166 die("Too many arguments");
171 die("Please specify a path to create");
173 char *dir = dirname(strdup(dst));
175 struct bchfs_handle fs = bcache_fs_open(dir);
177 struct bch_ioctl_subvolume i = {
181 .src_ptr = (unsigned long)src,
182 .dst_ptr = (unsigned long)dst,
185 xioctl(fs.ioctl_fd, BCH_IOCTL_SUBVOLUME_CREATE, &i);