diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-10 21:48:16 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-10 21:48:16 -0600 |
commit | 2145808d29f495cf872d9b3ffe05420ff9fc5be6 (patch) | |
tree | 78ec87bcb6bdf9a19bd6f5a2cb6cb3f8333bfdbc /cmd | |
parent | db92bd35807305e6daec5ec40bd67cbc43fe88ee (diff) |
implement dread
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/srv9p/static.c | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/cmd/srv9p/static.c b/cmd/srv9p/static.c index 912ec03..a6da53f 100644 --- a/cmd/srv9p/static.c +++ b/cmd/srv9p/static.c @@ -99,6 +99,35 @@ static struct lib9p_srv_file *static_dir_dcreate(struct lib9p_srv_ctx *ctx, stru return NULL; } +static size_t static_dir_dread(struct lib9p_srv_ctx *ctx, struct lib9p_srv_file *_dir, + uint8_t *buf, + uint32_t byte_count, + size_t _obj_offset) { + assert(ctx); + struct static_dir *dir = (struct static_dir *)_dir; + assert(dir); + + uint32_t byte_offset = 0; + size_t obj_offset = _obj_offset; + while (dir->members[obj_offset]) { + struct lib9p_srv_file *filep = dir->members[obj_offset]; + struct lib9p_stat stat = filep->vtable->stat(ctx, filep); + if (lib9p_ctx_has_error(&ctx->basectx)) + break; + uint32_t nbytes = lib9p_marshal_stat(&ctx->basectx, byte_count-byte_offset, &stat, + &buf[byte_offset]); + if (!nbytes) { + if (obj_offset == _obj_offset) + lib9p_error(&ctx->basectx, + LINUX_ERANGE, "stat object does not fit into negotiated max message size"); + break; + } + byte_offset += nbytes; + obj_offset++; + } + return obj_offset - _obj_offset; +} + struct lib9p_srv_file_vtable static_dir_vtable = { .clone = static_dir_clone, .free = static_dir_free, @@ -110,10 +139,6 @@ struct lib9p_srv_file_vtable static_dir_vtable = { .dopen = static_dir_dopen, .dcreate = static_dir_dcreate, -}; -/* - struct lib9p_srv_io_dir_vtable static_dir_io_vtable = { - .readdir = TODO, - }; -*/ + .dread = static_dir_dread, +}; |