erofs-utils: lib: use Z_EROFS_LCLUSTER_TYPE_MAX to simplify switches
Subsystems (2)
PATCH v2 1/10 erofs-utils: lib: use Z_EROFS_LCLUSTER_TYPE_MAX to simplify switches
Source kernel commit: 3b7781aeaefb627d4e07c1af9be923f9e8047d8b
--- lib/zmap.c | 60 ++++++++++++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 36 deletions(-)
lib/zmap.c +24 -36
@@ -282,26 +282,22 @@ static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m,if (err)return err; -switch (m->type) { -case Z_EROFS_LCLUSTER_TYPE_NONHEAD : +if (m->type >=Z_EROFS_LCLUSTER_TYPE_MAX ) { +erofs_err ("unknown type %u @ lcn %lu of nid %llu" , + m->type, lcn, vi->nid |0ULL ); +DBG_BUGON (1 ); +return -EOPNOTSUPP ; + }else if (m->type ==Z_EROFS_LCLUSTER_TYPE_NONHEAD ) { lookback_distance = m->delta[0 ];if (!lookback_distance) - goto err_bogus; +break ;continue ; -case Z_EROFS_LCLUSTER_TYPE_PLAIN : -case Z_EROFS_LCLUSTER_TYPE_HEAD1 : -case Z_EROFS_LCLUSTER_TYPE_HEAD2 : + }else { m->headtype = m->type; m->map->m_la = (lcn << lclusterbits) | m->clusterofs;return 0 ; -default : -erofs_err ("unknown type %u @ lcn %lu of nid %llu" , - m->type, lcn, vi->nid |0ULL ); -DBG_BUGON (1 ); -return -EOPNOTSUPP ; } } -err_bogus:erofs_err ("bogus lookback distance %u @ lcn %lu of nid %llu" , lookback_distance, m->lcn |0ULL , vi->nid);DBG_BUGON (1 );
@@ -345,36 +341,30 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,DBG_BUGON (lcn == initial_lcn && m->type ==Z_EROFS_LCLUSTER_TYPE_NONHEAD ); -switch (m->type) { -case Z_EROFS_LCLUSTER_TYPE_PLAIN : -case Z_EROFS_LCLUSTER_TYPE_HEAD1 : -case Z_EROFS_LCLUSTER_TYPE_HEAD2 : +if (m->type ==Z_EROFS_LCLUSTER_TYPE_NONHEAD ) { +if (m->delta[0 ] !=1 ) { +erofs_err ("bogus CBLKCNT @ lcn %lu of nid %llu" , + lcn, vi->nid |0ULL ); +DBG_BUGON (1 ); +return -EFSCORRUPTED ; + } +if (m->compressedblks) + goto out; + }else if (m->type <Z_EROFS_LCLUSTER_TYPE_MAX ) {/* * if the 1st NONHEAD lcluster is actually PLAIN or HEAD type * rather than CBLKCNT, it's a 1 block-sized pcluster. */ m->compressedblks =1 ; -break ; -case Z_EROFS_LCLUSTER_TYPE_NONHEAD : -if (m->delta[0 ] !=1 ) - goto err_bonus_cblkcnt; -if (m->compressedblks) -break ; -/* fallthrough */ -default : -erofs_err ("cannot found CBLKCNT @ lcn %lu of nid %llu" , - lcn, vi->nid |0ULL ); -DBG_BUGON (1 ); -return -EFSCORRUPTED ; + goto out; } -out: - m->map->m_plen =erofs_pos (sbi, m->compressedblks); -return 0 ; -err_bonus_cblkcnt: -erofs_err ("bogus CBLKCNT @ lcn %lu of nid %llu" , +erofs_err ("cannot found CBLKCNT @ lcn %lu of nid %llu" , lcn, vi->nid |0ULL );DBG_BUGON (1 );return -EFSCORRUPTED ; +out: + m->map->m_plen =erofs_pos (sbi, m->compressedblks); +return 0 ; }static int z_erofs_get_extent_decompressedlen (struct z_erofs_maprecorder *m)
@@ -402,9 +392,7 @@ static int z_erofs_get_extent_decompressedlen(struct z_erofs_maprecorder *m) m->delta[1 ] =1 ;DBG_BUGON (1 ); } - }else if (m->type ==Z_EROFS_LCLUSTER_TYPE_PLAIN || - m->type ==Z_EROFS_LCLUSTER_TYPE_HEAD1 || - m->type ==Z_EROFS_LCLUSTER_TYPE_HEAD2 ) { + }else if (m->type <Z_EROFS_LCLUSTER_TYPE_MAX ) {if (lcn != headlcn)break ;/* ends at the next HEAD lcluster */ m->delta[1 ] =1 ;
Signature · 1 line
2.43.5
PATCH v2 2/10 erofs-utils: lib: simplify tail inline pcluster handling
Source kernel commit: b7710262d743aca112877d12abed61ce8a5d0d98
--- include/erofs/internal.h | 4 ++-- lib/zmap.c | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-)
include/erofs/internal.h +2 -2
@@ -270,8 +270,8 @@ struct erofs_inode {erofs_off_t fragment_size; };union { -unsigned int z_idataoff; -erofs_off_t fragmentoff; +erofs_off_t fragmentoff; +erofs_off_t z_fragmentoff; };#define z_idata_size idata_size };
lib/zmap.c +10 -10
@@ -414,8 +414,8 @@ static int z_erofs_do_map_blocks(struct erofs_inode *vi, int flags) {struct erofs_sb_info *sbi = vi->sbi; -bool ztailpacking = vi->z_advise &Z_EROFS_ADVISE_INLINE_PCLUSTER ;bool fragment = vi->z_advise &Z_EROFS_ADVISE_FRAGMENT_PCLUSTER ; +bool ztailpacking = vi->z_idata_size;struct z_erofs_maprecorder m = { .inode = vi, .map = map,
@@ -435,9 +435,8 @@ static int z_erofs_do_map_blocks(struct erofs_inode *vi,if (err) goto out; -if (ztailpacking && (flags &EROFS_GET_BLOCKS_FINDTAIL )) - vi->z_idataoff = m.nextpackoff; - +if ((flags &EROFS_GET_BLOCKS_FINDTAIL ) && ztailpacking) + vi->z_fragmentoff = m.nextpackoff; map->m_flags =EROFS_MAP_MAPPED |EROFS_MAP_ENCODED ; end = (m.lcn +1ULL ) << lclusterbits;
@@ -492,7 +491,7 @@ static int z_erofs_do_map_blocks(struct erofs_inode *vi, }if (ztailpacking && m.lcn == vi->z_tailextent_headlcn) { map->m_flags |=EROFS_MAP_META ; - map->m_pa = vi->z_idataoff; + map->m_pa = vi->z_fragmentoff; map->m_plen = vi->z_idata_size; }else if (fragment && m.lcn == vi->z_tailextent_headlcn) { map->m_flags |=EROFS_MAP_FRAGMENT ;
@@ -568,6 +567,10 @@ static int z_erofs_fill_inode_lazy(struct erofs_inode *vi) vi->z_advise =le16_to_cpu (h->h_advise); vi->z_algorithmtype[0 ] = h->h_algorithmtype &15 ; vi->z_algorithmtype[1 ] = h->h_algorithmtype >>4 ; +if (vi->z_advise &Z_EROFS_ADVISE_FRAGMENT_PCLUSTER ) + vi->z_fragmentoff =le32_to_cpu (h->h_fragmentoff); +else if (vi->z_advise &Z_EROFS_ADVISE_INLINE_PCLUSTER ) + vi->z_idata_size =le16_to_cpu (h->h_idata_size); headnr =0 ; if (vi->z_algorithmtype[0] >= Z_EROFS_COMPRESSION_MAX ||
@@ -586,14 +589,12 @@ static int z_erofs_fill_inode_lazy(struct erofs_inode *vi)return -EFSCORRUPTED ; } -if (vi->z_advise &Z_EROFS_ADVISE_INLINE_PCLUSTER ) { +if (vi->z_idata_size) {struct erofs_map_blocks map = { .index =UINT_MAX }; - vi->idata_size =le16_to_cpu (h->h_idata_size); err =z_erofs_do_map_blocks (vi, &map,EROFS_GET_BLOCKS_FINDTAIL ); -if (!map.m_plen || -erofs_blkoff (sbi, map.m_pa) + map.m_plen >erofs_blksiz (sbi)) { +if (erofs_blkoff (sbi, map.m_pa) + map.m_plen >erofs_blksiz (sbi)) {erofs_err ("invalid tail-packing pclustersize %llu" , map.m_plen |0ULL );return -EFSCORRUPTED ;
@@ -605,7 +606,6 @@ static int z_erofs_fill_inode_lazy(struct erofs_inode *vi) !(h->h_clusterbits >> Z_EROFS_FRAGMENT_INODE_BIT)) {struct erofs_map_blocks map = { .index =UINT_MAX }; - vi->fragmentoff =le32_to_cpu (h->h_fragmentoff); err =z_erofs_do_map_blocks (vi, &map,EROFS_GET_BLOCKS_FINDTAIL );if (err <0 )
Signature · 1 line
2.43.5
PATCH v2 3/10 erofs-utils: lib: clean up header parsing for ztailpacking and fragments
In reply to Gao XiangSource kernel commit: 540787d38b10dbc16a7d2bc2845752ab1605403a
--- lib/zmap.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
lib/zmap.c +7 -15
@@ -493,6 +493,11 @@ static int z_erofs_do_map_blocks(struct erofs_inode *vi, map->m_flags |=EROFS_MAP_META ; map->m_pa = vi->z_fragmentoff; map->m_plen = vi->z_idata_size; +if (erofs_blkoff (sbi, map->m_pa) + map->m_plen >erofs_blksiz (sbi)) { +erofs_err ("invalid tail-packing pclustersize %llu" , + map->m_plen |0ULL ); + goto out; + } }else if (fragment && m.lcn == vi->z_tailextent_headlcn) { map->m_flags |=EROFS_MAP_FRAGMENT ; }else {
@@ -589,21 +594,8 @@ static int z_erofs_fill_inode_lazy(struct erofs_inode *vi)return -EFSCORRUPTED ; } -if (vi->z_idata_size) { -struct erofs_map_blocks map = { .index =UINT_MAX }; - - err =z_erofs_do_map_blocks (vi, &map, -EROFS_GET_BLOCKS_FINDTAIL ); -if (erofs_blkoff (sbi, map.m_pa) + map.m_plen >erofs_blksiz (sbi)) { -erofs_err ("invalid tail-packing pclustersize %llu" , - map.m_plen |0ULL ); -return -EFSCORRUPTED ; - } -if (err <0 ) -return err; - } -if (vi->z_advise &Z_EROFS_ADVISE_FRAGMENT_PCLUSTER && - !(h->h_clusterbits >>Z_EROFS_FRAGMENT_INODE_BIT )) { +if (vi->z_idata_size || + (vi->z_advise &Z_EROFS_ADVISE_FRAGMENT_PCLUSTER )) {struct erofs_map_blocks map = { .index =UINT_MAX }; err = z_erofs_do_map_blocks(vi, &map,
Signature · 1 line
2.43.5
PATCH v2 4/10 erofs-utils: get rid of NULL_ADDR{,_UL}
In reply to Gao Xiang.. And replace them with EROFS_NULL_ADDR.
--- include/erofs/cache.h | 4 ++-- include/erofs/internal.h | 3 --- lib/cache.c | 24 ++++++++++++------------ lib/inode.c | 2 +- lib/rebuild.c | 2 +- 5 files changed, 16 insertions(+), 19 deletions(-)
include/erofs/cache.h +2 -2
@@ -107,8 +107,8 @@ static inline erofs_off_t erofs_btell(struct erofs_buffer_head *bh, bool end)struct erofs_bufmgr *bmgr = (struct erofs_bufmgr *)bb->buffers.fsprivate; -if (bb->blkaddr ==NULL_ADDR ) -return NULL_ADDR_UL ; +if (bb->blkaddr ==EROFS_NULL_ADDR ) +return EROFS_NULL_ADDR ;return erofs_pos (bmgr->sbi, bb->blkaddr) + (end ?list_next_entry (bh, list)->off : bh->off);
include/erofs/internal.h +0 -3
@@ -44,9 +44,6 @@ typedef u64 erofs_nid_t;/* data type for filesystem-wide blocks number */ typedef u32 erofs_blk_t ; -#define NULL_ADDR ((unsigned int)-1) -#define NULL_ADDR_UL ((unsigned long)-1) -/* global sbi */ extern struct erofs_sb_info g_sbi;
lib/cache.c +12 -12
@@ -49,7 +49,7 @@ struct erofs_bufmgr *erofs_buffer_init(struct erofs_sb_info *sbi, } }init_list_head (&bmgr->blkh.list); - bmgr->blkh.blkaddr =NULL_ADDR ; + bmgr->blkh.blkaddr =EROFS_NULL_ADDR ; bmgr->tail_blkaddr = startblk; bmgr->last_mapped_block = &bmgr->blkh; bmgr->dsunit =0 ;
@@ -79,7 +79,7 @@ static void erofs_update_bwatermeter(struct erofs_buffer_block *bb, bool free)struct erofs_bufmgr *bmgr = bb->buffers.fsprivate;struct erofs_sb_info *sbi = bmgr->sbi;unsigned int blksiz =erofs_blksiz (sbi); -bool mapped = bb->blkaddr !=NULL_ADDR ; +bool mapped = bb->blkaddr !=EROFS_NULL_ADDR ;struct list_head *h = bmgr->watermeter[bb->type][mapped];unsigned int nr;
@@ -127,12 +127,12 @@ static int __erofs_battach(struct erofs_buffer_block *bb, oob =cmpsgn (alignedoffset + incr + inline_ext, bb->buffers.nblocks << sbi->blkszbits);if (oob >=0 ) { -/* the next buffer block should be NULL_ADDR all the time */ -if (oob &&list_next_entry (bb, list)->blkaddr !=NULL_ADDR ) +/* the next buffer block should be EROFS_NULL_ADDR all the time */ +if (oob &&list_next_entry (bb, list)->blkaddr !=EROFS_NULL_ADDR )return -EINVAL ; blkaddr = bb->blkaddr; -if (blkaddr !=NULL_ADDR ) { +if (blkaddr !=EROFS_NULL_ADDR ) { tailupdate = (bmgr->tail_blkaddr == blkaddr + bb->buffers.nblocks);if (oob && !tailupdate)
@@ -244,7 +244,7 @@ static int erofs_bfind_for_attach(struct erofs_bufmgr *bmgr,/* skip the last mapped block */ if (mapped && -list_next_entry (cur, list)->blkaddr ==NULL_ADDR ) { +list_next_entry (cur, list)->blkaddr ==EROFS_NULL_ADDR ) {DBG_BUGON (cur != bmgr->last_mapped_block); cur =list_next_entry (cur, sibling);if (&cur->sibling == bt)
@@ -252,7 +252,7 @@ static int erofs_bfind_for_attach(struct erofs_bufmgr *bmgr, }DBG_BUGON (cur->type != type); -DBG_BUGON ((cur->blkaddr !=NULL_ADDR ) ^ mapped); +DBG_BUGON ((cur->blkaddr !=EROFS_NULL_ADDR ) ^ mapped);DBG_BUGON (used != (cur->buffers.off & blkmask)); ret = __erofs_battach(cur, NULL, size, alignsize,
@@ -327,7 +327,7 @@ struct erofs_buffer_head *erofs_balloc(struct erofs_bufmgr *bmgr,return ERR_PTR (-ENOMEM ); bb->type = type; - bb->blkaddr =NULL_ADDR ; + bb->blkaddr =EROFS_NULL_ADDR ; bb->buffers.off =0 ; bb->buffers.nblocks =0 ; bb->buffers.fsprivate = bmgr;
@@ -388,7 +388,7 @@ static void __erofs_mapbh(struct erofs_buffer_block *bb)struct erofs_bufmgr *bmgr = bb->buffers.fsprivate;erofs_blk_t blkaddr = bmgr->tail_blkaddr; -if (bb->blkaddr ==NULL_ADDR ) { +if (bb->blkaddr ==EROFS_NULL_ADDR ) { bb->blkaddr = blkaddr;if (__erofs_unlikely (bmgr->dsunit >1 ) && bb->type ==DATA ) {struct erofs_buffer_block *pb =list_prev_entry (bb, list);
@@ -418,14 +418,14 @@ erofs_blk_t erofs_mapbh(struct erofs_bufmgr *bmgr, bmgr = bb->buffers.fsprivate; t = bmgr->last_mapped_block; -if (bb && bb->blkaddr !=NULL_ADDR ) +if (bb && bb->blkaddr !=EROFS_NULL_ADDR )return bb->blkaddr;do { t =list_next_entry (t, list);if (t == &bmgr->blkh)break ; -DBG_BUGON (t->blkaddr !=NULL_ADDR ); +DBG_BUGON (t->blkaddr !=EROFS_NULL_ADDR );__erofs_mapbh (t); }while (t != bb);return bmgr->tail_blkaddr;
@@ -501,7 +501,7 @@ void erofs_bdrop(struct erofs_buffer_head *bh, bool tryrevoke)bool rollback = false;/* tail_blkaddr could be rolled back after revoking all bhs */ -if (tryrevoke && blkaddr !=NULL_ADDR && +if (tryrevoke && blkaddr !=EROFS_NULL_ADDR && bmgr->tail_blkaddr == blkaddr + bb->buffers.nblocks) rollback = true;
lib/inode.c +1 -1
@@ -189,7 +189,7 @@ int erofs_allocate_inode_bh_data(struct erofs_inode *inode, erofs_blk_t nblocks)if (!nblocks) {/* it has only tail-end data */ - inode->u.i_blkaddr =NULL_ADDR ; + inode->u.i_blkaddr =EROFS_NULL_ADDR ;return 0 ; }
lib/rebuild.c +1 -1
@@ -249,7 +249,7 @@ static int erofs_rebuild_update_inode(struct erofs_sb_info *dst_sb,break ;case S_IFREG :if (!inode->i_size) { - inode->u.i_blkaddr =NULL_ADDR ; + inode->u.i_blkaddr =EROFS_NULL_ADDR ;break ; }if (datamode ==EROFS_REBUILD_DATA_BLOB_INDEX )
Signature · 1 line
2.43.5
PATCH v2 5/10 erofs-utils: lib: sync up with the 48-bit kernel erofs_fs.h
In reply to Gao XiangKeep in sync with the related kernel commits:
commit 61ba89b57905 ("erofs: add 48-bit block addressing on-disk support") commit efb2aef569b3 ("erofs: add encoded extent on-disk definition")
--- include/erofs/internal.h | 4 +- include/erofs_fs.h | 191 ++++++++++++++++++--------------------- lib/blobchunk.c | 20 ++-- lib/compress.c | 2 +- lib/data.c | 8 +- lib/inode.c | 6 +- lib/namei.c | 4 +- lib/super.c | 16 ++-- lib/zmap.c | 2 +- 9 files changed, 119 insertions(+), 134 deletions(-)
include/erofs/internal.h +2 -2
@@ -59,8 +59,8 @@ struct erofs_bufmgr;struct erofs_device_info {u8 tag[64 ]; -u32 blocks; -u32 mapped_blkaddr; +erofs_blk_t blocks; +erofs_blk_t uniaddr; };/* all filesystem-wide lz4 configurations */
include/erofs_fs.h +88 -103
310 lines not on this page · raw message
lib/blobchunk.c +10 -10
@@ -159,32 +159,32 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode, chunk = *(void **)(inode->chunkindexes + src);if (chunk->blkaddr ==EROFS_NULL_ADDR ) { - idx.blkaddr =EROFS_NULL_ADDR ; + idx.startblk_lo =EROFS_NULL_ADDR ; }else if (chunk->device_id) {DBG_BUGON (!(inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES )); - idx.blkaddr = chunk->blkaddr; + idx.startblk_lo = chunk->blkaddr; extent_start =EROFS_NULL_ADDR ; }else { - idx.blkaddr = remapped_base + chunk->blkaddr; + idx.startblk_lo = remapped_base + chunk->blkaddr; }if (extent_start ==EROFS_NULL_ADDR || - idx.blkaddr != extent_end) { + idx.startblk_lo != extent_end) {if (extent_start !=EROFS_NULL_ADDR ) { remaining_blks -= extent_end - extent_start;tarerofs_blocklist_write (extent_start, extent_end - extent_start, source_offset,0 ); } - extent_start = idx.blkaddr; + extent_start = idx.startblk_lo; source_offset = chunk->sourceoffset; } - extent_end = idx.blkaddr + chunkblks; + extent_end = idx.startblk_lo + chunkblks; idx.device_id =cpu_to_le16 (chunk->device_id); - idx.blkaddr =cpu_to_le32 (idx.blkaddr); + idx.startblk_lo =cpu_to_le32 (idx.startblk_lo);if (unit ==EROFS_BLOCK_MAP_ENTRY_SIZE ) -memcpy (inode->chunkindexes + dst, &idx.blkaddr, unit); +memcpy (inode->chunkindexes + dst, &idx.startblk_lo, unit);else memcpy (inode->chunkindexes + dst, &idx,sizeof (idx)); }
@@ -502,8 +502,8 @@ int erofs_mkfs_dump_blobs(struct erofs_sb_info *sbi) i =0 ; do { struct erofs_deviceslot dis = { - .mapped_blkaddr = cpu_to_le32(nblocks), - .blocks = cpu_to_le32(sbi->devs[i].blocks), + .uniaddr_lo = cpu_to_le32(nblocks), + .blocks_lo = cpu_to_le32(sbi->devs[i].blocks), }; memcpy(dis.tag, sbi->devs[i].tag, sizeof(dis.tag));
lib/compress.c +1 -1
@@ -120,7 +120,7 @@ static struct {static bool z_erofs_mt_enabled; -#define Z_EROFS_LEGACY_MAP_HEADER_SIZE Z_EROFS_FULL_INDEX_ALIGN(0) +#define Z_EROFS_LEGACY_MAP_HEADER_SIZE Z_EROFS_FULL_INDEX_START(0)static void z_erofs_fini_full_indexes (struct z_erofs_compress_ictx *ctx) {
lib/data.c +4 -4
@@ -117,14 +117,14 @@ int __erofs_map_blocks(struct erofs_inode *inode, }/* parse chunk indexes */ idx = (void *)buf +erofs_blkoff (sbi, pos); -switch (le32_to_cpu (idx->blkaddr)) { +switch (le32_to_cpu (idx->startblk_lo)) {case EROFS_NULL_ADDR : map->m_flags =0 ;break ;default : map->m_deviceid =le16_to_cpu (idx->device_id) & sbi->device_id_mask; - map->m_pa =erofs_pos (sbi,le32_to_cpu (idx->blkaddr)); + map->m_pa =erofs_pos (sbi,le32_to_cpu (idx->startblk_lo)); map->m_flags =EROFS_MAP_MAPPED ;break ; }
@@ -154,9 +154,9 @@ int erofs_map_dev(struct erofs_sb_info *sbi, struct erofs_map_dev *map)erofs_off_t startoff, length; dif = sbi->devs + id; -if (!dif->mapped_blkaddr) +if (!dif->uniaddr)continue ; - startoff =erofs_pos (sbi, dif->mapped_blkaddr); + startoff =erofs_pos (sbi, dif->uniaddr); length =erofs_pos (sbi, dif->blocks); if (map->m_pa >= startoff &&
lib/inode.c +3 -3
@@ -603,18 +603,18 @@ int erofs_iflush(struct erofs_inode *inode) S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) u1.rdev = cpu_to_le32(inode->u.i_rdev); else if (is_inode_layout_compression(inode)) - u1.compressed_blocks = cpu_to_le32(inode->u.i_blocks); + u1.blocks_lo = cpu_to_le32(inode->u.i_blocks); else if (inode->datalayout == EROFS_INODE_CHUNK_BASED) u1.c.format = cpu_to_le16(inode->u.chunkformat); else - u1.raw_blkaddr = cpu_to_le32(inode->u.i_blkaddr); + u1.startblk_lo = cpu_to_le32(inode->u.i_blkaddr);switch (inode->inode_isize) {case sizeof (struct erofs_inode_compact ): u.dic.i_format =cpu_to_le16 (0 | (inode->datalayout <<1 )); u.dic.i_xattr_icount =cpu_to_le16 (icount); u.dic.i_mode =cpu_to_le16 (inode->i_mode); - u.dic.i_nlink =cpu_to_le16 (inode->i_nlink); + u.dic.i_nb.nlink =cpu_to_le16 (inode->i_nlink); u.dic.i_size =cpu_to_le32 ((u32 )inode->i_size); u.dic.i_ino =cpu_to_le32 (inode->i_ino[0 ]);
lib/namei.c +2 -2
@@ -77,7 +77,7 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi) iu = dic->i_u; vi->i_uid =le16_to_cpu (dic->i_uid); vi->i_gid =le16_to_cpu (dic->i_gid); - vi->i_nlink =le16_to_cpu (dic->i_nlink); + vi->i_nlink =le16_to_cpu (dic->i_nb.nlink); vi->i_mtime = sbi->build_time; vi->i_mtime_nsec = sbi->build_time_nsec;
@@ -94,7 +94,7 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi)case S_IFREG :case S_IFDIR :case S_IFLNK : - vi->u.i_blkaddr =le32_to_cpu (iu.raw_blkaddr); + vi->u.i_blkaddr =le32_to_cpu (iu.startblk_lo);break ;case S_IFCHR :case S_IFBLK :
lib/super.c +8 -8
@@ -63,8 +63,8 @@ static int erofs_init_devices(struct erofs_sb_info *sbi,return ret; } - sbi->devs[i].mapped_blkaddr =le32_to_cpu (dis.mapped_blkaddr); - sbi->devs[i].blocks =le32_to_cpu (dis.blocks); + sbi->devs[i].uniaddr =le32_to_cpu (dis.uniaddr_lo); + sbi->devs[i].blocks =le32_to_cpu (dis.blocks_lo);memcpy (sbi->devs[i].tag, dis.tag,sizeof (dis.tag)); sbi->total_blocks += sbi->devs[i].blocks; pos +=EROFS_DEVT_SLOT_SIZE ;
@@ -110,19 +110,19 @@ int erofs_read_superblock(struct erofs_sb_info *sbi) dsb->sb_extslots);return -EINVAL ; } - sbi->primarydevice_blocks =le32_to_cpu (dsb->blocks); + sbi->primarydevice_blocks =le32_to_cpu (dsb->blocks_lo); sbi->meta_blkaddr =le32_to_cpu (dsb->meta_blkaddr); sbi->xattr_blkaddr =le32_to_cpu (dsb->xattr_blkaddr); sbi->xattr_prefix_start =le32_to_cpu (dsb->xattr_prefix_start); sbi->xattr_prefix_count = dsb->xattr_prefix_count; sbi->islotbits =EROFS_ISLOTBITS ; - sbi->root_nid =le16_to_cpu (dsb->root_nid); + sbi->root_nid =le16_to_cpu (dsb->rb.rootnid_2b); sbi->packed_nid =le64_to_cpu (dsb->packed_nid); sbi->inos =le64_to_cpu (dsb->inos); sbi->checksum =le32_to_cpu (dsb->checksum); sbi->build_time =le64_to_cpu (dsb->build_time); - sbi->build_time_nsec =le32_to_cpu (dsb->build_time_nsec); + sbi->build_time_nsec =le32_to_cpu (dsb->fixed_nsec);memcpy (&sbi->uuid, dsb->uuid,sizeof (dsb->uuid));
@@ -161,10 +161,10 @@ int erofs_writesb(struct erofs_sb_info *sbi, struct erofs_buffer_head *sb_bh,struct erofs_super_block sb = { .magic =cpu_to_le32 (EROFS_SUPER_MAGIC_V1 ), .blkszbits = sbi->blkszbits, - .root_nid =cpu_to_le16 (sbi->root_nid), + .rb.rootnid_2b =cpu_to_le16 (sbi->root_nid), .inos =cpu_to_le64 (sbi->inos), .build_time =cpu_to_le64 (sbi->build_time), - .build_time_nsec =cpu_to_le32 (sbi->build_time_nsec), + .fixed_nsec =cpu_to_le32 (sbi->build_time_nsec), .meta_blkaddr =cpu_to_le32 (sbi->meta_blkaddr), .xattr_blkaddr =cpu_to_le32 (sbi->xattr_blkaddr), .xattr_prefix_count = sbi->xattr_prefix_count,
@@ -181,7 +181,7 @@ int erofs_writesb(struct erofs_sb_info *sbi, struct erofs_buffer_head *sb_bh,int ret; *blocks =erofs_mapbh (sbi->bmgr,NULL ); - sb.blocks =cpu_to_le32 (*blocks); + sb.blocks_lo =cpu_to_le32 (*blocks);memcpy (sb.uuid, sbi->uuid,sizeof (sb.uuid));memcpy (sb.volume_name, sbi->volume_name,sizeof (sb.volume_name));
lib/zmap.c +1 -1
@@ -30,7 +30,7 @@ static int z_erofs_load_full_lcluster(struct z_erofs_maprecorder *m, {struct erofs_inode *const vi = m->inode;struct erofs_sb_info *sbi = vi->sbi; -const erofs_off_t pos =Z_EROFS_FULL_INDEX_ALIGN (erofs_iloc (vi) + +const erofs_off_t pos =Z_EROFS_FULL_INDEX_START (erofs_iloc (vi) + vi->inode_isize + vi->xattr_isize) + lcn *sizeof (struct z_erofs_lcluster_index );erofs_blk_t eblk =erofs_blknr (sbi, pos);
Signature · 1 line
2.43.5
PATCH v2 6/10 erofs-utils: implement 48-bit block addressing for unencoded inodes
In reply to Gao Xiang.. Also port the same kernel logic to erofsfuse and dump.erofs.
--- dump/main.c | 1 + include/erofs/internal.h | 21 +++--- include/erofs_fs.h | 2 +- lib/blobchunk.c | 2 +- lib/block_list.c | 8 +-- lib/data.c | 143 +++++++++++++++------------------------ lib/inode.c | 6 +- lib/namei.c | 35 +++++++--- lib/super.c | 14 +++- mkfs/main.c | 12 ++-- 10 files changed, 117 insertions(+), 127 deletions(-)
dump/main.c +1 -0
@@ -104,6 +104,7 @@ static struct erofsdump_feature feature_lists[] = { { false, EROFS_FEATURE_INCOMPAT_FRAGMENTS, "fragments" }, { false, EROFS_FEATURE_INCOMPAT_DEDUPE, "dedupe" }, { false, EROFS_FEATURE_INCOMPAT_XATTR_PREFIXES, "xattr_prefixes" }, + { false, EROFS_FEATURE_INCOMPAT_48BIT, "48bit" }, };static int erofsdump_readdir (struct erofs_dir_context *ctx);
include/erofs/internal.h +11 -10
@@ -41,15 +41,14 @@ typedef unsigned short umode_t;typedef u64 erofs_off_t ;typedef u64 erofs_nid_t ; -/* data type for filesystem-wide blocks number */ -typedef u32 erofs_blk_t ; +typedef u64 erofs_blk_t ;/* global sbi */ extern struct erofs_sb_info g_sbi;#define erofs_blksiz (sbi) (1u << (sbi)->blkszbits) -#define erofs_blknr (sbi, addr) ((addr) >> (sbi)->blkszbits) -#define erofs_blkoff (sbi, addr) ((addr) & (erofs_blksiz(sbi) - 1)) +#define erofs_blknr (sbi, pos) ((pos) >> (sbi)->blkszbits) +#define erofs_blkoff (sbi, pos) ((pos) & (erofs_blksiz(sbi) - 1))#define erofs_pos (sbi, nr) ((erofs_off_t)(nr) << (sbi)->blkszbits)#define BLK_ROUND_UP (sbi, addr) \ (roundup(addr, erofs_blksiz(sbi)) >> (sbi)->blkszbits)
@@ -88,8 +87,8 @@ struct erofs_sb_info {u64 total_blocks;u64 primarydevice_blocks; -erofs_blk_t meta_blkaddr; -erofs_blk_t xattr_blkaddr; +u32 meta_blkaddr; +u32 xattr_blkaddr;u32 feature_compat;u32 feature_incompat;
@@ -98,8 +97,9 @@ struct erofs_sb_info {unsigned char blkszbits;u32 sb_size;/* total superblock size */ -u32 build_time_nsec; -u64 build_time; +u32 build_time; +u32 fixed_nsec; +u64 epoch;/* what we really care is nid, rather than ino.. */ erofs_nid_t root_nid;
@@ -170,6 +170,7 @@ EROFS_FEATURE_FUNCS(ztailpacking, incompat, INCOMPAT_ZTAILPACKING) EROFS_FEATURE_FUNCS(fragments, incompat, INCOMPAT_FRAGMENTS) EROFS_FEATURE_FUNCS(dedupe, incompat, INCOMPAT_DEDUPE) EROFS_FEATURE_FUNCS(xattr_prefixes, incompat, INCOMPAT_XATTR_PREFIXES) +EROFS_FEATURE_FUNCS(48bit, incompat, INCOMPAT_48BIT) EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM)EROFS_FEATURE_FUNCS (xattr_filter, compat,COMPAT_XATTR_FILTER )
@@ -214,8 +215,8 @@ struct erofs_inode {u32 i_nlink;union { -u32 i_blkaddr; -u32 i_blocks; +erofs_blk_t i_blkaddr; +erofs_blk_t i_blocks;u32 i_rdev;struct {unsigned short chunkformat;
include/erofs_fs.h +1 -1
@@ -256,7 +256,7 @@ static inline unsigned int erofs_xattr_entry_size(struct erofs_xattr_entry *e) }/* represent a zeroed chunk (hole) */ -#define EROFS_NULL_ADDR -1 +#define EROFS_NULL_ADDR -1ULL/* 4-byte block address array */ #define EROFS_BLOCK_MAP_ENTRY_SIZE sizeof(__le32)
lib/blobchunk.c +1 -1
@@ -159,7 +159,7 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode, chunk = *(void **)(inode->chunkindexes + src);if (chunk->blkaddr ==EROFS_NULL_ADDR ) { - idx.startblk_lo =EROFS_NULL_ADDR ; + idx.startblk_lo = (u32 )EROFS_NULL_ADDR ; }else if (chunk->device_id) {DBG_BUGON (!(inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES )); idx.startblk_lo = chunk->blkaddr;
lib/block_list.c +4 -4
@@ -38,9 +38,9 @@ void tarerofs_blocklist_write(erofs_blk_t blkaddr, erofs_blk_t nblocks,return ;if (zeroedlen) -fprintf (block_list_fp,"%08x %8x %08" PRIx64" %08u\n" , - blkaddr, nblocks, srcoff, zeroedlen); +fprintf (block_list_fp,"%08llx %8llx %08" PRIx64" %08u\n" , + blkaddr |0ULL , nblocks |0ULL , srcoff, zeroedlen);else -fprintf (block_list_fp,"%08x %8x %08" PRIx64"\n" , - blkaddr, nblocks, srcoff); +fprintf (block_list_fp,"%08llx %8llx %08" PRIx64"\n" , + blkaddr |0ULL , nblocks |0ULL , srcoff); }
lib/data.c +55 -88
173 lines not on this page · raw message
lib/inode.c +3 -3
@@ -925,7 +925,7 @@ static bool erofs_should_use_inode_extended(struct erofs_inode *inode)if (inode->i_nlink >USHRT_MAX )return true;if ((inode->i_mtime != inode->sbi->build_time || - inode->i_mtime_nsec != inode->sbi->build_time_nsec) && + inode->i_mtime_nsec != inode->sbi->fixed_nsec) && !cfg.c_ignore_mtime)return true;return false;
@@ -1025,7 +1025,7 @@ int __erofs_fill_inode(struct erofs_inode *inode, struct stat *st,break ;case TIMESTAMP_FIXED : inode->i_mtime = sbi->build_time; - inode->i_mtime_nsec = sbi->build_time_nsec; + inode->i_mtime_nsec = sbi->fixed_nsec;default :break ; }
@@ -1993,7 +1993,7 @@ struct erofs_inode *erofs_rebuild_make_root(struct erofs_sb_info *sbi) root->i_mode =S_IFDIR |0777 ; root->i_parent = root; root->i_mtime = root->sbi->build_time; - root->i_mtime_nsec = root->sbi->build_time_nsec; + root->i_mtime_nsec = root->sbi->fixed_nsec;erofs_init_empty_dir (root);return root; }
lib/namei.c +24 -11
@@ -28,9 +28,9 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi)char buf[sizeof (struct erofs_inode_extended )];erofs_off_t inode_loc =erofs_iloc (vi);struct erofs_sb_info *sbi = vi->sbi; +erofs_blk_t addrmask =BIT_ULL (48 ) -1 ; +struct erofs_inode_extended *die, copied;struct erofs_inode_compact *dic; -struct erofs_inode_extended *die; -union erofs_inode_i_u iu;DBG_BUGON (!sbi); ret =erofs_dev_read (sbi,0 , buf, inode_loc,sizeof (*dic));
@@ -60,7 +60,8 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi) vi->xattr_isize =erofs_xattr_ibody_size (die->i_xattr_icount); vi->i_mode =le16_to_cpu (die->i_mode); vi->i_ino[0 ] =le32_to_cpu (die->i_ino); - iu = die->i_u; + copied.i_u = die->i_u; + copied.i_nb = die->i_nb; vi->i_uid =le32_to_cpu (die->i_uid); vi->i_gid =le32_to_cpu (die->i_gid); vi->i_nlink =le32_to_cpu (die->i_nlink);
@@ -74,13 +75,21 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi) vi->xattr_isize =erofs_xattr_ibody_size (dic->i_xattr_icount); vi->i_mode =le16_to_cpu (dic->i_mode); vi->i_ino[0 ] =le32_to_cpu (dic->i_ino); - iu = dic->i_u; + copied.i_u = dic->i_u; + copied.i_nb = dic->i_nb; vi->i_uid =le16_to_cpu (dic->i_uid); vi->i_gid =le16_to_cpu (dic->i_gid); - vi->i_nlink =le16_to_cpu (dic->i_nb.nlink); - - vi->i_mtime = sbi->build_time; - vi->i_mtime_nsec = sbi->build_time_nsec; +if (!S_ISDIR (vi->i_mode) && + ((ifmt >>EROFS_I_NLINK_1_BIT ) &1 )) { + vi->i_nlink =1 ; + copied.i_nb = dic->i_nb; + }else { + vi->i_nlink =le16_to_cpu (dic->i_nb.nlink); + copied.i_nb.startblk_hi =0 ; + addrmask =BIT_ULL (32 ) -1 ; + } + vi->i_mtime = sbi->epoch +le32_to_cpu (dic->i_mtime); + vi->i_mtime_nsec = sbi->fixed_nsec; vi->i_size =le32_to_cpu (dic->i_size);break ;
@@ -94,11 +103,15 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi)case S_IFREG :case S_IFDIR :case S_IFLNK : - vi->u.i_blkaddr =le32_to_cpu (iu.startblk_lo); + vi->u.i_blkaddr =le32_to_cpu (copied.i_u.startblk_lo) | + ((u64 )le16_to_cpu (copied.i_nb.startblk_hi) <<32 ); +if (vi->datalayout ==EROFS_INODE_FLAT_PLAIN && + !((vi->u.i_blkaddr ^EROFS_NULL_ADDR ) & addrmask)) + vi->u.i_blkaddr =EROFS_NULL_ADDR ;break ;case S_IFCHR :case S_IFBLK : - vi->u.i_rdev =erofs_new_decode_dev (le32_to_cpu (iu.rdev)); + vi->u.i_rdev =erofs_new_decode_dev (le32_to_cpu (copied.i_u.rdev));break ;case S_IFIFO :case S_IFSOCK :
@@ -113,7 +126,7 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi) vi->flags =0 ;if (vi->datalayout ==EROFS_INODE_CHUNK_BASED ) {/* fill chunked inode summary info */ - vi->u.chunkformat =le16_to_cpu (iu.c.format); + vi->u.chunkformat =le16_to_cpu (copied.i_u.c.format);if (vi->u.chunkformat & ~EROFS_CHUNK_FORMAT_ALL ) {erofs_err ("unsupported chunk format %x of nid %llu" , vi->u.chunkformat, vi->nid |0ULL );
lib/super.c +11 -3
@@ -116,13 +116,20 @@ int erofs_read_superblock(struct erofs_sb_info *sbi) sbi->xattr_prefix_start =le32_to_cpu (dsb->xattr_prefix_start); sbi->xattr_prefix_count = dsb->xattr_prefix_count; sbi->islotbits =EROFS_ISLOTBITS ; - sbi->root_nid =le16_to_cpu (dsb->rb.rootnid_2b); +if (erofs_sb_has_48bit (sbi) && dsb->rootnid_8b) { + sbi->root_nid =le64_to_cpu (dsb->rootnid_8b); + sbi->primarydevice_blocks = (sbi->primarydevice_blocks <<32 ) | +le16_to_cpu (dsb->rb.blocks_hi); + }else { + sbi->root_nid =le16_to_cpu (dsb->rb.rootnid_2b); + } sbi->packed_nid =le64_to_cpu (dsb->packed_nid); sbi->inos =le64_to_cpu (dsb->inos); sbi->checksum =le32_to_cpu (dsb->checksum); + sbi->epoch = (s64 )le64_to_cpu (dsb->epoch); + sbi->fixed_nsec =le32_to_cpu (dsb->fixed_nsec); sbi->build_time =le64_to_cpu (dsb->build_time); - sbi->build_time_nsec =le32_to_cpu (dsb->fixed_nsec);memcpy (&sbi->uuid, dsb->uuid,sizeof (dsb->uuid));
@@ -163,8 +170,9 @@ int erofs_writesb(struct erofs_sb_info *sbi, struct erofs_buffer_head *sb_bh, .blkszbits = sbi->blkszbits, .rb.rootnid_2b = cpu_to_le16(sbi->root_nid), .inos = cpu_to_le64(sbi->inos), + .epoch = cpu_to_le64(sbi->epoch), .build_time = cpu_to_le64(sbi->build_time), - .fixed_nsec = cpu_to_le32(sbi->build_time_nsec), + .fixed_nsec = cpu_to_le32(sbi->fixed_nsec), .meta_blkaddr = cpu_to_le32(sbi->meta_blkaddr), .xattr_blkaddr = cpu_to_le32(sbi->xattr_blkaddr), .xattr_prefix_count = sbi->xattr_prefix_count,
mkfs/main.c +6 -6
@@ -1179,12 +1179,12 @@ static void erofs_mkfs_showsummaries(erofs_blk_t nblocks)erofs_uuid_unparse_lower (g_sbi.uuid, uuid_str);fprintf (stdout,"------\nFilesystem UUID: %s\n" -"Filesystem total blocks: %u (of %u-byte blocks)\n" +"Filesystem total blocks: %llu (of %u-byte blocks)\n" "Filesystem total inodes: %llu\n" -"Filesystem %s metadata blocks: %u\n" +"Filesystem %s metadata blocks: %llu\n" "Filesystem %s deduplicated bytes (of source files): %llu\n" , - uuid_str, nblocks,1U << g_sbi.blkszbits, g_sbi.inos |0ULL , - incr,erofs_total_metablocks (g_sbi.bmgr), + uuid_str, nblocks |0ULL ,1U << g_sbi.blkszbits, g_sbi.inos |0ULL , + incr,erofs_total_metablocks (g_sbi.bmgr) |0ULL , incr, g_sbi.saved_by_deduplication |0ULL ); }
@@ -1217,10 +1217,10 @@ int main(int argc, char **argv)if (cfg.c_unix_timestamp !=-1 ) { g_sbi.build_time = cfg.c_unix_timestamp; - g_sbi.build_time_nsec =0 ; + g_sbi.fixed_nsec =0 ; }else if (!gettimeofday (&t,NULL )) { g_sbi.build_time = t.tv_sec; - g_sbi.build_time_nsec = t.tv_usec; + g_sbi.fixed_nsec = t.tv_usec; } err = erofs_dev_open(&g_sbi, cfg.c_img_path, O_RDWR |
Signature · 1 line
2.43.5
PATCH v2 7/10 erofs-utils: mkfs: support 48-bit block addressing for unencoded inodes
In reply to Gao XiangAdd an extended option -E48bit to indicate 48-bit block addressing is used. Then, 32-byte inodes is preferred since they have per-inode timestamps too.
--- lib/blobchunk.c | 28 ++++++++++------ lib/inode.c | 88 ++++++++++++++++++++++++++++++++++++++++++------- mkfs/main.c | 27 ++++++++++++--- 3 files changed, 118 insertions(+), 25 deletions(-)
lib/blobchunk.c +18 -10
@@ -141,10 +141,11 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,struct erofs_sb_info *sbi = inode->sbi;erofs_blk_t remaining_blks =BLK_ROUND_UP (sbi, inode->i_size);struct erofs_inode_chunk_index idx = {0 }; +erofs_blk_t extent_end =EROFS_NULL_ADDR , chunkblks;erofs_blk_t extent_start =EROFS_NULL_ADDR ; -erofs_blk_t extent_end, chunkblks;erofs_off_t source_offset;unsigned int dst, src, unit, zeroedlen; +bool _48bit;if (inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES ) unit =sizeof (struct erofs_inode_chunk_index );
@@ -152,36 +153,39 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode, unit =EROFS_BLOCK_MAP_ENTRY_SIZE ; chunkblks =1U << (inode->u.chunkformat &EROFS_CHUNK_FORMAT_BLKBITS_MASK ); + _48bit = inode->u.chunkformat &EROFS_CHUNK_FORMAT_48BIT ;for (dst = src =0 ; dst < inode->extent_isize; src +=sizeof (void *), dst += unit) {struct erofs_blobchunk *chunk; +erofs_blk_t startblk; chunk = *(void **)(inode->chunkindexes + src);if (chunk->blkaddr ==EROFS_NULL_ADDR ) { - idx.startblk_lo = (u32 )EROFS_NULL_ADDR ; + startblk =EROFS_NULL_ADDR ; }else if (chunk->device_id) {DBG_BUGON (!(inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES )); - idx.startblk_lo = chunk->blkaddr; + startblk = chunk->blkaddr; extent_start =EROFS_NULL_ADDR ; }else { - idx.startblk_lo = remapped_base + chunk->blkaddr; + startblk = remapped_base + chunk->blkaddr; } -if (extent_start ==EROFS_NULL_ADDR || - idx.startblk_lo != extent_end) { +if (extent_start ==EROFS_NULL_ADDR || startblk != extent_end) {if (extent_start !=EROFS_NULL_ADDR ) { remaining_blks -= extent_end - extent_start;tarerofs_blocklist_write (extent_start, extent_end - extent_start, source_offset,0 ); } - extent_start = idx.startblk_lo; + extent_start = startblk; source_offset = chunk->sourceoffset; } - extent_end = idx.startblk_lo + chunkblks; + extent_end = startblk + chunkblks; idx.device_id =cpu_to_le16 (chunk->device_id); - idx.startblk_lo =cpu_to_le32 (idx.startblk_lo); + idx.startblk_lo =cpu_to_le32 (startblk); + idx.startblk_hi =cpu_to_le32 (startblk >>32 ); +DBG_BUGON (!_48bit && idx.startblk_hi);if (unit ==EROFS_BLOCK_MAP_ENTRY_SIZE )memcpy (inode->chunkindexes + dst, &idx.startblk_lo, unit);
@@ -189,8 +193,8 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,memcpy (inode->chunkindexes + dst, &idx,sizeof (idx)); } off =roundup (off, unit); - extent_end =min (extent_end, extent_start + remaining_blks);if (extent_start !=EROFS_NULL_ADDR ) { + extent_end =min (extent_end, extent_start + remaining_blks); zeroedlen = inode->i_size & (erofs_blksiz (sbi) -1 );if (zeroedlen) zeroedlen =erofs_blksiz (sbi) - zeroedlen;
@@ -357,6 +361,10 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd, goto err; } +/* FIXME! `chunk->blkaddr` is not the final blkaddr here */ +if (chunk->blkaddr !=EROFS_NULL_ADDR && + chunk->blkaddr >=UINT32_MAX ) + inode->u.chunkformat |=EROFS_CHUNK_FORMAT_48BIT ;if (!erofs_blob_can_merge (sbi, lastch, chunk)) {erofs_update_minextblks (sbi, interval_start, pos, &minextblks);
lib/inode.c +77 -11
174 lines not on this page · raw message
mkfs/main.c +23 -4
@@ -320,6 +320,18 @@ static int erofs_mkfs_feat_set_fragdedupe(bool en, const char *val,return 0 ; } +static int erofs_mkfs_feat_set_48bit (bool en,const char *val, +unsigned int vallen) +{ +if (vallen) +return -EINVAL ; +if (en) +erofs_sb_set_48bit (&g_sbi); +else +erofs_sb_clear_48bit (&g_sbi); +return 0 ; +} + static struct { char *feat; int (*set)(bool en, const char *val, unsigned int len);
@@ -330,6 +342,7 @@ static struct { {"all-fragments", erofs_mkfs_feat_set_all_fragments}, {"dedupe", erofs_mkfs_feat_set_dedupe}, {"fragdedupe", erofs_mkfs_feat_set_fragdedupe}, + {"48bit", erofs_mkfs_feat_set_48bit}, {NULL, NULL}, };
@@ -1196,6 +1209,7 @@ int main(int argc, char **argv)erofs_blk_t nblocks =0 ;struct timeval t;FILE *blklst =NULL ; +s64 mkfs_time =0 ;u32 crc;erofs_init_configure ();
@@ -1215,12 +1229,17 @@ int main(int argc, char **argv)return 1 ; } + g_sbi.fixed_nsec =0 ;if (cfg.c_unix_timestamp !=-1 ) { - g_sbi.build_time = cfg.c_unix_timestamp; - g_sbi.fixed_nsec =0 ; + mkfs_time = cfg.c_unix_timestamp; }else if (!gettimeofday (&t,NULL )) { - g_sbi.build_time = t.tv_sec; - g_sbi.fixed_nsec = t.tv_usec; + mkfs_time = t.tv_sec; + } +if (erofs_sb_has_48bit (&g_sbi)) { + g_sbi.epoch =max_t (s64,0 , mkfs_time -UINT32_MAX ); + g_sbi.build_time = mkfs_time - g_sbi.epoch; + }else { + g_sbi.epoch = mkfs_time; } err = erofs_dev_open(&g_sbi, cfg.c_img_path, O_RDWR |
Signature · 1 line
2.43.5
PATCH v3 7/10 erofs-utils: mkfs: support 48-bit block addressing for unencoded inodes
Add an extended option -E48bit to indicate 48-bit block addressing is used. Then, 32-byte inodes is preferred since they have per-inode timestamps too.
--- lib/blobchunk.c | 31 +++++++++++------ lib/inode.c | 88 ++++++++++++++++++++++++++++++++++++++++++------- mkfs/main.c | 27 ++++++++++++--- 3 files changed, 121 insertions(+), 25 deletions(-)
lib/blobchunk.c +21 -10
@@ -141,10 +141,11 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,struct erofs_sb_info *sbi = inode->sbi;erofs_blk_t remaining_blks =BLK_ROUND_UP (sbi, inode->i_size);struct erofs_inode_chunk_index idx = {0 }; +erofs_blk_t extent_end =EROFS_NULL_ADDR , chunkblks, addrmask;erofs_blk_t extent_start =EROFS_NULL_ADDR ; -erofs_blk_t extent_end, chunkblks;erofs_off_t source_offset;unsigned int dst, src, unit, zeroedlen; +bool _48bit;if (inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES ) unit =sizeof (struct erofs_inode_chunk_index );
@@ -152,36 +153,42 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode, unit =EROFS_BLOCK_MAP_ENTRY_SIZE ; chunkblks =1U << (inode->u.chunkformat &EROFS_CHUNK_FORMAT_BLKBITS_MASK ); + _48bit = inode->u.chunkformat &EROFS_CHUNK_FORMAT_48BIT ;for (dst = src =0 ; dst < inode->extent_isize; src +=sizeof (void *), dst += unit) {struct erofs_blobchunk *chunk; +erofs_blk_t startblk; chunk = *(void **)(inode->chunkindexes + src);if (chunk->blkaddr ==EROFS_NULL_ADDR ) { - idx.startblk_lo = (u32 )EROFS_NULL_ADDR ; + startblk =EROFS_NULL_ADDR ; }else if (chunk->device_id) {DBG_BUGON (!(inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES )); - idx.startblk_lo = chunk->blkaddr; + startblk = chunk->blkaddr; extent_start =EROFS_NULL_ADDR ; }else { - idx.startblk_lo = remapped_base + chunk->blkaddr; + startblk = remapped_base + chunk->blkaddr; } -if (extent_start ==EROFS_NULL_ADDR || - idx.startblk_lo != extent_end) { +if (extent_start ==EROFS_NULL_ADDR || startblk != extent_end) {if (extent_start !=EROFS_NULL_ADDR ) { remaining_blks -= extent_end - extent_start;tarerofs_blocklist_write (extent_start, extent_end - extent_start, source_offset,0 ); } - extent_start = idx.startblk_lo; + extent_start = startblk; source_offset = chunk->sourceoffset; } - extent_end = idx.startblk_lo + chunkblks; + extent_end = startblk + chunkblks; + + addrmask = _48bit ?BIT_ULL (48 ) -1 :BIT_ULL (32 ) -1 ; + startblk &= addrmask; idx.device_id =cpu_to_le16 (chunk->device_id); - idx.startblk_lo =cpu_to_le32 (idx.startblk_lo); + idx.startblk_lo =cpu_to_le32 (startblk); + idx.startblk_hi =cpu_to_le32 (startblk >>32 ); +DBG_BUGON (!_48bit && idx.startblk_hi);if (unit ==EROFS_BLOCK_MAP_ENTRY_SIZE )memcpy (inode->chunkindexes + dst, &idx.startblk_lo, unit);
@@ -189,8 +196,8 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,memcpy (inode->chunkindexes + dst, &idx,sizeof (idx)); } off =roundup (off, unit); - extent_end =min (extent_end, extent_start + remaining_blks);if (extent_start !=EROFS_NULL_ADDR ) { + extent_end =min (extent_end, extent_start + remaining_blks); zeroedlen = inode->i_size & (erofs_blksiz (sbi) -1 );if (zeroedlen) zeroedlen =erofs_blksiz (sbi) - zeroedlen;
@@ -357,6 +364,10 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd, goto err; } +/* FIXME! `chunk->blkaddr` is not the final blkaddr here */ +if (chunk->blkaddr !=EROFS_NULL_ADDR && + chunk->blkaddr >=UINT32_MAX ) + inode->u.chunkformat |=EROFS_CHUNK_FORMAT_48BIT ;if (!erofs_blob_can_merge (sbi, lastch, chunk)) {erofs_update_minextblks (sbi, interval_start, pos, &minextblks);
lib/inode.c +77 -11
174 lines not on this page · raw message
mkfs/main.c +23 -4
@@ -320,6 +320,18 @@ static int erofs_mkfs_feat_set_fragdedupe(bool en, const char *val,return 0 ; } +static int erofs_mkfs_feat_set_48bit (bool en,const char *val, +unsigned int vallen) +{ +if (vallen) +return -EINVAL ; +if (en) +erofs_sb_set_48bit (&g_sbi); +else +erofs_sb_clear_48bit (&g_sbi); +return 0 ; +} + static struct { char *feat; int (*set)(bool en, const char *val, unsigned int len);
@@ -330,6 +342,7 @@ static struct { {"all-fragments", erofs_mkfs_feat_set_all_fragments}, {"dedupe", erofs_mkfs_feat_set_dedupe}, {"fragdedupe", erofs_mkfs_feat_set_fragdedupe}, + {"48bit", erofs_mkfs_feat_set_48bit}, {NULL, NULL}, };
@@ -1196,6 +1209,7 @@ int main(int argc, char **argv)erofs_blk_t nblocks =0 ;struct timeval t;FILE *blklst =NULL ; +s64 mkfs_time =0 ;u32 crc;erofs_init_configure ();
@@ -1215,12 +1229,17 @@ int main(int argc, char **argv)return 1 ; } + g_sbi.fixed_nsec =0 ;if (cfg.c_unix_timestamp !=-1 ) { - g_sbi.build_time = cfg.c_unix_timestamp; - g_sbi.fixed_nsec =0 ; + mkfs_time = cfg.c_unix_timestamp; }else if (!gettimeofday (&t,NULL )) { - g_sbi.build_time = t.tv_sec; - g_sbi.fixed_nsec = t.tv_usec; + mkfs_time = t.tv_sec; + } +if (erofs_sb_has_48bit (&g_sbi)) { + g_sbi.epoch =max_t (s64,0 , mkfs_time -UINT32_MAX ); + g_sbi.build_time = mkfs_time - g_sbi.epoch; + }else { + g_sbi.epoch = mkfs_time; } err = erofs_dev_open(&g_sbi, cfg.c_img_path, O_RDWR |
Signature · 1 line
2.43.5
PATCH v2 8/10 erofs-utils: support dot-omitted directories
In reply to Gao XiangOmit the dot dirent by default if 48bit layout is set.
--- include/erofs/config.h | 1 + include/erofs/internal.h | 1 + lib/dir.c | 2 ++ lib/inode.c | 35 +++++++++++++++++++++++++---------- lib/namei.c | 3 ++- mkfs/main.c | 14 ++++++++++++++ 6 files changed, 45 insertions(+), 11 deletions(-)
include/erofs/config.h +1 -0
@@ -66,6 +66,7 @@ struct erofs_configure {bool c_xattr_name_filter;bool c_ovlfs_strip;bool c_hard_dereference; +bool c_dot_omitted;#ifdef HAVE_LIBSELINUX struct selabel_handle *sehnd;
include/erofs/internal.h +1 -0
@@ -239,6 +239,7 @@ struct erofs_inode {bool opaque;/* OVL: non-merge dir that may contain whiteout entries */ bool whiteouts; +bool dot_omitted;unsigned int xattr_isize;unsigned int extent_isize;
lib/dir.c +2 -0
@@ -150,6 +150,8 @@ int erofs_iterate_dir(struct erofs_dir_context *ctx, bool fsck)return -ENOTDIR ; ctx->flags &= ~EROFS_READDIR_ALL_SPECIAL_FOUND ; +if (dir->dot_omitted) + ctx->flags |=EROFS_READDIR_DOT_FOUND ; pos =0 ;while (pos < dir->i_size) {erofs_blk_t lblk =erofs_blknr (sbi, pos);
lib/inode.c +25 -10
@@ -253,21 +253,29 @@ static int erofs_prepare_dir_file(struct erofs_inode *dir, {struct erofs_sb_info *sbi = dir->sbi;struct erofs_dentry *d, *n, **sorted_d; +bool dot_omitted = cfg.c_dot_omitted;unsigned int i;unsigned int d_size =0 ; sorted_d =malloc (nr_subdirs *sizeof (d));if (!sorted_d)return -ENOMEM ; + + dir->dot_omitted = dot_omitted; i =0 ;list_for_each_entry_safe (d, n, &dir->i_subdirs, d_child) {list_del (&d->d_child); +if (dot_omitted && !strcmp (d->name,"." )) { +erofs_iput (d->inode); +free (d); +continue ; + } sorted_d[i++] = d; } -DBG_BUGON (i != nr_subdirs); -qsort (sorted_d, nr_subdirs,sizeof (d), comp_subdir); -for (i =0 ; i < nr_subdirs; i++) -list_add_tail (&sorted_d[i]->d_child, &dir->i_subdirs); +DBG_BUGON (i + dot_omitted != nr_subdirs); +qsort (sorted_d, i,sizeof (d), comp_subdir); +while (i) +list_add (&sorted_d[--i]->d_child, &dir->i_subdirs);free (sorted_d);/* let's calculate dir size */
@@ -640,10 +648,12 @@ int erofs_iflush(struct erofs_inode *inode) nlink_1 = false; nb = (union erofs_inode_i_nb ){}; } + fmt =S_ISDIR (inode->i_mode) && inode->dot_omitted ? +1 <<EROFS_I_DOT_OMITTED_BIT :0 ;switch (inode->inode_isize) {case sizeof (struct erofs_inode_compact ): - fmt =0 | (inode->datalayout <<1 ); + fmt |=0 | (inode->datalayout <<1 ); u.dic.i_xattr_icount =cpu_to_le16 (icount); u.dic.i_mode =cpu_to_le16 (inode->i_mode); u.dic.i_nb.nlink =cpu_to_le16 (inode->i_nlink);
@@ -668,7 +678,8 @@ int erofs_iflush(struct erofs_inode *inode) u.dic.i_format =cpu_to_le16 (fmt);break ;case sizeof (struct erofs_inode_extended ): - u.die.i_format =cpu_to_le16 (1 | (inode->datalayout <<1 )); + fmt |=1 | (inode->datalayout <<1 ); + u.die.i_format =cpu_to_le16 (fmt); u.die.i_xattr_icount =cpu_to_le16 (icount); u.die.i_mode =cpu_to_le16 (inode->i_mode); u.die.i_nlink =cpu_to_le32 (inode->i_nlink);
@@ -1538,13 +1549,17 @@ static int erofs_mkfs_handle_directory(struct erofs_inode *dir)/* * if there're too many subdirs as compact form, set nlink=1 -* rather than upgrade to use extented form instead. +* rather than upgrade to use extented form instead if possible. */ if (i_nlink >USHRT_MAX && - dir->inode_isize ==sizeof (struct erofs_inode_compact )) - dir->i_nlink =1 ; -else + dir->inode_isize ==sizeof (struct erofs_inode_compact )) { +if (dir->dot_omitted) + dir->inode_isize =sizeof (struct erofs_inode_extended ); +else + dir->i_nlink =1 ; + }else { dir->i_nlink = i_nlink; + }return erofs_mkfs_go (sbi,EROFS_MKFS_JOB_DIR , &dir,sizeof (dir));
lib/namei.c +2 -1
@@ -100,8 +100,9 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi) }switch (vi->i_mode &S_IFMT ) { -case S_IFREG :case S_IFDIR : + vi->dot_omitted = (ifmt >>EROFS_I_DOT_OMITTED_BIT ) &1 ; +case S_IFREG :case S_IFLNK : vi->u.i_blkaddr =le32_to_cpu (copied.i_u.startblk_lo) | ((u64 )le16_to_cpu (copied.i_nb.startblk_hi) <<32 );
mkfs/main.c +14 -0
@@ -332,6 +332,16 @@ static int erofs_mkfs_feat_set_48bit(bool en, const char *val,return 0 ; } +static int erofs_mkfs_feat_set_dot_omitted (bool en,const char *val, +unsigned int vallen) +{ +if (vallen) +return -EINVAL ; + + cfg.c_dot_omitted = en; +return 0 ; +} + static struct { char *feat; int (*set)(bool en, const char *val, unsigned int len);
@@ -343,6 +353,7 @@ static struct { {"dedupe", erofs_mkfs_feat_set_dedupe}, {"fragdedupe", erofs_mkfs_feat_set_fragdedupe}, {"48bit", erofs_mkfs_feat_set_48bit}, + {"dot-omitted", erofs_mkfs_feat_set_dot_omitted}, {NULL, NULL}, };
@@ -1242,6 +1253,9 @@ int main(int argc, char **argv) g_sbi.epoch = mkfs_time; } +if (cfg.c_dot_omitted) +erofs_sb_set_48bit (&g_sbi); + err =erofs_dev_open (&g_sbi, cfg.c_img_path,O_RDWR | (incremental_mode ?0 :O_TRUNC ));if (err) {
Signature · 1 line
2.43.5
PATCH v2 9/10 erofs-utils: lib: implement encoded extent metadata
In reply to Gao XiangSource kernel commit: efb2aef569b35b415c232c4e9fdecd0e540e1f60 Source kernel commit: 1d191b4ca51d73699cb127386b95ac152af2b930
--- fsck/main.c | 2 +- include/erofs/internal.h | 3 +- lib/compress.c | 14 +-- lib/zmap.c | 178 ++++++++++++++++++++++++++++++++++----- 4 files changed, 166 insertions(+), 31 deletions(-)
fsck/main.c +1 -1
@@ -572,7 +572,7 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd) }if (map.m_plen >Z_EROFS_PCLUSTER_MAX_SIZE ) { -if (compressed) { +if (compressed && !(map.m_flags &EROFS_MAP_FRAGMENT )) {erofs_err ("invalid pcluster size %" PRIu64" @ offset %" PRIu64" of nid %" PRIu64, map.m_plen, map.m_la, inode->nid |0ULL );
include/erofs/internal.h +2 -1
@@ -262,11 +262,12 @@ struct erofs_inode {struct {uint16_t z_advise;uint8_t z_algorithmtype[2 ]; -uint8_t z_logical_clusterbits; +uint8_t z_lclusterbits;uint8_t z_physical_clusterblks;union {uint64_t z_tailextent_headlcn;erofs_off_t fragment_size; +u64 z_extents; };union {erofs_off_t fragmentoff;
lib/compress.c +7 -7
@@ -272,7 +272,7 @@ static void z_erofs_commit_extent(struct z_erofs_compress_sctx *ctx,static int z_erofs_compress_dedupe (struct z_erofs_compress_sctx *ctx) {struct erofs_inode *inode = ctx->ictx->inode; -const unsigned int lclustermask = (1 << inode->z_logical_clusterbits) -1 ; +const unsigned int lclustermask = (1 << inode->z_lclusterbits) -1 ;struct erofs_sb_info *sbi = inode->sbi;struct z_erofs_extent_item *ei = ctx->pivot;
@@ -405,7 +405,7 @@ static int write_uncompressed_extents(struct z_erofs_compress_sctx *ctx, char *dst) {struct erofs_inode *inode = ctx->ictx->inode; -unsigned int lclustersize =1 << inode->z_logical_clusterbits; +unsigned int lclustersize =1 << inode->z_lclusterbits;struct z_erofs_extent_item *ei;int count;
@@ -875,7 +875,7 @@ int z_erofs_convert_to_compacted_format(struct erofs_inode *inode,const unsigned int totalidx = (legacymetasize -Z_EROFS_LEGACY_MAP_HEADER_SIZE ) /sizeof (struct z_erofs_lcluster_index ); -const unsigned int logical_clusterbits = inode->z_logical_clusterbits; +const unsigned int logical_clusterbits = inode->z_lclusterbits;u8 *out, *in;struct z_erofs_compressindex_vec cv[16 ];struct erofs_sb_info *sbi = inode->sbi;
@@ -984,7 +984,7 @@ static void z_erofs_write_mapheader(struct erofs_inode *inode, .h_algorithmtype = inode->z_algorithmtype[1] << 4 | inode->z_algorithmtype[0], /* lclustersize */ - .h_clusterbits = inode->z_logical_clusterbits - sbi->blkszbits, + .h_clusterbits = inode->z_lclusterbits - sbi->blkszbits, };if (inode->z_advise &Z_EROFS_ADVISE_FRAGMENT_PCLUSTER )
@@ -1011,8 +1011,8 @@ static void *z_erofs_write_indexes(struct z_erofs_compress_ictx *ctx)if (inode->fragment_size && inode->fragmentoff >>32 ) { inode->datalayout =EROFS_INODE_COMPRESSED_FULL ; }else if (!cfg.c_legacy_compress && !ctx->dedupe && - inode->z_logical_clusterbits <=14 ) { -if (inode->z_logical_clusterbits <=12 ) + inode->z_lclusterbits <=14 ) { +if (inode->z_lclusterbits <=12 ) inode->z_advise |=Z_EROFS_ADVISE_COMPACTED_2B ; inode->datalayout =EROFS_INODE_COMPRESSED_COMPACT ; }else {
@@ -1584,7 +1584,7 @@ void *erofs_begin_compressed_file(struct erofs_inode *inode, int fd, u64 fpos)/* initialize per-file compression setting */ inode->z_advise =0 ; - inode->z_logical_clusterbits = sbi->blkszbits; + inode->z_lclusterbits = sbi->blkszbits;if (cfg.c_fragments && !cfg.c_dedupe) inode->z_advise |=Z_EROFS_ADVISE_INTERLACED_PCLUSTER ;
lib/zmap.c +156 -22
273 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH v2 10/10 erofs-utils: support encoded extents
In reply to Gao XiangUse encoded extents if 48bit is set and metadata is smaller for big pclusters.
For Zstd and libdeflate, since they don't natively support fixed-size output compression, switch to use fixed-size input compression if --max-extent-bytes= is specified and no more than -C. Later we will introduce a simpilified option for users too.
--- include/erofs/internal.h | 2 +- include/erofs_fs.h | 3 +- lib/compress.c | 224 +++++++++++++++++++++++++++++------- lib/compressor.c | 11 ++ lib/compressor.h | 6 + lib/compressor_libdeflate.c | 18 +++ lib/compressor_libzstd.c | 18 +++ 7 files changed, 237 insertions(+), 45 deletions(-)
include/erofs/internal.h +1 -1
@@ -267,12 +267,12 @@ struct erofs_inode {union {uint64_t z_tailextent_headlcn;erofs_off_t fragment_size; -u64 z_extents; };union {erofs_off_t fragmentoff;erofs_off_t z_fragmentoff; }; +u64 z_extents;#define z_idata_size idata_size }; };
include/erofs_fs.h +2 -1
@@ -413,8 +413,9 @@ struct z_erofs_lcluster_index { } di_u; }; +#define Z_EROFS_MAP_HEADER_START (end) round_up(end, 8)#define Z_EROFS_MAP_HEADER_END (end) \ - (round_up(end, 8) + sizeof(struct z_erofs_map_header)) + (Z_EROFS_MAP_HEADER_START(end) + sizeof(struct z_erofs_map_header))#define Z_EROFS_FULL_INDEX_START (end) (Z_EROFS_MAP_HEADER_END(end) + 8)#define Z_EROFS_EXTENT_PLEN_PARTIAL BIT(27)
lib/compress.c +181 -43
356 lines not on this page · raw message
lib/compressor.c +11 -0
@@ -85,6 +85,17 @@ int erofs_compress_destsize(const struct erofs_compress *c,return c->alg->c->compress_destsize (c, src, srcsize, dst, dstsize); } +int erofs_compress (const struct erofs_compress *c, +const void *src,unsigned int srcsize, +void *dst,unsigned int dstcapacity) +{ +DBG_BUGON (!c->alg); +if (!c->alg->c->compress) +return -EOPNOTSUPP ; + +return c->alg->c->compress (c, src, srcsize, dst, dstcapacity); +} +int erofs_compressor_init (struct erofs_sb_info *sbi,struct erofs_compress *c,char *alg_name,int compression_level,u32 dict_size) {
lib/compressor.h +6 -0
@@ -26,6 +26,9 @@ struct erofs_compressor {int (*compress_destsize)(const struct erofs_compress *c,const void *src,unsigned int *srcsize,void *dst,unsigned int dstsize); +int (*compress)(const struct erofs_compress *c, +const void *src,unsigned int srcsize, +void *dst,unsigned int dstcapacity); };struct erofs_algorithm {
@@ -60,6 +63,9 @@ int z_erofs_get_compress_algorithm_id(const struct erofs_compress *c);int erofs_compress_destsize (const struct erofs_compress *c,const void *src,unsigned int *srcsize,void *dst,unsigned int dstsize); +int erofs_compress (const struct erofs_compress *c, +const void *src,unsigned int srcsize, +void *dst,unsigned int dstcapacity);int erofs_compressor_init (struct erofs_sb_info *sbi,struct erofs_compress *c,char *alg_name,int compression_level,u32 dict_size);
lib/compressor_libdeflate.c +18 -0
@@ -12,6 +12,23 @@ struct erofs_libdeflate_context {size_t last_uncompressed_size; }; +static int libdeflate_compress (const struct erofs_compress *c, +const void *src,unsigned int srcsize, +void *dst,unsigned int dstcapacity) +{ +struct erofs_libdeflate_context *ctx = c->private_data; +size_t csize; + + csize =libdeflate_deflate_compress (ctx->strm, src, srcsize, + dst, dstcapacity); +if (!csize) +return -ENOSPC ; +/* See the comment in libdeflate_compress_destsize() */ +if (!((u8 *)dst)[0 ]) + ((u8 *)dst)[0 ] =1 << (2 +1 ); +return csize; +} +static int libdeflate_compress_destsize (const struct erofs_compress *c,const void *src,unsigned int *srcsize,void *dst,unsigned int dstsize)
@@ -137,5 +154,6 @@ const struct erofs_compressor erofs_compressor_libdeflate = { .exit = compressor_libdeflate_exit, .reset = compressor_libdeflate_reset, .setlevel = erofs_compressor_libdeflate_setlevel, + .compress = libdeflate_compress, .compress_destsize = libdeflate_compress_destsize, };
lib/compressor_libzstd.c +18 -0
@@ -8,6 +8,23 @@#include "compressor.h" #include "erofs/atomic.h" +static int libzstd_compress (const struct erofs_compress *c, +const void *src,unsigned int srcsize, +void *dst,unsigned int dstcapacity) +{ +ZSTD_CCtx *cctx = c->private_data; +size_t csize; + + csize =ZSTD_compress2 (cctx, dst, dstcapacity, src, srcsize); +if (ZSTD_isError (csize)) { +if (ZSTD_getErrorCode (csize) == ZSTD_error_dstSize_tooSmall) +return -ENOSPC ; +erofs_err ("Zstd compress failed: %s" ,ZSTD_getErrorName (csize)); +return -EFAULT ; + } +return csize; +} +static int libzstd_compress_destsize (const struct erofs_compress *c,const void *src,unsigned int *srcsize,void *dst,unsigned int dstsize)
@@ -139,5 +156,6 @@ const struct erofs_compressor erofs_compressor_libzstd = { .exit = compressor_libzstd_exit, .setlevel = erofs_compressor_libzstd_setlevel, .setdictsize = erofs_compressor_libzstd_setdictsize, + .compress = libzstd_compress, .compress_destsize = libzstd_compress_destsize, };
Signature · 1 line
2.43.5