add linux_emul base, reorganize docs
[openbsd_emul.git] / linux_emul_base / error.c
1 #include <u.h>
2 #include <libc.h>
3 #include <ureg.h>
4 #include "dat.h"
5 #include "fns.h"
6 #include "linux.h"
7
8 int
9 Efmt(Fmt *f)
10 {
11 static char *t[] = {
12 [EPERM] "EPERM",
13 [ENOENT] "ENOENT",
14 [ESRCH] "ESRCH",
15 [EINTR] "EINTR",
16 [EIO] "EIO",
17 [ENXIO] "ENXIO",
18 [E2BIG] "E2BIG",
19 [ENOEXEC] "ENOEXEC",
20 [EBADF] "EBADF",
21 [ECHILD] "ECHILD",
22 [EAGAIN] "EAGAIN",
23 [ENOMEM] "ENOMEM",
24 [EACCES] "EACCES",
25 [EFAULT] "EFAULT",
26 [ENOTBLK] "ENOTBLK",
27 [EBUSY] "EBUSY",
28 [EEXIST] "EEXIST",
29 [EXDEV] "EXDEV",
30 [ENODEV] "ENODEV",
31 [ENOTDIR] "ENOTDIR",
32 [EISDIR] "EISDIR",
33 [EINVAL] "EINVAL",
34 [ENFILE] "ENFILE",
35 [EMFILE] "EMFILE",
36 [ENOTTY] "ENOTTY",
37 [ETXTBSY] "ETXTBSY",
38 [EFBIG] "EFBIG",
39 [ENOSPC] "ENOSPC",
40 [ESPIPE] "ESPIPE",
41 [EROFS] "EROFS",
42 [EMLINK] "EMLINK",
43 [EPIPE] "EPIPE",
44 [EDOM] "EDOM",
45 [ERANGE] "ERANGE",
46 [EDEADLK] "EDEADLK",
47 [ENAMETOOLONG] "ENAMETOOLONG",
48 [ENOLCK] "ENOLCK",
49 [ENOSYS] "ENOSYS",
50 [ENOTEMPTY] "ENOTEMPTY",
51 [ELOOP] "ELOOP",
52 [ENOMSG] "ENOMSG",
53 [EIDRM] "EIDRM",
54 [ECHRNG] "ECHRNG",
55 [EL2NSYNC] "EL2NSYNC",
56 [EL3HLT] "EL3HLT",
57 [EL3RST] "EL3RST",
58 [ELNRNG] "ELNRNG",
59 [EUNATCH] "EUNATCH",
60 [ENOCSI] "ENOCSI",
61 [EL2HLT] "EL2HLT",
62 [EBADE] "EBADE",
63 [EBADR] "EBADR",
64 [EXFULL] "EXFULL",
65 [ENOANO] "ENOANO",
66 [EBADRQC] "EBADRQC",
67 [EBADSLT] "EBADSLT",
68 [EBFONT] "EBFONT",
69 [ENOSTR] "ENOSTR",
70 [ENODATA] "ENODATA",
71 [ETIME] "ETIME",
72 [ENOSR] "ENOSR",
73 [ENONET] "ENONET",
74 [ENOPKG] "ENOPKG",
75 [EREMOTE] "EREMOTE",
76 [ENOLINK] "ENOLINK",
77 [EADV] "EADV",
78 [ESRMNT] "ESRMNT",
79 [ECOMM] "ECOMM",
80 [EPROTO] "EPROTO",
81 [EMULTIHOP] "EMULTIHOP",
82 [EDOTDOT] "EDOTDOT",
83 [EBADMSG] "EBADMSG",
84 [EOVERFLOW] "EOVERFLOW",
85 [ENOTUNIQ] "ENOTUNIQ",
86 [EBADFD] "EBADFD",
87 [EREMCHG] "EREMCHG",
88 [ELIBACC] "ELIBACC",
89 [ELIBBAD] "ELIBBAD",
90 [ELIBSCN] "ELIBSCN",
91 [ELIBMAX] "ELIBMAX",
92 [ELIBEXEC] "ELIBEXEC",
93 [EILSEQ] "EILSEQ",
94 [ERESTART] "ERESTART",
95 [ESTRPIPE] "ESTRPIPE",
96 [EUSERS] "EUSERS",
97 [ENOTSOCK] "ENOTSOCK",
98 [EDESTADDRREQ] "EDESTADDRREQ",
99 [EMSGSIZE] "EMSGSIZE",
100 [EPROTOTYPE] "EPROTOTYPE",
101 [ENOPROTOOPT] "ENOPROTOOPT",
102 [EPROTONOSUPPORT] "EPROTONOSUPPORT",
103 [ESOCKTNOSUPPORT] "ESOCKTNOSUPPORT",
104 [EOPNOTSUPP] "EOPNOTSUPP",
105 [EPFNOSUPPORT] "EPFNOSUPPORT",
106 [EAFNOSUPPORT] "EAFNOSUPPORT",
107 [EADDRINUSE] "EADDRINUSE",
108 [EADDRNOTAVAIL] "EADDRNOTAVAIL",
109 [ENETDOWN] "ENETDOWN",
110 [ENETUNREACH] "ENETUNREACH",
111 [ENETRESET] "ENETRESET",
112 [ECONNABORTED] "ECONNABORTED",
113 [ECONNRESET] "ECONNRESET",
114 [ENOBUFS] "ENOBUFS",
115 [EISCONN] "EISCONN",
116 [ENOTCONN] "ENOTCONN",
117 [ESHUTDOWN] "ESHUTDOWN",
118 [ETOOMANYREFS] "ETOOMANYREFS",
119 [ETIMEDOUT] "ETIMEDOUT",
120 [ECONNREFUSED] "ECONNREFUSED",
121 [EHOSTDOWN] "EHOSTDOWN",
122 [EHOSTUNREACH] "EHOSTUNREACH",
123 [EALREADY] "EALREADY",
124 [EINPROGRESS] "EINPROGRESS",
125 [ESTALE] "ESTALE",
126 [EUCLEAN] "EUCLEAN",
127 [ENOTNAM] "ENOTNAM",
128 [ENAVAIL] "ENAVAIL",
129 [EISNAM] "EISNAM",
130 [EREMOTEIO] "EREMOTEIO",
131 [EDQUOT] "EDQUOT",
132 [ENOMEDIUM] "ENOMEDIUM",
133 [EMEDIUMTYPE] "EMEDIUMTYPE",
134 };
135
136 int e;
137
138 e = va_arg(f->args, int);
139 if(e >= 0 || -e >= nelem(t))
140 return fmtprint(f, "%d", e);
141 return fmtprint(f, "%d [%s]", e, t[-e]);
142 }
143
144 int
145 mkerror(void)
146 {
147 static struct {
148 int num;
149 char *msg;
150 } t[] = {
151 /* from /sys/src/9/port/errstr.h */
152 {EINVAL, "inconsistent mount"},
153 {EINVAL, "not mounted"},
154 {EINVAL, "not in union"},
155 {EIO, "mount rpc error"},
156 {EIO, "mounted device shut down"},
157 {EPERM, "mounted directory forbids creation"},
158 {ENOENT, "does not exist"},
159 {ENXIO, "unknown device in # filename"},
160 {ENOTDIR, "not a directory"},
161 {EISDIR, "file is a directory"},
162 {EINVAL, "bad character in file name"},
163 {EINVAL, "file name syntax"},
164 {EPERM, "permission denied"},
165 {EPERM, "inappropriate use of fd"},
166 {EINVAL, "bad arg in system call"},
167 {EBUSY, "device or object already in use"},
168 {EIO, "i/o error"},
169 {EIO, "read or write too large"},
170 {EIO, "read or write too small"},
171 {EADDRINUSE, "network port not available"},
172 {ESHUTDOWN, "write to hungup stream"},
173 {ESHUTDOWN, "i/o on hungup channel"},
174 {EINVAL, "bad process or channel control request"},
175 {EBUSY, "no free devices"},
176 {ESRCH, "process exited"},
177 {ECHILD, "no living children"},
178 {EIO, "i/o error in demand load"},
179 {ENOMEM, "virtual memory allocation failed"},
180 {EBADF, "fd out of range or not open"},
181 {EMFILE, "no free file descriptors"},
182 {ESPIPE, "seek on a stream"},
183 {ENOEXEC, "exec header invalid"},
184 {ETIMEDOUT, "connection timed out"},
185 {ECONNREFUSED, "connection refused"},
186 {ECONNREFUSED, "connection in use"},
187 {ERESTART, "interrupted"},
188 {ENOMEM, "kernel allocate failed"},
189 {EINVAL, "segments overlap"},
190 {EIO, "i/o count too small"},
191 {EINVAL, "bad attach specifier"},
192
193 /* from exhausted() calls in kernel */
194 {ENFILE, "no free file descriptors"},
195 {EBUSY, "no free mount devices"},
196 {EBUSY, "no free mount rpc buffer"},
197 {EBUSY, "no free segments"},
198 {ENOMEM, "no free memory"},
199 {ENOBUFS, "no free Blocks"},
200 {EBUSY, "no free routes"},
201
202 /* from ken */
203 {EINVAL, "attach -- bad specifier"},
204 {EBADF, "unknown fid"},
205 {EINVAL, "bad character in directory name"},
206 {EBADF, "read/write -- on non open fid"},
207 {EIO, "read/write -- count too big"},
208 {EIO, "phase error -- directory entry not allocated"},
209 {EIO, "phase error -- qid does not match"},
210 {EACCES, "access permission denied"},
211 {ENOENT, "directory entry not found"},
212 {EINVAL, "open/create -- unknown mode"},
213 {ENOTDIR, "walk -- in a non-directory"},
214 {ENOTDIR, "create -- in a non-directory"},
215 {EIO, "phase error -- cannot happen"},
216 {EEXIST, "create -- file exists"},
217 {EINVAL, "create -- . and .. illegal names"},
218 {ENOTEMPTY, "remove -- directory not empty"},
219 {EINVAL, "attach -- privileged user"},
220 {EPERM, "wstat -- not owner"},
221 {EPERM, "wstat -- not in group"},
222 {EINVAL, "create/wstat -- bad character in file name"},
223 {EBUSY, "walk -- too many (system wide)"},
224 {EROFS, "file system read only"},
225 {ENOSPC, "file system full"},
226 {EINVAL, "read/write -- offset negative"},
227 {EBUSY, "open/create -- file is locked"},
228 {EBUSY, "close/read/write -- lock is broken"},
229
230 /* from sockets */
231 {ENOTSOCK, "not a socket"},
232 {EPROTONOSUPPORT, "protocol not supported"},
233 {ECONNREFUSED, "connection refused"},
234 {EAFNOSUPPORT, "address family not supported"},
235 {ENOBUFS, "insufficient buffer space"},
236 {EOPNOTSUPP, "operation not supported"},
237 {EADDRINUSE, "address in use"},
238
239 /* other */
240 {EEXIST, "file already exists"},
241 {EEXIST, "is a directory"},
242 {ENOTEMPTY, "directory not empty"},
243 };
244
245 int r, i;
246 char msg[ERRMAX];
247
248 rerrstr(msg, sizeof(msg));
249
250 r = -EIO;
251 for(i=0; i<nelem(t); i++){
252 if(strstr(msg, t[i].msg)){
253 r = -t[i].num;
254 break;
255 }
256 }
257
258 trace("mkerror(%s): %E", msg, r);
259 return r;
260 }
261
262 int sys_nosys(void)
263 {
264 trace("syscall %s not implemented", current->syscall);
265 return -ENOSYS;
266 }