diff options
Diffstat (limited to 'lib9p/srv.c')
-rw-r--r-- | lib9p/srv.c | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/lib9p/srv.c b/lib9p/srv.c index 3535f9a..e7fdb03 100644 --- a/lib9p/srv.c +++ b/lib9p/srv.c @@ -1,6 +1,6 @@ /* lib9p/srv.c - 9P server * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -116,9 +116,9 @@ static uint32_t rerror_overhead_for_version(enum lib9p_version version, struct lib9p_msg_Rerror empty_error = { 0 }; bool e; - e = lib9p_marshal(&empty_ctx, LIB9P_TYP_Rerror, - &empty_error, /* host_body */ - scratch); /* net_bytes */ + e = lib9p_Rmsg_marshal(&empty_ctx, LIB9P_TYP_Rerror, + &empty_error, /* host_body */ + scratch); /* net_bytes */ assert(!e); uint32_t min_msg_size = decode_u32le(scratch); @@ -162,8 +162,8 @@ 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_marshal(&req->ctx.basectx, LIB9P_TYP_Rerror, - &host, req->net_bytes); + lib9p_Rmsg_marshal(&req->ctx.basectx, LIB9P_TYP_Rerror, + &host, req->net_bytes); cr_mutex_lock(&sess->parent_conn->writelock); r = VCALL(sess->parent_conn->fd, write, @@ -369,14 +369,7 @@ static void handle_message(struct _lib9p_srv_req *ctx) { uint8_t host_resp[CONFIG_9P_MAX_HOSTMSG_SIZE]; /* Unmarshal it. */ - enum lib9p_msg_type typ = ctx->net_bytes[4]; - if (typ % 2 != 0) { - lib9p_errorf(&ctx->ctx.basectx, - LINUX_EOPNOTSUPP, "expected a T-message but got an R-message: message_type=%s", - lib9p_msg_type_str(&ctx->ctx.basectx, typ)); - goto write; - } - ssize_t host_size = lib9p_validate(&ctx->ctx.basectx, ctx->net_bytes); + ssize_t host_size = lib9p_Tmsg_validate(&ctx->ctx.basectx, ctx->net_bytes); if (host_size < 0) goto write; if ((size_t)host_size > sizeof(host_req)) { @@ -385,7 +378,8 @@ static void handle_message(struct _lib9p_srv_req *ctx) { host_size, sizeof(host_req)); goto write; } - lib9p_unmarshal(&ctx->ctx.basectx, ctx->net_bytes, + enum lib9p_msg_type typ; + lib9p_Tmsg_unmarshal(&ctx->ctx.basectx, ctx->net_bytes, &typ, host_req); /* Handle it. */ @@ -395,8 +389,8 @@ static void handle_message(struct _lib9p_srv_req *ctx) { if (lib9p_ctx_has_error(&ctx->ctx.basectx)) respond_error(ctx); else { - if (lib9p_marshal(&ctx->ctx.basectx, typ+1, host_resp, - ctx->net_bytes)) + if (lib9p_Rmsg_marshal(&ctx->ctx.basectx, typ+1, host_resp, + ctx->net_bytes)) goto write; cr_mutex_lock(&ctx->parent_sess->parent_conn->writelock); @@ -605,7 +599,7 @@ static void handle_Tattach(struct _lib9p_srv_req *ctx, &(struct lib9p_msg_Rclunk){}); return; } - lib9p_assert_stat(stat); + lib9p_stat_assert(stat); assert(stat.file_mode & LIB9P_DM_DIR); @@ -676,7 +670,7 @@ static void handle_Twalk(struct _lib9p_srv_req *ctx, util_release(&ctx->ctx, member); /* presumption of taking ref-A failed */ break; } - lib9p_assert_stat(stat); + lib9p_stat_assert(stat); isdir = stat.file_mode & LIB9P_DM_DIR; if (isdir && !util_check_perm(&ctx->ctx, &stat, 0b001)) { lib9p_error(&ctx->ctx.basectx, @@ -751,7 +745,7 @@ static void handle_Topen(struct _lib9p_srv_req *ctx, struct lib9p_stat parent_stat = VCALL(file->_parent_dir, stat, &ctx->ctx); if (lib9p_ctx_has_error(&ctx->ctx.basectx)) return; - lib9p_assert_stat(parent_stat); + lib9p_stat_assert(parent_stat); if (!util_check_perm(&ctx->ctx, &parent_stat, 0b010)) { lib9p_error(&ctx->ctx.basectx, LINUX_EACCES, "permission denied to remove-on-close"); @@ -762,7 +756,7 @@ static void handle_Topen(struct _lib9p_srv_req *ctx, struct lib9p_stat stat = VCALL(file, stat, &ctx->ctx); if (lib9p_ctx_has_error(&ctx->ctx.basectx)) return; - lib9p_assert_stat(stat); + lib9p_stat_assert(stat); if (stat.file_mode & LIB9P_QT_APPEND) reqmode = reqmode & ~LIB9P_O_TRUNC; uint8_t perm_bits = 0; @@ -851,7 +845,7 @@ static void handle_Tread(struct _lib9p_srv_req *ctx, uint32_t len = 0; for (size_t i = 0; i < num; i++) { uint32_t i_len; - lib9p_validate_stat(&ctx->ctx.basectx, req->count, &((uint8_t *)resp->data.dat)[len], &i_len, NULL); + lib9p_stat_validate(&ctx->ctx.basectx, req->count, &((uint8_t *)resp->data.dat)[len], &i_len, NULL); len += i_len; } resp->data.len = len; @@ -932,7 +926,7 @@ static void handle_Tstat(struct _lib9p_srv_req *ctx, resp->stat = VCALL(fidinfo->file, stat, &ctx->ctx); if (!lib9p_ctx_has_error(&ctx->ctx.basectx)) - lib9p_assert_stat(resp->stat); + lib9p_stat_assert(resp->stat); } static void handle_Twstat(struct _lib9p_srv_req *ctx, |