aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRussell King <rmk+kernel@armlinux.org.uk>2019-03-24 06:54:03 -0400
committerRussell King <rmk+kernel@armlinux.org.uk>2019-05-31 05:30:36 -0400
commit1e504cf85dddb9dd2f4c262a72277d2f9564cbea (patch)
tree7b2425721fcdc8864e14c14495a3d044a1608648
parente93c9c99a629c61837d5a7fc2120cd2b6c70dbdd (diff)
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: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
-rw-r--r--fs/adfs/dir.c68
1 files 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 @@ out:
100 return ret; 100 return ret;
101} 101}
102 102
103static int 103static int __adfs_compare(const unsigned char *qstr, u32 qlen,
104adfs_match(const struct qstr *name, struct object_info *obj) 104 const char *str, u32 len)
105{ 105{
106 int i; 106 u32 i;
107 107
108 if (name->len != obj->name_len) 108 if (qlen != len)
109 return 0; 109 return 1;
110 110
111 for (i = 0; i < name->len; i++) { 111 for (i = 0; i < qlen; i++) {
112 char c1, c2; 112 unsigned char qc, c;
113 113
114 c1 = name->name[i]; 114 qc = qstr[i];
115 c2 = obj->name[i]; 115 c = str[i];
116 116
117 if (c1 >= 'A' && c1 <= 'Z') 117 if (qc >= 'A' && qc <= 'Z')
118 c1 += 'a' - 'A'; 118 qc += 'a' - 'A';
119 if (c2 >= 'A' && c2 <= 'Z') 119 if (c >= 'A' && c <= 'Z')
120 c2 += 'a' - 'A'; 120 c += 'a' - 'A';
121 121
122 if (c1 != c2) 122 if (qc != c)
123 return 0; 123 return 1;
124 } 124 }
125 return 1; 125 return 0;
126} 126}
127 127
128static int 128static int adfs_dir_lookup_byname(struct inode *inode, const struct qstr *qstr,
129adfs_dir_lookup_byname(struct inode *inode, const struct qstr *name, struct object_info *obj) 129 struct object_info *obj)
130{ 130{
131 struct super_block *sb = inode->i_sb; 131 struct super_block *sb = inode->i_sb;
132 const struct adfs_dir_ops *ops = ADFS_SB(sb)->s_dir; 132 const struct adfs_dir_ops *ops = ADFS_SB(sb)->s_dir;
133 const unsigned char *name;
133 struct adfs_dir dir; 134 struct adfs_dir dir;
135 u32 name_len;
134 int ret; 136 int ret;
135 137
136 ret = ops->read(sb, inode->i_ino, inode->i_size, &dir); 138 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 goto unlock_out; 155 goto unlock_out;
154 156
155 ret = -ENOENT; 157 ret = -ENOENT;
158 name = qstr->name;
159 name_len = qstr->len;
156 while (ops->getnext(&dir, obj) == 0) { 160 while (ops->getnext(&dir, obj) == 0) {
157 if (adfs_match(name, obj)) { 161 if (!__adfs_compare(name, name_len, obj->name, obj->name_len)) {
158 ret = 0; 162 ret = 0;
159 break; 163 break;
160 } 164 }
@@ -212,30 +216,10 @@ adfs_hash(const struct dentry *parent, struct qstr *qstr)
212 * Compare two names, taking note of the name length 216 * Compare two names, taking note of the name length
213 * requirements of the underlying filesystem. 217 * requirements of the underlying filesystem.
214 */ 218 */
215static int 219static int adfs_compare(const struct dentry *dentry, unsigned int len,
216adfs_compare(const struct dentry *dentry, 220 const char *str, const struct qstr *qstr)
217 unsigned int len, const char *str, const struct qstr *name)
218{ 221{
219 int i; 222 return __adfs_compare(qstr->name, qstr->len, str, len);
220
221 if (len != name->len)
222 return 1;
223
224 for (i = 0; i < name->len; i++) {
225 char a, b;
226
227 a = str[i];
228 b = name->name[i];
229
230 if (a >= 'A' && a <= 'Z')
231 a += 'a' - 'A';
232 if (b >= 'A' && b <= 'Z')
233 b += 'a' - 'A';
234
235 if (a != b)
236 return 1;
237 }
238 return 0;
239} 223}
240 224
241const struct dentry_operations adfs_dentry_operations = { 225const struct dentry_operations adfs_dentry_operations = {