There are so many parameters in erofs_rebuild_get_dentry(), let's
wrap these parameters into `struct erofs_rebuild_getdentry_ctx`.

Signed-off-by: Hongzhen Luo <[email protected]>
---
 include/erofs/rebuild.h | 12 +++++++--
 lib/rebuild.c           | 59 ++++++++++++++++++++++++-----------------
 lib/tar.c               | 17 +++++++++---
 3 files changed, 59 insertions(+), 29 deletions(-)

diff --git a/include/erofs/rebuild.h b/include/erofs/rebuild.h
index 59b2f6f57005..b37bc80e8a3c 100644
--- a/include/erofs/rebuild.h
+++ b/include/erofs/rebuild.h
@@ -15,8 +15,16 @@ enum erofs_rebuild_datamode {
        EROFS_REBUILD_DATA_FULL,
 };
 
-struct erofs_dentry *erofs_rebuild_get_dentry(struct erofs_inode *pwd,
-               char *path, bool aufs, bool *whout, bool *opq, bool to_head);
+struct erofs_rebuild_getdentry_ctx {
+       struct erofs_inode *pwd;
+       char *path;
+       bool aufs;
+       bool *whout;
+       bool *opq;
+       bool to_head;
+};
+
+struct erofs_dentry *erofs_rebuild_get_dentry(struct 
erofs_rebuild_getdentry_ctx *ctx);
 
 int erofs_rebuild_load_tree(struct erofs_inode *root, struct erofs_sb_info 
*sbi,
                            enum erofs_rebuild_datamode mode);
diff --git a/lib/rebuild.c b/lib/rebuild.c
index b37823e48858..58f1701b3721 100644
--- a/lib/rebuild.c
+++ b/lib/rebuild.c
@@ -16,6 +16,7 @@
 #include "erofs/blobchunk.h"
 #include "erofs/internal.h"
 #include "liberofs_uuid.h"
+#include "erofs/rebuild.h"
 
 #ifdef HAVE_LINUX_AUFS_TYPE_H
 #include <linux/aufs_type.h>
@@ -58,18 +59,17 @@ static struct erofs_dentry *erofs_rebuild_mkdir(struct 
erofs_inode *dir,
        return d;
 }
 
