Skip to content

Commit

Permalink
fs/adfs: factor out filename case lowering
Browse files Browse the repository at this point in the history
Factor out the filename case lowering of directory names when comparing
or hashing filenames.

Acked-by: Al Viro <[email protected]>
Signed-off-by: Russell King <[email protected]>
  • Loading branch information
Russell King committed May 31, 2019
1 parent 1e504cf commit 525715d
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions fs/adfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ adfs_dir_update(struct super_block *sb, struct object_info *obj, int wait)
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)
{
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 525715d

Please sign in to comment.