summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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,