Skip to content

Commit 6f2cbe4

Browse files
Chi Zhilingnamjaejeon
authored andcommitted
exfat: use exfat_cluster_walk helper
Replace the custom exfat_walk_fat_chain() function and open-coded FAT chain walking logic with the exfat_cluster_walk() helper across exfat_find_location, __exfat_get_dentry_set, and exfat_map_cluster. Suggested-by: Sungjong Seo <sj1557.seo@samsung.com> 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 f5e5177 commit 6f2cbe4

2 files changed

Lines changed: 13 additions & 45 deletions

File tree

fs/exfat/dir.c

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -562,38 +562,6 @@ int exfat_put_dentry_set(struct exfat_entry_set_cache *es, int sync)
562562
return err;
563563
}
564564

565-
static int exfat_walk_fat_chain(struct super_block *sb,
566-
struct exfat_chain *p_dir, unsigned int byte_offset,
567-
unsigned int *clu)
568-
{
569-
struct exfat_sb_info *sbi = EXFAT_SB(sb);
570-
unsigned int clu_offset;
571-
unsigned int cur_clu;
572-
573-
clu_offset = EXFAT_B_TO_CLU(byte_offset, sbi);
574-
cur_clu = p_dir->dir;
575-
576-
if (p_dir->flags == ALLOC_NO_FAT_CHAIN) {
577-
cur_clu += clu_offset;
578-
} else {
579-
while (clu_offset > 0) {
580-
if (exfat_get_next_cluster(sb, &cur_clu))
581-
return -EIO;
582-
if (cur_clu == EXFAT_EOF_CLUSTER) {
583-
exfat_fs_error(sb,
584-
"invalid dentry access beyond EOF (clu : %u, eidx : %d)",
585-
p_dir->dir,
586-
EXFAT_B_TO_DEN(byte_offset));
587-
return -EIO;
588-
}
589-
clu_offset--;
590-
}
591-
}
592-
593-
*clu = cur_clu;
594-
return 0;
595-
}
596-
597565
static int exfat_find_location(struct super_block *sb, struct exfat_chain *p_dir,
598566
int entry, sector_t *sector, int *offset)
599567
{
@@ -603,10 +571,19 @@ static int exfat_find_location(struct super_block *sb, struct exfat_chain *p_dir
603571

604572
off = EXFAT_DEN_TO_B(entry);
605573

606-
ret = exfat_walk_fat_chain(sb, p_dir, off, &clu);
574+
clu = p_dir->dir;
575+
ret = exfat_cluster_walk(sb, &clu, EXFAT_B_TO_CLU(off, sbi), p_dir->flags);
607576
if (ret)
608577
return ret;
609578

579+
if (clu == EXFAT_EOF_CLUSTER) {
580+
exfat_fs_error(sb,
581+
"unexpected early break in cluster chain (clu : %u, len : %d)",
582+
p_dir->dir,
583+
EXFAT_B_TO_CLU(off, sbi));
584+
return -EIO;
585+
}
586+
610587
if (!exfat_test_bitmap(sb, clu)) {
611588
exfat_err(sb, "failed to test cluster bit(%u)", clu);
612589
return -EIO;
@@ -792,9 +769,7 @@ static int __exfat_get_dentry_set(struct exfat_entry_set_cache *es,
792769
if (exfat_is_last_sector_in_cluster(sbi, sec)) {
793770
unsigned int clu = exfat_sector_to_cluster(sbi, sec);
794771

795-
if (p_dir->flags == ALLOC_NO_FAT_CHAIN)
796-
clu++;
797-
else if (exfat_get_next_cluster(sb, &clu))
772+
if (exfat_cluster_walk(sb, &clu, 1, p_dir->flags))
798773
goto put_es;
799774
sec = exfat_cluster_to_sector(sbi, clu);
800775
} else {

fs/exfat/inode.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,8 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
225225
* *clu = (the first cluster of the allocated chain) =>
226226
* (the last cluster of ...)
227227
*/
228-
if (ei->flags == ALLOC_NO_FAT_CHAIN) {
229-
*clu += num_to_be_allocated - 1;
230-
} else {
231-
while (num_to_be_allocated > 1) {
232-
if (exfat_get_next_cluster(sb, clu))
233-
return -EIO;
234-
num_to_be_allocated--;
235-
}
236-
}
228+
if (exfat_cluster_walk(sb, clu, num_to_be_allocated - 1, ei->flags))
229+
return -EIO;
237230
*count = 1;
238231
}
239232

0 commit comments

Comments
 (0)