aboutsummaryrefslogtreecommitdiffstats
path: root/community/fuse-exfat/0001-allow-command-line-argument-order-used-by-mount-8.patch
blob: e2dc19a465d13e0d0c1abe5ee4e78c6ea7076915 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
From 49f3e46bb8b2f23b3267a70318605adf50b5903f Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Sat, 29 Sep 2018 16:54:33 +0300
Subject: [PATCH] allow command line argument order used by mount(8)

The mount spec and directory are passed as the first and second
arguments to the helper, followed by the options.

The current implementation works on glibc but fails on POSIX-conforming
C libraries such as musl.
---
 fuse/main.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/fuse/main.c b/fuse/main.c
index c645390..50b6787 100644
--- a/fuse/main.c
+++ b/fuse/main.c
@@ -512,9 +512,17 @@ static int fuse_exfat_main(char* mount_options, char* mount_point)
 			&fuse_exfat_ops, NULL);
 }
 
+static void read_arg(char **param, int *argc, char ***argv) {
+	if (!*param && *argc > optind && (*argv)[optind][0] != '-') {
+		*param = (*argv)[optind];
+		((*argv)++)[1] = (*argv)[0];
+		(*argc)--;
+	}
+}
+
 int main(int argc, char* argv[])
 {
-	const char* spec = NULL;
+	char* spec = NULL;
 	char* mount_point = NULL;
 	char* fuse_options;
 	char* exfat_options;
@@ -523,6 +531,9 @@ int main(int argc, char* argv[])
 
 	printf("FUSE exfat %s\n", VERSION);
 
+	read_arg(&spec, &argc, &argv);
+	read_arg(&mount_point, &argc, &argv);
+
 	fuse_options = strdup("allow_other,"
 #if defined(__linux__) || defined(__FreeBSD__)
 			"big_writes,"
@@ -573,15 +584,16 @@ int main(int argc, char* argv[])
 			usage(argv[0]);
 			break;
 		}
+
+		read_arg(&spec, &argc, &argv);
+		read_arg(&mount_point, &argc, &argv);
 	}
-	if (argc - optind != 2)
+	if (!mount_point || argc > optind)
 	{
 		free(exfat_options);
 		free(fuse_options);
 		usage(argv[0]);
 	}
-	spec = argv[optind];
-	mount_point = argv[optind + 1];
 
 	if (exfat_mount(&ef, spec, exfat_options) != 0)
 	{
-- 
2.14.4