From: Baokun Li Date: Fri, 21 Nov 2025 09:06:40 +0000 (+0800) Subject: ext4: add EXT4_LBLK_TO_PG and EXT4_PG_TO_LBLK for block/page conversion X-Git-Tag: v6.19-rc1~161^2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a8de76b2b0f84333a2778db04ce51811c260d9d;p=thirdparty%2Fkernel%2Flinux.git ext4: add EXT4_LBLK_TO_PG and EXT4_PG_TO_LBLK for block/page conversion As BS > PS support is coming, all block number to page index (and vice-versa) conversions must now go via bytes. Added EXT4_LBLK_TO_PG() and EXT4_PG_TO_LBLK() macros to simplify these conversions and handle both BS <= PS and BS > PS scenarios cleanly. Suggested-by: Jan Kara Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Message-ID: <20251121090654.631996-11-libaokun@huaweicloud.com> Signed-off-by: Theodore Ts'o --- diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 4581ff8aef195..5ade4e22dcfff 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -370,6 +370,12 @@ struct ext4_io_submit { (round_up((offset), i_blocksize(inode)) >> (inode)->i_blkbits) #define EXT4_LBLK_TO_B(inode, lblk) ((loff_t)(lblk) << (inode)->i_blkbits) +/* Translate a block number to a page index */ +#define EXT4_LBLK_TO_PG(inode, lblk) (EXT4_LBLK_TO_B((inode), (lblk)) >> \ + PAGE_SHIFT) +/* Translate a page index to a block number */ +#define EXT4_PG_TO_LBLK(inode, pnum) (((loff_t)(pnum) << PAGE_SHIFT) >> \ + (inode)->i_blkbits) /* Translate a block number to a cluster number */ #define EXT4_B2C(sbi, blk) ((blk) >> (sbi)->s_cluster_bits) /* Translate a cluster number to a block number */