From: Russell King <rmk+kernel@armlinux.org.uk>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org
Subject: [PATCH 1/7] fs/adfs: factor out filename comparison
Date: Mon, 20 May 2019 15:13:03 +0100 [thread overview]
Message-ID: <E1hSj2F-0000LH-Jc@rmk-PC.armlinux.org.uk> (raw)
In-Reply-To: <20190520141227.krqowhs3yg7hpige@shell.armlinux.org.uk>
We have essentially the same code in adfs_compare() as adfs_match(), so
arrange to use a common implementation.
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
---
fs/adfs/dir.c | 68 +++++++++++++++++++++++------------------------------------
1 file changed, 26 insertions(+), 42 deletions(-)
diff --git a/fs/adfs/dir.c b/fs/adfs/dir.c
index e18eff854e1a..bebe2ab86aae 100644
--- a/fs/adfs/dir.c
+++ b/fs/adfs/dir.c
@@ -100,37 +100,39 @@ adfs_dir_update(struct super_block *sb, struct object_info *obj, int wait)
return ret;
}
-static int
-adfs_match(const struct qstr *name, struct object_info *obj)
+static int __adfs_compare(const unsigned char *qstr, u32 qlen,
+ const char *str, u32 len)
{
- int i;
+ u32 i;
- if (name->len != obj->name_len)
- return 0;
+ if (qlen != len)
+ return 1;
- for (i = 0; i < name->len; i++) {
- char c1, c2;
+ for (i = 0; i < qlen; i++) {
+ unsigned char qc, c;
- c1 = name->name[i];
- c2 = obj->name[i];
+ qc = qstr[i];
+ c = str[i];
- if (c1 >= 'A' && c1 <= 'Z')
- c1 += 'a' - 'A';
- if (c2 >= 'A' && c2 <= 'Z')
- c2 += 'a' - 'A';
+ if (qc >= 'A' && qc <= 'Z')
+ qc += 'a' - 'A';
+ if (c >= 'A' && c <= 'Z')
+ c += 'a' - 'A';
- if (c1 != c2)
- return 0;
+ if (qc != c)
+ return 1;
}
- return 1;
+ return 0;
}
-static int
-adfs_dir_lookup_byname(struct inode *inode, const struct qstr *name, struct object_info *obj)
+static int adfs_dir_lookup_byname(struct inode *inode, const struct qstr *qstr,
+ struct object_info *obj)
{
struct super_block *sb = inode->i_sb;
const struct adfs_dir_ops *ops = ADFS_SB(sb)->s_dir;
+ const unsigned char *name;
struct adfs_dir dir;
+ u32 name_len;
int ret;
ret = ops->read(sb, inode->i_ino, inode->i_size, &dir);
@@ -153,8 +155,10 @@ adfs_dir_lookup_byname(struct inode *inode, const struct qstr *name, struct obje
goto unlock_out;
ret = -ENOENT;
+ name = qstr->name;
+ name_len = qstr->len;
while (ops->getnext(&dir, obj) == 0) {
- if (adfs_match(name, obj)) {
+ if (!__adfs_compare(name, name_len, obj->name, obj->name_len)) {
ret = 0;
break;
}
@@ -212,30 +216,10 @@ adfs_hash(const struct dentry *parent, struct qstr *qstr)
* Compare two names, taking note of the name length
* requirements of the underlying filesystem.
*/
-static int
-adfs_compare(const struct dentry *dentry,
- unsigned int len, const char *str, const struct qstr *name)
+static int adfs_compare(const struct dentry *dentry, unsigned int len,
+ const char *str, const struct qstr *qstr)
{
- int i;
-
- if (len != name->len)
- return 1;
-
- for (i = 0; i < name->len; i++) {
- char a, b;
-
- a = str[i];
- b = name->name[i];
-
- if (a >= 'A' && a <= 'Z')
- a += 'a' - 'A';
- if (b >= 'A' && b <= 'Z')
- b += 'a' - 'A';
-
- if (a != b)
- return 1;
- }
- return 0;
+ return __adfs_compare(qstr->name, qstr->len, str, len);
}
const struct dentry_operations adfs_dentry_operations = {
--
2.7.4
next prev parent reply other threads:[~2019-05-20 14:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-20 14:12 [PATCH 0/7] fs/adfs fixes Russell King - ARM Linux admin
2019-05-20 14:13 ` Russell King [this message]
2019-05-20 14:13 ` [PATCH 2/7] fs/adfs: factor out filename case lowering Russell King
2019-05-20 14:13 ` [PATCH 3/7] fs/adfs: factor out object fixups Russell King
2019-05-20 14:13 ` [PATCH 4/7] fs/adfs: factor out filename fixup Russell King
2019-05-20 14:13 ` [PATCH 5/7] fs/adfs: remove truncated filename hashing Russell King
2019-05-20 14:13 ` [PATCH 6/7] fs/adfs: move append_filetype_suffix() into adfs_object_fixup() Russell King
2019-05-20 14:13 ` [PATCH 7/7] fs/adfs: fix filename fixup handling for "/" and "//" names Russell King
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=E1hSj2F-0000LH-Jc@rmk-PC.armlinux.org.uk \
--to=rmk+kernel@armlinux.org.uk \
--cc=linux-fsdevel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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).