summaryrefslogtreecommitdiff
path: root/lib9p
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-02 12:44:41 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-02 12:44:41 -0600
commit50cfe77ace4caa424352a163f90bbf7a684b60d6 (patch)
treeeec52aca00a7dada9335cef9f3f6555b4039c851 /lib9p
parentada828fc3eaf9891e1bbb6503106d36ef53b6c8a (diff)
more bitfield
Diffstat (limited to 'lib9p')
-rw-r--r--lib9p/9P2000.txt8
-rw-r--r--lib9p/9P2000.u.txt2
-rw-r--r--lib9p/include/lib9p/_types.h19
-rw-r--r--lib9p/types.c6
-rwxr-xr-xlib9p/types.gen13
5 files changed, 37 insertions, 11 deletions
diff --git a/lib9p/9P2000.txt b/lib9p/9P2000.txt
index 3f1f10a..d90175b 100644
--- a/lib9p/9P2000.txt
+++ b/lib9p/9P2000.txt
@@ -30,7 +30,8 @@ d = "len[4] len*(dat[1])"
# string (u16le `n`, then `n` bytes of UTF-8)
s = "len[2] len*(utf8[1])"
-bitfield qid_type 8
+# QID Type (see qid below)
+bitfield qt 8
7/DIR
6/APPEND
5/EXCL
@@ -46,6 +47,9 @@ bitfield qid_type 8
# Plan 9, in 2003-12.
2/TMP
#1/unused
+
+ # "The name QTFILE, defined to be zero, identifies the value
+ # of the type for a plain file."
FILE=0
# uniQue IDentification - "two files on the same server hierarchy are
@@ -62,7 +66,7 @@ bitfield qid_type 8
#
# - "type" indicates "whether the file is a directory, append-only
# file, etc."; is an instance of the qid_type bitfield.
-qid = "type[qid_type] vers[4] path[8]"
+qid = "type[qt] vers[4] path[8]"
# stat (TODO)
stat = "stat_size[2]"
diff --git a/lib9p/9P2000.u.txt b/lib9p/9P2000.u.txt
index a1dbcfb..29fd2d8 100644
--- a/lib9p/9P2000.u.txt
+++ b/lib9p/9P2000.u.txt
@@ -19,7 +19,7 @@ Tauth += "n_uname[4]"
Rerror += "errno[4]"
-qid_type += 1/SYMLINK
+qt += 1/SYMLINK
# DMDIR = 1<<31
# DMAPPEND = 1<<30
diff --git a/lib9p/include/lib9p/_types.h b/lib9p/include/lib9p/_types.h
index cd1ded5..b904318 100644
--- a/lib9p/include/lib9p/_types.h
+++ b/lib9p/include/lib9p/_types.h
@@ -17,7 +17,18 @@ enum lib9p_version {
const char *lib9p_version_str(enum lib9p_version);
-/* non-message structs ********************************************************/
+/* non-message types **********************************************************/
+
+typedef uint8_t lib9p_qt_t;
+#define LIB9P_QT_DIR ((lib9p_qt_t)(1<<7))
+#define LIB9P_QT_APPEND ((lib9p_qt_t)(1<<6))
+#define LIB9P_QT_EXCL ((lib9p_qt_t)(1<<5))
+#define LIB9P_QT__PLAN9_MOUNT ((lib9p_qt_t)(1<<4))
+#define LIB9P_QT_AUTH ((lib9p_qt_t)(1<<3))
+#define LIB9P_QT_TMP ((lib9p_qt_t)(1<<2))
+#define LIB9P_QT_SYMLINK ((lib9p_qt_t)(1<<1))
+#define LIB9P_QT__UNUSED_0 ((lib9p_qt_t)(1<<0))
+#define LIB9P_QT_FILE ((lib9p_qt_t)(0))
struct lib9p_d {
uint32_t len;
@@ -30,9 +41,9 @@ struct lib9p_s {
};
struct lib9p_qid {
- lib9p_qid_type_t type;
- uint32_t vers;
- uint64_t path;
+ lib9p_qt_t type;
+ uint32_t vers;
+ uint64_t path;
};
struct lib9p_stat {
diff --git a/lib9p/types.c b/lib9p/types.c
index 4854ed4..c4812d1 100644
--- a/lib9p/types.c
+++ b/lib9p/types.c
@@ -344,7 +344,7 @@ static ALWAYS_INLINE bool checksize_s(struct _checksize_ctx *ctx) {
}
static ALWAYS_INLINE bool checksize_qid(struct _checksize_ctx *ctx) {
- return checksize_qid_type(ctx)
+ return checksize_qt(ctx)
|| checksize_4(ctx)
|| checksize_8(ctx);
}
@@ -571,7 +571,7 @@ static ALWAYS_INLINE void unmarshal_s(struct _unmarshal_ctx *ctx, struct lib9p_s
static ALWAYS_INLINE void unmarshal_qid(struct _unmarshal_ctx *ctx, struct lib9p_qid *out) {
memset(out, 0, sizeof(*out));
- unmarshal_qid_type(ctx, &out->type);
+ unmarshal_qt(ctx, &out->type);
unmarshal_4(ctx, &out->vers);
unmarshal_8(ctx, &out->path);
}
@@ -860,7 +860,7 @@ static ALWAYS_INLINE bool marshal_s(struct _marshal_ctx *ctx, struct lib9p_s *va
}
static ALWAYS_INLINE bool marshal_qid(struct _marshal_ctx *ctx, struct lib9p_qid *val) {
- return marshal_qid_type(ctx, &val->type)
+ return marshal_qt(ctx, &val->type)
|| marshal_4(ctx, &val->vers)
|| marshal_8(ctx, &val->path);
}
diff --git a/lib9p/types.gen b/lib9p/types.gen
index 1a2d45a..7d74558 100755
--- a/lib9p/types.gen
+++ b/lib9p/types.gen
@@ -343,8 +343,19 @@ enum {idprefix}version {{
ret += f"const char *{idprefix}version_str(enum {idprefix}version);\n"
ret += """
-/* non-message structs ********************************************************/
+/* non-message types **********************************************************/
"""
+ for bf in just_bitfields(typs):
+ ret += "\n"
+ ret += f"typedef uint{bf.static_size*8}_t {c_typename(idprefix, bf)};\n"
+ vals = dict([
+ *reversed([((k or f"_UNUSED_{v}"), f"1<<{v}") for (v, k) in enumerate(bf.bits)]),
+ *[(k, v) for (k, v) in bf.aliases.items() if v],
+ ])
+ namewidth = max(len(name) for name in vals)
+ for name, val in vals.items():
+ ret += f"#define {idprefix.upper()}{bf.name.upper()}_{name.ljust(namewidth)} (({c_typename(idprefix, bf)})({val}))\n"
+
for struct in just_structs_nonmsg(typs):
all_the_same = len(struct.members) == 0 or all(
m.ver == struct.members[0].ver for m in struct.members