[PATCH] erofs: support uncompressed pcluster with more than 1 block
Yue Hu
zbestahu at gmail.com
Fri Sep 2 16:31:34 AEST 2022
From: Yue Hu <huyue2 at coolpad.com>
The length of uncompressed pcluster may exceed one block in some new
scenarios such as non 4K-sized lcluster (which will be supported later).
So, let's support the decompression for this firstly.
Signed-off-by: Yue Hu <huyue2 at coolpad.com>
---
fs/erofs/decompressor.c | 56 +++++++++++++++++++++++++----------------
1 file changed, 35 insertions(+), 21 deletions(-)
diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
index 2d55569f96ac..fe6abb79e560 100644
--- a/fs/erofs/decompressor.c
+++ b/fs/erofs/decompressor.c
@@ -320,41 +320,55 @@ static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq,
static int z_erofs_shifted_transform(struct z_erofs_decompress_req *rq,
struct page **pagepool)
{
+ const unsigned int nrpages_in = rq->inputsize >> PAGE_SHIFT;
const unsigned int nrpages_out =
PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT;
const unsigned int righthalf = min_t(unsigned int, rq->outputsize,
PAGE_SIZE - rq->pageofs_out);
- const unsigned int lefthalf = rq->outputsize - righthalf;
+ const unsigned int lefthalf = min_t(unsigned int,
+ rq->outputsize - righthalf,
+ PAGE_SIZE - righthalf);
unsigned char *src, *dst;
+ unsigned int i;
- if (nrpages_out > 2) {
+ if (nrpages_in == 1 && nrpages_out > 2) {
DBG_BUGON(1);
return -EIO;
}
- if (rq->out[0] == *rq->in) {
- DBG_BUGON(nrpages_out != 1);
- return 0;
- }
+ i = 0;
+ do {
+ src = kmap_atomic(rq->in[i]) + rq->pageofs_in;
+
+ if (rq->out[i]) {
+ if (rq->out[i] == rq->in[i]) {
+ DBG_BUGON(nrpages_in == 1 && nrpages_out != 1);
+ } else {
+ dst = kmap_atomic(rq->out[i]);
+ memcpy(dst + rq->pageofs_out, src, righthalf);
+ kunmap_atomic(dst);
+ }
+ }
- src = kmap_atomic(*rq->in) + rq->pageofs_in;
- if (rq->out[0]) {
- dst = kmap_atomic(rq->out[0]);
- memcpy(dst + rq->pageofs_out, src, righthalf);
- kunmap_atomic(dst);
- }
+ if (i + 1 == nrpages_out) {
+ kunmap_atomic(src);
+ break;
+ }
- if (nrpages_out == 2) {
- DBG_BUGON(!rq->out[1]);
- if (rq->out[1] == *rq->in) {
- memmove(src, src + righthalf, lefthalf);
+ if (rq->out[i + 1]) {
+ if (rq->out[i + 1] == rq->in[i]) {
+ memmove(src, src + righthalf, lefthalf);
+ } else {
+ dst = kmap_atomic(rq->out[i + 1]);
+ memcpy(dst, src + righthalf, lefthalf);
+ kunmap_atomic(dst);
+ }
} else {
- dst = kmap_atomic(rq->out[1]);
- memcpy(dst, src + righthalf, lefthalf);
- kunmap_atomic(dst);
+ DBG_BUGON(nrpages_in == 1 && nrpages_out == 2);
}
- }
- kunmap_atomic(src);
+ kunmap_atomic(src);
+ } while (++i < nrpages_in);
+
return 0;
}
--
2.17.1
More information about the Linux-erofs
mailing list