From: Miklos Szeredi Date: Mon, 15 Nov 2004 10:05:12 +0000 (+0000) Subject: fix X-Git-Tag: fuse_2_0_merge3~3 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=d4d6b364df4290c46111bd033c6031d7e4d5ef74;p=qemu-gpiodev%2Flibfuse.git fix --- diff --git a/ChangeLog b/ChangeLog index 9e6a0e6..7084029 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-11-15 Miklos Szeredi + + * 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 * 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);