diff options
Diffstat (limited to 'lib9p')
-rwxr-xr-x | lib9p/idl.gen | 4 | ||||
-rw-r--r-- | lib9p/idl/2002-9P2000.9p | 2 | ||||
-rw-r--r-- | lib9p/idl/2005-9P2000.u.9p | 1 | ||||
-rw-r--r-- | lib9p/idl/__init__.py | 20 | ||||
-rw-r--r-- | lib9p/include/lib9p/9p.generated.h | 3 | ||||
-rw-r--r-- | lib9p/include/lib9p/9p.h | 5 | ||||
-rw-r--r-- | lib9p/srv.c | 2 |
7 files changed, 31 insertions, 6 deletions
diff --git a/lib9p/idl.gen b/lib9p/idl.gen index 0a43583..31f6527 100755 --- a/lib9p/idl.gen +++ b/lib9p/idl.gen @@ -227,6 +227,10 @@ enum {idprefix}version {{ match typ: case idl.Number(): ret += f"typedef {c_typename(typ.prim)} {c_typename(typ)};\n" + prefix = f"{idprefix.upper()}{typ.name.upper()}_" + namewidth = max(len(name) for name in typ.vals) + for name, val in typ.vals.items(): + ret += f"#define {prefix}{name.ljust(namewidth)} (({c_typename(typ)})UINT{typ.static_size*8}_C({val}))\n" case idl.Bitfield(): ret += f"typedef {c_typename(typ.prim)} {c_typename(typ)};\n" names = [ diff --git a/lib9p/idl/2002-9P2000.9p b/lib9p/idl/2002-9P2000.9p index 4b0738f..c1cd74b 100644 --- a/lib9p/idl/2002-9P2000.9p +++ b/lib9p/idl/2002-9P2000.9p @@ -21,9 +21,11 @@ version "9P2000" # tag - identify a request/response pair num tag = 2 + "NOTAG = ~0" # file identifier - like a UNIX file-descriptor num fid = 4 + "NOFID = ~0" # data - s32le `n`, then `n` bytes of data struct d = "len[4,max=s32_max] len*(dat[1])" diff --git a/lib9p/idl/2005-9P2000.u.9p b/lib9p/idl/2005-9P2000.u.9p index 0529e47..d96bbce 100644 --- a/lib9p/idl/2005-9P2000.u.9p +++ b/lib9p/idl/2005-9P2000.u.9p @@ -12,6 +12,7 @@ from ./2002-9P2000.9p import * # numeric user ID num nuid = 4 + "NONUID = ~0" struct stat += "file_extension[s]" "file_owner_n_uid[nuid]" diff --git a/lib9p/idl/__init__.py b/lib9p/idl/__init__.py index c08a89e..ab45ed0 100644 --- a/lib9p/idl/__init__.py +++ b/lib9p/idl/__init__.py @@ -50,8 +50,11 @@ class Number: prim: Primitive + vals: dict[str, str] + def __init__(self) -> None: self.in_versions = set() + self.vals = {} @property def static_size(self) -> int: @@ -195,12 +198,27 @@ re_memtype = f"(?:{re_symname}|{re_priname})" # typenames that a struct member re_expr = f"(?:(?:-|\\+|[0-9]+|&?{re_symname})+)" +re_numspec = f"(?P<name>{re_symname})\\s*=\\s*(?P<val>\\S+)" + re_bitspec_bit = f"(?P<bit>[0-9]+)\\s*=\\s*(?P<name>{re_symname})" re_bitspec_alias = f"(?P<name>{re_symname})\\s*=\\s*(?P<val>\\S+)" re_memberspec = f"(?:(?P<cnt>{re_symname})\\*\\()?(?P<name>{re_symname})\\[(?P<typ>{re_memtype})(?:,max=(?P<max>{re_expr})|,val=(?P<val>{re_expr}))*\\]\\)?" +def parse_numspec(ver: str, n: Number, spec: str) -> None: + spec = spec.strip() + + if m := re.fullmatch(re_numspec, spec): + name = m.group("name") + val = m.group("val") + if name in n.vals: + raise ValueError(f"{n.name}: name {repr(name)} already assigned") + n.vals[name] = val + else: + raise SyntaxError(f"invalid num spec {repr(spec)}") + + def parse_bitspec(ver: str, bf: Bitfield, spec: str) -> None: spec = spec.strip() @@ -433,6 +451,8 @@ def parse_file( match prev: case Bitfield(): parse_bitspec(version, prev, m.group("specs")) + case Number(): + parse_numspec(version, prev, m.group("specs")) case Struct(): # and Message() parse_members(version, env, prev, m.group("specs")) case _: diff --git a/lib9p/include/lib9p/9p.generated.h b/lib9p/include/lib9p/9p.generated.h index 96462a2..3bc77c4 100644 --- a/lib9p/include/lib9p/9p.generated.h +++ b/lib9p/include/lib9p/9p.generated.h @@ -86,8 +86,10 @@ enum lib9p_msg_type { /* uint8_t */ #if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u typedef uint16_t lib9p_tag_t; +#define LIB9P_TAG_NOTAG ((lib9p_tag_t)UINT16_C(~0)) typedef uint32_t lib9p_fid_t; +#define LIB9P_FID_NOFID ((lib9p_fid_t)UINT32_C(~0)) struct lib9p_d { uint32_t len; @@ -158,6 +160,7 @@ typedef uint8_t lib9p_qt_t; #endif /* CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u */ #if CONFIG_9P_ENABLE_9P2000_u typedef uint32_t lib9p_nuid_t; +#define LIB9P_NUID_NONUID ((lib9p_nuid_t)UINT32_C(~0)) #endif /* CONFIG_9P_ENABLE_9P2000_u */ #if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u diff --git a/lib9p/include/lib9p/9p.h b/lib9p/include/lib9p/9p.h index 72a8292..21c10e0 100644 --- a/lib9p/include/lib9p/9p.h +++ b/lib9p/include/lib9p/9p.h @@ -19,11 +19,6 @@ #error config.h must define CONFIG_9P_MAX_ERR_SIZE #endif -/******************************************************************************/ - -#define LIB9P_NOTAG ((uint16_t)~0U) -#define LIB9P_NOFID ((uint32_t)~0U) - /* ctx ************************************************************************/ struct lib9p_ctx { diff --git a/lib9p/srv.c b/lib9p/srv.c index 259ef04..d5b643d 100644 --- a/lib9p/srv.c +++ b/lib9p/srv.c @@ -562,7 +562,7 @@ static void handle_Tattach(struct _lib9p_srv_req *ctx, LINUX_EOPNOTSUPP, "TODO: auth not implemented"); return; } else { - if (req->afid != LIB9P_NOFID) { + if (req->afid != LIB9P_FID_NOFID) { lib9p_error(&ctx->ctx.basectx, LINUX_EACCES, "FID provided as auth-file, but no auth-file is required"); return; |