Re: [patch] tmpfs: incr. link-count on directory rename

From: Christoph Rohland (cr@sap.com)
Date: Tue Feb 19 2002 - 11:39:14 EST


Hi Uli,

On 14 Feb 2002, Uli Martens wrote:
> Oops, you're right, the linkcount of old_dir isn't decremented at
> the moment, too. I will test your patch this evening, but I think it
> looks better than mine... ;)

I prefer this one.

Linus, Marcelo, please apply.

The patch fixes the refcounting of directories on renames in tmpfs.

Greetings
                Christoph

diff -uNr 18-rc1/mm/shmem.c c/mm/shmem.c
--- 18-rc1/mm/shmem.c Thu Jan 17 10:06:05 2002
+++ c/mm/shmem.c Tue Feb 19 17:31:23 2002
@@ -1083,19 +1083,25 @@
  */
 static int shmem_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry)
 {
- int error = -ENOTEMPTY;
+ struct inode *inode;
 
- if (shmem_empty(new_dentry)) {
- struct inode *inode = new_dentry->d_inode;
- if (inode) {
- inode->i_ctime = CURRENT_TIME;
- inode->i_nlink--;
- dput(new_dentry);
- }
- error = 0;
- old_dentry->d_inode->i_ctime = old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME;
+ if (!shmem_empty(new_dentry))
+ return -ENOTEMPTY;
+
+ inode = new_dentry->d_inode;
+ if (inode) {
+ inode->i_ctime = CURRENT_TIME;
+ inode->i_nlink--;
+ dput(new_dentry);
+ }
+ inode = old_dentry->d_inode;
+ if (S_ISDIR(inode->i_mode)) {
+ old_dir->i_nlink--;
+ new_dir->i_nlink++;
         }
- return error;
+
+ inode->i_ctime = old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME;
+ return 0;
 }
 
 static int shmem_symlink(struct inode * dir, struct dentry *dentry, const char * symname)

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Feb 23 2002 - 21:00:23 EST