Trailing slashes on non-directory filenames

Alain.Knaff@poboxes.com ("Alain.Knaff@poboxes.com")
Sat, 09 Aug 1997 13:01:29 +0200


In the new kernels with dcache, the following command works on plain
files:

> cat myfile/
this is a test

IMHO, it's prettier if trailing slashes are only accepted if the
object is actually a directory. The following patch fixes this, and
more ;-)

Regards,

Alain

diff -ur 2.1.48/linux/fs/namei.c linux/fs/namei.c
--- 2.1.48/linux/fs/namei.c Tue Aug 5 20:56:09 1997
+++ linux/fs/namei.c Sat Aug 9 12:30:28 1997
@@ -383,7 +383,7 @@
}

if (!*name)
- goto return_base;
+ return base;

/* At this point we know we have a real path component. */
for(;;) {
@@ -391,7 +391,7 @@
unsigned long hash;
struct qstr this;
struct inode *inode;
- char c, follow;
+ char c;

dentry = ERR_PTR(-ENOENT);
inode = base->d_inode;
@@ -411,6 +411,11 @@
hash = init_name_hash();
len = 0;
c = *name;
+
+ if(!c)
+ /* trailing slash -> empty path component */
+ return base;
+
do {
len++; name++;
c = name_translate_char(base, c);
@@ -421,28 +426,30 @@
this.len = len;
this.hash = end_name_hash(hash);

- /* remove trailing slashes? */
- follow = follow_link;
- if (c) {
- follow |= c;
- do {
- c = *++name;
- } while (c == '/');
- }
-
dentry = lookup(base, &this);
if (IS_ERR(dentry))
break;

- if (!follow)
- break;
-
- base = do_follow_link(base, dentry);
- if (c && !IS_ERR(base))
- continue;
-
-return_base:
- return base;
+ if(follow_link || c ||
+ (dentry->d_inode && dentry->d_inode->i_op &&
+ dentry->d_inode->i_op->lookup)) {
+ /* follow links if asked to do so, or if directory */
+ dentry = do_follow_link(base, dentry);
+ if (IS_ERR(dentry))
+ return dentry;
+ } else
+ dput(base);
+
+ if(!c)
+ /* end of path */
+ return dentry;
+
+ /* remove slashes before next path component */
+ do
+ c = *++name;
+ while (c == '/');
+
+ base = dentry;
}
dput(base);
return dentry;