[PATCH] erofs-utils: lib: fix the incorrect nblocks number under chunk mode
Hongzhen Luo
hongzhen at linux.alibaba.com
Wed Sep 11 18:10:20 AEST 2024
Currently, in chunk mode, the number of blocks (nblocks) for the last
chunk written to the blocklist file is the size of the chunk, which may
not be consistent with the size of the original file in the last chunk.
This patch writes the actual number of blocks of the file in the last
chunk to the blocklist file.
Signed-off-by: Hongzhen Luo <hongzhen at linux.alibaba.com>
---
lib/blobchunk.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/lib/blobchunk.c b/lib/blobchunk.c
index 33dadd5..40b731b 100644
--- a/lib/blobchunk.c
+++ b/lib/blobchunk.c
@@ -135,6 +135,7 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,
{
struct erofs_inode_chunk_index idx = {0};
erofs_blk_t extent_start = EROFS_NULL_ADDR;
+ erofs_blk_t front_blks = 0, tail_blks;
erofs_blk_t extent_end, chunkblks;
erofs_off_t source_offset;
unsigned int dst, src, unit;
@@ -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) {
+ front_blks += extent_end - extent_start;
tarerofs_blocklist_write(extent_start,
extent_end - extent_start,
source_offset);
@@ -187,9 +189,12 @@ 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)
- tarerofs_blocklist_write(extent_start, extent_end - extent_start,
+ if (extent_start != EROFS_NULL_ADDR) {
+ tail_blks = BLK_ROUND_UP(inode->sbi, inode->i_size)
+ - front_blks;
+ tarerofs_blocklist_write(extent_start, tail_blks,
source_offset);
+ }
erofs_droid_blocklist_write_extent(inode, extent_start,
extent_start == EROFS_NULL_ADDR ?
0 : extent_end - extent_start,
--
2.43.5
More information about the Linux-erofs
mailing list