public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ramfs: pretend dirent sizes
@ 2005-07-15  3:01 Jan Blunck
  2005-07-15  3:11 ` Andrew Morton
  2005-07-15 18:52 ` Linus Torvalds
  0 siblings, 2 replies; 24+ messages in thread
From: Jan Blunck @ 2005-07-15  3:01 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Andrew Morton, Linux-Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 258 bytes --]

This patch adds bogo dirent sizes for ramfs like already available for 
tmpfs.

Although i_size of directories isn't covered by the POSIX standard it is 
a bad idea to always set it to zero. Therefore pretend a bogo dirent 
size for directory i_sizes.

Jan


[-- Attachment #2: ramfs_bogo_dirent_size.diff --]
[-- Type: text/x-patch, Size: 3065 bytes --]

Signed-off-by: Jan Blunck <j.blunck@tu-harburg.de>

 fs/ramfs/inode.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 47 insertions(+), 4 deletions(-)

Index: linux-2.6/fs/ramfs/inode.c
===================================================================
--- linux-2.6.orig/fs/ramfs/inode.c
+++ linux-2.6/fs/ramfs/inode.c
@@ -38,6 +38,9 @@
 /* some random number */
 #define RAMFS_MAGIC	0x858458f6
 
+/* Pretend that each entry is of this size in directory's i_size */
+#define BOGO_DIRENT_SIZE 20
+
 static struct super_operations ramfs_ops;
 static struct address_space_operations ramfs_aops;
 static struct inode_operations ramfs_file_inode_operations;
@@ -77,6 +80,7 @@ struct inode *ramfs_get_inode(struct sup
 
 			/* directory inodes start off with i_nlink == 2 (for "." entry) */
 			inode->i_nlink++;
+			inode->i_size = 2 * BOGO_DIRENT_SIZE;
 			break;
 		case S_IFLNK:
 			inode->i_op = &page_symlink_inode_operations;
@@ -97,6 +101,7 @@ ramfs_mknod(struct inode *dir, struct de
 	int error = -ENOSPC;
 
 	if (inode) {
+		dir->i_size += BOGO_DIRENT_SIZE;
 		if (dir->i_mode & S_ISGID) {
 			inode->i_gid = dir->i_gid;
 			if (S_ISDIR(mode))
@@ -132,6 +137,7 @@ static int ramfs_symlink(struct inode * 
 		int l = strlen(symname)+1;
 		error = page_symlink(inode, symname, l);
 		if (!error) {
+			dir->i_size += BOGO_DIRENT_SIZE;
 			if (dir->i_mode & S_ISGID)
 				inode->i_gid = dir->i_gid;
 			d_instantiate(dentry, inode);
@@ -142,6 +148,43 @@ static int ramfs_symlink(struct inode * 
 	return error;
 }
 
+static int ramfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
+{
+	dir->i_size += BOGO_DIRENT_SIZE;
+	return simple_link(old_dentry, dir, dentry);
+}
+
+static int ramfs_unlink(struct inode *dir, struct dentry *dentry)
+{
+	dir->i_size -= BOGO_DIRENT_SIZE;
+	return simple_unlink(dir, dentry);
+}
+
+static int ramfs_rmdir(struct inode *dir, struct dentry *dentry)
+{
+	int ret;
+
+	ret = simple_rmdir(dir, dentry);
+	if (ret != -ENOTEMPTY)
+		dir->i_size -= BOGO_DIRENT_SIZE;
+
+	return ret;
+}
+
+static int ramfs_rename(struct inode *old_dir, struct dentry *old_dentry,
+			struct inode *new_dir, struct dentry *new_dentry)
+{
+	int ret;
+
+	ret = simple_rename(old_dir, old_dentry, new_dir, new_dentry);
+	if (ret != -ENOTEMPTY) {
+		old_dir->i_size -= BOGO_DIRENT_SIZE;
+		new_dir->i_size += BOGO_DIRENT_SIZE;
+	}
+
+	return ret;
+}
+
 static struct address_space_operations ramfs_aops = {
 	.readpage	= simple_readpage,
 	.prepare_write	= simple_prepare_write,
@@ -164,13 +207,13 @@ static struct inode_operations ramfs_fil
 static struct inode_operations ramfs_dir_inode_operations = {
 	.create		= ramfs_create,
 	.lookup		= simple_lookup,
-	.link		= simple_link,
-	.unlink		= simple_unlink,
+	.link		= ramfs_link,
+	.unlink		= ramfs_unlink,
 	.symlink	= ramfs_symlink,
 	.mkdir		= ramfs_mkdir,
-	.rmdir		= simple_rmdir,
+	.rmdir		= ramfs_rmdir,
 	.mknod		= ramfs_mknod,
-	.rename		= simple_rename,
+	.rename		= ramfs_rename,
 };
 
 static struct super_operations ramfs_ops = {

^ permalink raw reply	[flat|nested] 24+ messages in thread
[parent not found: <4qoKs-6yv-13@gated-at.bofh.it>]

end of thread, other threads:[~2005-07-21  7:28 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-15  3:01 [PATCH] ramfs: pretend dirent sizes Jan Blunck
2005-07-15  3:11 ` Andrew Morton
2005-07-15 10:16   ` Jan Blunck
2005-07-15 18:52 ` Linus Torvalds
2005-07-16  0:39   ` Chris Wedgwood
2005-07-19  9:28     ` Jan Blunck
2005-07-19 16:16       ` Chris Wedgwood
2005-07-19 18:22         ` Jan Blunck
2005-07-19 18:32           ` Chris Wedgwood
2005-07-19 19:14             ` Jan Blunck
2005-07-19 19:16               ` Chris Wedgwood
2005-07-20 11:21                 ` Jörn Engel
2005-07-20 18:11                   ` Chris Wedgwood
2005-07-20 18:48                     ` Jan Blunck
2005-07-20 18:52                       ` Peter Staubach
2005-07-21  7:26                       ` Jörn Engel
2005-07-21  7:20                     ` Jörn Engel
2005-07-21  7:25                       ` Chris Wedgwood
2005-07-21  7:27                         ` Jörn Engel
2005-07-20 18:24                 ` Jan Blunck
2005-07-20 18:50                   ` Peter Staubach
2005-07-19  9:46   ` Jan Blunck
     [not found] <4qoKs-6yv-13@gated-at.bofh.it>
     [not found] ` <4qoU5-6CQ-3@gated-at.bofh.it>
     [not found]   ` <4qvsI-32Y-17@gated-at.bofh.it>
2005-07-15 13:12     ` Bodo Eggert
2005-07-19  9:13       ` Jan Blunck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox