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