summaryrefslogtreecommitdiffstats
path: root/fs/adfs/dir.c
diff options
context:
space:
mode:
authorRussell King <rmk+kernel@armlinux.org.uk>2019-03-24 13:22:04 +0100
committerRussell King <rmk+kernel@armlinux.org.uk>2019-05-31 11:30:49 +0200
commit525715d0161f360df5f9f7ba8d9b77f60068dec5 (patch)
tree25c465d54662172231dad7921ec2665bb4b3ef31 /fs/adfs/dir.c
parentfs/adfs: factor out filename comparison (diff)
downloadlinux-525715d0161f360df5f9f7ba8d9b77f60068dec5.tar.xz
linux-525715d0161f360df5f9f7ba8d9b77f60068dec5.zip
fs/adfs: factor out filename case lowering
Factor out the filename case lowering of directory names when comparing or hashing filenames. Acked-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Diffstat (limited to 'fs/adfs/dir.c')
-rw-r--r--fs/adfs/dir.c34
1 files changed, 12 insertions, 22 deletions
diff --git a/fs/adfs/dir.c b/fs/adfs/dir.c
index bebe2ab86aae..be4b4f950500 100644
--- a/fs/adfs/dir.c
+++ b/fs/adfs/dir.c
@@ -100,6 +100,13 @@ out:
return ret;
}
+static unsigned char adfs_tolower(unsigned char c)
+{
+ if (c >= 'A' && c <= 'Z')
+ c += 'a' - 'A';
+ return c;
+}
+
static int __adfs_compare(const unsigned char *qstr, u32 qlen,
const char *str, u32 len)
{
@@ -108,20 +115,10 @@ static int __adfs_compare(const unsigned char *qstr, u32 qlen,
if (qlen != len)
return 1;
- for (i = 0; i < qlen; i++) {
- unsigned char qc, c;
-
- qc = qstr[i];
- c = str[i];
-
- if (qc >= 'A' && qc <= 'Z')
- qc += 'a' - 'A';
- if (c >= 'A' && c <= 'Z')
- c += 'a' - 'A';
-
- if (qc != c)
+ for (i = 0; i < qlen; i++)
+ if (adfs_tolower(qstr[i]) != adfs_tolower(str[i]))
return 1;
- }
+
return 0;
}
@@ -198,15 +195,8 @@ adfs_hash(const struct dentry *parent, struct qstr *qstr)
qstr->len = i = name_len;
name = qstr->name;
hash = init_name_hash(parent);
- while (i--) {
- char c;
-
- c = *name++;
- if (c >= 'A' && c <= 'Z')
- c += 'a' - 'A';
-
- hash = partial_name_hash(c, hash);
- }
+ while (i--)
+ hash = partial_name_hash(adfs_tolower(*name++), hash);
qstr->hash = end_name_hash(hash);
return 0;