From affe77a2b068a9de236f0d7703092dbfafacff5e Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Tue, 29 Oct 2024 01:22:12 -0600 Subject: lib9p/9p.h: Tidy up --- lib9p/9p.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'lib9p/9p.c') diff --git a/lib9p/9p.c b/lib9p/9p.c index 9f0bd4c..9ea0c46 100644 --- a/lib9p/9p.c +++ b/lib9p/9p.c @@ -13,6 +13,21 @@ #include "internal.h" +/* ctx ************************************************************************/ + +void lib9p_ctx_clear_error(struct lib9p_ctx *ctx) { + assert(ctx); +#ifdef CONFIG_9P_ENABLE_9P2000_u + ctx->err_num = 0; +#endif + ctx->err_msg[0] = '\0'; +} + +bool lib9p_ctx_has_error(struct lib9p_ctx *ctx) { + assert(ctx); + return ctx->err_msg[0]; +} + int lib9p_error(struct lib9p_ctx *ctx, uint32_t linux_errno, char const *msg) { if (lib9p_ctx_has_error(ctx)) return -1; @@ -49,12 +64,13 @@ int lib9p_errorf(struct lib9p_ctx *ctx, uint32_t linux_errno, char const *fmt, . return -1; } - const char *lib9p_msg_type_str(struct lib9p_ctx *ctx, enum lib9p_msg_type typ) { assert(0 <= typ && typ <= 0xFF); return _lib9p_versions[ctx->version].msgs[typ].name; } +/* main message functions *****************************************************/ + ssize_t lib9p_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes) { /* Inspect the first 5 bytes ourselves. */ struct _validate_ctx subctx = { @@ -115,6 +131,8 @@ bool lib9p_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body, return table.marshal(&subctx, body); } +/* `struct lib9p_stat` helpers ************************************************/ + bool lib9p_validate_stat(struct lib9p_ctx *ctx, uint32_t net_size, uint8_t *net_bytes, uint32_t *ret_net_size, ssize_t *ret_host_size) { struct _validate_ctx subctx = { -- cgit v1.2.3-2-g168b