diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-29 01:22:12 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-29 01:23:49 -0600 |
commit | affe77a2b068a9de236f0d7703092dbfafacff5e (patch) | |
tree | 996ad7216b10c0237657e947bbb7aafc24aef170 /lib9p/include | |
parent | 4d185da010aea1d307c8ff7807ef3d4359083ed0 (diff) |
lib9p/9p.h: Tidy up
Diffstat (limited to 'lib9p/include')
-rw-r--r-- | lib9p/include/lib9p/9p.h | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/lib9p/include/lib9p/9p.h b/lib9p/include/lib9p/9p.h index bf304ac..171ad3b 100644 --- a/lib9p/include/lib9p/9p.h +++ b/lib9p/include/lib9p/9p.h @@ -24,13 +24,15 @@ #define CONFIG_9P_ENABLE_9P2000 #endif -/******************************************************************************/ +/* protocol definitions *******************************************************/ #include <lib9p/9p.generated.h> /* *after* config.h */ #define LIB9P_NOTAG ((uint16_t)~0U) #define LIB9P_NOFID ((uint32_t)~0U) +/* ctx ************************************************************************/ + struct lib9p_ctx { /* negotiated */ enum lib9p_version version; @@ -43,37 +45,19 @@ struct lib9p_ctx { char err_msg[CONFIG_9P_MAX_ERR_SIZE]; }; -static 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'; -} +void lib9p_ctx_clear_error(struct lib9p_ctx *ctx); -static bool lib9p_ctx_has_error(struct lib9p_ctx *ctx) { - assert(ctx); - return ctx->err_msg[0]; -} - -const char *lib9p_msg_type_str(struct lib9p_ctx *, enum lib9p_msg_type); - -/** Assert that a `struct lib9p_stat` object looks valid. */ -static inline void lib9p_assert_stat(struct lib9p_stat stat) { - assert( ((bool)(stat.file_mode & LIB9P_DM_DIR )) == ((bool)(stat.file_qid.type & LIB9P_QT_DIR )) ); - assert( ((bool)(stat.file_mode & LIB9P_DM_APPEND )) == ((bool)(stat.file_qid.type & LIB9P_QT_APPEND )) ); - assert( ((bool)(stat.file_mode & LIB9P_DM_EXCL )) == ((bool)(stat.file_qid.type & LIB9P_QT_EXCL )) ); - assert( ((bool)(stat.file_mode & _LIB9P_DM_PLAN9_MOUNT)) == ((bool)(stat.file_qid.type & _LIB9P_QT_PLAN9_MOUNT)) ); - assert( ((bool)(stat.file_mode & LIB9P_DM_AUTH )) == ((bool)(stat.file_qid.type & LIB9P_QT_AUTH )) ); - assert( ((bool)(stat.file_mode & LIB9P_DM_TMP )) == ((bool)(stat.file_qid.type & LIB9P_QT_TMP )) ); - assert( (stat.file_size == 0) || !(stat.file_mode & LIB9P_DM_DIR) ); -} +bool lib9p_ctx_has_error(struct lib9p_ctx *ctx); /** Write an static error into ctx, return -1. */ int lib9p_error(struct lib9p_ctx *ctx, uint32_t linux_errno, char const *msg); /** Write a printf-style error into ctx, return -1. */ int lib9p_errorf(struct lib9p_ctx *ctx, uint32_t linux_errno, char const *fmt, ...); +const char *lib9p_msg_type_str(struct lib9p_ctx *, enum lib9p_msg_type); + +/* main message functions *****************************************************/ + /** * Validate a message's structure; it's size, string encodings, enums, * and bitfields. @@ -138,6 +122,19 @@ void lib9p_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, bool lib9p_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body, uint8_t *ret_bytes); +/* `struct lib9p_stat` helpers ************************************************/ + +/** Assert that a `struct lib9p_stat` object looks valid. */ +static inline void lib9p_assert_stat(struct lib9p_stat stat) { + assert( ((bool)(stat.file_mode & LIB9P_DM_DIR )) == ((bool)(stat.file_qid.type & LIB9P_QT_DIR )) ); + assert( ((bool)(stat.file_mode & LIB9P_DM_APPEND )) == ((bool)(stat.file_qid.type & LIB9P_QT_APPEND )) ); + assert( ((bool)(stat.file_mode & LIB9P_DM_EXCL )) == ((bool)(stat.file_qid.type & LIB9P_QT_EXCL )) ); + assert( ((bool)(stat.file_mode & _LIB9P_DM_PLAN9_MOUNT)) == ((bool)(stat.file_qid.type & _LIB9P_QT_PLAN9_MOUNT)) ); + assert( ((bool)(stat.file_mode & LIB9P_DM_AUTH )) == ((bool)(stat.file_qid.type & LIB9P_QT_AUTH )) ); + assert( ((bool)(stat.file_mode & LIB9P_DM_TMP )) == ((bool)(stat.file_qid.type & LIB9P_QT_TMP )) ); + assert( (stat.file_size == 0) || !(stat.file_mode & LIB9P_DM_DIR) ); +} + /** * TODO * |