Skip to content

Commit 0852b6c

Browse files
committed
erofs: fix 1 lcluster-sized pcluster for big pcluster
If the 1st NONHEAD lcluster of a pcluster isn't CBLKCNT lcluster type rather than a HEAD or PLAIN type instead, which means its pclustersize _must_ be 1 lcluster (since its uncompressed size < 2 lclusters), as illustrated below: HEAD HEAD / PLAIN lcluster type ____________ ____________ |_:__________|_________:__| file data (uncompressed) . . .____________. |____________| pcluster data (compressed) Such on-disk case was explained before [1] but missed to be handled properly in the runtime implementation. It can be observed if manually generating 1 lcluster-sized pcluster with 2 lclusters (thus CBLKCNT doesn't exist.) Let's fix it now. [1] https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected] Fixes: cec6e93 ("erofs: support parsing big pcluster compress indexes") Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Gao Xiang <[email protected]>
1 parent 46f2e04 commit 0852b6c

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

fs/erofs/zmap.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,14 +450,31 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
450450
lcn = m->lcn + 1;
451451
if (m->compressedlcs)
452452
goto out;
453-
if (lcn == initial_lcn)
454-
goto err_bonus_cblkcnt;
455453

456454
err = z_erofs_load_cluster_from_disk(m, lcn);
457455
if (err)
458456
return err;
459457

458+
/*
459+
* If the 1st NONHEAD lcluster has already been handled initially w/o
460+
* valid compressedlcs, which means at least it mustn't be CBLKCNT, or
461+
* an internal implemenatation error is detected.
462+
*
463+
* The following code can also handle it properly anyway, but let's
464+
* BUG_ON in the debugging mode only for developers to notice that.
465+
*/
466+
DBG_BUGON(lcn == initial_lcn &&
467+
m->type == Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD);
468+
460469
switch (m->type) {
470+
case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN:
471+
case Z_EROFS_VLE_CLUSTER_TYPE_HEAD:
472+
/*
473+
* if the 1st NONHEAD lcluster is actually PLAIN or HEAD type
474+
* rather than CBLKCNT, it's a 1 lcluster-sized pcluster.
475+
*/
476+
m->compressedlcs = 1;
477+
break;
461478
case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD:
462479
if (m->delta[0] != 1)
463480
goto err_bonus_cblkcnt;

0 commit comments

Comments
 (0)