Generic utility functions (CKRM RCFS rewrite)

Miscellaneous generic utility functions for filesystems moved to inode.c
The rcfs_unhash code will be removed later.

Signed-off-by: Shailabh Nagar <[EMAIL PROTECTED]>

 fs/rcfs/dir.c   |   17 -----------------
 fs/rcfs/inode.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 17 deletions(-)

Index: linux-2.6.12/fs/rcfs/dir.c
===================================================================
--- linux-2.6.12.orig/fs/rcfs/dir.c	2005-08-09 15:30:32.518957088 -0400
+++ linux-2.6.12/fs/rcfs/dir.c	2005-08-09 15:30:32.591945992 -0400
@@ -31,23 +31,6 @@
 #include <linux/rcfs.h>
 #include <asm/uaccess.h>
 
-#define rcfs_positive(dentry)  ((dentry)->d_inode && !d_unhashed((dentry)))
-
-int rcfs_empty(struct dentry *dentry)
-{
-	struct dentry *child;
-	int ret = 0;
-
-	spin_lock(&dcache_lock);
-	list_for_each_entry(child, &dentry->d_subdirs, d_child)
-	    if (!rcfs_is_magic(child) && rcfs_positive(child))
-		goto out;
-	ret = 1;
-out:
-	spin_unlock(&dcache_lock);
-	return ret;
-}
-
 /* Directory inode operations */
 
 int rcfs_create_coredir(struct inode *dir, struct dentry *dentry)
Index: linux-2.6.12/fs/rcfs/inode.c
===================================================================
--- linux-2.6.12.orig/fs/rcfs/inode.c	2005-08-09 15:30:32.519956936 -0400
+++ linux-2.6.12/fs/rcfs/inode.c	2005-08-09 15:30:32.592945840 -0400
@@ -282,6 +282,58 @@ static struct inode *rcfs_get_inode(stru
 	return inode;
 }
 
+static inline int rcfs_positive(struct dentry *dentry)
+{
+	return dentry->d_inode && !d_unhashed(dentry);
+}
+
+static int rcfs_empty (struct dentry *dentry)
+{
+	struct list_head *list;
+
+	spin_lock(&dcache_lock);
+
+	list_for_each(list, &dentry->d_subdirs) {
+		struct dentry *de = list_entry(list, struct dentry, d_child);
+		if (rcfs_positive(de)) {
+			spin_unlock(&dcache_lock);
+			return 0;
+		}
+	}
+
+	spin_unlock(&dcache_lock);
+	return 1;
+}
+
+static struct dentry *rcfs_get_dentry(struct dentry *parent, const char *name)
+{
+	struct qstr qstr;
+
+	qstr.name = name;
+	qstr.len = strlen(name);
+	qstr.hash = full_name_hash(name,qstr.len);
+	return lookup_hash(&qstr,parent);
+}
+
+/* Copy of fs:namei.c:d_unhash/dentry_unhash.
+   Remove and use dentry_unhash instead on post-2.6.9 kernels */
+void rcfs_unhash(struct dentry *dentry)
+{
+	dget(dentry);
+	spin_lock(&dcache_lock);
+	switch (atomic_read(&dentry->d_count)) {
+	default:
+		spin_unlock(&dcache_lock);
+		shrink_dcache_parent(dentry);
+		spin_lock(&dcache_lock);
+		if (atomic_read(&dentry->d_count) != 2)
+			break;
+	case 2:
+		__d_drop(dentry);
+	}
+	spin_unlock(&dcache_lock);
+}
+
 static struct file_system_type rcfs_fs_type = {
 	.owner =	THIS_MODULE,
 	.name =		"rcfs",

Reply via email to