From: Gao Xiang Date: Thu, 6 Feb 2025 12:50:33 +0000 (+0800) Subject: erofs-utils: lib: refine z_erofs_get_extent_compressedlen() X-Git-Tag: accepted/tizen/unified/20250610.081809~47 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=53e9c577bbf4c2af6d782ca1dbeaae19ce91d6b5;p=platform%2Fupstream%2Ferofs-utils.git erofs-utils: lib: refine z_erofs_get_extent_compressedlen() Source kernel commit: 8f9530aeeb4f756bdfa70510b40e5d28ea3c742e Signed-off-by: Gao Xiang Link: https://lore.kernel.org/r/20250206125034.1462966-8-hsiangkao@linux.alibaba.com --- diff --git a/lib/zmap.c b/lib/zmap.c index f116c17..e61efe3 100644 --- a/lib/zmap.c +++ b/lib/zmap.c @@ -319,26 +319,20 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m, { struct erofs_inode *const vi = m->inode; struct erofs_sb_info *sbi = vi->sbi; - struct erofs_map_blocks *const map = m->map; - const unsigned int lclusterbits = vi->z_logical_clusterbits; - unsigned long lcn; + bool bigpcl1 = vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1; + bool bigpcl2 = vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_2; + unsigned long lcn = m->lcn + 1; int err; - DBG_BUGON(m->type != Z_EROFS_LCLUSTER_TYPE_PLAIN && - m->type != Z_EROFS_LCLUSTER_TYPE_HEAD1 && - m->type != Z_EROFS_LCLUSTER_TYPE_HEAD2); + DBG_BUGON(m->type == Z_EROFS_LCLUSTER_TYPE_NONHEAD); DBG_BUGON(m->type != m->headtype); - if (m->headtype == Z_EROFS_LCLUSTER_TYPE_PLAIN || - ((m->headtype == Z_EROFS_LCLUSTER_TYPE_HEAD1) && - !(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1)) || - ((m->headtype == Z_EROFS_LCLUSTER_TYPE_HEAD2) && - !(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_2))) { - map->m_plen = 1 << lclusterbits; - return 0; - } + if ((m->headtype == Z_EROFS_LCLUSTER_TYPE_HEAD1 && !bigpcl1) || + ((m->headtype == Z_EROFS_LCLUSTER_TYPE_PLAIN || + m->headtype == Z_EROFS_LCLUSTER_TYPE_HEAD2) && !bigpcl2) || + (lcn << vi->z_logical_clusterbits) >= vi->i_size) + m->compressedblks = 1; - lcn = m->lcn + 1; if (m->compressedblks) goto out; @@ -363,9 +357,9 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m, case Z_EROFS_LCLUSTER_TYPE_HEAD2: /* * if the 1st NONHEAD lcluster is actually PLAIN or HEAD type - * rather than CBLKCNT, it's a 1 lcluster-sized pcluster. + * rather than CBLKCNT, it's a 1 block-sized pcluster. */ - m->compressedblks = 1 << (lclusterbits - sbi->blkszbits); + m->compressedblks = 1; break; case Z_EROFS_LCLUSTER_TYPE_NONHEAD: if (m->delta[0] != 1) @@ -380,7 +374,7 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m, return -EFSCORRUPTED; } out: - map->m_plen = m->compressedblks << sbi->blkszbits; + m->map->m_plen = erofs_pos(sbi, m->compressedblks); return 0; err_bonus_cblkcnt: erofs_err("bogus CBLKCNT @ lcn %lu of nid %llu",