-struct erofs_dentry *erofs_rebuild_get_dentry(struct erofs_inode *pwd,
-               char *path, bool aufs, bool *whout, bool *opq, bool to_head)
+struct erofs_dentry *erofs_rebuild_get_dentry(struct 
erofs_rebuild_getdentry_ctx *ctx)
 {
        struct erofs_dentry *d = NULL;
-       unsigned int len = strlen(path);
-       char *s = path;
+       unsigned int len = strlen(ctx->path);
+       char *s = ctx->path;
 
-       *whout = false;
-       *opq = false;
+       *ctx->whout = false;
+       *ctx->opq = false;
 
-       while (s < path + len) {
-               char *slash = memchr(s, '/', path + len - s);
+       while (s < ctx->path + len) {
+               char *slash = memchr(s, '/', ctx->path + len - s);
 
                if (slash) {
                        if (s == slash) {
@@ -82,22 +82,22 @@ struct erofs_dentry *erofs_rebuild_get_dentry(struct 
erofs_inode *pwd,
                if (!memcmp(s, ".", 2)) {
                        /* null */
                } else if (!memcmp(s, "..", 3)) {
-                       pwd = pwd->i_parent;
+                       ctx->pwd = ctx->pwd->i_parent;
                } else {
                        struct erofs_inode *inode = NULL;
 
-                       if (aufs && !slash) {
+                       if (ctx->aufs && !slash) {
                                if (!memcmp(s, AUFS_WH_DIROPQ, 
sizeof(AUFS_WH_DIROPQ))) {
-                                       *opq = true;
+                                       *ctx->opq = true;
                                        break;
                                }
                                if (!memcmp(s, AUFS_WH_PFX, sizeof(AUFS_WH_PFX) 
- 1)) {
                                        s += sizeof(AUFS_WH_PFX) - 1;
-                                       *whout = true;
+                                       *ctx->whout = true;
                                }
                        }
 
-                       list_for_each_entry(d, &pwd->i_subdirs, d_child) {
+                       list_for_each_entry(d, &ctx->pwd->i_subdirs, d_child) {
                                if (!strcmp(d->name, s)) {
                                        if (d->type != EROFS_FT_DIR && slash)
                                                return ERR_PTR(-EIO);
@@ -107,22 +107,22 @@ struct erofs_dentry *erofs_rebuild_get_dentry(struct 
erofs_inode *pwd,
                        }
 
                        if (inode) {
-                               if (to_head) {
+                               if (ctx->to_head) {
                                        list_del(&d->d_child);
-                                       list_add(&d->d_child, &pwd->i_subdirs);
+                                       list_add(&d->d_child, 
&ctx->pwd->i_subdirs);
                                }
-                               pwd = inode;
+                               ctx->pwd = inode;
                        } else if (!slash) {
-                               d = erofs_d_alloc(pwd, s);
+                               d = erofs_d_alloc(ctx->pwd, s);
                                if (IS_ERR(d))
                                        return d;
                                d->type = EROFS_FT_UNKNOWN;
-                               d->inode = pwd;
+                               d->inode = ctx->pwd;
                        } else {
-                               d = erofs_rebuild_mkdir(pwd, s);
+                               d = erofs_rebuild_mkdir(ctx->pwd, s);
                                if (IS_ERR(d))
                                        return d;
-                               pwd = d->inode;
+                               ctx->pwd = d->inode;
                        }
                }
                if (slash) {
@@ -267,6 +267,7 @@ static int erofs_rebuild_dirent_iter(struct 
erofs_dir_context *ctx)
 {
        struct erofs_rebuild_dir_context *rctx = (void *)ctx;
        struct erofs_inode *mergedir = rctx->mergedir;
+       struct erofs_rebuild_getdentry_ctx dctx;
        struct erofs_inode *dir = ctx->dir;
        struct erofs_inode *inode, *candidate;
        struct erofs_inode src;
@@ -286,8 +287,12 @@ static int erofs_rebuild_dirent_iter(struct 
erofs_dir_context *ctx)
        erofs_dbg("parsing %s", path);
        dname = path + strlen(mergedir->i_srcpath) + 1;
 
-       d = erofs_rebuild_get_dentry(mergedir, dname, false,
-                                    &dumb, &dumb, false);
+       dctx.pwd = mergedir;
+       dctx.path = dname;
+       dctx.aufs = false;
+       dctx.whout = dctx.opq = &dumb;
+       dctx.to_head = false;
+       d = erofs_rebuild_get_dentry(&dctx);
        if (IS_ERR(d)) {
                ret = PTR_ERR(d);
                goto out;
@@ -435,6 +440,7 @@ int erofs_rebuild_load_tree(struct erofs_inode *root, 
struct erofs_sb_info *sbi,
 static int erofs_rebuild_basedir_dirent_iter(struct erofs_dir_context *ctx)
 {
        struct erofs_rebuild_dir_context *rctx = (void *)ctx;
+       struct erofs_rebuild_getdentry_ctx dctx;
        struct erofs_inode *dir = ctx->dir;
        struct erofs_inode *mergedir = rctx->mergedir;
        struct erofs_dentry *d;
@@ -448,8 +454,13 @@ static int erofs_rebuild_basedir_dirent_iter(struct 
erofs_dir_context *ctx)
        dname = strndup(ctx->dname, ctx->de_namelen);
        if (!dname)
                return -ENOMEM;
-       d = erofs_rebuild_get_dentry(mergedir, dname, false,
-                                    &dumb, &dumb, false);
+
+       dctx.pwd = mergedir;
+       dctx.path = dname;
+       dctx.aufs = false;
+       dctx.whout = dctx.opq = &dumb;
+       dctx.to_head = false;
+       d = erofs_rebuild_get_dentry(&dctx);
        if (IS_ERR(d)) {
                ret = PTR_ERR(d);
                goto out;
diff --git a/lib/tar.c b/lib/tar.c
index 990c6cb1b372..60f12cc539c9 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -657,6 +657,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;
+       struct erofs_rebuild_getdentry_ctx dctx;
        bool whout, opq, e = false;
        struct stat st;
        erofs_off_t tar_offset, dataoff;
@@ -907,7 +908,13 @@ out_eot:
 
        erofs_dbg("parsing %s (mode %05o)", eh.path, st.st_mode);
 
-       d = erofs_rebuild_get_dentry(root, eh.path, tar->aufs, &whout, &opq, 
true);
+       dctx.pwd = root;
+       dctx.path = eh.path;
+       dctx.aufs = tar->aufs;
+       dctx.whout = &whout;
+       dctx.opq = &opq;
+       dctx.to_head = true;
+       d = erofs_rebuild_get_dentry(&dctx);
        if (IS_ERR(d)) {
                ret = PTR_ERR(d);
                goto out;
@@ -945,8 +952,12 @@ out_eot:
                }
                d->inode = NULL;
 
-               d2 = erofs_rebuild_get_dentry(root, eh.link, tar->aufs,
-                                             &dumb, &dumb, false);
+               dctx.pwd = root;
+               dctx.path = eh.link;
+               dctx.aufs = tar->aufs;
+               dctx.whout = dctx.opq = &dumb;
+               dctx.to_head = false;
+               d2 = erofs_rebuild_get_dentry(&dctx);
                if (IS_ERR(d2)) {
                        ret = PTR_ERR(d2);
                        goto out;
-- 
2.43.5

Reply via email to