Messages in this thread Patch in this message | | | From | Yue Hu <> | Subject | [RFC PATCH v2] erofs: support uncompressed pcluster with more than 1 block | Date | Fri, 2 Sep 2022 21:50:36 +0800 |
| |
From: Yue Hu <huyue2@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@coolpad.com> --- v2: fix tail data length.
fs/erofs/decompressor.c | 64 ++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 23 deletions(-)
diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index 2d55569f96ac..77d2b6cb6eda 100644 --- a/fs/erofs/decompressor.c +++ b/fs/erofs/decompressor.c @@ -320,41 +320,59 @@ 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; + unsigned int righthalf, lefthalf, i; unsigned char *src, *dst; - 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 { + unsigned int outputsize = rq->outputsize; + + righthalf = min_t(unsigned int, outputsize, + PAGE_SIZE - rq->pageofs_out); + lefthalf = min_t(unsigned int, outputsize - righthalf, + PAGE_SIZE - righthalf); + + 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); + + if (outputsize > PAGE_SIZE) + outputsize -= PAGE_SIZE; + } while (++i < nrpages_in); + return 0; } -- 2.17.1
| |