From c0aa439917eb204ef481bc037dc3f552ab9d36c0 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sat, 12 Oct 2024 18:39:00 -0600 Subject: lib9p: Fix directory listing --- lib9p/srv.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib9p/srv.c b/lib9p/srv.c index 6953687..a3e4335 100644 --- a/lib9p/srv.c +++ b/lib9p/srv.c @@ -813,6 +813,7 @@ static void handle_Tread(struct _lib9p_srv_req *ctx, /* Do it. */ if (fidinfo->flags & FIDFLAG_ISDIR) { + /* Translate byte-offset to object-index. */ size_t idx; if (req->offset == 0) idx = 0; @@ -824,16 +825,19 @@ static void handle_Tread(struct _lib9p_srv_req *ctx, fidinfo->dir_off, req->offset); return; } + /* Do it. */ size_t num = file->vtable->dread(&ctx->ctx, file, (uint8_t *)resp->data.dat, req->count, idx); - fidinfo->dir_idx = idx+num; + /* Translate object-count back to byte-count. */ uint32_t len = 0; for (size_t i = 0; i < num; i++) { uint32_t i_len; - lib9p_validate_stat(&ctx->ctx.basectx, req->count, (uint8_t *)resp->data.dat, &i_len, NULL); + lib9p_validate_stat(&ctx->ctx.basectx, req->count, &((uint8_t *)resp->data.dat)[len], &i_len, NULL); len += i_len; } - fidinfo->dir_off = req->offset + len; resp->data.len = len; + /* Remember. */ + fidinfo->dir_idx = idx+num; + fidinfo->dir_off = req->offset + len; } else resp->data.len = file->vtable->pread(&ctx->ctx, file, resp->data.dat, req->count, req->offset); } -- cgit v1.2.3-2-g168b