Linux-EROFS Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Yifan Zhao <stopire@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: xiang@kernel.org, Yifan Zhao <stopire@gmail.com>
Subject: [PATCH] erofs-utils: lib: fix chunk index reads from metabox
Date: Sat,  5 Sep 2026 20:09:00 +0800	[thread overview]
Message-ID: <20260905120900.943511-1-stopire@gmail.com> (raw)

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



                 reply	other threads:[~2026-09-05 12:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260905120900.943511-1-stopire@gmail.com \
    --to=stopire@gmail.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=xiang@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox