Later we are going to introduce new feature of merging multiple erofs images generated from tarfs mode. Add helpers registering and cleaning these images.
Signed-off-by: Jingbo Xu <[email protected]> --- include/erofs/rebuild.h | 12 +++++++++++ lib/rebuild.c | 45 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/include/erofs/rebuild.h b/include/erofs/rebuild.h index 92873c9..df7613a 100644 --- a/include/erofs/rebuild.h +++ b/include/erofs/rebuild.h @@ -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); diff --git a/lib/rebuild.c b/lib/rebuild.c index 7aaa071..e2f6c1d 100644 --- a/lib/rebuild.c +++ b/lib/rebuild.c @@ -16,6 +16,9 @@ #define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME #endif +unsigned int imgs_count; +static LIST_HEAD(imgs_list); + static struct erofs_dentry *erofs_rebuild_mkdir(struct erofs_inode *dir, const char *s) { @@ -115,3 +118,45 @@ struct erofs_dentry *erofs_rebuild_get_dentry(struct erofs_inode *pwd, } return d; } + +struct erofs_img *erofs_get_img(const char *path) +{ + struct erofs_img *img = malloc(sizeof(*img)); + + if (!img) + return ERR_PTR(-ENOMEM); + + img->path = realpath(path, NULL); + if (!img->path) { + erofs_err("failed to parse image file (%s): %s", + path, erofs_strerror(-errno)); + free(img); + return ERR_PTR(-ENOENT); + } + + img->dev = ++imgs_count; + return img; +} + +int erofs_add_img(const char *path) +{ + struct erofs_img *img = erofs_get_img(path); + + if (IS_ERR(img)) + return PTR_ERR(img); + + list_add_tail(&img->list, &imgs_list); + return 0; +} + +void erofs_cleanup_imgs(void) +{ + struct erofs_img *img, *n; + + list_for_each_entry_safe(img, n, &imgs_list, list) { + list_del(&img->list); + free(img->path); + free(img); + } + imgs_count = 0; +} -- 2.19.1.6.gb485710b
