Skip to content

Commit 2a8de76

Browse files
LiBaokun96tytso
authored andcommitted
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 <jack@suse.cz> Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Zhang Yi <yi.zhang@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> Message-ID: <20251121090654.631996-11-libaokun@huaweicloud.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 125d1f6 commit 2a8de76

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

fs/ext4/ext4.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,12 @@ struct ext4_io_submit {
370370
(round_up((offset), i_blocksize(inode)) >> (inode)->i_blkbits)
371371
#define EXT4_LBLK_TO_B(inode, lblk) ((loff_t)(lblk) << (inode)->i_blkbits)
372372

373+
/* Translate a block number to a page index */
374+
#define EXT4_LBLK_TO_PG(inode, lblk) (EXT4_LBLK_TO_B((inode), (lblk)) >> \
375+
PAGE_SHIFT)
376+
/* Translate a page index to a block number */
377+
#define EXT4_PG_TO_LBLK(inode, pnum) (((loff_t)(pnum) << PAGE_SHIFT) >> \
378+
(inode)->i_blkbits)
373379
/* Translate a block number to a cluster number */
374380
#define EXT4_B2C(sbi, blk) ((blk) >> (sbi)->s_cluster_bits)
375381
/* Translate a cluster number to a block number */

0 commit comments

Comments
 (0)