Re: [PATCH v3 06/11] exfat: add data_start_bytes and exfat_cluster_to_phys() helper

From: CharSyam

Date: Wed May 13 2026 - 11:42:09 EST


Hi, Namjae.

The calculation looks correct to me. I just have a minor naming suggestion:
since this helper returns a byte offset, while exFAT already has
exfat_cluster_to_sector() for sector-based addresses, would it be clearer to
name this helper exfat_cluster_to_phys_bytes()?

Thanks
DaeMyung

2026년 5월 13일 (수) 오후 8:27, Namjae Jeon <linkinjeon@xxxxxxxxxx>님이 작성:
>
> This caches the data area start offset in bytes (data_start_bytes)
> and introduces a helper function exfat_cluster_to_phys() to compute
> the physical byte position of a given cluster.
>
> Signed-off-by: Namjae Jeon <linkinjeon@xxxxxxxxxx>
> ---
> fs/exfat/exfat_fs.h | 8 ++++++++
> fs/exfat/super.c | 1 +
> 2 files changed, 9 insertions(+)
>
> diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h
> index 6e7fd6822b01..415f987afa9a 100644
> --- a/fs/exfat/exfat_fs.h
> +++ b/fs/exfat/exfat_fs.h
> @@ -227,6 +227,7 @@ struct exfat_sb_info {
> unsigned long long FAT1_start_sector; /* FAT1 start sector */
> unsigned long long FAT2_start_sector; /* FAT2 start sector */
> unsigned long long data_start_sector; /* data area start sector */
> + unsigned long long data_start_bytes;
> unsigned int num_FAT_sectors; /* num of FAT sectors */
> unsigned int root_dir; /* root dir cluster */
> unsigned int dentries_per_clu; /* num of dentries per cluster */
> @@ -400,6 +401,13 @@ static inline loff_t exfat_ondisk_size(const struct inode *inode)
> return ((loff_t)inode->i_blocks) << 9;
> }
>
> +static inline loff_t exfat_cluster_to_phys(struct exfat_sb_info *sbi,
> + unsigned int clus)
> +{
> + return ((loff_t)(clus - EXFAT_RESERVED_CLUSTERS) << sbi->cluster_size_bits) +
> + sbi->data_start_bytes;
> +}
> +
> /*
> * helpers for cluster size to byte conversion.
> */
> diff --git a/fs/exfat/super.c b/fs/exfat/super.c
> index cb2f8eefff99..388db271c6bf 100644
> --- a/fs/exfat/super.c
> +++ b/fs/exfat/super.c
> @@ -499,6 +499,7 @@ static int exfat_read_boot_sector(struct super_block *sb)
> if (p_boot->num_fats == 2)
> sbi->FAT2_start_sector += sbi->num_FAT_sectors;
> sbi->data_start_sector = le32_to_cpu(p_boot->clu_offset);
> + sbi->data_start_bytes = sbi->data_start_sector << p_boot->sect_size_bits;
> sbi->num_sectors = le64_to_cpu(p_boot->vol_length);
> /* because the cluster index starts with 2 */
> sbi->num_clusters = le32_to_cpu(p_boot->clu_count) +
> --
> 2.25.1
>
>