summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-11 13:11:27 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-11 13:11:27 -0600
commit74537d36cd9a32817d18163cccdb60f88b024950 (patch)
treef1dab33de1c6d1b66e650aacabb7505379e47aa2
parent8d333c97017352ec7a63bfe1aff829a06fbe841e (diff)
lib9p: Implement Twrite
-rw-r--r--lib9p/srv.c23
1 files changed, 21 insertions, 2 deletions
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,