erofs-utils: simplify erofs_insert_ihash
PATCH 1/9 erofs-utils: simplify erofs_insert_ihash
Get rid of unnecessary arguments for simplicity.
--- include/erofs/inode.h | 2 +- lib/inode.c | 16 +++++++--------- lib/rebuild.c | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-)
include/erofs/inode.h +1 -1
@@ -26,7 +26,7 @@ unsigned char erofs_mode_to_ftype(umode_t mode);umode_t erofs_ftype_to_mode (unsigned int ftype,unsigned int perm);unsigned char erofs_ftype_to_dtype (unsigned int filetype);void erofs_inode_manager_init (void ); -void erofs_insert_ihash (struct erofs_inode *inode,dev_t dev,ino_t ino); +void erofs_insert_ihash (struct erofs_inode *inode);struct erofs_inode *erofs_iget (dev_t dev,ino_t ino);struct erofs_inode *erofs_iget_by_nid (erofs_nid_t nid);unsigned int erofs_iput (struct erofs_inode *inode);
lib/inode.c +7 -9
@@ -94,10 +94,11 @@ void erofs_inode_manager_init(void)init_list_head (&inode_hashtable[i]); } -void erofs_insert_ihash (struct erofs_inode *inode,dev_t dev,ino_t ino) +void erofs_insert_ihash (struct erofs_inode *inode) { -list_add (&inode->i_hash, - &inode_hashtable[(ino ^ dev) %NR_INODE_HASHTABLE ]); +unsigned int nr = (inode->i_ino[1 ] ^ inode->dev) %NR_INODE_HASHTABLE ; + +list_add (&inode->i_hash, &inode_hashtable[nr]); }/* get the inode from the (source) inode # */
@@ -991,11 +992,6 @@ static int erofs_fill_inode(struct erofs_inode *inode, struct stat *st,if (!inode->i_srcpath)return -ENOMEM ; -if (!S_ISDIR (inode->i_mode)) { - inode->dev = st->st_dev; - inode->i_ino[1 ] = st->st_ino; - } -if (erofs_should_use_inode_extended (inode)) {if (cfg.c_force_inodeversion ==FORCE_INODE_COMPACT ) { erofs_err("file %s cannot be in compact form",
@@ -1007,7 +1003,9 @@ static int erofs_fill_inode(struct erofs_inode *inode, struct stat *st, inode->inode_isize =sizeof (struct erofs_inode_compact ); } -erofs_insert_ihash (inode, st->st_dev, st->st_ino); + inode->dev = st->st_dev; + inode->i_ino[1 ] = st->st_ino; +erofs_insert_ihash (inode);return 0 ; }
lib/rebuild.c +1 -1
@@ -346,7 +346,7 @@ static int erofs_rebuild_dirent_iter(struct erofs_dir_context *ctx) goto out; } -erofs_insert_ihash (inode, inode->dev, inode->i_ino[1 ]); +erofs_insert_ihash (inode); parent = dir = inode; }
Signature · 1 line
2.39.3
PATCH 2/9 erofs-utils: mkfs: minor cleanup & rearrangement
Introduce erofs_flush_packed_inode() and more for exporting liberofs APIs later.
--- include/erofs/fragments.h | 2 +- lib/fragments.c | 15 ++++++++++++--- lib/inode.c | 11 ++++++----- mkfs/main.c | 27 ++++++++++----------------- 4 files changed, 29 insertions(+), 26 deletions(-)
include/erofs/fragments.h +1 -1
@@ -17,7 +17,7 @@ extern const char *erofs_frags_packedname;FILE *erofs_packedfile_init (void );void erofs_packedfile_exit (void ); -struct erofs_inode *erofs_mkfs_build_packedfile (void ); +int erofs_flush_packed_inode (struct erofs_sb_info *sbi);int z_erofs_fragments_dedupe (struct erofs_inode *inode,int fd,u32 *tofcrc);int z_erofs_pack_file_from_fd (struct erofs_inode *inode,int fd,u32 tofcrc);
lib/fragments.c +12 -3
@@ -326,12 +326,21 @@ int z_erofs_pack_fragments(struct erofs_inode *inode, void *data,return len; } -struct erofs_inode *erofs_mkfs_build_packedfile (void ) +int erofs_flush_packed_inode (struct erofs_sb_info *sbi) { +struct erofs_inode *inode; + +if (!erofs_sb_has_fragments (sbi)) +return -EINVAL ;fflush (packedfile); +if (!ftello (packedfile)) +return 0 ; -return erofs_mkfs_build_special_from_fd (&sbi,fileno (packedfile), -EROFS_PACKED_INODE ); + inode =erofs_mkfs_build_special_from_fd (sbi,fileno (packedfile), +EROFS_PACKED_INODE ); + sbi->packed_nid =erofs_lookupnid (inode); +erofs_iput (inode); +return 0 ; }void erofs_packedfile_exit (void )
lib/inode.c +6 -5
@@ -1533,21 +1533,22 @@ static void erofs_mark_parent_inode(struct erofs_inode *inode,static int erofs_mkfs_dump_tree (struct erofs_inode *root,bool rebuild) { -struct erofs_inode *dumpdir; +struct erofs_sb_info *sbi = root->sbi; +struct erofs_inode *dumpdir =erofs_igrab (root);int err;erofs_mark_parent_inode (root, root);/* rootdir mark */ root->next_dirwrite =NULL ; - (void )erofs_igrab (root); - dumpdir = root; err = !rebuild ?erofs_mkfs_handle_inode (root) :erofs_rebuild_handle_inode (root);if (err)return err; -erofs_mkfs_flushjobs (root->sbi); +erofs_mkfs_flushjobs (sbi);erofs_fixup_meta_blkaddr (root);/* assign root NID */ + sbi->root_nid = root->nid; + do { int err; struct erofs_inode *dir = dumpdir;
@@ -1584,7 +1585,7 @@ static int erofs_mkfs_dump_tree(struct erofs_inode *root, bool rebuild) } *last = dumpdir;/* fixup the last (or the only) one */ dumpdir = head; - err =erofs_mkfs_go (dir->sbi,EROFS_MKFS_JOB_DIR_BH , + err =erofs_mkfs_go (sbi,EROFS_MKFS_JOB_DIR_BH , &dir,sizeof (dir));if (err)return err;
mkfs/main.c +10 -17
@@ -1136,7 +1136,7 @@ int main(int argc, char **argv) {int err =0 ;struct erofs_buffer_head *sb_bh; -struct erofs_inode *root, *packed_inode; +struct erofs_inode *root;erofs_blk_t nblocks;struct timeval t;FILE *packedfile =NULL ;
@@ -1342,36 +1342,29 @@ int main(int argc, char **argv) goto exit; } } - sbi.root_nid =erofs_lookupnid (root);erofs_iput (root);if (erofstar.index_mode && sbi.extra_devices && !erofstar.mapfile) sbi.devs[0 ].blocks =BLK_ROUND_UP (&sbi, erofstar.offset); -if (erofstar.index_mode || cfg.c_chunkbits || sbi.extra_devices) { - err =erofs_mkfs_dump_blobs (&sbi); +if (erofs_sb_has_fragments (&sbi)) { +erofs_update_progressinfo ("Handling packed data ..." ); + err =erofs_flush_packed_inode (&sbi);if (err) goto exit; } - sbi.packed_nid =0 ; -if ((cfg.c_fragments || cfg.c_extra_ea_name_prefixes) && -erofs_sb_has_fragments (&sbi)) { -erofs_update_progressinfo ("Handling packed_file ..." ); - packed_inode =erofs_mkfs_build_packedfile (); -if (IS_ERR (packed_inode)) { - err =PTR_ERR (packed_inode); - goto exit; - } - sbi.packed_nid =erofs_lookupnid (packed_inode); -erofs_iput (packed_inode); - } -/* flush all buffers except for the superblock */ err =erofs_bflush (NULL );if (err) goto exit; +if (erofstar.index_mode || cfg.c_chunkbits || sbi.extra_devices) { + err =erofs_mkfs_dump_blobs (&sbi); +if (err) + goto exit; + } + err =erofs_writesb (&sbi, sb_bh, &nblocks);if (err) goto exit;
Signature · 1 line
2.39.3
PATCH 3/9 erofs-utils: fix up root inode for incremental builds
In reply to Gao XiangMove the new root inode to the original location if it cannot be accessed by the super block.
--- include/erofs/inode.h | 3 +- lib/inode.c | 95 +++++++++++++++++++++++++++++++++++-------- mkfs/main.c | 13 ++++-- 3 files changed, 88 insertions(+), 23 deletions(-)
include/erofs/inode.h +2 -1
@@ -34,7 +34,7 @@ erofs_nid_t erofs_lookupnid(struct erofs_inode *inode);int erofs_iflush (struct erofs_inode *inode);struct erofs_dentry *erofs_d_alloc (struct erofs_inode *parent,const char *name); -int erofs_rebuild_dump_tree (struct erofs_inode *dir); +int erofs_rebuild_dump_tree (struct erofs_inode *dir,bool incremental);int erofs_init_empty_dir (struct erofs_inode *dir);int __erofs_fill_inode (struct erofs_inode *inode,struct stat *st,const char *path);
@@ -43,6 +43,7 @@ struct erofs_inode *erofs_mkfs_build_tree_from_path(struct erofs_sb_info *sbi, const char *path);struct erofs_inode *erofs_mkfs_build_special_from_fd (struct erofs_sb_info *sbi,int fd,const char *name); +int erofs_fixup_root_inode (struct erofs_inode *root); #ifdef __cplusplus }
lib/inode.c +77 -18
144 lines not on this page · raw message
mkfs/main.c +9 -4
@@ -1136,7 +1136,7 @@ int main(int argc, char **argv) {int err =0 ;struct erofs_buffer_head *sb_bh; -struct erofs_inode *root; +struct erofs_inode *root =NULL ;erofs_blk_t nblocks;struct timeval t;FILE *packedfile =NULL ;
@@ -1309,7 +1309,7 @@ int main(int argc, char **argv)if (err <0 ) goto exit; - err =erofs_rebuild_dump_tree (root); + err =erofs_rebuild_dump_tree (root, false);if (err <0 ) goto exit; }else if (rebuild_mode) {
@@ -1322,7 +1322,7 @@ int main(int argc, char **argv) err =erofs_rebuild_load_trees (root);if (err) goto exit; - err =erofs_rebuild_dump_tree (root); + err =erofs_rebuild_dump_tree (root, false);if (err) goto exit; }else {
@@ -1342,7 +1342,6 @@ int main(int argc, char **argv) goto exit; } } -erofs_iput (root);if (erofstar.index_mode && sbi.extra_devices && !erofstar.mapfile) sbi.devs[0 ].blocks =BLK_ROUND_UP (&sbi, erofstar.offset);
@@ -1359,6 +1358,10 @@ int main(int argc, char **argv)if (err) goto exit; +erofs_fixup_root_inode (root); +erofs_iput (root); + root =NULL ; +if (erofstar.index_mode || cfg.c_chunkbits || sbi.extra_devices) { err =erofs_mkfs_dump_blobs (&sbi);if (err)
@@ -1379,6 +1382,8 @@ int main(int argc, char **argv)if (!err &&erofs_sb_has_sb_chksum (&sbi)) err =erofs_mkfs_superblock_csum_set (); exit: +if (root) +erofs_iput (root);z_erofs_compress_exit ();z_erofs_dedupe_exit ();erofs_blocklist_close ();
Signature · 1 line
2.39.3
PATCH 4/9 erofs-utils: introduce incremental builds
In reply to Gao XiangThis introduces incremental build support for mkfs, where new on-disk (meta)data will be appended in a log-structured manner, except for the root inode (due to current on-disk limitations), as illustrated below:
___________________________________________
| base | delta 0 | delta 1 | .. | delta n-1 |
|______|_________|_________|____|___________|
---> image/data growth direction--- include/erofs/inode.h | 1 + include/erofs/internal.h | 6 +-- lib/inode.c | 72 +++++++++++++++++++++++++++----- lib/rebuild.c | 89 ++++++++++++++++++++++++++++++++++------ 4 files changed, 143 insertions(+), 25 deletions(-)
include/erofs/inode.h +1 -0
@@ -34,6 +34,7 @@ erofs_nid_t erofs_lookupnid(struct erofs_inode *inode);int erofs_iflush (struct erofs_inode *inode);struct erofs_dentry *erofs_d_alloc (struct erofs_inode *parent,const char *name); +bool erofs_dentry_is_wht (struct erofs_sb_info *sbi,struct erofs_dentry *d);int erofs_rebuild_dump_tree (struct erofs_inode *dir,bool incremental);int erofs_init_empty_dir (struct erofs_inode *dir); int __erofs_fill_inode(struct erofs_inode *inode, struct stat *st,
include/erofs/internal.h +3 -3
@@ -303,13 +303,13 @@ static inline struct erofs_inode *erofs_parent_inode(struct erofs_inode *inode)struct erofs_dentry {struct list_head d_child;/* child of parent list */ - -unsigned int type; -char name[EROFS_NAME_LEN ];union {struct erofs_inode *inode;erofs_nid_t nid; }; +char name[EROFS_NAME_LEN ]; +u8 type; +bool validnid; };static inline bool is_dot_dotdot_len (const char *name,unsigned int len)
lib/inode.c +62 -10
167 lines not on this page · raw message
lib/rebuild.c +77 -12
145 lines not on this page · raw message
Signature · 1 line
2.39.3
PATCH 5/9 erofs-utils: fix up unchanged directory pNIDs for incremental builds
In reply to Gao XiangFor incremental builds, it's unnecessary to dump all unchanged directories, yet the pNIDs of those directories need to be fixed to the new parent on-disk inodes.
--- lib/inode.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-)
lib/inode.c +85 -1
@@ -337,6 +337,81 @@ static void erofs_d_invalidate(struct erofs_dentry *d)erofs_iput (inode); } +static int erofs_rebuild_inode_fix_pnid (struct erofs_inode *parent, +erofs_nid_t nid) +{ +struct erofs_inode dir = { + .sbi = parent->sbi, + .nid = nid + }; +unsigned int bsz =erofs_blksiz (dir.sbi); +unsigned int err, isz; +erofs_off_t boff, off; +erofs_nid_t pnid; +bool fixed = false; + + err =erofs_read_inode_from_disk (&dir); +if (err) +return err; + +if (!S_ISDIR (dir.i_mode)) +return -ENOTDIR ; + +if (dir.datalayout !=EROFS_INODE_FLAT_INLINE && + dir.datalayout !=EROFS_INODE_FLAT_PLAIN ) +return -EOPNOTSUPP ; + + pnid =erofs_lookupnid (parent); + isz = dir.inode_isize + dir.xattr_isize; + boff =erofs_pos (dir.sbi, dir.u.i_blkaddr); +for (off =0 ; off < dir.i_size; off += bsz) { +char buf[EROFS_MAX_BLOCK_SIZE ]; +struct erofs_dirent *de = (struct erofs_dirent *)buf; +unsigned int nameoff, count, de_nameoff; + + count =min_t (erofs_off_t, bsz, dir.i_size - off); + err =erofs_pread (&dir, buf, count, off); +if (err) +return err; + + nameoff =le16_to_cpu (de->nameoff); +if (nameoff <sizeof (struct erofs_dirent ) || + nameoff >= count) { +erofs_err ("invalid de[0].nameoff %u @ nid %llu, offset %llu" , + nameoff, dir.nid |0ULL , off |0ULL ); +return -EFSCORRUPTED ; + } + +while ((char *)de < buf + nameoff) { + de_nameoff =le16_to_cpu (de->nameoff); +if (((char *)(de +1 ) >= buf + nameoff ? +strnlen (buf + de_nameoff, count - de_nameoff) ==2 : +le16_to_cpu (de[1 ].nameoff) == de_nameoff +2 ) && + !memcmp (buf + de_nameoff,".." ,2 )) { +if (de->nid ==cpu_to_le64 (pnid)) +return 0 ; + de->nid =cpu_to_le64 (pnid); + fixed = true; +break ; + } + ++de; + } + +if (!fixed) +continue ; + err =erofs_dev_write (dir.sbi, buf, + (off + bsz > dir.i_size && + dir.datalayout ==EROFS_INODE_FLAT_INLINE ? +erofs_iloc (&dir) + isz : boff + off), count); +erofs_dbg ("directory %llu pNID is updated to %llu" , + nid |0ULL , pnid |0ULL ); +break ; + } +if (err || fixed) +return err; +return -EFSCORRUPTED ; +} +static int erofs_write_dir_file (struct erofs_inode *dir) { struct erofs_dentry *head = list_first_entry(&dir->i_subdirs,
@@ -358,6 +433,13 @@ static int erofs_write_dir_file(struct erofs_inode *dir)const unsigned int len =strlen (d->name) +sizeof (struct erofs_dirent ); +/* XXX: a bit hacky, but to avoid another traversal */ +if (d->validnid && d->type ==EROFS_FT_DIR ) { + ret =erofs_rebuild_inode_fix_pnid (dir, d->nid); +if (ret) +return ret; + } +erofs_d_invalidate (d);if (used + len >erofs_blksiz (sbi)) { ret = write_dirblock(sbi, q, head, d,
@@ -1192,7 +1274,9 @@ static int erofs_mkfs_jobfn(struct erofs_mkfs_jobitem *item) }if (item->type ==EROFS_MKFS_JOB_DIR_BH ) { -erofs_write_dir_file (inode); + ret =erofs_write_dir_file (inode); +if (ret) +return ret;erofs_write_tail_end (inode); inode->bh->op = &erofs_write_inode_bhops;erofs_iput (inode);
Signature · 1 line
2.39.3
PATCH 6/9 erofs-utils: support building image with reserved space
In reply to Gao XiangA new mode is prepared in order to preallocate/reserve data blocks only since some applications tend to fill data after EROFS images are built.
--- include/erofs/internal.h | 7 +++- include/erofs/rebuild.h | 9 ++++- lib/inode.c | 45 +++++++++++++++++---- lib/rebuild.c | 84 ++++++++++++++++++++++++---------------- lib/tar.c | 2 +- mkfs/main.c | 3 +- 6 files changed, 104 insertions(+), 46 deletions(-)
include/erofs/internal.h +6 -1
@@ -170,6 +170,11 @@ EROFS_FEATURE_FUNCS(xattr_filter, compat, COMPAT_XATTR_FILTER)struct erofs_diskbuf ; +#define EROFS_INODE_DATA_SOURCE_NONE 0 +#define EROFS_INODE_DATA_SOURCE_LOCALPATH 1 +#define EROFS_INODE_DATA_SOURCE_DISKBUF 2 +#define EROFS_INODE_DATA_SOURCE_RESVSP 3 +struct erofs_inode {struct list_head i_hash, i_subdirs, i_xattrs;
@@ -216,9 +221,9 @@ struct erofs_inode {unsigned char inode_isize;/* inline tail-end packing size */ unsigned short idata_size; +char datasource;bool compressed_idata;bool lazy_tailblock; -bool with_diskbuf;bool opaque;/* OVL: non-merge dir that may contain whiteout entries */ bool whiteouts;
include/erofs/rebuild.h +8 -1
@@ -9,10 +9,17 @@ extern "C"#include "internal.h" +enum erofs_rebuild_datamode { +EROFS_REBUILD_DATA_BLOB_INDEX , +EROFS_REBUILD_DATA_RESVSP , +EROFS_REBUILD_DATA_FULL , +}; +struct erofs_dentry *erofs_rebuild_get_dentry (struct erofs_inode *pwd,char *path,bool aufs,bool *whout,bool *opq,bool to_head); -int erofs_rebuild_load_tree (struct erofs_inode *root,struct erofs_sb_info *sbi); +int erofs_rebuild_load_tree (struct erofs_inode *root,struct erofs_sb_info *sbi, +enum erofs_rebuild_datamode mode); #ifdef __cplusplus }
lib/inode.c +37 -8
84 lines not on this page · raw message
lib/rebuild.c +50 -34
161 lines not on this page · raw message
lib/tar.c +1 -1
@@ -607,7 +607,7 @@ static int tarerofs_write_file_data(struct erofs_inode *inode, j -= nread; }erofs_diskbuf_commit (inode->i_diskbuf, inode->i_size); - inode->with_diskbuf = true; + inode->datasource =EROFS_INODE_DATA_SOURCE_DISKBUF ;return 0 ; }
mkfs/main.c +2 -1
@@ -1060,7 +1060,8 @@ static int erofs_rebuild_load_trees(struct erofs_inode *root)int ret, idx;list_for_each_entry (src, &rebuild_src_list, list) { - ret =erofs_rebuild_load_tree (root, src); + ret =erofs_rebuild_load_tree (root, src, +EROFS_REBUILD_DATA_BLOB_INDEX );if (ret) {erofs_err ("failed to load %s" , src->devname);return ret;
Signature · 1 line
2.39.3
PATCH 7/9 erofs-utils: fix incremental builds for tarerofs index mode
In reply to Gao XiangThe blob data area should be considered in the total block number to prevent overlap during incremental builds.
--- lib/blobchunk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/blobchunk.c +2 -2
@@ -517,7 +517,7 @@ int erofs_mkfs_dump_blobs(struct erofs_sb_info *sbi)return 0 ; } - bh =erofs_balloc (DATA , blobfile ? datablob_size :0 ,0 ,0 ); + bh =erofs_balloc (DATA , datablob_size,0 ,0 );if (IS_ERR (bh))return PTR_ERR (bh);
@@ -532,7 +532,7 @@ int erofs_mkfs_dump_blobs(struct erofs_sb_info *sbi) sbi->bdev.fd, &pos_out, datablob_size); ret = ret < datablob_size ? -EIO :0 ; }else { - ret =0 ; + ret =erofs_io_ftruncate (&sbi->bdev, pos_out + datablob_size); } bh->op = &erofs_drop_directly_bhops;erofs_bdrop (bh, false);
Signature · 1 line
2.39.3
PATCH 8/9 erofs-utils: enable incremental builds
In reply to Gao Xiang--incremental=<data|rvsp> are now supported for tarerofs but only --incremental=rvsp works for the rebuild mode.
For example:
$ mkfs.erofs --tar=f --gzip --aufs --clean=data foo.erofs f0.tgz $ mkfs.erofs --tar=f --gzip --aufs --incremental=data foo.erofs f1.tgz ... $ mkfs.erofs --tar=f --gzip --aufs --incremental=data foo.erofs fn-1.tgz
--- include/erofs/io.h | 2 + include/erofs/tar.h | 3 +- lib/io.c | 13 +++++ lib/tar.c | 15 ++++- mkfs/main.c | 137 ++++++++++++++++++++++++++++++++++---------- 5 files changed, 135 insertions(+), 35 deletions(-)
include/erofs/io.h +2 -0
@@ -32,6 +32,7 @@ struct erofs_vfops {int (*ftruncate)(struct erofs_vfile *vf,u64 length);ssize_t (*read)(struct erofs_vfile *vf,void *buf,size_t len);off_t (*lseek)(struct erofs_vfile *vf,u64 offset,int whence); +int (*fstat)(struct erofs_vfile *vf,struct stat *buf); };struct erofs_vfile {
@@ -40,6 +41,7 @@ struct erofs_vfile {int fd; }; +int erofs_io_fstat (struct erofs_vfile *vf,struct stat *buf);ssize_t erofs_io_pwrite (struct erofs_vfile *vf,const void *buf,u64 pos,size_t len);int erofs_io_fsync (struct erofs_vfile *vf);ssize_t erofs_io_fallocate (struct erofs_vfile *vf,u64 offset,size_t len,bool pad);
include/erofs/tar.h +2 -1
@@ -57,9 +57,10 @@ struct erofs_tarfile {struct erofs_iostream ios;char *mapfile, *dumpfile; +u32 dev;int fd;u64 offset; -bool index_mode, headeronly_mode, aufs; +bool index_mode, headeronly_mode, rvsp_mode, aufs; };void erofs_iostream_close (struct erofs_iostream *ios);
lib/io.c +13 -0
@@ -26,6 +26,19 @@#define EROFS_MODNAME "erofs_io"#include "erofs/print.h" +int erofs_io_fstat (struct erofs_vfile *vf,struct stat *buf) +{ +if (unlikely (cfg.c_dry_run)) { + buf->st_size =0 ; + buf->st_mode =S_IFREG |0777 ; +return 0 ; + } + +if (vf->ops) +return vf->ops->fstat (vf, buf); +return fstat (vf->fd, buf); +} +ssize_t erofs_io_pwrite (struct erofs_vfile *vf,const void *buf,u64 pos,size_t len) {
lib/tar.c +12 -3
@@ -942,6 +942,7 @@ new_inode: ret =PTR_ERR (inode); goto out; } + inode->dev = tar->dev; inode->i_parent = d->inode; d->inode = inode; d->type =erofs_mode_to_ftype (st.st_mode);
@@ -981,13 +982,21 @@ new_inode: inode->i_link =malloc (inode->i_size +1 );memcpy (inode->i_link, eh.link, inode->i_size +1 ); }else if (inode->i_size) { -if (tar->headeronly_mode) +if (tar->headeronly_mode) { ret =erofs_write_zero_inode (inode); -else if (tar->index_mode) + }else if (tar->rvsp_mode) { + inode->datasource =EROFS_INODE_DATA_SOURCE_RESVSP ; + inode->i_ino[1 ] = data_offset; +if (erofs_iostream_lskip (&tar->ios, inode->i_size)) + ret = -EIO ; +else + ret =0 ; + }else if (tar->index_mode) { ret =tarerofs_write_file_index (inode, tar, data_offset); -else + }else { ret =tarerofs_write_file_data (inode, tar); + }if (ret) goto out; }
mkfs/main.c +106 -31
243 lines not on this page · raw message
Signature · 1 line
2.39.3
PATCH 9/9 erofs-utils: enable mapfile for `--tar=f`
In reply to Gao XiangThe data offsets in the tar streams can always be looked up now:
mkfs.erofs --tar=f,MAPFILE IMAGE TARBALL
--- lib/tar.c | 3 ++- mkfs/main.c | 40 ++++++++++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 13 deletions(-)
lib/tar.c +2 -1
@@ -858,7 +858,8 @@ restart: eh.link =strndup (th->linkname,sizeof (th->linkname)); } -if (tar->index_mode && !tar->mapfile && +/* EROFS metadata index referring to the original tar data */ +if (tar->index_mode && sbi->extra_devices &&erofs_blkoff (sbi, data_offset)) {erofs_err ("invalid tar data alignment @ %llu" , tar_offset); ret = -EIO ;
mkfs/main.c +28 -12
@@ -423,6 +423,27 @@ static int mkfs_apply_zfeature_bits(uintmax_t bits)return 0 ; } +static void mkfs_parse_tar_cfg (char *cfg) +{ +char *p; + + tar_mode = true; +if (!cfg) +return ; + p =strchr (cfg,',' ); +if (p) { + *p ='\0' ; +if ((*++p) !='\0' ) + erofstar.mapfile =strdup (p); + } +if (!strcmp (cfg,"headerball" )) + erofstar.headeronly_mode = true; + +if (erofstar.headeronly_mode || !strcmp (optarg,"i" ) || + !strcmp (optarg,"0" )) + erofstar.index_mode = true; +} +static int mkfs_parse_one_compress_alg (char *alg,struct erofs_compr_opts *copts) {
@@ -729,15 +750,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[]) cfg.c_extra_ea_name_prefixes = true;break ;case 20 : -if (optarg && (!strcmp (optarg,"i" ) || (!strcmp (optarg,"headerball" ) || - !strcmp (optarg,"0" ) || !memcmp (optarg,"0," ,2 )))) { - erofstar.index_mode = true; -if (!memcmp (optarg,"0," ,2 )) - erofstar.mapfile =strdup (optarg +2 ); -if (!strcmp (optarg,"headerball" )) - erofstar.headeronly_mode = true; - } - tar_mode = true; +mkfs_parse_tar_cfg (optarg);break ;case 21 : erofstar.aufs = true;
@@ -1266,10 +1279,13 @@ int main(int argc, char **argv)erofs_err ("failed to open %s" , erofstar.mapfile); goto exit; } - } - -if (erofstar.index_mode) + }else if (erofstar.index_mode) { +/* +* If mapfile is unspecified for tarfs index mode, 512-byte +* block size is enforced here. +*/ sbi.blkszbits =9 ; + } }if (rebuild_mode) {
Signature · 1 line
2.39.3