summaryrefslogtreecommitdiff
path: root/lib9p
diff options
context:
space:
mode:
Diffstat (limited to 'lib9p')
-rw-r--r--lib9p/9p.c26
-rwxr-xr-xlib9p/idl.gen29
-rw-r--r--lib9p/include/lib9p/9p.generated.h55
-rw-r--r--lib9p/include/lib9p/9p.h8
-rw-r--r--lib9p/srv.c15
5 files changed, 113 insertions, 20 deletions
diff --git a/lib9p/9p.c b/lib9p/9p.c
index ecb75fd..06f4023 100644
--- a/lib9p/9p.c
+++ b/lib9p/9p.c
@@ -146,15 +146,17 @@ void _lib9p_unmarshal(const struct _lib9p_recv_tentry xxx_table[LIB9P_VER_NUM][0
}
void lib9p_Tmsg_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes,
- enum lib9p_msg_type *ret_typ, void *ret_body) {
+ struct lib9p_Tmsg *ret) {
+ assert(ret);
_lib9p_unmarshal(_lib9p_table_Tmsg_recv,
- ctx, net_bytes, ret_typ, ret_body);
+ ctx, net_bytes, &ret->typ, &ret->body);
}
void lib9p_Rmsg_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes,
- enum lib9p_msg_type *ret_typ, void *ret_body) {
+ struct lib9p_Rmsg *ret) {
+ assert(ret);
_lib9p_unmarshal(_lib9p_table_Rmsg_recv,
- ctx, net_bytes, ret_typ, ret_body);
+ ctx, net_bytes, &ret->typ, &ret->body);
}
static
@@ -171,16 +173,20 @@ bool _lib9p_marshal(const struct _lib9p_send_tentry xxx_table[LIB9P_VER_NUM][0x8
return tentry.marshal(&subctx, body);
}
-bool lib9p_Tmsg_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body,
+bool lib9p_Tmsg_marshal(struct lib9p_ctx *ctx, struct lib9p_Tmsg *msg,
uint8_t *ret_bytes) {
- assert(typ % 2 == 0);
- return _lib9p_marshal(_lib9p_table_Tmsg_send, ctx, typ, body, ret_bytes);
+ assert(msg);
+ assert(msg->typ % 2 == 0);
+ return _lib9p_marshal(_lib9p_table_Tmsg_send, ctx, msg->typ, &msg->body,
+ ret_bytes);
}
-bool lib9p_Rmsg_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body,
+bool lib9p_Rmsg_marshal(struct lib9p_ctx *ctx, struct lib9p_Rmsg *msg,
uint8_t *ret_bytes) {
- assert(typ % 2 == 1);
- return _lib9p_marshal(_lib9p_table_Rmsg_send, ctx, typ, body, ret_bytes);
+ assert(msg);
+ assert(msg->typ % 2 == 1);
+ return _lib9p_marshal(_lib9p_table_Rmsg_send, ctx, msg->typ, &msg->body,
+ ret_bytes);
}
/* `struct lib9p_stat` helpers ************************************************/
diff --git a/lib9p/idl.gen b/lib9p/idl.gen
index e796855..3271bb4 100755
--- a/lib9p/idl.gen
+++ b/lib9p/idl.gen
@@ -266,6 +266,35 @@ enum {idprefix}version {{
ret += "};\n"
ret += ifdef_pop(0)
+ ret += """
+/* container types ************************************************************/
+"""
+ ret += "\n"
+ ret += f"struct {idprefix}Tmsg {{\n"
+ ret += f"\tenum {idprefix}msg_type typ;\n"
+ ret += "\tunion {\n"
+ msgs = [msg for msg in typs if isinstance(msg, idl.Message) and msg.msgid % 2 == 0]
+ typewidth = max(len(c_typename(msg)) for msg in msgs)
+ for msg in msgs:
+ ret += ifdef_push(1, c_ver_ifdef(msg.in_versions))
+ ret += f"\t\t{c_typename(msg).ljust(typewidth)} {msg.name};\n"
+ ret += ifdef_pop(0)
+ ret += "\t} body;\n"
+ ret += "};\n"
+
+ ret += "\n"
+ ret += f"struct {idprefix}Rmsg {{\n"
+ ret += f"\tenum {idprefix}msg_type typ;\n"
+ ret += "\tunion {\n"
+ msgs = [msg for msg in typs if isinstance(msg, idl.Message) and msg.msgid % 2 == 1]
+ typewidth = max(len(c_typename(msg)) for msg in msgs)
+ for msg in msgs:
+ ret += ifdef_push(1, c_ver_ifdef(msg.in_versions))
+ ret += f"\t\t{c_typename(msg).ljust(typewidth)} {msg.name};\n"
+ ret += ifdef_pop(0)
+ ret += "\t} body;\n"
+ ret += "};\n"
+
return ret
diff --git a/lib9p/include/lib9p/9p.generated.h b/lib9p/include/lib9p/9p.generated.h
index a6dc13c..db43d82 100644
--- a/lib9p/include/lib9p/9p.generated.h
+++ b/lib9p/include/lib9p/9p.generated.h
@@ -397,3 +397,58 @@ struct lib9p_msg_Rswrite {
uint32_t count;
};
#endif /* CONFIG_9P_ENABLE_9P2000_e */
+
+/* container types ************************************************************/
+
+struct lib9p_Tmsg {
+ enum lib9p_msg_type typ;
+ union {
+#if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u
+ struct lib9p_msg_Tversion Tversion;
+ struct lib9p_msg_Tauth Tauth;
+ struct lib9p_msg_Tattach Tattach;
+ struct lib9p_msg_Tflush Tflush;
+ struct lib9p_msg_Twalk Twalk;
+ struct lib9p_msg_Topen Topen;
+ struct lib9p_msg_Tcreate Tcreate;
+ struct lib9p_msg_Tread Tread;
+ struct lib9p_msg_Twrite Twrite;
+ struct lib9p_msg_Tclunk Tclunk;
+ struct lib9p_msg_Tremove Tremove;
+ struct lib9p_msg_Tstat Tstat;
+ struct lib9p_msg_Twstat Twstat;
+#endif /* CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u */
+#if CONFIG_9P_ENABLE_9P2000_e
+ struct lib9p_msg_Tsession Tsession;
+ struct lib9p_msg_Tsread Tsread;
+ struct lib9p_msg_Tswrite Tswrite;
+#endif /* CONFIG_9P_ENABLE_9P2000_e */
+ } body;
+};
+
+struct lib9p_Rmsg {
+ enum lib9p_msg_type typ;
+ union {
+#if CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u
+ struct lib9p_msg_Rversion Rversion;
+ struct lib9p_msg_Rauth Rauth;
+ struct lib9p_msg_Rattach Rattach;
+ struct lib9p_msg_Rerror Rerror;
+ struct lib9p_msg_Rflush Rflush;
+ struct lib9p_msg_Rwalk Rwalk;
+ struct lib9p_msg_Ropen Ropen;
+ struct lib9p_msg_Rcreate Rcreate;
+ struct lib9p_msg_Rread Rread;
+ struct lib9p_msg_Rwrite Rwrite;
+ struct lib9p_msg_Rclunk Rclunk;
+ struct lib9p_msg_Rremove Rremove;
+ struct lib9p_msg_Rstat Rstat;
+ struct lib9p_msg_Rwstat Rwstat;
+#endif /* CONFIG_9P_ENABLE_9P2000 || CONFIG_9P_ENABLE_9P2000_e || CONFIG_9P_ENABLE_9P2000_u */
+#if CONFIG_9P_ENABLE_9P2000_e
+ struct lib9p_msg_Rsession Rsession;
+ struct lib9p_msg_Rsread Rsread;
+ struct lib9p_msg_Rswrite Rswrite;
+#endif /* CONFIG_9P_ENABLE_9P2000_e */
+ } body;
+};
diff --git a/lib9p/include/lib9p/9p.h b/lib9p/include/lib9p/9p.h
index 72a8292..adb7553 100644
--- a/lib9p/include/lib9p/9p.h
+++ b/lib9p/include/lib9p/9p.h
@@ -93,7 +93,7 @@ ssize_t lib9p_Tmsg_validate(struct lib9p_ctx *ctx, uint8_t *net_bytes);
* @return ret_body : the message body, must be at least lib9p_Tmsg_validate() bytes
*/
void lib9p_Tmsg_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes,
- enum lib9p_msg_type *ret_typ, void *ret_body);
+ struct lib9p_Tmsg *ret);
/**
* Marshal a `struct lib9p_msg_{typ}` structure into a byte-array.
@@ -113,7 +113,7 @@ void lib9p_Tmsg_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes,
*
* @errno LINUX_ERANGE: reply does not fit in ctx->max_msg_size
*/
-bool lib9p_Tmsg_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body,
+bool lib9p_Tmsg_marshal(struct lib9p_ctx *ctx, struct lib9p_Tmsg *msg,
uint8_t *ret_bytes);
/* main R-message functions ***************************************************/
@@ -122,8 +122,8 @@ bool lib9p_Tmsg_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *bo
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,
+ struct lib9p_Rmsg *ret);
+bool lib9p_Rmsg_marshal(struct lib9p_ctx *ctx, struct lib9p_Rmsg *msg,
uint8_t *ret_bytes);
diff --git a/lib9p/srv.c b/lib9p/srv.c
index e7fdb03..fb74319 100644
--- a/lib9p/srv.c
+++ b/lib9p/srv.c
@@ -113,12 +113,13 @@ static uint32_t rerror_overhead_for_version(enum lib9p_version version,
.version = version,
.max_msg_size = CONFIG_9P_MAX_MSG_SIZE,
};
- struct lib9p_msg_Rerror empty_error = { 0 };
bool e;
- e = lib9p_Rmsg_marshal(&empty_ctx, LIB9P_TYP_Rerror,
- &empty_error, /* host_body */
- scratch); /* net_bytes */
+ e = lib9p_Rmsg_marshal(&empty_ctx,
+ &(struct lib9p_Rmsg){
+ .typ = LIB9P_TYP_Rerror,
+ },
+ scratch);
assert(!e);
uint32_t min_msg_size = decode_u32le(scratch);
@@ -162,8 +163,10 @@ 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_Rmsg_marshal(&req->ctx.basectx, LIB9P_TYP_Rerror,
- &host, req->net_bytes);
+ lib9p_Rmsg_marshal(&req->ctx.basectx, &(struct lib9p_Rmsg){
+ .typ = LIB9P_TYP_Rerror,
+ .body = host,
+ }, req->net_bytes);
cr_mutex_lock(&sess->parent_conn->writelock);
r = VCALL(sess->parent_conn->fd, write,