* [PATCH] erofs-utils: lib: fix chunk index reads from metabox
@ 2026-09-05 12:09 Yifan Zhao
0 siblings, 0 replies; only message in thread
From: Yifan Zhao @ 2026-09-05 12:09 UTC (permalink / raw)
To: linux-erofs; +Cc: xiang, Yifan Zhao
Chunk indexes stored in metabox are incorrectly read from the primary
device, resulting in incorrect file contents.
Assisted-by: Codex:gpt-6-astra
Signed-off-by: Yifan Zhao <stopire@gmail.com>
---
lib/data.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/lib/data.c b/lib/data.c
index 5a17af5..fa2907b 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -72,7 +72,7 @@ int __erofs_map_blocks(struct erofs_inode *inode,
struct erofs_sb_info *sbi = inode->sbi;
unsigned int unit, blksz = 1 << sbi->blkszbits;
struct erofs_inode_chunk_index *idx;
- u8 buf[EROFS_MAX_BLOCK_SIZE];
+ struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
erofs_blk_t startblk, addrmask, nblocks;
bool tailpacking;
erofs_off_t pos;
@@ -115,11 +115,10 @@ int __erofs_map_blocks(struct erofs_inode *inode,
pos = roundup(erofs_iloc(vi) + vi->inode_isize +
vi->xattr_isize, unit) + unit * chunknr;
- err = erofs_blk_read(sbi, 0, buf, erofs_blknr(sbi, pos), 1);
- if (err < 0)
- return -EIO;
-
- idx = (void *)buf + erofs_blkoff(sbi, pos);
+ idx = erofs_read_metabuf(&buf, sbi, pos,
+ erofs_inode_in_metabox(vi));
+ if (IS_ERR(idx))
+ return PTR_ERR(idx);
map->m_la = chunknr << vi->u.chunkbits;
map->m_llen = min_t(erofs_off_t, 1ULL << vi->u.chunkbits,
round_up(inode->i_size - map->m_la, blksz));
@@ -141,6 +140,7 @@ int __erofs_map_blocks(struct erofs_inode *inode,
map->m_flags = EROFS_MAP_MAPPED;
}
}
+ erofs_put_metabuf(&buf);
out:
if (!err) {
map->m_plen = map->m_llen;
--
2.55.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-09-05 12:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-05 12:09 [PATCH] erofs-utils: lib: fix chunk index reads from metabox Yifan Zhao
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.