]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
exfat: introduce exfat_cluster_walk helper
authorChi Zhiling <chizhiling@kylinos.cn>
Fri, 3 Apr 2026 08:05:34 +0000 (16:05 +0800)
committerNamjae Jeon <linkinjeon@kernel.org>
Fri, 3 Apr 2026 13:41:04 +0000 (22:41 +0900)
Introduce exfat_cluster_walk() to walk the FAT chain by a given step,
handling both ALLOC_NO_FAT_CHAIN and ALLOC_FAT_CHAIN modes. Also
redefine exfat_get_next_cluster as a thin wrapper around it for
backward compatibility.

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>
fs/exfat/exfat_fs.h

index 9fed9fb33caecb2656e1fa451b08fd32e619d5e6..7f9d0cfa252b8a573348f6a289af0d649b2fc956 100644 (file)
@@ -437,7 +437,8 @@ int exfat_set_volume_dirty(struct super_block *sb);
 int exfat_clear_volume_dirty(struct super_block *sb);
 
 /* fatent.c */
-#define exfat_get_next_cluster(sb, pclu) exfat_ent_get(sb, *(pclu), pclu, NULL)
+#define exfat_get_next_cluster(sb, pclu) \
+       exfat_cluster_walk(sb, (pclu), 1, ALLOC_FAT_CHAIN)
 
 int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
                struct exfat_chain *p_chain, bool sync_bmap);
@@ -456,6 +457,26 @@ int exfat_count_num_clusters(struct super_block *sb,
 int exfat_blk_readahead(struct super_block *sb, sector_t sec,
                sector_t *ra, blkcnt_t *ra_cnt, sector_t end);
 
+static inline int
+exfat_cluster_walk(struct super_block *sb, unsigned int *clu,
+               unsigned int step, int flags)
+{
+       struct buffer_head *bh = NULL;
+
+       if (flags == ALLOC_NO_FAT_CHAIN) {
+               (*clu) += step;
+               return 0;
+       }
+
+       while (step--) {
+               if (exfat_ent_get(sb, *clu, clu, &bh))
+                       return -EIO;
+       }
+       brelse(bh);
+
+       return 0;
+}
+
 /* balloc.c */
 int exfat_load_bitmap(struct super_block *sb);
 void exfat_free_bitmap(struct exfat_sb_info *sbi);