From: Yue Hu <zbestahu@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: Yue Hu <huyue2@coolpad.com>, zhangwen@coolpad.com
Subject: [RFC PATCH] erofs-utils: fsck: support fragments
Date: Sat, 24 Dec 2022 17:43:19 +0800 [thread overview]
Message-ID: <20221224094319.10317-1-zbestahu@gmail.com> (raw)
From: Yue Hu <huyue2@coolpad.com>
Add compressed fragments support for fsck.erofs.
Signed-off-by: Yue Hu <huyue2@coolpad.com>
---
fsck/main.c | 41 +++++++++++++++++++++++++++++++++++++++--
lib/zmap.c | 1 +
2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/fsck/main.c b/fsck/main.c
index 2a9c501..9babc61 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -421,6 +421,31 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
if (!(map.m_flags & EROFS_MAP_MAPPED) || !fsckcfg.check_decomp)
continue;
+ if (map.m_flags & EROFS_MAP_FRAGMENT) {
+ struct erofs_inode packed_inode = {
+ .nid = sbi.packed_nid,
+ };
+
+ ret = erofs_read_inode_from_disk(&packed_inode);
+ if (ret) {
+ erofs_err("failed to read packed inode from disk");
+ goto out;
+ }
+
+ if (!buffer || map.m_llen > buffer_size) {
+ buffer_size = map.m_llen;
+ buffer = realloc(buffer, map.m_llen);
+ BUG_ON(!buffer);
+ }
+ ret = erofs_pread(&packed_inode, buffer, map.m_llen,
+ inode->fragmentoff);
+ if (ret)
+ goto out;
+
+ compressed = true; /* force using buffer */
+ goto write_outfd;
+ }
+
if (map.m_plen > raw_size) {
raw_size = map.m_plen;
raw = realloc(raw, raw_size);
@@ -476,6 +501,7 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
}
}
+write_outfd:
if (outfd >= 0 && write(outfd, compressed ? buffer : raw,
map.m_llen) < 0) {
erofs_err("I/O error occurred when verifying data chunk @ nid %llu",
@@ -486,8 +512,9 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
}
if (fsckcfg.print_comp_ratio) {
- fsckcfg.logical_blocks += BLK_ROUND_UP(inode->i_size);
fsckcfg.physical_blocks += BLK_ROUND_UP(pchunk_len);
+ if (!erofs_is_packed_inode(inode))
+ fsckcfg.logical_blocks += BLK_ROUND_UP(inode->i_size);
}
out:
if (raw)
@@ -732,6 +759,8 @@ static int erofsfsck_check_inode(erofs_nid_t pnid, erofs_nid_t nid)
ret = erofs_extract_dir(&inode);
break;
case S_IFREG:
+ if (erofs_is_packed_inode(&inode))
+ goto verify;
ret = erofs_extract_file(&inode);
break;
case S_IFLNK:
@@ -767,7 +796,7 @@ verify:
ret = erofs_iterate_dir(&ctx, true);
}
- if (!ret)
+ if (!ret && !erofs_is_packed_inode(&inode))
erofsfsck_set_attributes(&inode, fsckcfg.extract_path);
if (ret == -ECANCELED)
@@ -822,6 +851,14 @@ int main(int argc, char **argv)
goto exit_put_super;
}
+ if (erofs_sb_has_fragments()) {
+ err = erofsfsck_check_inode(sbi.packed_nid, sbi.packed_nid);
+ if (err) {
+ erofs_err("failed to verify packed file");
+ goto exit_put_super;
+ }
+ }
+
err = erofsfsck_check_inode(sbi.root_nid, sbi.root_nid);
if (fsckcfg.corrupted) {
if (!fsckcfg.extract_path)
diff --git a/lib/zmap.c b/lib/zmap.c
index 41e0713..ca65038 100644
--- a/lib/zmap.c
+++ b/lib/zmap.c
@@ -639,6 +639,7 @@ static int z_erofs_do_map_blocks(struct erofs_inode *vi,
map->m_plen = vi->z_idata_size;
} else if (fragment && m.lcn == vi->z_tailextent_headlcn) {
map->m_flags |= EROFS_MAP_FRAGMENT;
+ map->m_plen = 0;
} else {
map->m_pa = blknr_to_addr(m.pblk);
err = z_erofs_get_extent_compressedlen(&m, initial_lcn);
--
2.17.1
next reply other threads:[~2022-12-24 9:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-24 9:43 Yue Hu [this message]
2023-01-04 2:48 ` [RFC PATCH] erofs-utils: fsck: support fragments Xiang Gao
2023-01-04 3:24 ` Yue Hu
2023-01-04 3:32 ` Xiang Gao
2023-01-04 7:26 ` Yue Hu
2023-01-04 7:28 ` Xiang Gao
2023-01-04 7:42 ` 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=20221224094319.10317-1-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