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_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>

authored by

Chi Zhiling and committed by
Namjae Jeon
6f2cbe45 f5e5177f

+13 -45
+11 -36
fs/exfat/dir.c
··· 562 562 return err; 563 563 } 564 564 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 - 597 565 static int exfat_find_location(struct super_block *sb, struct exfat_chain *p_dir, 598 566 int entry, sector_t *sector, int *offset) 599 567 { ··· 571 603 572 604 off = EXFAT_DEN_TO_B(entry); 573 605 574 - ret = exfat_walk_fat_chain(sb, p_dir, off, &clu); 606 + clu = p_dir->dir; 607 + ret = exfat_cluster_walk(sb, &clu, EXFAT_B_TO_CLU(off, sbi), p_dir->flags); 575 608 if (ret) 576 609 return ret; 610 + 611 + if (clu == EXFAT_EOF_CLUSTER) { 612 + exfat_fs_error(sb, 613 + "unexpected early break in cluster chain (clu : %u, len : %d)", 614 + p_dir->dir, 615 + EXFAT_B_TO_CLU(off, sbi)); 616 + return -EIO; 617 + } 577 618 578 619 if (!exfat_test_bitmap(sb, clu)) { 579 620 exfat_err(sb, "failed to test cluster bit(%u)", clu); ··· 769 792 if (exfat_is_last_sector_in_cluster(sbi, sec)) { 770 793 unsigned int clu = exfat_sector_to_cluster(sbi, sec); 771 794 772 - if (p_dir->flags == ALLOC_NO_FAT_CHAIN) 773 - clu++; 774 - else if (exfat_get_next_cluster(sb, &clu)) 795 + if (exfat_cluster_walk(sb, &clu, 1, p_dir->flags)) 775 796 goto put_es; 776 797 sec = exfat_cluster_to_sector(sbi, clu); 777 798 } else {
+2 -9
fs/exfat/inode.c
··· 225 225 * *clu = (the first cluster of the allocated chain) => 226 226 * (the last cluster of ...) 227 227 */ 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; 237 230 *count = 1; 238 231 } 239 232