[RFC 3/7] cramfs: allow unlinking of files

Previous thread: [RFC 0/7] [RFC] cramfs: fake write support by arnd on Saturday, May 31, 2008 - 11:37 am. (32 messages)

Next thread: [RFC 6/7] cramfs: read directory entries from dcache by arnd on Saturday, May 31, 2008 - 11:20 am. (1 message)
To: <linux-fsdevel@...>
Cc: <linux-kernel@...>, <hch@...>
Date: Saturday, May 31, 2008 - 11:20 am

The new cramfs_unlink function replaces an existing dentry with
a pinned negative dentry in cramfs, so that lookup does not find
it any more.

The readdir function gets changed here to no longer show the file
if a negative dentry exists.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
fs/cramfs/inode.c | 27 ++++++++++++++++++++++++++-
1 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c
index 8aa04d7..6b9f21f 100644
--- a/fs/cramfs/inode.c
+++ b/fs/cramfs/inode.c
@@ -348,12 +348,14 @@ static int cramfs_readdir(struct file *filp, void *dirent, filldir_t filldir)

copied = 0;
while (offset < inode->i_size) {
+ struct qstr qstr = { .name = buf, };
struct cramfs_inode *de;
unsigned long nextoffset;
char *name;
ino_t ino;
mode_t mode;
int namelen, error;
+ struct dentry *dentry;

mutex_lock(&read_mutex);
de = cramfs_read(sb, OFFSET(inode) + offset, sizeof(*de)+CRAMFS_MAXPATHLEN);
@@ -379,7 +381,15 @@ static int cramfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
break;
namelen--;
}
- error = filldir(dirent, buf, namelen, offset, ino, mode >> 12);
+ qstr.len = namelen;
+ dentry = d_hash_and_lookup(filp->f_path.dentry, &qstr);
+
+ error = 0;
+ if (!dentry || (dentry->d_inode))
+ error = filldir(dirent, buf, namelen, offset,
+ ino, mode >> 12);
+
+ dput(dentry);
if (error)
break;

@@ -391,6 +401,19 @@ static int cramfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
return 0;
}

+int cramfs_unlink(struct inode *dir, struct dentry *dentry)
+{
+ struct inode *inode = dentry->d_inode;
+ struct dentry *new;
+
+ inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
+ drop_nlink(inode);
+ new = d_alloc(dentry->d_parent, &dentry->d_name);
+ d_add(new, NULL);
+
+ dget(dentry);
+ return 0;
+}
/*
* Lookup and fill in the inode data..
*/
@@ -512,...

To: <arnd@...>
Cc: <linux-fsdevel@...>, <linux-kernel@...>, <hch@...>
Date: Sunday, June 1, 2008 - 12:54 pm

How is the negative dentry dropped on umount? Looks like we want a
per-sb list to put them on. Then we can walk it and dput each one at

Jörn

--
"[One] doesn't need to know [...] how to cause a headache in order
to take an aspirin."
-- Scott Culp, Manager of the Microsoft Security Response Center, 2001
--

To: Jörn Engel <joern@...>
Cc: <linux-fsdevel@...>, <linux-kernel@...>, <hch@...>
Date: Sunday, June 1, 2008 - 5:28 pm

Good point. I think ramfs does exactly that, using kill_litter_super.
I haven't tested unmount so far, and should probably do something like
that in cramfs_put_super.

Arnd <><
--

Previous thread: [RFC 0/7] [RFC] cramfs: fake write support by arnd on Saturday, May 31, 2008 - 11:37 am. (32 messages)

Next thread: [RFC 6/7] cramfs: read directory entries from dcache by arnd on Saturday, May 31, 2008 - 11:20 am. (1 message)