diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-01-14 01:11:17 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-01-14 01:11:17 -0700 |
commit | f7c75fe0113cdbd3e13b4e22edf76d9456c4b064 (patch) | |
tree | d65c0c26f7d100085d6a563aea9df1b501cbbd19 /lib9p | |
parent | 7eda822ef31a15d22de03fc1eec7d995f661b26d (diff) | |
parent | a02f59f255006a2d6cb236fe2448b69c9c223adb (diff) |
Merge branch 'lukeshu/9p-code-size'
Diffstat (limited to 'lib9p')
-rw-r--r-- | lib9p/9p.c | 97 | ||||
-rw-r--r-- | lib9p/9p.generated.c | 1396 | ||||
-rwxr-xr-x | lib9p/idl.gen | 69 | ||||
-rw-r--r-- | lib9p/include/lib9p/9p.h | 50 | ||||
-rw-r--r-- | lib9p/internal.h | 24 | ||||
-rw-r--r-- | lib9p/srv.c | 40 |
6 files changed, 525 insertions, 1151 deletions
@@ -1,6 +1,6 @@ /* lib9p/9p.c - Base 9P protocol utilities for both clients and servers * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -9,6 +9,9 @@ #include <stdio.h> /* for vsnprintf() */ #include <string.h> /* for strncpy() */ +#define LOG_NAME 9P +#include <libmisc/log.h> /* for const_byte_str() */ + #include <lib9p/9p.h> #include "internal.h" @@ -69,12 +72,16 @@ const char *lib9p_msg_type_str(struct lib9p_ctx *ctx, enum lib9p_msg_type typ) { #pragma GCC diagnostic ignored "-Wtype-limits" assert(0 <= typ && typ <= 0xFF); #pragma GCC diagnostic pop - return _lib9p_versions[ctx->version].msgs[typ].name; + return _lib9p_table_msg_name[ctx->version][typ] ?: const_byte_str(typ); } /* main message functions *****************************************************/ -ssize_t lib9p_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes) { +static +ssize_t _lib9p_validate(uint8_t xxx_low_typ_bit, + const char *xxx_errmsg, + const struct _lib9p_recv_tentry xxx_table[LIB9P_VER_NUM][0x80], + struct lib9p_ctx *ctx, uint8_t *net_bytes) { /* Inspect the first 5 bytes ourselves. */ struct _validate_ctx subctx = { .ctx = ctx, @@ -87,13 +94,16 @@ ssize_t lib9p_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes) { if (subctx.net_size < 5) return lib9p_error(ctx, LINUX_EBADMSG, "message is impossibly short"); uint8_t typ = net_bytes[4]; - struct _table_msg table = _lib9p_versions[ctx->version].msgs[typ]; - if (!table.validate) + if (typ % 2 != xxx_low_typ_bit) + return lib9p_errorf(ctx, LINUX_EOPNOTSUPP, "%s: message_type=%s", xxx_errmsg, + lib9p_msg_type_str(ctx, typ)); + struct _lib9p_recv_tentry tentry = xxx_table[ctx->version][typ/2]; + if (!tentry.validate) return lib9p_errorf(ctx, LINUX_EOPNOTSUPP, "unknown message type: %s (protocol_version=%s)", lib9p_msg_type_str(ctx, typ), lib9p_version_str(ctx->version)); - /* Now use the message-type-specific table to process the whole thing. */ - if (table.validate(&subctx)) + /* Now use the message-type-specific tentry to process the whole thing. */ + if (tentry.validate(&subctx)) return -1; assert(subctx.net_offset <= subctx.net_size); if (subctx.net_offset < subctx.net_size) @@ -102,13 +112,25 @@ ssize_t lib9p_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes) { /* Return. */ ssize_t ret; - if (__builtin_add_overflow(table.basesize, subctx.host_extra, &ret)) + if (__builtin_add_overflow(tentry.basesize, subctx.host_extra, &ret)) return lib9p_error(ctx, LINUX_EMSGSIZE, "unmarshalled payload overflows SSIZE_MAX"); return ret; } -void lib9p_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, - enum lib9p_msg_type *ret_typ, void *ret_body) { +ssize_t lib9p_Tmsg_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes) { + return _lib9p_validate(0, "expected a T-message but got an R-message", _lib9p_table_Tmsg_recv, + ctx, net_bytes); +} + +ssize_t lib9p_Rmsg_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes) { + return _lib9p_validate(1, "expected an R-message but got a T-message", _lib9p_table_Rmsg_recv, + ctx, net_bytes); +} + +static +void _lib9p_unmarshal(const struct _lib9p_recv_tentry xxx_table[LIB9P_VER_NUM][0x80], + struct lib9p_ctx *ctx, uint8_t *net_bytes, + enum lib9p_msg_type *ret_typ, void *ret_body) { struct _unmarshal_ctx subctx = { .ctx = ctx, .net_bytes = net_bytes, @@ -116,27 +138,54 @@ void lib9p_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, .net_offset = 0, }; - *ret_typ = net_bytes[4]; - struct _table_msg table = _lib9p_versions[ctx->version].msgs[*ret_typ]; - subctx.extra = ret_body + table.basesize; - table.unmarshal(&subctx, ret_body); + enum lib9p_msg_type typ = net_bytes[4]; + *ret_typ = typ; + struct _lib9p_recv_tentry tentry = xxx_table[ctx->version][typ/2]; + subctx.extra = ret_body + tentry.basesize; + tentry.unmarshal(&subctx, ret_body); +} + +void lib9p_Tmsg_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, + enum lib9p_msg_type *ret_typ, void *ret_body) { + _lib9p_unmarshal(_lib9p_table_Tmsg_recv, + ctx, net_bytes, ret_typ, ret_body); } -bool lib9p_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body, - uint8_t *ret_bytes) { +void lib9p_Rmsg_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, + enum lib9p_msg_type *ret_typ, void *ret_body) { + _lib9p_unmarshal(_lib9p_table_Rmsg_recv, + ctx, net_bytes, ret_typ, ret_body); +} + +static +bool _lib9p_marshal(const struct _lib9p_send_tentry xxx_table[LIB9P_VER_NUM][0x80], + struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body, + uint8_t *ret_bytes) { struct _marshal_ctx subctx = { .ctx = ctx, .net_bytes = ret_bytes, .net_offset = 0, }; - struct _table_msg table = _lib9p_versions[ctx->version].msgs[typ]; - return table.marshal(&subctx, body); + struct _lib9p_send_tentry tentry = xxx_table[ctx->version][typ/2]; + return tentry.marshal(&subctx, body); +} + +bool lib9p_Tmsg_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body, + uint8_t *ret_bytes) { + assert(typ % 2 == 0); + return _lib9p_marshal(_lib9p_table_Tmsg_send, ctx, typ, body, ret_bytes); +} + +bool lib9p_Rmsg_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body, + uint8_t *ret_bytes) { + assert(typ % 2 == 1); + return _lib9p_marshal(_lib9p_table_Rmsg_send, ctx, typ, body, ret_bytes); } /* `struct lib9p_stat` helpers ************************************************/ -bool lib9p_validate_stat(struct lib9p_ctx *ctx, uint32_t net_size, uint8_t *net_bytes, +bool lib9p_stat_validate(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 = { .ctx = ctx, @@ -146,7 +195,7 @@ bool lib9p_validate_stat(struct lib9p_ctx *ctx, uint32_t net_size, uint8_t *net_ .net_offset = 0, .host_extra = 0, }; - if (_lib9p_validate_stat(&subctx)) + if (_lib9p_stat_validate(&subctx)) return true; if (ret_net_size) *ret_net_size = subctx.net_offset; @@ -156,7 +205,7 @@ bool lib9p_validate_stat(struct lib9p_ctx *ctx, uint32_t net_size, uint8_t *net_ return false; } -uint32_t lib9p_unmarshal_stat(struct lib9p_ctx *ctx, uint8_t *net_bytes, +uint32_t lib9p_stat_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, struct lib9p_stat *ret_obj, void *ret_extra) { struct _unmarshal_ctx subctx = { .ctx = ctx, @@ -165,11 +214,11 @@ uint32_t lib9p_unmarshal_stat(struct lib9p_ctx *ctx, uint8_t *net_bytes, .extra = ret_extra, }; - _lib9p_unmarshal_stat(&subctx, ret_obj); + _lib9p_stat_unmarshal(&subctx, ret_obj); return subctx.net_offset; } -uint32_t lib9p_marshal_stat(struct lib9p_ctx *ctx, uint32_t max_net_size, struct lib9p_stat *obj, +uint32_t lib9p_stat_marshal(struct lib9p_ctx *ctx, uint32_t max_net_size, struct lib9p_stat *obj, uint8_t *ret_bytes) { struct lib9p_ctx _ctx = *ctx; _ctx.max_msg_size = max_net_size; @@ -178,7 +227,7 @@ uint32_t lib9p_marshal_stat(struct lib9p_ctx *ctx, uint32_t max_net_size, struct .net_bytes = ret_bytes, .net_offset = 0, }; - if (_lib9p_marshal_stat(&subctx, obj)) + if (_lib9p_stat_marshal(&subctx, obj)) return 0; return subctx.net_offset; } diff --git a/lib9p/9p.generated.c b/lib9p/9p.generated.c index c260647..984ba7f 100644 --- a/lib9p/9p.generated.c +++ b/lib9p/9p.generated.c @@ -1790,1065 +1790,377 @@ LM_FLATTEN static bool marshal_Rswrite(struct _marshal_ctx *ctx, struct lib9p_ms #endif /* CONFIG_9P_ENABLE_9P2000_e */ /* tables / exports ***********************************************************/ - -#define _MSG(typ) [LIB9P_TYP_##typ] = { \ - .name = #typ, \ +#define _MSG_NAME(typ) [LIB9P_TYP_##typ] = #typ +#define _MSG_RECV(typ) [LIB9P_TYP_##typ/2] = { \ .basesize = sizeof(struct lib9p_msg_##typ), \ .validate = validate_##typ, \ .unmarshal = (_unmarshal_fn_t)unmarshal_##typ, \ - .marshal = (_marshal_fn_t)marshal_##typ, \ } -#define _NONMSG(num) [num] = { \ - .name = #num, \ +#define _MSG_SEND(typ) [LIB9P_TYP_##typ/2] = { \ + .marshal = (_marshal_fn_t)marshal_##typ, \ } -struct _table_version _lib9p_versions[LIB9P_VER_NUM] = { - [LIB9P_VER_unknown] = { .msgs = { - _NONMSG(0x00), - _NONMSG(0x01), - _NONMSG(0x02), - _NONMSG(0x03), - _NONMSG(0x04), - _NONMSG(0x05), - _NONMSG(0x06), - _NONMSG(0x07), - _NONMSG(0x08), - _NONMSG(0x09), - _NONMSG(0x0A), - _NONMSG(0x0B), - _NONMSG(0x0C), - _NONMSG(0x0D), - _NONMSG(0x0E), - _NONMSG(0x0F), - _NONMSG(0x10), - _NONMSG(0x11), - _NONMSG(0x12), - _NONMSG(0x13), - _NONMSG(0x14), - _NONMSG(0x15), - _NONMSG(0x16), - _NONMSG(0x17), - _NONMSG(0x18), - _NONMSG(0x19), - _NONMSG(0x1A), - _NONMSG(0x1B), - _NONMSG(0x1C), - _NONMSG(0x1D), - _NONMSG(0x1E), - _NONMSG(0x1F), - _NONMSG(0x20), - _NONMSG(0x21), - _NONMSG(0x22), - _NONMSG(0x23), - _NONMSG(0x24), - _NONMSG(0x25), - _NONMSG(0x26), - _NONMSG(0x27), - _NONMSG(0x28), - _NONMSG(0x29), - _NONMSG(0x2A), - _NONMSG(0x2B), - _NONMSG(0x2C), - _NONMSG(0x2D), - _NONMSG(0x2E), - _NONMSG(0x2F), - _NONMSG(0x30), - _NONMSG(0x31), - _NONMSG(0x32), - _NONMSG(0x33), - _NONMSG(0x34), - _NONMSG(0x35), - _NONMSG(0x36), - _NONMSG(0x37), - _NONMSG(0x38), - _NONMSG(0x39), - _NONMSG(0x3A), - _NONMSG(0x3B), - _NONMSG(0x3C), - _NONMSG(0x3D), - _NONMSG(0x3E), - _NONMSG(0x3F), - _NONMSG(0x40), - _NONMSG(0x41), - _NONMSG(0x42), - _NONMSG(0x43), - _NONMSG(0x44), - _NONMSG(0x45), - _NONMSG(0x46), - _NONMSG(0x47), - _NONMSG(0x48), - _NONMSG(0x49), - _NONMSG(0x4A), - _NONMSG(0x4B), - _NONMSG(0x4C), - _NONMSG(0x4D), - _NONMSG(0x4E), - _NONMSG(0x4F), - _NONMSG(0x50), - _NONMSG(0x51), - _NONMSG(0x52), - _NONMSG(0x53), - _NONMSG(0x54), - _NONMSG(0x55), - _NONMSG(0x56), - _NONMSG(0x57), - _NONMSG(0x58), - _NONMSG(0x59), - _NONMSG(0x5A), - _NONMSG(0x5B), - _NONMSG(0x5C), - _NONMSG(0x5D), - _NONMSG(0x5E), - _NONMSG(0x5F), - _NONMSG(0x60), - _NONMSG(0x61), - _NONMSG(0x62), - _NONMSG(0x63), - _MSG(Tversion), - _MSG(Rversion), - _NONMSG(0x66), - _NONMSG(0x67), - _NONMSG(0x68), - _NONMSG(0x69), - _NONMSG(0x6A), - _MSG(Rerror), - _NONMSG(0x6C), - _NONMSG(0x6D), - _NONMSG(0x6E), - _NONMSG(0x6F), - _NONMSG(0x70), - _NONMSG(0x71), - _NONMSG(0x72), - _NONMSG(0x73), - _NONMSG(0x74), - _NONMSG(0x75), - _NONMSG(0x76), - _NONMSG(0x77), - _NONMSG(0x78), - _NONMSG(0x79), - _NONMSG(0x7A), - _NONMSG(0x7B), - _NONMSG(0x7C), - _NONMSG(0x7D), - _NONMSG(0x7E), - _NONMSG(0x7F), - _NONMSG(0x80), - _NONMSG(0x81), - _NONMSG(0x82), - _NONMSG(0x83), - _NONMSG(0x84), - _NONMSG(0x85), - _NONMSG(0x86), - _NONMSG(0x87), - _NONMSG(0x88), - _NONMSG(0x89), - _NONMSG(0x8A), - _NONMSG(0x8B), - _NONMSG(0x8C), - _NONMSG(0x8D), - _NONMSG(0x8E), - _NONMSG(0x8F), - _NONMSG(0x90), - _NONMSG(0x91), - _NONMSG(0x92), - _NONMSG(0x93), - _NONMSG(0x94), - _NONMSG(0x95), - _NONMSG(0x96), - _NONMSG(0x97), - _NONMSG(0x98), - _NONMSG(0x99), - _NONMSG(0x9A), - _NONMSG(0x9B), - _NONMSG(0x9C), - _NONMSG(0x9D), - _NONMSG(0x9E), - _NONMSG(0x9F), - _NONMSG(0xA0), - _NONMSG(0xA1), - _NONMSG(0xA2), - _NONMSG(0xA3), - _NONMSG(0xA4), - _NONMSG(0xA5), - _NONMSG(0xA6), - _NONMSG(0xA7), - _NONMSG(0xA8), - _NONMSG(0xA9), - _NONMSG(0xAA), - _NONMSG(0xAB), - _NONMSG(0xAC), - _NONMSG(0xAD), - _NONMSG(0xAE), - _NONMSG(0xAF), - _NONMSG(0xB0), - _NONMSG(0xB1), - _NONMSG(0xB2), - _NONMSG(0xB3), - _NONMSG(0xB4), - _NONMSG(0xB5), - _NONMSG(0xB6), - _NONMSG(0xB7), - _NONMSG(0xB8), - _NONMSG(0xB9), - _NONMSG(0xBA), - _NONMSG(0xBB), - _NONMSG(0xBC), - _NONMSG(0xBD), - _NONMSG(0xBE), - _NONMSG(0xBF), - _NONMSG(0xC0), - _NONMSG(0xC1), - _NONMSG(0xC2), - _NONMSG(0xC3), - _NONMSG(0xC4), - _NONMSG(0xC5), - _NONMSG(0xC6), - _NONMSG(0xC7), - _NONMSG(0xC8), - _NONMSG(0xC9), - _NONMSG(0xCA), - _NONMSG(0xCB), - _NONMSG(0xCC), - _NONMSG(0xCD), - _NONMSG(0xCE), - _NONMSG(0xCF), - _NONMSG(0xD0), - _NONMSG(0xD1), - _NONMSG(0xD2), - _NONMSG(0xD3), - _NONMSG(0xD4), - _NONMSG(0xD5), - _NONMSG(0xD6), - _NONMSG(0xD7), - _NONMSG(0xD8), - _NONMSG(0xD9), - _NONMSG(0xDA), - _NONMSG(0xDB), - _NONMSG(0xDC), - _NONMSG(0xDD), - _NONMSG(0xDE), - _NONMSG(0xDF), - _NONMSG(0xE0), - _NONMSG(0xE1), - _NONMSG(0xE2), - _NONMSG(0xE3), - _NONMSG(0xE4), - _NONMSG(0xE5), - _NONMSG(0xE6), - _NONMSG(0xE7), - _NONMSG(0xE8), - _NONMSG(0xE9), - _NONMSG(0xEA), - _NONMSG(0xEB), - _NONMSG(0xEC), - _NONMSG(0xED), - _NONMSG(0xEE), - _NONMSG(0xEF), - _NONMSG(0xF0), - _NONMSG(0xF1), - _NONMSG(0xF2), - _NONMSG(0xF3), - _NONMSG(0xF4), - _NONMSG(0xF5), - _NONMSG(0xF6), - _NONMSG(0xF7), - _NONMSG(0xF8), - _NONMSG(0xF9), - _NONMSG(0xFA), - _NONMSG(0xFB), - _NONMSG(0xFC), - _NONMSG(0xFD), - _NONMSG(0xFE), - _NONMSG(0xFF), - }}, +const char * _lib9p_table_msg_name[LIB9P_VER_NUM][0x100] = { + [LIB9P_VER_unknown] = { + _MSG_NAME(Tversion), + _MSG_NAME(Rversion), + _MSG_NAME(Rerror), + }, +#if CONFIG_9P_ENABLE_9P2000 + [LIB9P_VER_9P2000] = { + _MSG_NAME(Tversion), + _MSG_NAME(Rversion), + _MSG_NAME(Tauth), + _MSG_NAME(Rauth), + _MSG_NAME(Tattach), + _MSG_NAME(Rattach), + _MSG_NAME(Rerror), + _MSG_NAME(Tflush), + _MSG_NAME(Rflush), + _MSG_NAME(Twalk), + _MSG_NAME(Rwalk), + _MSG_NAME(Topen), + _MSG_NAME(Ropen), + _MSG_NAME(Tcreate), + _MSG_NAME(Rcreate), + _MSG_NAME(Tread), + _MSG_NAME(Rread), + _MSG_NAME(Twrite), + _MSG_NAME(Rwrite), + _MSG_NAME(Tclunk), + _MSG_NAME(Rclunk), + _MSG_NAME(Tremove), + _MSG_NAME(Rremove), + _MSG_NAME(Tstat), + _MSG_NAME(Rstat), + _MSG_NAME(Twstat), + _MSG_NAME(Rwstat), + }, +#endif /* CONFIG_9P_ENABLE_9P2000 */ +#if CONFIG_9P_ENABLE_9P2000_e + [LIB9P_VER_9P2000_e] = { + _MSG_NAME(Tversion), + _MSG_NAME(Rversion), + _MSG_NAME(Tauth), + _MSG_NAME(Rauth), + _MSG_NAME(Tattach), + _MSG_NAME(Rattach), + _MSG_NAME(Rerror), + _MSG_NAME(Tflush), + _MSG_NAME(Rflush), + _MSG_NAME(Twalk), + _MSG_NAME(Rwalk), + _MSG_NAME(Topen), + _MSG_NAME(Ropen), + _MSG_NAME(Tcreate), + _MSG_NAME(Rcreate), + _MSG_NAME(Tread), + _MSG_NAME(Rread), + _MSG_NAME(Twrite), + _MSG_NAME(Rwrite), + _MSG_NAME(Tclunk), + _MSG_NAME(Rclunk), + _MSG_NAME(Tremove), + _MSG_NAME(Rremove), + _MSG_NAME(Tstat), + _MSG_NAME(Rstat), + _MSG_NAME(Twstat), + _MSG_NAME(Rwstat), + _MSG_NAME(Tsession), + _MSG_NAME(Rsession), + _MSG_NAME(Tsread), + _MSG_NAME(Rsread), + _MSG_NAME(Tswrite), + _MSG_NAME(Rswrite), + }, +#endif /* CONFIG_9P_ENABLE_9P2000_e */ +#if CONFIG_9P_ENABLE_9P2000_u + [LIB9P_VER_9P2000_u] = { + _MSG_NAME(Tversion), + _MSG_NAME(Rversion), + _MSG_NAME(Tauth), + _MSG_NAME(Rauth), + _MSG_NAME(Tattach), + _MSG_NAME(Rattach), + _MSG_NAME(Rerror), + _MSG_NAME(Tflush), + _MSG_NAME(Rflush), + _MSG_NAME(Twalk), + _MSG_NAME(Rwalk), + _MSG_NAME(Topen), + _MSG_NAME(Ropen), + _MSG_NAME(Tcreate), + _MSG_NAME(Rcreate), + _MSG_NAME(Tread), + _MSG_NAME(Rread), + _MSG_NAME(Twrite), + _MSG_NAME(Rwrite), + _MSG_NAME(Tclunk), + _MSG_NAME(Rclunk), + _MSG_NAME(Tremove), + _MSG_NAME(Rremove), + _MSG_NAME(Tstat), + _MSG_NAME(Rstat), + _MSG_NAME(Twstat), + _MSG_NAME(Rwstat), + }, +#endif /* CONFIG_9P_ENABLE_9P2000_u */ +}; + +const struct _lib9p_recv_tentry _lib9p_table_Tmsg_recv[LIB9P_VER_NUM][0x80] = { + [LIB9P_VER_unknown] = { + _MSG_RECV(Tversion), + }, +#if CONFIG_9P_ENABLE_9P2000 + [LIB9P_VER_9P2000] = { + _MSG_RECV(Tversion), + _MSG_RECV(Tauth), + _MSG_RECV(Tattach), + _MSG_RECV(Tflush), + _MSG_RECV(Twalk), + _MSG_RECV(Topen), + _MSG_RECV(Tcreate), + _MSG_RECV(Tread), + _MSG_RECV(Twrite), + _MSG_RECV(Tclunk), + _MSG_RECV(Tremove), + _MSG_RECV(Tstat), + _MSG_RECV(Twstat), + }, +#endif /* CONFIG_9P_ENABLE_9P2000 */ +#if CONFIG_9P_ENABLE_9P2000_e + [LIB9P_VER_9P2000_e] = { + _MSG_RECV(Tversion), + _MSG_RECV(Tauth), + _MSG_RECV(Tattach), + _MSG_RECV(Tflush), + _MSG_RECV(Twalk), + _MSG_RECV(Topen), + _MSG_RECV(Tcreate), + _MSG_RECV(Tread), + _MSG_RECV(Twrite), + _MSG_RECV(Tclunk), + _MSG_RECV(Tremove), + _MSG_RECV(Tstat), + _MSG_RECV(Twstat), + _MSG_RECV(Tsession), + _MSG_RECV(Tsread), + _MSG_RECV(Tswrite), + }, +#endif /* CONFIG_9P_ENABLE_9P2000_e */ +#if CONFIG_9P_ENABLE_9P2000_u + [LIB9P_VER_9P2000_u] = { + _MSG_RECV(Tversion), + _MSG_RECV(Tauth), + _MSG_RECV(Tattach), + _MSG_RECV(Tflush), + _MSG_RECV(Twalk), + _MSG_RECV(Topen), + _MSG_RECV(Tcreate), + _MSG_RECV(Tread), + _MSG_RECV(Twrite), + _MSG_RECV(Tclunk), + _MSG_RECV(Tremove), + _MSG_RECV(Tstat), + _MSG_RECV(Twstat), + }, +#endif /* CONFIG_9P_ENABLE_9P2000_u */ +}; + +const struct _lib9p_recv_tentry _lib9p_table_Rmsg_recv[LIB9P_VER_NUM][0x80] = { + [LIB9P_VER_unknown] = { + _MSG_RECV(Rversion), + _MSG_RECV(Rerror), + }, +#if CONFIG_9P_ENABLE_9P2000 + [LIB9P_VER_9P2000] = { + _MSG_RECV(Rversion), + _MSG_RECV(Rauth), + _MSG_RECV(Rattach), + _MSG_RECV(Rerror), + _MSG_RECV(Rflush), + _MSG_RECV(Rwalk), + _MSG_RECV(Ropen), + _MSG_RECV(Rcreate), + _MSG_RECV(Rread), + _MSG_RECV(Rwrite), + _MSG_RECV(Rclunk), + _MSG_RECV(Rremove), + _MSG_RECV(Rstat), + _MSG_RECV(Rwstat), + }, +#endif /* CONFIG_9P_ENABLE_9P2000 */ +#if CONFIG_9P_ENABLE_9P2000_e + [LIB9P_VER_9P2000_e] = { + _MSG_RECV(Rversion), + _MSG_RECV(Rauth), + _MSG_RECV(Rattach), + _MSG_RECV(Rerror), + _MSG_RECV(Rflush), + _MSG_RECV(Rwalk), + _MSG_RECV(Ropen), + _MSG_RECV(Rcreate), + _MSG_RECV(Rread), + _MSG_RECV(Rwrite), + _MSG_RECV(Rclunk), + _MSG_RECV(Rremove), + _MSG_RECV(Rstat), + _MSG_RECV(Rwstat), + _MSG_RECV(Rsession), + _MSG_RECV(Rsread), + _MSG_RECV(Rswrite), + }, +#endif /* CONFIG_9P_ENABLE_9P2000_e */ +#if CONFIG_9P_ENABLE_9P2000_u + [LIB9P_VER_9P2000_u] = { + _MSG_RECV(Rversion), + _MSG_RECV(Rauth), + _MSG_RECV(Rattach), + _MSG_RECV(Rerror), + _MSG_RECV(Rflush), + _MSG_RECV(Rwalk), + _MSG_RECV(Ropen), + _MSG_RECV(Rcreate), + _MSG_RECV(Rread), + _MSG_RECV(Rwrite), + _MSG_RECV(Rclunk), + _MSG_RECV(Rremove), + _MSG_RECV(Rstat), + _MSG_RECV(Rwstat), + }, +#endif /* CONFIG_9P_ENABLE_9P2000_u */ +}; + +const struct _lib9p_send_tentry _lib9p_table_Tmsg_send[LIB9P_VER_NUM][0x80] = { + [LIB9P_VER_unknown] = { + _MSG_SEND(Tversion), + }, +#if CONFIG_9P_ENABLE_9P2000 + [LIB9P_VER_9P2000] = { + _MSG_SEND(Tversion), + _MSG_SEND(Tauth), + _MSG_SEND(Tattach), + _MSG_SEND(Tflush), + _MSG_SEND(Twalk), + _MSG_SEND(Topen), + _MSG_SEND(Tcreate), + _MSG_SEND(Tread), + _MSG_SEND(Twrite), + _MSG_SEND(Tclunk), + _MSG_SEND(Tremove), + _MSG_SEND(Tstat), + _MSG_SEND(Twstat), + }, +#endif /* CONFIG_9P_ENABLE_9P2000 */ +#if CONFIG_9P_ENABLE_9P2000_e + [LIB9P_VER_9P2000_e] = { + _MSG_SEND(Tversion), + _MSG_SEND(Tauth), + _MSG_SEND(Tattach), + _MSG_SEND(Tflush), + _MSG_SEND(Twalk), + _MSG_SEND(Topen), + _MSG_SEND(Tcreate), + _MSG_SEND(Tread), + _MSG_SEND(Twrite), + _MSG_SEND(Tclunk), + _MSG_SEND(Tremove), + _MSG_SEND(Tstat), + _MSG_SEND(Twstat), + _MSG_SEND(Tsession), + _MSG_SEND(Tsread), + _MSG_SEND(Tswrite), + }, +#endif /* CONFIG_9P_ENABLE_9P2000_e */ +#if CONFIG_9P_ENABLE_9P2000_u + [LIB9P_VER_9P2000_u] = { + _MSG_SEND(Tversion), + _MSG_SEND(Tauth), + _MSG_SEND(Tattach), + _MSG_SEND(Tflush), + _MSG_SEND(Twalk), + _MSG_SEND(Topen), + _MSG_SEND(Tcreate), + _MSG_SEND(Tread), + _MSG_SEND(Twrite), + _MSG_SEND(Tclunk), + _MSG_SEND(Tremove), + _MSG_SEND(Tstat), + _MSG_SEND(Twstat), + }, +#endif /* CONFIG_9P_ENABLE_9P2000_u */ +}; + +const struct _lib9p_send_tentry _lib9p_table_Rmsg_send[LIB9P_VER_NUM][0x80] = { + [LIB9P_VER_unknown] = { + _MSG_SEND(Rversion), + _MSG_SEND(Rerror), + }, #if CONFIG_9P_ENABLE_9P2000 - [LIB9P_VER_9P2000] = { .msgs = { - _NONMSG(0x00), - _NONMSG(0x01), - _NONMSG(0x02), - _NONMSG(0x03), - _NONMSG(0x04), - _NONMSG(0x05), - _NONMSG(0x06), - _NONMSG(0x07), - _NONMSG(0x08), - _NONMSG(0x09), - _NONMSG(0x0A), - _NONMSG(0x0B), - _NONMSG(0x0C), - _NONMSG(0x0D), - _NONMSG(0x0E), - _NONMSG(0x0F), - _NONMSG(0x10), - _NONMSG(0x11), - _NONMSG(0x12), - _NONMSG(0x13), - _NONMSG(0x14), - _NONMSG(0x15), - _NONMSG(0x16), - _NONMSG(0x17), - _NONMSG(0x18), - _NONMSG(0x19), - _NONMSG(0x1A), - _NONMSG(0x1B), - _NONMSG(0x1C), - _NONMSG(0x1D), - _NONMSG(0x1E), - _NONMSG(0x1F), - _NONMSG(0x20), - _NONMSG(0x21), - _NONMSG(0x22), - _NONMSG(0x23), - _NONMSG(0x24), - _NONMSG(0x25), - _NONMSG(0x26), - _NONMSG(0x27), - _NONMSG(0x28), - _NONMSG(0x29), - _NONMSG(0x2A), - _NONMSG(0x2B), - _NONMSG(0x2C), - _NONMSG(0x2D), - _NONMSG(0x2E), - _NONMSG(0x2F), - _NONMSG(0x30), - _NONMSG(0x31), - _NONMSG(0x32), - _NONMSG(0x33), - _NONMSG(0x34), - _NONMSG(0x35), - _NONMSG(0x36), - _NONMSG(0x37), - _NONMSG(0x38), - _NONMSG(0x39), - _NONMSG(0x3A), - _NONMSG(0x3B), - _NONMSG(0x3C), - _NONMSG(0x3D), - _NONMSG(0x3E), - _NONMSG(0x3F), - _NONMSG(0x40), - _NONMSG(0x41), - _NONMSG(0x42), - _NONMSG(0x43), - _NONMSG(0x44), - _NONMSG(0x45), - _NONMSG(0x46), - _NONMSG(0x47), - _NONMSG(0x48), - _NONMSG(0x49), - _NONMSG(0x4A), - _NONMSG(0x4B), - _NONMSG(0x4C), - _NONMSG(0x4D), - _NONMSG(0x4E), - _NONMSG(0x4F), - _NONMSG(0x50), - _NONMSG(0x51), - _NONMSG(0x52), - _NONMSG(0x53), - _NONMSG(0x54), - _NONMSG(0x55), - _NONMSG(0x56), - _NONMSG(0x57), - _NONMSG(0x58), - _NONMSG(0x59), - _NONMSG(0x5A), - _NONMSG(0x5B), - _NONMSG(0x5C), - _NONMSG(0x5D), - _NONMSG(0x5E), - _NONMSG(0x5F), - _NONMSG(0x60), - _NONMSG(0x61), - _NONMSG(0x62), - _NONMSG(0x63), - _MSG(Tversion), - _MSG(Rversion), - _MSG(Tauth), - _MSG(Rauth), - _MSG(Tattach), - _MSG(Rattach), - _NONMSG(0x6A), - _MSG(Rerror), - _MSG(Tflush), - _MSG(Rflush), - _MSG(Twalk), - _MSG(Rwalk), - _MSG(Topen), - _MSG(Ropen), - _MSG(Tcreate), - _MSG(Rcreate), - _MSG(Tread), - _MSG(Rread), - _MSG(Twrite), - _MSG(Rwrite), - _MSG(Tclunk), - _MSG(Rclunk), - _MSG(Tremove), - _MSG(Rremove), - _MSG(Tstat), - _MSG(Rstat), - _MSG(Twstat), - _MSG(Rwstat), - _NONMSG(0x80), - _NONMSG(0x81), - _NONMSG(0x82), - _NONMSG(0x83), - _NONMSG(0x84), - _NONMSG(0x85), - _NONMSG(0x86), - _NONMSG(0x87), - _NONMSG(0x88), - _NONMSG(0x89), - _NONMSG(0x8A), - _NONMSG(0x8B), - _NONMSG(0x8C), - _NONMSG(0x8D), - _NONMSG(0x8E), - _NONMSG(0x8F), - _NONMSG(0x90), - _NONMSG(0x91), - _NONMSG(0x92), - _NONMSG(0x93), - _NONMSG(0x94), - _NONMSG(0x95), - _NONMSG(0x96), - _NONMSG(0x97), - _NONMSG(0x98), - _NONMSG(0x99), - _NONMSG(0x9A), - _NONMSG(0x9B), - _NONMSG(0x9C), - _NONMSG(0x9D), - _NONMSG(0x9E), - _NONMSG(0x9F), - _NONMSG(0xA0), - _NONMSG(0xA1), - _NONMSG(0xA2), - _NONMSG(0xA3), - _NONMSG(0xA4), - _NONMSG(0xA5), - _NONMSG(0xA6), - _NONMSG(0xA7), - _NONMSG(0xA8), - _NONMSG(0xA9), - _NONMSG(0xAA), - _NONMSG(0xAB), - _NONMSG(0xAC), - _NONMSG(0xAD), - _NONMSG(0xAE), - _NONMSG(0xAF), - _NONMSG(0xB0), - _NONMSG(0xB1), - _NONMSG(0xB2), - _NONMSG(0xB3), - _NONMSG(0xB4), - _NONMSG(0xB5), - _NONMSG(0xB6), - _NONMSG(0xB7), - _NONMSG(0xB8), - _NONMSG(0xB9), - _NONMSG(0xBA), - _NONMSG(0xBB), - _NONMSG(0xBC), - _NONMSG(0xBD), - _NONMSG(0xBE), - _NONMSG(0xBF), - _NONMSG(0xC0), - _NONMSG(0xC1), - _NONMSG(0xC2), - _NONMSG(0xC3), - _NONMSG(0xC4), - _NONMSG(0xC5), - _NONMSG(0xC6), - _NONMSG(0xC7), - _NONMSG(0xC8), - _NONMSG(0xC9), - _NONMSG(0xCA), - _NONMSG(0xCB), - _NONMSG(0xCC), - _NONMSG(0xCD), - _NONMSG(0xCE), - _NONMSG(0xCF), - _NONMSG(0xD0), - _NONMSG(0xD1), - _NONMSG(0xD2), - _NONMSG(0xD3), - _NONMSG(0xD4), - _NONMSG(0xD5), - _NONMSG(0xD6), - _NONMSG(0xD7), - _NONMSG(0xD8), - _NONMSG(0xD9), - _NONMSG(0xDA), - _NONMSG(0xDB), - _NONMSG(0xDC), - _NONMSG(0xDD), - _NONMSG(0xDE), - _NONMSG(0xDF), - _NONMSG(0xE0), - _NONMSG(0xE1), - _NONMSG(0xE2), - _NONMSG(0xE3), - _NONMSG(0xE4), - _NONMSG(0xE5), - _NONMSG(0xE6), - _NONMSG(0xE7), - _NONMSG(0xE8), - _NONMSG(0xE9), - _NONMSG(0xEA), - _NONMSG(0xEB), - _NONMSG(0xEC), - _NONMSG(0xED), - _NONMSG(0xEE), - _NONMSG(0xEF), - _NONMSG(0xF0), - _NONMSG(0xF1), - _NONMSG(0xF2), - _NONMSG(0xF3), - _NONMSG(0xF4), - _NONMSG(0xF5), - _NONMSG(0xF6), - _NONMSG(0xF7), - _NONMSG(0xF8), - _NONMSG(0xF9), - _NONMSG(0xFA), - _NONMSG(0xFB), - _NONMSG(0xFC), - _NONMSG(0xFD), - _NONMSG(0xFE), - _NONMSG(0xFF), - }}, + [LIB9P_VER_9P2000] = { + _MSG_SEND(Rversion), + _MSG_SEND(Rauth), + _MSG_SEND(Rattach), + _MSG_SEND(Rerror), + _MSG_SEND(Rflush), + _MSG_SEND(Rwalk), + _MSG_SEND(Ropen), + _MSG_SEND(Rcreate), + _MSG_SEND(Rread), + _MSG_SEND(Rwrite), + _MSG_SEND(Rclunk), + _MSG_SEND(Rremove), + _MSG_SEND(Rstat), + _MSG_SEND(Rwstat), + }, #endif /* CONFIG_9P_ENABLE_9P2000 */ #if CONFIG_9P_ENABLE_9P2000_e - [LIB9P_VER_9P2000_e] = { .msgs = { - _NONMSG(0x00), - _NONMSG(0x01), - _NONMSG(0x02), - _NONMSG(0x03), - _NONMSG(0x04), - _NONMSG(0x05), - _NONMSG(0x06), - _NONMSG(0x07), - _NONMSG(0x08), - _NONMSG(0x09), - _NONMSG(0x0A), - _NONMSG(0x0B), - _NONMSG(0x0C), - _NONMSG(0x0D), - _NONMSG(0x0E), - _NONMSG(0x0F), - _NONMSG(0x10), - _NONMSG(0x11), - _NONMSG(0x12), - _NONMSG(0x13), - _NONMSG(0x14), - _NONMSG(0x15), - _NONMSG(0x16), - _NONMSG(0x17), - _NONMSG(0x18), - _NONMSG(0x19), - _NONMSG(0x1A), - _NONMSG(0x1B), - _NONMSG(0x1C), - _NONMSG(0x1D), - _NONMSG(0x1E), - _NONMSG(0x1F), - _NONMSG(0x20), - _NONMSG(0x21), - _NONMSG(0x22), - _NONMSG(0x23), - _NONMSG(0x24), - _NONMSG(0x25), - _NONMSG(0x26), - _NONMSG(0x27), - _NONMSG(0x28), - _NONMSG(0x29), - _NONMSG(0x2A), - _NONMSG(0x2B), - _NONMSG(0x2C), - _NONMSG(0x2D), - _NONMSG(0x2E), - _NONMSG(0x2F), - _NONMSG(0x30), - _NONMSG(0x31), - _NONMSG(0x32), - _NONMSG(0x33), - _NONMSG(0x34), - _NONMSG(0x35), - _NONMSG(0x36), - _NONMSG(0x37), - _NONMSG(0x38), - _NONMSG(0x39), - _NONMSG(0x3A), - _NONMSG(0x3B), - _NONMSG(0x3C), - _NONMSG(0x3D), - _NONMSG(0x3E), - _NONMSG(0x3F), - _NONMSG(0x40), - _NONMSG(0x41), - _NONMSG(0x42), - _NONMSG(0x43), - _NONMSG(0x44), - _NONMSG(0x45), - _NONMSG(0x46), - _NONMSG(0x47), - _NONMSG(0x48), - _NONMSG(0x49), - _NONMSG(0x4A), - _NONMSG(0x4B), - _NONMSG(0x4C), - _NONMSG(0x4D), - _NONMSG(0x4E), - _NONMSG(0x4F), - _NONMSG(0x50), - _NONMSG(0x51), - _NONMSG(0x52), - _NONMSG(0x53), - _NONMSG(0x54), - _NONMSG(0x55), - _NONMSG(0x56), - _NONMSG(0x57), - _NONMSG(0x58), - _NONMSG(0x59), - _NONMSG(0x5A), - _NONMSG(0x5B), - _NONMSG(0x5C), - _NONMSG(0x5D), - _NONMSG(0x5E), - _NONMSG(0x5F), - _NONMSG(0x60), - _NONMSG(0x61), - _NONMSG(0x62), - _NONMSG(0x63), - _MSG(Tversion), - _MSG(Rversion), - _MSG(Tauth), - _MSG(Rauth), - _MSG(Tattach), - _MSG(Rattach), - _NONMSG(0x6A), - _MSG(Rerror), - _MSG(Tflush), - _MSG(Rflush), - _MSG(Twalk), - _MSG(Rwalk), - _MSG(Topen), - _MSG(Ropen), - _MSG(Tcreate), - _MSG(Rcreate), - _MSG(Tread), - _MSG(Rread), - _MSG(Twrite), - _MSG(Rwrite), - _MSG(Tclunk), - _MSG(Rclunk), - _MSG(Tremove), - _MSG(Rremove), - _MSG(Tstat), - _MSG(Rstat), - _MSG(Twstat), - _MSG(Rwstat), - _NONMSG(0x80), - _NONMSG(0x81), - _NONMSG(0x82), - _NONMSG(0x83), - _NONMSG(0x84), - _NONMSG(0x85), - _NONMSG(0x86), - _NONMSG(0x87), - _NONMSG(0x88), - _NONMSG(0x89), - _NONMSG(0x8A), - _NONMSG(0x8B), - _NONMSG(0x8C), - _NONMSG(0x8D), - _NONMSG(0x8E), - _NONMSG(0x8F), - _NONMSG(0x90), - _NONMSG(0x91), - _NONMSG(0x92), - _NONMSG(0x93), - _NONMSG(0x94), - _NONMSG(0x95), - _MSG(Tsession), - _MSG(Rsession), - _MSG(Tsread), - _MSG(Rsread), - _MSG(Tswrite), - _MSG(Rswrite), - _NONMSG(0x9C), - _NONMSG(0x9D), - _NONMSG(0x9E), - _NONMSG(0x9F), - _NONMSG(0xA0), - _NONMSG(0xA1), - _NONMSG(0xA2), - _NONMSG(0xA3), - _NONMSG(0xA4), - _NONMSG(0xA5), - _NONMSG(0xA6), - _NONMSG(0xA7), - _NONMSG(0xA8), - _NONMSG(0xA9), - _NONMSG(0xAA), - _NONMSG(0xAB), - _NONMSG(0xAC), - _NONMSG(0xAD), - _NONMSG(0xAE), - _NONMSG(0xAF), - _NONMSG(0xB0), - _NONMSG(0xB1), - _NONMSG(0xB2), - _NONMSG(0xB3), - _NONMSG(0xB4), - _NONMSG(0xB5), - _NONMSG(0xB6), - _NONMSG(0xB7), - _NONMSG(0xB8), - _NONMSG(0xB9), - _NONMSG(0xBA), - _NONMSG(0xBB), - _NONMSG(0xBC), - _NONMSG(0xBD), - _NONMSG(0xBE), - _NONMSG(0xBF), - _NONMSG(0xC0), - _NONMSG(0xC1), - _NONMSG(0xC2), - _NONMSG(0xC3), - _NONMSG(0xC4), - _NONMSG(0xC5), - _NONMSG(0xC6), - _NONMSG(0xC7), - _NONMSG(0xC8), - _NONMSG(0xC9), - _NONMSG(0xCA), - _NONMSG(0xCB), - _NONMSG(0xCC), - _NONMSG(0xCD), - _NONMSG(0xCE), - _NONMSG(0xCF), - _NONMSG(0xD0), - _NONMSG(0xD1), - _NONMSG(0xD2), - _NONMSG(0xD3), - _NONMSG(0xD4), - _NONMSG(0xD5), - _NONMSG(0xD6), - _NONMSG(0xD7), - _NONMSG(0xD8), - _NONMSG(0xD9), - _NONMSG(0xDA), - _NONMSG(0xDB), - _NONMSG(0xDC), - _NONMSG(0xDD), - _NONMSG(0xDE), - _NONMSG(0xDF), - _NONMSG(0xE0), - _NONMSG(0xE1), - _NONMSG(0xE2), - _NONMSG(0xE3), - _NONMSG(0xE4), - _NONMSG(0xE5), - _NONMSG(0xE6), - _NONMSG(0xE7), - _NONMSG(0xE8), - _NONMSG(0xE9), - _NONMSG(0xEA), - _NONMSG(0xEB), - _NONMSG(0xEC), - _NONMSG(0xED), - _NONMSG(0xEE), - _NONMSG(0xEF), - _NONMSG(0xF0), - _NONMSG(0xF1), - _NONMSG(0xF2), - _NONMSG(0xF3), - _NONMSG(0xF4), - _NONMSG(0xF5), - _NONMSG(0xF6), - _NONMSG(0xF7), - _NONMSG(0xF8), - _NONMSG(0xF9), - _NONMSG(0xFA), - _NONMSG(0xFB), - _NONMSG(0xFC), - _NONMSG(0xFD), - _NONMSG(0xFE), - _NONMSG(0xFF), - }}, + [LIB9P_VER_9P2000_e] = { + _MSG_SEND(Rversion), + _MSG_SEND(Rauth), + _MSG_SEND(Rattach), + _MSG_SEND(Rerror), + _MSG_SEND(Rflush), + _MSG_SEND(Rwalk), + _MSG_SEND(Ropen), + _MSG_SEND(Rcreate), + _MSG_SEND(Rread), + _MSG_SEND(Rwrite), + _MSG_SEND(Rclunk), + _MSG_SEND(Rremove), + _MSG_SEND(Rstat), + _MSG_SEND(Rwstat), + _MSG_SEND(Rsession), + _MSG_SEND(Rsread), + _MSG_SEND(Rswrite), + }, #endif /* CONFIG_9P_ENABLE_9P2000_e */ #if CONFIG_9P_ENABLE_9P2000_u - [LIB9P_VER_9P2000_u] = { .msgs = { - _NONMSG(0x00), - _NONMSG(0x01), - _NONMSG(0x02), - _NONMSG(0x03), - _NONMSG(0x04), - _NONMSG(0x05), - _NONMSG(0x06), - _NONMSG(0x07), - _NONMSG(0x08), - _NONMSG(0x09), - _NONMSG(0x0A), - _NONMSG(0x0B), - _NONMSG(0x0C), - _NONMSG(0x0D), - _NONMSG(0x0E), - _NONMSG(0x0F), - _NONMSG(0x10), - _NONMSG(0x11), - _NONMSG(0x12), - _NONMSG(0x13), - _NONMSG(0x14), - _NONMSG(0x15), - _NONMSG(0x16), - _NONMSG(0x17), - _NONMSG(0x18), - _NONMSG(0x19), - _NONMSG(0x1A), - _NONMSG(0x1B), - _NONMSG(0x1C), - _NONMSG(0x1D), - _NONMSG(0x1E), - _NONMSG(0x1F), - _NONMSG(0x20), - _NONMSG(0x21), - _NONMSG(0x22), - _NONMSG(0x23), - _NONMSG(0x24), - _NONMSG(0x25), - _NONMSG(0x26), - _NONMSG(0x27), - _NONMSG(0x28), - _NONMSG(0x29), - _NONMSG(0x2A), - _NONMSG(0x2B), - _NONMSG(0x2C), - _NONMSG(0x2D), - _NONMSG(0x2E), - _NONMSG(0x2F), - _NONMSG(0x30), - _NONMSG(0x31), - _NONMSG(0x32), - _NONMSG(0x33), - _NONMSG(0x34), - _NONMSG(0x35), - _NONMSG(0x36), - _NONMSG(0x37), - _NONMSG(0x38), - _NONMSG(0x39), - _NONMSG(0x3A), - _NONMSG(0x3B), - _NONMSG(0x3C), - _NONMSG(0x3D), - _NONMSG(0x3E), - _NONMSG(0x3F), - _NONMSG(0x40), - _NONMSG(0x41), - _NONMSG(0x42), - _NONMSG(0x43), - _NONMSG(0x44), - _NONMSG(0x45), - _NONMSG(0x46), - _NONMSG(0x47), - _NONMSG(0x48), - _NONMSG(0x49), - _NONMSG(0x4A), - _NONMSG(0x4B), - _NONMSG(0x4C), - _NONMSG(0x4D), - _NONMSG(0x4E), - _NONMSG(0x4F), - _NONMSG(0x50), - _NONMSG(0x51), - _NONMSG(0x52), - _NONMSG(0x53), - _NONMSG(0x54), - _NONMSG(0x55), - _NONMSG(0x56), - _NONMSG(0x57), - _NONMSG(0x58), - _NONMSG(0x59), - _NONMSG(0x5A), - _NONMSG(0x5B), - _NONMSG(0x5C), - _NONMSG(0x5D), - _NONMSG(0x5E), - _NONMSG(0x5F), - _NONMSG(0x60), - _NONMSG(0x61), - _NONMSG(0x62), - _NONMSG(0x63), - _MSG(Tversion), - _MSG(Rversion), - _MSG(Tauth), - _MSG(Rauth), - _MSG(Tattach), - _MSG(Rattach), - _NONMSG(0x6A), - _MSG(Rerror), - _MSG(Tflush), - _MSG(Rflush), - _MSG(Twalk), - _MSG(Rwalk), - _MSG(Topen), - _MSG(Ropen), - _MSG(Tcreate), - _MSG(Rcreate), - _MSG(Tread), - _MSG(Rread), - _MSG(Twrite), - _MSG(Rwrite), - _MSG(Tclunk), - _MSG(Rclunk), - _MSG(Tremove), - _MSG(Rremove), - _MSG(Tstat), - _MSG(Rstat), - _MSG(Twstat), - _MSG(Rwstat), - _NONMSG(0x80), - _NONMSG(0x81), - _NONMSG(0x82), - _NONMSG(0x83), - _NONMSG(0x84), - _NONMSG(0x85), - _NONMSG(0x86), - _NONMSG(0x87), - _NONMSG(0x88), - _NONMSG(0x89), - _NONMSG(0x8A), - _NONMSG(0x8B), - _NONMSG(0x8C), - _NONMSG(0x8D), - _NONMSG(0x8E), - _NONMSG(0x8F), - _NONMSG(0x90), - _NONMSG(0x91), - _NONMSG(0x92), - _NONMSG(0x93), - _NONMSG(0x94), - _NONMSG(0x95), - _NONMSG(0x96), - _NONMSG(0x97), - _NONMSG(0x98), - _NONMSG(0x99), - _NONMSG(0x9A), - _NONMSG(0x9B), - _NONMSG(0x9C), - _NONMSG(0x9D), - _NONMSG(0x9E), - _NONMSG(0x9F), - _NONMSG(0xA0), - _NONMSG(0xA1), - _NONMSG(0xA2), - _NONMSG(0xA3), - _NONMSG(0xA4), - _NONMSG(0xA5), - _NONMSG(0xA6), - _NONMSG(0xA7), - _NONMSG(0xA8), - _NONMSG(0xA9), - _NONMSG(0xAA), - _NONMSG(0xAB), - _NONMSG(0xAC), - _NONMSG(0xAD), - _NONMSG(0xAE), - _NONMSG(0xAF), - _NONMSG(0xB0), - _NONMSG(0xB1), - _NONMSG(0xB2), - _NONMSG(0xB3), - _NONMSG(0xB4), - _NONMSG(0xB5), - _NONMSG(0xB6), - _NONMSG(0xB7), - _NONMSG(0xB8), - _NONMSG(0xB9), - _NONMSG(0xBA), - _NONMSG(0xBB), - _NONMSG(0xBC), - _NONMSG(0xBD), - _NONMSG(0xBE), - _NONMSG(0xBF), - _NONMSG(0xC0), - _NONMSG(0xC1), - _NONMSG(0xC2), - _NONMSG(0xC3), - _NONMSG(0xC4), - _NONMSG(0xC5), - _NONMSG(0xC6), - _NONMSG(0xC7), - _NONMSG(0xC8), - _NONMSG(0xC9), - _NONMSG(0xCA), - _NONMSG(0xCB), - _NONMSG(0xCC), - _NONMSG(0xCD), - _NONMSG(0xCE), - _NONMSG(0xCF), - _NONMSG(0xD0), - _NONMSG(0xD1), - _NONMSG(0xD2), - _NONMSG(0xD3), - _NONMSG(0xD4), - _NONMSG(0xD5), - _NONMSG(0xD6), - _NONMSG(0xD7), - _NONMSG(0xD8), - _NONMSG(0xD9), - _NONMSG(0xDA), - _NONMSG(0xDB), - _NONMSG(0xDC), - _NONMSG(0xDD), - _NONMSG(0xDE), - _NONMSG(0xDF), - _NONMSG(0xE0), - _NONMSG(0xE1), - _NONMSG(0xE2), - _NONMSG(0xE3), - _NONMSG(0xE4), - _NONMSG(0xE5), - _NONMSG(0xE6), - _NONMSG(0xE7), - _NONMSG(0xE8), - _NONMSG(0xE9), - _NONMSG(0xEA), - _NONMSG(0xEB), - _NONMSG(0xEC), - _NONMSG(0xED), - _NONMSG(0xEE), - _NONMSG(0xEF), - _NONMSG(0xF0), - _NONMSG(0xF1), - _NONMSG(0xF2), - _NONMSG(0xF3), - _NONMSG(0xF4), - _NONMSG(0xF5), - _NONMSG(0xF6), - _NONMSG(0xF7), - _NONMSG(0xF8), - _NONMSG(0xF9), - _NONMSG(0xFA), - _NONMSG(0xFB), - _NONMSG(0xFC), - _NONMSG(0xFD), - _NONMSG(0xFE), - _NONMSG(0xFF), - }}, + [LIB9P_VER_9P2000_u] = { + _MSG_SEND(Rversion), + _MSG_SEND(Rauth), + _MSG_SEND(Rattach), + _MSG_SEND(Rerror), + _MSG_SEND(Rflush), + _MSG_SEND(Rwalk), + _MSG_SEND(Ropen), + _MSG_SEND(Rcreate), + _MSG_SEND(Rread), + _MSG_SEND(Rwrite), + _MSG_SEND(Rclunk), + _MSG_SEND(Rremove), + _MSG_SEND(Rstat), + _MSG_SEND(Rwstat), + }, #endif /* CONFIG_9P_ENABLE_9P2000_u */ }; -LM_FLATTEN bool _lib9p_validate_stat(struct _validate_ctx *ctx) { +LM_FLATTEN bool _lib9p_stat_validate(struct _validate_ctx *ctx) { return validate_stat(ctx); } -LM_FLATTEN void _lib9p_unmarshal_stat(struct _unmarshal_ctx *ctx, struct lib9p_stat *out) { +LM_FLATTEN void _lib9p_stat_unmarshal(struct _unmarshal_ctx *ctx, struct lib9p_stat *out) { unmarshal_stat(ctx, out); } -LM_FLATTEN bool _lib9p_marshal_stat(struct _marshal_ctx *ctx, struct lib9p_stat *val) { +LM_FLATTEN bool _lib9p_stat_marshal(struct _marshal_ctx *ctx, struct lib9p_stat *val) { return marshal_stat(ctx, val); } diff --git a/lib9p/idl.gen b/lib9p/idl.gen index 72efb7b..e796855 100755 --- a/lib9p/idl.gen +++ b/lib9p/idl.gen @@ -2,7 +2,7 @@ # lib9p/idl.gen - Generate C marshalers/unmarshalers for .9p files # defining 9P protocol variants. # -# Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> +# Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> # SPDX-License-Identifier: AGPL-3.0-or-later import os.path @@ -694,52 +694,57 @@ LM_ALWAYS_INLINE static bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) for msg in [msg for msg in typs if isinstance(msg, idl.Message)]: id2typ[msg.msgid] = msg - ret += "\n" + ret += f"#define _MSG_NAME(typ) [{idprefix.upper()}TYP_##typ] = #typ\n" ret += c_macro( - f"#define _MSG(typ) [{idprefix.upper()}TYP_##typ] = {{", - f"\t\t.name = #typ,", + f"#define _MSG_RECV(typ) [{idprefix.upper()}TYP_##typ/2] = {{", f"\t\t.basesize = sizeof(struct {idprefix}msg_##typ),", f"\t\t.validate = validate_##typ,", f"\t\t.unmarshal = (_unmarshal_fn_t)unmarshal_##typ,", - f"\t\t.marshal = (_marshal_fn_t)marshal_##typ,", f"\t}}", ) ret += c_macro( - f"#define _NONMSG(num) [num] = {{", f"\t\t.name = #num,", f"\t}}" + f"#define _MSG_SEND(typ) [{idprefix.upper()}TYP_##typ/2] = {{", + f"\t\t.marshal = (_marshal_fn_t)marshal_##typ,", + f"\t}}", ) - ret += "\n" - ret += f"struct _table_version _{idprefix}versions[{c_ver_enum('NUM')}] = {{\n" - for ver in ["unknown", *sorted(versions)]: - if ver != "unknown": - ret += ifdef_push(1, c_ver_ifdef({ver})) - ret += f"\t[{c_ver_enum(ver)}] = {{ .msgs = {{\n" - - for n in range(0, 0x100): - xmsg: idl.Message | None = id2typ.get(n, None) - if xmsg: - if ver == "unknown": # SPECIAL - if xmsg.name not in ["Tversion", "Rversion", "Rerror"]: - xmsg = None - else: - if ver not in xmsg.in_versions: - xmsg = None - if xmsg: - ret += f"\t\t_MSG({xmsg.name}),\n" - else: - ret += "\t\t_NONMSG(0x{:02X}),\n".format(n) - ret += "\t}},\n" - ret += ifdef_pop(0) - ret += "};\n" + tables = [ + ("msg", "name", "char *", (0, 0x100, 1)), + ("Tmsg", "recv", f"struct _{idprefix}recv_tentry", (0, 0x100, 2)), + ("Rmsg", "recv", f"struct _{idprefix}recv_tentry", (1, 0x100, 2)), + ("Tmsg", "send", f"struct _{idprefix}send_tentry", (0, 0x100, 2)), + ("Rmsg", "send", f"struct _{idprefix}send_tentry", (1, 0x100, 2)), + ] + for grp, meth, tentry, rng in tables: + ret += "\n" + ret += f"const {tentry} _{idprefix}table_{grp}_{meth}[{c_ver_enum('NUM')}][{hex(len(range(*rng)))}] = {{\n" + for ver in ["unknown", *sorted(versions)]: + if ver != "unknown": + ret += ifdef_push(1, c_ver_ifdef({ver})) + ret += f"\t[{c_ver_enum(ver)}] = {{\n" + for n in range(*rng): + xmsg: idl.Message | None = id2typ.get(n, None) + if xmsg: + if ver == "unknown": # SPECIAL + if xmsg.name not in ["Tversion", "Rversion", "Rerror"]: + xmsg = None + else: + if ver not in xmsg.in_versions: + xmsg = None + if xmsg: + ret += f"\t\t_MSG_{meth.upper()}({xmsg.name}),\n" + ret += "\t},\n" + ret += ifdef_pop(0) + ret += "};\n" ret += f""" -LM_FLATTEN bool _{idprefix}validate_stat(struct _validate_ctx *ctx) {{ +LM_FLATTEN bool _{idprefix}stat_validate(struct _validate_ctx *ctx) {{ \treturn validate_stat(ctx); }} -LM_FLATTEN void _{idprefix}unmarshal_stat(struct _unmarshal_ctx *ctx, struct lib9p_stat *out) {{ +LM_FLATTEN void _{idprefix}stat_unmarshal(struct _unmarshal_ctx *ctx, struct lib9p_stat *out) {{ \tunmarshal_stat(ctx, out); }} -LM_FLATTEN bool _{idprefix}marshal_stat(struct _marshal_ctx *ctx, struct lib9p_stat *val) {{ +LM_FLATTEN bool _{idprefix}stat_marshal(struct _marshal_ctx *ctx, struct lib9p_stat *val) {{ \treturn marshal_stat(ctx, val); }} """ diff --git a/lib9p/include/lib9p/9p.h b/lib9p/include/lib9p/9p.h index fb1f97d..72a8292 100644 --- a/lib9p/include/lib9p/9p.h +++ b/lib9p/include/lib9p/9p.h @@ -1,6 +1,6 @@ /* lib9p/9p.h - Base 9P protocol definitions for both clients and servers * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -49,7 +49,7 @@ 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 *****************************************************/ +/* main T-message functions ***************************************************/ /** * Validate a message's structure; it's size, string encodings, enums, @@ -68,13 +68,14 @@ const char *lib9p_msg_type_str(struct lib9p_ctx *, enum lib9p_msg_type); * * @return required size, or -1 on error * + * @errno LINUX_EOPNOTSUPP: message is an R-message * @errno LINUX_EOPNOTSUPP: message has unknown type * @errno LINUX_EBADMSG: message is wrong size for content * @errno LINUX_EBADMSG: message contains invalid UTF-8 * @errno LINUX_EBADMSG: message contains a bitfield with unknown bits * @errno LINUX_EMSGSIZE: would-be return value overflows SSIZE_MAX */ -ssize_t lib9p_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes); +ssize_t lib9p_Tmsg_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes); /** * Unmarshal the 9P message `net_bytes` into the C struct `ret_body`. @@ -82,25 +83,25 @@ ssize_t lib9p_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes); * Emits an error (return 0, set ctx->err_num and ctx->err_msg) if a * string contains invalid UTF-8 or a nul-byte. * - * lib9p_unmarshal does no validation; you must run lib9p_validate() - * first. + * lib9p_unmarshal does no validation; you must run + * lib9p_Tmsg_validate() first. * * @param ctx : negotiated protocol parameters, where to record errors * @param net_bytes : the complete message, starting with the "size[4]" * * @return ret_typ : the mesage type - * @return ret_body : the message body, must be at least lib9p_validate() bytes + * @return ret_body : the message body, must be at least lib9p_Tmsg_validate() bytes */ -void lib9p_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, - enum lib9p_msg_type *ret_typ, void *ret_body); +void lib9p_Tmsg_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, + enum lib9p_msg_type *ret_typ, void *ret_body); /** * Marshal a `struct lib9p_msg_{typ}` structure into a byte-array. * - * lib9p_marshal does no validation; it trusts that the programmer - * won't give it garbage input. However, just as it doesn't marshal - * struct fields that aren't in ctx->version, it won't marshal - * bitfield bits that aren't in ctx->version; it applies a + * lib9p_Tmsg_marshal does no validation; it trusts that the + * programmer won't give it garbage input. However, just as it + * doesn't marshal struct fields that aren't in ctx->version, it won't + * 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 @@ -112,13 +113,24 @@ void lib9p_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, * * @errno LINUX_ERANGE: reply does not fit in ctx->max_msg_size */ -bool lib9p_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body, - uint8_t *ret_bytes); +bool lib9p_Tmsg_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body, + uint8_t *ret_bytes); + +/* 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); +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, + 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) { +static inline void lib9p_stat_assert(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 )) ); @@ -132,10 +144,10 @@ static inline void lib9p_assert_stat(struct lib9p_stat stat) { * TODO * * @return ret_net_size: number of bytes consumed; <=net_size - * @return ret_host_size: number of bytes that lib9p_unmarshal_stat would take + * @return ret_host_size: number of bytes that lib9p_stat_unmarshal would take * @return whether there was an error */ -bool lib9p_validate_stat(struct lib9p_ctx *ctx, uint32_t net_size, uint8_t *net_bytes, +bool lib9p_stat_validate(struct lib9p_ctx *ctx, uint32_t net_size, uint8_t *net_bytes, uint32_t *ret_net_size, ssize_t *ret_host_size); /** @@ -145,14 +157,14 @@ bool lib9p_validate_stat(struct lib9p_ctx *ctx, uint32_t net_size, uint8_t *net_ * @return ret_extra : where to put strings for the stat object * @return consumed net_bytes */ -uint32_t lib9p_unmarshal_stat(struct lib9p_ctx *ctx, uint8_t *net_bytes, +uint32_t lib9p_stat_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, struct lib9p_stat *ret_obj, void *ret_extra); /** * @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 */ -uint32_t lib9p_marshal_stat(struct lib9p_ctx *ctx, uint32_t max_net_size, struct lib9p_stat *obj, +uint32_t lib9p_stat_marshal(struct lib9p_ctx *ctx, uint32_t max_net_size, struct lib9p_stat *obj, uint8_t *ret_bytes); #endif /* _LIB9P_9P_H_ */ diff --git a/lib9p/internal.h b/lib9p/internal.h index b1a367d..57d61cb 100644 --- a/lib9p/internal.h +++ b/lib9p/internal.h @@ -1,6 +1,6 @@ /* lib9p/internal.h - TODO * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -73,25 +73,27 @@ struct _marshal_ctx { }; typedef bool (*_marshal_fn_t)(struct _marshal_ctx *ctx, void *host_val); -/* tables *********************************************************************/ +/* tables / exports ***********************************************************/ -struct _table_msg { - char *name; +struct _lib9p_recv_tentry { size_t basesize; _validate_fn_t validate; _unmarshal_fn_t unmarshal; - _marshal_fn_t marshal; }; -struct _table_version { - struct _table_msg msgs[0x100]; +struct _lib9p_send_tentry { + _marshal_fn_t marshal; }; -extern struct _table_version _lib9p_versions[LIB9P_VER_NUM]; +extern const char * _lib9p_table_msg_name[LIB9P_VER_NUM][0x100]; +extern const struct _lib9p_recv_tentry _lib9p_table_Tmsg_recv[LIB9P_VER_NUM][0x80]; +extern const struct _lib9p_recv_tentry _lib9p_table_Rmsg_recv[LIB9P_VER_NUM][0x80]; +extern const struct _lib9p_send_tentry _lib9p_table_Tmsg_send[LIB9P_VER_NUM][0x80]; +extern const struct _lib9p_send_tentry _lib9p_table_Rmsg_send[LIB9P_VER_NUM][0x80]; -bool _lib9p_validate_stat(struct _validate_ctx *ctx); -void _lib9p_unmarshal_stat(struct _unmarshal_ctx *ctx, struct lib9p_stat *out); -bool _lib9p_marshal_stat(struct _marshal_ctx *ctx, struct lib9p_stat *val); +bool _lib9p_stat_validate(struct _validate_ctx *ctx); +void _lib9p_stat_unmarshal(struct _unmarshal_ctx *ctx, struct lib9p_stat *out); +bool _lib9p_stat_marshal(struct _marshal_ctx *ctx, struct lib9p_stat *val); /* unmarshal utilities ********************************************************/ diff --git a/lib9p/srv.c b/lib9p/srv.c index 3535f9a..e7fdb03 100644 --- a/lib9p/srv.c +++ b/lib9p/srv.c @@ -1,6 +1,6 @@ /* lib9p/srv.c - 9P server * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -116,9 +116,9 @@ static uint32_t rerror_overhead_for_version(enum lib9p_version version, struct lib9p_msg_Rerror empty_error = { 0 }; bool e; - e = lib9p_marshal(&empty_ctx, LIB9P_TYP_Rerror, - &empty_error, /* host_body */ - scratch); /* net_bytes */ + e = lib9p_Rmsg_marshal(&empty_ctx, LIB9P_TYP_Rerror, + &empty_error, /* host_body */ + scratch); /* net_bytes */ assert(!e); uint32_t min_msg_size = decode_u32le(scratch); @@ -162,8 +162,8 @@ static void respond_error(struct _lib9p_srv_req *req) { if (((uint32_t)host.ename.len) + sess->rerror_overhead > sess->max_msg_size) host.ename.len = sess->max_msg_size - sess->rerror_overhead; - lib9p_marshal(&req->ctx.basectx, LIB9P_TYP_Rerror, - &host, req->net_bytes); + lib9p_Rmsg_marshal(&req->ctx.basectx, LIB9P_TYP_Rerror, + &host, req->net_bytes); cr_mutex_lock(&sess->parent_conn->writelock); r = VCALL(sess->parent_conn->fd, write, @@ -369,14 +369,7 @@ static void handle_message(struct _lib9p_srv_req *ctx) { uint8_t host_resp[CONFIG_9P_MAX_HOSTMSG_SIZE]; /* Unmarshal it. */ - enum lib9p_msg_type typ = ctx->net_bytes[4]; - if (typ % 2 != 0) { - lib9p_errorf(&ctx->ctx.basectx, - LINUX_EOPNOTSUPP, "expected a T-message but got an R-message: message_type=%s", - lib9p_msg_type_str(&ctx->ctx.basectx, typ)); - goto write; - } - ssize_t host_size = lib9p_validate(&ctx->ctx.basectx, ctx->net_bytes); + ssize_t host_size = lib9p_Tmsg_validate(&ctx->ctx.basectx, ctx->net_bytes); if (host_size < 0) goto write; if ((size_t)host_size > sizeof(host_req)) { @@ -385,7 +378,8 @@ static void handle_message(struct _lib9p_srv_req *ctx) { host_size, sizeof(host_req)); goto write; } - lib9p_unmarshal(&ctx->ctx.basectx, ctx->net_bytes, + enum lib9p_msg_type typ; + lib9p_Tmsg_unmarshal(&ctx->ctx.basectx, ctx->net_bytes, &typ, host_req); /* Handle it. */ @@ -395,8 +389,8 @@ static void handle_message(struct _lib9p_srv_req *ctx) { if (lib9p_ctx_has_error(&ctx->ctx.basectx)) respond_error(ctx); else { - if (lib9p_marshal(&ctx->ctx.basectx, typ+1, host_resp, - ctx->net_bytes)) + if (lib9p_Rmsg_marshal(&ctx->ctx.basectx, typ+1, host_resp, + ctx->net_bytes)) goto write; cr_mutex_lock(&ctx->parent_sess->parent_conn->writelock); @@ -605,7 +599,7 @@ static void handle_Tattach(struct _lib9p_srv_req *ctx, &(struct lib9p_msg_Rclunk){}); return; } - lib9p_assert_stat(stat); + lib9p_stat_assert(stat); assert(stat.file_mode & LIB9P_DM_DIR); @@ -676,7 +670,7 @@ static void handle_Twalk(struct _lib9p_srv_req *ctx, util_release(&ctx->ctx, member); /* presumption of taking ref-A failed */ break; } - lib9p_assert_stat(stat); + lib9p_stat_assert(stat); isdir = stat.file_mode & LIB9P_DM_DIR; if (isdir && !util_check_perm(&ctx->ctx, &stat, 0b001)) { lib9p_error(&ctx->ctx.basectx, @@ -751,7 +745,7 @@ static void handle_Topen(struct _lib9p_srv_req *ctx, struct lib9p_stat parent_stat = VCALL(file->_parent_dir, stat, &ctx->ctx); if (lib9p_ctx_has_error(&ctx->ctx.basectx)) return; - lib9p_assert_stat(parent_stat); + lib9p_stat_assert(parent_stat); if (!util_check_perm(&ctx->ctx, &parent_stat, 0b010)) { lib9p_error(&ctx->ctx.basectx, LINUX_EACCES, "permission denied to remove-on-close"); @@ -762,7 +756,7 @@ static void handle_Topen(struct _lib9p_srv_req *ctx, struct lib9p_stat stat = VCALL(file, stat, &ctx->ctx); if (lib9p_ctx_has_error(&ctx->ctx.basectx)) return; - lib9p_assert_stat(stat); + lib9p_stat_assert(stat); if (stat.file_mode & LIB9P_QT_APPEND) reqmode = reqmode & ~LIB9P_O_TRUNC; uint8_t perm_bits = 0; @@ -851,7 +845,7 @@ static void handle_Tread(struct _lib9p_srv_req *ctx, uint32_t len = 0; for (size_t i = 0; i < num; i++) { uint32_t i_len; - lib9p_validate_stat(&ctx->ctx.basectx, req->count, &((uint8_t *)resp->data.dat)[len], &i_len, NULL); + lib9p_stat_validate(&ctx->ctx.basectx, req->count, &((uint8_t *)resp->data.dat)[len], &i_len, NULL); len += i_len; } resp->data.len = len; @@ -932,7 +926,7 @@ static void handle_Tstat(struct _lib9p_srv_req *ctx, resp->stat = VCALL(fidinfo->file, stat, &ctx->ctx); if (!lib9p_ctx_has_error(&ctx->ctx.basectx)) - lib9p_assert_stat(resp->stat); + lib9p_stat_assert(resp->stat); } static void handle_Twstat(struct _lib9p_srv_req *ctx, |