Skip to content

Commit 08cf4a8

Browse files
Chi Zhilingnamjaejeon
authored andcommitted
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>
1 parent 227468f commit 08cf4a8

2 files changed

Lines changed: 25 additions & 74 deletions

File tree

fs/exfat/dir.c

Lines changed: 18 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,19 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent
9393
clu_offset = EXFAT_DEN_TO_CLU(dentry, sbi);
9494
exfat_chain_dup(&clu, &dir);
9595

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) {
10097
/* hint_information */
10198
if (clu_offset > 0 && ei->hint_bmap.off != EXFAT_EOF_CLUSTER &&
10299
ei->hint_bmap.off > 0 && clu_offset >= ei->hint_bmap.off) {
103100
clu_offset -= ei->hint_bmap.off;
104101
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;
112103
}
113104
}
114105

106+
if (exfat_chain_advance(sb, &clu, clu_offset))
107+
return -EIO;
108+
115109
while (clu.dir != EXFAT_EOF_CLUSTER && dentry < max_dentries) {
116110
i = dentry & (dentries_per_clu - 1);
117111

@@ -160,15 +154,8 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent
160154
return 0;
161155
}
162156

163-
if (clu.flags == ALLOC_NO_FAT_CHAIN) {
164-
if (--clu.size > 0)
165-
clu.dir++;
166-
else
167-
clu.dir = EXFAT_EOF_CLUSTER;
168-
} else {
169-
if (exfat_get_next_cluster(sb, &(clu.dir)))
170-
return -EIO;
171-
}
157+
if (exfat_chain_advance(sb, &clu, 1))
158+
return -EIO;
172159
}
173160

174161
out:
@@ -1085,19 +1072,12 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
10851072
step = DIRENT_STEP_FILE;
10861073
}
10871074

1088-
if (clu.flags == ALLOC_NO_FAT_CHAIN) {
1089-
if (--clu.size > 0)
1090-
clu.dir++;
1091-
else
1092-
clu.dir = EXFAT_EOF_CLUSTER;
1093-
} else {
1094-
if (exfat_get_next_cluster(sb, &clu.dir))
1095-
return -EIO;
1075+
if (exfat_chain_advance(sb, &clu, 1))
1076+
return -EIO;
10961077

1097-
/* break if the cluster chain includes a loop */
1098-
if (unlikely(++clu_count > EXFAT_DATA_CLUSTER_COUNT(sbi)))
1099-
goto not_found;
1100-
}
1078+
/* break if the cluster chain includes a loop */
1079+
if (unlikely(++clu_count > EXFAT_DATA_CLUSTER_COUNT(sbi)))
1080+
goto not_found;
11011081
}
11021082

11031083
not_found:
@@ -1132,14 +1112,7 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
11321112
if (!((dentry + 1) & (dentries_per_clu - 1))) {
11331113
int ret = 0;
11341114

1135-
if (clu.flags == ALLOC_NO_FAT_CHAIN) {
1136-
if (--clu.size > 0)
1137-
clu.dir++;
1138-
else
1139-
clu.dir = EXFAT_EOF_CLUSTER;
1140-
} else {
1141-
ret = exfat_get_next_cluster(sb, &clu.dir);
1142-
}
1115+
ret = exfat_chain_advance(sb, &clu, 1);
11431116

11441117
if (ret || clu.dir == EXFAT_EOF_CLUSTER) {
11451118
/* just initialized hint_stat */
@@ -1184,20 +1157,12 @@ int exfat_count_dir_entries(struct super_block *sb, struct exfat_chain *p_dir)
11841157
count++;
11851158
}
11861159

1187-
if (clu.flags == ALLOC_NO_FAT_CHAIN) {
1188-
if (--clu.size > 0)
1189-
clu.dir++;
1190-
else
1191-
clu.dir = EXFAT_EOF_CLUSTER;
1192-
} else {
1193-
if (exfat_get_next_cluster(sb, &(clu.dir)))
1194-
return -EIO;
1195-
1196-
if (unlikely(++clu_count > sbi->used_clusters)) {
1197-
exfat_fs_error(sb, "FAT or bitmap is corrupted");
1198-
return -EIO;
1199-
}
1160+
if (exfat_chain_advance(sb, &clu, 1))
1161+
return -EIO;
12001162

1163+
if (unlikely(++clu_count > sbi->used_clusters)) {
1164+
exfat_fs_error(sb, "FAT or bitmap is corrupted");
1165+
return -EIO;
12011166
}
12021167
}
12031168

fs/exfat/namei.c

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,8 @@ static int exfat_search_empty_slot(struct super_block *sb,
246246
i += ret;
247247

248248
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;
258251

259252
i -= dentries_per_clu;
260253
}
@@ -925,19 +918,12 @@ static int exfat_check_dir_empty(struct super_block *sb,
925918
return -ENOTEMPTY;
926919
}
927920

928-
if (clu.flags == ALLOC_NO_FAT_CHAIN) {
929-
if (--clu.size > 0)
930-
clu.dir++;
931-
else
932-
clu.dir = EXFAT_EOF_CLUSTER;
933-
} else {
934-
if (exfat_get_next_cluster(sb, &(clu.dir)))
935-
return -EIO;
921+
if (exfat_chain_advance(sb, &clu, 1))
922+
return -EIO;
936923

937-
/* break if the cluster chain includes a loop */
938-
if (unlikely(++clu_count > EXFAT_DATA_CLUSTER_COUNT(sbi)))
939-
break;
940-
}
924+
/* break if the cluster chain includes a loop */
925+
if (unlikely(++clu_count > EXFAT_DATA_CLUSTER_COUNT(sbi)))
926+
break;
941927
}
942928

943929
return 0;

0 commit comments

Comments
 (0)