Skip to content

Commit 1ca0152

Browse files
committed
erofs: refine z_erofs_transform_plain() for sub-page block support
Sub-page block support is still unusable even with previous commits if interlaced PLAIN pclusters exist. Such pclusters can be found if the fragment feature is enabled. This commit tries to handle "the head part" of interlaced PLAIN pclusters first: it was once explained in commit fdffc09 ("erofs: support interlaced uncompressed data for compressed files"). It uses a unique way for both shifted and interlaced PLAIN pclusters. As an added bonus, PLAIN pclusters larger than the block size is also supported now for the upcoming large lclusters. Reviewed-by: Yue Hu <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Gao Xiang <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e5aba91 commit 1ca0152

File tree

1 file changed

+48
-33
lines changed

1 file changed

+48
-33
lines changed

fs/erofs/decompressor.c

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -320,43 +320,58 @@ static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq,
320320
static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
321321
struct page **pagepool)
322322
{
323-
const unsigned int inpages = PAGE_ALIGN(rq->inputsize) >> PAGE_SHIFT;
324-
const unsigned int outpages =
323+
const unsigned int nrpages_in =
324+
PAGE_ALIGN(rq->pageofs_in + rq->inputsize) >> PAGE_SHIFT;
325+
const unsigned int nrpages_out =
325326
PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT;
326-
const unsigned int righthalf = min_t(unsigned int, rq->outputsize,
327-
PAGE_SIZE - rq->pageofs_out);
328-
const unsigned int lefthalf = rq->outputsize - righthalf;
329-
const unsigned int interlaced_offset =
330-
rq->alg == Z_EROFS_COMPRESSION_SHIFTED ? 0 : rq->pageofs_out;
331-
u8 *src;
332-
333-
if (outpages > 2 && rq->alg == Z_EROFS_COMPRESSION_SHIFTED) {
334-
DBG_BUGON(1);
335-
return -EFSCORRUPTED;
336-
}
337-
338-
if (rq->out[0] == *rq->in) {
339-
DBG_BUGON(rq->pageofs_out);
340-
return 0;
327+
const unsigned int bs = rq->sb->s_blocksize;
328+
unsigned int cur = 0, ni = 0, no, pi, po, insz, cnt;
329+
u8 *kin;
330+
331+
DBG_BUGON(rq->outputsize > rq->inputsize);
332+
if (rq->alg == Z_EROFS_COMPRESSION_INTERLACED) {
333+
cur = bs - (rq->pageofs_out & (bs - 1));
334+
pi = (rq->pageofs_in + rq->inputsize - cur) & ~PAGE_MASK;
335+
cur = min(cur, rq->outputsize);
336+
if (cur && rq->out[0]) {
337+
kin = kmap_local_page(rq->in[nrpages_in - 1]);
338+
if (rq->out[0] == rq->in[nrpages_in - 1]) {
339+
memmove(kin + rq->pageofs_out, kin + pi, cur);
340+
flush_dcache_page(rq->out[0]);
341+
} else {
342+
memcpy_to_page(rq->out[0], rq->pageofs_out,
343+
kin + pi, cur);
344+
}
345+
kunmap_local(kin);
346+
}
347+
rq->outputsize -= cur;
341348
}
342349

343-
src = kmap_local_page(rq->in[inpages - 1]) + rq->pageofs_in;
344-
if (rq->out[0])
345-
memcpy_to_page(rq->out[0], rq->pageofs_out,
346-
src + interlaced_offset, righthalf);
347-
348-
if (outpages > inpages) {
349-
DBG_BUGON(!rq->out[outpages - 1]);
350-
if (rq->out[outpages - 1] != rq->in[inpages - 1]) {
351-
memcpy_to_page(rq->out[outpages - 1], 0, src +
352-
(interlaced_offset ? 0 : righthalf),
353-
lefthalf);
354-
} else if (!interlaced_offset) {
355-
memmove(src, src + righthalf, lefthalf);
356-
flush_dcache_page(rq->in[inpages - 1]);
357-
}
350+
for (; rq->outputsize; rq->pageofs_in = 0, cur += PAGE_SIZE, ni++) {
351+
insz = min(PAGE_SIZE - rq->pageofs_in, rq->outputsize);
352+
rq->outputsize -= insz;
353+
if (!rq->in[ni])
354+
continue;
355+
kin = kmap_local_page(rq->in[ni]);
356+
pi = 0;
357+
do {
358+
no = (rq->pageofs_out + cur + pi) >> PAGE_SHIFT;
359+
po = (rq->pageofs_out + cur + pi) & ~PAGE_MASK;
360+
DBG_BUGON(no >= nrpages_out);
361+
cnt = min(insz - pi, PAGE_SIZE - po);
362+
if (rq->out[no] == rq->in[ni]) {
363+
memmove(kin + po,
364+
kin + rq->pageofs_in + pi, cnt);
365+
flush_dcache_page(rq->out[no]);
366+
} else if (rq->out[no]) {
367+
memcpy_to_page(rq->out[no], po,
368+
kin + rq->pageofs_in + pi, cnt);
369+
}
370+
pi += cnt;
371+
} while (pi < insz);
372+
kunmap_local(kin);
358373
}
359-
kunmap_local(src);
374+
DBG_BUGON(ni > nrpages_in);
360375
return 0;
361376
}
362377

0 commit comments

Comments
 (0)