From fdd1b9b4ecaf53c5e393d1e445ed8d7af02d5a96 Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Thu, 21 Jun 2007 13:48:07 +0000 Subject: Add fs subtype support to mount.fuse --- util/mount.fuse.c | 70 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 15 deletions(-) (limited to 'util/mount.fuse.c') diff --git a/util/mount.fuse.c b/util/mount.fuse.c index d156009..4cc0394 100644 --- a/util/mount.fuse.c +++ b/util/mount.fuse.c @@ -6,7 +6,6 @@ static char *progname; - static char *xstrdup(const char *s) { char *t = strdup(s); @@ -54,37 +53,66 @@ static void add_arg(char **cmdp, const char *opt) int main(int argc, char *argv[]) { - char *type; + char *type = NULL; char *source; const char *mountpoint; + char *basename; char *options = NULL; char *command = NULL; char *setuid = NULL; int i; progname = argv[0]; + basename = strrchr(argv[0], '/'); + if (basename) + basename++; + else + basename = argv[0]; + + if (strncmp(basename, "mount.fuse.", 11) == 0) + type = basename + 11; + if (strncmp(basename, "mount.fuseblk.", 14) == 0) + type = basename + 14; + + if (type && !type[0]) + type = NULL; + if (argc < 3) { - fprintf(stderr, - "usage: %s type#[source] mountpoint [-o opt[,opts...]]\n", - progname); + fprintf(stderr, "usage: %s %s destination [-t type] [-o opt[,opts...]]\n", + progname, type ? "source" : "type#[source]"); exit(1); } - type = xstrdup(argv[1]); - source = strchr(type, '#'); - if (source) - *source++ = '\0'; + source = argv[1]; + if (!source[0]) + source = NULL; - if (!type[0]) { - fprintf(stderr, "%s: empty filesystem type\n", progname); - exit(1); - } mountpoint = argv[2]; for (i = 3; i < argc; i++) { - if (strcmp(argv[i], "-v") == 0) + if (strcmp(argv[i], "-v") == 0) { continue; - if (strcmp(argv[i], "-o") == 0) { + } else if (strcmp(argv[i], "-t") == 0) { + i++; + + if (i == argc) { + fprintf(stderr, + "%s: missing argument to option '-t'\n", progname); + exit(1); + } + type = argv[i]; + if (strncmp(type, "fuse.", 5) == 0) + type += 5; + else if (strncmp(type, "fuseblk.", 8) == 0) + type += 8; + + if (!type[0]) { + fprintf(stderr, + "%s: empty type given as argument to option '-t'\n", + progname); + exit(1); + } + } else if (strcmp(argv[i], "-o") == 0) { char *opts; char *opt; i++; @@ -122,6 +150,18 @@ int main(int argc, char *argv[]) } } + if (!type) { + type = xstrdup(source); + source = strchr(type, '#'); + if (source) + *source++ = '\0'; + + if (!type[0]) { + fprintf(stderr, "%s: empty filesystem type\n", progname); + exit(1); + } + } + add_arg(&command, type); if (source) add_arg(&command, source); -- cgit v1.2.3