From: Yongpeng Yang <[email protected]> The raw __le32 pointer arithmetic in f2fs_truncate_data_blocks_range() directly accesses block addresses via get_dnode_addr() and pointer increment. This pattern is not friendly for inline extent access where the inode data layout may differ from direct block format.
Replace the raw pointer access with f2fs_data_blkaddr() which provides a proper abstraction layer. This prepares for inline extent support where the data block address retrieval needs to go through a different path. Signed-off-by: Yongpeng Yang <[email protected]> --- fs/f2fs/file.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 633e9ade654f..e40e136f9d43 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -659,7 +659,6 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count) { struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); int nr_free = 0, ofs = dn->ofs_in_node, len = count; - __le32 *addr; bool compressed_cluster = false; int cluster_index = 0, valid_blocks = 0; int cluster_size = F2FS_I(dn->inode)->i_cluster_size; @@ -667,12 +666,11 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count) block_t blkstart; int blklen = 0; - addr = get_dnode_addr(dn->inode, dn->node_folio) + ofs; - blkstart = le32_to_cpu(*addr); + blkstart = f2fs_data_blkaddr(dn); /* Assumption: truncation starts with cluster */ - for (; count > 0; count--, addr++, dn->ofs_in_node++, cluster_index++) { - block_t blkaddr = le32_to_cpu(*addr); + for (; count > 0; count--, dn->ofs_in_node++, cluster_index++) { + block_t blkaddr = f2fs_data_blkaddr(dn); if (f2fs_compressed_file(dn->inode) && !(cluster_index & (cluster_size - 1))) { @@ -715,7 +713,10 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count) if (blklen) f2fs_invalidate_blocks(sbi, blkstart, blklen); - blkstart = le32_to_cpu(*(addr + 1)); + /* data_blkaddr may exceed the boundary of blocks. */ + if (count > 1) + blkstart = data_blkaddr(dn->inode, + dn->node_folio, dn->ofs_in_node + 1); blklen = 0; } -- 2.43.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
