]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
exfat: introduce exfat_chain_advance helper
authorChi Zhiling <chizhiling@kylinos.cn>
Fri, 3 Apr 2026 08:05:37 +0000 (16:05 +0800)
committerNamjae Jeon <linkinjeon@kernel.org>
Fri, 3 Apr 2026 13:41:08 +0000 (22:41 +0900)
Introduce exfat_chain_advance() to walk a exfat_chain structure by a
given step, updating both ->dir and ->size fields atomically. This
helper handles both ALLOC_NO_FAT_CHAIN and ALLOC_FAT_CHAIN modes with
proper boundary checking.

Suggested-by: Yuezhang Mo <Yuezhang.Mo@sony.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>
fs/exfat/exfat_fs.h

index 7f9d0cfa252b8a573348f6a289af0d649b2fc956..89ef5368277f8dd144ac11b2506e171d0a22cfba 100644 (file)
@@ -552,6 +552,27 @@ int exfat_read_volume_label(struct super_block *sb,
 int exfat_write_volume_label(struct super_block *sb,
                             struct exfat_uni_name *label);
 
+static inline int exfat_chain_advance(struct super_block *sb,
+               struct exfat_chain *chain, unsigned int step)
+{
+       unsigned int clu = chain->dir;
+
+       if (unlikely(chain->size < step))
+               return -EIO;
+
+       if (exfat_cluster_walk(sb, &clu, step, chain->flags))
+               return -EIO;
+
+       chain->size -= step;
+
+       if (chain->size == 0 && chain->flags == ALLOC_NO_FAT_CHAIN)
+               chain->dir = EXFAT_EOF_CLUSTER;
+       else
+               chain->dir = clu;
+
+       return 0;
+}
+
 /* inode.c */
 extern const struct inode_operations exfat_file_inode_operations;
 void exfat_sync_inode(struct inode *inode);