Diff of /util/mount.fuse.c [e6e7a2] .. [6ca269] Maximize Restore

  Switch to side-by-side view

--- a/util/mount.fuse.c
+++ b/util/mount.fuse.c
@@ -5,8 +5,6 @@
   This program can be distributed under the terms of the GNU GPL.
   See the file COPYING.
 */
-
-#include <config.h>
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -61,33 +59,43 @@
 	*cmdp = cmd;
 }
 
-static char *add_option(const char *opt, char *options)
+static char *add_option(char *options, const char *separator, const char *opt)
 {
 	int oldlen = options ? strlen(options) : 0;
 
-	options = xrealloc(options, oldlen + 1 + strlen(opt) + 1);
+	options = xrealloc(options, oldlen + strlen(separator) + strlen(opt) + 1);
 	if (!oldlen)
 		strcpy(options, opt);
 	else {
-		strcat(options, ",");
+		strcat(options, separator);
 		strcat(options, opt);
 	}
 	return options;
 }
 
+static void fail(void)
+{
+	fprintf(stderr,
+		"usage: %s %s destination [-t type] [-o opt[,opts...]]\n",
+		progname, "[source|type#[source]]");
+	exit(1);
+}
+
 int main(int argc, char *argv[])
 {
 	char *type = NULL;
-	char *source;
-	const char *mountpoint;
+	char *source = NULL;
+	const char *mountpoint = NULL;
 	char *basename;
 	char *options = NULL;
 	char *command = NULL;
 	char *setuid = NULL;
+	char *literals = NULL;
 	int i;
 	int dev = 1;
 	int suid = 1;
-
+	int literal = 0;
+	
 	progname = argv[0];
 	basename = strrchr(argv[0], '/');
 	if (basename)
@@ -103,21 +111,22 @@
 	if (type && !type[0])
 		type = NULL;
 
-	if (argc < 3) {
-		fprintf(stderr,
-			"usage: %s %s destination [-t type] [-o opt[,opts...]]\n",
-			progname, type ? "source" : "type#[source]");
-		exit(1);
-	}
-
-	source = argv[1];
-	if (!source[0])
-		source = NULL;
-
-	mountpoint = argv[2];
-
-	for (i = 3; i < argc; i++) {
-		if (strcmp(argv[i], "-v") == 0) {
+	for (i = 1; i < argc; i++) {
+		fprintf(stderr, "parameter %d: %s\n", i, argv[i]);
+		if (literal) {
+			fprintf(stderr, "literal set.\n");
+			literals = add_option(literals, " ", argv[i]);
+			fprintf(stderr, "literals: \'%s\'\n", literals);
+		} else if (argv[i][0] != '-') {
+		    if (!source)
+				source = argv[i];
+			else if (!mountpoint)
+				mountpoint = argv[i];
+			else {
+				fprintf(stderr, "Expected two non-option arguments: source and mountpoint.\n");
+				fail();
+			}
+		} else if (strcmp(argv[i], "-v") == 0) {
 			continue;
 		} else if (strcmp(argv[i], "-t") == 0) {
 			i++;
@@ -126,7 +135,7 @@
 				fprintf(stderr,
 					"%s: missing argument to option '-t'\n",
 					progname);
-				exit(1);
+				fail();
 			}
 			type = argv[i];
 			if (strncmp(type, "fuse.", 5) == 0)
@@ -138,7 +147,7 @@
 				fprintf(stderr,
 					"%s: empty type given as argument to option '-t'\n",
 					progname);
-				exit(1);
+				fail();
 			}
 		} else	if (strcmp(argv[i], "-o") == 0) {
 			char *opts;
@@ -173,18 +182,30 @@
 						dev = 0;
 					else if (strcmp(opt, "nosuid") == 0)
 						suid = 0;
-
-					options = add_option(opt, options);
+					if (opt[0] == '-')
+						literals = add_option(literals, " ", opt);
+					else
+						options = add_option(options, ",", opt);
 				}
 				opt = strtok(NULL, ",");
 			}
+		} else if (strcmp(argv[i], "--") == 0) {
+			literal = 1;
 		}
 	}
 
+	if (!mountpoint) {
+		fprintf(stderr,
+			"Mountpoint not set.");
+		fail();
+	}
+	
+	if (!source[0])
+		source = NULL;
 	if (dev)
-		options = add_option("dev", options);
+		options = add_option(options, ",", "dev");
 	if (suid)
-		options = add_option("suid", options);
+		options = add_option(options, ",", "suid");
 
 	if (!type) {
 		if (source) {
@@ -195,11 +216,11 @@
 			if (!type[0]) {
 				fprintf(stderr, "%s: empty filesystem type\n",
 					progname);
-				exit(1);
+				fail();
 			}
 		} else {
 			fprintf(stderr, "%s: empty source\n", progname);
-			exit(1);
+			fail();
 		}
 	}
 
@@ -210,6 +231,9 @@
 	if (options) {
 		add_arg(&command, "-o");
 		add_arg(&command, options);
+	}
+	if (literals) {
+		add_arg(&command, literals);
 	}
 
 	if (setuid && setuid[0]) {
@@ -225,6 +249,7 @@
 		setenv("HOME", "/root", 0);
 	}
 
+	fprintf(stderr, "executing /bin/sh -c %s\n", command);
 	execl("/bin/sh", "/bin/sh", "-c", command, NULL);
 	fprintf(stderr, "%s: failed to execute /bin/sh: %s\n", progname,
 		strerror(errno));