Skip to contentSkip to conversation

erofs-utils: dump: use a new subdir context for erofs_get_pathname()

PATCH New Gao Xiang 1 participant 1 message Aug 3, 2023 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs-utils: dump: use a new subdir context for erofs_get_pathname()

It's absolutely unsafe to reuse struct erofs_dir_context. Also, we'd like to refactor erofs_get_pathname() in the future.

---
 lib/dir.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
lib/dir.c +10 -4
index e8df9f7..fff0bc0 100644
@@ -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);
Signature · 1 line
2.24.4