linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ren <l.s.r@web.de>
To: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] Consolidate dot-stripping code
Date: Sun, 27 Jul 2003 17:10:02 +0200	[thread overview]
Message-ID: <20030727171002.3f8eaed5.l.s.r@web.de> (raw)

Hi,

there are several places inside fs/vfat/namei.c where the length of a
struct qstr without any trailing dots is calculated. The patch below
adds a function vfat_qstrlen() which does that and makes use of it.

This cuts down on code size. Binary size is unchanged, because
vfat_qstrlen() is inline'd. It could be un-inline'd later.

Please consider applying this cleanup.

René



diff -u ./fs/vfat/namei.c~ ./fs/vfat/namei.c
--- linux-2.6.0-test1-bk3/fs/vfat/namei.c~	2003-07-27 16:41:36.000000000 +0200
+++ linux-2.6.0-test1-bk3/fs/vfat/namei.c	2003-07-27 16:47:54.000000000 +0200
@@ -114,6 +114,17 @@
 	return 0;
 }
 
+/* returns the length of a struct qstr, ignoring trailing dots */
+static inline unsigned int vfat_qstrlen(struct qstr *qstr)
+{
+	unsigned int len = qstr->len;
+	
+	while (len && qstr->name[len-1] == '.')
+		len--;
+	
+	return len;
+}
+
 /*
  * Compute the hash for the vfat name corresponding to the dentry.
  * Note: if the name is invalid, we leave the hash code unchanged so
@@ -122,15 +133,7 @@
  */
 static int vfat_hash(struct dentry *dentry, struct qstr *qstr)
 {
-	const unsigned char *name;
-	int len;
-
-	len = qstr->len;
-	name = qstr->name;
-	while (len && name[len-1] == '.')
-		len--;
-
-	qstr->hash = full_name_hash(name, len);
+	qstr->hash = full_name_hash(qstr->name, vfat_qstrlen(qstr));
 
 	return 0;
 }
@@ -145,13 +148,11 @@
 {
 	struct nls_table *t = MSDOS_SB(dentry->d_inode->i_sb)->nls_io;
 	const unsigned char *name;
-	int len;
+	unsigned int len;
 	unsigned long hash;
 
-	len = qstr->len;
 	name = qstr->name;
-	while (len && name[len-1] == '.')
-		len--;
+	len = vfat_qstrlen(qstr);
 
 	hash = init_name_hash();
 	while (len--)
@@ -167,15 +168,11 @@
 static int vfat_cmpi(struct dentry *dentry, struct qstr *a, struct qstr *b)
 {
 	struct nls_table *t = MSDOS_SB(dentry->d_inode->i_sb)->nls_io;
-	int alen, blen;
+	unsigned int alen, blen;
 
 	/* A filename cannot end in '.' or we treat it like it has none */
-	alen = a->len;
-	blen = b->len;
-	while (alen && a->name[alen-1] == '.')
-		alen--;
-	while (blen && b->name[blen-1] == '.')
-		blen--;
+	alen = vfat_qstrlen(a);
+	blen = vfat_qstrlen(b);
 	if (alen == blen) {
 		if (vfat_strnicmp(t, a->name, b->name, alen) == 0)
 			return 0;
@@ -188,15 +185,11 @@
  */
 static int vfat_cmp(struct dentry *dentry, struct qstr *a, struct qstr *b)
 {
-	int alen, blen;
+	unsigned int alen, blen;
 
 	/* A filename cannot end in '.' or we treat it like it has none */
-	alen = a->len;
-	blen = b->len;
-	while (alen && a->name[alen-1] == '.')
-		alen--;
-	while (blen && b->name[blen-1] == '.')
-		blen--;
+	alen = vfat_qstrlen(a);
+	blen = vfat_qstrlen(b);
 	if (alen == blen) {
 		if (strncmp(a->name, b->name, alen) == 0)
 			return 0;
@@ -761,7 +754,7 @@
 	struct msdos_dir_slot *dir_slots;
 	loff_t offset;
 	int slots, slot;
-	int res, len;
+	int res;
 	struct msdos_dir_entry *dummy_de;
 	struct buffer_head *dummy_bh;
 	loff_t dummy_i_pos;
@@ -771,10 +764,7 @@
 	if (dir_slots == NULL)
 		return -ENOMEM;
 
-	len = qname->len;
-	while (len && qname->name[len-1] == '.')
-		len--;
-	res = vfat_build_slots(dir, qname->name, len,
+	res = vfat_build_slots(dir, qname->name, vfat_qstrlen(qname),
 			       dir_slots, &slots, is_dir);
 	if (res < 0)
 		goto cleanup;
@@ -825,12 +815,9 @@
 {
 	struct super_block *sb = dir->i_sb;
 	loff_t offset;
-	int res,len;
+	int res;
 
-	len = qname->len;
-	while (len && qname->name[len-1] == '.') 
-		len--;
-	res = fat_search_long(dir, qname->name, len,
+	res = fat_search_long(dir, qname->name, vfat_qstrlen(qname),
 			(MSDOS_SB(sb)->options.name_check != 's'),
 			&offset,&sinfo->longname_offset);
 	if (res>0) {

             reply	other threads:[~2003-07-27 15:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-27 15:10 Ren [this message]
2003-07-27 16:33 ` [PATCH] Consolidate dot-stripping code OGAWA Hirofumi

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=20030727171002.3f8eaed5.l.s.r@web.de \
    --to=l.s.r@web.de \
    --cc=hirofumi@mail.parknet.co.jp \
    --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;
as well as URLs for NNTP newsgroup(s).