diff options
Diffstat (limited to 'lib9p')
-rw-r--r-- | lib9p/9p.c | 31 | ||||
-rw-r--r-- | lib9p/9p.generated.c | 361 | ||||
-rwxr-xr-x | lib9p/idl.gen | 102 | ||||
-rw-r--r-- | lib9p/include/lib9p/9p.generated.h | 2 | ||||
-rw-r--r-- | lib9p/include/lib9p/9p.h | 7 | ||||
-rw-r--r-- | lib9p/internal.h | 1 |
6 files changed, 252 insertions, 252 deletions
@@ -16,6 +16,25 @@ #include "internal.h" +/* strings ********************************************************************/ + +const char *lib9p_version_str(enum lib9p_version ver) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtype-limits" + assert(0 <= ver && ver < LIB9P_VER_NUM); +#pragma GCC diagnostic pop + return _lib9p_table_ver_name[ver]; +} + +const char *lib9p_msgtype_str(enum lib9p_version ver, enum lib9p_msg_type typ) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtype-limits" + assert(0 <= ver && ver < LIB9P_VER_NUM); + assert(0 <= typ && typ <= 0xFF); +#pragma GCC diagnostic pop + return _lib9p_table_msg_name[ver][typ] ?: const_byte_str(typ); +} + /* ctx ************************************************************************/ void lib9p_ctx_clear_error(struct lib9p_ctx *ctx) { @@ -67,14 +86,6 @@ 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) { -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wtype-limits" - assert(0 <= typ && typ <= 0xFF); -#pragma GCC diagnostic pop - return _lib9p_table_msg_name[ctx->version][typ] ?: const_byte_str(typ); -} - /* main message functions *****************************************************/ static @@ -96,11 +107,11 @@ ssize_t _lib9p_validate(uint8_t xxx_low_typ_bit, uint8_t typ = net_bytes[4]; 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)); + lib9p_msgtype_str(ctx->version, 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)); + lib9p_msgtype_str(ctx->version, typ), lib9p_version_str(ctx->version)); /* Now use the message-type-specific tentry to process the whole thing. */ if (tentry.validate(&subctx)) diff --git a/lib9p/9p.generated.c b/lib9p/9p.generated.c index d809588..29fa4a6 100644 --- a/lib9p/9p.generated.c +++ b/lib9p/9p.generated.c @@ -12,14 +12,6 @@ #include "internal.h" /* utilities ******************************************************************/ - -/** - * is_ver(ctx, ver) is essentially `(ctx->ctx->version == LIB9P_VER_##ver)`, - * but compiles correctly (to `false`) even if `LIB9P_VER_##ver` isn't defined - * (because `!CONFIG_9P_ENABLE_##ver`). This is useful when `||`ing - * several version checks together. - */ -#define is_ver(ctx, ver) _is_ver_##ver(ctx->ctx->version) #if CONFIG_9P_ENABLE_9P2000 #define _is_ver_9P2000(v) (v == LIB9P_VER_9P2000) #else @@ -41,9 +33,17 @@ #define _is_ver_9P2000_u(v) false #endif +/** + * is_ver(ctx, ver) is essentially `(ctx->ctx->version == LIB9P_VER_##ver)`, + * but compiles correctly (to `false`) even if `LIB9P_VER_##ver` isn't defined + * (because `!CONFIG_9P_ENABLE_##ver`). This is useful when `||`ing + * several version checks together. + */ +#define is_ver(ctx, ver) _is_ver_##ver(ctx->ctx->version) + /* strings ********************************************************************/ -static const char *version_strs[LIB9P_VER_NUM] = { +const char *_lib9p_table_ver_name[LIB9P_VER_NUM] = { [LIB9P_VER_unknown] = "unknown", #if CONFIG_9P_ENABLE_9P2000 [LIB9P_VER_9P2000] = "9P2000", @@ -59,13 +59,172 @@ static const char *version_strs[LIB9P_VER_NUM] = { #endif /* CONFIG_9P_ENABLE_9P2000_u */ }; -const char *lib9p_version_str(enum lib9p_version ver) { -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wtype-limits" - assert(0 <= ver && ver < LIB9P_VER_NUM); -#pragma GCC diagnostic pop - return version_strs[ver]; -} +#define _MSG_NAME(typ) [LIB9P_TYP_##typ] = #typ +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_L + [LIB9P_VER_9P2000_L] = { + _MSG_NAME(Rlerror), + _MSG_NAME(Tstatfs), + _MSG_NAME(Rstatfs), + _MSG_NAME(Tlopen), + _MSG_NAME(Rlopen), + _MSG_NAME(Tlcreate), + _MSG_NAME(Rlcreate), + _MSG_NAME(Tsymlink), + _MSG_NAME(Rsymlink), + _MSG_NAME(Tmknod), + _MSG_NAME(Rmknod), + _MSG_NAME(Trename), + _MSG_NAME(Rrename), + _MSG_NAME(Treadlink), + _MSG_NAME(Rreadlink), + _MSG_NAME(Tgetattr), + _MSG_NAME(Rgetattr), + _MSG_NAME(Tsetattr), + _MSG_NAME(Rsetattr), + _MSG_NAME(Txattrwalk), + _MSG_NAME(Rxattrwalk), + _MSG_NAME(Txattrcreate), + _MSG_NAME(Rxattrcreate), + _MSG_NAME(Treaddir), + _MSG_NAME(Rreaddir), + _MSG_NAME(Tfsync), + _MSG_NAME(Rfsync), + _MSG_NAME(Tlock), + _MSG_NAME(Rlock), + _MSG_NAME(Tgetlock), + _MSG_NAME(Rgetlock), + _MSG_NAME(Tlink), + _MSG_NAME(Rlink), + _MSG_NAME(Tmkdir), + _MSG_NAME(Trenameat), + _MSG_NAME(Rrenameat), + _MSG_NAME(Tunlinkat), + _MSG_NAME(Runlinkat), + _MSG_NAME(Tversion), + _MSG_NAME(Rversion), + _MSG_NAME(Tauth), + _MSG_NAME(Rauth), + _MSG_NAME(Tattach), + _MSG_NAME(Rattach), + _MSG_NAME(Tflush), + _MSG_NAME(Rflush), + _MSG_NAME(Twalk), + _MSG_NAME(Rwalk), + _MSG_NAME(Tread), + _MSG_NAME(Rread), + _MSG_NAME(Twrite), + _MSG_NAME(Rwrite), + _MSG_NAME(Tclunk), + _MSG_NAME(Tremove), + _MSG_NAME(Rremove), + }, +#endif /* CONFIG_9P_ENABLE_9P2000_L */ +#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 */ +}; /* bitmasks *******************************************************************/ @@ -3810,8 +3969,8 @@ LM_FLATTEN static bool marshal_Twstat(struct _marshal_ctx *ctx, struct lib9p_msg } #endif /* CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u */ -/* tables / exports ***********************************************************/ -#define _MSG_NAME(typ) [LIB9P_TYP_##typ] = #typ +/* function tables ************************************************************/ + #define _MSG_RECV(typ) [LIB9P_TYP_##typ/2] = { \ .basesize = sizeof(struct lib9p_msg_##typ), \ .validate = validate_##typ, \ @@ -3821,172 +3980,6 @@ LM_FLATTEN static bool marshal_Twstat(struct _marshal_ctx *ctx, struct lib9p_msg .marshal = (_marshal_fn_t)marshal_##typ, \ } -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_L - [LIB9P_VER_9P2000_L] = { - _MSG_NAME(Rlerror), - _MSG_NAME(Tstatfs), - _MSG_NAME(Rstatfs), - _MSG_NAME(Tlopen), - _MSG_NAME(Rlopen), - _MSG_NAME(Tlcreate), - _MSG_NAME(Rlcreate), - _MSG_NAME(Tsymlink), - _MSG_NAME(Rsymlink), - _MSG_NAME(Tmknod), - _MSG_NAME(Rmknod), - _MSG_NAME(Trename), - _MSG_NAME(Rrename), - _MSG_NAME(Treadlink), - _MSG_NAME(Rreadlink), - _MSG_NAME(Tgetattr), - _MSG_NAME(Rgetattr), - _MSG_NAME(Tsetattr), - _MSG_NAME(Rsetattr), - _MSG_NAME(Txattrwalk), - _MSG_NAME(Rxattrwalk), - _MSG_NAME(Txattrcreate), - _MSG_NAME(Rxattrcreate), - _MSG_NAME(Treaddir), - _MSG_NAME(Rreaddir), - _MSG_NAME(Tfsync), - _MSG_NAME(Rfsync), - _MSG_NAME(Tlock), - _MSG_NAME(Rlock), - _MSG_NAME(Tgetlock), - _MSG_NAME(Rgetlock), - _MSG_NAME(Tlink), - _MSG_NAME(Rlink), - _MSG_NAME(Tmkdir), - _MSG_NAME(Trenameat), - _MSG_NAME(Rrenameat), - _MSG_NAME(Tunlinkat), - _MSG_NAME(Runlinkat), - _MSG_NAME(Tversion), - _MSG_NAME(Rversion), - _MSG_NAME(Tauth), - _MSG_NAME(Rauth), - _MSG_NAME(Tattach), - _MSG_NAME(Rattach), - _MSG_NAME(Tflush), - _MSG_NAME(Rflush), - _MSG_NAME(Twalk), - _MSG_NAME(Rwalk), - _MSG_NAME(Tread), - _MSG_NAME(Rread), - _MSG_NAME(Twrite), - _MSG_NAME(Rwrite), - _MSG_NAME(Tclunk), - _MSG_NAME(Tremove), - _MSG_NAME(Rremove), - }, -#endif /* CONFIG_9P_ENABLE_9P2000_L */ -#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), diff --git a/lib9p/idl.gen b/lib9p/idl.gen index 47ca49a..4c3103c 100755 --- a/lib9p/idl.gen +++ b/lib9p/idl.gen @@ -204,8 +204,6 @@ enum {idprefix}version {{ ret += ifdef_pop(0) ret += f"\t{c_ver_enum('NUM')},\n" ret += "};\n" - ret += "\n" - ret += f"const char *{idprefix}version_str(enum {idprefix}version);\n" ret += """ /* enum msg_type **************************************************************/ @@ -330,6 +328,38 @@ def gen_c(versions: set[str], typs: list[idl.Type]) -> str: def unused(arg: str) -> str: return f"LM_UNUSED({arg})" + for v in sorted(versions): + ret += f"#if CONFIG_9P_ENABLE_{v.replace('.', '_')}\n" + ret += f"\t#define _is_ver_{v.replace('.', '_')}(v) (v == {c_ver_enum(v)})\n" + ret += "#else\n" + ret += f"\t#define _is_ver_{v.replace('.', '_')}(v) false\n" + ret += "#endif\n" + id2typ: dict[int, idl.Message] = {} + for msg in [msg for msg in typs if isinstance(msg, idl.Message)]: + id2typ[msg.msgid] = msg + + def msg_table(grp: str, meth: str, tentry: str, rng: tuple[int, int, int]) -> str: + 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" + return ret + ret += "\n" ret += "/**\n" ret += f" * is_ver(ctx, ver) is essentially `(ctx->ctx->version == {idprefix.upper()}VER_##ver)`,\n" @@ -338,18 +368,12 @@ def gen_c(versions: set[str], typs: list[idl.Type]) -> str: ret += " * several version checks together.\n" ret += " */\n" ret += "#define is_ver(ctx, ver) _is_ver_##ver(ctx->ctx->version)\n" - for v in sorted(versions): - ret += f"#if CONFIG_9P_ENABLE_{v.replace('.', '_')}\n" - ret += f"\t#define _is_ver_{v.replace('.', '_')}(v) (v == {c_ver_enum(v)})\n" - ret += "#else\n" - ret += f"\t#define _is_ver_{v.replace('.', '_')}(v) false\n" - ret += "#endif\n" # strings ################################################################## ret += f""" /* strings ********************************************************************/ -static const char *version_strs[{c_ver_enum('NUM')}] = {{ +const char *_lib9p_table_ver_name[{c_ver_enum('NUM')}] = {{ """ for ver in ["unknown", *sorted(versions)]: if ver in versions: @@ -357,15 +381,10 @@ static const char *version_strs[{c_ver_enum('NUM')}] = {{ ret += f'\t[{c_ver_enum(ver)}] = "{ver}",\n' ret += ifdef_pop(0) ret += "};\n" - ret += f""" -const char *{idprefix}version_str(enum {idprefix}version ver) {{ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wtype-limits" - assert(0 <= ver && ver < {c_ver_enum('NUM')}); -#pragma GCC diagnostic pop - return version_strs[ver]; -}} -""" + + ret += "\n" + ret += f"#define _MSG_NAME(typ) [{idprefix.upper()}TYP_##typ] = #typ\n" + ret += msg_table("msg", "name", "char *", (0, 0x100, 1)) # bitmasks ################################################################# ret += f""" @@ -739,15 +758,11 @@ LM_ALWAYS_INLINE static bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) ret += "}\n" ret += ifdef_pop(0) - # tables / exports ######################################################### + # function tables ########################################################## ret += """ -/* tables / exports ***********************************************************/ -""" - id2typ: dict[int, idl.Message] = {} - for msg in [msg for msg in typs if isinstance(msg, idl.Message)]: - id2typ[msg.msgid] = msg +/* function tables ************************************************************/ - ret += f"#define _MSG_NAME(typ) [{idprefix.upper()}TYP_##typ] = #typ\n" +""" ret += c_macro( f"#define _MSG_RECV(typ) [{idprefix.upper()}TYP_##typ/2] = {{", f"\t\t.basesize = sizeof(struct {idprefix}msg_##typ),", @@ -760,35 +775,14 @@ LM_ALWAYS_INLINE static bool marshal_8(struct _marshal_ctx *ctx, uint64_t *val) f"\t\t.marshal = (_marshal_fn_t)marshal_##typ,", f"\t}}", ) - - 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 += "\n" + ret += msg_table("Tmsg", "recv", f"struct _{idprefix}recv_tentry", (0, 0x100, 2)) + ret += "\n" + ret += msg_table("Rmsg", "recv", f"struct _{idprefix}recv_tentry", (1, 0x100, 2)) + ret += "\n" + ret += msg_table("Tmsg", "send", f"struct _{idprefix}send_tentry", (0, 0x100, 2)) + ret += "\n" + ret += msg_table("Rmsg", "send", f"struct _{idprefix}send_tentry", (1, 0x100, 2)) ret += f""" LM_FLATTEN bool _{idprefix}stat_validate(struct _validate_ctx *ctx) {{ diff --git a/lib9p/include/lib9p/9p.generated.h b/lib9p/include/lib9p/9p.generated.h index cf30e00..5b98ba8 100644 --- a/lib9p/include/lib9p/9p.generated.h +++ b/lib9p/include/lib9p/9p.generated.h @@ -45,8 +45,6 @@ enum lib9p_version { LIB9P_VER_NUM, }; -const char *lib9p_version_str(enum lib9p_version); - /* enum msg_type **************************************************************/ enum lib9p_msg_type { /* uint8_t */ diff --git a/lib9p/include/lib9p/9p.h b/lib9p/include/lib9p/9p.h index 21c10e0..24bae2b 100644 --- a/lib9p/include/lib9p/9p.h +++ b/lib9p/include/lib9p/9p.h @@ -19,6 +19,11 @@ #error config.h must define CONFIG_9P_MAX_ERR_SIZE #endif +/* strings ********************************************************************/ + +const char *lib9p_version_str(enum lib9p_version); +const char *lib9p_msgtype_str(enum lib9p_version, enum lib9p_msg_type); + /* ctx ************************************************************************/ struct lib9p_ctx { @@ -42,8 +47,6 @@ int lib9p_error(struct lib9p_ctx *ctx, uint32_t linux_errno, char const *msg); /** Write a printf-style error into ctx, return -1. */ int lib9p_errorf(struct lib9p_ctx *ctx, uint32_t linux_errno, char const *fmt, ...); -const char *lib9p_msg_type_str(struct lib9p_ctx *, enum lib9p_msg_type); - /* main T-message functions ***************************************************/ /** diff --git a/lib9p/internal.h b/lib9p/internal.h index 57d61cb..8ac5ebd 100644 --- a/lib9p/internal.h +++ b/lib9p/internal.h @@ -85,6 +85,7 @@ struct _lib9p_send_tentry { _marshal_fn_t marshal; }; +extern const char * _lib9p_table_ver_name[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]; |