]>
Commit | Line | Data |
---|---|---|
38fa6f00 MT |
1 | diff --git a/eject.c b/eject.c |
2 | index d67089c..f7b2a2e 100644 | |
3 | --- a/eject.c | |
4 | +++ b/eject.c | |
5 | @@ -370,6 +370,30 @@ static int FileExists(const char *name, const int try, int *found) | |
6 | ||
7 | ||
8 | /* | |
9 | + * Linux mangles spaces in mount points by changing them to an octal string | |
10 | + * of '\040'. So lets scan the mount point and fix it up by replacing all | |
11 | + * occurrences off '\0##' with the ASCII value of 0##. Requires a writable | |
12 | + * string as input as we mangle in place. Some of this was taken from the | |
13 | + * util-linux package. | |
14 | + */ | |
15 | +#define octalify(a) ((a) & 7) | |
16 | +#define tooctal(s) (64*octalify(s[1]) + 8*octalify(s[2]) + octalify(s[3])) | |
17 | +#define isoctal(a) (((a) & ~7) == '0') | |
18 | +static char *DeMangleMount(char *s) | |
19 | +{ | |
20 | + char *tmp = s; | |
21 | + while ((tmp = strchr(tmp, '\\')) != NULL) { | |
22 | + if (isoctal(tmp[1]) && isoctal(tmp[2]) && isoctal(tmp[3])) { | |
23 | + tmp[0] = tooctal(tmp); | |
24 | + memmove(tmp+1, tmp+4, strlen(tmp)-3); | |
25 | + } | |
26 | + ++tmp; | |
27 | + } | |
28 | + return s; | |
29 | +} | |
30 | + | |
31 | + | |
32 | +/* | |
33 | * Given name, such as foo, see if any of the following exist: | |
34 | * | |
35 | * foo (if foo starts with '.' or '/') | |
36 | @@ -882,6 +906,8 @@ static int MountedDevice(const char *name, char **mountName, char **deviceName) | |
37 | rc = sscanf(line, "%1023s %1023s", s1, s2); | |
38 | if (rc >= 2) { | |
39 | int mtabmaj, mtabmin; | |
40 | + DeMangleMount(s1); | |
41 | + DeMangleMount(s2); | |
42 | GetMajorMinor(s1, &mtabmaj, &mtabmin); | |
43 | if (((strcmp(s1, name) == 0) || (strcmp(s2, name) == 0)) || | |
44 | ((maj != -1) && (maj == mtabmaj) && (min == mtabmin))) { | |
45 | @@ -928,6 +954,8 @@ static int MountableDevice(const char *name, char **mountName, char **deviceName | |
46 | ||
47 | while (fgets(line, sizeof(line), fp) != 0) { | |
48 | rc = sscanf(line, "%1023s %1023s", s1, s2); | |
49 | + DeMangleMount(s1); | |
50 | + DeMangleMount(s2); | |
51 | if (rc >= 2 && s1[0] != '#' && strcmp(s2, name) == 0) { | |
52 | FCLOSE(fp); | |
53 | *deviceName = strdup(s1); | |
54 | @@ -968,6 +996,8 @@ static void UnmountDevices(const char *pattern) | |
55 | while (fgets(line, sizeof(line), fp) != 0) { | |
56 | status = sscanf(line, "%1023s %1023s", s1, s2); | |
57 | if (status >= 2) { | |
58 | + DeMangleMount(s1); | |
59 | + DeMangleMount(s2); | |
60 | status = regexec(&preg, s1, 0, 0, 0); | |
61 | if (status == 0) { | |
62 | if (v_option) |