From f132dab76a07473d41e14f5f4fb1857a3229ec6a Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Thu, 17 Oct 2024 14:31:03 -0600 Subject: libmisc --- lib9p/9p.c | 28 +- lib9p/9p.generated.c | 1206 ++++++++++++++++++++++++++++-------- lib9p/CMakeLists.txt | 2 +- lib9p/idl.gen | 56 +- lib9p/include/lib9p/9p.generated.h | 2 - lib9p/include/lib9p/9p.h | 2 + lib9p/include/lib9p/srv.h | 38 +- lib9p/internal.h | 13 +- lib9p/srv.c | 64 +- 9 files changed, 1042 insertions(+), 369 deletions(-) (limited to 'lib9p') diff --git a/lib9p/9p.c b/lib9p/9p.c index a008ccc..86d0ab8 100644 --- a/lib9p/9p.c +++ b/lib9p/9p.c @@ -49,6 +49,12 @@ 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; +} + ssize_t lib9p_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes) { /* Inspect the first 5 bytes ourselves. */ struct _validate_ctx subctx = { @@ -62,13 +68,13 @@ 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 _vtable_msg vtable = _lib9p_vtables[ctx->version].msgs[typ]; - if (!vtable.validate) + struct _table_msg table = _lib9p_versions[ctx->version].msgs[typ]; + if (!table.validate) return lib9p_errorf(ctx, LINUX_EOPNOTSUPP, "unknown message type: %s (protocol_version=%s)", - lib9p_msg_type_str(typ), lib9p_version_str(ctx->version)); + lib9p_msg_type_str(ctx, typ), lib9p_version_str(ctx->version)); - /* Now use the message-type-specific vtable to process the whole thing. */ - if (vtable.validate(&subctx)) + /* Now use the message-type-specific table to process the whole thing. */ + if (table.validate(&subctx)) return -1; assert(subctx.net_offset <= subctx.net_size); if (subctx.net_offset < subctx.net_size) @@ -77,7 +83,7 @@ ssize_t lib9p_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes) { /* Return. */ ssize_t ret; - if (__builtin_add_overflow(vtable.basesize, subctx.host_extra, &ret)) + if (__builtin_add_overflow(table.basesize, subctx.host_extra, &ret)) return lib9p_error(ctx, LINUX_EMSGSIZE, "unmarshalled payload overflows SSIZE_MAX"); return ret; } @@ -92,9 +98,9 @@ void lib9p_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes, }; *ret_typ = net_bytes[4]; - struct _vtable_msg vtable = _lib9p_vtables[ctx->version].msgs[*ret_typ]; - subctx.extra = ret_body + vtable.basesize; - vtable.unmarshal(&subctx, ret_body); + struct _table_msg table = _lib9p_versions[ctx->version].msgs[*ret_typ]; + subctx.extra = ret_body + table.basesize; + table.unmarshal(&subctx, ret_body); } bool lib9p_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body, @@ -105,8 +111,8 @@ bool lib9p_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body, .net_offset = 0, }; - struct _vtable_msg vtable = _lib9p_vtables[ctx->version].msgs[typ]; - return vtable.marshal(&subctx, body); + struct _table_msg table = _lib9p_versions[ctx->version].msgs[typ]; + return table.marshal(&subctx, body); } bool lib9p_validate_stat(struct lib9p_ctx *ctx, uint32_t net_size, uint8_t *net_bytes, diff --git a/lib9p/9p.generated.c b/lib9p/9p.generated.c index 50ed53f..6136433 100644 --- a/lib9p/9p.generated.c +++ b/lib9p/9p.generated.c @@ -30,270 +30,6 @@ const char *lib9p_version_str(enum lib9p_version ver) { return version_strs[ver]; } -static const char *msg_type_strs[0x100] = { - [0x00] = "0x00", - [0x01] = "0x01", - [0x02] = "0x02", - [0x03] = "0x03", - [0x04] = "0x04", - [0x05] = "0x05", - [0x06] = "0x06", - [0x07] = "0x07", - [0x08] = "0x08", - [0x09] = "0x09", - [0x0A] = "0x0A", - [0x0B] = "0x0B", - [0x0C] = "0x0C", - [0x0D] = "0x0D", - [0x0E] = "0x0E", - [0x0F] = "0x0F", - [0x10] = "0x10", - [0x11] = "0x11", - [0x12] = "0x12", - [0x13] = "0x13", - [0x14] = "0x14", - [0x15] = "0x15", - [0x16] = "0x16", - [0x17] = "0x17", - [0x18] = "0x18", - [0x19] = "0x19", - [0x1A] = "0x1A", - [0x1B] = "0x1B", - [0x1C] = "0x1C", - [0x1D] = "0x1D", - [0x1E] = "0x1E", - [0x1F] = "0x1F", - [0x20] = "0x20", - [0x21] = "0x21", - [0x22] = "0x22", - [0x23] = "0x23", - [0x24] = "0x24", - [0x25] = "0x25", - [0x26] = "0x26", - [0x27] = "0x27", - [0x28] = "0x28", - [0x29] = "0x29", - [0x2A] = "0x2A", - [0x2B] = "0x2B", - [0x2C] = "0x2C", - [0x2D] = "0x2D", - [0x2E] = "0x2E", - [0x2F] = "0x2F", - [0x30] = "0x30", - [0x31] = "0x31", - [0x32] = "0x32", - [0x33] = "0x33", - [0x34] = "0x34", - [0x35] = "0x35", - [0x36] = "0x36", - [0x37] = "0x37", - [0x38] = "0x38", - [0x39] = "0x39", - [0x3A] = "0x3A", - [0x3B] = "0x3B", - [0x3C] = "0x3C", - [0x3D] = "0x3D", - [0x3E] = "0x3E", - [0x3F] = "0x3F", - [0x40] = "0x40", - [0x41] = "0x41", - [0x42] = "0x42", - [0x43] = "0x43", - [0x44] = "0x44", - [0x45] = "0x45", - [0x46] = "0x46", - [0x47] = "0x47", - [0x48] = "0x48", - [0x49] = "0x49", - [0x4A] = "0x4A", - [0x4B] = "0x4B", - [0x4C] = "0x4C", - [0x4D] = "0x4D", - [0x4E] = "0x4E", - [0x4F] = "0x4F", - [0x50] = "0x50", - [0x51] = "0x51", - [0x52] = "0x52", - [0x53] = "0x53", - [0x54] = "0x54", - [0x55] = "0x55", - [0x56] = "0x56", - [0x57] = "0x57", - [0x58] = "0x58", - [0x59] = "0x59", - [0x5A] = "0x5A", - [0x5B] = "0x5B", - [0x5C] = "0x5C", - [0x5D] = "0x5D", - [0x5E] = "0x5E", - [0x5F] = "0x5F", - [0x60] = "0x60", - [0x61] = "0x61", - [0x62] = "0x62", - [0x63] = "0x63", - [0x64] = "Tversion", - [0x65] = "Rversion", - [0x66] = "Tauth", - [0x67] = "Rauth", - [0x68] = "Tattach", - [0x69] = "Rattach", - [0x6A] = "0x6A", - [0x6B] = "Rerror", - [0x6C] = "Tflush", - [0x6D] = "Rflush", - [0x6E] = "Twalk", - [0x6F] = "Rwalk", - [0x70] = "Topen", - [0x71] = "Ropen", - [0x72] = "Tcreate", - [0x73] = "Rcreate", - [0x74] = "Tread", - [0x75] = "Rread", - [0x76] = "Twrite", - [0x77] = "Rwrite", - [0x78] = "Tclunk", - [0x79] = "Rclunk", - [0x7A] = "Tremove", - [0x7B] = "Rremove", - [0x7C] = "Tstat", - [0x7D] = "Rstat", - [0x7E] = "Twstat", - [0x7F] = "Rwstat", - [0x80] = "0x80", - [0x81] = "0x81", - [0x82] = "0x82", - [0x83] = "0x83", - [0x84] = "0x84", - [0x85] = "0x85", - [0x86] = "0x86", - [0x87] = "0x87", - [0x88] = "0x88", - [0x89] = "0x89", - [0x8A] = "0x8A", - [0x8B] = "0x8B", - [0x8C] = "0x8C", - [0x8D] = "0x8D", - [0x8E] = "0x8E", - [0x8F] = "0x8F", - [0x90] = "0x90", - [0x91] = "0x91", - [0x92] = "0x92", - [0x93] = "0x93", - [0x94] = "0x94", - [0x95] = "0x95", - [0x96] = "Tsession", - [0x97] = "Rsession", - [0x98] = "Tsread", - [0x99] = "Rsread", - [0x9A] = "Tswrite", - [0x9B] = "Rswrite", - [0x9C] = "0x9C", - [0x9D] = "0x9D", - [0x9E] = "0x9E", - [0x9F] = "0x9F", - [0xA0] = "0xA0", - [0xA1] = "0xA1", - [0xA2] = "0xA2", - [0xA3] = "0xA3", - [0xA4] = "0xA4", - [0xA5] = "0xA5", - [0xA6] = "0xA6", - [0xA7] = "0xA7", - [0xA8] = "0xA8", - [0xA9] = "0xA9", - [0xAA] = "0xAA", - [0xAB] = "0xAB", - [0xAC] = "0xAC", - [0xAD] = "0xAD", - [0xAE] = "0xAE", - [0xAF] = "0xAF", - [0xB0] = "0xB0", - [0xB1] = "0xB1", - [0xB2] = "0xB2", - [0xB3] = "0xB3", - [0xB4] = "0xB4", - [0xB5] = "0xB5", - [0xB6] = "0xB6", - [0xB7] = "0xB7", - [0xB8] = "0xB8", - [0xB9] = "0xB9", - [0xBA] = "0xBA", - [0xBB] = "0xBB", - [0xBC] = "0xBC", - [0xBD] = "0xBD", - [0xBE] = "0xBE", - [0xBF] = "0xBF", - [0xC0] = "0xC0", - [0xC1] = "0xC1", - [0xC2] = "0xC2", - [0xC3] = "0xC3", - [0xC4] = "0xC4", - [0xC5] = "0xC5", - [0xC6] = "0xC6", - [0xC7] = "0xC7", - [0xC8] = "0xC8", - [0xC9] = "0xC9", - [0xCA] = "0xCA", - [0xCB] = "0xCB", - [0xCC] = "0xCC", - [0xCD] = "0xCD", - [0xCE] = "0xCE", - [0xCF] = "0xCF", - [0xD0] = "0xD0", - [0xD1] = "0xD1", - [0xD2] = "0xD2", - [0xD3] = "0xD3", - [0xD4] = "0xD4", - [0xD5] = "0xD5", - [0xD6] = "0xD6", - [0xD7] = "0xD7", - [0xD8] = "0xD8", - [0xD9] = "0xD9", - [0xDA] = "0xDA", - [0xDB] = "0xDB", - [0xDC] = "0xDC", - [0xDD] = "0xDD", - [0xDE] = "0xDE", - [0xDF] = "0xDF", - [0xE0] = "0xE0", - [0xE1] = "0xE1", - [0xE2] = "0xE2", - [0xE3] = "0xE3", - [0xE4] = "0xE4", - [0xE5] = "0xE5", - [0xE6] = "0xE6", - [0xE7] = "0xE7", - [0xE8] = "0xE8", - [0xE9] = "0xE9", - [0xEA] = "0xEA", - [0xEB] = "0xEB", - [0xEC] = "0xEC", - [0xED] = "0xED", - [0xEE] = "0xEE", - [0xEF] = "0xEF", - [0xF0] = "0xF0", - [0xF1] = "0xF1", - [0xF2] = "0xF2", - [0xF3] = "0xF3", - [0xF4] = "0xF4", - [0xF5] = "0xF5", - [0xF6] = "0xF6", - [0xF7] = "0xF7", - [0xF8] = "0xF8", - [0xF9] = "0xF9", - [0xFA] = "0xFA", - [0xFB] = "0xFB", - [0xFC] = "0xFC", - [0xFD] = "0xFD", - [0xFE] = "0xFE", - [0xFF] = "0xFF", -}; - -const char *lib9p_msg_type_str(enum lib9p_msg_type typ) { - assert(0 <= typ && typ <= 0xFF); - return msg_type_strs[typ]; -} - /* validate_* *****************************************************************/ static ALWAYS_INLINE bool _validate_size_net(struct _validate_ctx *ctx, uint32_t n) { @@ -2042,29 +1778,387 @@ static FLATTEN bool marshal_Rswrite(struct _marshal_ctx *ctx, struct lib9p_msg_R } #endif /* defined(CONFIG_9P_ENABLE_9P2000_e) */ -/* vtables / exports **********************************************************/ +/* tables / exports ***********************************************************/ #define _MSG(typ) [LIB9P_TYP_##typ] = { \ + .name = #typ, \ .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, \ + } -struct _vtable_version _lib9p_vtables[LIB9P_VER_NUM] = { +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), }}, #if defined(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), @@ -2086,16 +2180,245 @@ struct _vtable_version _lib9p_vtables[LIB9P_VER_NUM] = { _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), }}, #endif /* defined(CONFIG_9P_ENABLE_9P2000) */ #if defined(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), @@ -2117,22 +2440,245 @@ struct _vtable_version _lib9p_vtables[LIB9P_VER_NUM] = { _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), }}, #endif /* defined(CONFIG_9P_ENABLE_9P2000_e) */ #if defined(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), @@ -2154,6 +2700,134 @@ struct _vtable_version _lib9p_vtables[LIB9P_VER_NUM] = { _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), }}, #endif /* defined(CONFIG_9P_ENABLE_9P2000_u) */ }; diff --git a/lib9p/CMakeLists.txt b/lib9p/CMakeLists.txt index 784397b..829ac8e 100644 --- a/lib9p/CMakeLists.txt +++ b/lib9p/CMakeLists.txt @@ -12,5 +12,5 @@ target_sources(lib9p INTERFACE ) target_link_libraries(lib9p INTERFACE libcr_ipc - libnet + libmisc ) diff --git a/lib9p/idl.gen b/lib9p/idl.gen index e911ed7..a353a86 100755 --- a/lib9p/idl.gen +++ b/lib9p/idl.gen @@ -636,8 +636,6 @@ enum {idprefix}version {{ ret += f"\t{idprefix.upper()}TYP_{msg.name.ljust(namewidth)} = {msg.msgid},\n" ret += ifdef_pop(0) ret += "};\n" - ret += "\n" - ret += f"const char *{idprefix}msg_type_str(enum {idprefix}msg_type);\n" for msg in [msg for msg in typs if isinstance(msg, Message)]: ret += "\n" @@ -717,20 +715,6 @@ const char *{idprefix}version_str(enum {idprefix}version ver) {{ assert(0 <= ver && ver < {c_ver_enum('NUM')}); return version_strs[ver]; }} - -static const char *msg_type_strs[0x100] = {{ -""" - id2name: dict[int, str] = {} - for msg in [msg for msg in typs if isinstance(msg, Message)]: - id2name[msg.msgid] = msg.name - for n in range(0, 0x100): - ret += '\t[0x{:02X}] = "{}",\n'.format(n, id2name.get(n, "0x{:02X}".format(n))) - ret += "};\n" - ret += f""" -const char *{idprefix}msg_type_str(enum {idprefix}msg_type typ) {{ - assert(0 <= typ && typ <= 0xFF); - return msg_type_strs[typ]; -}} """ # validate_* ############################################################### @@ -1093,33 +1077,45 @@ static ALWAYS_INLINE bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) { ret += "}\n" ret += ifdef_pop(0) - # vtables / exports ######################################################## + # tables / exports ######################################################### ret += f""" -/* vtables / exports **********************************************************/ +/* tables / exports ***********************************************************/ #define _MSG(typ) [{idprefix.upper()}TYP_##typ] = {{ \\ + .name = #typ, \\ .basesize = sizeof(struct {idprefix}msg_##typ), \\ .validate = validate_##typ, \\ .unmarshal = (_unmarshal_fn_t)unmarshal_##typ, \\ .marshal = (_marshal_fn_t)marshal_##typ, \\ }} +#define _NONMSG(num) [num] = {{ \\ + .name = #num, \\ + }} -struct _vtable_version _{idprefix}vtables[{c_ver_enum('NUM')}] = {{ +struct _table_version _{idprefix}versions[{c_ver_enum('NUM')}] = {{ """ - - ret += f"\t[{c_ver_enum('unknown')}] = {{ .msgs = {{\n" + id2typ: dict[int, Message] = {} for msg in [msg for msg in typs if isinstance(msg, Message)]: - if msg.name in ["Tversion", "Rversion", "Rerror"]: # SPECIAL - ret += f"\t\t_MSG({msg.name}),\n" - ret += "\t}},\n" + id2typ[msg.msgid] = msg - for ver in sorted(versions): - ret += ifdef_push(1, c_ver_ifdef({ver})) + 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 msg in [msg for msg in typs if isinstance(msg, Message)]: - if ver not in msg.in_versions: - continue - ret += f"\t\t_MSG({msg.name}),\n" + + for n in range(0, 0x100): + xmsg: 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" diff --git a/lib9p/include/lib9p/9p.generated.h b/lib9p/include/lib9p/9p.generated.h index 584960c..ca7ca07 100644 --- a/lib9p/include/lib9p/9p.generated.h +++ b/lib9p/include/lib9p/9p.generated.h @@ -184,8 +184,6 @@ enum lib9p_msg_type { /* uint8_t */ #endif /* defined(CONFIG_9P_ENABLE_9P2000_e) */ }; -const char *lib9p_msg_type_str(enum lib9p_msg_type); - #if defined(CONFIG_9P_ENABLE_9P2000) || defined(CONFIG_9P_ENABLE_9P2000_e) || defined(CONFIG_9P_ENABLE_9P2000_u) struct lib9p_msg_Tversion { lib9p_tag_t tag; diff --git a/lib9p/include/lib9p/9p.h b/lib9p/include/lib9p/9p.h index e7ddb15..a99cd5d 100644 --- a/lib9p/include/lib9p/9p.h +++ b/lib9p/include/lib9p/9p.h @@ -56,6 +56,8 @@ static bool lib9p_ctx_has_error(struct lib9p_ctx *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 )) ); diff --git a/lib9p/include/lib9p/srv.h b/lib9p/include/lib9p/srv.h index 91663e7..797695c 100644 --- a/lib9p/include/lib9p/srv.h +++ b/lib9p/include/lib9p/srv.h @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -38,50 +39,48 @@ static inline int lib9p_srv_acknowledge_flush(struct lib9p_srv_ctx *ctx) { return -1; } -/* vtables you must implement *************************************************/ +/* interface definitions ******************************************************/ struct lib9p_srv_file; struct lib9p_srv_file_vtable { /* all - resource management */ - struct lib9p_srv_file *(*clone )(struct lib9p_srv_ctx *, struct lib9p_srv_file *); - void (*free )(struct lib9p_srv_ctx *, struct lib9p_srv_file *); + struct lib9p_srv_file *(*clone )(struct lib9p_srv_file *, struct lib9p_srv_ctx *); + void (*free )(struct lib9p_srv_file *, struct lib9p_srv_ctx *); /* all - syscalls */ - uint32_t (*io )(struct lib9p_srv_ctx *, struct lib9p_srv_file *, + uint32_t (*io )(struct lib9p_srv_file *, struct lib9p_srv_ctx *, lib9p_o_t flags); - struct lib9p_stat (*stat )(struct lib9p_srv_ctx *, struct lib9p_srv_file *); - void (*wstat )(struct lib9p_srv_ctx *, struct lib9p_srv_file *, + struct lib9p_stat (*stat )(struct lib9p_srv_file *, struct lib9p_srv_ctx *); + void (*wstat )(struct lib9p_srv_file *, struct lib9p_srv_ctx *, struct lib9p_stat new); - void (*remove )(struct lib9p_srv_ctx *, struct lib9p_srv_file *); + void (*remove )(struct lib9p_srv_file *, struct lib9p_srv_ctx *); /* directories - base */ - struct lib9p_srv_file *(*dopen )(struct lib9p_srv_ctx *, struct lib9p_srv_file *, + struct lib9p_srv_file *(*dopen )(struct lib9p_srv_file *, struct lib9p_srv_ctx *, char *childname); - struct lib9p_srv_file *(*dcreate)(struct lib9p_srv_ctx *, struct lib9p_srv_file *, + struct lib9p_srv_file *(*dcreate)(struct lib9p_srv_file *, struct lib9p_srv_ctx *, char *childname, lib9p_dm_t perm, lib9p_o_t flags); /* directories - once opened */ - size_t /* <- obj cnt */(*dread )(struct lib9p_srv_ctx *, struct lib9p_srv_file *, + size_t /* <- obj cnt */(*dread )(struct lib9p_srv_file *, struct lib9p_srv_ctx *, uint8_t *buf, uint32_t byte_count, /* <- num bytes */ size_t obj_offset); /* <- starting at this object */ /* non-directories - once opened */ - uint32_t (*pread )(struct lib9p_srv_ctx *, struct lib9p_srv_file *, + uint32_t (*pread )(struct lib9p_srv_file *, struct lib9p_srv_ctx *, void *buf, uint32_t byte_count, uint64_t byte_offset); - uint32_t (*pwrite )(struct lib9p_srv_ctx *, struct lib9p_srv_file *, + uint32_t (*pwrite )(struct lib9p_srv_file *, struct lib9p_srv_ctx *, void *buf, uint32_t byte_count, uint64_t byte_offset); }; -/* objects you'll deal with ***************************************************/ - -struct lib9p_srv_file { +typedef struct lib9p_srv_file { struct lib9p_srv_file_vtable *vtable; /* Managed by srv.c, but should be cloned by ->vtable->clone(). */ @@ -90,11 +89,8 @@ struct lib9p_srv_file { /* Managed by srv.c, but should be initialized to 0 by ->vtable->clone(). */ /* ref type 1: an entry in fidmap * ref type 2: ->_parent_dir of another file */ - struct lib9p_srv_file *_refcount; - - /* This is where your implementation data goes. */ - char data[0]; -}; + unsigned int _refcount; +} implements_lib9p_srv_file; /* main server entrypoints ****************************************************/ @@ -119,7 +115,7 @@ struct lib9p_srv { * @errno LINUX_ERANGE R-message does not fit into max_msg_size */ -__attribute__ ((noreturn)) void lib9p_srv_read_cr(struct lib9p_srv *srv, struct libnet_listener *listener); +__attribute__ ((noreturn)) void lib9p_srv_read_cr(struct lib9p_srv *srv, implements_net_listener *listener); COROUTINE lib9p_srv_write_cr(void *_srv); #endif /* _LIB9P_SRV_H_ */ diff --git a/lib9p/internal.h b/lib9p/internal.h index 013024e..d78823d 100644 --- a/lib9p/internal.h +++ b/lib9p/internal.h @@ -45,7 +45,7 @@ static_assert(CONFIG_9P_MAX_HOSTMSG_SIZE <= SSIZE_MAX); #define CAT2(a, b) a##b #define CAT3(a, b, c) a##b##c -/* vtables ********************************************************************/ +/* specialized contexts *******************************************************/ struct _validate_ctx { struct lib9p_ctx *ctx; @@ -77,18 +77,21 @@ struct _marshal_ctx { }; typedef bool (*_marshal_fn_t)(struct _marshal_ctx *ctx, void *host_val); -struct _vtable_msg { +/* tables *********************************************************************/ + +struct _table_msg { + char *name; size_t basesize; _validate_fn_t validate; _unmarshal_fn_t unmarshal; _marshal_fn_t marshal; }; -struct _vtable_version { - struct _vtable_msg msgs[0xFF]; +struct _table_version { + struct _table_msg msgs[0x100]; }; -extern struct _vtable_version _lib9p_vtables[LIB9P_VER_NUM]; +extern struct _table_version _lib9p_versions[LIB9P_VER_NUM]; bool _lib9p_validate_stat(struct _validate_ctx *ctx); void _lib9p_unmarshal_stat(struct _unmarshal_ctx *ctx, struct lib9p_stat *out); diff --git a/lib9p/srv.c b/lib9p/srv.c index 90791f3..cc4a048 100644 --- a/lib9p/srv.c +++ b/lib9p/srv.c @@ -14,15 +14,13 @@ #include #include #include -#include +#include #include #include "internal.h" /* structs ********************************************************************/ -#define MCALL(o, m, ...) (o)->vtable->m(o __VA_OPT__(,) __VA_ARGS__) - #define FIDFLAG_OPEN_R (1<<0) #define FIDFLAG_OPEN_W (1<<1) #define FIDFLAG_RCLOSE (1<<2) @@ -59,7 +57,7 @@ struct _srv_fidinfo { struct _srv_conn { /* immutable */ struct lib9p_srv *parent_srv; - struct libnet_conn *fd; + implements_net_conn *fd; cid_t reader; /* the lib9p_srv_read_cr() coroutine */ /* mutable */ cr_mutex_t writelock; @@ -151,7 +149,7 @@ static void respond_error(struct _lib9p_srv_req *req) { &host, req->net_bytes); cr_mutex_lock(&sess->parent_conn->writelock); - r = MCALL(sess->parent_conn->fd, write, + r = VCALL(sess->parent_conn->fd, write, req->net_bytes, decode_u32le(req->net_bytes)); cr_mutex_unlock(&sess->parent_conn->writelock); if (r < 0) @@ -160,12 +158,12 @@ static void respond_error(struct _lib9p_srv_req *req) { /* read coroutine *************************************************************/ -static bool read_at_least(struct libnet_conn *fd, uint8_t *buf, size_t goal, size_t *done) { +static bool read_at_least(implements_net_conn *fd, uint8_t *buf, size_t goal, size_t *done) { assert(buf); assert(goal); assert(done); while (*done < goal) { - ssize_t r = MCALL(fd, read, &buf[*done], CONFIG_9P_MAX_MSG_SIZE - *done); + ssize_t r = VCALL(fd, read, &buf[*done], CONFIG_9P_MAX_MSG_SIZE - *done); if (r < 0) { nonrespond_errorf("read: %s", strerror(-r)); return true; @@ -181,7 +179,7 @@ static bool read_at_least(struct libnet_conn *fd, uint8_t *buf, size_t goal, siz static void handle_message(struct _lib9p_srv_req *ctx); -__attribute__ ((noreturn)) void lib9p_srv_read_cr(struct lib9p_srv *srv, struct libnet_listener *listener) { +__attribute__ ((noreturn)) void lib9p_srv_read_cr(struct lib9p_srv *srv, implements_net_listener *listener) { uint8_t buf[CONFIG_9P_MAX_MSG_SIZE]; assert(srv); @@ -193,7 +191,7 @@ __attribute__ ((noreturn)) void lib9p_srv_read_cr(struct lib9p_srv *srv, struct for (;;) { struct _srv_conn conn = { .parent_srv = srv, - .fd = MCALL(listener, accept), + .fd = VCALL(listener, accept), .reader = cr_getcid(), }; if (!conn.fd) { @@ -253,12 +251,12 @@ __attribute__ ((noreturn)) void lib9p_srv_read_cr(struct lib9p_srv *srv, struct _lib9p_srv_reqch_send_req(&srv->_reqch, &req); } close: - MCALL(conn.fd, close, true, sess.reqs.len == 0); + VCALL(conn.fd, close, true, sess.reqs.len == 0); if (sess.reqs.len) { sess.closing = true; cr_pause_and_yield(); assert(sess.reqs.len == 0); - MCALL(conn.fd, close, true, true); + VCALL(conn.fd, close, true, true); } } } @@ -358,7 +356,7 @@ static void handle_message(struct _lib9p_srv_req *ctx) { 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(typ)); + lib9p_msg_type_str(&ctx->ctx.basectx, typ)); goto write; } ssize_t host_size = lib9p_validate(&ctx->ctx.basectx, ctx->net_bytes); @@ -385,17 +383,17 @@ static void handle_message(struct _lib9p_srv_req *ctx) { goto write; cr_mutex_lock(&ctx->parent_sess->parent_conn->writelock); - MCALL(ctx->parent_sess->parent_conn->fd, write, + VCALL(ctx->parent_sess->parent_conn->fd, write, ctx->net_bytes, decode_u32le(ctx->net_bytes)); cr_mutex_unlock(&ctx->parent_sess->parent_conn->writelock); } } #define util_handler_common(ctx, req, resp) do { \ - assert(ctx); \ - assert(req); \ - assert(resp); \ - resp->tag = req->tag; \ + assert(ctx); \ + assert(req); \ + assert(resp); \ + resp->tag = req->tag; \ } while (0) static inline bool util_check_perm(struct lib9p_srv_ctx *ctx, struct lib9p_stat *stat, uint8_t action) { @@ -415,7 +413,7 @@ static inline bool util_release(struct lib9p_srv_ctx *ctx, struct lib9p_srv_file if (file->_refcount == 0) { if (file->_parent_dir != file) util_release(ctx, file->_parent_dir); - file->vtable->free(ctx, file); + VCALL(file, free, ctx); } return lib9p_ctx_has_error(&ctx->basectx); } @@ -437,11 +435,11 @@ static void handle_Tversion(struct _lib9p_srv_req *ctx, (req->version.utf8[6] == '\0' || req->version.utf8[6] == '.')) { version = LIB9P_VER_9P2000; #ifdef CONFIG_9P_ENABLE_9P2000_u - if (strcmp((char *)&req->version.utf8[6], ".u") == 0) + if (strcmp(&req->version.utf8[6], ".u") == 0) version = LIB9P_VER_9P2000_u; #endif #ifdef CONFIG_9P_ENABLE_9P2000_e - if (strcmp((char *)&req->version.utf8[6], ".e") == 0) + if (strcmp(&req->version.utf8[6], ".e") == 0) version = LIB9P_VER_9P2000_e; #endif } @@ -458,7 +456,7 @@ static void handle_Tversion(struct _lib9p_srv_req *ctx, #pragma GCC diagnostic ignored "-Wdiscarded-qualifiers" resp->version.utf8 = lib9p_version_str(version); #pragma GCC diagnostic pop - resp->version.len = strlen((char *)resp->version.utf8); + resp->version.len = strlen(resp->version.utf8); resp->max_msg_size = (CONFIG_9P_MAX_MSG_SIZE < req->max_msg_size) ? CONFIG_9P_MAX_MSG_SIZE : req->max_msg_size; @@ -583,7 +581,7 @@ static void handle_Tattach(struct _lib9p_srv_req *ctx, return; } - struct lib9p_stat stat = rootdir->vtable->stat(&ctx->ctx, rootdir); + struct lib9p_stat stat = VCALL(rootdir, stat, &ctx->ctx); if (lib9p_ctx_has_error(&ctx->ctx.basectx)) { handle_Tclunk(ctx, &(struct lib9p_msg_Tclunk){.fid = req->fid}, @@ -627,7 +625,7 @@ static void handle_Twalk(struct _lib9p_srv_req *ctx, struct lib9p_srv_file *dir = fidinfo->file; if (req->newfid != req->fid) { - dir = dir->vtable->clone(&ctx->ctx, dir); + dir = VCALL(dir, clone, &ctx->ctx); assert((dir == NULL) == lib9p_ctx_has_error(&ctx->ctx.basectx)); if (lib9p_ctx_has_error(&ctx->ctx.basectx)) return; @@ -647,7 +645,7 @@ static void handle_Twalk(struct _lib9p_srv_req *ctx, break; } - member = dir->vtable->dopen(&ctx->ctx, dir, req->wname[resp->nwqid].utf8); + member = VCALL(dir, dopen, &ctx->ctx, req->wname[resp->nwqid].utf8); assert((member == NULL) == lib9p_ctx_has_error(&ctx->ctx.basectx)); if (lib9p_ctx_has_error(&ctx->ctx.basectx)) break; @@ -656,7 +654,7 @@ static void handle_Twalk(struct _lib9p_srv_req *ctx, } member->_refcount++; /* presumptively take ref-A */ - struct lib9p_stat stat = member->vtable->stat(&ctx->ctx, member); + struct lib9p_stat stat = VCALL(member, stat, &ctx->ctx); if (lib9p_ctx_has_error(&ctx->ctx.basectx)) { util_release(&ctx->ctx, member); /* presumption of taking ref-A failed */ break; @@ -733,7 +731,7 @@ static void handle_Topen(struct _lib9p_srv_req *ctx, /* Check permissions. */ if (reqmode & LIB9P_O_RCLOSE) { - struct lib9p_stat parent_stat = file->_parent_dir->vtable->stat(&ctx->ctx, file->_parent_dir); + 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); @@ -744,7 +742,7 @@ static void handle_Topen(struct _lib9p_srv_req *ctx, } fidflags = fidflags | FIDFLAG_RCLOSE; } - struct lib9p_stat stat = file->vtable->stat(&ctx->ctx, file); + struct lib9p_stat stat = VCALL(file, stat, &ctx->ctx); if (lib9p_ctx_has_error(&ctx->ctx.basectx)) return; lib9p_assert_stat(stat); @@ -775,7 +773,7 @@ static void handle_Topen(struct _lib9p_srv_req *ctx, } /* Actually make the call. */ - uint32_t iounit = file->vtable->io(&ctx->ctx, file, reqmode); + uint32_t iounit = VCALL(file, io, &ctx->ctx, reqmode); if (lib9p_ctx_has_error(&ctx->ctx.basectx)) return; @@ -831,7 +829,7 @@ static void handle_Tread(struct _lib9p_srv_req *ctx, return; } /* Do it. */ - size_t num = file->vtable->dread(&ctx->ctx, file, (uint8_t *)resp->data.dat, req->count, idx); + size_t num = VCALL(file, dread, &ctx->ctx, (uint8_t *)resp->data.dat, req->count, idx); /* Translate object-count back to byte-count. */ uint32_t len = 0; for (size_t i = 0; i < num; i++) { @@ -844,7 +842,7 @@ static void handle_Tread(struct _lib9p_srv_req *ctx, fidinfo->dir_idx = idx+num; fidinfo->dir_off = req->offset + len; } else - resp->data.len = file->vtable->pread(&ctx->ctx, file, resp->data.dat, req->count, req->offset); + resp->data.len = VCALL(file, pread, &ctx->ctx, resp->data.dat, req->count, req->offset); } static void handle_Twrite(struct _lib9p_srv_req *ctx, @@ -869,7 +867,7 @@ static void handle_Twrite(struct _lib9p_srv_req *ctx, struct lib9p_srv_file *file = fidinfo->file; /* Do it. */ - resp->count = file->vtable->pwrite(&ctx->ctx, file, req->data.dat, req->data.len, req->offset); + resp->count = VCALL(file, pwrite, &ctx->ctx, req->data.dat, req->data.len, req->offset); } static void handle_Tclunk(struct _lib9p_srv_req *ctx, @@ -890,7 +888,7 @@ static void handle_Tclunk(struct _lib9p_srv_req *ctx, return; } - fidinfo->file->vtable->free(&ctx->ctx, fidinfo->file); + VCALL(fidinfo->file, free, &ctx->ctx); fidmap_del(&ctx->parent_sess->fids, req->fid); } @@ -915,7 +913,7 @@ static void handle_Tstat(struct _lib9p_srv_req *ctx, return; } - resp->stat = fidinfo->file->vtable->stat(&ctx->ctx, fidinfo->file); + resp->stat = VCALL(fidinfo->file, stat, &ctx->ctx); if (!lib9p_ctx_has_error(&ctx->ctx.basectx)) lib9p_assert_stat(resp->stat); } -- cgit v1.2.3-2-g168b