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 static void subvolume_create_usage(void)
24 puts("bcachefs subvolume create - create a new subvolume\n"
25 "Usage: bcachefs subvolume create [OPTION]... path\n"
28 " -h, --help Display this help and exit\n"
30 "Report bugs to <linux-bcachefs@vger.kernel.org>");
33 int cmd_subvolume_create(int argc, char *argv[])
35 static const struct option longopts[] = {
36 { "help", no_argument, NULL, 'h' },
42 while ((opt = getopt_long(argc, argv, "h", longopts, NULL)) != -1)
45 subvolume_create_usage();
50 while ((path = arg_pop())) {
51 char *dir = dirname(strdup(path));
53 struct bchfs_handle fs = bcache_fs_open(dir);
55 struct bch_ioctl_subvolume i = {
58 .dst_ptr = (unsigned long)path,
61 xioctl(fs.ioctl_fd, BCH_IOCTL_SUBVOLUME_CREATE, &i);
68 static void subvolume_delete_usage(void)
70 puts("bcachefs subvolume delete - delete an existing subvolume\n"
71 "Usage: bcachefs subvolume delete [OPTION]... path\n"
74 " -h, --help Display this help and exit\n"
76 "Report bugs to <linux-bcachefs@vger.kernel.org>");
79 int cmd_subvolume_delete(int argc, char *argv[])
81 static const struct option longopts[] = {
82 { "help", no_argument, NULL, 'h' },
88 while ((opt = getopt_long(argc, argv, "h", longopts, NULL)) != -1)
91 subvolume_delete_usage();
96 while ((path = arg_pop())) {
97 char *dir = dirname(strdup(path));
99 struct bchfs_handle fs = bcache_fs_open(dir);
101 struct bch_ioctl_subvolume i = {
104 .dst_ptr = (unsigned long)path,
107 xioctl(fs.ioctl_fd, BCH_IOCTL_SUBVOLUME_DESTROY, &i);
114 static void snapshot_create_usage(void)
116 puts("bcachefs subvolume snapshot - create a snapshot \n"
117 "Usage: bcachefs subvolume snapshot [OPTION]... <source> <dest>\n"
119 "Create a snapshot of <source> at <dest>. If specified, <source> must be a subvolume;\n"
120 "if not specified the snapshot will be of the subvolme containing <dest>.\n"
122 " -r Make snapshot read only\n"
123 " -h, --help Display this help and exit\n"
125 "Report bugs to <linux-bcachefs@vger.kernel.org>");
128 int cmd_subvolume_snapshot(int argc, char *argv[])
130 static const struct option longopts[] = {
131 { "help", no_argument, NULL, 'h' },
134 unsigned flags = BCH_SUBVOL_SNAPSHOT_CREATE;
137 while ((opt = getopt_long(argc, argv, "rh", longopts, NULL)) != -1)
140 flags |= BCH_SUBVOL_SNAPSHOT_RO;
143 snapshot_create_usage();
148 char *src = arg_pop();
149 char *dst = arg_pop();
152 die("Too many arguments");
157 die("Please specify a path to create");
159 char *dir = dirname(strdup(dst));
161 struct bchfs_handle fs = bcache_fs_open(dir);
163 struct bch_ioctl_subvolume i = {
167 .src_ptr = (unsigned long)src,
168 .dst_ptr = (unsigned long)dst,
171 xioctl(fs.ioctl_fd, BCH_IOCTL_SUBVOLUME_CREATE, &i);