summaryrefslogtreecommitdiff
path: root/lib9p/srv.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib9p/srv.c')
-rw-r--r--lib9p/srv.c88
1 files changed, 45 insertions, 43 deletions
diff --git a/lib9p/srv.c b/lib9p/srv.c
index 7785e4d..d29479f 100644
--- a/lib9p/srv.c
+++ b/lib9p/srv.c
@@ -27,6 +27,8 @@
#define IMPLEMENTATION_FOR_LIB9P_SRV_H YES
#include <lib9p/srv.h>
+#include "srv_errno.h"
+
/* config *********************************************************************/
#include "config.h"
@@ -342,7 +344,7 @@ static inline struct srv_fidinfo *srv_fid_store(struct srv_req *ctx, lib9p_fid_t
map_del(&ctx->parent_sess->fids, fid);
} else {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EBADF, "FID already in use");
+ E_POSIX_EBADF, "FID already in use");
return NULL;
}
}
@@ -388,7 +390,7 @@ static void srv_respond_error(struct srv_req *req) {
.errstr = lib9p_strn(req->basectx.err_msg,
CONFIG_9P_MAX_ERR_SIZE),
#if CONFIG_9P_ENABLE_9P2000_u
- .errnum = req->basectx.err_num,
+ .errnum = libmisc_to_linuxgeneric_errno(req->basectx.err_num),
#endif
};
@@ -397,7 +399,7 @@ static void srv_respond_error(struct srv_req *req) {
uint32_t overhead = lib9p_version_min_Rerror_size(sess->version);
/* Truncate the error-string if necessary to avoid needing to
- * return LIB9P_ERRNO_L_ERANGE. */
+ * return E_POSIX_ERANGE. */
if (((uint32_t)host.errstr.len) + overhead > sess->max_msg_size)
host.errstr.len = sess->max_msg_size - overhead;
@@ -497,7 +499,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, LIB9P_ERRNO_L_EMSGSIZE,
+ lib9p_error(&req.basectx, E_POSIX_EMSGSIZE,
"T-message larger than ", sess.initialized ? "negotiated" : "server", " limit",
" (", goal, " > ", sess.max_msg_size, ")");
srv_respond_error(&req);
@@ -760,7 +762,7 @@ static void handle_Tversion(struct srv_req *ctx,
lib9p_version_min_Rread_size(ctx->basectx.version)+1);
if (req->max_msg_size < min_msg_size) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EDOM, "requested max_msg_size is less than minimum for ", lib9p_version_str(version),
+ 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;
}
@@ -814,7 +816,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,
- LIB9P_ERRNO_L_EOPNOTSUPP, "authentication not required");
+ E_POSIX_EOPNOTSUPP, "authentication not required");
goto tauth_return;
}
@@ -823,7 +825,7 @@ static void handle_Tauth(struct srv_req *ctx,
srv->auth(ctx, req->aname);
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EOPNOTSUPP, "TODO: auth not implemented");
+ E_POSIX_EOPNOTSUPP, "TODO: auth not implemented");
if (lib9p_ctx_has_error(&ctx->basectx))
ctx->user = srv_userid_decref(ctx->user);
@@ -838,7 +840,7 @@ static void handle_Tattach(struct srv_req *ctx,
if (req->fid == LIB9P_FID_NOFID) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EBADF, "cannot assign to NOFID");
+ E_POSIX_EBADF, "cannot assign to NOFID");
goto tattach_return;
}
@@ -847,37 +849,37 @@ static void handle_Tattach(struct srv_req *ctx,
struct srv_fidinfo *afid = map_load(&ctx->parent_sess->fids, req->afid);
if (!afid)
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EACCES, "FID provided as auth-file is not a valid FID");
+ E_POSIX_EACCES, "FID provided as auth-file is not a valid FID");
else if (afid->type != SRV_FILETYPE_AUTH)
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EACCES, "FID provided as auth-file is not an auth-file");
+ 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,
- LIB9P_ERRNO_L_EACCES,
+ 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,
- LIB9P_ERRNO_L_EACCES,
+ 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,
- LIB9P_ERRNO_L_EACCES,
+ 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,
- LIB9P_ERRNO_L_EACCES, "FID provided as auth-file has not completed authentication");
+ E_POSIX_EACCES, "FID provided as auth-file has not completed authentication");
if (lib9p_ctx_has_error(&ctx->basectx))
goto tattach_return;
ctx->user = srv_userid_incref(afid->user);
} else {
if (req->afid != LIB9P_FID_NOFID) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EACCES, "FID provided as auth-file, but no auth-file is required");
+ 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);
@@ -937,19 +939,19 @@ static void handle_Twalk(struct srv_req *ctx,
if (req->newfid == LIB9P_FID_NOFID) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EBADF, "cannot assign to NOFID");
+ 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,
- LIB9P_ERRNO_L_EBADF, "bad file number ", req->fid);
+ E_POSIX_EBADF, "bad file number ", req->fid);
goto twalk_return;
}
if (fidinfo->flags & FIDFLAG_OPEN) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EALREADY, "cannot walk on FID open for I/O");
+ E_POSIX_EALREADY, "cannot walk on FID open for I/O");
goto twalk_return;
}
ctx->user = srv_userid_incref(fidinfo->user);
@@ -963,7 +965,7 @@ static void handle_Twalk(struct srv_req *ctx,
for (resp.nwqid = 0; resp.nwqid < req->nwname; resp.nwqid++) {
if (pathinfo->type != SRV_FILETYPE_DIR) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_ENOTDIR, "not a directory");
+ E_POSIX_ENOTDIR, "not a directory");
break;
}
@@ -988,7 +990,7 @@ static void handle_Twalk(struct srv_req *ctx,
lib9p_srv_stat_assert(stat);
if (!srv_check_perm(ctx, &stat, 0b001)) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EACCES, "you do not have execute permission on that directory");
+ E_POSIX_EACCES, "you do not have execute permission on that directory");
srv_path_decref(ctx, LO_CALL(new_pathinfo->file, qid).path);
break;
}
@@ -1022,12 +1024,12 @@ static void handle_Topen(struct srv_req *ctx,
struct srv_fidinfo *fidinfo = map_load(&ctx->parent_sess->fids, req->fid);
if (!fidinfo) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EBADF, "bad file number ", req->fid);
+ E_POSIX_EBADF, "bad file number ", req->fid);
goto topen_return;
}
if (fidinfo->flags & FIDFLAG_OPEN) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EALREADY, "FID is already open");
+ E_POSIX_EALREADY, "FID is already open");
goto topen_return;
}
if (fidinfo->type == SRV_FILETYPE_DIR) {
@@ -1035,7 +1037,7 @@ static void handle_Topen(struct srv_req *ctx,
(req->mode & LIB9P_O_TRUNC) ||
(req->mode & LIB9P_O_RCLOSE) ) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EISDIR, "directories cannot be written, executed, truncated, or removed-on-close");
+ E_POSIX_EISDIR, "directories cannot be written, executed, truncated, or removed-on-close");
goto topen_return;
}
}
@@ -1057,7 +1059,7 @@ static void handle_Topen(struct srv_req *ctx,
lib9p_srv_stat_assert(parent_stat);
if (!srv_check_perm(ctx, &parent_stat, 0b010)) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EACCES, "permission denied to remove-on-close");
+ E_POSIX_EACCES, "permission denied to remove-on-close");
goto topen_return;
}
fidflags |= FIDFLAG_RCLOSE;
@@ -1068,7 +1070,7 @@ static void handle_Topen(struct srv_req *ctx,
lib9p_srv_stat_assert(stat);
if ((stat.mode & LIB9P_DM_EXCL) && pathinfo->io_refcount) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EEXIST, "exclusive file is already opened");
+ E_POSIX_EEXIST, "exclusive file is already opened");
goto topen_return;
}
if (stat.mode & LIB9P_DM_APPEND) {
@@ -1097,7 +1099,7 @@ static void handle_Topen(struct srv_req *ctx,
}
if (!srv_check_perm(ctx, &stat, perm_bits)) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EACCES, "permission denied");
+ E_POSIX_EACCES, "permission denied");
goto topen_return;
}
@@ -1153,7 +1155,7 @@ static void handle_Tcreate(struct srv_req *ctx,
srv_handler_common(ctx, create, req);
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EOPNOTSUPP, "create not (yet?) implemented");
+ E_POSIX_EOPNOTSUPP, "create not (yet?) implemented");
srv_respond(ctx, create, &resp);
}
@@ -1192,12 +1194,12 @@ static void handle_Tread(struct srv_req *ctx,
struct srv_fidinfo *fidinfo = map_load(&ctx->parent_sess->fids, req->fid);
if (!fidinfo) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EBADF, "bad file number ", req->fid);
+ E_POSIX_EBADF, "bad file number ", req->fid);
goto tread_return;
}
if (!(fidinfo->flags & FIDFLAG_OPEN_R)) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EINVAL, "FID not open for reading");
+ E_POSIX_EINVAL, "FID not open for reading");
goto tread_return;
}
@@ -1213,7 +1215,7 @@ static void handle_Tread(struct srv_req *ctx,
fidinfo->dir.buffered_dirent = (struct lib9p_srv_dirent){};
} else if (req->offset != fidinfo->dir.off) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EINVAL, "invalid offset (must be 0 or ", fidinfo->dir.off, "): ", req->offset);
+ E_POSIX_EINVAL, "invalid offset (must be 0 or ", fidinfo->dir.off, "): ", req->offset);
goto tread_return;
}
/* Read. */
@@ -1266,7 +1268,7 @@ static void handle_Tread(struct srv_req *ctx,
if (!nbytes) {
if (!resp.count) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_ERANGE, "stat object does not fit into negotiated max message size");
+ E_POSIX_ERANGE, "stat object does not fit into negotiated max message size");
goto tread_return;
}
fidinfo->dir.buffered_dirent = member_dirent;
@@ -1313,12 +1315,12 @@ static void handle_Twrite(struct srv_req *ctx,
struct srv_fidinfo *fidinfo = map_load(&ctx->parent_sess->fids, req->fid);
if (!fidinfo) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EBADF, "bad file number ", req->fid);
+ E_POSIX_EBADF, "bad file number ", req->fid);
goto twrite_return;
}
if (!(fidinfo->flags & FIDFLAG_OPEN_W)) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EINVAL, "FID not open for writing");
+ E_POSIX_EINVAL, "FID not open for writing");
goto twrite_return;
}
if (fidinfo->flags & FIDFLAG_APPEND)
@@ -1340,7 +1342,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,
- LIB9P_ERRNO_L_EBADF, "bad file number ", req->fid);
+ E_POSIX_EBADF, "bad file number ", req->fid);
goto tclunk_return;
}
@@ -1357,7 +1359,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,
- LIB9P_ERRNO_L_EBADF, "bad file number ", req->fid);
+ E_POSIX_EBADF, "bad file number ", req->fid);
goto tremove_return;
}
@@ -1366,7 +1368,7 @@ static void handle_Tremove(struct srv_req *ctx,
assert(pathinfo);
if (pathinfo->parent_dir == fidinfo->path) {
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EBUSY, "cannot remove root");
+ E_POSIX_EBUSY, "cannot remove root");
remove = false;
goto tremove_main;
}
@@ -1375,7 +1377,7 @@ static void handle_Tremove(struct srv_req *ctx,
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,
- LIB9P_ERRNO_L_EACCES, "you do not have write permission on the parent directory");
+ E_POSIX_EACCES, "you do not have write permission on the parent directory");
remove = false;
goto tremove_main;
}
@@ -1393,7 +1395,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,
- LIB9P_ERRNO_L_EBADF, "bad file number ", req->fid);
+ E_POSIX_EBADF, "bad file number ", req->fid);
goto tstat_return;
}
struct srv_pathinfo *pathinfo = map_load(&ctx->parent_sess->paths, fidinfo->path);
@@ -1416,7 +1418,7 @@ static void handle_Twstat(struct srv_req *ctx,
srv_handler_common(ctx, wstat, req);
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EOPNOTSUPP, "wstat not (yet?) implemented");
+ E_POSIX_EOPNOTSUPP, "wstat not (yet?) implemented");
srv_respond(ctx, wstat, &resp);
}
@@ -1428,7 +1430,7 @@ static void handle_Topenfd(struct srv_req *ctx,
srv_handler_common(ctx, openfd, req);
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EOPNOTSUPP, "openfd not (yet?) implemented");
+ E_POSIX_EOPNOTSUPP, "openfd not (yet?) implemented");
srv_respond(ctx, openfd, &resp);
}
@@ -1440,7 +1442,7 @@ static void handle_Tsession(struct srv_req *ctx,
srv_handler_common(ctx, session, req);
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EOPNOTSUPP, "session not (yet?) implemented");
+ E_POSIX_EOPNOTSUPP, "session not (yet?) implemented");
srv_respond(ctx, session, &resp);
}
@@ -1450,7 +1452,7 @@ static void handle_Tsread(struct srv_req *ctx,
srv_handler_common(ctx, sread, req);
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EOPNOTSUPP, "sread not (yet?) implemented");
+ E_POSIX_EOPNOTSUPP, "sread not (yet?) implemented");
srv_respond(ctx, sread, &resp);
}
@@ -1460,7 +1462,7 @@ static void handle_Tswrite(struct srv_req *ctx,
srv_handler_common(ctx, swrite, req);
lib9p_error(&ctx->basectx,
- LIB9P_ERRNO_L_EOPNOTSUPP, "swrite not (yet?) implemented");
+ E_POSIX_EOPNOTSUPP, "swrite not (yet?) implemented");
srv_respond(ctx, swrite, &resp);
}