erofs-utils: remove global sbi in library
v2 cover erofs-utils: remove global sbi in library
changes since v1:
- patch 1: rename iloc() to erofs_iloc() (Gao Xiang)
v1: https://lore.kernel.org/all/[email protected]/
Later mkfs is going to be capable of converting multiple erofs images into one merged erofs image, in which case there are multiple device context and sbi instances.
In preparation for that, remove global device context and sbi in all libraries except buffer block library, as there's still only one output erofs image.
The device context is inlined into sbi. Each erofs_inode keeps a reference to corresponding sbi through vi->sbi. Global sbi is remained but only used by utils directly, e.g. mkfs/dump/fsck.
Jingbo Xu (2):
erofs-utils: simplify iloc()
erofs-utils: remove global sbi in library
dump/main.c | 30 +++--- fsck/main.c | 41 ++++---- fuse/main.c | 24 ++--- include/erofs/blobchunk.h | 4 +- include/erofs/cache.h | 6 +- include/erofs/compress.h | 8 +- include/erofs/compress_hints.h | 2 +- include/erofs/decompress.h | 1 + include/erofs/dir.h | 3 +- include/erofs/internal.h | 59 ++++++------ include/erofs/io.h | 38 ++++---- include/erofs/tar.h | 4 +- include/erofs/xattr.h | 16 ++-- lib/blobchunk.c | 45 ++++----- lib/cache.c | 42 ++++----- lib/compress.c | 165 ++++++++++++++++++--------------- lib/compress_hints.c | 10 +- lib/compressor.c | 15 +-- lib/compressor.h | 4 +- lib/compressor_lz4.c | 2 +- lib/compressor_lz4hc.c | 2 +- lib/data.c | 69 +++++++------- lib/decompress.c | 29 +++--- lib/dir.c | 21 +++-- lib/fragments.c | 2 +- lib/inode.c | 118 ++++++++++++----------- lib/io.c | 119 +++++++++++------------- lib/namei.c | 36 ++++--- lib/super.c | 51 +++++----- lib/tar.c | 36 +++---- lib/xattr.c | 75 ++++++++------- lib/zmap.c | 43 +++++---- mkfs/main.c | 62 ++++++------- 33 files changed, 627 insertions(+), 555 deletions(-)
Signature · 1 line
2.19.1.6.gb485710b
PATCH v2 1/2 erofs-utils: simplify iloc()
Pass in inodes directly to clean up all callers. Also rename iloc() as erofs_iloc().
--- fsck/main.c | 2 +- include/erofs/internal.h | 10 +++++----- lib/data.c | 4 ++-- lib/namei.c | 2 +- lib/xattr.c | 8 ++++---- lib/zmap.c | 6 +++--- 6 files changed, 16 insertions(+), 16 deletions(-)
fsck/main.c +1 -1
@@ -325,7 +325,7 @@ static int erofs_verify_xattr(struct erofs_inode *inode) } } - addr =iloc (inode->nid) + inode->inode_isize; + addr =erofs_iloc (inode) + inode->inode_isize; ret =dev_read (0 , buf, addr, xattr_hdr_size);if (ret <0 ) { erofs_err("failed to read xattr header @ nid %llu: %d",
include/erofs/internal.h +5 -5
@@ -103,11 +103,6 @@ struct erofs_sb_info {/* make sure that any user of the erofs headers has atleast 64bit off_t type */ extern int erofs_assert_largefile[sizeof (off_t)-8 ]; -static inline erofs_off_t iloc (erofs_nid_t nid) -{ -return erofs_pos (sbi.meta_blkaddr) + (nid << sbi.islotbits); -} -#define EROFS_FEATURE_FUNCS (name, compat, feature) \ static inline bool erofs_sb_has_##name(void) \ { \
@@ -219,6 +214,11 @@ struct erofs_inode {unsigned int fragment_size; }; +static inline erofs_off_t erofs_iloc (struct erofs_inode *inode) +{ +return erofs_pos (sbi.meta_blkaddr) + (inode->nid << sbi.islotbits); +} +static inline bool is_inode_layout_compression (struct erofs_inode *inode) {return erofs_inode_is_data_compressed (inode->datalayout);
lib/data.c +2 -2
@@ -33,7 +33,7 @@ static int erofs_map_blocks_flatmode(struct erofs_inode *inode, map->m_plen =erofs_pos (lastblk) - offset; }else if (tailendpacking) {/* 2 - inode inline B: inode, [xattrs], inline last blk... */ - map->m_pa =iloc (vi->nid) + vi->inode_isize + + map->m_pa =erofs_iloc (vi) + vi->inode_isize + vi->xattr_isize +erofs_blkoff (map->m_la); map->m_plen = inode->i_size - offset;
@@ -89,7 +89,7 @@ int erofs_map_blocks(struct erofs_inode *inode, unit =EROFS_BLOCK_MAP_ENTRY_SIZE ;/* block map */ chunknr = map->m_la >> vi->u.chunkbits; - pos =roundup (iloc (vi->nid) + vi->inode_isize + + pos =roundup (erofs_iloc (vi) + vi->inode_isize + vi->xattr_isize, unit) + unit * chunknr; err =blk_read (0 , buf,erofs_blknr (pos),1 );
lib/namei.c +1 -1
@@ -28,7 +28,7 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi)char buf[sizeof (struct erofs_inode_extended )];struct erofs_inode_compact *dic;struct erofs_inode_extended *die; -const erofs_off_t inode_loc =iloc (vi->nid); +const erofs_off_t inode_loc =erofs_iloc (vi); ret =dev_read (0 , buf, inode_loc,sizeof (*dic));if (ret <0 )
lib/xattr.c +4 -4
@@ -871,8 +871,8 @@ static int init_inode_xattrs(struct erofs_inode *vi)return -ENOATTR ; } - it.blkaddr =erofs_blknr (iloc (vi->nid) + vi->inode_isize); - it.ofs =erofs_blkoff (iloc (vi->nid) + vi->inode_isize); + it.blkaddr =erofs_blknr (erofs_iloc (vi) + vi->inode_isize); + it.ofs =erofs_blkoff (erofs_iloc (vi) + vi->inode_isize); ret =blk_read (0 , it.page, it.blkaddr,1 );if (ret <0 )
@@ -962,8 +962,8 @@ static int inline_xattr_iter_pre(struct xattr_iter *it, inline_xattr_ofs = vi->inode_isize + xattr_header_sz; - it->blkaddr =erofs_blknr (iloc (vi->nid) + inline_xattr_ofs); - it->ofs =erofs_blkoff (iloc (vi->nid) + inline_xattr_ofs); + it->blkaddr =erofs_blknr (erofs_iloc (vi) + inline_xattr_ofs); + it->ofs =erofs_blkoff (erofs_iloc (vi) + inline_xattr_ofs); ret =blk_read (0 , it->page, it->blkaddr,1 );if (ret <0 )
lib/zmap.c +3 -3
@@ -39,7 +39,7 @@ static int z_erofs_fill_inode_lazy(struct erofs_inode *vi)if (vi->flags &EROFS_I_Z_INITED )return 0 ; - pos =round_up (iloc (vi->nid) + vi->inode_isize + vi->xattr_isize,8 ); + pos =round_up (erofs_iloc (vi) + vi->inode_isize + vi->xattr_isize,8 ); ret =dev_read (0 , buf, pos,sizeof (buf));if (ret <0 )return -EIO ;
@@ -143,7 +143,7 @@ static int legacy_load_cluster_from_disk(struct z_erofs_maprecorder *m, unsigned long lcn) {struct erofs_inode *const vi = m->inode; -const erofs_off_t ibase =iloc (vi->nid); +const erofs_off_t ibase =erofs_iloc (vi);const erofs_off_t pos =Z_EROFS_FULL_INDEX_ALIGN (ibase + vi->inode_isize + vi->xattr_isize) + lcn *sizeof (struct z_erofs_lcluster_index );
@@ -342,7 +342,7 @@ static int compacted_load_cluster_from_disk(struct z_erofs_maprecorder *m, {struct erofs_inode *const vi = m->inode;const unsigned int lclusterbits = vi->z_logical_clusterbits; -const erofs_off_t ebase =round_up (iloc (vi->nid) + vi->inode_isize + +const erofs_off_t ebase =round_up (erofs_iloc (vi) + vi->inode_isize + vi->xattr_isize,8 ) +sizeof (struct z_erofs_map_header );const unsigned int totalidx =BLK_ROUND_UP (vi->i_size);
Signature · 1 line
2.19.1.6.gb485710b
PATCH v2 2/2 erofs-utils: remove global sbi in library
In reply to Jingbo XuLater mkfs is going to be capable of converting multiple erofs images into one merged erofs image, in which case there are multiple device context and sbi instances.
In preparation for that, remove global device context and sbi in all libraries except buffer block library, as there's still only one output erofs image.
The device context is inlined into sbi. Global sbi is remained but only used by utils directly, e.g. mkfs/dump/fsck.
--- dump/main.c | 30 +++--- fsck/main.c | 39 ++++---- fuse/main.c | 24 ++--- include/erofs/blobchunk.h | 4 +- include/erofs/cache.h | 6 +- include/erofs/compress.h | 8 +- include/erofs/compress_hints.h | 2 +- include/erofs/decompress.h | 1 + include/erofs/dir.h | 3 +- include/erofs/internal.h | 51 +++++----- include/erofs/io.h | 38 ++++---- include/erofs/tar.h | 4 +- include/erofs/xattr.h | 16 ++-- lib/blobchunk.c | 45 ++++----- lib/cache.c | 42 ++++----- lib/compress.c | 165 ++++++++++++++++++--------------- lib/compress_hints.c | 10 +- lib/compressor.c | 15 +-- lib/compressor.h | 4 +- lib/compressor_lz4.c | 2 +- lib/compressor_lz4hc.c | 2 +- lib/data.c | 65 +++++++------ lib/decompress.c | 29 +++--- lib/dir.c | 21 +++-- lib/fragments.c | 2 +- lib/inode.c | 118 ++++++++++++----------- lib/io.c | 119 +++++++++++------------- lib/namei.c | 36 ++++--- lib/super.c | 51 +++++----- lib/tar.c | 36 +++---- lib/xattr.c | 75 ++++++++------- lib/zmap.c | 37 +++++--- mkfs/main.c | 62 ++++++------- 33 files changed, 617 insertions(+), 545 deletions(-)
dump/main.c +15 -15
@@ -154,7 +154,7 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)usage ();exit (0 );case 3 : - err =blob_open_ro (optarg); + err =blob_open_ro (&sbi, optarg);if (err)return err; ++sbi.extra_devices;
@@ -202,7 +202,7 @@ static int erofsdump_get_occupied_size(struct erofs_inode *inode,case EROFS_INODE_COMPRESSED_FULL :case EROFS_INODE_COMPRESSED_COMPACT : stats.compressed_files++; - *size = inode->u.i_blocks *erofs_blksiz (); + *size = inode->u.i_blocks *erofs_blksiz (inode->sbi);break ;default :erofs_err ("unknown datalayout" );
@@ -272,10 +272,10 @@ static int erofsdump_read_packed_inode(void)erofs_off_t occupied_size =0 ;struct erofs_inode vi = { .nid = sbi.packed_nid }; -if (!(erofs_sb_has_fragments () && sbi.packed_nid >0 )) +if (!(erofs_sb_has_fragments (&sbi) && sbi.packed_nid >0 ))return 0 ; - err =erofs_read_inode_from_disk (&vi); + err =erofs_read_inode_from_disk (&sbi, &vi);if (err) {erofs_err ("failed to read packed file inode from disk" );return err;
@@ -298,7 +298,7 @@ static int erofsdump_readdir(struct erofs_dir_context *ctx)erofs_off_t occupied_size =0 ;struct erofs_inode vi = { .nid = ctx->de_nid }; - err =erofs_read_inode_from_disk (&vi); + err =erofs_read_inode_from_disk (&sbi, &vi);if (err) {erofs_err ("failed to read file inode from disk" );return err;
@@ -362,13 +362,13 @@ static void erofsdump_show_fileinfo(bool show_extent) };if (dumpcfg.inode_path) { - err =erofs_ilookup (dumpcfg.inode_path, &inode); + err =erofs_ilookup (&sbi, dumpcfg.inode_path, &inode);if (err) {erofs_err ("read inode failed @ %s" , dumpcfg.inode_path);return ; } }else { - err =erofs_read_inode_from_disk (&inode); + err =erofs_read_inode_from_disk (&sbi, &inode);if (err) {erofs_err ("read inode failed @ nid %llu" , inode.nid |0ULL );
@@ -382,7 +382,7 @@ static void erofsdump_show_fileinfo(bool show_extent)return ; } - err =erofs_get_pathname (inode.nid, path,sizeof (path)); + err =erofs_get_pathname (inode.sbi, inode.nid, path,sizeof (path));if (err <0 ) {strncpy (path,"(not found)" ,sizeof (path) -1 ); path[sizeof (path) -1 ] ='\0' ;
@@ -447,7 +447,7 @@ static void erofsdump_show_fileinfo(bool show_extent) .m_deviceid = map.m_deviceid, .m_pa = map.m_pa, }; - err =erofs_map_dev (&mdev); + err =erofs_map_dev (inode.sbi, &mdev);if (err) {erofs_err ("failed to map device" );return ;
@@ -604,7 +604,7 @@ static void erofsdump_show_superblock(void) sbi.xattr_blkaddr);fprintf (stdout,"Filesystem root nid: %llu\n" , sbi.root_nid |0ULL ); -if (erofs_sb_has_fragments () && sbi.packed_nid >0 ) +if (erofs_sb_has_fragments (&sbi) && sbi.packed_nid >0 )fprintf (stdout,"Filesystem packed nid: %llu\n" , sbi.packed_nid |0ULL ); fprintf(stdout, "Filesystem inode count: %llu\n",
@@ -636,13 +636,13 @@ int main(int argc, char **argv) goto exit; } - err =dev_open_ro (cfg.c_img_path); + err =dev_open_ro (&sbi, cfg.c_img_path);if (err) {erofs_err ("failed to open image file" ); goto exit; } - err =erofs_read_superblock (); + err =erofs_read_superblock (&sbi);if (err) {erofs_err ("failed to read superblock" ); goto exit_dev_close;
@@ -667,11 +667,11 @@ int main(int argc, char **argv)erofsdump_show_fileinfo (dumpcfg.show_extent); exit_put_super: -erofs_put_super (); +erofs_put_super (&sbi); exit_dev_close: -dev_close (); +dev_close (&sbi); exit: -blob_closeall (); +blob_closeall (&sbi);erofs_exit_configure ();return err; }
fsck/main.c +20 -19
@@ -158,7 +158,7 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv) }break ;case 3 : - ret =blob_open_ro (optarg); + ret =blob_open_ro (&sbi, optarg);if (ret)return ret; ++sbi.extra_devices;
@@ -279,7 +279,7 @@ static int erofs_check_sb_chksum(void)struct erofs_super_block *sb;int ret; - ret =blk_read (0 , buf,0 ,1 ); + ret =blk_read (&sbi,0 , buf,0 ,1 );if (ret) {erofs_err ("failed to read superblock to check checksum: %d" , ret);
@@ -289,7 +289,7 @@ static int erofs_check_sb_chksum(void) sb = (struct erofs_super_block *)(buf +EROFS_SUPER_OFFSET ); sb->checksum =0 ; - crc =erofs_crc32c (~0 , (u8 *)sb,erofs_blksiz () -EROFS_SUPER_OFFSET ); + crc =erofs_crc32c (~0 , (u8 *)sb,erofs_blksiz (&sbi) -EROFS_SUPER_OFFSET );if (crc != sbi.checksum) {erofs_err ("superblock chksum doesn't match: saved(%08xh) calculated(%08xh)" , sbi.checksum, crc);
@@ -302,6 +302,7 @@ static int erofs_check_sb_chksum(void)static int erofs_verify_xattr (struct erofs_inode *inode) { +struct erofs_sb_info *sbi = inode->sbi;unsigned int xattr_hdr_size =sizeof (struct erofs_xattr_ibody_header );unsigned int xattr_entry_size =sizeof (struct erofs_xattr_entry );erofs_off_t addr;
@@ -326,7 +327,7 @@ static int erofs_verify_xattr(struct erofs_inode *inode) } addr =erofs_iloc (inode) + inode->inode_isize; - ret =dev_read (0 , buf, addr, xattr_hdr_size); + ret =dev_read (sbi,0 , buf, addr, xattr_hdr_size);if (ret <0 ) {erofs_err ("failed to read xattr header @ nid %llu: %d" , inode->nid |0ULL , ret);
@@ -335,12 +336,12 @@ static int erofs_verify_xattr(struct erofs_inode *inode) ih = (struct erofs_xattr_ibody_header *)buf; xattr_shared_count = ih->h_shared_count; - ofs =erofs_blkoff (addr) + xattr_hdr_size; + ofs =erofs_blkoff (sbi, addr) + xattr_hdr_size; addr += xattr_hdr_size; remaining -= xattr_hdr_size;for (i =0 ; i < xattr_shared_count; ++i) { -if (ofs >=erofs_blksiz ()) { -if (ofs !=erofs_blksiz ()) { +if (ofs >=erofs_blksiz (sbi)) { +if (ofs !=erofs_blksiz (sbi)) {erofs_err ("unaligned xattr entry in xattr shared area @ nid %llu" , inode->nid |0ULL ); ret = -EFSCORRUPTED ;
@@ -356,7 +357,7 @@ static int erofs_verify_xattr(struct erofs_inode *inode)while (remaining >0 ) {unsigned int entry_sz; - ret =dev_read (0 , buf, addr, xattr_entry_size); + ret =dev_read (sbi,0 , buf, addr, xattr_entry_size);if (ret) {erofs_err ("failed to read xattr entry @ nid %llu: %d" , inode->nid |0ULL , ret);
@@ -483,7 +484,7 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)u64 count =min_t (u64, alloc_rawsize, map.m_llen); - ret =erofs_read_one_data (&map, raw, p, count); + ret =erofs_read_one_data (inode, &map, raw, p, count);if (ret) goto out;
@@ -497,8 +498,8 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)if (fsckcfg.print_comp_ratio) {if (!erofs_is_packed_inode (inode)) - fsckcfg.logical_blocks +=BLK_ROUND_UP (inode->i_size); - fsckcfg.physical_blocks +=BLK_ROUND_UP (pchunk_len); + fsckcfg.logical_blocks +=BLK_ROUND_UP (inode->sbi, inode->i_size); + fsckcfg.physical_blocks +=BLK_ROUND_UP (inode->sbi, pchunk_len); } out:if (raw)
@@ -845,7 +846,7 @@ static int erofsfsck_check_inode(erofs_nid_t pnid, erofs_nid_t nid)erofs_dbg ("check inode: nid(%llu)" , nid |0ULL ); inode.nid = nid; - ret =erofs_read_inode_from_disk (&inode); + ret =erofs_read_inode_from_disk (&sbi, &inode);if (ret) {if (ret == -EIO ) erofs_err("I/O error occurred when reading nid(%llu)",
@@ -920,19 +921,19 @@ int main(int argc, char *argv[]) cfg.c_dbg_lvl =-1 ;#endif - err =dev_open_ro (cfg.c_img_path); + err =dev_open_ro (&sbi, cfg.c_img_path);if (err) {erofs_err ("failed to open image file" ); goto exit; } - err =erofs_read_superblock (); + err =erofs_read_superblock (&sbi);if (err) {erofs_err ("failed to read superblock" ); goto exit_dev_close; } -if (erofs_sb_has_sb_chksum () &&erofs_check_sb_chksum ()) { +if (erofs_sb_has_sb_chksum (&sbi) &&erofs_check_sb_chksum ()) {erofs_err ("failed to verify superblock checksum" ); goto exit_put_super; }
@@ -940,7 +941,7 @@ int main(int argc, char *argv[])if (fsckcfg.extract_path)erofsfsck_hardlink_init (); -if (erofs_sb_has_fragments () && sbi.packed_nid >0 ) { +if (erofs_sb_has_fragments (&sbi) && sbi.packed_nid >0 ) { err =erofsfsck_check_inode (sbi.packed_nid, sbi.packed_nid);if (err) {erofs_err ("failed to verify packed file" );
@@ -974,11 +975,11 @@ exit_hardlink:if (fsckcfg.extract_path)erofsfsck_hardlink_exit (); exit_put_super: -erofs_put_super (); +erofs_put_super (&sbi); exit_dev_close: -dev_close (); +dev_close (&sbi); exit: -blob_closeall (); +blob_closeall (&sbi);erofs_exit_configure ();return err ?1 :0 ; }
fuse/main.c +12 -12
@@ -49,7 +49,7 @@ int erofsfuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, };erofs_dbg ("readdir:%s offset=%llu" , path, (long long )offset); - ret =erofs_ilookup (path, &dir); + ret =erofs_ilookup (&sbi, path, &dir);if (ret)return ret;
@@ -88,14 +88,14 @@ static int erofsfuse_getattr(const char *path, struct stat *stbuf)int ret;erofs_dbg ("getattr(%s)" , path); - ret =erofs_ilookup (path, &vi); + ret =erofs_ilookup (&sbi, path, &vi);if (ret)return -ENOENT ; stbuf->st_mode = vi.i_mode; stbuf->st_nlink = vi.i_nlink; stbuf->st_size = vi.i_size; - stbuf->st_blocks =roundup (vi.i_size,erofs_blksiz ()) >>9 ; + stbuf->st_blocks =roundup (vi.i_size,erofs_blksiz (vi.sbi)) >>9 ; stbuf->st_uid = vi.i_uid; stbuf->st_gid = vi.i_gid;if (S_ISBLK (vi.i_mode) ||S_ISCHR (vi.i_mode))
@@ -115,7 +115,7 @@ static int erofsfuse_read(const char *path, char *buffer,erofs_dbg ("path:%s size=%zd offset=%llu" , path, size, (long long )offset); - ret =erofs_ilookup (path, &vi); + ret =erofs_ilookup (&sbi, path, &vi);if (ret)return ret;
@@ -155,7 +155,7 @@ static int erofsfuse_getxattr(const char *path, const char *name, char *value,erofs_dbg ("getxattr(%s): name=%s size=%llu" , path, name, size); - ret =erofs_ilookup (path, &vi); + ret =erofs_ilookup (&sbi, path, &vi);if (ret)return ret;
@@ -169,7 +169,7 @@ static int erofsfuse_listxattr(const char *path, char *list, size_t size)erofs_dbg ("listxattr(%s): size=%llu" , path, size); - ret =erofs_ilookup (path, &vi); + ret =erofs_ilookup (&sbi, path, &vi);if (ret)return ret;
@@ -244,7 +244,7 @@ static int optional_opt_func(void *data, const char *arg, int key,switch (key) {case 1 : - ret =blob_open_ro (arg +sizeof ("--device=" ) -1 ); + ret =blob_open_ro (&sbi, arg +sizeof ("--device=" ) -1 );if (ret)return -1 ; ++sbi.extra_devices;
@@ -325,13 +325,13 @@ int main(int argc, char *argv[]) cfg.c_offset = fusecfg.offset;erofsfuse_dumpcfg (); - ret =dev_open_ro (fusecfg.disk); + ret =dev_open_ro (&sbi, fusecfg.disk);if (ret) {fprintf (stderr,"failed to open: %s\n" , fusecfg.disk); goto err_fuse_free_args; } - ret =erofs_read_superblock (); + ret =erofs_read_superblock (&sbi);if (ret) {fprintf (stderr,"failed to read erofs super block\n" ); goto err_dev_close;
@@ -339,10 +339,10 @@ int main(int argc, char *argv[]) ret =fuse_main (args.argc, args.argv, &erofs_ops,NULL ); -erofs_put_super (); +erofs_put_super (&sbi); err_dev_close: -blob_closeall (); -dev_close (); +blob_closeall (&sbi); +dev_close (&sbi); err_fuse_free_args:fuse_opt_free_args (&args); err:
include/erofs/blobchunk.h +2 -2
@@ -18,10 +18,10 @@ struct erofs_blobchunk *erofs_get_unhashed_chunk(erofs_off_t chunksize, unsigned int device_id, erofs_blk_t blkaddr);int erofs_blob_write_chunk_indexes (struct erofs_inode *inode,erofs_off_t off);int erofs_blob_write_chunked_file (struct erofs_inode *inode,int fd); -int erofs_blob_remap (void ); +int erofs_blob_remap (struct erofs_sb_info *sbi);void erofs_blob_exit (void );int erofs_blob_init (const char *blobfile_path); -int erofs_generate_devtable (void ); +int erofs_generate_devtable (struct erofs_sb_info *sbi); #ifdef __cplusplus }
include/erofs/cache.h +3 -3
@@ -57,14 +57,14 @@ struct erofs_buffer_block {static inline const int get_alignsize (int type,int *type_ret) {if (type ==DATA ) -return erofs_blksiz (); +return erofs_blksiz (&sbi);if (type ==INODE ) { *type_ret =META ;return sizeof (struct erofs_inode_compact ); }else if (type ==DIRA ) { *type_ret =META ; -return erofs_blksiz (); +return erofs_blksiz (&sbi); }else if (type ==XATTR ) { *type_ret =META ;return sizeof (struct erofs_xattr_entry );
@@ -88,7 +88,7 @@ static inline erofs_off_t erofs_btell(struct erofs_buffer_head *bh, bool end)if (bb->blkaddr ==NULL_ADDR )return NULL_ADDR_UL ; -return erofs_pos (bb->blkaddr) + +return erofs_pos (&sbi, bb->blkaddr) + (end ?list_next_entry (bh, list)->off : bh->off); }
include/erofs/compress.h +5 -3
@@ -19,18 +19,20 @@ extern "C"void z_erofs_drop_inline_pcluster (struct erofs_inode *inode);int erofs_write_compressed_file (struct erofs_inode *inode,int fd); -int z_erofs_compress_init (struct erofs_buffer_head *bh); +int z_erofs_compress_init (struct erofs_sb_info *sbi,struct erofs_buffer_head *bh);int z_erofs_compress_exit (void );const char *z_erofs_list_available_compressors (unsigned int i);static inline bool erofs_is_packed_inode (struct erofs_inode *inode) { +erofs_nid_t packed_nid = inode->sbi->packed_nid; +if (inode->nid ==EROFS_PACKED_NID_UNALLOCATED ) { -DBG_BUGON (sbi.packed_nid !=EROFS_PACKED_NID_UNALLOCATED ); +DBG_BUGON (packed_nid !=EROFS_PACKED_NID_UNALLOCATED );return true; } -return (sbi.packed_nid >0 && inode->nid == sbi.packed_nid); +return (packed_nid >0 && inode->nid == packed_nid); }#ifdef __cplusplus
include/erofs/compress_hints.h +1 -1
@@ -25,7 +25,7 @@ struct erofs_compress_hints {bool z_erofs_apply_compress_hints (struct erofs_inode *inode);void erofs_cleanup_compress_hints (void ); -int erofs_load_compress_hints (void ); +int erofs_load_compress_hints (struct erofs_sb_info *sbi); #ifdef __cplusplus }
include/erofs/decompress.h +1 -0
@@ -14,6 +14,7 @@ extern "C"#include "internal.h" struct z_erofs_decompress_req { +struct erofs_sb_info *sbi;char *in, *out;/*
include/erofs/dir.h +2 -1
@@ -62,7 +62,8 @@ struct erofs_dir_context {/* Iterate over inodes that are in directory */ int erofs_iterate_dir (struct erofs_dir_context *ctx,bool fsck);/* Get a full pathname of the inode NID */ -int erofs_get_pathname (erofs_nid_t nid,char *buf,size_t size); +int erofs_get_pathname (struct erofs_sb_info *sbi,erofs_nid_t nid, +char *buf,size_t size); #ifdef __cplusplus }
include/erofs/internal.h +29 -22
106 lines not on this page · raw message
include/erofs/io.h +20 -18
@@ -22,34 +22,36 @@ extern "C"#define O_BINARY 0#endif -void blob_closeall (void ); -int blob_open_ro (const char *dev); -int dev_open (const char *devname); -int dev_open_ro (const char *dev); -void dev_close (void ); -int dev_write (const void *buf,u64 offset,size_t len); -int dev_read (int device_id,void *buf,u64 offset,size_t len); -int dev_fillzero (u64 offset,size_t len,bool padding); -int dev_fsync (void ); -int dev_resize (erofs_blk_t nblocks); -u64 dev_length (void ); - -extern int erofs_devfd; +void blob_closeall (struct erofs_sb_info *sbi); +int blob_open_ro (struct erofs_sb_info *sbi,const char *dev); +int dev_open (struct erofs_sb_info *sbi,const char *devname); +int dev_open_ro (struct erofs_sb_info *sbi,const char *dev); +void dev_close (struct erofs_sb_info *sbi); +int dev_write (struct erofs_sb_info *sbi,const void *buf, +u64 offset,size_t len); +int dev_read (struct erofs_sb_info *sbi,int device_id, +void *buf,u64 offset,size_t len); +int dev_fillzero (struct erofs_sb_info *sbi,u64 offset, +size_t len,bool padding); +int dev_fsync (struct erofs_sb_info *sbi); +int dev_resize (struct erofs_sb_info *sbi,erofs_blk_t nblocks);ssize_t erofs_copy_file_range (int fd_in,erofs_off_t *off_in,int fd_out,erofs_off_t *off_out,size_t length); -static inline int blk_write (const void *buf,erofs_blk_t blkaddr, -u32 nblocks) +static inline int blk_write (struct erofs_sb_info *sbi,const void *buf, +erofs_blk_t blkaddr,u32 nblocks) { -return dev_write (buf,erofs_pos (blkaddr),erofs_pos (nblocks)); +return dev_write (sbi, buf,erofs_pos (sbi, blkaddr), +erofs_pos (sbi, nblocks)); } -static inline int blk_read (int device_id,void *buf, +static inline int blk_read (struct erofs_sb_info *sbi,int device_id,void *buf,erofs_blk_t start,u32 nblocks) { -return dev_read (device_id, buf,erofs_pos (start),erofs_pos (nblocks)); +return dev_read (sbi, device_id, buf,erofs_pos (sbi, start), +erofs_pos (sbi, nblocks)); }#ifdef __cplusplus
include/erofs/tar.h +2 -2
@@ -23,7 +23,7 @@ struct erofs_tarfile {int tarerofs_init_empty_dir (struct erofs_inode *inode);int tarerofs_parse_tar (struct erofs_inode *root,struct erofs_tarfile *tar); -int tarerofs_reserve_devtable (unsigned int devices); -int tarerofs_write_devtable (struct erofs_tarfile *tar); +int tarerofs_reserve_devtable (struct erofs_sb_info *sbi,unsigned int devices); +int tarerofs_write_devtable (struct erofs_sb_info *sbi,struct erofs_tarfile *tar);#endif
include/erofs/xattr.h +9 -7
@@ -24,15 +24,17 @@ static inline unsigned int inlinexattr_header_size(struct erofs_inode *vi)sizeof (u32) * vi->xattr_shared_count; } -static inline erofs_blk_t xattrblock_addr (unsigned int xattr_id) +static inline erofs_blk_t xattrblock_addr (struct erofs_inode *vi, +unsigned int xattr_id) { -return sbi.xattr_blkaddr + - ((xattr_id *sizeof (__u32)) >> sbi.blkszbits); +return vi->sbi->xattr_blkaddr + +erofs_blknr (vi->sbi, xattr_id *sizeof (__u32)); } -static inline unsigned int xattrblock_offset (unsigned int xattr_id) +static inline unsigned int xattrblock_offset (struct erofs_inode *vi, +unsigned int xattr_id) { -return (xattr_id *sizeof (__u32)) & (erofs_blksiz () -1 ); +return erofs_blkoff (vi->sbi, xattr_id *sizeof (__u32)); }#define EROFS_INODE_XATTR_ICOUNT (_size) ({\
@@ -75,11 +77,11 @@ static inline unsigned int xattrblock_offset(unsigned int xattr_id)int erofs_scan_file_xattrs (struct erofs_inode *inode);int erofs_prepare_xattr_ibody (struct erofs_inode *inode);char *erofs_export_xattr_ibody (struct list_head *ixattrs,unsigned int size); -int erofs_build_shared_xattrs_from_path (const char *path); +int erofs_build_shared_xattrs_from_path (struct erofs_sb_info *sbi,const char *path);int erofs_xattr_insert_name_prefix (const char *prefix);void erofs_xattr_cleanup_name_prefixes (void ); -int erofs_xattr_write_name_prefixes (FILE *f); +int erofs_xattr_write_name_prefixes (struct erofs_sb_info *sbi,FILE *f);int erofs_setxattr (struct erofs_inode *inode,char *key,const void *value,size_t size);
lib/blobchunk.c +23 -22
123 lines not on this page · raw message
lib/cache.c +21 -21
130 lines not on this page · raw message
lib/compress.c +88 -77
540 lines not on this page · raw message
lib/compress_hints.c +5 -5
@@ -86,7 +86,7 @@ void erofs_cleanup_compress_hints(void) } } -int erofs_load_compress_hints (void ) +int erofs_load_compress_hints (struct erofs_sb_info *sbi) {char buf[PATH_MAX +100 ];FILE *f;
@@ -133,21 +133,21 @@ int erofs_load_compress_hints(void) } } -if (pclustersize %erofs_blksiz ()) { +if (pclustersize %erofs_blksiz (sbi)) {erofs_warn ("invalid physical clustersize %u, " "use default pclusterblks %u" , pclustersize, cfg.c_pclusterblks_def);continue ; }erofs_insert_compress_hints (pattern, - pclustersize /erofs_blksiz (), ccfg); + pclustersize /erofs_blksiz (sbi), ccfg);if (pclustersize > max_pclustersize) max_pclustersize = pclustersize; } -if (cfg.c_pclusterblks_max *erofs_blksiz () < max_pclustersize) { - cfg.c_pclusterblks_max = max_pclustersize /erofs_blksiz (); +if (cfg.c_pclusterblks_max *erofs_blksiz (sbi) < max_pclustersize) { + cfg.c_pclusterblks_max = max_pclustersize /erofs_blksiz (sbi);erofs_warn ("update max pclusterblks to %u" , cfg.c_pclusterblks_max); } out:
lib/compressor.c +9 -6
@@ -42,10 +42,10 @@ int erofs_compress_destsize(const struct erofs_compress *c,if (ret <0 )return ret; -/* XXX: ret >= erofs_blksiz() is a temporary hack for ztailpacking */ -if (inblocks || ret >=erofs_blksiz () || +/* XXX: ret >= destsize_alignsize is a temporary hack for ztailpacking */ +if (inblocks || ret >= c->destsize_alignsize || uncompressed_capacity != *srcsize) - compressed_size =roundup (ret,erofs_blksiz ()); + compressed_size =roundup (ret, c->destsize_alignsize);else compressed_size = ret;DBG_BUGON (c->compress_threshold <100 );
@@ -72,16 +72,19 @@ int erofs_compressor_setlevel(struct erofs_compress *c, int compression_level)return 0 ; } -int erofs_compressor_init (struct erofs_compress *c,char *alg_name) +int erofs_compressor_init (struct erofs_sb_info *sbi, +struct erofs_compress *c,char *alg_name) {int ret, i; + c->sbi = sbi; +/* should be written in "minimum compression ratio * 100" */ c->compress_threshold =100 ;/* optimize for 4k size page */ - c->destsize_alignsize =erofs_blksiz (); - c->destsize_redzone_begin =erofs_blksiz () -16 ; + c->destsize_alignsize =erofs_blksiz (sbi); + c->destsize_redzone_begin =erofs_blksiz (sbi) -16 ; c->destsize_redzone_end =EROFS_CONFIG_COMPR_DEF_BOUNDARY ;if (!alg_name) {
lib/compressor.h +3 -1
@@ -27,6 +27,7 @@ struct erofs_compressor { };struct erofs_compress { +struct erofs_sb_info *sbi;const struct erofs_compressor *alg;unsigned int compress_threshold;
@@ -52,7 +53,8 @@ int erofs_compress_destsize(const struct erofs_compress *c, void *dst, unsigned int dstsize, bool inblocks);int erofs_compressor_setlevel (struct erofs_compress *c,int compression_level); -int erofs_compressor_init (struct erofs_compress *c,char *alg_name); +int erofs_compressor_init (struct erofs_sb_info *sbi, +struct erofs_compress *c,char *alg_name);int erofs_compressor_exit (struct erofs_compress *c);#endif
lib/compressor_lz4.c +1 -1
@@ -33,7 +33,7 @@ static int compressor_lz4_exit(struct erofs_compress *c)static int compressor_lz4_init (struct erofs_compress *c) { c->alg = &erofs_compressor_lz4; - sbi.lz4_max_distance =LZ4_DISTANCE_MAX ; + c->sbi->lz4_max_distance =LZ4_DISTANCE_MAX ;return 0 ; }
lib/compressor_lz4hc.c +1 -1
@@ -44,7 +44,7 @@ static int compressor_lz4hc_init(struct erofs_compress *c)if (!c->private_data)return -ENOMEM ; - sbi.lz4_max_distance =LZ4_DISTANCE_MAX ; + c->sbi->lz4_max_distance =LZ4_DISTANCE_MAX ;return 0 ; }
lib/data.c +35 -30
192 lines not on this page · raw message
lib/decompress.c +17 -12
@@ -97,14 +97,15 @@ static int zerr(int ret)static int z_erofs_decompress_deflate (struct z_erofs_decompress_req *rq) {int ret =0 ; +struct erofs_sb_info *sbi = rq->sbi;u8 *dest = (u8 *)rq->out;u8 *src = (u8 *)rq->in;u8 *buff =NULL ;unsigned int inputmargin =0 ;z_stream strm; -while (!src[inputmargin & (erofs_blksiz () -1 )]) -if (!(++inputmargin & (erofs_blksiz () -1 ))) +while (!src[inputmargin & (erofs_blksiz (sbi) -1 )]) +if (!(++inputmargin & (erofs_blksiz (sbi) -1 )))break ;if (inputmargin >= rq->inputsize)
@@ -158,6 +159,7 @@ out_inflate_end:static int z_erofs_decompress_lzma (struct z_erofs_decompress_req *rq) {int ret =0 ; +struct erofs_sb_info *sbi = rq->sbi;u8 *dest = (u8 *)rq->out;u8 *src = (u8 *)rq->in;u8 *buff =NULL ;
@@ -165,8 +167,8 @@ static int z_erofs_decompress_lzma(struct z_erofs_decompress_req *rq)lzma_stream strm;lzma_ret ret2; -while (!src[inputmargin & (erofs_blksiz () -1 )]) -if (!(++inputmargin & (erofs_blksiz () -1 ))) +while (!src[inputmargin & (erofs_blksiz (sbi) -1 )]) +if (!(++inputmargin & (erofs_blksiz (sbi) -1 )))break ;if (inputmargin >= rq->inputsize)
@@ -224,12 +226,13 @@ static int z_erofs_decompress_lz4(struct z_erofs_decompress_req *rq)char *buff =NULL ;bool support_0padding = false;unsigned int inputmargin =0 ; +struct erofs_sb_info *sbi = rq->sbi; -if (erofs_sb_has_lz4_0padding ()) { +if (erofs_sb_has_lz4_0padding (sbi)) { support_0padding = true; -while (!src[inputmargin & (erofs_blksiz () -1 )]) -if (!(++inputmargin & (erofs_blksiz () -1 ))) +while (!src[inputmargin & (erofs_blksiz (sbi) -1 )]) +if (!(++inputmargin & (erofs_blksiz (sbi) -1 )))break ;if (inputmargin >= rq->inputsize)
@@ -274,22 +277,24 @@ out:int z_erofs_decompress (struct z_erofs_decompress_req *rq) { +struct erofs_sb_info *sbi = rq->sbi; +if (rq->alg ==Z_EROFS_COMPRESSION_INTERLACED ) {unsigned int count, rightpart, skip; -/* XXX: should support inputsize >= erofs_blksiz() later */ -if (rq->inputsize >erofs_blksiz ()) +/* XXX: should support inputsize >= erofs_blksiz(sbi) later */ +if (rq->inputsize >erofs_blksiz (sbi))return -EFSCORRUPTED ; -if (rq->decodedlength >erofs_blksiz ()) +if (rq->decodedlength >erofs_blksiz (sbi))return -EFSCORRUPTED ;if (rq->decodedlength < rq->decodedskip)return -EFSCORRUPTED ; count = rq->decodedlength - rq->decodedskip; - skip =erofs_blkoff (rq->interlaced_offset + rq->decodedskip); - rightpart =min (erofs_blksiz () - skip, count); + skip =erofs_blkoff (sbi, rq->interlaced_offset + rq->decodedskip); + rightpart =min (erofs_blksiz (sbi) - skip, count);memcpy (rq->out, rq->in + skip, rightpart);memcpy (rq->out + rightpart, rq->in, count - rightpart);return 0 ;
lib/dir.c +12 -9
@@ -10,6 +10,7 @@ static int traverse_dirents(struct erofs_dir_context *ctx, bool fsck) {struct erofs_inode *dir = ctx->dir; +struct erofs_sb_info *sbi = dir->sbi;struct erofs_dirent *de = dentry_blk;const struct erofs_dirent *end = dentry_blk + next_nameoff;const char *prev_name =NULL ;
@@ -77,8 +78,8 @@ static int traverse_dirents(struct erofs_dir_context *ctx, goto out; } ctx->flags |=EROFS_READDIR_DOTDOT_FOUND ; -if (sbi.root_nid == dir->nid) { - ctx->pnid = sbi.root_nid; +if (sbi->root_nid == dir->nid) { + ctx->pnid = sbi->root_nid; ctx->flags |=EROFS_READDIR_VALID_PNID ; } if (fsck &&
@@ -124,6 +125,7 @@ out:int erofs_iterate_dir (struct erofs_dir_context *ctx,bool fsck) {struct erofs_inode *dir = ctx->dir; +struct erofs_sb_info *sbi = dir->sbi;int err =0 ;erofs_off_t pos;char buf[EROFS_MAX_BLOCK_SIZE ];
@@ -134,9 +136,9 @@ int erofs_iterate_dir(struct erofs_dir_context *ctx, bool fsck) ctx->flags &= ~EROFS_READDIR_ALL_SPECIAL_FOUND ; pos =0 ;while (pos < dir->i_size) { -erofs_blk_t lblk =erofs_blknr (pos); +erofs_blk_t lblk =erofs_blknr (sbi, pos);erofs_off_t maxsize =min_t (erofs_off_t, - dir->i_size - pos,erofs_blksiz ()); + dir->i_size - pos,erofs_blksiz (sbi));const struct erofs_dirent *de = (const void *)buf;unsigned int nameoff;
@@ -149,7 +151,7 @@ int erofs_iterate_dir(struct erofs_dir_context *ctx, bool fsck) nameoff =le16_to_cpu (de->nameoff);if (nameoff <sizeof (struct erofs_dirent ) || - nameoff >=erofs_blksiz ()) { + nameoff >=erofs_blksiz (sbi)) {erofs_err ("invalid de[0].nameoff %u @ nid %llu, lblk %u" , nameoff, dir->nid |0ULL , lblk);return -EFSCORRUPTED ;
@@ -206,7 +208,7 @@ static int erofs_get_pathname_iter(struct erofs_dir_context *ctx)if (ctx->de_ftype ==EROFS_FT_DIR || ctx->de_ftype ==EROFS_FT_UNKNOWN ) {struct erofs_inode dir = { .nid = ctx->de_nid }; - ret =erofs_read_inode_from_disk (&dir); + ret =erofs_read_inode_from_disk (ctx->dir->sbi, &dir);if (ret) {erofs_err ("read inode failed @ nid %llu" , dir.nid |0ULL );return ret;
@@ -230,10 +232,11 @@ static int erofs_get_pathname_iter(struct erofs_dir_context *ctx)return 0 ; } -int erofs_get_pathname (erofs_nid_t nid,char *buf,size_t size) +int erofs_get_pathname (struct erofs_sb_info *sbi,erofs_nid_t nid, +char *buf,size_t size) {int ret; -struct erofs_inode root = { .nid = sbi.root_nid }; +struct erofs_inode root = { .nid = sbi->root_nid };struct erofs_get_pathname_context pathctx = { .ctx.flags =0 , .ctx.dir = &root,
@@ -256,7 +259,7 @@ int erofs_get_pathname(erofs_nid_t nid, char *buf, size_t size)return 0 ; } - ret =erofs_read_inode_from_disk (&root); + ret =erofs_read_inode_from_disk (sbi, &root);if (ret) {erofs_err ("read inode failed @ nid %llu" , root.nid |0ULL );return ret;
lib/fragments.c +1 -1
@@ -229,7 +229,7 @@ void z_erofs_fragments_commit(struct erofs_inode *inode) inode->datalayout =EROFS_INODE_COMPRESSED_FULL ; inode->z_advise |=Z_EROFS_ADVISE_FRAGMENT_PCLUSTER ; -erofs_sb_set_fragments (); +erofs_sb_set_fragments (inode->sbi); } int z_erofs_pack_file_from_fd(struct erofs_inode *inode, int fd,
lib/inode.c +65 -53
363 lines not on this page · raw message
lib/io.c +55 -64
276 lines not on this page · raw message
lib/namei.c +21 -15
@@ -22,15 +22,18 @@ static dev_t erofs_new_decode_dev(u32 dev)return makedev (major, minor); } -int erofs_read_inode_from_disk (struct erofs_inode *vi) +int erofs_read_inode_from_disk (struct erofs_sb_info *sbi,struct erofs_inode *vi) {int ret, ifmt;char buf[sizeof (struct erofs_inode_extended )];struct erofs_inode_compact *dic;struct erofs_inode_extended *die; -const erofs_off_t inode_loc =erofs_iloc (vi); +erofs_off_t inode_loc; - ret =dev_read (0 , buf, inode_loc,sizeof (*dic)); + vi->sbi = sbi; + inode_loc =erofs_iloc (vi); + + ret =dev_read (sbi,0 , buf, inode_loc,sizeof (*dic));if (ret <0 )return -EIO ;
@@ -47,7 +50,7 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi)case EROFS_INODE_LAYOUT_EXTENDED : vi->inode_isize =sizeof (struct erofs_inode_extended ); - ret =dev_read (0 , buf +sizeof (*dic), inode_loc +sizeof (*dic), + ret =dev_read (sbi,0 , buf +sizeof (*dic), inode_loc +sizeof (*dic),sizeof (*die) -sizeof (*dic));if (ret <0 )return -EIO ;
@@ -114,8 +117,8 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi) vi->i_gid =le16_to_cpu (dic->i_gid); vi->i_nlink =le16_to_cpu (dic->i_nlink); - vi->i_mtime = sbi.build_time; - vi->i_mtime_nsec = sbi.build_time_nsec; + vi->i_mtime = sbi->build_time; + vi->i_mtime_nsec = sbi->build_time_nsec; vi->i_size =le32_to_cpu (dic->i_size);if (vi->datalayout ==EROFS_INODE_CHUNK_BASED )
@@ -134,10 +137,10 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi) vi->u.chunkformat, vi->nid | 0ULL);return -EOPNOTSUPP ; } - vi->u.chunkbits = sbi.blkszbits + + vi->u.chunkbits = sbi->blkszbits + (vi->u.chunkformat &EROFS_CHUNK_FORMAT_BLKBITS_MASK ); }else if (erofs_inode_is_data_compressed (vi->datalayout)) { -if (erofs_blksiz () !=EROFS_MAX_BLOCK_SIZE ) +if (erofs_blksiz (vi->sbi) !=EROFS_MAX_BLOCK_SIZE )return -EOPNOTSUPP ;return z_erofs_fill_inode (vi); }
@@ -185,6 +188,7 @@ struct erofs_dirent *find_target_dirent(erofs_nid_t pnid, }struct nameidata { +struct erofs_sb_info *sbi;erofs_nid_t nid;unsigned int ftype; };
@@ -195,16 +199,17 @@ int erofs_namei(struct nameidata *nd, const char *name, unsigned int len)int ret;char buf[EROFS_MAX_BLOCK_SIZE ];struct erofs_inode vi = { .nid = nid }; +struct erofs_sb_info *sbi = nd->sbi;erofs_off_t offset; - ret =erofs_read_inode_from_disk (&vi); + ret =erofs_read_inode_from_disk (sbi, &vi);if (ret)return ret; offset =0 ;while (offset < vi.i_size) {erofs_off_t maxsize =min_t (erofs_off_t, - vi.i_size - offset,erofs_blksiz ()); + vi.i_size - offset,erofs_blksiz (sbi));struct erofs_dirent *de = (void *)buf;unsigned int nameoff;
@@ -214,7 +219,7 @@ int erofs_namei(struct nameidata *nd, const char *name, unsigned int len) nameoff =le16_to_cpu (de->nameoff);if (nameoff <sizeof (struct erofs_dirent ) || - nameoff >=erofs_blksiz ()) { + nameoff >=erofs_blksiz (sbi)) {erofs_err ("invalid de[0].nameoff %u @ nid %llu" , nameoff, nid |0ULL );return -EFSCORRUPTED ;
@@ -236,7 +241,7 @@ int erofs_namei(struct nameidata *nd, const char *name, unsigned int len)static int link_path_walk (const char *name,struct nameidata *nd) { - nd->nid = sbi.root_nid; + nd->nid = nd->sbi->root_nid;while (*name =='/' ) name++;
@@ -263,15 +268,16 @@ static int link_path_walk(const char *name, struct nameidata *nd)return 0 ; } -int erofs_ilookup (const char *path,struct erofs_inode *vi) +int erofs_ilookup (struct erofs_sb_info *sbi,const char *path, +struct erofs_inode *vi) {int ret; -struct nameidata nd; +struct nameidata nd = { .sbi = sbi }; ret =link_path_walk (path, &nd);if (ret)return ret; vi->nid = nd.nid; -return erofs_read_inode_from_disk (vi); +return erofs_read_inode_from_disk (sbi, vi); }
lib/super.c +26 -25
89 lines not on this page · raw message
lib/tar.c +19 -17
@@ -161,8 +161,8 @@ static struct erofs_dentry *tarerofs_mkdir(struct erofs_inode *dir, const char * inode->i_parent = dir; inode->i_uid =getuid (); inode->i_gid =getgid (); - inode->i_mtime = sbi.build_time; - inode->i_mtime_nsec = sbi.build_time_nsec; + inode->i_mtime = inode->sbi->build_time; + inode->i_mtime_nsec = inode->sbi->build_time_nsec;tarerofs_init_empty_dir (inode); d =erofs_d_alloc (dir, s);
@@ -353,14 +353,15 @@ out:int tarerofs_write_chunk_indexes (struct erofs_inode *inode,erofs_blk_t blkaddr) { +struct erofs_sb_info *sbi = inode->sbi;unsigned int chunkbits =ilog2 (inode->i_size -1 ) +1 ;unsigned int count, unit;erofs_off_t chunksize, len, pos;struct erofs_inode_chunk_index *idx; -if (chunkbits < sbi.blkszbits) - chunkbits = sbi.blkszbits; - inode->u.chunkformat |= chunkbits - sbi.blkszbits; +if (chunkbits < sbi->blkszbits) + chunkbits = sbi->blkszbits; + inode->u.chunkformat |= chunkbits - sbi->blkszbits; inode->u.chunkformat |=EROFS_CHUNK_FORMAT_INDEXES ; chunksize =1ULL << chunkbits; count =DIV_ROUND_UP (inode->i_size, chunksize);
@@ -382,7 +383,7 @@ int tarerofs_write_chunk_indexes(struct erofs_inode *inode, erofs_blk_t blkaddr)return PTR_ERR (chunk); *(void **)idx++ = chunk; - blkaddr +=erofs_blknr (len); + blkaddr +=erofs_blknr (sbi, len); } inode->datalayout =EROFS_INODE_CHUNK_BASED ;return 0 ;
@@ -410,6 +411,7 @@ int tarerofs_parse_tar(struct erofs_inode *root, struct erofs_tarfile *tar) {char path[PATH_MAX ];struct erofs_pax_header eh = tar->global; +struct erofs_sb_info *sbi = root->sbi;bool e, whout, opq;struct stat st;erofs_off_t tar_offset, data_offset;
@@ -616,7 +618,7 @@ restart: eh.link =strndup (th.linkname,sizeof (th.linkname)); } -if (tar->index_mode &&erofs_blkoff (tar_offset +sizeof (th))) { +if (tar->index_mode &&erofs_blkoff (sbi, tar_offset +sizeof (th))) {erofs_err ("invalid tar data alignment @ %llu" , tar_offset); ret = -EIO ; goto out;
@@ -719,7 +721,7 @@ new_inode:memcpy (inode->i_link, eh.link, inode->i_size +1 ); }else if (tar->index_mode) { ret =tarerofs_write_chunk_indexes (inode, -erofs_blknr (data_offset)); +erofs_blknr (sbi, data_offset));if (ret) goto out;if (erofs_lskip (tar->fd, inode->i_size)) {
@@ -774,7 +776,7 @@ invalid_tar:static struct erofs_buffer_head *bh_devt; -int tarerofs_reserve_devtable (unsigned int devices) +int tarerofs_reserve_devtable (struct erofs_sb_info *sbi,unsigned int devices) {if (!devices)return 0 ;
@@ -786,27 +788,27 @@ int tarerofs_reserve_devtable(unsigned int devices)erofs_mapbh (bh_devt->block); bh_devt->op = &erofs_skip_write_bhops; - sbi.devt_slotoff =erofs_btell (bh_devt, false) /EROFS_DEVT_SLOT_SIZE ; - sbi.extra_devices = devices; -erofs_sb_set_device_table (); + sbi->devt_slotoff =erofs_btell (bh_devt, false) /EROFS_DEVT_SLOT_SIZE ; + sbi->extra_devices = devices; +erofs_sb_set_device_table (sbi);return 0 ; } -int tarerofs_write_devtable (struct erofs_tarfile *tar) +int tarerofs_write_devtable (struct erofs_sb_info *sbi,struct erofs_tarfile *tar) {erofs_off_t pos_out;unsigned int i; -if (!sbi.extra_devices) +if (!sbi->extra_devices)return 0 ; pos_out =erofs_btell (bh_devt, false); -for (i =0 ; i < sbi.extra_devices; ++i) { +for (i =0 ; i < sbi->extra_devices; ++i) {struct erofs_deviceslot dis = { - .blocks =erofs_blknr (tar->offset), + .blocks =erofs_blknr (sbi, tar->offset), };int ret; - ret =dev_write (&dis, pos_out,sizeof (dis)); + ret =dev_write (sbi, &dis, pos_out,sizeof (dis));if (ret)return ret; pos_out +=sizeof (dis);
lib/xattr.c +41 -34
207 lines not on this page · raw message
mkfs/main.c +31 -31
62 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.19.1.6.gb485710b
Part of the diff is not shown here. View the raw message.
PATCH v3 2/2 erofs-utils: lib: avoid global sbi dependencies (take 1)
From: Jingbo Xu <[email protected]>
Later mkfs is going to be able to convert multiple erofs images into one merged erofs image, in which case there are multiple device contexts and sbi instances.
In preparation for that, remove global device context and sbi if possible except the buffer cache implementation, as there's still only one erofs output image.
The device context is now folded into sbi. Global sbi still exists but it is only used by binaries directly, e.g. mkfs/dump/fsck.
---
I plan to apply this patch.
dump/main.c | 28 ++--- fsck/main.c | 38 +++---- fuse/main.c | 20 ++-- include/erofs/blobchunk.h | 4 +- include/erofs/cache.h | 6 +- include/erofs/compress.h | 9 +- include/erofs/compress_hints.h | 2 +- include/erofs/decompress.h | 1 + include/erofs/dir.h | 3 +- include/erofs/internal.h | 48 +++++---- include/erofs/io.h | 38 +++---- include/erofs/tar.h | 4 +- include/erofs/xattr.h | 16 +-- lib/blobchunk.c | 46 ++++---- lib/cache.c | 47 +++++---- lib/compress.c | 187 ++++++++++++++++++--------------- lib/compress_hints.c | 10 +- lib/compressor.c | 15 +-- lib/compressor.h | 4 +- lib/compressor_lz4.c | 2 +- lib/compressor_lz4hc.c | 2 +- lib/data.c | 66 +++++++----- lib/decompress.c | 29 ++--- lib/dir.c | 25 +++-- lib/fragments.c | 2 +- lib/inode.c | 118 +++++++++++---------- lib/io.c | 119 ++++++++++----------- lib/namei.c | 31 +++--- lib/super.c | 51 ++++----- lib/tar.c | 36 ++++--- lib/xattr.c | 75 +++++++------ lib/zmap.c | 37 ++++--- mkfs/main.c | 62 +++++------ 33 files changed, 640 insertions(+), 541 deletions(-)
dump/main.c +14 -14
@@ -154,7 +154,7 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)usage ();exit (0 );case 3 : - err =blob_open_ro (optarg); + err =blob_open_ro (&sbi, optarg);if (err)return err; ++sbi.extra_devices;
@@ -202,7 +202,7 @@ static int erofsdump_get_occupied_size(struct erofs_inode *inode,case EROFS_INODE_COMPRESSED_FULL :case EROFS_INODE_COMPRESSED_COMPACT : stats.compressed_files++; - *size = inode->u.i_blocks *erofs_blksiz (); + *size = inode->u.i_blocks *erofs_blksiz (inode->sbi);break ;default :erofs_err ("unknown datalayout" );
@@ -270,9 +270,9 @@ static int erofsdump_read_packed_inode(void) {int err;erofs_off_t occupied_size =0 ; -struct erofs_inode vi = { .nid = sbi.packed_nid }; +struct erofs_inode vi = { .sbi = &sbi, .nid = sbi.packed_nid }; -if (!(erofs_sb_has_fragments () && sbi.packed_nid >0 )) +if (!(erofs_sb_has_fragments (&sbi) && sbi.packed_nid >0 ))return 0 ; err =erofs_read_inode_from_disk (&vi);
@@ -296,7 +296,7 @@ static int erofsdump_readdir(struct erofs_dir_context *ctx) {int err;erofs_off_t occupied_size =0 ; -struct erofs_inode vi = { .nid = ctx->de_nid }; +struct erofs_inode vi = { .sbi = &sbi, .nid = ctx->de_nid }; err =erofs_read_inode_from_disk (&vi);if (err) {
@@ -351,7 +351,7 @@ static void erofsdump_show_fileinfo(bool show_extent)int err, i;erofs_off_t size;u16 access_mode; -struct erofs_inode inode = { .nid = dumpcfg.nid }; +struct erofs_inode inode = { .sbi = &sbi, .nid = dumpcfg.nid };char path[PATH_MAX ];char access_mode_str[] ="rwxrwxrwx" ;char timebuf[128 ] = {0 };
@@ -382,7 +382,7 @@ static void erofsdump_show_fileinfo(bool show_extent)return ; } - err =erofs_get_pathname (inode.nid, path,sizeof (path)); + err =erofs_get_pathname (inode.sbi, inode.nid, path,sizeof (path));if (err <0 ) {strncpy (path,"(not found)" ,sizeof (path) -1 ); path[sizeof (path) -1 ] ='\0' ;
@@ -447,7 +447,7 @@ static void erofsdump_show_fileinfo(bool show_extent) .m_deviceid = map.m_deviceid, .m_pa = map.m_pa, }; - err =erofs_map_dev (&mdev); + err =erofs_map_dev (inode.sbi, &mdev);if (err) {erofs_err ("failed to map device" );return ;
@@ -604,7 +604,7 @@ static void erofsdump_show_superblock(void) sbi.xattr_blkaddr);fprintf (stdout,"Filesystem root nid: %llu\n" , sbi.root_nid |0ULL ); -if (erofs_sb_has_fragments () && sbi.packed_nid >0 ) +if (erofs_sb_has_fragments (&sbi) && sbi.packed_nid >0 )fprintf (stdout,"Filesystem packed nid: %llu\n" , sbi.packed_nid |0ULL ); fprintf(stdout, "Filesystem inode count: %llu\n",
@@ -636,13 +636,13 @@ int main(int argc, char **argv) goto exit; } - err =dev_open_ro (cfg.c_img_path); + err =dev_open_ro (&sbi, cfg.c_img_path);if (err) {erofs_err ("failed to open image file" ); goto exit; } - err =erofs_read_superblock (); + err =erofs_read_superblock (&sbi);if (err) {erofs_err ("failed to read superblock" ); goto exit_dev_close;
@@ -667,11 +667,11 @@ int main(int argc, char **argv)erofsdump_show_fileinfo (dumpcfg.show_extent); exit_put_super: -erofs_put_super (); +erofs_put_super (&sbi); exit_dev_close: -dev_close (); +dev_close (&sbi); exit: -blob_closeall (); +blob_closeall (&sbi);erofs_exit_configure ();return err; }
fsck/main.c +20 -18
@@ -158,7 +158,7 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv) }break ;case 3 : - ret =blob_open_ro (optarg); + ret =blob_open_ro (&sbi, optarg);if (ret)return ret; ++sbi.extra_devices;
@@ -279,7 +279,7 @@ static int erofs_check_sb_chksum(void)struct erofs_super_block *sb;int ret; - ret =blk_read (0 , buf,0 ,1 ); + ret =blk_read (&sbi,0 , buf,0 ,1 );if (ret) {erofs_err ("failed to read superblock to check checksum: %d" , ret);
@@ -289,7 +289,7 @@ static int erofs_check_sb_chksum(void) sb = (struct erofs_super_block *)(buf +EROFS_SUPER_OFFSET ); sb->checksum =0 ; - crc =erofs_crc32c (~0 , (u8 *)sb,erofs_blksiz () -EROFS_SUPER_OFFSET ); + crc =erofs_crc32c (~0 , (u8 *)sb,erofs_blksiz (&sbi) -EROFS_SUPER_OFFSET );if (crc != sbi.checksum) {erofs_err ("superblock chksum doesn't match: saved(%08xh) calculated(%08xh)" , sbi.checksum, crc);
@@ -302,6 +302,7 @@ static int erofs_check_sb_chksum(void)static int erofs_verify_xattr (struct erofs_inode *inode) { +struct erofs_sb_info *sbi = inode->sbi;unsigned int xattr_hdr_size =sizeof (struct erofs_xattr_ibody_header );unsigned int xattr_entry_size =sizeof (struct erofs_xattr_entry );erofs_off_t addr;
@@ -326,7 +327,7 @@ static int erofs_verify_xattr(struct erofs_inode *inode) } addr =erofs_iloc (inode) + inode->inode_isize; - ret =dev_read (0 , buf, addr, xattr_hdr_size); + ret =dev_read (sbi,0 , buf, addr, xattr_hdr_size);if (ret <0 ) {erofs_err ("failed to read xattr header @ nid %llu: %d" , inode->nid |0ULL , ret);
@@ -335,12 +336,12 @@ static int erofs_verify_xattr(struct erofs_inode *inode) ih = (struct erofs_xattr_ibody_header *)buf; xattr_shared_count = ih->h_shared_count; - ofs =erofs_blkoff (addr) + xattr_hdr_size; + ofs =erofs_blkoff (sbi, addr) + xattr_hdr_size; addr += xattr_hdr_size; remaining -= xattr_hdr_size;for (i =0 ; i < xattr_shared_count; ++i) { -if (ofs >=erofs_blksiz ()) { -if (ofs !=erofs_blksiz ()) { +if (ofs >=erofs_blksiz (sbi)) { +if (ofs !=erofs_blksiz (sbi)) {erofs_err ("unaligned xattr entry in xattr shared area @ nid %llu" , inode->nid |0ULL ); ret = -EFSCORRUPTED ;
@@ -356,7 +357,7 @@ static int erofs_verify_xattr(struct erofs_inode *inode)while (remaining >0 ) {unsigned int entry_sz; - ret =dev_read (0 , buf, addr, xattr_entry_size); + ret =dev_read (sbi,0 , buf, addr, xattr_entry_size);if (ret) {erofs_err ("failed to read xattr entry @ nid %llu: %d" , inode->nid |0ULL , ret);
@@ -483,7 +484,7 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)u64 count =min_t (u64, alloc_rawsize, map.m_llen); - ret =erofs_read_one_data (&map, raw, p, count); + ret =erofs_read_one_data (inode, &map, raw, p, count);if (ret) goto out;
@@ -497,8 +498,8 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)if (fsckcfg.print_comp_ratio) {if (!erofs_is_packed_inode (inode)) - fsckcfg.logical_blocks +=BLK_ROUND_UP (inode->i_size); - fsckcfg.physical_blocks +=BLK_ROUND_UP (pchunk_len); + fsckcfg.logical_blocks +=BLK_ROUND_UP (inode->sbi, inode->i_size); + fsckcfg.physical_blocks +=BLK_ROUND_UP (inode->sbi, pchunk_len); } out:if (raw)
@@ -845,6 +846,7 @@ static int erofsfsck_check_inode(erofs_nid_t pnid, erofs_nid_t nid)erofs_dbg ("check inode: nid(%llu)" , nid |0ULL ); inode.nid = nid; + inode.sbi = &sbi; ret =erofs_read_inode_from_disk (&inode);if (ret) {if (ret == -EIO )
@@ -920,19 +922,19 @@ int main(int argc, char *argv[]) cfg.c_dbg_lvl =-1 ;#endif - err =dev_open_ro (cfg.c_img_path); + err =dev_open_ro (&sbi, cfg.c_img_path);if (err) {erofs_err ("failed to open image file" ); goto exit; } - err =erofs_read_superblock (); + err =erofs_read_superblock (&sbi);if (err) {erofs_err ("failed to read superblock" ); goto exit_dev_close; } -if (erofs_sb_has_sb_chksum () &&erofs_check_sb_chksum ()) { +if (erofs_sb_has_sb_chksum (&sbi) &&erofs_check_sb_chksum ()) {erofs_err ("failed to verify superblock checksum" ); goto exit_put_super; }
@@ -940,7 +942,7 @@ int main(int argc, char *argv[])if (fsckcfg.extract_path)erofsfsck_hardlink_init (); -if (erofs_sb_has_fragments () && sbi.packed_nid >0 ) { +if (erofs_sb_has_fragments (&sbi) && sbi.packed_nid >0 ) { err =erofsfsck_check_inode (sbi.packed_nid, sbi.packed_nid);if (err) {erofs_err ("failed to verify packed file" );
@@ -974,11 +976,11 @@ exit_hardlink:if (fsckcfg.extract_path)erofsfsck_hardlink_exit (); exit_put_super: -erofs_put_super (); +erofs_put_super (&sbi); exit_dev_close: -dev_close (); +dev_close (&sbi); exit: -blob_closeall (); +blob_closeall (&sbi);erofs_exit_configure ();return err ?1 :0 ; }
fuse/main.c +12 -8
@@ -49,6 +49,7 @@ int erofsfuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, };erofs_dbg ("readdir:%s offset=%llu" , path, (long long )offset); + dir.sbi = &sbi; ret =erofs_ilookup (path, &dir);if (ret)return ret;
@@ -84,7 +85,7 @@ static int erofsfuse_open(const char *path, struct fuse_file_info *fi)static int erofsfuse_getattr (const char *path,struct stat *stbuf) { -struct erofs_inode vi = {}; +struct erofs_inode vi = { .sbi = &sbi };int ret;erofs_dbg ("getattr(%s)" , path);
@@ -95,7 +96,7 @@ static int erofsfuse_getattr(const char *path, struct stat *stbuf) stbuf->st_mode = vi.i_mode; stbuf->st_nlink = vi.i_nlink; stbuf->st_size = vi.i_size; - stbuf->st_blocks =roundup (vi.i_size,erofs_blksiz ()) >>9 ; + stbuf->st_blocks =roundup (vi.i_size,erofs_blksiz (vi.sbi)) >>9 ; stbuf->st_uid = vi.i_uid; stbuf->st_gid = vi.i_gid;if (S_ISBLK (vi.i_mode) ||S_ISCHR (vi.i_mode))
@@ -115,6 +116,7 @@ static int erofsfuse_read(const char *path, char *buffer,erofs_dbg ("path:%s size=%zd offset=%llu" , path, size, (long long )offset); + vi.sbi = &sbi; ret =erofs_ilookup (path, &vi);if (ret)return ret;
@@ -155,6 +157,7 @@ static int erofsfuse_getxattr(const char *path, const char *name, char *value,erofs_dbg ("getxattr(%s): name=%s size=%llu" , path, name, size); + vi.sbi = &sbi; ret =erofs_ilookup (path, &vi);if (ret)return ret;
@@ -169,6 +172,7 @@ static int erofsfuse_listxattr(const char *path, char *list, size_t size)erofs_dbg ("listxattr(%s): size=%llu" , path, size); + vi.sbi = &sbi; ret =erofs_ilookup (path, &vi);if (ret)return ret;
@@ -244,7 +248,7 @@ static int optional_opt_func(void *data, const char *arg, int key,switch (key) {case 1 : - ret =blob_open_ro (arg +sizeof ("--device=" ) -1 ); + ret =blob_open_ro (&sbi, arg +sizeof ("--device=" ) -1 );if (ret)return -1 ; ++sbi.extra_devices;
@@ -325,13 +329,13 @@ int main(int argc, char *argv[]) cfg.c_offset = fusecfg.offset;erofsfuse_dumpcfg (); - ret =dev_open_ro (fusecfg.disk); + ret =dev_open_ro (&sbi, fusecfg.disk);if (ret) {fprintf (stderr,"failed to open: %s\n" , fusecfg.disk); goto err_fuse_free_args; } - ret =erofs_read_superblock (); + ret =erofs_read_superblock (&sbi);if (ret) {fprintf (stderr,"failed to read erofs super block\n" ); goto err_dev_close;
@@ -339,10 +343,10 @@ int main(int argc, char *argv[]) ret =fuse_main (args.argc, args.argv, &erofs_ops,NULL ); -erofs_put_super (); +erofs_put_super (&sbi); err_dev_close: -blob_closeall (); -dev_close (); +blob_closeall (&sbi); +dev_close (&sbi); err_fuse_free_args:fuse_opt_free_args (&args); err:
include/erofs/blobchunk.h +2 -2
@@ -18,10 +18,10 @@ struct erofs_blobchunk *erofs_get_unhashed_chunk(erofs_off_t chunksize, unsigned int device_id, erofs_blk_t blkaddr);int erofs_blob_write_chunk_indexes (struct erofs_inode *inode,erofs_off_t off);int erofs_blob_write_chunked_file (struct erofs_inode *inode,int fd); -int erofs_blob_remap (void ); +int erofs_blob_remap (struct erofs_sb_info *sbi);void erofs_blob_exit (void );int erofs_blob_init (const char *blobfile_path); -int erofs_generate_devtable (void ); +int erofs_generate_devtable (struct erofs_sb_info *sbi); #ifdef __cplusplus }
include/erofs/cache.h +3 -3
@@ -57,14 +57,14 @@ struct erofs_buffer_block {static inline const int get_alignsize (int type,int *type_ret) {if (type ==DATA ) -return erofs_blksiz (); +return erofs_blksiz (&sbi);if (type ==INODE ) { *type_ret =META ;return sizeof (struct erofs_inode_compact ); }else if (type ==DIRA ) { *type_ret =META ; -return erofs_blksiz (); +return erofs_blksiz (&sbi); }else if (type ==XATTR ) { *type_ret =META ;return sizeof (struct erofs_xattr_entry );
@@ -88,7 +88,7 @@ static inline erofs_off_t erofs_btell(struct erofs_buffer_head *bh, bool end)if (bb->blkaddr ==NULL_ADDR )return NULL_ADDR_UL ; -return erofs_pos (bb->blkaddr) + +return erofs_pos (&sbi, bb->blkaddr) + (end ?list_next_entry (bh, list)->off : bh->off); }
include/erofs/compress.h +6 -3
@@ -19,18 +19,21 @@ extern "C"void z_erofs_drop_inline_pcluster (struct erofs_inode *inode);int erofs_write_compressed_file (struct erofs_inode *inode,int fd); -int z_erofs_compress_init (struct erofs_buffer_head *bh); +int z_erofs_compress_init (struct erofs_sb_info *sbi, +struct erofs_buffer_head *bh);int z_erofs_compress_exit (void );const char *z_erofs_list_available_compressors (unsigned int i);static inline bool erofs_is_packed_inode (struct erofs_inode *inode) { +erofs_nid_t packed_nid = inode->sbi->packed_nid; +if (inode->nid ==EROFS_PACKED_NID_UNALLOCATED ) { -DBG_BUGON (sbi.packed_nid !=EROFS_PACKED_NID_UNALLOCATED ); +DBG_BUGON (packed_nid !=EROFS_PACKED_NID_UNALLOCATED );return true; } -return (sbi.packed_nid >0 && inode->nid == sbi.packed_nid); +return (packed_nid >0 && inode->nid == packed_nid); }#ifdef __cplusplus
include/erofs/compress_hints.h +1 -1
@@ -25,7 +25,7 @@ struct erofs_compress_hints {bool z_erofs_apply_compress_hints (struct erofs_inode *inode);void erofs_cleanup_compress_hints (void ); -int erofs_load_compress_hints (void ); +int erofs_load_compress_hints (struct erofs_sb_info *sbi); #ifdef __cplusplus }
include/erofs/decompress.h +1 -0
@@ -14,6 +14,7 @@ extern "C"#include "internal.h" struct z_erofs_decompress_req { +struct erofs_sb_info *sbi;char *in, *out;/*
include/erofs/dir.h +2 -1
@@ -62,7 +62,8 @@ struct erofs_dir_context {/* Iterate over inodes that are in directory */ int erofs_iterate_dir (struct erofs_dir_context *ctx,bool fsck);/* Get a full pathname of the inode NID */ -int erofs_get_pathname (erofs_nid_t nid,char *buf,size_t size); +int erofs_get_pathname (struct erofs_sb_info *sbi,erofs_nid_t nid, +char *buf,size_t size); #ifdef __cplusplus }
include/erofs/internal.h +28 -20
111 lines not on this page · raw message
include/erofs/io.h +20 -18
@@ -22,34 +22,36 @@ extern "C"#define O_BINARY 0#endif -void blob_closeall (void ); -int blob_open_ro (const char *dev); -int dev_open (const char *devname); -int dev_open_ro (const char *dev); -void dev_close (void ); -int dev_write (const void *buf,u64 offset,size_t len); -int dev_read (int device_id,void *buf,u64 offset,size_t len); -int dev_fillzero (u64 offset,size_t len,bool padding); -int dev_fsync (void ); -int dev_resize (erofs_blk_t nblocks); -u64 dev_length (void ); - -extern int erofs_devfd; +void blob_closeall (struct erofs_sb_info *sbi); +int blob_open_ro (struct erofs_sb_info *sbi,const char *dev); +int dev_open (struct erofs_sb_info *sbi,const char *devname); +int dev_open_ro (struct erofs_sb_info *sbi,const char *dev); +void dev_close (struct erofs_sb_info *sbi); +int dev_write (struct erofs_sb_info *sbi,const void *buf, +u64 offset,size_t len); +int dev_read (struct erofs_sb_info *sbi,int device_id, +void *buf,u64 offset,size_t len); +int dev_fillzero (struct erofs_sb_info *sbi,u64 offset, +size_t len,bool padding); +int dev_fsync (struct erofs_sb_info *sbi); +int dev_resize (struct erofs_sb_info *sbi,erofs_blk_t nblocks);ssize_t erofs_copy_file_range (int fd_in,erofs_off_t *off_in,int fd_out,erofs_off_t *off_out,size_t length); -static inline int blk_write (const void *buf,erofs_blk_t blkaddr, -u32 nblocks) +static inline int blk_write (struct erofs_sb_info *sbi,const void *buf, +erofs_blk_t blkaddr,u32 nblocks) { -return dev_write (buf,erofs_pos (blkaddr),erofs_pos (nblocks)); +return dev_write (sbi, buf,erofs_pos (sbi, blkaddr), +erofs_pos (sbi, nblocks)); } -static inline int blk_read (int device_id,void *buf, +static inline int blk_read (struct erofs_sb_info *sbi,int device_id,void *buf,erofs_blk_t start,u32 nblocks) { -return dev_read (device_id, buf,erofs_pos (start),erofs_pos (nblocks)); +return dev_read (sbi, device_id, buf,erofs_pos (sbi, start), +erofs_pos (sbi, nblocks)); }#ifdef __cplusplus
include/erofs/tar.h +2 -2
@@ -23,7 +23,7 @@ struct erofs_tarfile {int tarerofs_init_empty_dir (struct erofs_inode *inode);int tarerofs_parse_tar (struct erofs_inode *root,struct erofs_tarfile *tar); -int tarerofs_reserve_devtable (unsigned int devices); -int tarerofs_write_devtable (struct erofs_tarfile *tar); +int tarerofs_reserve_devtable (struct erofs_sb_info *sbi,unsigned int devices); +int tarerofs_write_devtable (struct erofs_sb_info *sbi,struct erofs_tarfile *tar);#endif
include/erofs/xattr.h +9 -7
@@ -24,15 +24,17 @@ static inline unsigned int inlinexattr_header_size(struct erofs_inode *vi)sizeof (u32) * vi->xattr_shared_count; } -static inline erofs_blk_t xattrblock_addr (unsigned int xattr_id) +static inline erofs_blk_t xattrblock_addr (struct erofs_inode *vi, +unsigned int xattr_id) { -return sbi.xattr_blkaddr + - ((xattr_id *sizeof (__u32)) >> sbi.blkszbits); +return vi->sbi->xattr_blkaddr + +erofs_blknr (vi->sbi, xattr_id *sizeof (__u32)); } -static inline unsigned int xattrblock_offset (unsigned int xattr_id) +static inline unsigned int xattrblock_offset (struct erofs_inode *vi, +unsigned int xattr_id) { -return (xattr_id *sizeof (__u32)) & (erofs_blksiz () -1 ); +return erofs_blkoff (vi->sbi, xattr_id *sizeof (__u32)); }#define EROFS_INODE_XATTR_ICOUNT (_size) ({\
@@ -75,11 +77,11 @@ static inline unsigned int xattrblock_offset(unsigned int xattr_id)int erofs_scan_file_xattrs (struct erofs_inode *inode);int erofs_prepare_xattr_ibody (struct erofs_inode *inode);char *erofs_export_xattr_ibody (struct list_head *ixattrs,unsigned int size); -int erofs_build_shared_xattrs_from_path (const char *path); +int erofs_build_shared_xattrs_from_path (struct erofs_sb_info *sbi,const char *path);int erofs_xattr_insert_name_prefix (const char *prefix);void erofs_xattr_cleanup_name_prefixes (void ); -int erofs_xattr_write_name_prefixes (FILE *f); +int erofs_xattr_write_name_prefixes (struct erofs_sb_info *sbi,FILE *f);int erofs_setxattr (struct erofs_inode *inode,char *key,const void *value,size_t size);
lib/blobchunk.c +24 -22
124 lines not on this page · raw message
lib/cache.c +25 -22
145 lines not on this page · raw message
lib/compress.c +102 -85
573 lines not on this page · raw message
lib/compress_hints.c +5 -5
@@ -86,7 +86,7 @@ void erofs_cleanup_compress_hints(void) } } -int erofs_load_compress_hints (void ) +int erofs_load_compress_hints (struct erofs_sb_info *sbi) {char buf[PATH_MAX +100 ];FILE *f;
@@ -133,21 +133,21 @@ int erofs_load_compress_hints(void) } } -if (pclustersize %erofs_blksiz ()) { +if (pclustersize %erofs_blksiz (sbi)) {erofs_warn ("invalid physical clustersize %u, " "use default pclusterblks %u" , pclustersize, cfg.c_pclusterblks_def);continue ; }erofs_insert_compress_hints (pattern, - pclustersize /erofs_blksiz (), ccfg); + pclustersize /erofs_blksiz (sbi), ccfg);if (pclustersize > max_pclustersize) max_pclustersize = pclustersize; } -if (cfg.c_pclusterblks_max *erofs_blksiz () < max_pclustersize) { - cfg.c_pclusterblks_max = max_pclustersize /erofs_blksiz (); +if (cfg.c_pclusterblks_max *erofs_blksiz (sbi) < max_pclustersize) { + cfg.c_pclusterblks_max = max_pclustersize /erofs_blksiz (sbi);erofs_warn ("update max pclusterblks to %u" , cfg.c_pclusterblks_max); } out:
lib/compressor.c +9 -6
@@ -42,10 +42,10 @@ int erofs_compress_destsize(const struct erofs_compress *c,if (ret <0 )return ret; -/* XXX: ret >= erofs_blksiz() is a temporary hack for ztailpacking */ -if (inblocks || ret >=erofs_blksiz () || +/* XXX: ret >= destsize_alignsize is a temporary hack for ztailpacking */ +if (inblocks || ret >= c->destsize_alignsize || uncompressed_capacity != *srcsize) - compressed_size =roundup (ret,erofs_blksiz ()); + compressed_size =roundup (ret, c->destsize_alignsize);else compressed_size = ret;DBG_BUGON (c->compress_threshold <100 );
@@ -72,16 +72,19 @@ int erofs_compressor_setlevel(struct erofs_compress *c, int compression_level)return 0 ; } -int erofs_compressor_init (struct erofs_compress *c,char *alg_name) +int erofs_compressor_init (struct erofs_sb_info *sbi, +struct erofs_compress *c,char *alg_name) {int ret, i; + c->sbi = sbi; +/* should be written in "minimum compression ratio * 100" */ c->compress_threshold =100 ;/* optimize for 4k size page */ - c->destsize_alignsize =erofs_blksiz (); - c->destsize_redzone_begin =erofs_blksiz () -16 ; + c->destsize_alignsize =erofs_blksiz (sbi); + c->destsize_redzone_begin =erofs_blksiz (sbi) -16 ; c->destsize_redzone_end =EROFS_CONFIG_COMPR_DEF_BOUNDARY ;if (!alg_name) {
lib/compressor.h +3 -1
@@ -27,6 +27,7 @@ struct erofs_compressor { };struct erofs_compress { +struct erofs_sb_info *sbi;const struct erofs_compressor *alg;unsigned int compress_threshold;
@@ -52,7 +53,8 @@ int erofs_compress_destsize(const struct erofs_compress *c, void *dst, unsigned int dstsize, bool inblocks);int erofs_compressor_setlevel (struct erofs_compress *c,int compression_level); -int erofs_compressor_init (struct erofs_compress *c,char *alg_name); +int erofs_compressor_init (struct erofs_sb_info *sbi, +struct erofs_compress *c,char *alg_name);int erofs_compressor_exit (struct erofs_compress *c);#endif
lib/compressor_lz4.c +1 -1
@@ -33,7 +33,7 @@ static int compressor_lz4_exit(struct erofs_compress *c)static int compressor_lz4_init (struct erofs_compress *c) { c->alg = &erofs_compressor_lz4; - sbi.lz4_max_distance =LZ4_DISTANCE_MAX ; + c->sbi->lz4_max_distance =LZ4_DISTANCE_MAX ;return 0 ; }
lib/compressor_lz4hc.c +1 -1
@@ -44,7 +44,7 @@ static int compressor_lz4hc_init(struct erofs_compress *c)if (!c->private_data)return -ENOMEM ; - sbi.lz4_max_distance =LZ4_DISTANCE_MAX ; + c->sbi->lz4_max_distance =LZ4_DISTANCE_MAX ;return 0 ; }
lib/data.c +37 -29
191 lines not on this page · raw message
lib/decompress.c +17 -12
@@ -97,14 +97,15 @@ static int zerr(int ret)static int z_erofs_decompress_deflate (struct z_erofs_decompress_req *rq) {int ret =0 ; +struct erofs_sb_info *sbi = rq->sbi;u8 *dest = (u8 *)rq->out;u8 *src = (u8 *)rq->in;u8 *buff =NULL ;unsigned int inputmargin =0 ;z_stream strm; -while (!src[inputmargin & (erofs_blksiz () -1 )]) -if (!(++inputmargin & (erofs_blksiz () -1 ))) +while (!src[inputmargin & (erofs_blksiz (sbi) -1 )]) +if (!(++inputmargin & (erofs_blksiz (sbi) -1 )))break ;if (inputmargin >= rq->inputsize)
@@ -158,6 +159,7 @@ out_inflate_end:static int z_erofs_decompress_lzma (struct z_erofs_decompress_req *rq) {int ret =0 ; +struct erofs_sb_info *sbi = rq->sbi;u8 *dest = (u8 *)rq->out;u8 *src = (u8 *)rq->in;u8 *buff =NULL ;
@@ -165,8 +167,8 @@ static int z_erofs_decompress_lzma(struct z_erofs_decompress_req *rq)lzma_stream strm;lzma_ret ret2; -while (!src[inputmargin & (erofs_blksiz () -1 )]) -if (!(++inputmargin & (erofs_blksiz () -1 ))) +while (!src[inputmargin & (erofs_blksiz (sbi) -1 )]) +if (!(++inputmargin & (erofs_blksiz (sbi) -1 )))break ;if (inputmargin >= rq->inputsize)
@@ -224,12 +226,13 @@ static int z_erofs_decompress_lz4(struct z_erofs_decompress_req *rq)char *buff =NULL ;bool support_0padding = false;unsigned int inputmargin =0 ; +struct erofs_sb_info *sbi = rq->sbi; -if (erofs_sb_has_lz4_0padding ()) { +if (erofs_sb_has_lz4_0padding (sbi)) { support_0padding = true; -while (!src[inputmargin & (erofs_blksiz () -1 )]) -if (!(++inputmargin & (erofs_blksiz () -1 ))) +while (!src[inputmargin & (erofs_blksiz (sbi) -1 )]) +if (!(++inputmargin & (erofs_blksiz (sbi) -1 )))break ;if (inputmargin >= rq->inputsize)
@@ -274,22 +277,24 @@ out:int z_erofs_decompress (struct z_erofs_decompress_req *rq) { +struct erofs_sb_info *sbi = rq->sbi; +if (rq->alg ==Z_EROFS_COMPRESSION_INTERLACED ) {unsigned int count, rightpart, skip; -/* XXX: should support inputsize >= erofs_blksiz() later */ -if (rq->inputsize >erofs_blksiz ()) +/* XXX: should support inputsize >= erofs_blksiz(sbi) later */ +if (rq->inputsize >erofs_blksiz (sbi))return -EFSCORRUPTED ; -if (rq->decodedlength >erofs_blksiz ()) +if (rq->decodedlength >erofs_blksiz (sbi))return -EFSCORRUPTED ;if (rq->decodedlength < rq->decodedskip)return -EFSCORRUPTED ; count = rq->decodedlength - rq->decodedskip; - skip =erofs_blkoff (rq->interlaced_offset + rq->decodedskip); - rightpart =min (erofs_blksiz () - skip, count); + skip =erofs_blkoff (sbi, rq->interlaced_offset + rq->decodedskip); + rightpart =min (erofs_blksiz (sbi) - skip, count);memcpy (rq->out, rq->in + skip, rightpart);memcpy (rq->out + rightpart, rq->in, count - rightpart);return 0 ;
lib/dir.c +17 -8
@@ -10,6 +10,7 @@ static int traverse_dirents(struct erofs_dir_context *ctx, bool fsck) {struct erofs_inode *dir = ctx->dir; +struct erofs_sb_info *sbi = dir->sbi;struct erofs_dirent *de = dentry_blk;const struct erofs_dirent *end = dentry_blk + next_nameoff;const char *prev_name =NULL ;
@@ -77,8 +78,8 @@ static int traverse_dirents(struct erofs_dir_context *ctx, goto out; } ctx->flags |=EROFS_READDIR_DOTDOT_FOUND ; -if (sbi.root_nid == dir->nid) { - ctx->pnid = sbi.root_nid; +if (sbi->root_nid == dir->nid) { + ctx->pnid = sbi->root_nid; ctx->flags |=EROFS_READDIR_VALID_PNID ; } if (fsck &&
@@ -124,6 +125,7 @@ out:int erofs_iterate_dir (struct erofs_dir_context *ctx,bool fsck) {struct erofs_inode *dir = ctx->dir; +struct erofs_sb_info *sbi = dir->sbi;int err =0 ;erofs_off_t pos;char buf[EROFS_MAX_BLOCK_SIZE ];
@@ -134,9 +136,9 @@ int erofs_iterate_dir(struct erofs_dir_context *ctx, bool fsck) ctx->flags &= ~EROFS_READDIR_ALL_SPECIAL_FOUND ; pos =0 ;while (pos < dir->i_size) { -erofs_blk_t lblk =erofs_blknr (pos); +erofs_blk_t lblk =erofs_blknr (sbi, pos);erofs_off_t maxsize =min_t (erofs_off_t, - dir->i_size - pos,erofs_blksiz ()); + dir->i_size - pos,erofs_blksiz (sbi));const struct erofs_dirent *de = (const void *)buf;unsigned int nameoff;
@@ -149,7 +151,7 @@ int erofs_iterate_dir(struct erofs_dir_context *ctx, bool fsck) nameoff =le16_to_cpu (de->nameoff);if (nameoff <sizeof (struct erofs_dirent ) || - nameoff >=erofs_blksiz ()) { + nameoff >=erofs_blksiz (sbi)) {erofs_err ("invalid de[0].nameoff %u @ nid %llu, lblk %u" , nameoff, dir->nid |0ULL , lblk);return -EFSCORRUPTED ;
@@ -204,7 +206,10 @@ static int erofs_get_pathname_iter(struct erofs_dir_context *ctx) }if (ctx->de_ftype ==EROFS_FT_DIR || ctx->de_ftype ==EROFS_FT_UNKNOWN ) { -struct erofs_inode dir = { .nid = ctx->de_nid }; +struct erofs_inode dir = { + .sbi = ctx->dir->sbi, + .nid = ctx->de_nid + }; ret =erofs_read_inode_from_disk (&dir);if (ret) {
@@ -230,10 +235,14 @@ static int erofs_get_pathname_iter(struct erofs_dir_context *ctx)return 0 ; } -int erofs_get_pathname (erofs_nid_t nid,char *buf,size_t size) +int erofs_get_pathname (struct erofs_sb_info *sbi,erofs_nid_t nid, +char *buf,size_t size) {int ret; -struct erofs_inode root = { .nid = sbi.root_nid }; +struct erofs_inode root = { + .sbi = sbi, + .nid = sbi->root_nid, + };struct erofs_get_pathname_context pathctx = { .ctx.flags =0 , .ctx.dir = &root,
lib/fragments.c +1 -1
@@ -229,7 +229,7 @@ void z_erofs_fragments_commit(struct erofs_inode *inode) inode->datalayout =EROFS_INODE_COMPRESSED_FULL ; inode->z_advise |=Z_EROFS_ADVISE_FRAGMENT_PCLUSTER ; -erofs_sb_set_fragments (); +erofs_sb_set_fragments (inode->sbi); } int z_erofs_pack_file_from_fd(struct erofs_inode *inode, int fd,
lib/inode.c +65 -53
363 lines not on this page · raw message
lib/io.c +55 -64
276 lines not on this page · raw message
lib/namei.c +19 -12
@@ -26,11 +26,15 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi) {int ret, ifmt;char buf[sizeof (struct erofs_inode_extended )]; +struct erofs_sb_info *sbi = vi->sbi;struct erofs_inode_compact *dic;struct erofs_inode_extended *die; -const erofs_off_t inode_loc =erofs_iloc (vi); +erofs_off_t inode_loc; - ret =dev_read (0 , buf, inode_loc,sizeof (*dic)); +DBG_BUGON (!sbi); + inode_loc =erofs_iloc (vi); + + ret =dev_read (sbi,0 , buf, inode_loc,sizeof (*dic));if (ret <0 )return -EIO ;
@@ -47,7 +51,8 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi)case EROFS_INODE_LAYOUT_EXTENDED : vi->inode_isize =sizeof (struct erofs_inode_extended ); - ret =dev_read (0 , buf +sizeof (*dic), inode_loc +sizeof (*dic), + ret =dev_read (sbi,0 , buf +sizeof (*dic), + inode_loc +sizeof (*dic),sizeof (*die) -sizeof (*dic));if (ret <0 )return -EIO ;
@@ -114,8 +119,8 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi) vi->i_gid =le16_to_cpu (dic->i_gid); vi->i_nlink =le16_to_cpu (dic->i_nlink); - vi->i_mtime = sbi.build_time; - vi->i_mtime_nsec = sbi.build_time_nsec; + vi->i_mtime = sbi->build_time; + vi->i_mtime_nsec = sbi->build_time_nsec; vi->i_size =le32_to_cpu (dic->i_size);if (vi->datalayout ==EROFS_INODE_CHUNK_BASED )
@@ -134,10 +139,10 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi) vi->u.chunkformat, vi->nid | 0ULL);return -EOPNOTSUPP ; } - vi->u.chunkbits = sbi.blkszbits + + vi->u.chunkbits = sbi->blkszbits + (vi->u.chunkformat &EROFS_CHUNK_FORMAT_BLKBITS_MASK ); }else if (erofs_inode_is_data_compressed (vi->datalayout)) { -if (erofs_blksiz () !=EROFS_MAX_BLOCK_SIZE ) +if (erofs_blksiz (vi->sbi) !=EROFS_MAX_BLOCK_SIZE )return -EOPNOTSUPP ;return z_erofs_fill_inode (vi); }
@@ -185,6 +190,7 @@ struct erofs_dirent *find_target_dirent(erofs_nid_t pnid, }struct nameidata { +struct erofs_sb_info *sbi;erofs_nid_t nid;unsigned int ftype; };
@@ -194,7 +200,8 @@ int erofs_namei(struct nameidata *nd, const char *name, unsigned int len)erofs_nid_t nid = nd->nid;int ret;char buf[EROFS_MAX_BLOCK_SIZE ]; -struct erofs_inode vi = { .nid = nid }; +struct erofs_sb_info *sbi = nd->sbi; +struct erofs_inode vi = { .sbi = sbi, .nid = nid };erofs_off_t offset; ret =erofs_read_inode_from_disk (&vi);
@@ -204,7 +211,7 @@ int erofs_namei(struct nameidata *nd, const char *name, unsigned int len) offset =0 ;while (offset < vi.i_size) {erofs_off_t maxsize =min_t (erofs_off_t, - vi.i_size - offset,erofs_blksiz ()); + vi.i_size - offset,erofs_blksiz (sbi));struct erofs_dirent *de = (void *)buf;unsigned int nameoff;
@@ -214,7 +221,7 @@ int erofs_namei(struct nameidata *nd, const char *name, unsigned int len) nameoff =le16_to_cpu (de->nameoff);if (nameoff <sizeof (struct erofs_dirent ) || - nameoff >=erofs_blksiz ()) { + nameoff >=erofs_blksiz (sbi)) {erofs_err ("invalid de[0].nameoff %u @ nid %llu" , nameoff, nid |0ULL );return -EFSCORRUPTED ;
@@ -236,7 +243,7 @@ int erofs_namei(struct nameidata *nd, const char *name, unsigned int len)static int link_path_walk (const char *name,struct nameidata *nd) { - nd->nid = sbi.root_nid; + nd->nid = nd->sbi->root_nid;while (*name =='/' ) name++;
@@ -266,7 +273,7 @@ static int link_path_walk(const char *name, struct nameidata *nd)int erofs_ilookup (const char *path,struct erofs_inode *vi) {int ret; -struct nameidata nd; +struct nameidata nd = { .sbi = vi->sbi }; ret =link_path_walk (path, &nd);if (ret)
lib/super.c +26 -25
89 lines not on this page · raw message
lib/tar.c +19 -17
@@ -161,8 +161,8 @@ static struct erofs_dentry *tarerofs_mkdir(struct erofs_inode *dir, const char * inode->i_parent = dir; inode->i_uid =getuid (); inode->i_gid =getgid (); - inode->i_mtime = sbi.build_time; - inode->i_mtime_nsec = sbi.build_time_nsec; + inode->i_mtime = inode->sbi->build_time; + inode->i_mtime_nsec = inode->sbi->build_time_nsec;tarerofs_init_empty_dir (inode); d =erofs_d_alloc (dir, s);
@@ -353,14 +353,15 @@ out:int tarerofs_write_chunk_indexes (struct erofs_inode *inode,erofs_blk_t blkaddr) { +struct erofs_sb_info *sbi = inode->sbi;unsigned int chunkbits =ilog2 (inode->i_size -1 ) +1 ;unsigned int count, unit;erofs_off_t chunksize, len, pos;struct erofs_inode_chunk_index *idx; -if (chunkbits < sbi.blkszbits) - chunkbits = sbi.blkszbits; - inode->u.chunkformat |= chunkbits - sbi.blkszbits; +if (chunkbits < sbi->blkszbits) + chunkbits = sbi->blkszbits; + inode->u.chunkformat |= chunkbits - sbi->blkszbits; inode->u.chunkformat |=EROFS_CHUNK_FORMAT_INDEXES ; chunksize =1ULL << chunkbits; count =DIV_ROUND_UP (inode->i_size, chunksize);
@@ -382,7 +383,7 @@ int tarerofs_write_chunk_indexes(struct erofs_inode *inode, erofs_blk_t blkaddr)return PTR_ERR (chunk); *(void **)idx++ = chunk; - blkaddr +=erofs_blknr (len); + blkaddr +=erofs_blknr (sbi, len); } inode->datalayout =EROFS_INODE_CHUNK_BASED ;return 0 ;
@@ -410,6 +411,7 @@ int tarerofs_parse_tar(struct erofs_inode *root, struct erofs_tarfile *tar) {char path[PATH_MAX ];struct erofs_pax_header eh = tar->global; +struct erofs_sb_info *sbi = root->sbi;bool e, whout, opq;struct stat st;erofs_off_t tar_offset, data_offset;
@@ -616,7 +618,7 @@ restart: eh.link =strndup (th.linkname,sizeof (th.linkname)); } -if (tar->index_mode &&erofs_blkoff (tar_offset +sizeof (th))) { +if (tar->index_mode &&erofs_blkoff (sbi, tar_offset +sizeof (th))) {erofs_err ("invalid tar data alignment @ %llu" , tar_offset); ret = -EIO ; goto out;
@@ -719,7 +721,7 @@ new_inode:memcpy (inode->i_link, eh.link, inode->i_size +1 ); }else if (tar->index_mode) { ret =tarerofs_write_chunk_indexes (inode, -erofs_blknr (data_offset)); +erofs_blknr (sbi, data_offset));if (ret) goto out;if (erofs_lskip (tar->fd, inode->i_size)) {
@@ -774,7 +776,7 @@ invalid_tar:static struct erofs_buffer_head *bh_devt; -int tarerofs_reserve_devtable (unsigned int devices) +int tarerofs_reserve_devtable (struct erofs_sb_info *sbi,unsigned int devices) {if (!devices)return 0 ;
@@ -786,27 +788,27 @@ int tarerofs_reserve_devtable(unsigned int devices)erofs_mapbh (bh_devt->block); bh_devt->op = &erofs_skip_write_bhops; - sbi.devt_slotoff =erofs_btell (bh_devt, false) /EROFS_DEVT_SLOT_SIZE ; - sbi.extra_devices = devices; -erofs_sb_set_device_table (); + sbi->devt_slotoff =erofs_btell (bh_devt, false) /EROFS_DEVT_SLOT_SIZE ; + sbi->extra_devices = devices; +erofs_sb_set_device_table (sbi);return 0 ; } -int tarerofs_write_devtable (struct erofs_tarfile *tar) +int tarerofs_write_devtable (struct erofs_sb_info *sbi,struct erofs_tarfile *tar) {erofs_off_t pos_out;unsigned int i; -if (!sbi.extra_devices) +if (!sbi->extra_devices)return 0 ; pos_out =erofs_btell (bh_devt, false); -for (i =0 ; i < sbi.extra_devices; ++i) { +for (i =0 ; i < sbi->extra_devices; ++i) {struct erofs_deviceslot dis = { - .blocks =erofs_blknr (tar->offset), + .blocks =erofs_blknr (sbi, tar->offset), };int ret; - ret =dev_write (&dis, pos_out,sizeof (dis)); + ret =dev_write (sbi, &dis, pos_out,sizeof (dis));if (ret)return ret; pos_out +=sizeof (dis);
lib/xattr.c +41 -34
184 lines not on this page · raw message
mkfs/main.c +31 -31
62 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.24.4
Part of the diff is not shown here. View the raw message.