5 #include <sys/statvfs.h>
7 #include <fuse_lowlevel.h>
10 #include "libbcachefs.h"
11 #include "tools-util.h"
13 #include "libbcachefs/bcachefs.h"
14 #include "libbcachefs/alloc_foreground.h"
15 #include "libbcachefs/btree_iter.h"
16 #include "libbcachefs/buckets.h"
17 #include "libbcachefs/dirent.h"
18 #include "libbcachefs/error.h"
19 #include "libbcachefs/fs-common.h"
20 #include "libbcachefs/inode.h"
21 #include "libbcachefs/io.h"
22 #include "libbcachefs/opts.h"
23 #include "libbcachefs/super.h"
26 #include "libbcachefs/fs.h"
28 #include <linux/dcache.h>
30 /* XXX cut and pasted from fsck.c */
31 #define QSTR(n) { { { .len = strlen(n) } }, .name = n }
33 static inline u64 map_root_ino(u64 ino)
35 return ino == 1 ? 4096 : ino;
38 static inline u64 unmap_root_ino(u64 ino)
40 return ino == 4096 ? 1 : ino;
43 static struct stat inode_to_stat(struct bch_fs *c,
44 struct bch_inode_unpacked *bi)
46 return (struct stat) {
47 .st_ino = bi->bi_inum,
48 .st_size = bi->bi_size,
49 .st_mode = bi->bi_mode,
52 .st_nlink = bch2_inode_nlink_get(bi),
53 .st_rdev = bi->bi_dev,
54 .st_blksize = block_bytes(c),
55 .st_blocks = bi->bi_sectors,
56 .st_atim = bch2_time_to_timespec(c, bi->bi_atime),
57 .st_mtim = bch2_time_to_timespec(c, bi->bi_mtime),
58 .st_ctim = bch2_time_to_timespec(c, bi->bi_ctime),
62 static struct fuse_entry_param inode_to_entry(struct bch_fs *c,
63 struct bch_inode_unpacked *bi)
65 return (struct fuse_entry_param) {
67 .generation = bi->bi_generation,
68 .attr = inode_to_stat(c, bi),
69 .attr_timeout = DBL_MAX,
70 .entry_timeout = DBL_MAX,
74 static void bcachefs_fuse_init(void *arg, struct fuse_conn_info *conn)
76 conn->want |= FUSE_CAP_WRITEBACK_CACHE;
78 //conn->want |= FUSE_CAP_POSIX_ACL;
81 static void bcachefs_fuse_destroy(void *arg)
83 struct bch_fs *c = arg;
88 static void bcachefs_fuse_lookup(fuse_req_t req, fuse_ino_t dir,
91 struct bch_fs *c = fuse_req_userdata(req);
92 struct bch_inode_unpacked bi;
93 struct qstr qstr = QSTR(name);
97 dir = map_root_ino(dir);
99 ret = bch2_inode_find_by_inum(c, dir, &bi);
101 fuse_reply_err(req, -ret);
105 struct bch_hash_info hash_info = bch2_hash_info_init(c, &bi);
107 inum = bch2_dirent_lookup(c, dir, &hash_info, &qstr);
113 ret = bch2_inode_find_by_inum(c, inum, &bi);
117 bi.bi_inum = unmap_root_ino(bi.bi_inum);
119 struct fuse_entry_param e = inode_to_entry(c, &bi);
120 fuse_reply_entry(req, &e);
123 fuse_reply_err(req, -ret);
126 static void bcachefs_fuse_getattr(fuse_req_t req, fuse_ino_t inum,
127 struct fuse_file_info *fi)
129 struct bch_fs *c = fuse_req_userdata(req);
130 struct bch_inode_unpacked bi;
134 inum = map_root_ino(inum);
136 ret = bch2_inode_find_by_inum(c, inum, &bi);
138 fuse_reply_err(req, -ret);
142 bi.bi_inum = unmap_root_ino(bi.bi_inum);
144 attr = inode_to_stat(c, &bi);
145 fuse_reply_attr(req, &attr, DBL_MAX);
148 static void bcachefs_fuse_setattr(fuse_req_t req, fuse_ino_t inum,
149 struct stat *attr, int to_set,
150 struct fuse_file_info *fi)
152 struct bch_fs *c = fuse_req_userdata(req);
153 struct bch_inode_unpacked inode_u;
154 struct btree_trans trans;
155 struct btree_iter *iter;
159 inum = map_root_ino(inum);
161 bch2_trans_init(&trans, c, 0, 0);
163 bch2_trans_begin(&trans);
164 now = bch2_current_time(c);
166 iter = bch2_inode_peek(&trans, &inode_u, inum, BTREE_ITER_INTENT);
167 ret = PTR_ERR_OR_ZERO(iter);
171 if (to_set & FUSE_SET_ATTR_MODE)
172 inode_u.bi_mode = attr->st_mode;
173 if (to_set & FUSE_SET_ATTR_UID)
174 inode_u.bi_uid = attr->st_uid;
175 if (to_set & FUSE_SET_ATTR_GID)
176 inode_u.bi_gid = attr->st_gid;
177 if (to_set & FUSE_SET_ATTR_SIZE)
178 inode_u.bi_size = attr->st_size;
179 if (to_set & FUSE_SET_ATTR_ATIME)
180 inode_u.bi_atime = timespec_to_bch2_time(c, attr->st_atim);
181 if (to_set & FUSE_SET_ATTR_MTIME)
182 inode_u.bi_mtime = timespec_to_bch2_time(c, attr->st_mtim);
183 if (to_set & FUSE_SET_ATTR_ATIME_NOW)
184 inode_u.bi_atime = now;
185 if (to_set & FUSE_SET_ATTR_MTIME_NOW)
186 inode_u.bi_mtime = now;
188 ret = bch2_inode_write(&trans, iter, &inode_u) ?:
189 bch2_trans_commit(&trans, NULL, NULL,
191 BTREE_INSERT_NOFAIL);
196 bch2_trans_exit(&trans);
199 *attr = inode_to_stat(c, &inode_u);
200 fuse_reply_attr(req, attr, DBL_MAX);
202 fuse_reply_err(req, -ret);
206 static void bcachefs_fuse_readlink(fuse_req_t req, fuse_ino_t inum)
208 //struct bch_fs *c = fuse_req_userdata(req);
210 //char *link = malloc();
212 //fuse_reply_readlink(req, link);
215 static int do_create(struct bch_fs *c, u64 dir,
216 const char *name, mode_t mode, dev_t rdev,
217 struct bch_inode_unpacked *new_inode)
219 struct qstr qstr = QSTR(name);
220 struct bch_inode_unpacked dir_u;
222 dir = map_root_ino(dir);
224 bch2_inode_init_early(c, new_inode);
226 return bch2_trans_do(c, NULL, BTREE_INSERT_ATOMIC,
227 bch2_create_trans(&trans,
230 0, 0, mode, rdev, NULL, NULL));
233 static void bcachefs_fuse_mknod(fuse_req_t req, fuse_ino_t dir,
234 const char *name, mode_t mode,
237 struct bch_fs *c = fuse_req_userdata(req);
238 struct bch_inode_unpacked new_inode;
241 ret = do_create(c, dir, name, mode, rdev, &new_inode);
245 struct fuse_entry_param e = inode_to_entry(c, &new_inode);
246 fuse_reply_entry(req, &e);
249 fuse_reply_err(req, -ret);
252 static void bcachefs_fuse_mkdir(fuse_req_t req, fuse_ino_t dir,
253 const char *name, mode_t mode)
255 bcachefs_fuse_mknod(req, dir, name, mode, 0);
258 static void bcachefs_fuse_unlink(fuse_req_t req, fuse_ino_t dir,
261 struct bch_fs *c = fuse_req_userdata(req);
262 struct bch_inode_unpacked dir_u, inode_u;
263 struct qstr qstr = QSTR(name);
266 dir = map_root_ino(dir);
268 ret = bch2_trans_do(c, NULL, BTREE_INSERT_ATOMIC|BTREE_INSERT_NOFAIL,
269 bch2_unlink_trans(&trans, dir, &dir_u,
272 fuse_reply_err(req, -ret);
275 static void bcachefs_fuse_rmdir(fuse_req_t req, fuse_ino_t dir,
278 dir = map_root_ino(dir);
280 bcachefs_fuse_unlink(req, dir, name);
284 static void bcachefs_fuse_symlink(fuse_req_t req, const char *link,
285 fuse_ino_t parent, const char *name)
287 struct bch_fs *c = fuse_req_userdata(req);
291 static void bcachefs_fuse_rename(fuse_req_t req,
292 fuse_ino_t src_dir, const char *srcname,
293 fuse_ino_t dst_dir, const char *dstname,
296 struct bch_fs *c = fuse_req_userdata(req);
297 struct bch_inode_unpacked dst_dir_u, src_dir_u;
298 struct bch_inode_unpacked src_inode_u, dst_inode_u;
299 struct qstr dst_name = QSTR(srcname);
300 struct qstr src_name = QSTR(dstname);
303 src_dir = map_root_ino(src_dir);
304 dst_dir = map_root_ino(dst_dir);
306 /* XXX handle overwrites */
307 ret = bch2_trans_do(c, NULL, BTREE_INSERT_ATOMIC,
308 bch2_rename_trans(&trans,
311 &src_inode_u, &dst_inode_u,
312 &src_name, &dst_name,
315 fuse_reply_err(req, -ret);
318 static void bcachefs_fuse_link(fuse_req_t req, fuse_ino_t inum,
319 fuse_ino_t newparent, const char *newname)
321 struct bch_fs *c = fuse_req_userdata(req);
322 struct bch_inode_unpacked inode_u;
323 struct qstr qstr = QSTR(newname);
326 ret = bch2_trans_do(c, NULL, BTREE_INSERT_ATOMIC,
327 bch2_link_trans(&trans, newparent,
328 inum, &inode_u, &qstr));
331 struct fuse_entry_param e = inode_to_entry(c, &inode_u);
332 fuse_reply_entry(req, &e);
334 fuse_reply_err(req, -ret);
338 static void bcachefs_fuse_open(fuse_req_t req, fuse_ino_t inum,
339 struct fuse_file_info *fi)
341 fi->direct_io = false;
342 fi->keep_cache = true;
343 fi->cache_readdir = true;
345 fuse_reply_open(req, fi);
348 static void userbio_init(struct bio *bio, struct bio_vec *bv,
349 void *buf, size_t size)
351 bio_init(bio, bv, 1);
352 bio->bi_iter.bi_size = size;
358 static int get_inode_io_opts(struct bch_fs *c, u64 inum,
359 struct bch_io_opts *opts)
361 struct bch_inode_unpacked inode;
362 if (bch2_inode_find_by_inum(c, inum, &inode))
365 *opts = bch2_opts_to_inode_opts(c->opts);
366 bch2_io_opts_apply(opts, bch2_inode_opts_get(&inode));
370 static void bcachefs_fuse_read_endio(struct bio *bio)
372 closure_put(bio->bi_private);
375 static void bcachefs_fuse_read(fuse_req_t req, fuse_ino_t inum,
376 size_t size, off_t offset,
377 struct fuse_file_info *fi)
379 struct bch_fs *c = fuse_req_userdata(req);
381 if ((size|offset) & block_bytes(c)) {
382 fuse_reply_err(req, EINVAL);
386 struct bch_io_opts io_opts;
387 if (get_inode_io_opts(c, inum, &io_opts)) {
388 fuse_reply_err(req, ENOENT);
392 void *buf = aligned_alloc(max(PAGE_SIZE, size), size);
394 fuse_reply_err(req, ENOMEM);
398 struct bch_read_bio rbio;
402 closure_init_stack(&cl);
403 userbio_init(&rbio.bio, &bv, buf, size);
404 bio_set_op_attrs(&rbio.bio, REQ_OP_READ, REQ_SYNC);
405 rbio.bio.bi_iter.bi_sector = offset >> 9;
406 rbio.bio.bi_end_io = bcachefs_fuse_read_endio;
407 rbio.bio.bi_private = &cl;
409 bch2_read(c, rbio_init(&rbio.bio, io_opts), inum);
413 if (likely(!rbio.bio.bi_status)) {
414 fuse_reply_buf(req, buf, size);
416 fuse_reply_err(req, -blk_status_to_errno(rbio.bio.bi_status));
422 static void bcachefs_fuse_write(fuse_req_t req, fuse_ino_t inum,
423 const char *buf, size_t size,
425 struct fuse_file_info *fi)
427 struct bch_fs *c = fuse_req_userdata(req);
428 struct bch_io_opts io_opts;
429 struct bch_write_op op;
433 if ((size|offset) & block_bytes(c)) {
434 fuse_reply_err(req, EINVAL);
438 closure_init_stack(&cl);
440 if (get_inode_io_opts(c, inum, &io_opts)) {
441 fuse_reply_err(req, ENOENT);
445 bch2_write_op_init(&op, c, io_opts);
446 op.write_point = writepoint_hashed(0);
447 op.nr_replicas = io_opts.data_replicas;
448 op.target = io_opts.foreground_target;
449 op.pos = POS(inum, offset >> 9);
451 userbio_init(&op.wbio.bio, &bv, (void *) buf, size);
452 bio_set_op_attrs(&op.wbio.bio, REQ_OP_WRITE, REQ_SYNC);
454 if (bch2_disk_reservation_get(c, &op.res, size >> 9,
455 op.nr_replicas, 0)) {
456 /* XXX: use check_range_allocated like dio write path */
457 fuse_reply_err(req, ENOSPC);
461 closure_call(&op.cl, bch2_write, NULL, &cl);
465 fuse_reply_write(req, (size_t) op.written << 9);
468 fuse_reply_err(req, -op.error);
473 static void bcachefs_fuse_flush(fuse_req_t req, fuse_ino_t inum,
474 struct fuse_file_info *fi)
476 struct bch_fs *c = fuse_req_userdata(req);
479 static void bcachefs_fuse_release(fuse_req_t req, fuse_ino_t inum,
480 struct fuse_file_info *fi)
482 struct bch_fs *c = fuse_req_userdata(req);
485 static void bcachefs_fuse_fsync(fuse_req_t req, fuse_ino_t inum, int datasync,
486 struct fuse_file_info *fi)
488 struct bch_fs *c = fuse_req_userdata(req);
491 static void bcachefs_fuse_opendir(fuse_req_t req, fuse_ino_t inum,
492 struct fuse_file_info *fi)
494 struct bch_fs *c = fuse_req_userdata(req);
498 struct fuse_dir_entry {
504 struct fuse_dir_context {
505 struct dir_context ctx;
510 struct fuse_dir_entry *prev;
513 static int fuse_send_dir_entry(struct fuse_dir_context *ctx, loff_t pos)
515 struct fuse_dir_entry *de = ctx->prev;
518 struct stat statbuf = {
519 .st_ino = unmap_root_ino(de->ino),
520 .st_mode = de->type << 12,
523 size_t len = fuse_add_direntry(ctx->req, ctx->buf, ctx->bufsize,
524 de->name, &statbuf, pos);
528 if (len > ctx->bufsize)
537 static int fuse_filldir(struct dir_context *_ctx,
538 const char *name, int namelen,
539 loff_t pos, u64 ino, unsigned type)
541 struct fuse_dir_context *ctx =
542 container_of(_ctx, struct fuse_dir_context, ctx);
544 fuse_log(FUSE_LOG_DEBUG, "fuse_filldir(ctx={.ctx={.pos=%llu}}, "
545 "name=%s, namelen=%d, pos=%lld, dir=%llu, type=%u)\n",
546 ctx->ctx.pos, name, namelen, pos, ino, type);
549 * We have to emit directory entries after reading the next entry,
550 * because the previous entry contains a pointer to next.
553 int ret = fuse_send_dir_entry(ctx, pos);
558 struct fuse_dir_entry *cur = malloc(sizeof *cur + namelen + 1);
561 memcpy(cur->name, name, namelen);
562 cur->name[namelen] = 0;
569 static bool handle_dots(struct fuse_dir_context *ctx, fuse_ino_t dir)
573 if (ctx->ctx.pos == 0) {
574 ret = fuse_filldir(&ctx->ctx, ".", 1, ctx->ctx.pos,
575 unmap_root_ino(dir), DT_DIR);
581 if (ctx->ctx.pos == 1) {
582 ret = fuse_filldir(&ctx->ctx, "..", 2, ctx->ctx.pos,
583 /*TODO: parent*/ 1, DT_DIR);
592 static void bcachefs_fuse_readdir(fuse_req_t req, fuse_ino_t dir,
593 size_t size, off_t off,
594 struct fuse_file_info *fi)
596 struct bch_fs *c = fuse_req_userdata(req);
597 struct bch_inode_unpacked bi;
598 char *buf = calloc(size, 1);
599 struct fuse_dir_context ctx = {
600 .ctx.actor = fuse_filldir,
608 fuse_log(FUSE_LOG_DEBUG, "bcachefs_fuse_readdir(dir=%llu, size=%zu, "
609 "off=%lld)\n", dir, size, off);
611 dir = map_root_ino(dir);
613 ret = bch2_inode_find_by_inum(c, dir, &bi);
617 if (!S_ISDIR(bi.bi_mode)) {
622 if (!handle_dots(&ctx, dir))
625 ret = bch2_readdir(c, dir, &ctx.ctx);
629 * If we have something to send, the error above doesn't matter.
631 * Alternatively, if this send fails, but we previously sent something,
632 * then this is a success.
635 ret = fuse_send_dir_entry(&ctx, ctx.ctx.pos);
636 if (ret && ctx.buf != buf)
641 fuse_log(FUSE_LOG_DEBUG, "bcachefs_fuse_readdir reply %zd\n",
643 fuse_reply_buf(req, buf, ctx.buf - buf);
645 fuse_reply_err(req, -ret);
652 static void bcachefs_fuse_readdirplus(fuse_req_t req, fuse_ino_t dir,
653 size_t size, off_t off,
654 struct fuse_file_info *fi)
659 static void bcachefs_fuse_releasedir(fuse_req_t req, fuse_ino_t inum,
660 struct fuse_file_info *fi)
662 struct bch_fs *c = fuse_req_userdata(req);
665 static void bcachefs_fuse_fsyncdir(fuse_req_t req, fuse_ino_t inum, int datasync,
666 struct fuse_file_info *fi)
668 struct bch_fs *c = fuse_req_userdata(req);
672 static void bcachefs_fuse_statfs(fuse_req_t req, fuse_ino_t inum)
674 struct bch_fs *c = fuse_req_userdata(req);
675 struct bch_fs_usage_short usage = bch2_fs_usage_read_short(c);
676 unsigned shift = c->block_bits;
677 struct statvfs statbuf = {
678 .f_bsize = block_bytes(c),
679 .f_frsize = block_bytes(c),
680 .f_blocks = usage.capacity >> shift,
681 .f_bfree = (usage.capacity - usage.used) >> shift,
682 //.f_bavail = statbuf.f_bfree,
683 .f_files = usage.nr_inodes,
685 .f_namemax = BCH_NAME_MAX,
688 fuse_reply_statfs(req, &statbuf);
692 static void bcachefs_fuse_setxattr(fuse_req_t req, fuse_ino_t inum,
693 const char *name, const char *value,
694 size_t size, int flags)
696 struct bch_fs *c = fuse_req_userdata(req);
699 static void bcachefs_fuse_getxattr(fuse_req_t req, fuse_ino_t inum,
700 const char *name, size_t size)
702 struct bch_fs *c = fuse_req_userdata(req);
704 fuse_reply_xattr(req, );
707 static void bcachefs_fuse_listxattr(fuse_req_t req, fuse_ino_t inum, size_t size)
709 struct bch_fs *c = fuse_req_userdata(req);
712 static void bcachefs_fuse_removexattr(fuse_req_t req, fuse_ino_t inum,
715 struct bch_fs *c = fuse_req_userdata(req);
719 static void bcachefs_fuse_create(fuse_req_t req, fuse_ino_t dir,
720 const char *name, mode_t mode,
721 struct fuse_file_info *fi)
723 struct bch_fs *c = fuse_req_userdata(req);
724 struct bch_inode_unpacked new_inode;
727 ret = do_create(c, dir, name, mode, 0, &new_inode);
731 struct fuse_entry_param e = inode_to_entry(c, &new_inode);
732 fuse_reply_create(req, &e, fi);
735 fuse_reply_err(req, -ret);
740 static void bcachefs_fuse_write_buf(fuse_req_t req, fuse_ino_t inum,
741 struct fuse_bufvec *bufv, off_t off,
742 struct fuse_file_info *fi)
744 struct bch_fs *c = fuse_req_userdata(req);
747 static void bcachefs_fuse_fallocate(fuse_req_t req, fuse_ino_t inum, int mode,
748 off_t offset, off_t length,
749 struct fuse_file_info *fi)
751 struct bch_fs *c = fuse_req_userdata(req);
755 static const struct fuse_lowlevel_ops bcachefs_fuse_ops = {
756 .init = bcachefs_fuse_init,
757 .destroy = bcachefs_fuse_destroy,
758 .lookup = bcachefs_fuse_lookup,
759 .getattr = bcachefs_fuse_getattr,
760 .setattr = bcachefs_fuse_setattr,
761 .readlink = bcachefs_fuse_readlink,
762 .mknod = bcachefs_fuse_mknod,
763 .mkdir = bcachefs_fuse_mkdir,
764 .unlink = bcachefs_fuse_unlink,
765 .rmdir = bcachefs_fuse_rmdir,
766 //.symlink = bcachefs_fuse_symlink,
767 .rename = bcachefs_fuse_rename,
768 .link = bcachefs_fuse_link,
769 .open = bcachefs_fuse_open,
770 .read = bcachefs_fuse_read,
771 .write = bcachefs_fuse_write,
772 //.flush = bcachefs_fuse_flush,
773 //.release = bcachefs_fuse_release,
774 //.fsync = bcachefs_fuse_fsync,
775 //.opendir = bcachefs_fuse_opendir,
776 .readdir = bcachefs_fuse_readdir,
777 //.readdirplus = bcachefs_fuse_readdirplus,
778 //.releasedir = bcachefs_fuse_releasedir,
779 //.fsyncdir = bcachefs_fuse_fsyncdir,
780 .statfs = bcachefs_fuse_statfs,
781 //.setxattr = bcachefs_fuse_setxattr,
782 //.getxattr = bcachefs_fuse_getxattr,
783 //.listxattr = bcachefs_fuse_listxattr,
784 //.removexattr = bcachefs_fuse_removexattr,
785 .create = bcachefs_fuse_create,
789 .getlk = bcachefs_fuse_getlk,
790 .setlk = bcachefs_fuse_setlk,
792 //.write_buf = bcachefs_fuse_write_buf,
793 //.fallocate = bcachefs_fuse_fallocate,
798 * Setup and command parsing.
807 static void bf_context_free(struct bf_context *ctx)
811 free(ctx->devices_str);
812 for (i = 0; i < ctx->nr_devices; ++i)
813 free(ctx->devices[i]);
817 static struct fuse_opt bf_opts[] = {
822 * Fuse option parsing helper -- returning 0 means we consumed the argument, 1
825 static int bf_opt_proc(void *data, const char *arg, int key,
826 struct fuse_args *outargs)
828 struct bf_context *ctx = data;
831 case FUSE_OPT_KEY_NONOPT:
832 /* Just extract the first non-option string. */
833 if (!ctx->devices_str) {
834 ctx->devices_str = strdup(arg);
844 * dev1:dev2 -> [ dev1, dev2 ]
847 static void tokenize_devices(struct bf_context *ctx)
849 char *devices_str = strdup(ctx->devices_str);
850 char *devices_tmp = devices_str;
851 char **devices = NULL;
855 while ((dev = strsep(&devices_tmp, ":"))) {
856 if (strlen(dev) > 0) {
857 devices = realloc(devices, (nr + 1) * sizeof *devices);
858 devices[nr] = strdup(dev);
864 devices = malloc(sizeof *devices);
865 devices[0] = strdup(ctx->devices_str);
869 ctx->devices = devices;
870 ctx->nr_devices = nr;
875 static void usage(char *argv[])
877 printf("Usage: %s fusemount [options] <dev>[:dev2:...] <mountpoint>\n",
882 int cmd_fusemount(int argc, char *argv[])
884 struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
885 struct bch_opts bch_opts = bch2_opts_empty();
886 struct bf_context ctx = { 0 };
887 struct bch_fs *c = NULL;
890 /* Parse arguments. */
891 if (fuse_opt_parse(&args, &ctx, bf_opts, bf_opt_proc) < 0)
892 die("fuse_opt_parse err: %m");
894 struct fuse_cmdline_opts fuse_opts;
895 if (fuse_parse_cmdline(&args, &fuse_opts) < 0)
896 die("fuse_parse_cmdline err: %m");
898 if (fuse_opts.show_help) {
901 fuse_lowlevel_help();
905 if (fuse_opts.show_version) {
906 /* TODO: Show bcachefs version. */
907 printf("FUSE library version %s\n", fuse_pkgversion());
908 fuse_lowlevel_version();
912 if (!fuse_opts.mountpoint) {
914 printf("Please supply a mountpoint.\n");
918 if (!ctx.devices_str) {
920 printf("Please specify a device or device1:device2:...\n");
924 tokenize_devices(&ctx);
927 printf("Opening bcachefs filesystem on:\n");
928 for (i = 0; i < ctx.nr_devices; ++i)
929 printf("\t%s\n", ctx.devices[i]);
931 c = bch2_fs_open(ctx.devices, ctx.nr_devices, bch_opts);
933 die("error opening %s: %s", ctx.devices_str,
934 strerror(-PTR_ERR(c)));
937 struct fuse_session *se =
938 fuse_session_new(&args, &bcachefs_fuse_ops,
939 sizeof(bcachefs_fuse_ops), c);
941 die("fuse_lowlevel_new err: %m");
943 if (fuse_set_signal_handlers(se) < 0)
944 die("fuse_set_signal_handlers err: %m");
946 if (fuse_session_mount(se, fuse_opts.mountpoint))
947 die("fuse_mount err: %m");
949 fuse_daemonize(fuse_opts.foreground);
951 ret = fuse_session_loop(se);
954 fuse_session_unmount(se);
955 fuse_remove_signal_handlers(se);
956 fuse_session_destroy(se);
959 free(fuse_opts.mountpoint);
960 fuse_opt_free_args(&args);
961 bf_context_free(&ctx);