Linux-EROFS Archive mirror
 help / color / mirror / Atom feed
From: Yifan Zhao <zhaoyifan@sjtu.edu.cn>
To: linux-erofs@lists.ozlabs.org
Cc: Yifan Zhao <zhaoyifan@sjtu.edu.cn>
Subject: [PATCH] erofs-utils: fsck: extract chunk-based file with hole correctly
Date: Mon, 22 Apr 2024 18:05:21 +0800	[thread overview]
Message-ID: <20240422100521.206071-1-zhaoyifan@sjtu.edu.cn> (raw)

Currently fsck skips file extraction if it finds that EROFS_MAP_MAPPED
is unset, which is not the case for chunk-based files with hole. This
patch handles the corner case correctly.

Signed-off-by: Yifan Zhao <zhaoyifan@sjtu.edu.cn>
---
 fsck/main.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fsck/main.c b/fsck/main.c
index e5c37be..c10b68e 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -470,7 +470,7 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
 		pos += map.m_llen;
 
 		/* should skip decomp? */
-		if (!(map.m_flags & EROFS_MAP_MAPPED) || !fsckcfg.check_decomp)
+		if (map.m_la >= inode->i_size || !fsckcfg.check_decomp)
 			continue;
 
 		if (map.m_plen > Z_EROFS_PCLUSTER_MAX_SIZE) {
@@ -517,9 +517,14 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
 				u64 count = min_t(u64, alloc_rawsize,
 						  map.m_llen);
 
-				ret = erofs_read_one_data(inode, &map, raw, p, count);
-				if (ret)
-					goto out;
+				if (!(map.m_flags & EROFS_MAP_MAPPED)) {
+					memset(raw, 0, count);
+				} else {
+					ret = erofs_read_one_data(
+						inode, &map, raw, p, count);
+					if (ret)
+						goto out;
+				}
 
 				if (outfd >= 0 && write(outfd, raw, count) < 0)
 					goto fail_eio;
-- 
2.44.0


             reply	other threads:[~2024-04-22 10:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-22 10:05 Yifan Zhao [this message]
2024-04-22 10:28 ` [PATCH] erofs-utils: fsck: extract chunk-based file with hole correctly Gao Xiang
2024-04-22 11:31 ` [PATCH v2] " Yifan Zhao
2024-04-24  6:02   ` Gao Xiang

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=20240422100521.206071-1-zhaoyifan@sjtu.edu.cn \
    --to=zhaoyifan@sjtu.edu.cn \
    --cc=linux-erofs@lists.ozlabs.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).