mtd/fs/jffs2 dir.c,1.45.2.5,1.45.2.6

David Woodhouse dwmw2 at infradead.org
Thu Jun 20 19:54:50 EDT 2002


Update of /home/cvs/mtd/fs/jffs2
In directory phoenix.infradead.org:/tmp/cvs-serv25426

Modified Files:
      Tag: jffs2-2_4-branch
	dir.c 
Log Message:
Ensure nlink is decremented on victim in jffs2_rename()

Index: dir.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/dir.c,v
retrieving revision 1.45.2.5
retrieving revision 1.45.2.6
diff -u -r1.45.2.5 -r1.45.2.6
--- dir.c	23 Feb 2002 14:31:09 -0000	1.45.2.5
+++ dir.c	20 Jun 2002 23:54:48 -0000	1.45.2.6
@@ -939,6 +939,29 @@
                         struct inode *new_dir_i, struct dentry *new_dentry)
 {
 	int ret;
+	struct jffs2_inode_info *victim_f = NULL;
+
+	/* The VFS will check for us and prevent trying to rename a 
+	 * file over a directory and vice versa, but if it's a directory,
+	 * the VFS can't check whether the victim is empty. The filesystem
+	 * needs to do that for itself.
+	 */
+	if (new_dentry->d_inode) {
+		victim_f = JFFS2_INODE_INFO(new_dentry->d_inode);
+		if (S_ISDIR(new_dentry->d_inode->i_mode)) {
+			struct jffs2_full_dirent *fd;
+
+			down(&victim_f->sem);
+			for (fd = victim_f->dents; fd; fd = fd->next) {
+				if (fd->ino) {
+					up(&victim_f->sem);
+					return -ENOTEMPTY;
+				}
+			}
+			up(&victim_f->sem);
+		}
+	}
+
 	/* XXX: We probably ought to alloc enough space for
 	   both nodes at the same time. Writing the new link, 
 	   then getting -ENOSPC, is quite bad :)
@@ -948,6 +971,18 @@
 	ret = jffs2_do_link(old_dentry, new_dir_i, new_dentry, 1);
 	if (ret)
 		return ret;
+
+	if (victim_f) {
+		/* There was a victim. Kill it off nicely */
+		new_dentry->d_inode->i_nlink--;
+		/* Don't oops if the victim was a dirent pointing to an
+		   inode which didn't exist. */
+		if (victim_f->inocache) {
+			down(&victim_f->sem);
+			victim_f->inocache->nlink--;
+			up(&victim_f->sem);
+		}
+	}
 
 	/* Unlink the original */
 	ret = jffs2_do_unlink(old_dir_i, old_dentry, 1);





More information about the linux-mtd-cvs mailing list