Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

exfat: use exfat_chain_advance helper

Replace open-coded cluster chain walking logic with exfat_chain_advance()
across exfat_readdir, exfat_find_dir_entry, exfat_count_dir_entries,
exfat_search_empty_slot and exfat_check_dir_empty.

Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn>
Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
Reviewed-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>

authored by

Chi Zhiling and committed by
Namjae Jeon
08cf4a81 227468fc

+25 -74
+18 -53
fs/exfat/dir.c
··· 93 93 clu_offset = EXFAT_DEN_TO_CLU(dentry, sbi); 94 94 exfat_chain_dup(&clu, &dir); 95 95 96 - if (clu.flags == ALLOC_NO_FAT_CHAIN) { 97 - clu.dir += clu_offset; 98 - clu.size -= clu_offset; 99 - } else { 96 + if (clu.flags == ALLOC_FAT_CHAIN) { 100 97 /* hint_information */ 101 98 if (clu_offset > 0 && ei->hint_bmap.off != EXFAT_EOF_CLUSTER && 102 99 ei->hint_bmap.off > 0 && clu_offset >= ei->hint_bmap.off) { 103 100 clu_offset -= ei->hint_bmap.off; 104 101 clu.dir = ei->hint_bmap.clu; 105 - } 106 - 107 - while (clu_offset > 0 && clu.dir != EXFAT_EOF_CLUSTER) { 108 - if (exfat_get_next_cluster(sb, &(clu.dir))) 109 - return -EIO; 110 - 111 - clu_offset--; 102 + clu.size -= ei->hint_bmap.off; 112 103 } 113 104 } 105 + 106 + if (exfat_chain_advance(sb, &clu, clu_offset)) 107 + return -EIO; 114 108 115 109 while (clu.dir != EXFAT_EOF_CLUSTER && dentry < max_dentries) { 116 110 i = dentry & (dentries_per_clu - 1); ··· 154 160 return 0; 155 161 } 156 162 157 - if (clu.flags == ALLOC_NO_FAT_CHAIN) { 158 - if (--clu.size > 0) 159 - clu.dir++; 160 - else 161 - clu.dir = EXFAT_EOF_CLUSTER; 162 - } else { 163 - if (exfat_get_next_cluster(sb, &(clu.dir))) 164 - return -EIO; 165 - } 163 + if (exfat_chain_advance(sb, &clu, 1)) 164 + return -EIO; 166 165 } 167 166 168 167 out: ··· 1072 1085 step = DIRENT_STEP_FILE; 1073 1086 } 1074 1087 1075 - if (clu.flags == ALLOC_NO_FAT_CHAIN) { 1076 - if (--clu.size > 0) 1077 - clu.dir++; 1078 - else 1079 - clu.dir = EXFAT_EOF_CLUSTER; 1080 - } else { 1081 - if (exfat_get_next_cluster(sb, &clu.dir)) 1082 - return -EIO; 1088 + if (exfat_chain_advance(sb, &clu, 1)) 1089 + return -EIO; 1083 1090 1084 - /* break if the cluster chain includes a loop */ 1085 - if (unlikely(++clu_count > EXFAT_DATA_CLUSTER_COUNT(sbi))) 1086 - goto not_found; 1087 - } 1091 + /* break if the cluster chain includes a loop */ 1092 + if (unlikely(++clu_count > EXFAT_DATA_CLUSTER_COUNT(sbi))) 1093 + goto not_found; 1088 1094 } 1089 1095 1090 1096 not_found: ··· 1112 1132 if (!((dentry + 1) & (dentries_per_clu - 1))) { 1113 1133 int ret = 0; 1114 1134 1115 - if (clu.flags == ALLOC_NO_FAT_CHAIN) { 1116 - if (--clu.size > 0) 1117 - clu.dir++; 1118 - else 1119 - clu.dir = EXFAT_EOF_CLUSTER; 1120 - } else { 1121 - ret = exfat_get_next_cluster(sb, &clu.dir); 1122 - } 1135 + ret = exfat_chain_advance(sb, &clu, 1); 1123 1136 1124 1137 if (ret || clu.dir == EXFAT_EOF_CLUSTER) { 1125 1138 /* just initialized hint_stat */ ··· 1157 1184 count++; 1158 1185 } 1159 1186 1160 - if (clu.flags == ALLOC_NO_FAT_CHAIN) { 1161 - if (--clu.size > 0) 1162 - clu.dir++; 1163 - else 1164 - clu.dir = EXFAT_EOF_CLUSTER; 1165 - } else { 1166 - if (exfat_get_next_cluster(sb, &(clu.dir))) 1167 - return -EIO; 1187 + if (exfat_chain_advance(sb, &clu, 1)) 1188 + return -EIO; 1168 1189 1169 - if (unlikely(++clu_count > sbi->used_clusters)) { 1170 - exfat_fs_error(sb, "FAT or bitmap is corrupted"); 1171 - return -EIO; 1172 - } 1173 - 1190 + if (unlikely(++clu_count > sbi->used_clusters)) { 1191 + exfat_fs_error(sb, "FAT or bitmap is corrupted"); 1192 + return -EIO; 1174 1193 } 1175 1194 } 1176 1195
+7 -21
fs/exfat/namei.c
··· 246 246 i += ret; 247 247 248 248 while (i >= dentries_per_clu) { 249 - if (clu.flags == ALLOC_NO_FAT_CHAIN) { 250 - if (--clu.size > 0) 251 - clu.dir++; 252 - else 253 - clu.dir = EXFAT_EOF_CLUSTER; 254 - } else { 255 - if (exfat_get_next_cluster(sb, &clu.dir)) 256 - return -EIO; 257 - } 249 + if (exfat_chain_advance(sb, &clu, 1)) 250 + return -EIO; 258 251 259 252 i -= dentries_per_clu; 260 253 } ··· 918 925 return -ENOTEMPTY; 919 926 } 920 927 921 - if (clu.flags == ALLOC_NO_FAT_CHAIN) { 922 - if (--clu.size > 0) 923 - clu.dir++; 924 - else 925 - clu.dir = EXFAT_EOF_CLUSTER; 926 - } else { 927 - if (exfat_get_next_cluster(sb, &(clu.dir))) 928 - return -EIO; 928 + if (exfat_chain_advance(sb, &clu, 1)) 929 + return -EIO; 929 930 930 - /* break if the cluster chain includes a loop */ 931 - if (unlikely(++clu_count > EXFAT_DATA_CLUSTER_COUNT(sbi))) 932 - break; 933 - } 931 + /* break if the cluster chain includes a loop */ 932 + if (unlikely(++clu_count > EXFAT_DATA_CLUSTER_COUNT(sbi))) 933 + break; 934 934 } 935 935 936 936 return 0;