erofs-utils: lib: move buffer allocation into z_erofs_write_indexes()
Subsystems (2)
PATCH v2 1/8 erofs-utils: lib: move buffer allocation into z_erofs_write_indexes()
Just used to prepare for extent-based metadata. No logic changes.
---
no change.
lib/compress.c | 52 ++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 23 deletions(-)
lib/compress.c +29 -23
@@ -120,7 +120,7 @@ static bool z_erofs_mt_enabled;#define Z_EROFS_LEGACY_MAP_HEADER_SIZE Z_EROFS_FULL_INDEX_ALIGN(0) -static void z_erofs_write_indexes_final (struct z_erofs_compress_ictx *ctx) +static void z_erofs_fini_full_indexes (struct z_erofs_compress_ictx *ctx) {const unsigned int type =Z_EROFS_LCLUSTER_TYPE_PLAIN ;struct z_erofs_lcluster_index di;
@@ -136,8 +136,8 @@ static void z_erofs_write_indexes_final(struct z_erofs_compress_ictx *ctx) ctx->metacur +=sizeof (di); } -static void z_erofs_write_extent (struct z_erofs_compress_ictx *ctx, -struct z_erofs_inmem_extent *e) +static void z_erofs_write_full_indexes (struct z_erofs_compress_ictx *ctx, +struct z_erofs_inmem_extent *e) {struct erofs_inode *inode = ctx->inode;struct erofs_sb_info *sbi = inode->sbi;
@@ -233,20 +233,6 @@ static void z_erofs_write_extent(struct z_erofs_compress_ictx *ctx, ctx->clusterofs = clusterofs + count; } -static void z_erofs_write_indexes (struct z_erofs_compress_ictx *ctx) -{ -struct z_erofs_extent_item *ei, *n; - - ctx->clusterofs =0 ; -list_for_each_entry_safe (ei, n, &ctx->extents, list) { -z_erofs_write_extent (ctx, &ei->e); - -list_del (&ei->list); -free (ei); - } -z_erofs_write_indexes_final (ctx); -} -static bool z_erofs_need_refill (struct z_erofs_compress_sctx *ctx) {const bool final = !ctx->remaining;
@@ -1006,6 +992,31 @@ static void z_erofs_write_mapheader(struct erofs_inode *inode,memcpy (compressmeta, &h,sizeof (struct z_erofs_map_header )); } +static void *z_erofs_write_indexes (struct z_erofs_compress_ictx *ctx) +{ +struct erofs_inode *inode = ctx->inode; +struct z_erofs_extent_item *ei, *n; +void *metabuf; + + metabuf =malloc (BLK_ROUND_UP (inode->sbi, inode->i_size) * +sizeof (struct z_erofs_lcluster_index ) + +Z_EROFS_LEGACY_MAP_HEADER_SIZE ); +if (!metabuf) +return ERR_PTR (-ENOMEM ); + + ctx->metacur = metabuf +Z_EROFS_LEGACY_MAP_HEADER_SIZE ; + ctx->clusterofs =0 ; +list_for_each_entry_safe (ei, n, &ctx->extents, list) { +z_erofs_write_full_indexes (ctx, &ei->e); + +list_del (&ei->list); +free (ei); + } +z_erofs_fini_full_indexes (ctx); +z_erofs_write_mapheader (inode, metabuf); +return metabuf; +} +void z_erofs_drop_inline_pcluster (struct erofs_inode *inode) {struct erofs_sb_info *sbi = inode->sbi;
@@ -1126,15 +1137,11 @@ int erofs_commit_compressed_file(struct z_erofs_compress_ictx *ictx,DBG_BUGON (compressed_blocks < !!inode->idata_size); compressed_blocks -= !!inode->idata_size; - compressmeta =malloc (BLK_ROUND_UP (sbi, inode->i_size) * -sizeof (struct z_erofs_lcluster_index ) + -Z_EROFS_LEGACY_MAP_HEADER_SIZE ); + compressmeta =z_erofs_write_indexes (ictx);if (!compressmeta) { ret = -ENOMEM ; goto err_free_idata; } - ictx->metacur = compressmeta +Z_EROFS_LEGACY_MAP_HEADER_SIZE ; -z_erofs_write_indexes (ictx); legacymetasize = ictx->metacur - compressmeta;/* estimate if data compression saves space or not */
@@ -1146,7 +1153,6 @@ int erofs_commit_compressed_file(struct z_erofs_compress_ictx *ictx, goto err_free_meta; }z_erofs_dedupe_commit (false); -z_erofs_write_mapheader (inode, compressmeta);if (!ictx->fragemitted) sbi->saved_by_deduplication += inode->fragment_size;
Signature · 1 line
2.43.5
PATCH v2 2/8 erofs-utils: get rid of NULL_ADDR{,_UL}
.. And replace them with EROFS_NULL_ADDR.
---
no change.
include/erofs/cache.h | 4 ++-- include/erofs/internal.h | 3 --- lib/block_list.c | 4 ++-- lib/cache.c | 24 ++++++++++++------------ lib/inode.c | 4 ++-- lib/rebuild.c | 2 +- 6 files changed, 19 insertions(+), 22 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/block_list.c +2 -2
@@ -111,13 +111,13 @@ void erofs_droid_blocklist_write_tail_end(struct erofs_inode *inode,/* XXX: another hack, which means it has been outputed before */ if (erofs_blknr (inode->sbi, inode->i_size)) { -if (blkaddr ==NULL_ADDR ) +if (blkaddr ==EROFS_NULL_ADDR )fprintf (block_list_fp,"\n" );else fprintf (block_list_fp," %u\n" , blkaddr);return ; } -if (blkaddr !=NULL_ADDR ) +if (blkaddr !=EROFS_NULL_ADDR ) blocklist_write(inode->i_srcpath, blkaddr, 1, true, true); }#endif
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 +2 -2
@@ -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 ; }
@@ -844,7 +844,7 @@ static int erofs_write_tail_end(struct erofs_inode *inode) ibh->fsprivate =erofs_igrab (inode); ibh->op = &erofs_write_inline_bhops; -erofs_droid_blocklist_write_tail_end (inode,NULL_ADDR ); +erofs_droid_blocklist_write_tail_end (inode,EROFS_NULL_ADDR ); }else {int ret;erofs_off_t pos, zero_pos;
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 3/8 erofs-utils: lib: sync up with the 48-bit kernel erofs_fs.h
In reply to Gao XiangKeep in sync with related kernel commit.
---
no change.
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
@@ -160,17 +160,17 @@ 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,
@@ -182,15 +182,15 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode, first_extent, false); first_extent = false; } - 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)); }
@@ -513,8 +513,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
@@ -118,7 +118,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
@@ -604,18 +604,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 4/8 erofs-utils: implement 48-bit block addressing for unencoded inodes
In reply to Gao XiangPort the same kernel logic to erofsfuse and dump.erofs.
---
v2: new patch
dump/main.c | 1 + include/erofs/internal.h | 21 +++--- lib/block_list.c | 16 ++--- lib/data.c | 143 +++++++++++++++------------------------ lib/inode.c | 6 +- lib/namei.c | 35 +++++++--- lib/super.c | 14 +++- mkfs/main.c | 12 ++-- 8 files changed, 119 insertions(+), 129 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 )
@@ -211,8 +212,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;
lib/block_list.c +8 -8
@@ -38,11 +38,11 @@ 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); }#ifdef WITH_ANDROID
@@ -62,10 +62,10 @@ static void blocklist_write(const char *path, erofs_blk_t blk_start, }if (nblocks ==1 ) -fprintf (block_list_fp," %u" , blk_start); +fprintf (block_list_fp," %llu" , blk_start |0ULL );else -fprintf (block_list_fp," %u-%u" , blk_start, - blk_start + nblocks -1 ); +fprintf (block_list_fp," %llu-%llu" , blk_start |0ULL , + (blk_start + nblocks -1 ) |0ULL );if (last_extent)fprintf (block_list_fp,"\n" );
@@ -114,7 +114,7 @@ void erofs_droid_blocklist_write_tail_end(struct erofs_inode *inode,if (blkaddr ==EROFS_NULL_ADDR )fprintf (block_list_fp,"\n" );else -fprintf (block_list_fp," %u\n" , blkaddr); +fprintf (block_list_fp," %llu\n" , blkaddr |0ULL );return ; }if (blkaddr !=EROFS_NULL_ADDR )
lib/data.c +55 -88
173 lines not on this page · raw message
lib/inode.c +3 -3
@@ -930,7 +930,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;
@@ -1030,7 +1030,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 ; }
@@ -1998,7 +1998,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
@@ -1184,12 +1184,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 ); }
@@ -1222,10 +1222,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 5/8 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.
---
v2:
- fix chunk-based inode support.
lib/blobchunk.c | 27 ++++++++------- lib/inode.c | 88 ++++++++++++++++++++++++++++++++++++++++++------- mkfs/main.c | 27 ++++++++++++--- 3 files changed, 116 insertions(+), 26 deletions(-)
lib/blobchunk.c +16 -11
@@ -141,11 +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 first_extent = true; +bool _48bit, first_extent = true;if (inode->u.chunkformat &EROFS_CHUNK_FORMAT_INDEXES ) unit =sizeof (struct erofs_inode_chunk_index );
@@ -153,24 +153,25 @@ 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 =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,
@@ -182,12 +183,14 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode, first_extent, false); first_extent = false; } - 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);
@@ -195,8 +198,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;
@@ -368,6 +371,8 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd, goto err; } +if (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
@@ -322,6 +322,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);
@@ -332,6 +344,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}, };
@@ -1201,6 +1214,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 ();
@@ -1220,12 +1234,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 6/8 erofs-utils: support dot-omitted directories
In reply to Gao XiangOmit the dot dirent by default if 48bit layout is set.
---
no change.
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
@@ -236,6 +236,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 */
@@ -641,10 +649,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);
@@ -669,7 +679,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);
@@ -1543,13 +1554,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
@@ -334,6 +334,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);
@@ -345,6 +355,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}, };
@@ -1247,6 +1258,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 7/8 erofs-utils: lib: use compressed offsets in `struct z_erofs_inmem_extent`
In reply to Gao Xiang... to prepare for the new on-disk encoded extents.
---
no change.
include/erofs/dedupe.h | 4 +- lib/compress.c | 164 +++++++++++++++++++++-------------------- lib/dedupe.c | 12 +-- 3 files changed, 91 insertions(+), 89 deletions(-)
include/erofs/dedupe.h +2 -2
@@ -13,8 +13,8 @@ extern "C"#include "internal.h" struct z_erofs_inmem_extent { -erofs_blk_t blkaddr; -unsigned int compressedblks; +erofs_off_t pstart; +unsigned int plen;unsigned int length;bool raw, partial, inlined; };
lib/compress.c +83 -81
438 lines not on this page · raw message
lib/dedupe.c +6 -6
@@ -71,8 +71,8 @@ struct z_erofs_dedupe_item {long long hash;u64 prefix_xxh64; -erofs_blk_t compressed_blkaddr; -unsigned int compressed_blks; +erofs_off_t pstart; +unsigned int plen;int original_length;bool partial, raw;
@@ -139,8 +139,8 @@ int z_erofs_dedupe_match(struct z_erofs_dedupe_ctx *ctx) (window_size + extra < e->original_length); ctx->e.raw = e->raw; ctx->e.inlined = false; - ctx->e.blkaddr = e->compressed_blkaddr; - ctx->e.compressedblks = e->compressed_blks; + ctx->e.pstart = e->pstart; + ctx->e.plen = e->plen;return 0 ; }return -ENOENT ;
@@ -165,8 +165,8 @@ int z_erofs_dedupe_insert(struct z_erofs_inmem_extent *e, di->hash =erofs_rolling_hash_init (original_data, window_size, true);memcpy (di->payload, original_data, e->length); - di->compressed_blkaddr = e->blkaddr; - di->compressed_blks = e->compressedblks; + di->pstart = e->pstart; + di->plen = e->plen; di->partial = e->partial; di->raw = e->raw;
Signature · 1 line
2.43.5
PATCH v2 8/8 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, since it doesn't natively support fixed-sized output compression, switch to use fixed-sized input compression if --max-extent-bytes= is specified and no more than -C. Later we might introduce a simpilified option for users too.
---
no change.
include/erofs/internal.h | 1 + include/erofs_fs.h | 3 +- lib/compress.c | 257 ++++++++++++++++++++++++++++++--------- lib/compressor.c | 11 ++ lib/compressor.h | 6 + lib/compressor_libzstd.c | 17 +++ 6 files changed, 235 insertions(+), 60 deletions(-)
include/erofs/internal.h +1 -0
@@ -269,6 +269,7 @@ struct erofs_inode {unsigned int z_idataoff;erofs_off_t fragmentoff; }; +unsigned int 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 +198 -59
389 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 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_libzstd.c +17 -0
@@ -8,6 +8,22 @@#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 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 ; +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 +155,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