xref: /freebsd/sys/xen/error.h (revision f4b37ed0f8b307b1f3f0f630ca725d68f1dff30d)
1 /*-
2  * Copyright (c) 2014 Roger Pau Monné <royger@FreeBSD.org>.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #ifndef __XEN_ERROR_H__
30 #define __XEN_ERROR_H__
31 
32 /* List of Xen error codes */
33 #define	XEN_EPERM		 1	/* Operation not permitted */
34 #define	XEN_ENOENT		 2	/* No such file or directory */
35 #define	XEN_ESRCH		 3	/* No such process */
36 #define	XEN_EINTR		 4	/* Interrupted system call */
37 #define	XEN_EIO			 5	/* I/O error */
38 #define	XEN_ENXIO		 6	/* No such device or address */
39 #define	XEN_E2BIG		 7	/* Arg list too long */
40 #define	XEN_ENOEXEC		 8	/* Exec format error */
41 #define	XEN_EBADF		 9	/* Bad file number */
42 #define	XEN_ECHILD		10	/* No child processes */
43 #define	XEN_EAGAIN		11	/* Try again */
44 #define	XEN_ENOMEM		12	/* Out of memory */
45 #define	XEN_EACCES		13	/* Permission denied */
46 #define	XEN_EFAULT		14	/* Bad address */
47 #define	XEN_ENOTBLK		15	/* Block device required */
48 #define	XEN_EBUSY		16	/* Device or resource busy */
49 #define	XEN_EEXIST		17	/* File exists */
50 #define	XEN_EXDEV		18	/* Cross-device link */
51 #define	XEN_ENODEV		19	/* No such device */
52 #define	XEN_ENOTDIR		20	/* Not a directory */
53 #define	XEN_EISDIR		21	/* Is a directory */
54 #define	XEN_EINVAL		22	/* Invalid argument */
55 #define	XEN_ENFILE		23	/* File table overflow */
56 #define	XEN_EMFILE		24	/* Too many open files */
57 #define	XEN_ENOTTY		25	/* Not a typewriter */
58 #define	XEN_ETXTBSY		26	/* Text file busy */
59 #define	XEN_EFBIG		27	/* File too large */
60 #define	XEN_ENOSPC		28	/* No space left on device */
61 #define	XEN_ESPIPE		29	/* Illegal seek */
62 #define	XEN_EROFS		30	/* Read-only file system */
63 #define	XEN_EMLINK		31	/* Too many links */
64 #define	XEN_EPIPE		32	/* Broken pipe */
65 #define	XEN_EDOM		33	/* Math argument out of domain of func */
66 #define	XEN_ERANGE		34	/* Math result not representable */
67 #define	XEN_EDEADLK		35	/* Resource deadlock would occur */
68 #define	XEN_ENAMETOOLONG	36	/* File name too long */
69 #define	XEN_ENOLCK		37	/* No record locks available */
70 #define	XEN_ENOSYS		38	/* Function not implemented */
71 #define	XEN_ENOTEMPTY	 	39	/* Directory not empty */
72 #define	XEN_ELOOP		40	/* Too many symbolic links encountered */
73 #define	XEN_ENOMSG		42	/* No message of desired type */
74 #define	XEN_EIDRM		43	/* Identifier removed */
75 #define	XEN_ECHRNG		44	/* Channel number out of range */
76 #define	XEN_EL2NSYNC		45	/* Level 2 not synchronized */
77 #define	XEN_EL3HLT		46	/* Level 3 halted */
78 #define	XEN_EL3RST		47	/* Level 3 reset */
79 #define	XEN_ELNRNG		48	/* Link number out of range */
80 #define	XEN_EUNATCH		49	/* Protocol driver not attached */
81 #define	XEN_ENOCSI		50	/* No CSI structure available */
82 #define	XEN_EL2HLT		51	/* Level 2 halted */
83 #define	XEN_EBADE		52	/* Invalid exchange */
84 #define	XEN_EBADR		53	/* Invalid request descriptor */
85 #define	XEN_EXFULL		54	/* Exchange full */
86 #define	XEN_ENOANO		55	/* No anode */
87 #define	XEN_EBADRQC		56	/* Invalid request code */
88 #define	XEN_EBADSLT		57	/* Invalid slot */
89 #define	XEN_EBFONT		59	/* Bad font file format */
90 #define	XEN_ENOSTR		60	/* Device not a stream */
91 #define	XEN_ENODATA		61	/* No data available */
92 #define	XEN_ETIME		62	/* Timer expired */
93 #define	XEN_ENOSR		63	/* Out of streams resources */
94 #define	XEN_ENONET		64	/* Machine is not on the network */
95 #define	XEN_ENOPKG		65	/* Package not installed */
96 #define	XEN_EREMOTE		66	/* Object is remote */
97 #define	XEN_ENOLINK		67	/* Link has been severed */
98 #define	XEN_EADV		68	/* Advertise error */
99 #define	XEN_ESRMNT		69	/* Srmount error */
100 #define	XEN_ECOMM		70	/* Communication error on send */
101 #define	XEN_EPROTO		71	/* Protocol error */
102 #define	XEN_EMULTIHOP		72	/* Multihop attempted */
103 #define	XEN_EDOTDOT		73	/* RFS specific error */
104 #define	XEN_EBADMSG		74	/* Not a data message */
105 #define	XEN_EOVERFLOW		75	/* Value too large for defined data type */
106 #define	XEN_ENOTUNIQ		76	/* Name not unique on network */
107 #define	XEN_EBADFD		77	/* File descriptor in bad state */
108 #define	XEN_EREMCHG		78	/* Remote address changed */
109 #define	XEN_ELIBACC		79	/* Can not access a needed shared library */
110 #define	XEN_ELIBBAD		80	/* Accessing a corrupted shared library */
111 #define	XEN_ELIBSCN		81	/* .lib section in a.out corrupted */
112 #define	XEN_ELIBMAX		82	/* Attempting to link in too many shared libraries */
113 #define	XEN_ELIBEXEC		83	/* Cannot exec a shared library directly */
114 #define	XEN_EILSEQ		84	/* Illegal byte sequence */
115 #define	XEN_ERESTART		85	/* Interrupted system call should be restarted */
116 #define	XEN_ESTRPIPE		86	/* Streams pipe error */
117 #define	XEN_EUSERS		87	/* Too many users */
118 #define	XEN_ENOTSOCK		88	/* Socket operation on non-socket */
119 #define	XEN_EDESTADDRREQ	89	/* Destination address required */
120 #define	XEN_EMSGSIZE		90	/* Message too long */
121 #define	XEN_EPROTOTYPE		91	/* Protocol wrong type for socket */
122 #define	XEN_ENOPROTOOPT		92	/* Protocol not available */
123 #define	XEN_EPROTONOSUPPORT	93	/* Protocol not supported */
124 #define	XEN_ESOCKTNOSUPPORT	94	/* Socket type not supported */
125 #define	XEN_EOPNOTSUPP		95	/* Operation not supported on transport endpoint */
126 #define	XEN_EPFNOSUPPORT	96	/* Protocol family not supported */
127 #define	XEN_EAFNOSUPPORT	97	/* Address family not supported by protocol */
128 #define	XEN_EADDRINUSE		98	/* Address already in use */
129 #define	XEN_EADDRNOTAVAIL	99	/* Cannot assign requested address */
130 #define	XEN_ENETDOWN		100	/* Network is down */
131 #define	XEN_ENETUNREACH		101	/* Network is unreachable */
132 #define	XEN_ENETRESET		102	/* Network dropped connection because of reset */
133 #define	XEN_ECONNABORTED	103	/* Software caused connection abort */
134 #define	XEN_ECONNRESET		104	/* Connection reset by peer */
135 #define	XEN_ENOBUFS		105	/* No buffer space available */
136 #define	XEN_EISCONN		106	/* Transport endpoint is already connected */
137 #define	XEN_ENOTCONN		107	/* Transport endpoint is not connected */
138 #define	XEN_ESHUTDOWN		108	/* Cannot send after transport endpoint shutdown */
139 #define	XEN_ETOOMANYREFS	109	/* Too many references: cannot splice */
140 #define	XEN_ETIMEDOUT		110	/* Connection timed out */
141 #define	XEN_ECONNREFUSED	111	/* Connection refused */
142 #define	XEN_EHOSTDOWN		112	/* Host is down */
143 #define	XEN_EHOSTUNREACH	113	/* No route to host */
144 #define	XEN_EALREADY		114	/* Operation already in progress */
145 #define	XEN_EINPROGRESS		115	/* Operation now in progress */
146 #define	XEN_ESTALE		116	/* Stale NFS file handle */
147 #define	XEN_EUCLEAN		117	/* Structure needs cleaning */
148 #define	XEN_ENOTNAM		118	/* Not a XENIX named type file */
149 #define	XEN_ENAVAIL		119	/* No XENIX semaphores available */
150 #define	XEN_EISNAM		120	/* Is a named type file */
151 #define	XEN_EREMOTEIO		121	/* Remote I/O error */
152 #define	XEN_EDQUOT		122	/* Quota exceeded */
153 
154 #define	XEN_ENOMEDIUM		123	/* No medium found */
155 #define	XEN_EMEDIUMTYPE		124	/* Wrong medium type */
156 
157 /* Translation table */
158 static int xen_errors[] =
159 {
160 	[XEN_EPERM]		= EPERM,
161 	[XEN_ENOENT]		= ENOENT,
162 	[XEN_ESRCH]		= ESRCH,
163 	[XEN_EINTR]		= EINTR,
164 	[XEN_EIO]		= EIO,
165 	[XEN_ENXIO]		= ENXIO,
166 	[XEN_E2BIG]		= E2BIG,
167 	[XEN_ENOEXEC]		= ENOEXEC,
168 	[XEN_EBADF]		= EBADF,
169 	[XEN_ECHILD]		= ECHILD,
170 	[XEN_EAGAIN]		= EAGAIN,
171 	[XEN_ENOMEM]		= ENOMEM,
172 	[XEN_EACCES]		= EACCES,
173 	[XEN_EFAULT]		= EFAULT,
174 	[XEN_ENOTBLK]		= ENOTBLK,
175 	[XEN_EBUSY]		= EBUSY,
176 	[XEN_EEXIST]		= EEXIST,
177 	[XEN_EXDEV]		= EXDEV,
178 	[XEN_ENODEV]		= ENODEV,
179 	[XEN_ENOTDIR]		= ENOTDIR,
180 	[XEN_EISDIR]		= EISDIR,
181 	[XEN_EINVAL]		= EINVAL,
182 	[XEN_ENFILE]		= ENFILE,
183 	[XEN_EMFILE]		= EMFILE,
184 	[XEN_ENOTTY]		= ENOTTY,
185 	[XEN_ETXTBSY]		= ETXTBSY,
186 	[XEN_EFBIG]		= EFBIG,
187 	[XEN_ENOSPC]		= ENOSPC,
188 	[XEN_ESPIPE]		= ESPIPE,
189 	[XEN_EROFS]		= EROFS,
190 	[XEN_EMLINK]		= EMLINK,
191 	[XEN_EPIPE]		= EPIPE,
192 	[XEN_EDOM]		= EDOM,
193 	[XEN_ERANGE]		= ERANGE,
194 	[XEN_EDEADLK]		= EDEADLK,
195 	[XEN_ENAMETOOLONG]	= ENAMETOOLONG,
196 	[XEN_ENOLCK]		= ENOLCK,
197 	[XEN_ENOSYS]		= ENOSYS,
198 	[XEN_ENOTEMPTY]		= ENOTEMPTY,
199 	[XEN_ELOOP]		= ELOOP,
200 	[XEN_ENOMSG]		= ENOMSG,
201 	[XEN_EIDRM]		= EIDRM,
202 	[XEN_ECHRNG]		= ERANGE,
203 	[XEN_EL2NSYNC]		= EFAULT,
204 	[XEN_EL3HLT]		= EFAULT,
205 	[XEN_EL3RST]		= EFAULT,
206 	[XEN_ELNRNG]		= ERANGE,
207 	[XEN_EUNATCH]		= ENODEV,
208 	[XEN_ENOCSI]		= ENODEV,
209 	[XEN_EL2HLT]		= EFAULT,
210 	[XEN_EBADE]		= ERANGE,
211 	[XEN_EBADR]		= EINVAL,
212 	[XEN_EXFULL]		= ENOBUFS,
213 	[XEN_ENOANO]		= EINVAL,
214 	[XEN_EBADRQC]		= EINVAL,
215 	[XEN_EBADSLT]		= EINVAL,
216 	[XEN_EBFONT]		= EFAULT,
217 	[XEN_ENOSTR]		= EINVAL,
218 	[XEN_ENODATA]		= ENOENT,
219 	[XEN_ETIME]		= ETIMEDOUT,
220 	[XEN_ENOSR]		= EFAULT,
221 	[XEN_ENONET]		= ENETDOWN,
222 	[XEN_ENOPKG]		= EINVAL,
223 	[XEN_EREMOTE]		= EREMOTE,
224 	[XEN_ENOLINK]		= ENOLINK,
225 	[XEN_EADV]		= EFAULT,
226 	[XEN_ESRMNT]		= EFAULT,
227 	[XEN_ECOMM]		= EFAULT,
228 	[XEN_EPROTO]		= EPROTO,
229 	[XEN_EMULTIHOP]		= EMULTIHOP,
230 	[XEN_EDOTDOT]		= EFAULT,
231 	[XEN_EBADMSG]		= EBADMSG,
232 	[XEN_EOVERFLOW]		= EOVERFLOW,
233 	[XEN_ENOTUNIQ]		= EADDRINUSE,
234 	[XEN_EBADFD]		= EBADF,
235 	[XEN_EREMCHG]		= EHOSTDOWN,
236 	[XEN_ELIBACC]		= EFAULT,
237 	[XEN_ELIBBAD]		= EFAULT,
238 	[XEN_ELIBSCN]		= EFAULT,
239 	[XEN_ELIBMAX]		= EFAULT,
240 	[XEN_ELIBEXEC]		= EFAULT,
241 	[XEN_EILSEQ]		= EILSEQ,
242 	[XEN_ERESTART]		= EAGAIN,
243 	[XEN_ESTRPIPE]		= EPIPE,
244 	[XEN_EUSERS]		= EUSERS,
245 	[XEN_ENOTSOCK]		= ENOTSOCK,
246 	[XEN_EDESTADDRREQ]	= EDESTADDRREQ,
247 	[XEN_EMSGSIZE]		= EMSGSIZE,
248 	[XEN_EPROTOTYPE]	= EPROTOTYPE,
249 	[XEN_ENOPROTOOPT]	= ENOPROTOOPT,
250 	[XEN_EPROTONOSUPPORT]	= EPROTONOSUPPORT,
251 	[XEN_ESOCKTNOSUPPORT]	= ESOCKTNOSUPPORT,
252 	[XEN_EOPNOTSUPP]	= EOPNOTSUPP,
253 	[XEN_EPFNOSUPPORT]	= EPFNOSUPPORT,
254 	[XEN_EAFNOSUPPORT]	= EAFNOSUPPORT,
255 	[XEN_EADDRINUSE]	= EADDRINUSE,
256 	[XEN_EADDRNOTAVAIL]	= EADDRNOTAVAIL,
257 	[XEN_ENETDOWN]		= ENETDOWN,
258 	[XEN_ENETUNREACH]	= ENETUNREACH,
259 	[XEN_ENETRESET]		= ENETRESET,
260 	[XEN_ECONNABORTED]	= ECONNABORTED,
261 	[XEN_ECONNRESET]	= ECONNRESET,
262 	[XEN_ENOBUFS]		= ENOBUFS,
263 	[XEN_EISCONN]		= EISCONN,
264 	[XEN_ENOTCONN]		= ENOTCONN,
265 	[XEN_ESHUTDOWN]		= ESHUTDOWN,
266 	[XEN_ETOOMANYREFS]	= ETOOMANYREFS,
267 	[XEN_ETIMEDOUT]		= ETIMEDOUT,
268 	[XEN_ECONNREFUSED]	= ECONNREFUSED,
269 	[XEN_EHOSTDOWN]		= EHOSTDOWN,
270 	[XEN_EHOSTUNREACH]	= EHOSTUNREACH,
271 	[XEN_EALREADY]		= EALREADY,
272 	[XEN_EINPROGRESS]	= EINPROGRESS,
273 	[XEN_ESTALE]		= ESTALE,
274 	[XEN_EUCLEAN]		= EFAULT,
275 	[XEN_ENOTNAM]		= EFAULT,
276 	[XEN_ENAVAIL]		= EFAULT,
277 	[XEN_EISNAM]		= EFAULT,
278 	[XEN_EREMOTEIO]		= EIO,
279 	[XEN_EDQUOT]		= EDQUOT,
280 	[XEN_ENOMEDIUM]		= ENOENT,
281 	[XEN_EMEDIUMTYPE]	= ENOENT,
282 };
283 
284 static inline int
285 xen_translate_error(int error)
286 {
287 	int bsd_error;
288 
289 	KASSERT((error < 0), ("Value is not a valid Xen error code"));
290 
291 	if (-error >= nitems(xen_errors)) {
292 		/*
293 		 * We received an error value that cannot be translated,
294 		 * return EINVAL.
295 		 */
296 		return (EINVAL);
297 	}
298 
299 	bsd_error = xen_errors[-error];
300 	KASSERT((bsd_error != 0), ("Unknown Xen error code"));
301 
302 	return (bsd_error);
303 }
304 
305 #endif /* !__XEN_ERROR_H__ */
306