diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-29 22:25:02 -0400 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-06-06 23:01:30 -0600 |
commit | 945756b1b050bdf09d1119854cc5b22ad15efacd (patch) | |
tree | 8223c149ea0ff2863ffd2e1a90c2ebdfe8eb8b4b /lib9p/srv.c | |
parent | 8a9fc1704dcf3ec117a3bf37fd70a44a43873659 (diff) |
lib9p_core: Switch to use error.h
Diffstat (limited to 'lib9p/srv.c')
-rw-r--r-- | lib9p/srv.c | 221 |
1 files changed, 100 insertions, 121 deletions
diff --git a/lib9p/srv.c b/lib9p/srv.c index d29479f..917b41e 100644 --- a/lib9p/srv.c +++ b/lib9p/srv.c @@ -44,6 +44,17 @@ static_assert(CONFIG_9P_SRV_MAX_HOSTMSG_SIZE <= SSIZE_MAX); /* context ********************************************************************/ +void lib9p_ctx_clear_error(struct lib9p_srv_ctx *ctx) { + assert(ctx); + ctx->err_num = 0; + ctx->err_msg[0] = '\0'; +} + +bool lib9p_ctx_has_error(struct lib9p_srv_ctx *ctx) { + assert(ctx); + return ctx->err_msg[0]; +} + bool lib9p_srv_flush_requested(struct lib9p_srv_ctx *ctx) { assert(ctx); return cr_chan_can_send(&ctx->flush_ch); @@ -343,8 +354,7 @@ static inline struct srv_fidinfo *srv_fid_store(struct srv_req *ctx, lib9p_fid_t srv_path_decref(ctx, old_fidinfo->path); map_del(&ctx->parent_sess->fids, fid); } else { - lib9p_error(&ctx->basectx, - E_POSIX_EBADF, "FID already in use"); + lib9p_error(ctx, E_POSIX_EBADF, "FID already in use"); return NULL; } } @@ -381,16 +391,16 @@ static void srv_write_Rmsg(struct srv_req *req, struct lib9p_Rmsg_send_buf *resp static void srv_respond_error(struct srv_req *req) { #if CONFIG_9P_ENABLE_9P2000_u || CONFIG_9P_ENABLE_9P2000_L - assert(req->basectx.err_num); + assert(req->err_num); #endif - assert(req->basectx.err_msg[0]); + assert(req->err_msg[0]); struct lib9p_msg_Rerror host = { .tag = req->tag, - .errstr = lib9p_strn(req->basectx.err_msg, - CONFIG_9P_MAX_ERR_SIZE), + .errstr = lib9p_strn(req->err_msg, + CONFIG_9P_SRV_MAX_ERR_SIZE), #if CONFIG_9P_ENABLE_9P2000_u - .errnum = libmisc_to_linuxgeneric_errno(req->basectx.err_num), + .errnum = libmisc_to_linuxgeneric_errno(req->err_num), #endif }; @@ -499,7 +509,7 @@ void lib9p_srv_read(struct lib9p_srv *srv, lo_interface net_stream_conn _conn) { .net_bytes = buf, }; if (goal > sess.max_msg_size) { - lib9p_error(&req.basectx, E_POSIX_EMSGSIZE, + lib9p_error(&req, E_POSIX_EMSGSIZE, "T-message larger than ", sess.initialized ? "negotiated" : "server", " limit", " (", goal, " > ", sess.max_msg_size, ")"); srv_respond_error(&req); @@ -555,9 +565,9 @@ void lib9p_srv_read(struct lib9p_srv *srv, lo_interface net_stream_conn _conn) { }; MAP_FOREACH(&sess.fids, fid, fidinfo) { srv_fid_del(&pseudoreq, fid, fidinfo, false); - if (lib9p_ctx_has_error(&pseudoreq.basectx)) { - srv_nonrespond_error("clunk: ", (strn, pseudoreq.basectx.err_msg, CONFIG_9P_MAX_ERR_SIZE)); - lib9p_ctx_clear_error(&pseudoreq.basectx); + if (lib9p_ctx_has_error(&pseudoreq)) { + srv_nonrespond_error("clunk: ", (strn, pseudoreq.err_msg, CONFIG_9P_SRV_MAX_ERR_SIZE)); + lib9p_ctx_clear_error(&pseudoreq); } } map_free(&sess.fids); @@ -631,11 +641,14 @@ void lib9p_srv_worker(struct srv_req *ctx) { uint8_t *host_req = NULL; /* Unmarshal it. *****************************************************/ - ssize_t host_size = lib9p_Tmsg_validate(&ctx->basectx, ctx->net_bytes); - if (host_size < 0) { + size_t_or_error r = lib9p_Tmsg_validate(&ctx->basectx, ctx->net_bytes); + if (r.is_err) { + lib9p_error(ctx, r.err.num, (error, r.err)); + error_cleanup(&r.err); srv_respond_error(ctx); goto release; } + size_t host_size = r.size_t; host_req = calloc(1, host_size); assert(host_req); enum lib9p_msg_type typ; @@ -693,7 +706,7 @@ void lib9p_srv_worker(struct srv_req *ctx) { static inline void _srv_respond(struct srv_req *ctx, enum lib9p_msg_type resp_typ, void *host_resp) { assert(!ctx->responded); - if (lib9p_ctx_has_error(&ctx->basectx)) { + if (lib9p_ctx_has_error(ctx)) { error: srv_respond_error(ctx); } else if (ctx->flush_acknowledged) { @@ -701,10 +714,14 @@ static inline void _srv_respond(struct srv_req *ctx, enum lib9p_msg_type resp_ty } else { assert(host_resp); struct lib9p_Rmsg_send_buf net_resp; - if (lib9p_Rmsg_marshal(&ctx->basectx, - resp_typ, host_resp, - &net_resp)) + error err = lib9p_Rmsg_marshal(&ctx->basectx, + resp_typ, host_resp, + &net_resp); + if (!ERROR_IS_NULL(err)) { + lib9p_error(ctx, err.num, (error, err)); + error_cleanup(&err); goto error; + } srv_msglog(ctx, resp_typ, host_resp); srv_write_Rmsg(ctx, &net_resp); } @@ -761,7 +778,7 @@ static void handle_Tversion(struct srv_req *ctx, uint32_t min_msg_size = _LIB9P_MAX(lib9p_version_min_Rerror_size(ctx->basectx.version), lib9p_version_min_Rread_size(ctx->basectx.version)+1); if (req->max_msg_size < min_msg_size) { - lib9p_error(&ctx->basectx, + lib9p_error(ctx, E_POSIX_EDOM, "requested max_msg_size is less than minimum for ", lib9p_version_str(version), " (", req->max_msg_size, " < ", min_msg_size, ")"); goto tversion_return; @@ -794,9 +811,9 @@ static void handle_Tversion(struct srv_req *ctx, /* Close all FIDs. */ MAP_FOREACH(&ctx->parent_sess->fids, fid, fidinfo) { srv_fid_del(ctx, fid, fidinfo, false); - if (lib9p_ctx_has_error(&ctx->basectx)) { - srv_nonrespond_error("clunk: ", (strn, ctx->basectx.err_msg, CONFIG_9P_MAX_ERR_SIZE)); - lib9p_ctx_clear_error(&ctx->basectx); + if (lib9p_ctx_has_error(ctx)) { + srv_nonrespond_error("clunk: ", (strn, ctx->err_msg, CONFIG_9P_SRV_MAX_ERR_SIZE)); + lib9p_ctx_clear_error(ctx); } } @@ -815,8 +832,7 @@ static void handle_Tauth(struct srv_req *ctx, struct lib9p_srv *srv = ctx->parent_sess->parent_conn->parent_srv; if (!srv->auth) { - lib9p_error(&ctx->basectx, - E_POSIX_EOPNOTSUPP, "authentication not required"); + lib9p_error(ctx, E_POSIX_EOPNOTSUPP, "authentication not required"); goto tauth_return; } @@ -824,10 +840,9 @@ static void handle_Tauth(struct srv_req *ctx, srv->auth(ctx, req->aname); - lib9p_error(&ctx->basectx, - E_POSIX_EOPNOTSUPP, "TODO: auth not implemented"); + lib9p_error(ctx, E_POSIX_EOPNOTSUPP, "TODO: auth not implemented"); - if (lib9p_ctx_has_error(&ctx->basectx)) + if (lib9p_ctx_has_error(ctx)) ctx->user = srv_userid_decref(ctx->user); tauth_return: @@ -839,8 +854,7 @@ static void handle_Tattach(struct srv_req *ctx, srv_handler_common(ctx, attach, req); if (req->fid == LIB9P_FID_NOFID) { - lib9p_error(&ctx->basectx, - E_POSIX_EBADF, "cannot assign to NOFID"); + lib9p_error(ctx, E_POSIX_EBADF, "cannot assign to NOFID"); goto tattach_return; } @@ -848,38 +862,31 @@ static void handle_Tattach(struct srv_req *ctx, if (srv->auth) { struct srv_fidinfo *afid = map_load(&ctx->parent_sess->fids, req->afid); if (!afid) - lib9p_error(&ctx->basectx, - E_POSIX_EACCES, "FID provided as auth-file is not a valid FID"); + lib9p_error(ctx, E_POSIX_EACCES, "FID provided as auth-file is not a valid FID"); else if (afid->type != SRV_FILETYPE_AUTH) - lib9p_error(&ctx->basectx, - E_POSIX_EACCES, "FID provided as auth-file is not an auth-file"); + lib9p_error(ctx, E_POSIX_EACCES, "FID provided as auth-file is not an auth-file"); else if (!lib9p_str_eq(afid->user->name, req->uname)) - lib9p_error(&ctx->basectx, - E_POSIX_EACCES, + lib9p_error(ctx, E_POSIX_EACCES, "FID provided as auth-file is for user=", (qmem, afid->user->name.utf8, afid->user->name.len), " and cannot be used for user=", (qmem, req->uname.utf8, req->uname.len)); #if CONFIG_9P_ENABLE_9P2000_u || CONFIG_9P_ENABLE_9P2000_L else if (afid->user->num != req->unum) - lib9p_error(&ctx->basectx, - E_POSIX_EACCES, + lib9p_error(ctx, E_POSIX_EACCES, "FID provided as auth-file is for user=", afid->user->num, " and cannot be used for user=", req->unum); #endif else if (!lib9p_str_eq(afid->auth.aname, req->aname)) - lib9p_error(&ctx->basectx, - E_POSIX_EACCES, + lib9p_error(ctx, E_POSIX_EACCES, "FID provided as auth-file is for tree=", (qmem, afid->auth.aname.utf8, afid->auth.aname.len), " and cannot be used for tree=", (qmem, req->aname.utf8, req->aname.len)); else if (!afid->auth.completed) - lib9p_error(&ctx->basectx, - E_POSIX_EACCES, "FID provided as auth-file has not completed authentication"); - if (lib9p_ctx_has_error(&ctx->basectx)) + lib9p_error(ctx, E_POSIX_EACCES, "FID provided as auth-file has not completed authentication"); + if (lib9p_ctx_has_error(ctx)) goto tattach_return; ctx->user = srv_userid_incref(afid->user); } else { if (req->afid != LIB9P_FID_NOFID) { - lib9p_error(&ctx->basectx, - E_POSIX_EACCES, "FID provided as auth-file, but no auth-file is required"); + lib9p_error(ctx, E_POSIX_EACCES, "FID provided as auth-file, but no auth-file is required"); goto tattach_return; } ctx->user = srv_userid_new(req->uname, req->unum); @@ -887,8 +894,8 @@ static void handle_Tattach(struct srv_req *ctx, /* 1. File object */ lo_interface lib9p_srv_file root_file = srv->rootdir(ctx, req->aname); - assert(LO_IS_NULL(root_file) == lib9p_ctx_has_error(&ctx->basectx)); - if (lib9p_ctx_has_error(&ctx->basectx)) + assert(LO_IS_NULL(root_file) == lib9p_ctx_has_error(ctx)); + if (lib9p_ctx_has_error(ctx)) goto tattach_return; struct lib9p_qid root_qid = LO_CALL(root_file, qid); @@ -938,20 +945,17 @@ static void handle_Twalk(struct srv_req *ctx, srv_handler_common(ctx, walk, req); if (req->newfid == LIB9P_FID_NOFID) { - lib9p_error(&ctx->basectx, - E_POSIX_EBADF, "cannot assign to NOFID"); + lib9p_error(ctx, E_POSIX_EBADF, "cannot assign to NOFID"); goto twalk_return; } struct srv_fidinfo *fidinfo = map_load(&ctx->parent_sess->fids, req->fid); if (!fidinfo) { - lib9p_error(&ctx->basectx, - E_POSIX_EBADF, "bad file number ", req->fid); + lib9p_error(ctx, E_POSIX_EBADF, "bad file number ", req->fid); goto twalk_return; } if (fidinfo->flags & FIDFLAG_OPEN) { - lib9p_error(&ctx->basectx, - E_POSIX_EALREADY, "cannot walk on FID open for I/O"); + lib9p_error(ctx, E_POSIX_EALREADY, "cannot walk on FID open for I/O"); goto twalk_return; } ctx->user = srv_userid_incref(fidinfo->user); @@ -964,8 +968,7 @@ static void handle_Twalk(struct srv_req *ctx, resp.wqid = _resp_qid; for (resp.nwqid = 0; resp.nwqid < req->nwname; resp.nwqid++) { if (pathinfo->type != SRV_FILETYPE_DIR) { - lib9p_error(&ctx->basectx, - E_POSIX_ENOTDIR, "not a directory"); + lib9p_error(ctx, E_POSIX_ENOTDIR, "not a directory"); break; } @@ -976,8 +979,8 @@ static void handle_Twalk(struct srv_req *ctx, new_pathinfo->gc_refcount++; } else { lo_interface lib9p_srv_file member_file = LO_CALL(pathinfo->file, dwalk, ctx, req->wname[resp.nwqid]); - assert(LO_IS_NULL(member_file) == lib9p_ctx_has_error(&ctx->basectx)); - if (lib9p_ctx_has_error(&ctx->basectx)) + assert(LO_IS_NULL(member_file) == lib9p_ctx_has_error(ctx)); + if (lib9p_ctx_has_error(ctx)) break; new_pathinfo = srv_path_save(ctx, member_file, LO_CALL(pathinfo->file, qid).path); assert(new_pathinfo); @@ -985,12 +988,11 @@ static void handle_Twalk(struct srv_req *ctx, if (new_pathinfo->type == SRV_FILETYPE_DIR) { struct lib9p_srv_stat stat = LO_CALL(new_pathinfo->file, stat, ctx); - if (lib9p_ctx_has_error(&ctx->basectx)) + if (lib9p_ctx_has_error(ctx)) break; lib9p_srv_stat_assert(stat); if (!srv_check_perm(ctx, &stat, 0b001)) { - lib9p_error(&ctx->basectx, - E_POSIX_EACCES, "you do not have execute permission on that directory"); + lib9p_error(ctx, E_POSIX_EACCES, "you do not have execute permission on that directory"); srv_path_decref(ctx, LO_CALL(new_pathinfo->file, qid).path); break; } @@ -1005,10 +1007,10 @@ static void handle_Twalk(struct srv_req *ctx, if (!srv_fid_store(ctx, req->newfid, pathinfo, req->newfid == req->fid)) srv_path_decref(ctx, LO_CALL(pathinfo->file, qid).path); } else { - assert(lib9p_ctx_has_error(&ctx->basectx)); + assert(lib9p_ctx_has_error(ctx)); srv_path_decref(ctx, LO_CALL(pathinfo->file, qid).path); if (resp.nwqid > 0) - lib9p_ctx_clear_error(&ctx->basectx); + lib9p_ctx_clear_error(ctx); } twalk_return: if (ctx->user) @@ -1023,21 +1025,18 @@ static void handle_Topen(struct srv_req *ctx, /* Check that the FID is valid for this. */ struct srv_fidinfo *fidinfo = map_load(&ctx->parent_sess->fids, req->fid); if (!fidinfo) { - lib9p_error(&ctx->basectx, - E_POSIX_EBADF, "bad file number ", req->fid); + lib9p_error(ctx, E_POSIX_EBADF, "bad file number ", req->fid); goto topen_return; } if (fidinfo->flags & FIDFLAG_OPEN) { - lib9p_error(&ctx->basectx, - E_POSIX_EALREADY, "FID is already open"); + lib9p_error(ctx, E_POSIX_EALREADY, "FID is already open"); goto topen_return; } if (fidinfo->type == SRV_FILETYPE_DIR) { if ( ((req->mode & LIB9P_O_MODE_MASK) != LIB9P_O_MODE_READ) || (req->mode & LIB9P_O_TRUNC) || (req->mode & LIB9P_O_RCLOSE) ) { - lib9p_error(&ctx->basectx, - E_POSIX_EISDIR, "directories cannot be written, executed, truncated, or removed-on-close"); + lib9p_error(ctx, E_POSIX_EISDIR, "directories cannot be written, executed, truncated, or removed-on-close"); goto topen_return; } } @@ -1054,23 +1053,21 @@ static void handle_Topen(struct srv_req *ctx, struct srv_pathinfo *parent = map_load(&ctx->parent_sess->paths, pathinfo->parent_dir); assert(parent); struct lib9p_srv_stat parent_stat = LO_CALL(parent->file, stat, ctx); - if (lib9p_ctx_has_error(&ctx->basectx)) + if (lib9p_ctx_has_error(ctx)) goto topen_return; lib9p_srv_stat_assert(parent_stat); if (!srv_check_perm(ctx, &parent_stat, 0b010)) { - lib9p_error(&ctx->basectx, - E_POSIX_EACCES, "permission denied to remove-on-close"); + lib9p_error(ctx, E_POSIX_EACCES, "permission denied to remove-on-close"); goto topen_return; } fidflags |= FIDFLAG_RCLOSE; } struct lib9p_srv_stat stat = LO_CALL(pathinfo->file, stat, ctx); - if (lib9p_ctx_has_error(&ctx->basectx)) + if (lib9p_ctx_has_error(ctx)) goto topen_return; lib9p_srv_stat_assert(stat); if ((stat.mode & LIB9P_DM_EXCL) && pathinfo->io_refcount) { - lib9p_error(&ctx->basectx, - E_POSIX_EEXIST, "exclusive file is already opened"); + lib9p_error(ctx, E_POSIX_EEXIST, "exclusive file is already opened"); goto topen_return; } if (stat.mode & LIB9P_DM_APPEND) { @@ -1098,8 +1095,7 @@ static void handle_Topen(struct srv_req *ctx, break; } if (!srv_check_perm(ctx, &stat, perm_bits)) { - lib9p_error(&ctx->basectx, - E_POSIX_EACCES, "permission denied"); + lib9p_error(ctx, E_POSIX_EACCES, "permission denied"); goto topen_return; } @@ -1109,8 +1105,8 @@ static void handle_Topen(struct srv_req *ctx, switch (pathinfo->type) { case SRV_FILETYPE_DIR: fidinfo->dir.io = LO_CALL(pathinfo->file, dopen, ctx); - assert(LO_IS_NULL(fidinfo->dir.io) == lib9p_ctx_has_error(&ctx->basectx)); - if (lib9p_ctx_has_error(&ctx->basectx)) + assert(LO_IS_NULL(fidinfo->dir.io) == lib9p_ctx_has_error(ctx)); + if (lib9p_ctx_has_error(ctx)) goto topen_return; fidinfo->dir.idx = 0; fidinfo->dir.off = 0; @@ -1121,8 +1117,8 @@ static void handle_Topen(struct srv_req *ctx, fidinfo->file.io = LO_CALL(pathinfo->file, fopen, ctx, rd, wr, reqmode & LIB9P_O_TRUNC); - assert(LO_IS_NULL(fidinfo->file.io) == lib9p_ctx_has_error(&ctx->basectx)); - if (lib9p_ctx_has_error(&ctx->basectx)) + assert(LO_IS_NULL(fidinfo->file.io) == lib9p_ctx_has_error(ctx)); + if (lib9p_ctx_has_error(ctx)) goto topen_return; qid = LO_CALL(fidinfo->file.io, qid); iounit = LO_CALL(fidinfo->file.io, iounit); @@ -1154,8 +1150,7 @@ static void handle_Tcreate(struct srv_req *ctx, struct lib9p_msg_Tcreate *req) { srv_handler_common(ctx, create, req); - lib9p_error(&ctx->basectx, - E_POSIX_EOPNOTSUPP, "create not (yet?) implemented"); + lib9p_error(ctx, E_POSIX_EOPNOTSUPP, "create not (yet?) implemented"); srv_respond(ctx, create, &resp); } @@ -1193,13 +1188,11 @@ static void handle_Tread(struct srv_req *ctx, /* Check that the FID is valid for this. */ struct srv_fidinfo *fidinfo = map_load(&ctx->parent_sess->fids, req->fid); if (!fidinfo) { - lib9p_error(&ctx->basectx, - E_POSIX_EBADF, "bad file number ", req->fid); + lib9p_error(ctx, E_POSIX_EBADF, "bad file number ", req->fid); goto tread_return; } if (!(fidinfo->flags & FIDFLAG_OPEN_R)) { - lib9p_error(&ctx->basectx, - E_POSIX_EINVAL, "FID not open for reading"); + lib9p_error(ctx, E_POSIX_EINVAL, "FID not open for reading"); goto tread_return; } @@ -1214,8 +1207,7 @@ static void handle_Tread(struct srv_req *ctx, fidinfo->dir.off = 0; fidinfo->dir.buffered_dirent = (struct lib9p_srv_dirent){}; } else if (req->offset != fidinfo->dir.off) { - lib9p_error(&ctx->basectx, - E_POSIX_EINVAL, "invalid offset (must be 0 or ", fidinfo->dir.off, "): ", req->offset); + lib9p_error(ctx, E_POSIX_EINVAL, "invalid offset (must be 0 or ", fidinfo->dir.off, "): ", req->offset); goto tread_return; } /* Read. */ @@ -1229,10 +1221,10 @@ static void handle_Tread(struct srv_req *ctx, member_dirent = fidinfo->dir.buffered_dirent; } else { member_dirent = LO_CALL(fidinfo->dir.io, dread, ctx, fidinfo->dir.idx); - if (lib9p_ctx_has_error(&ctx->basectx)) { + if (lib9p_ctx_has_error(ctx)) { if (!resp.count) goto tread_return; - lib9p_ctx_clear_error(&ctx->basectx); + lib9p_ctx_clear_error(ctx); break; } } @@ -1247,16 +1239,16 @@ static void handle_Tread(struct srv_req *ctx, dir_pathinfo = map_load(&ctx->parent_sess->paths, fidinfo->path); assert(dir_pathinfo); member_file = LO_CALL(dir_pathinfo->file, dwalk, ctx, member_dirent.name); - assert(LO_IS_NULL(member_file) == lib9p_ctx_has_error(&ctx->basectx)); - if (!lib9p_ctx_has_error(&ctx->basectx)) + assert(LO_IS_NULL(member_file) == lib9p_ctx_has_error(ctx)); + if (!lib9p_ctx_has_error(ctx)) member_stat = LO_CALL(member_file, stat, ctx); } - if (lib9p_ctx_has_error(&ctx->basectx)) { + if (lib9p_ctx_has_error(ctx)) { if (!LO_IS_NULL(member_file)) LO_CALL(member_file, free); if (!resp.count) goto tread_return; - lib9p_ctx_clear_error(&ctx->basectx); + lib9p_ctx_clear_error(ctx); break; } lib9p_srv_stat_assert(member_stat); @@ -1267,8 +1259,7 @@ static void handle_Tread(struct srv_req *ctx, LO_CALL(member_file, free); if (!nbytes) { if (!resp.count) { - lib9p_error(&ctx->basectx, - E_POSIX_ERANGE, "stat object does not fit into negotiated max message size"); + lib9p_error(ctx, E_POSIX_ERANGE, "stat object does not fit into negotiated max message size"); goto tread_return; } fidinfo->dir.buffered_dirent = member_dirent; @@ -1286,7 +1277,7 @@ static void handle_Tread(struct srv_req *ctx, case SRV_FILETYPE_FILE: struct iovec iov; LO_CALL(fidinfo->file.io, pread, ctx, req->count, req->offset, &iov); - if (!lib9p_ctx_has_error(&ctx->basectx) && !ctx->flush_acknowledged) { + if (!lib9p_ctx_has_error(ctx) && !ctx->flush_acknowledged) { resp.count = iov.iov_len; resp.data = iov.iov_base; if (resp.count > req->count) @@ -1314,13 +1305,11 @@ static void handle_Twrite(struct srv_req *ctx, /* Check that the FID is valid for this. */ struct srv_fidinfo *fidinfo = map_load(&ctx->parent_sess->fids, req->fid); if (!fidinfo) { - lib9p_error(&ctx->basectx, - E_POSIX_EBADF, "bad file number ", req->fid); + lib9p_error(ctx, E_POSIX_EBADF, "bad file number ", req->fid); goto twrite_return; } if (!(fidinfo->flags & FIDFLAG_OPEN_W)) { - lib9p_error(&ctx->basectx, - E_POSIX_EINVAL, "FID not open for writing"); + lib9p_error(ctx, E_POSIX_EINVAL, "FID not open for writing"); goto twrite_return; } if (fidinfo->flags & FIDFLAG_APPEND) @@ -1341,8 +1330,7 @@ static void handle_Tclunk(struct srv_req *ctx, struct srv_fidinfo *fidinfo = map_load(&ctx->parent_sess->fids, req->fid); if (!fidinfo) { - lib9p_error(&ctx->basectx, - E_POSIX_EBADF, "bad file number ", req->fid); + lib9p_error(ctx, E_POSIX_EBADF, "bad file number ", req->fid); goto tclunk_return; } @@ -1358,8 +1346,7 @@ static void handle_Tremove(struct srv_req *ctx, struct srv_fidinfo *fidinfo = map_load(&ctx->parent_sess->fids, req->fid); if (!fidinfo) { - lib9p_error(&ctx->basectx, - E_POSIX_EBADF, "bad file number ", req->fid); + lib9p_error(ctx, E_POSIX_EBADF, "bad file number ", req->fid); goto tremove_return; } @@ -1367,17 +1354,15 @@ static void handle_Tremove(struct srv_req *ctx, struct srv_pathinfo *pathinfo = map_load(&ctx->parent_sess->paths, fidinfo->path); assert(pathinfo); if (pathinfo->parent_dir == fidinfo->path) { - lib9p_error(&ctx->basectx, - E_POSIX_EBUSY, "cannot remove root"); + lib9p_error(ctx, E_POSIX_EBUSY, "cannot remove root"); remove = false; goto tremove_main; } struct srv_pathinfo *parent = map_load(&ctx->parent_sess->paths, pathinfo->parent_dir); assert(parent); struct lib9p_srv_stat parent_stat = LO_CALL(parent->file, stat, ctx); - if (!lib9p_ctx_has_error(&ctx->basectx) && !srv_check_perm(ctx, &parent_stat, 0b010)) { - lib9p_error(&ctx->basectx, - E_POSIX_EACCES, "you do not have write permission on the parent directory"); + if (!lib9p_ctx_has_error(ctx) && !srv_check_perm(ctx, &parent_stat, 0b010)) { + lib9p_error(ctx, E_POSIX_EACCES, "you do not have write permission on the parent directory"); remove = false; goto tremove_main; } @@ -1394,8 +1379,7 @@ static void handle_Tstat(struct srv_req *ctx, struct srv_fidinfo *fidinfo = map_load(&ctx->parent_sess->fids, req->fid); if (!fidinfo) { - lib9p_error(&ctx->basectx, - E_POSIX_EBADF, "bad file number ", req->fid); + lib9p_error(ctx, E_POSIX_EBADF, "bad file number ", req->fid); goto tstat_return; } struct srv_pathinfo *pathinfo = map_load(&ctx->parent_sess->paths, fidinfo->path); @@ -1403,7 +1387,7 @@ static void handle_Tstat(struct srv_req *ctx, ctx->user = srv_userid_incref(fidinfo->user); struct lib9p_srv_stat stat = LO_CALL(pathinfo->file, stat, ctx); - if (lib9p_ctx_has_error(&ctx->basectx)) + if (lib9p_ctx_has_error(ctx)) goto tstat_return; lib9p_srv_stat_assert(stat); resp.stat = srv_stat_to_net_stat(stat); @@ -1417,8 +1401,7 @@ static void handle_Twstat(struct srv_req *ctx, struct lib9p_msg_Twstat *req) { srv_handler_common(ctx, wstat, req); - lib9p_error(&ctx->basectx, - E_POSIX_EOPNOTSUPP, "wstat not (yet?) implemented"); + lib9p_error(ctx, E_POSIX_EOPNOTSUPP, "wstat not (yet?) implemented"); srv_respond(ctx, wstat, &resp); } @@ -1429,8 +1412,7 @@ static void handle_Topenfd(struct srv_req *ctx, struct lib9p_msg_Topenfd *req) { srv_handler_common(ctx, openfd, req); - lib9p_error(&ctx->basectx, - E_POSIX_EOPNOTSUPP, "openfd not (yet?) implemented"); + lib9p_error(ctx, E_POSIX_EOPNOTSUPP, "openfd not (yet?) implemented"); srv_respond(ctx, openfd, &resp); } @@ -1441,8 +1423,7 @@ static void handle_Tsession(struct srv_req *ctx, struct lib9p_msg_Tsession *req) { srv_handler_common(ctx, session, req); - lib9p_error(&ctx->basectx, - E_POSIX_EOPNOTSUPP, "session not (yet?) implemented"); + lib9p_error(ctx, E_POSIX_EOPNOTSUPP, "session not (yet?) implemented"); srv_respond(ctx, session, &resp); } @@ -1451,8 +1432,7 @@ static void handle_Tsread(struct srv_req *ctx, struct lib9p_msg_Tsread *req) { srv_handler_common(ctx, sread, req); - lib9p_error(&ctx->basectx, - E_POSIX_EOPNOTSUPP, "sread not (yet?) implemented"); + lib9p_error(ctx, E_POSIX_EOPNOTSUPP, "sread not (yet?) implemented"); srv_respond(ctx, sread, &resp); } @@ -1461,8 +1441,7 @@ static void handle_Tswrite(struct srv_req *ctx, struct lib9p_msg_Tswrite *req) { srv_handler_common(ctx, swrite, req); - lib9p_error(&ctx->basectx, - E_POSIX_EOPNOTSUPP, "swrite not (yet?) implemented"); + lib9p_error(ctx, E_POSIX_EOPNOTSUPP, "swrite not (yet?) implemented"); srv_respond(ctx, swrite, &resp); } |