Commit 1e504cf8 authored by Russell King's avatar Russell King

fs/adfs: factor out filename comparison

We have essentially the same code in adfs_compare() as adfs_match(), so
arrange to use a common implementation.
Acked-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
parent e93c9c99
...@@ -100,37 +100,39 @@ adfs_dir_update(struct super_block *sb, struct object_info *obj, int wait) ...@@ -100,37 +100,39 @@ adfs_dir_update(struct super_block *sb, struct object_info *obj, int wait)
return ret; return ret;
} }
static int static int __adfs_compare(const unsigned char *qstr, u32 qlen,
adfs_match(const struct qstr *name, struct object_info *obj) const char *str, u32 len)
{ {
int i; u32 i;
if (name->len != obj->name_len) if (qlen != len)
return 0; return 1;
for (i = 0; i < name->len; i++) { for (i = 0; i < qlen; i++) {
char c1, c2; unsigned char qc, c;
c1 = name->name[i]; qc = qstr[i];
c2 = obj->name[i]; c = str[i];
if (c1 >= 'A' && c1 <= 'Z') if (qc >= 'A' && qc <= 'Z')
c1 += 'a' - 'A'; qc += 'a' - 'A';
if (c2 >= 'A' && c2 <= 'Z') if (c >= 'A' && c <= 'Z')
c2 += 'a' - 'A'; c += 'a' - 'A';
if (c1 != c2) if (qc != c)
return 0; return 1;
} }
return 1; return 0;
} }
static int static int adfs_dir_lookup_byname(struct inode *inode, const struct qstr *qstr,
adfs_dir_lookup_byname(struct inode *inode, const struct qstr *name, struct object_info *obj) struct object_info *obj)
{ {
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
const struct adfs_dir_ops *ops = ADFS_SB(sb)->s_dir; const struct adfs_dir_ops *ops = ADFS_SB(sb)->s_dir;
const unsigned char *name;
struct adfs_dir dir; struct adfs_dir dir;
u32 name_len;
int ret; int ret;
ret = ops->read(sb, inode->i_ino, inode->i_size, &dir); 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 ...@@ -153,8 +155,10 @@ adfs_dir_lookup_byname(struct inode *inode, const struct qstr *name, struct obje
goto unlock_out; goto unlock_out;
ret = -ENOENT; ret = -ENOENT;
name = qstr->name;
name_len = qstr->len;
while (ops->getnext(&dir, obj) == 0) { while (ops->getnext(&dir, obj) == 0) {
if (adfs_match(name, obj)) { if (!__adfs_compare(name, name_len, obj->name, obj->name_len)) {
ret = 0; ret = 0;
break; break;
} }
...@@ -212,30 +216,10 @@ adfs_hash(const struct dentry *parent, struct qstr *qstr) ...@@ -212,30 +216,10 @@ adfs_hash(const struct dentry *parent, struct qstr *qstr)
* Compare two names, taking note of the name length * Compare two names, taking note of the name length
* requirements of the underlying filesystem. * requirements of the underlying filesystem.
*/ */
static int static int adfs_compare(const struct dentry *dentry, unsigned int len,
adfs_compare(const struct dentry *dentry, const char *str, const struct qstr *qstr)
unsigned int len, const char *str, const struct qstr *name)
{ {
int i; return __adfs_compare(qstr->name, qstr->len, str, len);
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;
} }
const struct dentry_operations adfs_dentry_operations = { const struct dentry_operations adfs_dentry_operations = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment