erofs-utils: lib: refine z_erofs_get_extent_compressedlen()
authorGao Xiang <hsiangkao@linux.alibaba.com>
Thu, 6 Feb 2025 12:50:33 +0000 (20:50 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Sun, 9 Feb 2025 05:37:59 +0000 (13:37 +0800)
Source kernel commit: 8f9530aeeb4f756bdfa70510b40e5d28ea3c742e

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20250206125034.1462966-8-hsiangkao@linux.alibaba.com
lib/zmap.c

index f116c17d558af51adb3bdb65919c319903bd83ae..e61efe32c8fedf563ea5e21de6411556995af861 100644 (file)
@@ -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",