aboutsummaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-support/eject/eject/eject-2.1.5-spaces.patch
blob: a16c4b1ceb987dbe16231b0cc5579215c7bfec7b (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
Kept to help with spaces in the mount path

Upstream-Status: Backport

Linux mangles spaces in mount points by changing them to an octal string
of '\040'.  So lets scan the mount point and fix it up by replacing all
occurrences off '\0##' with the ASCII value of 0##.  Requires a writable
string as input as we mangle in place.  Some of this was taken from the
util-linux package.

Signed-off-by: Morgan Little <morgan.little@windriver.com>
--- eject/eject.c.ori   2007-06-24 00:08:44 -0700
+++ eject/eject.c       2007-06-24 00:12:44 -0700
@@ -370,6 +370,30 @@
 
 
 /*
+ * Linux mangles spaces in mount points by changing them to an octal string
+ * of '\040'.  So lets scan the mount point and fix it up by replacing all
+ * occurrences off '\0##' with the ASCII value of 0##.  Requires a writable
+ * string as input as we mangle in place.  Some of this was taken from the
+ * util-linux package.
+ */
+#define octalify(a) ((a) & 7)
+#define tooctal(s) (64*octalify(s[1]) + 8*octalify(s[2]) + octalify(s[3]))
+#define isoctal(a) (((a) & ~7) == '0')
+static char *DeMangleMount(char *s)
+{
+	char *tmp = s;
+	while ((tmp = strchr(tmp, '\\')) != NULL) {
+		if (isoctal(tmp[1]) && isoctal(tmp[2]) && isoctal(tmp[3])) {
+			tmp[0] = tooctal(tmp);
+			memmove(tmp+1, tmp+4, strlen(tmp)-3);
+		}
+		++tmp;
+	}
+	return s;
+}
+
+
+/*
  * Given name, such as foo, see if any of the following exist:
  *
  * foo (if foo starts with '.' or '/')
@@ -884,8 +908,8 @@
 			if (((strcmp(s1, name) == 0) || (strcmp(s2, name) == 0)) ||
 				((maj != -1) && (maj == mtabmaj) && (min == mtabmin))) {
 				FCLOSE(fp);
-				*deviceName = strdup(s1);
-				*mountName = strdup(s2);
+				*deviceName = DeMangleMount(strdup(s1));
+				*mountName = DeMangleMount(strdup(s2));
 				return 1;
 			}
 		}
@@ -928,8 +952,8 @@
 		rc = sscanf(line, "%1023s %1023s", s1, s2);
 		if (rc >= 2 && s1[0] != '#' && strcmp(s2, name) == 0) {
 			FCLOSE(fp);
-			*deviceName = strdup(s1);
-			*mountName = strdup(s2);
+			*deviceName = DeMangleMount(strdup(s1));
+			*mountName = DeMangleMount(strdup(s2));
 			return 1;
 		}
 	}