Commit ea0b7b0d authored by Yue Hu's avatar Yue Hu Committed by Gao Xiang

erofs: avoid the potentially wrong m_plen for big pcluster

Actually, 'compressedlcs' stores compressed block count rather than
lcluster count. Therefore, the number of bits for shifting the count
should be 'LOG_BLOCK_SIZE' rather than 'lclusterbits' although current
lcluster size is 4K.

The value of 'm_plen' will be wrong once we enable the non 4K-sized
lcluster.
Signed-off-by: default avatarYue Hu <huyue2@coolpad.com>
Reviewed-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
Reviewed-by: default avatarChao Yu <chao@kernel.org>
Link: https://lore.kernel.org/r/20220812060150.8510-1-huyue2@coolpad.comSigned-off-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
parent 5bd9628b
...@@ -141,7 +141,7 @@ struct z_erofs_maprecorder { ...@@ -141,7 +141,7 @@ struct z_erofs_maprecorder {
u8 type, headtype; u8 type, headtype;
u16 clusterofs; u16 clusterofs;
u16 delta[2]; u16 delta[2];
erofs_blk_t pblk, compressedlcs; erofs_blk_t pblk, compressedblks;
erofs_off_t nextpackoff; erofs_off_t nextpackoff;
}; };
...@@ -192,7 +192,7 @@ static int legacy_load_cluster_from_disk(struct z_erofs_maprecorder *m, ...@@ -192,7 +192,7 @@ static int legacy_load_cluster_from_disk(struct z_erofs_maprecorder *m,
DBG_BUGON(1); DBG_BUGON(1);
return -EFSCORRUPTED; return -EFSCORRUPTED;
} }
m->compressedlcs = m->delta[0] & m->compressedblks = m->delta[0] &
~Z_EROFS_VLE_DI_D0_CBLKCNT; ~Z_EROFS_VLE_DI_D0_CBLKCNT;
m->delta[0] = 1; m->delta[0] = 1;
} }
...@@ -293,7 +293,7 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m, ...@@ -293,7 +293,7 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
DBG_BUGON(1); DBG_BUGON(1);
return -EFSCORRUPTED; return -EFSCORRUPTED;
} }
m->compressedlcs = lo & ~Z_EROFS_VLE_DI_D0_CBLKCNT; m->compressedblks = lo & ~Z_EROFS_VLE_DI_D0_CBLKCNT;
m->delta[0] = 1; m->delta[0] = 1;
return 0; return 0;
} else if (i + 1 != (int)vcnt) { } else if (i + 1 != (int)vcnt) {
...@@ -497,7 +497,7 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m, ...@@ -497,7 +497,7 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
return 0; return 0;
} }
lcn = m->lcn + 1; lcn = m->lcn + 1;
if (m->compressedlcs) if (m->compressedblks)
goto out; goto out;
err = z_erofs_load_cluster_from_disk(m, lcn, false); err = z_erofs_load_cluster_from_disk(m, lcn, false);
...@@ -506,7 +506,7 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m, ...@@ -506,7 +506,7 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
/* /*
* If the 1st NONHEAD lcluster has already been handled initially w/o * If the 1st NONHEAD lcluster has already been handled initially w/o
* valid compressedlcs, which means at least it mustn't be CBLKCNT, or * valid compressedblks, which means at least it mustn't be CBLKCNT, or
* an internal implemenatation error is detected. * an internal implemenatation error is detected.
* *
* The following code can also handle it properly anyway, but let's * The following code can also handle it properly anyway, but let's
...@@ -523,12 +523,12 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m, ...@@ -523,12 +523,12 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
* if the 1st NONHEAD lcluster is actually PLAIN or HEAD type * 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 lcluster-sized pcluster.
*/ */
m->compressedlcs = 1; m->compressedblks = 1 << (lclusterbits - LOG_BLOCK_SIZE);
break; break;
case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD: case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD:
if (m->delta[0] != 1) if (m->delta[0] != 1)
goto err_bonus_cblkcnt; goto err_bonus_cblkcnt;
if (m->compressedlcs) if (m->compressedblks)
break; break;
fallthrough; fallthrough;
default: default:
...@@ -539,7 +539,7 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m, ...@@ -539,7 +539,7 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
return -EFSCORRUPTED; return -EFSCORRUPTED;
} }
out: out:
map->m_plen = (u64)m->compressedlcs << lclusterbits; map->m_plen = (u64)m->compressedblks << LOG_BLOCK_SIZE;
return 0; return 0;
err_bonus_cblkcnt: err_bonus_cblkcnt:
erofs_err(m->inode->i_sb, erofs_err(m->inode->i_sb,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment