From 53756872a48490157f9d3827b1f8bbf1bfa35993 Mon Sep 17 00:00:00 2001 From: Hongzhen Luo Date: Wed, 11 Sep 2024 16:55:31 +0800 Subject: [PATCH] erofs-utils: lib: fix incorrect nblocks in block list for chunked inodes Currently, the number of physical blocks (nblocks) for the last chunk written to the block list file is incorrectly recorded as the inode chunksize. This patch writes the actual number of physical blocks for the inode in the last chunk to the block list file. Fixes: 7b46f7a0160a ("erofs-utils: lib: merge consecutive chunks if possible") Fixes: b6749839e710 ("erofs-utils: generate preallocated extents for tarerofs") Signed-off-by: Hongzhen Luo Link: https://lore.kernel.org/r/20240911085531.2133723-1-hongzhen@linux.alibaba.com Signed-off-by: Gao Xiang --- lib/blobchunk.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/blobchunk.c b/lib/blobchunk.c index 33dadd5..6c2ea0e 100644 --- a/lib/blobchunk.c +++ b/lib/blobchunk.c @@ -133,6 +133,7 @@ static int erofs_blob_hashmap_cmp(const void *a, const void *b, int erofs_blob_write_chunk_indexes(struct erofs_inode *inode, erofs_off_t off) { + erofs_blk_t remaining_blks = BLK_ROUND_UP(inode->sbi, inode->i_size); struct erofs_inode_chunk_index idx = {0}; erofs_blk_t extent_start = EROFS_NULL_ADDR; erofs_blk_t extent_end, chunkblks; @@ -165,6 +166,7 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode, if (extent_start == EROFS_NULL_ADDR || idx.blkaddr != extent_end) { if (extent_start != EROFS_NULL_ADDR) { + remaining_blks -= extent_end - extent_start; tarerofs_blocklist_write(extent_start, extent_end - extent_start, source_offset); @@ -187,6 +189,7 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode, memcpy(inode->chunkindexes + dst, &idx, sizeof(idx)); } off = roundup(off, unit); + extent_end = min(extent_end, extent_start + remaining_blks); if (extent_start != EROFS_NULL_ADDR) tarerofs_blocklist_write(extent_start, extent_end - extent_start, source_offset); -- 2.34.1