From 8b95b3bcb5b85a582ef9723383fd137206bd5089 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Wed, 4 Jun 2025 17:10:56 -0600 Subject: lib9p: core.h: Fix doc comment --- lib9p/core_include/lib9p/core.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib9p/core_include') diff --git a/lib9p/core_include/lib9p/core.h b/lib9p/core_include/lib9p/core.h index 1fb71f1..69b8d3f 100644 --- a/lib9p/core_include/lib9p/core.h +++ b/lib9p/core_include/lib9p/core.h @@ -202,14 +202,12 @@ void lib9p_stat_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, * marshal bitfield bits that aren't in ctx->version; it applies a * version-specific mask to bitfields. * - * @param ctx : negotiated protocol parameters, where to record errors + * @param ctx : negotiated protocol parameters * @param max_net_size : the maximum network-encoded size to allow * @param obj : the message to encode * * @return ret_bytes: the buffer to encode into * @return the number of bytes written, or 0 if the stat object does not fit in max_net_size - * - * @errno L_ERANGE: reply does not fit in max_net_size */ uint32_t lib9p_stat_marshal(struct lib9p_ctx *ctx, uint32_t max_net_size, struct lib9p_stat *obj, uint8_t *ret_bytes); -- cgit v1.2.3-2-g168b From 2e50e86aade27ac8d66c768713c6cdb2526432c3 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Wed, 4 Jun 2025 20:21:40 -0600 Subject: Prune #includes --- lib9p/core_include/lib9p/_core_generated.h | 2 -- lib9p/core_include/lib9p/core.h | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib9p/core_include') diff --git a/lib9p/core_include/lib9p/_core_generated.h b/lib9p/core_include/lib9p/_core_generated.h index d1ecd6e..de7795a 100644 --- a/lib9p/core_include/lib9p/_core_generated.h +++ b/lib9p/core_include/lib9p/_core_generated.h @@ -6,8 +6,6 @@ /* config *********************************************************************/ -#include "config.h" - #ifndef CONFIG_9P_ENABLE_9P2000 #error config.h must define CONFIG_9P_ENABLE_9P2000 #endif diff --git a/lib9p/core_include/lib9p/core.h b/lib9p/core_include/lib9p/core.h index 69b8d3f..27553a3 100644 --- a/lib9p/core_include/lib9p/core.h +++ b/lib9p/core_include/lib9p/core.h @@ -16,7 +16,9 @@ #include #define CONFIG_9P_ENABLE_uninitialized 1 -#include +#include "config.h" + +#include /* _after_ other includes, including config.h */ #ifndef CONFIG_9P_MAX_ERR_SIZE #error config.h must define CONFIG_9P_MAX_ERR_SIZE -- cgit v1.2.3-2-g168b From 8a9fc1704dcf3ec117a3bf37fd70a44a43873659 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Thu, 29 May 2025 23:39:12 -0400 Subject: lib9p: Use errnums internally --- lib9p/core_include/lib9p/core.h | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'lib9p/core_include') diff --git a/lib9p/core_include/lib9p/core.h b/lib9p/core_include/lib9p/core.h index 27553a3..7bee2f1 100644 --- a/lib9p/core_include/lib9p/core.h +++ b/lib9p/core_include/lib9p/core.h @@ -51,9 +51,7 @@ struct lib9p_ctx { uint32_t max_msg_size; /* state */ -#if CONFIG_9P_ENABLE_9P2000_u || CONFIG_9P_ENABLE_9P2000_L - lib9p_errno_t err_num; -#endif + _errnum err_num; [[gnu::nonstring]] char err_msg[CONFIG_9P_MAX_ERR_SIZE]; }; @@ -61,16 +59,10 @@ void lib9p_ctx_clear_error(struct lib9p_ctx *ctx); bool lib9p_ctx_has_error(struct lib9p_ctx *ctx); -#if CONFIG_9P_ENABLE_9P2000_u || CONFIG_9P_ENABLE_9P2000_L - #define _lib9p_set_err_num(ctx, linux_errno) do { (ctx)->err_num = linux_errno; } while (0) -#else - #define _lib9p_set_err_num(ctx, linux_errno) do { } while (0) -#endif - /** Write a -style error into ctx, return -1. */ -#define lib9p_error(ctx, linux_errno, ...) ({ \ +#define lib9p_error(ctx, libmisc_errno, ...) ({ \ if (!lib9p_ctx_has_error(ctx)) { \ - _lib9p_set_err_num(ctx, linux_errno); \ + (ctx)->err_num = libmisc_errno; \ struct fmt_buf _w = { \ .dat = (ctx)->err_msg, \ .cap = sizeof((ctx)->err_msg), \ @@ -105,12 +97,12 @@ void fmt_print_lib9p_msg(lo_interface fmt_dest w, struct lib9p_ctx *ctx, enum li * * @return required size, or -1 on error * - * @errno L_EOPNOTSUPP: message is an R-message - * @errno L_EOPNOTSUPP: message has unknown type - * @errno L_EBADMSG: message is wrong size for content - * @errno L_EILSEQ: message contains invalid UTF-8, or the UTF-8 contains a nul-byte - * @errno L_EBADMSG: message contains a bitfield with unknown bits - * @errno L_EMSGSIZE: would-be return value overflows SSIZE_MAX + * @errno E_POSIX_EOPNOTSUPP: message is an R-message + * @errno E_POSIX_EOPNOTSUPP: message has unknown type + * @errno E_POSIX_EBADMSG: message is wrong size for content + * @errno E_POSIX_EILSEQ: message contains invalid UTF-8, or the UTF-8 contains a nul-byte + * @errno E_POSIX_EBADMSG: message contains a bitfield with unknown bits + * @errno E_POSIX_EMSGSIZE: would-be return value overflows SSIZE_MAX */ ssize_t lib9p_Tmsg_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes); @@ -145,7 +137,7 @@ void lib9p_Tmsg_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, * @return ret : the buffer to encode to * @return whether there was an error (false=success, true=error) * - * @errno L_ERANGE: reply does not fit in ctx->max_msg_size + * @errno E_POSIX_ERANGE: reply does not fit in ctx->max_msg_size */ bool lib9p_Tmsg_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body, struct lib9p_Tmsg_send_buf *ret); -- cgit v1.2.3-2-g168b From 945756b1b050bdf09d1119854cc5b22ad15efacd Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Thu, 29 May 2025 22:25:02 -0400 Subject: lib9p_core: Switch to use error.h --- lib9p/core_include/lib9p/core.h | 57 ++++++++++------------------------------- 1 file changed, 14 insertions(+), 43 deletions(-) (limited to 'lib9p/core_include') diff --git a/lib9p/core_include/lib9p/core.h b/lib9p/core_include/lib9p/core.h index 7bee2f1..9d92312 100644 --- a/lib9p/core_include/lib9p/core.h +++ b/lib9p/core_include/lib9p/core.h @@ -20,11 +20,6 @@ #include /* _after_ other includes, including config.h */ -#ifndef CONFIG_9P_MAX_ERR_SIZE - #error config.h must define CONFIG_9P_MAX_ERR_SIZE -#endif -static_assert(CONFIG_9P_MAX_ERR_SIZE <= UINT16_MAX); - /* constants ******************************************************************/ enum { @@ -49,32 +44,8 @@ struct lib9p_ctx { /* negotiated */ enum lib9p_version version; uint32_t max_msg_size; - - /* state */ - _errnum err_num; - [[gnu::nonstring]] char err_msg[CONFIG_9P_MAX_ERR_SIZE]; }; -void lib9p_ctx_clear_error(struct lib9p_ctx *ctx); - -bool lib9p_ctx_has_error(struct lib9p_ctx *ctx); - -/** Write a -style error into ctx, return -1. */ -#define lib9p_error(ctx, libmisc_errno, ...) ({ \ - if (!lib9p_ctx_has_error(ctx)) { \ - (ctx)->err_num = libmisc_errno; \ - struct fmt_buf _w = { \ - .dat = (ctx)->err_msg, \ - .cap = sizeof((ctx)->err_msg), \ - }; \ - lo_interface fmt_dest w = LO_BOX(fmt_dest, &_w); \ - fmt_print(w, __VA_ARGS__); \ - if (_w.len < _w.cap) \ - memset(_w.dat + _w.len, 0, _w.cap - _w.len); \ - } \ - -1; \ -}) - /* misc utilities *************************************************************/ uint32_t lib9p_version_min_Rerror_size(enum lib9p_version); @@ -92,10 +63,10 @@ void fmt_print_lib9p_msg(lo_interface fmt_dest w, struct lib9p_ctx *ctx, enum li * number may be larger than net_bytes due to (1) struct padding, (2) * array pointers. * - * @param ctx : negotiated protocol parameters, where to record errors + * @param ctx : negotiated protocol parameters * @param net_bytes : the complete request, starting with the "size[4]" * - * @return required size, or -1 on error + * @return required size, or an error * * @errno E_POSIX_EOPNOTSUPP: message is an R-message * @errno E_POSIX_EOPNOTSUPP: message has unknown type @@ -104,7 +75,7 @@ void fmt_print_lib9p_msg(lo_interface fmt_dest w, struct lib9p_ctx *ctx, enum li * @errno E_POSIX_EBADMSG: message contains a bitfield with unknown bits * @errno E_POSIX_EMSGSIZE: would-be return value overflows SSIZE_MAX */ -ssize_t lib9p_Tmsg_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes); +size_t_or_error lib9p_Tmsg_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes); /** * Unmarshal the 9P message `net_bytes` into the C struct `ret_body`. @@ -130,27 +101,27 @@ void lib9p_Tmsg_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, * marshal bitfield bits that aren't in ctx->version; it applies a * version-specific mask to bitfields. * - * @param ctx : negotiated protocol parameters, where to record errors + * @param ctx : negotiated protocol parameters * @param typ : the message type * @param msg : the message to encode (`struct lib9p_msg_XXXX` according to `typ`) * * @return ret : the buffer to encode to - * @return whether there was an error (false=success, true=error) + * @return error * * @errno E_POSIX_ERANGE: reply does not fit in ctx->max_msg_size */ -bool lib9p_Tmsg_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body, - struct lib9p_Tmsg_send_buf *ret); +error lib9p_Tmsg_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body, + struct lib9p_Tmsg_send_buf *ret); /* main R-message functions ***************************************************/ /** Same as above, but for R-messages instead of T-messages. */ -ssize_t lib9p_Rmsg_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes); +size_t_or_error lib9p_Rmsg_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes); void lib9p_Rmsg_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, enum lib9p_msg_type *ret_typ, void *ret_body); -bool lib9p_Rmsg_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body, - struct lib9p_Rmsg_send_buf *ret); +error lib9p_Rmsg_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body, + struct lib9p_Rmsg_send_buf *ret); /* `struct lib9p_stat` helpers ************************************************/ @@ -162,16 +133,16 @@ void fmt_print_lib9p_stat(lo_interface fmt_dest w, struct lib9p_ctx *ctx, struct /** * Validate a message's `stat` structure. * - * @param ctx : negotiated protocol parameters, where to record errors + * @param ctx : negotiated protocol parameters * @param net_bytes : network-encoded stat structure * @param net_size : the number of net_bytes that may be read * * @return ret_net_size : number of bytes consumed; <=net_size * @return ret_host_size : number of bytes that lib9p_stat_unmarshal would take - * @return whether there was an error + * @return error */ -bool lib9p_stat_validate(struct lib9p_ctx *ctx, uint32_t net_size, uint8_t *net_bytes, - uint32_t *ret_net_size, size_t *ret_host_size); +error lib9p_stat_validate(struct lib9p_ctx *ctx, uint32_t net_size, uint8_t *net_bytes, + uint32_t *ret_net_size, size_t *ret_host_size); /** * Unmarshal the 9P `net_bytes` into the C struct `ret_obj`. -- cgit v1.2.3-2-g168b