[PATCH] procfs: Fix hardlink counts
authorDaniel Drake <dsd@gentoo.org>
Sun, 1 May 2005 15:59:03 +0000 (08:59 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Sun, 1 May 2005 15:59:03 +0000 (08:59 -0700)
The pid directories in /proc/ currently return the wrong hardlink count - 3,
when there are actually 4 : ".", "..", "fd", and "task".

This is easy to notice using find(1):
cd /proc/<pid>
find

In the output, you'll see a message similar to:

find: WARNING: Hard link count is wrong for .: this may be a bug in your
filesystem driver.  Automatically turning on find's -noleaf option.
Earlier results may have failed to include directories that should have
been searched.

http://bugs.gentoo.org/show_bug.cgi?id=86031

I also noticed that CONFIG_SECURITY can add a 5th: attr, and performed a
similar fix on the task directories too.

Signed-off-by: Daniel Drake <dsd@gentoo.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
fs/proc/base.c

index 39fd336cfdb9ca68c354a22f432e74c63a9bf732..4718173af2c8c3469703bf114b6eba2a5ae3ad96 100644 (file)
@@ -1800,8 +1800,12 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
        inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
        inode->i_op = &proc_tgid_base_inode_operations;
        inode->i_fop = &proc_tgid_base_operations;
-       inode->i_nlink = 3;
        inode->i_flags|=S_IMMUTABLE;
+#ifdef CONFIG_SECURITY
+       inode->i_nlink = 5;
+#else
+       inode->i_nlink = 4;
+#endif
 
        dentry->d_op = &pid_base_dentry_operations;
 
@@ -1855,8 +1859,12 @@ static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry
        inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
        inode->i_op = &proc_tid_base_inode_operations;
        inode->i_fop = &proc_tid_base_operations;
-       inode->i_nlink = 3;
        inode->i_flags|=S_IMMUTABLE;
+#ifdef CONFIG_SECURITY
+       inode->i_nlink = 4;
+#else
+       inode->i_nlink = 3;
+#endif
 
        dentry->d_op = &pid_base_dentry_operations;