lkml.org 
[lkml]   [2008]   [May]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[patch 2/8] vfs: fix sys_getcwd for detached mounts
From: Miklos Szeredi <mszeredi@suse.cz>

Currently getcwd(2) on a detached mount will give a garbled result:

> mkdir /mnt/foo
> mount --bind /etc /mnt/foo
> cd /mnt/foo/skel
> /bin/pwd
/mnt/foo/skel
> umount -l /mnt/foo
> /bin/pwd
etcskel

After the patch it will give a much saner "/skel" result.

Thanks to John Johansen for pointing out this bug.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
CC: John Johansen <jjohansen@suse.de>
---
fs/dcache.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)

Index: linux-2.6/fs/dcache.c
===================================================================
--- linux-2.6.orig/fs/dcache.c 2008-05-29 12:46:22.000000000 +0200
+++ linux-2.6/fs/dcache.c 2008-05-29 12:46:22.000000000 +0200
@@ -1825,10 +1825,20 @@ char *__d_path(const struct path *path,
return retval;

global_root:
- retval += 1; /* hit the slash */
- name = &dentry->d_name;
- if (prepend(&retval, &buflen, name->name, name->len) != 0)
- goto Elong;
+ /*
+ * If this is a root dentry, then overwrite the slash. This
+ * will also DTRT with pseudo filesystems which have root
+ * dentries named "foo:".
+ *
+ * Otherwise this is the root of a detached mount, so don't do
+ * anything.
+ */
+ if (IS_ROOT(dentry)) {
+ retval += 1;
+ name = &dentry->d_name;
+ if (prepend(&retval, &buflen, name->name, name->len) != 0)
+ goto Elong;
+ }
root->mnt = vfsmnt;
root->dentry = dentry;
return retval;
--


\
 
 \ /
  Last update: 2008-05-29 13:37    [W:1.854 / U:0.184 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site