From: Yue Hu <zbestahu@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: Yue Hu <huyue2@coolpad.com>, zhangwen@coolpad.com
Subject: [PATCH v2 2/3] erofs-utils: fsck: cleanup erofs_verify_inode_data()
Date: Tue, 10 Jan 2023 16:49:59 +0800 [thread overview]
Message-ID: <20230110084959.1955-2-zbestahu@gmail.com> (raw)
In-Reply-To: <20230110084959.1955-1-zbestahu@gmail.com>
From: Yue Hu <huyue2@coolpad.com>
Diretly call {z_}erofs_read_{raw_}data_mapped() to avoid duplicated
code. Accordingly, fragment and partial-referenced plusters are also
supported after this change.
Signed-off-by: Yue Hu <huyue2@coolpad.com>
---
v2: parameter '0' -> false and update commit message
fsck/main.c | 57 +++++++++++------------------------------------------
1 file changed, 11 insertions(+), 46 deletions(-)
diff --git a/fsck/main.c b/fsck/main.c
index 2a9c501..4dfab29 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -366,7 +366,6 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
struct erofs_map_blocks map = {
.index = UINT_MAX,
};
- struct erofs_map_dev mdev;
int ret = 0;
bool compressed;
erofs_off_t pos = 0;
@@ -427,54 +426,20 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
BUG_ON(!raw);
}
- mdev = (struct erofs_map_dev) {
- .m_deviceid = map.m_deviceid,
- .m_pa = map.m_pa,
- };
- ret = erofs_map_dev(&sbi, &mdev);
- if (ret) {
- erofs_err("failed to map device of m_pa %" PRIu64 ", m_deviceid %u @ nid %llu: %d",
- map.m_pa, map.m_deviceid, inode->nid | 0ULL,
- ret);
- goto out;
- }
-
- if (compressed && map.m_llen > buffer_size) {
- buffer_size = map.m_llen;
- buffer = realloc(buffer, buffer_size);
- BUG_ON(!buffer);
- }
-
- ret = dev_read(mdev.m_deviceid, raw, mdev.m_pa, map.m_plen);
- if (ret < 0) {
- erofs_err("failed to read data of m_pa %" PRIu64 ", m_plen %" PRIu64 " @ nid %llu: %d",
- mdev.m_pa, map.m_plen, inode->nid | 0ULL,
- ret);
- goto out;
- }
-
if (compressed) {
- struct z_erofs_decompress_req rq = {
- .in = raw,
- .out = buffer,
- .decodedskip = 0,
- .interlaced_offset =
- map.m_algorithmformat == Z_EROFS_COMPRESSION_INTERLACED ?
- erofs_blkoff(map.m_la) : 0,
- .inputsize = map.m_plen,
- .decodedlength = map.m_llen,
- .alg = map.m_algorithmformat,
- .partial_decoding = 0
- };
-
- ret = z_erofs_decompress(&rq);
- if (ret < 0) {
- erofs_err("failed to decompress data of m_pa %" PRIu64 ", m_plen %" PRIu64 " @ nid %llu: %s",
- mdev.m_pa, map.m_plen,
- inode->nid | 0ULL, strerror(-ret));
- goto out;
+ if (map.m_llen > buffer_size) {
+ buffer_size = map.m_llen;
+ buffer = realloc(buffer, buffer_size);
+ BUG_ON(!buffer);
}
+ ret = z_erofs_read_data_mapped(inode, &map, raw,
+ buffer, 0, map.m_llen, false);
+ } else {
+ ret = erofs_read_raw_data_mapped(&map, raw, 0,
+ map.m_plen);
}
+ if (ret)
+ goto out;
if (outfd >= 0 && write(outfd, compressed ? buffer : raw,
map.m_llen) < 0) {
--
2.17.1
next prev parent reply other threads:[~2023-01-10 8:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-10 8:49 [PATCH v2 1/3] erofs-utils: lib: export parts of erofs_pread() Yue Hu
2023-01-10 8:49 ` Yue Hu [this message]
2023-01-10 9:00 ` Xiang Gao
2023-01-10 9:09 ` Yue Hu
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=20230110084959.1955-2-zbestahu@gmail.com \
--to=zbestahu@gmail.com \
--cc=huyue2@coolpad.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=zhangwen@coolpad.com \
/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