From 8df3f98f057fa421abf03a876488fad077727fdb Mon Sep 17 00:00:00 2001 From: lace <> Date: Tue, 20 Dec 2005 00:33:54 +0000 Subject: [PATCH] Provide more optimal default FUSE library options. Drop forgotten 'struct captive_options' redeclaration. Fixed mounting the image really read/write even if only "-o rw" appended. Provide proper devicename for FUSE/mtab. - Fixed double-mount bug during machine boot. --- src/client/fuse/main.c | 60 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/src/client/fuse/main.c b/src/client/fuse/main.c index 8ee0dcd..50942da 100644 --- a/src/client/fuse/main.c +++ b/src/client/fuse/main.c @@ -54,6 +54,8 @@ /* Config: */ /* FIXME: Dupe with libcaptive/client/options.c */ #define DEFAULT_SYSLOG_FACILITY LOG_DAEMON +/* Each element must be preceded by a comma (',')! */ +#define LIBFUSE_ADDONS ",default_permissions,kernel_cache" CaptiveVfsObject *capfuse_captive_vfs_object; @@ -116,12 +118,13 @@ int main(int argc,char **argv) { poptContext context; int errint; -int rest_argc; +int rest_argc,i; const char **rest_argv,**csp; struct captive_options options; const char **capfuse_argv; const char *program_name=argv[0]; const char *sandbox_server_argv0=G_STRINGIFY(SBINDIR) "/captive-sandbox-server"; +const char *image_filename; g_log_set_always_fatal(~(0 |G_LOG_LEVEL_MESSAGE @@ -141,20 +144,6 @@ const char *sandbox_server_argv0=G_STRINGIFY(SBINDIR) "/captive-sandbox-server"; /* Initialize GObject subsystem of GLib. */ g_type_init(); -struct captive_options { - struct captive_options_module filesystem; - enum captive_option_rwmode rwmode; - enum captive_option_media media; - gboolean debug_messages; - GIOChannel *image_iochannel; - GList *load_module; /* of 'struct captive_options_module *' */ - gboolean sandbox; - char **sandbox_server_argv; - gchar *sandbox_server_ior; - gchar *bug_pathname; - int syslog_facility; /* LOG_*; -1 if not used */ - }; - captive_options_init(&options); captive_options=&options; /* for parsing by 'CAPTIVE_POPT_INCLUDE' */ @@ -197,17 +186,38 @@ struct captive_options { captive_options=NULL; /* already parsed by 'CAPTIVE_POPT_INCLUDE' */ + /* Override the (default) Captive options with mount(8) supplied "-o" argument. */ + /* rest_argv[0] is the device now. */ + /* rest_argv[1] is the mountpoint now. */ + if (rest_argc>=4 && !strcmp(rest_argv[2],"-o")) { +const char *cs=rest_argv[3]; + + while (cs&&*cs) { + if ((!strncmp(cs,"ro",2) || !strncmp(cs,"rw",2)) && (cs[2]==',' || !cs[2])) { + if (!strncmp(cs,"ro",2)) + options.rwmode=CAPTIVE_OPTION_RWMODE_RO; + if (!strncmp(cs,"rw",2)) + options.rwmode=CAPTIVE_OPTION_RWMODE_RW; + } + if ((cs=strchr(cs,','))) + cs++; + } + } + /* image_iochannel */ if (rest_argc<1) { g_error(_("File/device disk image pathname command-line argument required")); return EXIT_FAILURE; } g_assert(options.image_iochannel==NULL); + image_filename=rest_argv[0]; + rest_argc--; + rest_argv++; if (!(options.image_iochannel=g_io_channel_new_file( - rest_argv[0], /* filename */ + image_filename, /* filename */ (options.rwmode==CAPTIVE_OPTION_RWMODE_RW ? "r+" : "r"), /* mode */ NULL))) { /* error */ - g_error(_("image_iochannel failed open of: %s"),rest_argv[0]); + g_error(_("image_iochannel failed open of: %s"),image_filename); return EXIT_FAILURE; } @@ -243,14 +253,24 @@ struct captive_options_module *options_module; return EXIT_FAILURE; } captive_options_free(&options); - rest_argc--; - rest_argv++; /* Simulate argv[0] there as it got cut by popt. */ - captive_newn_alloca(capfuse_argv,1+rest_argc+1); + captive_newn_alloca(capfuse_argv,1+rest_argc+1+2); capfuse_argv[0]=argv[0]; memcpy(capfuse_argv+1,rest_argv,sizeof(*rest_argv)*(rest_argc+1)); + for (i=1;capfuse_argv[i];i++) { + if (strcmp(capfuse_argv[i],"-o")) + continue; + capfuse_argv[i+1]=captive_printf_alloca("fsname=%s" LIBFUSE_ADDONS ",%s",image_filename,capfuse_argv[i+1]); + break; + } + if (!capfuse_argv[i]) { + capfuse_argv[i ]="-o"; + capfuse_argv[i+1]=captive_printf_alloca("fsname=%s" LIBFUSE_ADDONS,image_filename); + capfuse_argv[i+2]=NULL; + } + /* FIXFUSE: fuse_main()/fuse_main_real() would be enough for Captive fuse but * the public interface of fuse_main() is too broken. */ -- 1.8.3.1