Re: generic is_subdir() for dcache.c

Bill Hawes (whawes@star.net)
Tue, 03 Feb 1998 11:59:25 -0500


This is a multi-part message in MIME format.
--------------4B03E1D734B4C7C924213491
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Bill Hawes wrote:
>
> The attached patch copies the subdir() testing function from fs/ext2/namei.c to
> dcache.c. As most filesystems need to do a subdir test for their rename
> operation, this makes a useful generic addition.

OK, here's the patch ...

Bill
--------------4B03E1D734B4C7C924213491
Content-Type: text/plain; charset=us-ascii; name="dcache_84-patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="dcache_84-patch"

--- linux-2.1.84/include/linux/fs.h.old Fri Jan 30 22:47:02 1998
+++ linux-2.1.84/include/linux/fs.h Tue Feb 3 11:36:08 1998
@@ -728,6 +734,9 @@
extern struct dentry * open_namei(const char * pathname, int flag, int mode);
extern struct dentry * do_mknod(const char * filename, int mode, dev_t dev);
extern int do_pipe(int *);
+
+/* fs/dcache.c -- generic fs support functions */
+extern int is_subdir(struct dentry *, struct dentry *);
extern ino_t find_inode_number(struct dentry *, struct qstr *);

/*
--- linux-2.1.84/fs/dcache.c.old Sat Jan 24 10:13:16 1998
+++ linux-2.1.84/fs/dcache.c Tue Feb 3 11:31:29 1998
@@ -758,6 +758,30 @@
}

/*
+ * Test whether new_dentry is a subdirectory of old_dentry.
+ *
+ * Trivially implemented using the dcache structure
+ */
+int is_subdir(struct dentry * new_dentry, struct dentry * old_dentry)
+{
+ int result;
+
+ result = 0;
+ for (;;) {
+ if (new_dentry != old_dentry) {
+ struct dentry * parent = new_dentry->d_parent;
+ if (parent == new_dentry)
+ break;
+ new_dentry = parent;
+ continue;
+ }
+ result = 1;
+ break;
+ }
+ return result;
+}
+
+/*
* Check whether a dentry already exists for the given name,
* and return the inode number if it has an inode.
*
--- linux-2.1.84/kernel/ksyms.c.old Tue Jan 27 09:36:37 1998
+++ linux-2.1.84/kernel/ksyms.c Tue Feb 3 11:53:48 1998
@@ -203,6 +204,7 @@
EXPORT_SYMBOL(shrink_dcache_sb);
EXPORT_SYMBOL(shrink_dcache_parent);
EXPORT_SYMBOL(find_inode_number);
+EXPORT_SYMBOL(is_subdir);

#if !defined(CONFIG_NFSD) && defined(CONFIG_NFSD_MODULE)
EXPORT_SYMBOL(do_nfsservctl);

--------------4B03E1D734B4C7C924213491--