From 74537d36cd9a32817d18163cccdb60f88b024950 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Fri, 11 Oct 2024 13:11:27 -0600 Subject: lib9p: Implement Twrite --- lib9p/srv.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'lib9p') diff --git a/lib9p/srv.c b/lib9p/srv.c index a931106..610debf 100644 --- a/lib9p/srv.c +++ b/lib9p/srv.c @@ -718,6 +718,7 @@ static void handle_Topen(struct _lib9p_srv_req *ctx, } } + /* Variables. */ lib9p_o_t reqmode = req->mode; uint8_t fidflags = fidinfo->flags; struct lib9p_srv_file *file = fidinfo->file; @@ -801,9 +802,11 @@ static void handle_Tread(struct _lib9p_srv_req *ctx, return; } + /* Variables. */ struct lib9p_srv_file *file = fidinfo->file; resp->data.dat = (char *)(&resp[1]); + /* Do it. */ if (fidinfo->flags & FIDFLAG_ISDIR) { size_t idx; if (req->offset == 0) @@ -835,8 +838,24 @@ static void handle_Twrite(struct _lib9p_srv_req *ctx, struct lib9p_msg_Rwrite *resp) { handler_common(ctx, req, resp); - lib9p_error(&ctx->ctx.basectx, - LINUX_EOPNOTSUPP, "write not yet implemented"); + /* Check that the FID is valid for this. */ + struct _srv_fidinfo *fidinfo = fidmap_load(&ctx->parent_sess->fids, req->fid); + if (!fidinfo) { + lib9p_errorf(&ctx->ctx.basectx, + LINUX_EBADF, "bad file number %"PRIu32, req->fid); + return; + } + if (!(fidinfo->flags & FIDFLAG_OPEN_W)) { + lib9p_error(&ctx->ctx.basectx, + LINUX_EINVAL, "FID not open for writing"); + return; + } + + /* Variables. */ + struct lib9p_srv_file *file = fidinfo->file; + + /* Do it. */ + resp->count = file->vtable->pwrite(&ctx->ctx, file, req->data.dat, req->data.len, req->offset); } static void handle_Tclunk(struct _lib9p_srv_req *ctx, -- cgit v1.2.3-2-g168b