summaryrefslogtreecommitdiff
path: root/lib9p
diff options
context:
space:
mode:
Diffstat (limited to 'lib9p')
-rw-r--r--lib9p/9p.c32
-rw-r--r--lib9p/internal.h6
2 files changed, 29 insertions, 9 deletions
diff --git a/lib9p/9p.c b/lib9p/9p.c
index 51ff2eb..c54dae7 100644
--- a/lib9p/9p.c
+++ b/lib9p/9p.c
@@ -124,10 +124,12 @@ ssize_t _lib9p_validate(uint8_t xxx_low_typ_bit,
struct lib9p_ctx *ctx, uint8_t *net_bytes) {
/* Inspect the first 5 bytes ourselves. */
struct _validate_ctx subctx = {
+ /* input */
.ctx = ctx,
.net_size = uint32le_decode(net_bytes),
.net_bytes = net_bytes,
+ /* output */
.net_offset = 0,
.host_extra = 0,
};
@@ -171,17 +173,19 @@ static
void _lib9p_unmarshal(const struct _lib9p_recv_tentry xxx_table[LIB9P_VER_NUM][0x80],
struct lib9p_ctx *ctx, uint8_t *net_bytes,
enum lib9p_msg_type *ret_typ, void *ret_body) {
+ enum lib9p_msg_type typ = net_bytes[4];
+ *ret_typ = typ;
+ struct _lib9p_recv_tentry tentry = xxx_table[ctx->version][typ/2];
+
struct _unmarshal_ctx subctx = {
+ /* input */
.ctx = ctx,
.net_bytes = net_bytes,
+ /* output */
.net_offset = 0,
+ .extra = ret_body + tentry.basesize,
};
-
- enum lib9p_msg_type typ = net_bytes[4];
- *ret_typ = typ;
- struct _lib9p_recv_tentry tentry = xxx_table[ctx->version][typ/2];
- subctx.extra = ret_body + tentry.basesize;
tentry.unmarshal(&subctx, ret_body);
}
@@ -202,7 +206,10 @@ bool _lib9p_marshal(const struct _lib9p_send_tentry xxx_table[LIB9P_VER_NUM][0x8
struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *body,
uint8_t *ret_bytes) {
struct _marshal_ctx subctx = {
+ /* input */
.ctx = ctx,
+
+ /* ouptut */
.net_bytes = ret_bytes,
.net_offset = 0,
};
@@ -228,10 +235,12 @@ bool lib9p_Rmsg_marshal(struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void *bo
bool lib9p_stat_validate(struct lib9p_ctx *ctx, uint32_t net_size, uint8_t *net_bytes,
uint32_t *ret_net_size, ssize_t *ret_host_size) {
struct _validate_ctx subctx = {
+ /* input */
.ctx = ctx,
.net_size = net_size,
.net_bytes = net_bytes,
+ /* output */
.net_offset = 0,
.host_extra = 0,
};
@@ -248,11 +257,13 @@ bool lib9p_stat_validate(struct lib9p_ctx *ctx, uint32_t net_size, uint8_t *net_
uint32_t lib9p_stat_unmarshal(struct lib9p_ctx *ctx, uint8_t *net_bytes,
struct lib9p_stat *ret_obj, void *ret_extra) {
struct _unmarshal_ctx subctx = {
- .ctx = ctx,
- .net_bytes = net_bytes,
- .net_offset = 0,
+ /* input */
+ .ctx = ctx,
+ .net_bytes = net_bytes,
- .extra = ret_extra,
+ /* output */
+ .net_offset = 0,
+ .extra = ret_extra,
};
_lib9p_stat_unmarshal(&subctx, ret_obj);
return subctx.net_offset;
@@ -263,7 +274,10 @@ uint32_t lib9p_stat_marshal(struct lib9p_ctx *ctx, uint32_t max_net_size, struct
struct lib9p_ctx _ctx = *ctx;
_ctx.max_msg_size = max_net_size;
struct _marshal_ctx subctx = {
+ /* input */
.ctx = &_ctx,
+
+ /* output */
.net_bytes = ret_bytes,
.net_offset = 0,
};
diff --git a/lib9p/internal.h b/lib9p/internal.h
index d939d46..a648532 100644
--- a/lib9p/internal.h
+++ b/lib9p/internal.h
@@ -39,10 +39,12 @@ static_assert(CONFIG_9P_MAX_HOSTMSG_SIZE <= SSIZE_MAX);
/* specialized contexts *******************************************************/
struct _validate_ctx {
+ /* input */
struct lib9p_ctx *ctx;
uint32_t net_size;
uint8_t *net_bytes;
+ /* output */
uint32_t net_offset;
/* Increment `host_extra` to pre-allocate space that is
* "extra" beyond sizeof(). */
@@ -51,9 +53,11 @@ struct _validate_ctx {
typedef bool (*_validate_fn_t)(struct _validate_ctx *ctx);
struct _unmarshal_ctx {
+ /* input */
struct lib9p_ctx *ctx;
uint8_t *net_bytes;
+ /* output */
uint32_t net_offset;
/* `extra` points to the beginning of unallocated space. */
void *extra;
@@ -61,8 +65,10 @@ struct _unmarshal_ctx {
typedef void (*_unmarshal_fn_t)(struct _unmarshal_ctx *ctx, void *out);
struct _marshal_ctx {
+ /* input */
struct lib9p_ctx *ctx;
+ /* output */
uint8_t *net_bytes;
uint32_t net_offset;
};