diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-04-19 11:04:27 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-04-19 12:53:42 -0600 |
commit | d81b0e1036aedb127c4033a187b671deaaca54c4 (patch) | |
tree | 5c6f5a2e1bbbda0bc2a4d6f9c82b148ebf0d7569 /lib9p_util/static.c | |
parent | b85e0bd570de1245afa2738057925320789601c5 (diff) |
lib9p_srv: Rethink the dio interface
Diffstat (limited to 'lib9p_util/static.c')
-rw-r--r-- | lib9p_util/static.c | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/lib9p_util/static.c b/lib9p_util/static.c index e1df3ca..d2413c6 100644 --- a/lib9p_util/static.c +++ b/lib9p_util/static.c @@ -110,33 +110,23 @@ static lo_interface lib9p_srv_dio util9p_static_dir_dopen(struct util9p_static_d static void util9p_static_dir_iofree(struct util9p_static_dir *self) { assert(self); } -static size_t util9p_static_dir_dread(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, - uint8_t *buf, - uint32_t byte_count, - size_t _obj_offset) { +static struct lib9p_srv_dirent util9p_static_dir_dread(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, size_t idx) { assert(self); assert(ctx); - uint32_t byte_offset = 0; - size_t obj_offset = _obj_offset; - while (!LO_IS_NULL(self->members[obj_offset])) { - lo_interface lib9p_srv_file file = self->members[obj_offset]; - struct lib9p_stat stat = LO_CALL(file, stat, ctx); - if (lib9p_ctx_has_error(&ctx->basectx)) - break; - lib9p_stat_assert(stat); - uint32_t nbytes = lib9p_stat_marshal(&ctx->basectx, byte_count-byte_offset, &stat, - &buf[byte_offset]); - if (!nbytes) { - if (obj_offset == _obj_offset) - lib9p_error(&ctx->basectx, - LIB9P_ERRNO_L_ERANGE, "stat object does not fit into negotiated max message size"); - break; - } - byte_offset += nbytes; - obj_offset++; - } - return obj_offset - _obj_offset; + lo_interface lib9p_srv_file file = self->members[idx]; + if (LO_IS_NULL(file)) + return (struct lib9p_srv_dirent){}; + + struct lib9p_stat stat = LO_CALL(file, stat, ctx); + if (lib9p_ctx_has_error(&ctx->basectx)) + return (struct lib9p_srv_dirent){}; + lib9p_stat_assert(stat); + + return (struct lib9p_srv_dirent){ + .qid = stat.qid, + .name = stat.name, + }; } /* file ***********************************************************************/ |