Skip to contentSkip to conversation

correct tmpfs link count for directories

PATCH In review Christoph Rohland 2 participants 2 messages Feb 13, 2001

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 correct tmpfs link count for directories

Hi Alan,

The attached patch makes tmpfs behave more like other fs's. Apparently perl expects this.

Greetings
Christoph

mm/shmem.c +17 -15
diff -uNr 2.4.1-ac10/mm/shmem.c 2.4.1-ac10-nlink/mm/shmem.c
@@ -465,6 +465,7 @@
 			inode->i_fop = &shmem_file_operations;
 			break;
 		case S_IFDIR:
+			inode->i_nlink++;
 			inode->i_op = &shmem_dir_inode_operations;
 			inode->i_fop = &shmem_dir_operations;
 			break;
@@ -743,7 +744,12 @@
 
 static int shmem_mkdir(struct inode * dir, struct dentry * dentry, int mode)
 {
-	return shmem_mknod(dir, dentry, mode | S_IFDIR, 0);
+	int error;
+
+	if ((error = shmem_mknod(dir, dentry, mode | S_IFDIR, 0)))
+		return error;
+	dir->i_nlink++;
+	return 0;
 }
 
 static int shmem_create(struct inode *dir, struct dentry *dentry, int mode)
@@ -801,25 +807,21 @@
 	return 1;
 }
 
-/*
- * This works for both directories and regular files.
- * (non-directories will always have empty subdirs)
- */
 static int shmem_unlink(struct inode * dir, struct dentry *dentry)
 {
-	int retval = -ENOTEMPTY;
+	dentry->d_inode->i_nlink--;
+	dput(dentry);	/* Undo the count from "create" - this does all the work */
+	return 0;
+}
 
-	if (shmem_empty(dentry)) {
-		struct inode *inode = dentry->d_inode;
+static int shmem_rmdir(struct inode * dir, struct dentry *dentry)
+{
+	if (!shmem_empty(dentry))
+		return -ENOTEMPTY;
 
-		inode->i_nlink--;
-		dput(dentry);	/* Undo the count from "create" - this does all the work */
-		retval = 0;
-	}
-	return retval;
+	dir->i_nlink--;
+	return shmem_unlink(dir, dentry);
 }
-
-#define shmem_rmdir shmem_unlink
 
 /*
  * The VFS layer already does all the dentry stuff for rename,
#1 lore raw
Quoted 2 lines

The attached patch makes tmpfs behave more like other fs's. Apparently perl expects this.

A few apps assume this. All of them are buggy. I'll apply the patch.