patch for fs max name length

Bill Hawes (whawes@star.net)
Sun, 06 Sep 1998 11:05:59 -0400


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

Currently there are about 50 places in the kernel where a filesystem
tests whether a name exceeds the allowable maximum. Generally the name
being checked is in a dentry, and since dentry names are created in one
place, most of these individual tests could be eliminated by checking
the name length at creation time.

The attached patch adds an s_maxnamelen field to the superblock and
initializes it to 255, the value used by most (all?) of the
filesystems. When a filename is parsed, if name length exceeds this
maximum an ENAMETOOLONG error is returned, obviating the need for tests
within the various fs operation routines.

The default maximum is set only when a new super block is created, so
each filesystem can override the value if it needs to.

This change will allow us to remove a substantial number of redundant
tests, and will ensure that all filenames are properly tested against
the limit. If the patch looks OK, I'll follow up with one removing the
length checks from the various filesystems.

Regards,
Bill
--------------6CC9CA40FCEB28AE2BE57E24
Content-Type: text/plain; charset=us-ascii; name="namelen_120-patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="namelen_120-patch"

--- linux-2.1.120/include/linux/fs.h.old Sat Sep 5 10:52:53 1998
+++ linux-2.1.120/include/linux/fs.h Sun Sep 6 09:34:37 1998
@@ -522,6 +522,13 @@

extern int fasync_helper(int, struct file *, int, struct fasync_struct **);

+/*
+ * Super_block definitions
+ */
+
+/* filesystem can override this if necessary */
+#define DEFAULT_MAXNAMELEN (255)
+
#include <linux/minix_fs_sb.h>
#include <linux/ext2_fs_sb.h>
#include <linux/hpfs_fs_sb.h>
@@ -557,10 +564,8 @@
unsigned long s_time;
struct dentry *s_root;
struct wait_queue *s_wait;
+ int s_maxnamelen;

- struct inode *s_ibasket;
- short int s_ibasket_count;
- short int s_ibasket_max;
struct list_head s_dirty; /* dirty inodes */

union {
--- linux-2.1.120/fs/super.c.old Tue Sep 1 21:40:19 1998
+++ linux-2.1.120/fs/super.c Sun Sep 6 09:30:00 1998
@@ -573,6 +607,7 @@
s->s_dev = dev;
s->s_flags = flags;
s->s_dirt = 0;
+ s->s_maxnamelen = DEFAULT_MAXNAMELEN;
/* N.B. Should lock superblock now ... */
if (!type->read_super(s, data, silent))
goto out_fail;
--- linux-2.1.120/fs/namei.c.old Tue Sep 1 21:28:12 1998
+++ linux-2.1.120/fs/namei.c Sun Sep 6 10:05:31 1998
@@ -391,6 +391,13 @@
}
}

+ /*
+ * Check whether the name length exceeds the maximum.
+ */
+ dentry = ERR_PTR(-ENAMETOOLONG);
+ if (this.len > base->d_sb->s_maxnamelen)
+ break;
+
/* This does the actual lookups.. */
dentry = reserved_lookup(base, &this);
if (!dentry) {

--------------6CC9CA40FCEB28AE2BE57E24--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/faq.html