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.

Signed-off-by: Hongzhen Luo <[email protected]>
---
 lib/blobchunk.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/blobchunk.c b/lib/blobchunk.c
index 33dadd5..a0f3d0e 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,9 +189,11 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode 
*inode,
                        memcpy(inode->chunkindexes + dst, &idx, sizeof(idx));
        }
        off = roundup(off, unit);
-       if (extent_start != EROFS_NULL_ADDR)
+       if (extent_start != EROFS_NULL_ADDR) {
+               extent_end = min(extent_end, extent_start + remaining_blks);
                tarerofs_blocklist_write(extent_start, extent_end - 
extent_start,
                                         source_offset);
+       }
        erofs_droid_blocklist_write_extent(inode, extent_start,
                        extent_start == EROFS_NULL_ADDR ?
                                        0 : extent_end - extent_start,
-- 
2.43.5

Reply via email to