blob: a16c4b1ceb987dbe16231b0cc5579215c7bfec7b [file] [log] [blame]
Patrick Williamsb48b7b42016-08-17 15:04:38 -05001Kept to help with spaces in the mount path
2
3Upstream-Status: Backport
4
5Linux mangles spaces in mount points by changing them to an octal string
6of '\040'. So lets scan the mount point and fix it up by replacing all
7occurrences off '\0##' with the ASCII value of 0##. Requires a writable
8string as input as we mangle in place. Some of this was taken from the
9util-linux package.
10
11Signed-off-by: Morgan Little <morgan.little@windriver.com>
12--- eject/eject.c.ori 2007-06-24 00:08:44 -0700
13+++ eject/eject.c 2007-06-24 00:12:44 -0700
14@@ -370,6 +370,30 @@
15
16
17 /*
18+ * Linux mangles spaces in mount points by changing them to an octal string
19+ * of '\040'. So lets scan the mount point and fix it up by replacing all
20+ * occurrences off '\0##' with the ASCII value of 0##. Requires a writable
21+ * string as input as we mangle in place. Some of this was taken from the
22+ * util-linux package.
23+ */
24+#define octalify(a) ((a) & 7)
25+#define tooctal(s) (64*octalify(s[1]) + 8*octalify(s[2]) + octalify(s[3]))
26+#define isoctal(a) (((a) & ~7) == '0')
27+static char *DeMangleMount(char *s)
28+{
29+ char *tmp = s;
30+ while ((tmp = strchr(tmp, '\\')) != NULL) {
31+ if (isoctal(tmp[1]) && isoctal(tmp[2]) && isoctal(tmp[3])) {
32+ tmp[0] = tooctal(tmp);
33+ memmove(tmp+1, tmp+4, strlen(tmp)-3);
34+ }
35+ ++tmp;
36+ }
37+ return s;
38+}
39+
40+
41+/*
42 * Given name, such as foo, see if any of the following exist:
43 *
44 * foo (if foo starts with '.' or '/')
45@@ -884,8 +908,8 @@
46 if (((strcmp(s1, name) == 0) || (strcmp(s2, name) == 0)) ||
47 ((maj != -1) && (maj == mtabmaj) && (min == mtabmin))) {
48 FCLOSE(fp);
49- *deviceName = strdup(s1);
50- *mountName = strdup(s2);
51+ *deviceName = DeMangleMount(strdup(s1));
52+ *mountName = DeMangleMount(strdup(s2));
53 return 1;
54 }
55 }
56@@ -928,8 +952,8 @@
57 rc = sscanf(line, "%1023s %1023s", s1, s2);
58 if (rc >= 2 && s1[0] != '#' && strcmp(s2, name) == 0) {
59 FCLOSE(fp);
60- *deviceName = strdup(s1);
61- *mountName = strdup(s2);
62+ *deviceName = DeMangleMount(strdup(s1));
63+ *mountName = DeMangleMount(strdup(s2));
64 return 1;
65 }
66 }