X-Git-Url: http://git.osdn.net/view?p=android-x86%2Fexternal-exfat.git;a=blobdiff_plain;f=fuse%2Fmain.c;h=6d566d9f628bdb9c63fd6a2b4040fac4533cc690;hp=30239e257b0ca1c2aa3bcb4e2d187db775ba6aa3;hb=1d97b365a8cc33a0f3c22d16f737a5498f9f795b;hpb=ad86ee6bf77fd74437c48bd41988fe8a8914d466 diff --git a/fuse/main.c b/fuse/main.c index 30239e2..6d566d9 100644 --- a/fuse/main.c +++ b/fuse/main.c @@ -501,20 +501,17 @@ static char* add_fuse_options(char* options, const char* spec, bool ro) return options; } -static int fuse_exfat_main(char* mount_options, char* mount_point) -{ - char* argv[] = {"exfat", "-s", "-o", mount_options, mount_point, NULL}; - return fuse_main(sizeof(argv) / sizeof(argv[0]) - 1, argv, - &fuse_exfat_ops, NULL); -} - int main(int argc, char* argv[]) { + struct fuse_args mount_args = FUSE_ARGS_INIT(0, NULL); + struct fuse_args newfs_args = FUSE_ARGS_INIT(0, NULL); const char* spec = NULL; - char* mount_point = NULL; + const char* mount_point = NULL; char* mount_options; + int debug = 0; + struct fuse_chan* fc = NULL; + struct fuse* fh = NULL; int opt; - int rc; printf("FUSE exfat %s\n", VERSION); @@ -530,9 +527,7 @@ int main(int argc, char* argv[]) switch (opt) { case 'd': - mount_options = add_option(mount_options, "debug", NULL); - if (mount_options == NULL) - return 1; + debug = 1; break; case 'n': break; @@ -574,9 +569,70 @@ int main(int argc, char* argv[]) return 1; } - /* let FUSE do all its wizardry */ - rc = fuse_exfat_main(mount_options, mount_point); + /* create arguments for fuse_mount() */ + if (fuse_opt_add_arg(&mount_args, "exfat") != 0 || + fuse_opt_add_arg(&mount_args, "-o") != 0 || + fuse_opt_add_arg(&mount_args, mount_options) != 0) + { + exfat_unmount(&ef); + free(mount_options); + return 1; + } free(mount_options); - return rc; + + /* create FUSE mount point */ + fc = fuse_mount(mount_point, &mount_args); + fuse_opt_free_args(&mount_args); + if (fc == NULL) + { + exfat_unmount(&ef); + return 1; + } + + /* create arguments for fuse_new() */ + if (fuse_opt_add_arg(&newfs_args, "") != 0 || + (debug && fuse_opt_add_arg(&newfs_args, "-d") != 0)) + { + fuse_unmount(mount_point, fc); + exfat_unmount(&ef); + return 1; + } + + /* create new FUSE file system */ + fh = fuse_new(fc, &newfs_args, &fuse_exfat_ops, + sizeof(struct fuse_operations), NULL); + fuse_opt_free_args(&newfs_args); + if (fh == NULL) + { + fuse_unmount(mount_point, fc); + exfat_unmount(&ef); + return 1; + } + + /* exit session on HUP, TERM and INT signals and ignore PIPE signal */ + if (fuse_set_signal_handlers(fuse_get_session(fh)) != 0) + { + fuse_unmount(mount_point, fc); + fuse_destroy(fh); + exfat_unmount(&ef); + exfat_error("failed to set signal handlers"); + return 1; + } + + /* go to background (unless "-d" option is passed) and run FUSE + main loop */ + if (fuse_daemonize(debug) == 0) + { + if (fuse_loop(fh) != 0) + exfat_error("FUSE loop failure"); + } + else + exfat_error("failed to daemonize"); + + fuse_remove_signal_handlers(fuse_get_session(fh)); + /* note that fuse_unmount() must be called BEFORE fuse_destroy() */ + fuse_unmount(mount_point, fc); + fuse_destroy(fh); + return 0; }