diff options
author | Miklos Szeredi <miklos@szeredi.hu> | 2004-11-15 10:05:12 +0000 |
---|---|---|
committer | Miklos Szeredi <miklos@szeredi.hu> | 2004-11-15 10:05:12 +0000 |
commit | d4d6b364df4290c46111bd033c6031d7e4d5ef74 (patch) | |
tree | daed33d0070bd0e05d32c94e6375e56335e70aeb | |
parent | ff6ba3e66bd0a8eb80974783b4152207230b1f19 (diff) | |
download | fuse-d4d6b364df4290c46111bd033c6031d7e4d5ef74.tar.gz |
fix
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | util/fusermount.c | 64 |
2 files changed, 48 insertions, 22 deletions
@@ -1,3 +1,9 @@ +2004-11-15 Miklos Szeredi <miklos@szeredi.hu> + + * fusermount: do not resolve last component of mountpoint on if it + is '.' or '..'. This new path resolvation is now done on mount as + well as unmount. This enables relative paths to work on unmount. + 2004-11-14 Miklos Szeredi <miklos@szeredi.hu> * Released 2.1-pre1 diff --git a/util/fusermount.c b/util/fusermount.c index e9e195d..c8bfa5b 100644 --- a/util/fusermount.c +++ b/util/fusermount.c @@ -530,37 +530,57 @@ static int mount_fuse(const char *mnt, const char *opts) return fd; } -static char *resolve_path(const char *orig, int unmount) +static char *resolve_path(const char *orig) { char buf[PATH_MAX]; + char *copy; char *dst; - - if (unmount) { - char *end; - /* Resolving at unmount can only be done very carefully, not touching - the mountpoint... So for the moment it's not done. - - Just remove trailing slashes instead. - */ - dst = strdup(orig); - if (dst == NULL) { - fprintf(stderr, "%s: failed to allocate memory\n", progname); - return NULL; - } + char *end; + char *lastcomp; + const char *toresolv; - for (end = dst + strlen(dst) - 1; end > dst && *end == '/'; end --) - *end = '\0'; - - return dst; + copy = strdup(orig); + if (copy == NULL) { + fprintf(stderr, "%s: failed to allocate memory\n", progname); + return NULL; } - if (realpath(orig, buf) == NULL) { + toresolv = copy; + lastcomp = NULL; + for (end = copy + strlen(copy) - 1; end > copy && *end == '/'; end --); + if (end[0] != '/') { + char *tmp; + end[1] = '\0'; + tmp = strrchr(copy, '/'); + if (tmp == NULL) { + lastcomp = copy; + toresolv = "."; + } else { + lastcomp = tmp + 1; + if (tmp == copy) + toresolv = "/"; + } + if (strcmp(lastcomp, ".") == 0 || strcmp(lastcomp, "..") == 0) { + lastcomp = NULL; + toresolv = copy; + } + else if (tmp) + tmp[0] = '\0'; + } + if (realpath(toresolv, buf) == NULL) { fprintf(stderr, "%s: Bad mount point %s: %s\n", progname, orig, strerror(errno)); + free(copy); return NULL; } - - dst = strdup(buf); + if (lastcomp == NULL) + dst = strdup(buf); + else { + dst = (char *) malloc(strlen(buf) + 1 + strlen(lastcomp) + 1); + if (dst) + sprintf(dst, "%s/%s", buf, lastcomp); + } + free(copy); if (dst == NULL) fprintf(stderr, "%s: failed to allocate memory\n", progname); return dst; @@ -682,7 +702,7 @@ int main(int argc, char *argv[]) exit(1); } - mnt = resolve_path(origmnt, unmount); + mnt = resolve_path(origmnt); if (mnt == NULL) exit(1); |