@@ -75,21 +75,22 @@ int f2fs_init_casefolded_name(const struct inode *dir,
7575 struct f2fs_filename * fname )
7676{
7777#ifdef CONFIG_UNICODE
78- struct f2fs_sb_info * sbi = F2FS_SB (dir -> i_sb );
78+ struct super_block * sb = dir -> i_sb ;
79+ struct f2fs_sb_info * sbi = F2FS_SB (sb );
7980
8081 if (IS_CASEFOLDED (dir )) {
8182 fname -> cf_name .name = f2fs_kmalloc (sbi , F2FS_NAME_LEN ,
8283 GFP_NOFS );
8384 if (!fname -> cf_name .name )
8485 return - ENOMEM ;
85- fname -> cf_name .len = utf8_casefold (sbi -> s_encoding ,
86+ fname -> cf_name .len = utf8_casefold (sb -> s_encoding ,
8687 fname -> usr_fname ,
8788 fname -> cf_name .name ,
8889 F2FS_NAME_LEN );
8990 if ((int )fname -> cf_name .len <= 0 ) {
9091 kfree (fname -> cf_name .name );
9192 fname -> cf_name .name = NULL ;
92- if (f2fs_has_strict_mode ( sbi ))
93+ if (sb_has_strict_encoding ( sb ))
9394 return - EINVAL ;
9495 /* fall back to treating name as opaque byte sequence */
9596 }
@@ -215,8 +216,8 @@ static struct f2fs_dir_entry *find_in_block(struct inode *dir,
215216static bool f2fs_match_ci_name (const struct inode * dir , const struct qstr * name ,
216217 const u8 * de_name , u32 de_name_len )
217218{
218- const struct f2fs_sb_info * sbi = F2FS_SB ( dir -> i_sb ) ;
219- const struct unicode_map * um = sbi -> s_encoding ;
219+ const struct super_block * sb = dir -> i_sb ;
220+ const struct unicode_map * um = sb -> s_encoding ;
220221 struct qstr entry = QSTR_INIT (de_name , de_name_len );
221222 int res ;
222223
@@ -226,7 +227,7 @@ static bool f2fs_match_ci_name(const struct inode *dir, const struct qstr *name,
226227 * In strict mode, ignore invalid names. In non-strict mode,
227228 * fall back to treating them as opaque byte sequences.
228229 */
229- if (f2fs_has_strict_mode ( sbi ) || name -> len != entry .len )
230+ if (sb_has_strict_encoding ( sb ) || name -> len != entry .len )
230231 return false;
231232 return !memcmp (name -> name , entry .name , name -> len );
232233 }
@@ -1107,75 +1108,8 @@ const struct file_operations f2fs_dir_operations = {
11071108};
11081109
11091110#ifdef CONFIG_UNICODE
1110- static int f2fs_d_compare (const struct dentry * dentry , unsigned int len ,
1111- const char * str , const struct qstr * name )
1112- {
1113- const struct dentry * parent = READ_ONCE (dentry -> d_parent );
1114- const struct inode * dir = READ_ONCE (parent -> d_inode );
1115- const struct f2fs_sb_info * sbi = F2FS_SB (dentry -> d_sb );
1116- struct qstr entry = QSTR_INIT (str , len );
1117- char strbuf [DNAME_INLINE_LEN ];
1118- int res ;
1119-
1120- if (!dir || !IS_CASEFOLDED (dir ))
1121- goto fallback ;
1122-
1123- /*
1124- * If the dentry name is stored in-line, then it may be concurrently
1125- * modified by a rename. If this happens, the VFS will eventually retry
1126- * the lookup, so it doesn't matter what ->d_compare() returns.
1127- * However, it's unsafe to call utf8_strncasecmp() with an unstable
1128- * string. Therefore, we have to copy the name into a temporary buffer.
1129- */
1130- if (len <= DNAME_INLINE_LEN - 1 ) {
1131- memcpy (strbuf , str , len );
1132- strbuf [len ] = 0 ;
1133- entry .name = strbuf ;
1134- /* prevent compiler from optimizing out the temporary buffer */
1135- barrier ();
1136- }
1137-
1138- res = utf8_strncasecmp (sbi -> s_encoding , name , & entry );
1139- if (res >= 0 )
1140- return res ;
1141-
1142- if (f2fs_has_strict_mode (sbi ))
1143- return - EINVAL ;
1144- fallback :
1145- if (len != name -> len )
1146- return 1 ;
1147- return !!memcmp (str , name -> name , len );
1148- }
1149-
1150- static int f2fs_d_hash (const struct dentry * dentry , struct qstr * str )
1151- {
1152- struct f2fs_sb_info * sbi = F2FS_SB (dentry -> d_sb );
1153- const struct unicode_map * um = sbi -> s_encoding ;
1154- const struct inode * inode = READ_ONCE (dentry -> d_inode );
1155- unsigned char * norm ;
1156- int len , ret = 0 ;
1157-
1158- if (!inode || !IS_CASEFOLDED (inode ))
1159- return 0 ;
1160-
1161- norm = f2fs_kmalloc (sbi , PATH_MAX , GFP_ATOMIC );
1162- if (!norm )
1163- return - ENOMEM ;
1164-
1165- len = utf8_casefold (um , str , norm , PATH_MAX );
1166- if (len < 0 ) {
1167- if (f2fs_has_strict_mode (sbi ))
1168- ret = - EINVAL ;
1169- goto out ;
1170- }
1171- str -> hash = full_name_hash (dentry , norm , len );
1172- out :
1173- kvfree (norm );
1174- return ret ;
1175- }
1176-
11771111const struct dentry_operations f2fs_dentry_ops = {
1178- .d_hash = f2fs_d_hash ,
1179- .d_compare = f2fs_d_compare ,
1112+ .d_hash = generic_ci_d_hash ,
1113+ .d_compare = generic_ci_d_compare ,
11801114};
11811115#endif
0 commit comments