From: Andreas Gruenbacher Subject: Distinguish between connected and disconnected paths in d_path() Change d_path() so that it will never return a path starting with '/' if the path doesn't lead up to the chroot directory. Also ensure that the path returned never is the empty string: this would only occur with a lazily unmounted file system; return "." in that case instead. Signed-off-by: Andreas Gruenbacher --- fs/dcache.c | 18 ++++-------------- fs/namespace.c | 3 --- 2 files changed, 4 insertions(+), 17 deletions(-) --- a/fs/dcache.c +++ b/fs/dcache.c @@ -1829,8 +1829,11 @@ global_root: buffer++; buflen++; } - if (is_slash) + if (is_slash) { + if (*buffer == '\0') + *--buffer = '.'; goto out; + } } if (buflen < namelen) goto Elong; @@ -1843,18 +1846,6 @@ Elong: goto out; } -static char *__connect_d_path(char *path, char *buffer) -{ - if (!IS_ERR(path) && *path != '/') { - /* Pretend that disconnected paths are hanging off the root. */ - if (path == buffer) - path = ERR_PTR(-ENAMETOOLONG); - else - *--path = '/'; - } - return path; -} - /* write full pathname into buffer and return start of pathname */ char *d_path(struct dentry *dentry, struct vfsmount *vfsmnt, char *buf, int buflen) @@ -1868,7 +1859,6 @@ char *d_path(struct dentry *dentry, stru root = dget(current->fs->root); read_unlock(¤t->fs->lock); res = __d_path(dentry, vfsmnt, root, rootmnt, buf, buflen, 0); - res = __connect_d_path(res, buf); dput(root); mntput(rootmnt); return res; --- a/fs/namespace.c +++ b/fs/namespace.c @@ -1917,9 +1917,6 @@ char *d_namespace_path(struct dentry *de res = __d_path(dentry, vfsmnt, root, nsrootmnt, buf, buflen, 1); dput(root); mntput(nsrootmnt); - /* Prevent empty path for lazily unmounted filesystems. */ - if (!IS_ERR(res) && *res == '\0') - *--res = '.'; return res; } EXPORT_SYMBOL(d_namespace_path);