summaryrefslogtreecommitdiff
path: root/lib9p/srv.c
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-04 17:28:54 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-04 17:28:54 -0600
commit2fe787ba4db420f5b08573d77e35cfaa0d7a0793 (patch)
treeb9c1264b56d713a6df9b029606f87d824f3a3d20 /lib9p/srv.c
parentb683e779ef83b88f6ffc503a1d1a4f3ec25a5cfa (diff)
wip srv
Diffstat (limited to 'lib9p/srv.c')
-rw-r--r--lib9p/srv.c134
1 files changed, 104 insertions, 30 deletions
diff --git a/lib9p/srv.c b/lib9p/srv.c
index 1510a4a..0f9466c 100644
--- a/lib9p/srv.c
+++ b/lib9p/srv.c
@@ -8,7 +8,6 @@
#include <libcr_ipc/mutex.h>
#include <libnetio/netio.h>
-#include <lib9p/9p.h>
#include <lib9p/srv.h>
#include "internal.h"
@@ -55,7 +54,7 @@ struct lib9p_req {
uint16_t tag;
/* mutable */
uint8_t *net_bytes; /* CONFIG_9P_MAX_MSG_SIZE-sized */
- struct lib9p_reqctx ctx;
+ struct lib9p_ctx ctx;
};
/* base utilities *************************************************************/
@@ -85,7 +84,7 @@ static void respond_error(struct lib9p_req *req) {
struct lib9p_msg_Rerror host = {
.ename = {
.len = strnlen(req->ctx.err_msg, CONFIG_9P_MAX_ERR_SIZE),
- .utf8 = (uint8_t*)req->ctx.err_msg,
+ .utf8 = req->ctx.err_msg,
},
.errno = req->ctx.err_num,
};
@@ -204,6 +203,19 @@ COROUTINE lib9p_srv_read_cr(void *_srv) {
static void handle_Tversion(struct lib9p_req *ctx, struct lib9p_msg_Tversion *req, struct lib9p_msg_Rversion *resp);
static void handle_Tauth(struct lib9p_req *ctx, struct lib9p_msg_Tauth *req, struct lib9p_msg_Rauth *resp);
static void handle_Tattach(struct lib9p_req *ctx, struct lib9p_msg_Tattach *req, struct lib9p_msg_Rattach *resp);
+static void handle_Tflush(struct lib9p_req *ctx, struct lib9p_msg_Tflush *req, struct lib9p_msg_Rflush *resp);
+static void handle_Twalk(struct lib9p_req *ctx, struct lib9p_msg_Twalk *req, struct lib9p_msg_Rwalk *resp);
+static void handle_Topen(struct lib9p_req *ctx, struct lib9p_msg_Topen *req, struct lib9p_msg_Ropen *resp);
+static void handle_Tcreate(struct lib9p_req *ctx, struct lib9p_msg_Tcreate *req, struct lib9p_msg_Rcreate *resp);
+static void handle_Tread(struct lib9p_req *ctx, struct lib9p_msg_Tread *req, struct lib9p_msg_Rread *resp);
+static void handle_Twrite(struct lib9p_req *ctx, struct lib9p_msg_Twrite *req, struct lib9p_msg_Rwrite *resp);
+static void handle_Tclunk(struct lib9p_req *ctx, struct lib9p_msg_Tclunk *req, struct lib9p_msg_Rclunk *resp);
+static void handle_Tremove(struct lib9p_req *ctx, struct lib9p_msg_Tremove *req, struct lib9p_msg_Rremove *resp);
+static void handle_Tstat(struct lib9p_req *ctx, struct lib9p_msg_Tstat *req, struct lib9p_msg_Rstat *resp);
+static void handle_Twstat(struct lib9p_req *ctx, struct lib9p_msg_Twstat *req, struct lib9p_msg_Rwstat *resp);
+static void handle_Tsession(struct lib9p_req *ctx, struct lib9p_msg_Tsession *req, struct lib9p_msg_Rsession *resp);
+static void handle_Tsread(struct lib9p_req *ctx, struct lib9p_msg_Tsread *req, struct lib9p_msg_Rsread *resp);
+static void handle_Tswrite(struct lib9p_req *ctx, struct lib9p_msg_Tswrite *req, struct lib9p_msg_Rswrite *resp);
COROUTINE lib9p_srv_write_cr(void *_srv) {
uint8_t net[CONFIG_9P_MAX_MSG_SIZE];
@@ -247,49 +259,49 @@ COROUTINE lib9p_srv_write_cr(void *_srv) {
handle_Tversion(&req, (struct lib9p_msg_Tversion *)host_req, (struct lib9p_msg_Rversion *)host_resp);
break;
case LIB9P_TYP_Tauth:
- lib9p_errorf(&req.ctx, LINUX_EOPNOTSUPP, "%s not yet implemented", lib9p_msg_type_str(typ));
+ handle_Tauth(&req, (struct lib9p_msg_Tauth *)host_req, (struct lib9p_msg_Rauth *)host_resp);
break;
case LIB9P_TYP_Tattach:
- lib9p_errorf(&req.ctx, LINUX_EOPNOTSUPP, "%s not yet implemented", lib9p_msg_type_str(typ));
+ handle_Tattach(&req, (struct lib9p_msg_Tattach *)host_req, (struct lib9p_msg_Rattach *)host_resp);
break;
case LIB9P_TYP_Tflush:
- lib9p_errorf(&req.ctx, LINUX_EOPNOTSUPP, "%s not yet implemented", lib9p_msg_type_str(typ));
+ handle_Tflush(&req, (struct lib9p_msg_Tflush *)host_req, (struct lib9p_msg_Rflush *)host_resp);
break;
case LIB9P_TYP_Twalk:
- lib9p_errorf(&req.ctx, LINUX_EOPNOTSUPP, "%s not yet implemented", lib9p_msg_type_str(typ));
+ handle_Twalk(&req, (struct lib9p_msg_Twalk *)host_req, (struct lib9p_msg_Rwalk *)host_resp);
break;
case LIB9P_TYP_Topen:
- lib9p_errorf(&req.ctx, LINUX_EOPNOTSUPP, "%s not yet implemented", lib9p_msg_type_str(typ));
+ handle_Topen(&req, (struct lib9p_msg_Topen *)host_req, (struct lib9p_msg_Ropen *)host_resp);
break;
case LIB9P_TYP_Tcreate:
- lib9p_errorf(&req.ctx, LINUX_EOPNOTSUPP, "%s not yet implemented", lib9p_msg_type_str(typ));
+ handle_Tcreate(&req, (struct lib9p_msg_Tcreate *)host_req, (struct lib9p_msg_Rcreate *)host_resp);
break;
case LIB9P_TYP_Tread:
- lib9p_errorf(&req.ctx, LINUX_EOPNOTSUPP, "%s not yet implemented", lib9p_msg_type_str(typ));
+ handle_Tread(&req, (struct lib9p_msg_Tread *)host_req, (struct lib9p_msg_Rread *)host_resp);
break;
case LIB9P_TYP_Twrite:
- lib9p_errorf(&req.ctx, LINUX_EOPNOTSUPP, "%s not yet implemented", lib9p_msg_type_str(typ));
+ handle_Twrite(&req, (struct lib9p_msg_Twrite *)host_req, (struct lib9p_msg_Rwrite *)host_resp);
break;
case LIB9P_TYP_Tclunk:
- lib9p_errorf(&req.ctx, LINUX_EOPNOTSUPP, "%s not yet implemented", lib9p_msg_type_str(typ));
+ handle_Tclunk(&req, (struct lib9p_msg_Tclunk *)host_req, (struct lib9p_msg_Rclunk *)host_resp);
break;
case LIB9P_TYP_Tremove:
- lib9p_errorf(&req.ctx, LINUX_EOPNOTSUPP, "%s not yet implemented", lib9p_msg_type_str(typ));
+ handle_Tremove(&req, (struct lib9p_msg_Tremove *)host_req, (struct lib9p_msg_Rremove *)host_resp);
break;
case LIB9P_TYP_Tstat:
- lib9p_errorf(&req.ctx, LINUX_EOPNOTSUPP, "%s not yet implemented", lib9p_msg_type_str(typ));
+ handle_Tstat(&req, (struct lib9p_msg_Tstat *)host_req, (struct lib9p_msg_Rstat *)host_resp);
break;
case LIB9P_TYP_Twstat:
- lib9p_errorf(&req.ctx, LINUX_EOPNOTSUPP, "%s not yet implemented", lib9p_msg_type_str(typ));
+ handle_Twstat(&req, (struct lib9p_msg_Twstat *)host_req, (struct lib9p_msg_Rwstat *)host_resp);
break;
case LIB9P_TYP_Tsession: /* 9P2000.e */
- lib9p_errorf(&req.ctx, LINUX_EOPNOTSUPP, "%s not yet implemented", lib9p_msg_type_str(typ));
+ handle_Tsession(&req, (struct lib9p_msg_Tsession *)host_req, (struct lib9p_msg_Rsession *)host_resp);
break;
case LIB9P_TYP_Tsread: /* 9P2000.e */
- lib9p_errorf(&req.ctx, LINUX_EOPNOTSUPP, "%s not yet implemented", lib9p_msg_type_str(typ));
+ handle_Tsread(&req, (struct lib9p_msg_Tsread *)host_req, (struct lib9p_msg_Rsread *)host_resp);
break;
case LIB9P_TYP_Tswrite: /* 9P2000.e */
- lib9p_errorf(&req.ctx, LINUX_EOPNOTSUPP, "%s not yet implemented", lib9p_msg_type_str(typ));
+ handle_Tswrite(&req, (struct lib9p_msg_Tswrite *)host_req, (struct lib9p_msg_Rswrite *)host_resp);
break;
default:
assert(false);
@@ -338,27 +350,37 @@ static void handle_Tversion(struct lib9p_req *ctx, struct lib9p_msg_Tversion *re
return;
}
- resp->version.utf8 = (uint8_t *)lib9p_version_str(version);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
+ resp->version.utf8 = lib9p_version_str(version);
+#pragma GCC diagnostic pop
resp->version.len = strlen((char *)resp->version.utf8);
resp->max_msg_size = (CONFIG_9P_MAX_MSG_SIZE < req->max_msg_size)
? CONFIG_9P_MAX_MSG_SIZE
: req->max_msg_size;
}
-static void handle_Tauth(struct lib9p_req *ctx, struct lib9p_msg_Tauth *UNUSED(req), struct lib9p_msg_Rauth *UNUSED(resp)) {
+static void handle_Tauth(struct lib9p_req *ctx, struct lib9p_msg_Tauth *req, struct lib9p_msg_Rauth *UNUSED(resp)) {
if (!ctx->parent_sess->parent_conn->parent_srv->auth) {
lib9p_error(&ctx->ctx, LINUX_EOPNOTSUPP, "authentication not required");
return;
}
- ctx->ctx.uid = req->uid;
- ctx->ctx.uname = req->uname.utf8;
+ struct lib9p_srv_reqctx subctx = {
+ .base = &ctx->ctx,
+ .uid = req->n_uname,
+ .uname = req->uname.utf8,
+ };
+ ctx->parent_sess->parent_conn->parent_srv->auth(&subctx, req->aname.utf8);
lib9p_error(&ctx->ctx, LINUX_EOPNOTSUPP, "TODO: auth not implemented");
return;
}
-static void handle_Tattach(struct lib9p_req *ctx, struct lib9p_msg_Tattach *req, struct lib9p_msg_Rattach *resp) {
- ctx->ctx.uid = req->uid;
- ctx->ctx.uname = req->uname.utf8;
+static void handle_Tattach(struct lib9p_req *ctx, struct lib9p_msg_Tattach *req, struct lib9p_msg_Rattach *UNUSED(resp)) {
+ struct lib9p_srv_reqctx subctx = {
+ .base = &ctx->ctx,
+ .uid = req->n_uname,
+ .uname = req->uname.utf8,
+ };
if (ctx->parent_sess->parent_conn->parent_srv->auth) {
/*
struct lib9p_srv_filehandle *fh = fidmap_get(req->afid);
@@ -392,18 +414,70 @@ static void handle_Tattach(struct lib9p_req *ctx, struct lib9p_msg_Tattach *req,
return;
}
- struct lib9p_srv_file rootdir = ctx->parent_sess->parent_conn->parent_srv->rootdir(&ctx->ctx, req->aname.utf8);
- if (lib9p_ctx_has_error(&ctx->ctx.ctx))
+ struct lib9p_srv_file rootdir = ctx->parent_sess->parent_conn->parent_srv->rootdir(&subctx, req->aname.utf8);
+ if (lib9p_ctx_has_error(&ctx->ctx))
return;
struct lib9p_srv_file *rootdir_ptr = fidmap_store(&ctx->parent_sess->fids, req->fid, rootdir);
if (!rootdir_ptr) {
lib9p_error(&ctx->ctx, LINUX_EMFILE, "too many open files");
- if (rootdir.free)
- rootdir.free(ctx, rootdir.impldata);
+ if (rootdir.vtable.free)
+ rootdir.vtable.free(&subctx, rootdir.impldata);
return;
}
- resp->qid = rootdir.qid;
+ //resp->qid = rootdir.qid;
return;
}
+
+static void handle_Tflush(struct lib9p_req *ctx, struct lib9p_msg_Tflush *UNUSED(req), struct lib9p_msg_Rflush *UNUSED(resp)) {
+ lib9p_error(&ctx->ctx, LINUX_EOPNOTSUPP, "flush not yet implemented");
+}
+
+static void handle_Twalk(struct lib9p_req *ctx, struct lib9p_msg_Twalk *UNUSED(req), struct lib9p_msg_Rwalk *UNUSED(resp)) {
+ lib9p_error(&ctx->ctx, LINUX_EOPNOTSUPP, "walk not yet implemented");
+}
+
+static void handle_Topen(struct lib9p_req *ctx, struct lib9p_msg_Topen *UNUSED(req), struct lib9p_msg_Ropen *UNUSED(resp)) {
+ lib9p_error(&ctx->ctx, LINUX_EOPNOTSUPP, "open not yet implemented");
+}
+
+static void handle_Tcreate(struct lib9p_req *ctx, struct lib9p_msg_Tcreate *UNUSED(req), struct lib9p_msg_Rcreate *UNUSED(resp)) {
+ lib9p_error(&ctx->ctx, LINUX_EOPNOTSUPP, "create not yet implemented");
+}
+
+static void handle_Tread(struct lib9p_req *ctx, struct lib9p_msg_Tread *UNUSED(req), struct lib9p_msg_Rread *UNUSED(resp)) {
+ lib9p_error(&ctx->ctx, LINUX_EOPNOTSUPP, "read not yet implemented");
+}
+
+static void handle_Twrite(struct lib9p_req *ctx, struct lib9p_msg_Twrite *UNUSED(req), struct lib9p_msg_Rwrite *UNUSED(resp)) {
+ lib9p_error(&ctx->ctx, LINUX_EOPNOTSUPP, "write not yet implemented");
+}
+
+static void handle_Tclunk(struct lib9p_req *ctx, struct lib9p_msg_Tclunk *UNUSED(req), struct lib9p_msg_Rclunk *UNUSED(resp)) {
+ lib9p_error(&ctx->ctx, LINUX_EOPNOTSUPP, "clunk not yet implemented");
+}
+
+static void handle_Tremove(struct lib9p_req *ctx, struct lib9p_msg_Tremove *UNUSED(req), struct lib9p_msg_Rremove *UNUSED(resp)) {
+ lib9p_error(&ctx->ctx, LINUX_EOPNOTSUPP, "remove not yet implemented");
+}
+
+static void handle_Tstat(struct lib9p_req *ctx, struct lib9p_msg_Tstat *UNUSED(req), struct lib9p_msg_Rstat *UNUSED(resp)) {
+ lib9p_error(&ctx->ctx, LINUX_EOPNOTSUPP, "stat not yet implemented");
+}
+
+static void handle_Twstat(struct lib9p_req *ctx, struct lib9p_msg_Twstat *UNUSED(req), struct lib9p_msg_Rwstat *UNUSED(resp)) {
+ lib9p_error(&ctx->ctx, LINUX_EOPNOTSUPP, "wstat not yet implemented");
+}
+
+static void handle_Tsession(struct lib9p_req *ctx, struct lib9p_msg_Tsession *UNUSED(req), struct lib9p_msg_Rsession *UNUSED(resp)) {
+ lib9p_error(&ctx->ctx, LINUX_EOPNOTSUPP, "session not yet implemented");
+}
+
+static void handle_Tsread(struct lib9p_req *ctx, struct lib9p_msg_Tsread *UNUSED(req), struct lib9p_msg_Rsread *UNUSED(resp)) {
+ lib9p_error(&ctx->ctx, LINUX_EOPNOTSUPP, "sread not yet implemented");
+}
+
+static void handle_Tswrite(struct lib9p_req *ctx, struct lib9p_msg_Tswrite *UNUSED(req), struct lib9p_msg_Rswrite *UNUSED(resp)) {
+ lib9p_error(&ctx->ctx, LINUX_EOPNOTSUPP, "swrite not yet implemented");
+}