erofs-utils: dump: use a new subdir context for erofs_get_pathname()
authorGao Xiang <hsiangkao@linux.alibaba.com>
Thu, 3 Aug 2023 05:00:31 +0000 (13:00 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Thu, 3 Aug 2023 11:10:45 +0000 (19:10 +0800)
It's absolutely unsafe to reuse struct erofs_dir_context.  Also,
we'd like to refactor erofs_get_pathname() in the future.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20230803050031.130026-1-hsiangkao@linux.alibaba.com
lib/dir.c

index e8df9f70e322ef2505ed92182e8d0a3c22d3a4f5..fff0bc076fb34b5e6b60cd6bb5a820b033b552ec 100644 (file)
--- a/lib/dir.c
+++ b/lib/dir.c
@@ -217,10 +217,16 @@ static int erofs_get_pathname_iter(struct erofs_dir_context *ctx)
                }
 
                if (S_ISDIR(dir.i_mode)) {
-                       ctx->dir = &dir;
-                       pathctx->pos = pos + len + 1;
-                       ret = erofs_iterate_dir(ctx, false);
-                       pathctx->pos = pos;
+                       struct erofs_get_pathname_context nctx = {
+                               .ctx.flags = 0,
+                               .ctx.dir = &dir,
+                               .ctx.cb = erofs_get_pathname_iter,
+                               .target_nid = pathctx->target_nid,
+                               .buf = pathctx->buf,
+                               .size = pathctx->size,
+                               .pos = pos + len + 1,
+                       };
+                       ret = erofs_iterate_dir(&nctx.ctx, false);
                        if (ret == EROFS_PATHNAME_FOUND) {
                                pathctx->buf[pos++] = '/';
                                strncpy(pathctx->buf + pos, dname, len);