From e9d147260c2796d21b18b111f1e3b62d01ddda21 Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Mon, 27 Jan 2025 14:46:29 -0500 Subject: [PATCH] Fix ctx->pos updating to properly handle dent gaps We need to assure we're emitting dents with the proper position and we already have them as part of our dent. The only caveat is to increment ctx->pos once beyond the list to make sure the caller doesn't call us once more. Signed-off-by: Auke Kok --- kmod/src/dir.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kmod/src/dir.c b/kmod/src/dir.c index fb468df1..95ba9db0 100644 --- a/kmod/src/dir.c +++ b/kmod/src/dir.c @@ -537,15 +537,18 @@ static int scoutfs_readdir(struct file *file, struct dir_context *ctx) dent = page_address(page); for (; entries > 0; entries--) { + ctx->pos = le64_to_cpu(dent->pos); if (!dir_emit(ctx, dent->name, dent->hacky_name_len, le64_to_cpu(dent->ino), dentry_type(dent->type))) { ret = 0; goto out; } - ctx->pos = le64_to_cpu(dent->pos) + 1; dent = next_aligned_dirent(dent, dent->hacky_name_len); + + /* always advance ctx->pos past */ + ctx->pos++; } if (complete)