erofs-utils: fix tar.h
PATCH v2 1/16 erofs-utils: fix tar.h
Include "internal.h" to fix the dependency on prototypes of struct erofs_inode and struct erofs_sb_info.
--- include/erofs/tar.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
include/erofs/tar.h +11 -0
@@ -2,8 +2,15 @@ #ifndef __EROFS_TAR_H #define __EROFS_TAR_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include <sys/stat.h> +#include "internal.h" + struct erofs_pax_header { struct stat st; bool use_mtime;
@@ -27,4 +34,8 @@ int tarerofs_parse_tar(struct erofs_inode *root, 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); +#ifdef __cplusplus +} +#endif +#endif
Signature · 1 line
2.19.1.6.gb485710b
PATCH v2 2/16 erofs-utils: lib: add list_splice_tail() helper
Add list_splice_tail() helper.
--- include/erofs/list.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
include/erofs/list.h +20 -0
@@ -70,6 +70,26 @@ static inline int list_empty(struct list_head *head)return head->next == head; } +static inline void __list_splice (struct list_head *list, +struct list_head *prev,struct list_head *next) +{ +struct list_head *first = list->next; +struct list_head *last = list->prev; + + first->prev = prev; + prev->next = first; + + last->next = next; + next->prev = last; +} + +static inline void list_splice_tail (struct list_head *list, +struct list_head *head) +{ +if (!list_empty (list)) +__list_splice (list, head->prev, head); +} +#define list_entry (ptr, type, member) container_of(ptr, type, member)#define list_first_entry (ptr, type, member) \
Signature · 1 line
2.19.1.6.gb485710b
PATCH v2 3/16 erofs-utils: lib: add bitops library
In reply to Jingbo XuIntroduce following bitmap helpers:
DECLARE_BITMAP test_bit __set_bit __clear_bit find_next_bit find_next_zero_bit
--- include/erofs/bitops.h | 43 ++++++++++++++++++++++++ include/erofs/defs.h | 75 ++++++++++++++++++++++++++++++++++++++++++ lib/Makefile.am | 3 +- lib/bitops.c | 58 ++++++++++++++++++++++++++++++++ 4 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 include/erofs/bitops.h create mode 100644 lib/bitops.c
include/erofs/bitops.h new file +43 -0
@@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ +#ifndef __EROFS_BITOPS_H +#define __EROFS_BITOPS_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include "defs.h" + +static inline void __set_bit (int nr,volatile unsigned long *addr) +{ +unsigned long mask =BIT_MASK (nr); +unsigned long *p = ((unsigned long *)addr) +BIT_WORD (nr); + + *p |= mask; +} + +static inline void __clear_bit (int nr,volatile unsigned long *addr) +{ +unsigned long mask =BIT_MASK (nr); +unsigned long *p = ((unsigned long *)addr) +BIT_WORD (nr); + + *p &= ~mask; +} + +static inline int test_bit (int nr,const volatile unsigned long *addr) +{ +return 1UL & (addr[BIT_WORD (nr)] >> (nr & (BITS_PER_LONG -1 ))); +} + +unsigned long find_next_bit (const unsigned long *addr,unsigned long size, +unsigned long offset); + +unsigned long find_next_zero_bit (const unsigned long *addr,unsigned long size, +unsigned long offset); + +#ifdef __cplusplus +} +#endif + +#endif
include/erofs/defs.h +75 -0
81 lines not on this page · raw message
lib/Makefile.am +2 -1
@@ -19,6 +19,7 @@ noinst_HEADERS = $(top_srcdir)/include/erofs_fs.h \ $(top_srcdir)/include/erofs/io.h \ $(top_srcdir)/include/erofs/list.h \ $(top_srcdir)/include/erofs/print.h \ + $(top_srcdir)/include/erofs/bitops.h \ $(top_srcdir)/include/erofs/tar.h \ $(top_srcdir)/include/erofs/trace.h \ $(top_srcdir)/include/erofs/xattr.h \
@@ -31,7 +32,7 @@ liberofs_la_SOURCES = config.c io.c cache.c super.c inode.c xattr.c exclude.c \ namei.c data.c compress.c compressor.c zmap.c decompress.c \ compress_hints.c hashmap.c sha256.c blobchunk.c dir.c \ fragments.c rb_tree.c dedupe.c uuid_unparse.c uuid.c tar.c \ - block_list.c + block_list.c bitops.c liberofs_la_CFLAGS = -Wall ${libuuid_CFLAGS} -I$(top_srcdir)/include if ENABLE_LZ4
lib/bitops.c new file +58 -0
58 lines not on this page · raw message
Signature · 1 line
2.19.1.6.gb485710b
PATCH v2 4/16 erofs-utils: read i_ino in erofs_read_inode_from_disk()
In reply to Jingbo XuRead on-disk ino and store it in i_ino[0].
--- lib/namei.c | 2 ++ 1 file changed, 2 insertions(+)
lib/namei.c +2 -0
@@ -60,6 +60,7 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi) die = (struct erofs_inode_extended *)buf; vi->xattr_isize =erofs_xattr_ibody_size (die->i_xattr_icount); vi->i_mode =le16_to_cpu (die->i_mode); + vi->i_ino[0 ] =le32_to_cpu (die->i_ino);switch (vi->i_mode &S_IFMT ) {case S_IFREG :
@@ -95,6 +96,7 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi) vi->inode_isize =sizeof (struct erofs_inode_compact ); vi->xattr_isize =erofs_xattr_ibody_size (dic->i_xattr_icount); vi->i_mode =le16_to_cpu (dic->i_mode); + vi->i_ino[0 ] =le32_to_cpu (dic->i_ino);switch (vi->i_mode &S_IFMT ) {case S_IFREG :
Signature · 1 line
2.19.1.6.gb485710b
PATCH v2 5/16 erofs-utils: read dis->blocks in erofs_init_devices()
In reply to Jingbo XuRead dis->blocks in erofs_init_devices(). Also fix the missing le32_to_cpu() when reading mapped_blkaddr.
Initialize sbi->extra_devices from on-disk extra_devices.
--- lib/super.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
lib/super.c +4 -7
@@ -36,11 +36,7 @@ static int erofs_init_devices(struct erofs_sb_info *sbi,else ondisk_extradevs =le16_to_cpu (dsb->extra_devices); -if (ondisk_extradevs != sbi->extra_devices) { -erofs_err ("extra devices don't match (ondisk %u, given %u)" , - ondisk_extradevs, sbi->extra_devices); -return -EINVAL ; - } + sbi->extra_devices = ondisk_extradevs;if (!ondisk_extradevs)return 0 ;
@@ -59,8 +55,9 @@ static int erofs_init_devices(struct erofs_sb_info *sbi,return ret; } - sbi->devs[i].mapped_blkaddr = dis.mapped_blkaddr; - sbi->total_blocks += dis.blocks; + sbi->devs[i].mapped_blkaddr =le32_to_cpu (dis.mapped_blkaddr); + sbi->devs[i].blocks =le32_to_cpu (dis.blocks); + sbi->total_blocks += sbi->devs[i].blocks; pos +=EROFS_DEVT_SLOT_SIZE ; }return 0 ;
Signature · 1 line
2.19.1.6.gb485710b
PATCH v2 6/16 erofs-utils: add erofs_read_xattrs_from_disk() helper
In reply to Jingbo XuAdd erofs_read_xattrs_from_disk() helper to read extended attributes from disk.
--- include/erofs/xattr.h | 1 + lib/xattr.c | 76 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+)
include/erofs/xattr.h +1 -0
@@ -85,6 +85,7 @@ 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); +int erofs_read_xattrs_from_disk (struct erofs_inode *inode); #ifdef __cplusplus }
lib/xattr.c +76 -0
82 lines not on this page · raw message
Signature · 1 line
2.19.1.6.gb485710b
PATCH v2 7/16 erofs-utils: add erofs_inode_tag_opaque() helper
In reply to Jingbo XuAdd erofs_inode_tag_opaque() helper checking if it's an opaque directory.
--- include/erofs/internal.h | 2 ++ include/erofs/xattr.h | 22 ++++++++++++++++++++ lib/tar.c | 5 ----- lib/xattr.c | 44 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 5 deletions(-)
include/erofs/internal.h +2 -0
@@ -218,6 +218,8 @@ struct erofs_inode {#endif erofs_off_t fragmentoff;unsigned int fragment_size; + +bool opaque; };static inline erofs_off_t erofs_iloc (struct erofs_inode *inode)
include/erofs/xattr.h +22 -0
@@ -73,6 +73,27 @@ static inline unsigned int xattrblock_offset(struct erofs_inode *vi,#ifndef XATTR_NAME_POSIX_ACL_DEFAULT #define XATTR_NAME_POSIX_ACL_DEFAULT "system.posix_acl_default"#endif +#ifndef OVL_XATTR_NAMESPACE +#define OVL_XATTR_NAMESPACE "overlay." +#endif +#ifndef OVL_XATTR_OPAQUE_POSTFIX +#define OVL_XATTR_OPAQUE_POSTFIX "opaque" +#endif +#ifndef OVL_XATTR_TRUSTED_PREFIX +#define OVL_XATTR_TRUSTED_PREFIX XATTR_TRUSTED_PREFIX OVL_XATTR_NAMESPACE +#endif +#ifndef OVL_XATTR_OPAQUE_SUFFIX +#define OVL_XATTR_OPAQUE_SUFFIX OVL_XATTR_NAMESPACE OVL_XATTR_OPAQUE_POSTFIX +#endif +#ifndef OVL_XATTR_OPAQUE_SUFFIX_LEN +#define OVL_XATTR_OPAQUE_SUFFIX_LEN (sizeof(OVL_XATTR_OPAQUE_SUFFIX) - 1) +#endif +#ifndef OVL_XATTR_OPAQUE +#define OVL_XATTR_OPAQUE OVL_XATTR_TRUSTED_PREFIX OVL_XATTR_OPAQUE_POSTFIX +#endif +#ifndef OVL_XATTR_OPAQUE_LEN +#define OVL_XATTR_OPAQUE_LEN (sizeof(OVL_XATTR_OPAQUE) - 1) +#endif int erofs_scan_file_xattrs (struct erofs_inode *inode);int erofs_prepare_xattr_ibody (struct erofs_inode *inode);
@@ -86,6 +107,7 @@ 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);int erofs_read_xattrs_from_disk (struct erofs_inode *inode); +void erofs_inode_tag_opaque (struct erofs_inode *inode); #ifdef __cplusplus }
lib/tar.c +0 -5
@@ -19,11 +19,6 @@#include "erofs/xattr.h" #include "erofs/blobchunk.h" -#define OVL_XATTR_NAMESPACE "overlay." -#define OVL_XATTR_TRUSTED_PREFIX XATTR_TRUSTED_PREFIX OVL_XATTR_NAMESPACE -#define OVL_XATTR_OPAQUE_POSTFIX "opaque" -#define OVL_XATTR_OPAQUE OVL_XATTR_TRUSTED_PREFIX OVL_XATTR_OPAQUE_POSTFIX -#define EROFS_WHITEOUT_DEV 0static char erofs_libbuf[16384 ];
lib/xattr.c +44 -0
50 lines not on this page · raw message
Signature · 1 line
2.19.1.6.gb485710b
PATCH v2 8/16 erofs-utils: add erofs_insert_ihash() helper
In reply to Jingbo XuAdd erofs_insert_ihash() helper inserting inode into inode hash table.
Also add prototypes of erofs_iget() and erofs_iget_by_nid() in the header file.
--- include/erofs/inode.h | 3 +++ lib/inode.c | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-)
include/erofs/inode.h +3 -0
@@ -25,6 +25,9 @@ u32 erofs_new_encode_dev(dev_t dev);unsigned char erofs_mode_to_ftype (umode_t mode);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); +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);erofs_nid_t erofs_lookupnid (struct erofs_inode *inode); struct erofs_dentry *erofs_d_alloc(struct erofs_inode *parent,
lib/inode.c +7 -3
@@ -75,6 +75,12 @@ 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) +{ +list_add (&inode->i_hash, + &inode_hashtable[(ino ^ dev) %NR_INODE_HASHTABLE ]); +} +/* get the inode from the (source) inode # */ struct erofs_inode *erofs_iget (dev_t dev,ino_t ino) {
@@ -976,9 +982,7 @@ static int erofs_fill_inode(struct erofs_inode *inode, struct stat *st, inode->inode_isize =sizeof (struct erofs_inode_compact ); } -list_add (&inode->i_hash, - &inode_hashtable[(st->st_ino ^ st->st_dev) % -NR_INODE_HASHTABLE ]); +erofs_insert_ihash (inode, st->st_dev, st->st_ino);return 0 ; }
Signature · 1 line
2.19.1.6.gb485710b
PATCH v2 9/16 erofs-utils: add erofs_rebuild_dump_tree() helper
In reply to Jingbo XuEnhance tarerofs_dump_tree() so that it could optionally skip whiteout files. Rename it to erofs_rebuild_dump_tree().
--- include/erofs/inode.h | 2 +- include/erofs/internal.h | 2 ++ lib/inode.c | 23 ++++++++++++++++++++--- lib/tar.c | 2 -- mkfs/main.c | 2 +- 5 files changed, 24 insertions(+), 7 deletions(-)
include/erofs/inode.h +1 -1
@@ -32,7 +32,7 @@ unsigned int erofs_iput(struct erofs_inode *inode);erofs_nid_t erofs_lookupnid (struct erofs_inode *inode);struct erofs_dentry *erofs_d_alloc (struct erofs_inode *parent,const char *name); -int tarerofs_dump_tree (struct erofs_inode *dir); +int erofs_rebuild_dump_tree (struct erofs_inode *dir,bool skip_whout);int erofs_init_empty_dir (struct erofs_inode *dir);struct erofs_inode *erofs_new_inode (void );struct erofs_inode *erofs_mkfs_build_tree_from_path (const char *path);
include/erofs/internal.h +2 -0
@@ -415,6 +415,8 @@ static inline u32 erofs_crc32c(u32 crc, const u8 *in, size_t len)return crc; } +#define EROFS_WHITEOUT_DEV 0 + #ifdef __cplusplus }#endif
lib/inode.c +20 -3
@@ -1323,9 +1323,14 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(int fd, const char *name)return inode; } -int tarerofs_dump_tree (struct erofs_inode *dir) +static bool erofs_inode_is_whiteout (struct erofs_inode *inode) { -struct erofs_dentry *d; +return S_ISCHR (inode->i_mode) && inode->u.i_rdev ==EROFS_WHITEOUT_DEV ; +} + +int erofs_rebuild_dump_tree (struct erofs_inode *dir,bool skip_whout) +{ +struct erofs_dentry *d, *n;unsigned int nr_subdirs;int ret;
@@ -1368,6 +1373,18 @@ int tarerofs_dump_tree(struct erofs_inode *dir)return 0 ; } +if (skip_whout) { +list_for_each_entry_safe (d, n, &dir->i_subdirs, d_child) { +if (erofs_inode_is_whiteout (d->inode)) { +erofs_dbg ("skip whiteout %s" , d->inode->i_srcpath); +erofs_d_invalidate (d); +list_del (&d->d_child); +free (d); +continue ; + } + } + } + nr_subdirs =0 ;list_for_each_entry (d, &dir->i_subdirs, d_child) ++nr_subdirs;
@@ -1391,7 +1408,7 @@ int tarerofs_dump_tree(struct erofs_inode *dir)continue ; inode =erofs_igrab (d->inode); - ret =tarerofs_dump_tree (inode); + ret =erofs_rebuild_dump_tree (inode, skip_whout); dir->i_nlink += (erofs_mode_to_ftype (inode->i_mode) ==EROFS_FT_DIR );erofs_iput (inode);if (ret)
lib/tar.c +0 -2
@@ -19,8 +19,6 @@#include "erofs/xattr.h" #include "erofs/blobchunk.h" -#define EROFS_WHITEOUT_DEV 0 -static char erofs_libbuf[16384 ];struct tar_header {
mkfs/main.c +1 -1
@@ -947,7 +947,7 @@ int main(int argc, char **argv)if (err <0 ) goto exit; - err =tarerofs_dump_tree (root_inode); + err =erofs_rebuild_dump_tree (root_inode, false);if (err <0 ) goto exit; }
Signature · 1 line
2.19.1.6.gb485710b
PATCH v2 10/16 erofs-utils: add erofs_rebuild_get_dentry() helper
In reply to Jingbo XuRename tarerofs_get_dentry() to erofs_rebuild_get_dentry().
Also make whout and 'opq' parameter optional when aufs is false.
--- include/erofs/rebuild.h | 19 +++++++ lib/Makefile.am | 3 +- lib/rebuild.c | 117 ++++++++++++++++++++++++++++++++++++++++ lib/tar.c | 109 ++----------------------------------- 4 files changed, 141 insertions(+), 107 deletions(-) create mode 100644 include/erofs/rebuild.h create mode 100644 lib/rebuild.c
include/erofs/rebuild.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ +#ifndef __EROFS_REBUILD_H +#define __EROFS_REBUILD_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include "internal.h" + +struct erofs_dentry *erofs_rebuild_get_dentry (struct erofs_inode *pwd, +char *path,bool aufs,bool *whout,bool *opq); + +#ifdef __cplusplus +} +#endif + +#endif
lib/Makefile.am +2 -1
@@ -25,6 +25,7 @@ noinst_HEADERS = $(top_srcdir)/include/erofs_fs.h \ $(top_srcdir)/include/erofs/xattr.h \ $(top_srcdir)/include/erofs/compress_hints.h \ $(top_srcdir)/include/erofs/fragments.h \ + $(top_srcdir)/include/erofs/rebuild.h \ $(top_srcdir)/lib/liberofs_private.h noinst_HEADERS += compressor.h
@@ -32,7 +33,7 @@ liberofs_la_SOURCES = config.c io.c cache.c super.c inode.c xattr.c exclude.c \ namei.c data.c compress.c compressor.c zmap.c decompress.c \ compress_hints.c hashmap.c sha256.c blobchunk.c dir.c \ fragments.c rb_tree.c dedupe.c uuid_unparse.c uuid.c tar.c \ - block_list.c bitops.c + block_list.c bitops.c rebuild.c liberofs_la_CFLAGS = -Wall ${libuuid_CFLAGS} -I$(top_srcdir)/include if ENABLE_LZ4
lib/rebuild.c new file +117 -0
117 lines not on this page · raw message
lib/tar.c +3 -106
139 lines not on this page · raw message
Signature · 1 line
2.19.1.6.gb485710b
PATCH v2 11/16 erofs-utils: make erofs_get_unhashed_chunk() global
In reply to Jingbo Xu... so that it could be called from outside blobchunk.c later.
--- include/erofs/blobchunk.h | 2 ++ lib/blobchunk.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
include/erofs/blobchunk.h +2 -0
@@ -14,6 +14,8 @@ extern "C"#include "erofs/internal.h" +struct erofs_blobchunk *erofs_get_unhashed_chunk (unsigned int device_id, +erofs_blk_t blkaddr,erofs_off_t sourceoffset);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 tarerofs_write_chunkes (struct erofs_inode *inode,erofs_off_t data_offset);
lib/blobchunk.c +1 -1
@@ -38,7 +38,7 @@ struct erofs_blobchunk erofs_holechunk = { };static LIST_HEAD (unhashed_blobchunks); -static struct erofs_blobchunk *erofs_get_unhashed_chunk (unsigned int device_id, +struct erofs_blobchunk *erofs_get_unhashed_chunk (unsigned int device_id,erofs_blk_t blkaddr,erofs_off_t sourceoffset) {struct erofs_blobchunk *chunk;
Signature · 1 line
2.19.1.6.gb485710b
PATCH v2 12/16 erofs-utils: add erofs image helper
In reply to Jingbo XuLater we are going to introduce new feature of merging multiple erofs images generated from tarfs mode. Add helpers registering and cleaning these images.
--- include/erofs/rebuild.h | 12 +++++++++++ lib/rebuild.c | 45 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+)
include/erofs/rebuild.h +12 -0
@@ -9,6 +9,18 @@ extern "C"#include "internal.h" +struct erofs_img { +struct list_head list; +char *path; +dev_t dev; +struct erofs_sb_info sbi; +}; + +extern unsigned int imgs_count; +struct erofs_img *erofs_get_img (const char *path); +int erofs_add_img (const char *path); +void erofs_cleanup_imgs (void ); +struct erofs_dentry *erofs_rebuild_get_dentry (struct erofs_inode *pwd,char *path,bool aufs,bool *whout,bool *opq);
lib/rebuild.c +45 -0
54 lines not on this page · raw message
Signature · 1 line
2.19.1.6.gb485710b
PATCH v2 13/16 erofs-utils: add erofs_rebuild_load_tree() helper
In reply to Jingbo XuAdd erofs_rebuild_load_tree() helper loading inode tree from given erofs image, and making it merged into a given inode tree in an overlayfs like model.
--- include/erofs/rebuild.h | 2 + lib/rebuild.c | 269 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 271 insertions(+)
include/erofs/rebuild.h +2 -0
@@ -21,6 +21,8 @@ struct erofs_img *erofs_get_img(const char *path);int erofs_add_img (const char *path);void erofs_cleanup_imgs (void ); +int erofs_rebuild_load_tree (struct erofs_inode *root,struct erofs_img *img); +struct erofs_dentry *erofs_rebuild_get_dentry (struct erofs_inode *pwd,char *path,bool aufs,bool *whout,bool *opq);
lib/rebuild.c +269 -0
284 lines not on this page · raw message
Signature · 1 line
2.19.1.6.gb485710b
PATCH v2 14/16 erofs-utils: generate data block bitmap when loading tree
In reply to Jingbo XuEnhance erofs_rebuild_load_tree() making it generate a bitmap describing used data blocks by all regular files in given erofs image.
--- include/erofs/rebuild.h | 3 ++- lib/rebuild.c | 39 ++++++++++++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 6 deletions(-)
include/erofs/rebuild.h +2 -1
@@ -21,7 +21,8 @@ struct erofs_img *erofs_get_img(const char *path);int erofs_add_img (const char *path);void erofs_cleanup_imgs (void ); -int erofs_rebuild_load_tree (struct erofs_inode *root,struct erofs_img *img); +int erofs_rebuild_load_tree (struct erofs_inode *root,struct erofs_img *img, +unsigned long **datablk_map,unsigned long *datablks);struct erofs_dentry *erofs_rebuild_get_dentry (struct erofs_inode *pwd,char *path,bool aufs,bool *whout,bool *opq);
lib/rebuild.c +34 -5
@@ -11,6 +11,7 @@#include "erofs/dir.h" #include "erofs/xattr.h" #include "erofs/blobchunk.h" +#include "erofs/bitops.h" #include "erofs/internal.h" #ifdef HAVE_LINUX_AUFS_TYPE_H
@@ -125,7 +126,7 @@ struct erofs_dentry *erofs_rebuild_get_dentry(struct erofs_inode *pwd, }static int erofs_rebuild_fill_inode_map (struct erofs_inode *inode, -struct erofs_inode *vi,dev_t dev) +struct erofs_inode *vi,dev_t dev,unsigned long *datablk) {int ret;unsigned int count, unit, chunkbits, deviceid, i;
@@ -178,6 +179,9 @@ static int erofs_rebuild_fill_inode_map(struct erofs_inode *inode, goto err; } *(void **)idx++ = chunk; + +if (datablk) +__set_bit (blkaddr, datablk);erofs_dbg ("\t%s: chunk %d (deviceid %u, blkaddr %u)" , inode->i_srcpath, i, deviceid, blkaddr);
@@ -191,7 +195,7 @@ err: }static int erofs_rebuild_fill_inode (struct erofs_inode *inode, -struct erofs_inode *vi,dev_t dev) +struct erofs_inode *vi,dev_t dev,unsigned long *datablk) {int ret =0 ;
@@ -226,7 +230,7 @@ static int erofs_rebuild_fill_inode(struct erofs_inode *inode,case S_IFREG : inode->i_size = vi->i_size;if (inode->i_size) - ret =erofs_rebuild_fill_inode_map (inode, vi, dev); + ret =erofs_rebuild_fill_inode_map (inode, vi, dev, datablk);else inode->u.i_blkaddr =NULL_ADDR ;break ;
@@ -241,6 +245,7 @@ struct erofs_rebuild_dir_context {struct erofs_dir_context ctx;struct erofs_inode *root;dev_t dev; +unsigned long *datablk; };static int erofs_rebuild_dirent_iter (struct erofs_dir_context *ctx)
@@ -313,7 +318,8 @@ static int erofs_rebuild_dirent_iter(struct erofs_dir_context *ctx) inode->i_parent = d->inode; inode->dev = rctx->dev; - ret =erofs_rebuild_fill_inode (inode, &vi, rctx->dev); + ret =erofs_rebuild_fill_inode (inode, &vi, rctx->dev, + rctx->datablk);if (ret) goto exit_inode;
@@ -345,11 +351,13 @@ exit_inode: goto exit; } -int erofs_rebuild_load_tree (struct erofs_inode *root,struct erofs_img *img) +int erofs_rebuild_load_tree (struct erofs_inode *root,struct erofs_img *img, +unsigned long **datablk_map,unsigned long *datablks) {struct erofs_inode inode = {};struct erofs_sb_info *sbi = &img->sbi;struct erofs_rebuild_dir_context ctx; +unsigned long *datablk =NULL ;int ret;erofs_dbg ("Loading image %s..." , img->path);
@@ -366,11 +374,27 @@ int erofs_rebuild_load_tree(struct erofs_inode *root, struct erofs_img *img) goto exit; } +if (datablk_map) { +if (sbi->extra_devices) { +erofs_err ("don't support scanning data blocks for extra devices" ); + ret = -EOPNOTSUPP ; + goto exit; + } + + datablk =calloc (BITS_TO_LONGS (sbi->total_blocks), +sizeof (unsigned long )); +if (!datablk) { + ret = -ENOMEM ; + goto exit; + } + } + inode.nid = sbi->root_nid; inode.sbi = sbi; ret =erofs_read_inode_from_disk (&inode);if (ret) {erofs_err ("failed to read root inode of image %s" , img->path); +free (datablk); goto exit; } inode.i_srcpath =strdup ("/" );
@@ -380,9 +404,14 @@ int erofs_rebuild_load_tree(struct erofs_inode *root, struct erofs_img *img) .ctx.cb = erofs_rebuild_dirent_iter, .root = root, .dev = img->dev, + .datablk = datablk, }; ret =erofs_iterate_dir (&ctx.ctx, false);free (inode.i_srcpath); +if (datablk_map) { + *datablk_map = datablk; + *datablks = sbi->total_blocks; + } exit:dev_close (sbi);return ret;
Signature · 1 line
2.19.1.6.gb485710b
PATCH v2 15/16 erofs-utils: mkfs: add dependency on zlib_LIBS
In reply to Jingbo XuLater we are going to introduce new feature of merging multiple erofs images generated from tarfs mode, in which mkfs.erofs may read file data from disk. This requires dependency on zlib_LIBS for mkfs.erofs.
--- mkfs/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mkfs/Makefile.am +2 -1
@@ -6,4 +6,5 @@ AM_CPPFLAGS = ${libselinux_CFLAGS} mkfs_erofs_SOURCES = main.c mkfs_erofs_CFLAGS = -Wall -I$(top_srcdir)/include mkfs_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \ - ${libuuid_LIBS} ${liblz4_LIBS} ${liblzma_LIBS} ${libdeflate_LIBS} + ${libuuid_LIBS} ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} \ + ${libdeflate_LIBS}
Signature · 1 line
2.19.1.6.gb485710b
PATCH v2 16/16 erofs-utils: mkfs: introduce rebuild mode
In reply to Jingbo XuIntroduce a new rebuild mode merging multiple erofs images generated from tarfs mode. This can be called like:
mkfs.erofs IMAGE UPPER_IMAGE LOWER_IMAGE ...
--- include/erofs/rebuild.h | 1 + lib/rebuild.c | 25 ++++++++++ mkfs/main.c | 108 +++++++++++++++++++++++++--------------- 3 files changed, 93 insertions(+), 41 deletions(-)
include/erofs/rebuild.h +1 -0
@@ -23,6 +23,7 @@ void erofs_cleanup_imgs(void);int erofs_rebuild_load_tree (struct erofs_inode *root,struct erofs_img *img,unsigned long **datablk_map,unsigned long *datablks); +struct erofs_inode *erofs_rebuild_load_trees (void );struct erofs_dentry *erofs_rebuild_get_dentry (struct erofs_inode *pwd,char *path,bool aufs,bool *whout,bool *opq);
lib/rebuild.c +25 -0
@@ -417,6 +417,31 @@ exit:return ret; } +struct erofs_inode *erofs_rebuild_load_trees (void ) +{ +struct erofs_img *img; +struct erofs_inode *root; +int ret, index =0 ; + + root =erofs_new_inode (); +if (IS_ERR (root)) +return root; + root->i_srcpath =strdup ("/" ); + root->i_mode =S_IFDIR |0777 ; + root->i_parent = root; + root->i_mtime = root->sbi->build_time; + root->i_mtime_nsec = root->sbi->build_time_nsec; +erofs_init_empty_dir (root); + +list_for_each_entry (img, &imgs_list, list) { + ret =erofs_rebuild_load_tree (root, img,NULL ,NULL ); +if (ret) +return ERR_PTR (ret); + sbi.devs[index++].blocks = img->sbi.devs[0 ].blocks; + } +return root; +} +struct erofs_img *erofs_get_img (const char *path) {struct erofs_img *img =malloc (sizeof (*img));
mkfs/main.c +67 -41
184 lines not on this page · raw message
Signature · 1 line
2.19.1.6.gb485710b