448 | | argv[fuseArgCount++] = (const char*)"bfs_fuse"; |
449 | | argv[fuseArgCount++] = mntPoint; |
450 | | argv[fuseArgCount++] = (const char*)"-s"; |
451 | | if (gIsDebug) |
452 | | argv[fuseArgCount++] = (const char*)"-d"; |
453 | | |
454 | | initialiseFuseOps(&gFUSEOperations); |
455 | | |
456 | | int ret = fuse_main(fuseArgCount, (char**)argv, &gFUSEOperations, NULL); |
457 | | |
| 448 | static int |
| 449 | unmount_volume(const char* device, const char* mntPoint) |
| 450 | { |
473 | | return ret; |
| 471 | |
| 472 | static int |
| 473 | fssh_fuse_session(const char* device, const char* mntPoint, const char* fsName, |
| 474 | struct fuse_args& fuseArgs) |
| 475 | { |
| 476 | int ret; |
| 477 | |
| 478 | ret = mount_volume(device, mntPoint, fsName); |
| 479 | if (ret != 0) |
| 480 | return ret; |
| 481 | |
| 482 | char* fuseOptions = NULL; |
| 483 | |
| 484 | // default FUSE options |
| 485 | char* fsNameOption = NULL; |
| 486 | if (fuse_opt_add_opt(&fuseOptions, "allow_other") < 0 |
| 487 | || asprintf(&fsNameOption, "fsname=%s", device) < 0 |
| 488 | || fuse_opt_add_opt(&fuseOptions, fsNameOption) < 0) { |
| 489 | unmount_volume(device, mntPoint); |
| 490 | return 1; |
| 491 | } |
| 492 | |
| 493 | struct stat sbuf; |
| 494 | if ((stat(device, &sbuf) == 0) && S_ISBLK(sbuf.st_mode)) { |
| 495 | int blkSize = 512; |
| 496 | fssh_dev_t volumeID = get_volume_id(); |
| 497 | if (volumeID >= 0) { |
| 498 | fssh_fs_info info; |
| 499 | if (_kern_read_fs_info(volumeID, &info) == FSSH_B_OK) |
| 500 | blkSize = info.block_size; |
| 501 | } |
| 502 | |
| 503 | char* blkSizeOption = NULL; |
| 504 | if (fuse_opt_add_opt(&fuseOptions, "blkdev") < 0 |
| 505 | || asprintf(&blkSizeOption, "blksize=%i", blkSize) < 0 |
| 506 | || fuse_opt_add_opt(&fuseOptions, blkSizeOption) < 0) { |
| 507 | unmount_volume(device, mntPoint); |
| 508 | return 1; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | // Run the fuse_main() loop. |
| 513 | if (fuse_opt_add_arg(&fuseArgs, "-s") < 0 |
| 514 | || fuse_opt_add_arg(&fuseArgs, "-o") < 0 |
| 515 | || fuse_opt_add_arg(&fuseArgs, fuseOptions) < 0) { |
| 516 | unmount_volume(device, mntPoint); |
| 517 | return 1; |
| 518 | } |
| 519 | |
| 520 | initialiseFuseOps(&gFUSEOperations); |
| 521 | |
| 522 | int res = fuse_main(fuseArgs.argc, fuseArgs.argv, &gFUSEOperations, NULL); |
| 523 | |
| 524 | ret = unmount_volume(device, mntPoint); |
| 525 | if (ret != 0) |
| 526 | return ret; |
| 527 | |
| 528 | return res; |
494 | | // eat options |
495 | | int argi = 1; |
496 | | while (argi < argc && argv[argi][0] == '-') { |
497 | | const char* arg = argv[argi++]; |
498 | | if (strcmp(arg, "--help") == 0) { |
499 | | print_usage_and_exit(argv[0]); |
500 | | } else if (strcmp(arg, "-d") == 0) { |
| 561 | struct FsConfig* config = (FsConfig*) data; |
| 562 | |
| 563 | switch (key) { |
| 564 | case FUSE_OPT_KEY_NONOPT: |
| 565 | if (!config->device) { |
| 566 | config->device = arg; |
| 567 | return 0; |
| 568 | // don't pass the device path to fuse_main() |
| 569 | } else if (!config->mntPoint) |
| 570 | config->mntPoint = arg; |
| 571 | else |
| 572 | print_usage_and_exit(outArgs->argv[0]); |
| 573 | break; |
| 574 | case KEY_DEBUG: |
| 584 | |
| 585 | int |
| 586 | main(int argc, char* argv[]) |
| 587 | { |
| 588 | struct fuse_args fuseArgs = FUSE_ARGS_INIT(argc, argv); |
| 589 | struct FsConfig config; |
| 590 | memset(&config, 0, sizeof(config)); |
| 591 | const struct fuse_opt fsOptions[] = { |
| 592 | FUSE_OPT_KEY("uhelper=", FUSE_OPT_KEY_DISCARD), |
| 593 | // fuse_main() throws an error about this unknown option |
| 594 | // TODO: do not use fuse_main to mount filesystem, instead use |
| 595 | // fuse_mount, fuse_new, fuse_set_signal_handlers and fuse_loop |
| 596 | FUSE_OPT_KEY("-d", KEY_DEBUG), |
| 597 | FUSE_OPT_KEY("-h", KEY_HELP), |
| 598 | FUSE_OPT_KEY("--help", KEY_HELP), |
| 599 | FUSE_OPT_END |
| 600 | }; |
| 601 | |
| 602 | if (fuse_opt_parse(&fuseArgs, &config, fsOptions, process_options) < 0) |
| 603 | return 1; |
| 604 | |