public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jan Blunck <j.blunck@tu-harburg.de>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Andrew Morton <akpm@osdl.org>,
	Linux-Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH] ramfs: pretend dirent sizes
Date: Fri, 15 Jul 2005 05:01:25 +0200	[thread overview]
Message-ID: <42D72705.8010306@tu-harburg.de> (raw)

[-- 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 = {

             reply	other threads:[~2005-07-15  3:00 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-15  3:01 Jan Blunck [this message]
2005-07-15  3:11 ` [PATCH] ramfs: pretend dirent sizes 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42D72705.8010306@tu-harburg.de \
    --to=j.blunck@tu-harburg.de \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox