public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: arnd@arndb.de
To: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hch@lst.de
Subject: [RFC 3/7] cramfs: allow unlinking of files
Date: Sat, 31 May 2008 17:20:16 +0200	[thread overview]
Message-ID: <20080531153510.820446949@arndb.de> (raw)
In-Reply-To: 20080531152013.031903990@arndb.de

[-- Attachment #1: 0003-cramfs-allow-unlinking-of-files.patch --]
[-- Type: text/plain, Size: 2342 bytes --]

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,10 +535,12 @@ static const struct file_operations cramfs_directory_operations = {
 };
 
 static const struct inode_operations cramfs_dir_inode_operations = {
+	.unlink		= cramfs_unlink,
 	.lookup		= cramfs_lookup,
 };
 
 static const struct super_operations cramfs_ops = {
+	.drop_inode	= generic_delete_inode,
 	.put_super	= cramfs_put_super,
 	.remount_fs	= cramfs_remount,
 	.statfs		= cramfs_statfs,
-- 
1.5.4.3

-- 


  parent reply	other threads:[~2008-05-31 15:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20080531152013.031903990@arndb.de>
2008-05-31 15:20 ` [RFC 1/7] cramfs: allow remount rw arnd
2008-05-31 15:20 ` [RFC 2/7] cramfs: create unique inode numbers arnd
2008-06-01 16:50   ` Jörn Engel
2008-06-01 21:24     ` Arnd Bergmann
2008-06-02  5:42       ` Jörn Engel
2008-05-31 15:20 ` arnd [this message]
2008-06-01 16:54   ` [RFC 3/7] cramfs: allow unlinking of files Jörn Engel
2008-06-01 21:28     ` Arnd Bergmann
2008-05-31 15:20 ` [RFC 4/7] cramfs: allow rmdir arnd
2008-05-31 15:20 ` [RFC 5/7] cramfs: allow writing to existing files arnd
2008-05-31 15:20 ` [RFC 6/7] cramfs: read directory entries from dcache arnd
2008-05-31 15:20 ` [RFC 7/7] cramfs: add missing inode operations arnd

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=20080531153510.820446949@arndb.de \
    --to=arnd@arndb.de \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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