diff options
-rw-r--r-- | lib9p/srv.c | 10 |
1 files 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); } |