]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
exfat: add data_start_bytes and exfat_cluster_to_phys_bytes() helper
authorNamjae Jeon <linkinjeon@kernel.org>
Wed, 6 May 2026 01:52:27 +0000 (10:52 +0900)
committerNamjae Jeon <linkinjeon@kernel.org>
Mon, 15 Jun 2026 10:55:47 +0000 (19:55 +0900)
This caches the data area start offset in bytes (data_start_bytes)
and introduces a helper function exfat_cluster_to_phys_bytes() to compute
the physical byte position of a given cluster.

Acked-by: Christoph Hellwig <hch@lst.de>
Acked-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
fs/exfat/exfat_fs.h
fs/exfat/super.c

index e47fbfa1d8547952a84d0307781c1c6e807390ea..e60b955da0d0f8fd1b08143688a12a901c1d1e57 100644 (file)
@@ -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_bytes(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.
  */
index cb2f8eefff995714574a30363e6f797840b26bf5..388db271c6bf53f94ed34dba6853c993c395bf72 100644 (file)
@@ -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) +