xref: /freebsd/sys/compat/linux/linux_errno.inc (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 1994-1996 Søren Schmidt
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29/*
30 * Linux syscalls return negative errno's, we do positive and map them
31 * Reference:
32 *   FreeBSD: src/sys/sys/errno.h
33 *   Linux:   include/uapi/asm-generic/errno-base.h
34 *            include/uapi/asm-generic/errno.h
35 *
36 * XXX: The "XXX" comments below should be replaced with rationale
37 *      for the errno value chosen.
38 */
39static const int linux_errtbl[ELAST + 1] = {
40	/* [0, 9] */
41	[0] = -0,
42	[EPERM] = -LINUX_EPERM,
43	[ENOENT] = -LINUX_ENOENT,
44	[ESRCH] = -LINUX_ESRCH,
45	[EINTR] = -LINUX_EINTR,
46	[EIO] = -LINUX_EIO,
47	[ENXIO] = -LINUX_ENXIO,
48	[E2BIG] = -LINUX_E2BIG,
49	[ENOEXEC] = -LINUX_ENOEXEC,
50	[EBADF] = -LINUX_EBADF,
51
52	/* [10, 19] */
53	[ECHILD] = -LINUX_ECHILD,
54	[EDEADLK] = -LINUX_EDEADLK,
55	[ENOMEM] = -LINUX_ENOMEM,
56	[EACCES] = -LINUX_EACCES,
57	[EFAULT] = -LINUX_EFAULT,
58	[ENOTBLK] = -LINUX_ENOTBLK,
59	[EBUSY] = -LINUX_EBUSY,
60	[EEXIST] = -LINUX_EEXIST,
61	[EXDEV] = -LINUX_EXDEV,
62	[ENODEV] = -LINUX_ENODEV,
63
64	/* [20, 29] */
65	[ENOTDIR] = -LINUX_ENOTDIR,
66	[EISDIR] = -LINUX_EISDIR,
67	[EINVAL] = -LINUX_EINVAL,
68	[ENFILE] = -LINUX_ENFILE,
69	[EMFILE] = -LINUX_EMFILE,
70	[ENOTTY] = -LINUX_ENOTTY,
71	[ETXTBSY] = -LINUX_ETXTBSY,
72	[EFBIG] = -LINUX_EFBIG,
73	[ENOSPC] = -LINUX_ENOSPC,
74	[ESPIPE] = -LINUX_ESPIPE,
75
76	/* [30, 39] */
77	[EROFS] = -LINUX_EROFS,
78	[EMLINK] = -LINUX_EMLINK,
79	[EPIPE] = -LINUX_EPIPE,
80	[EDOM] = -LINUX_EDOM,
81	[ERANGE] = -LINUX_ERANGE,
82	[EAGAIN] = -LINUX_EAGAIN,
83	[EINPROGRESS] = -LINUX_EINPROGRESS,
84	[EALREADY] = -LINUX_EALREADY,
85	[ENOTSOCK] = -LINUX_ENOTSOCK,
86	[EDESTADDRREQ] = -LINUX_EDESTADDRREQ,
87
88	/* [40, 49] */
89	[EMSGSIZE] = -LINUX_EMSGSIZE,
90	[EPROTOTYPE] = -LINUX_EPROTOTYPE,
91	[ENOPROTOOPT] = -LINUX_ENOPROTOOPT,
92	[EPROTONOSUPPORT] = -LINUX_EPROTONOTSUPPORT,
93	[ESOCKTNOSUPPORT] = -LINUX_ESOCKNOTSUPPORT,
94	[EOPNOTSUPP] = -LINUX_EOPNOTSUPPORT,
95	[EPFNOSUPPORT] = -LINUX_EPFNOTSUPPORT,
96	[EAFNOSUPPORT] = -LINUX_EAFNOTSUPPORT,
97	[EADDRINUSE] = -LINUX_EADDRINUSE,
98	[EADDRNOTAVAIL] = -LINUX_EADDRNOTAVAIL,
99
100	/* [50, 59] */
101	[ENETDOWN] = -LINUX_ENETDOWN,
102	[ENETUNREACH] = -LINUX_ENETUNREACH,
103	[ENETRESET] = -LINUX_ENETRESET,
104	[ECONNABORTED] = -LINUX_ECONNABORTED,
105	[ECONNRESET] = -LINUX_ECONNRESET,
106	[ENOBUFS] = -LINUX_ENOBUFS,
107	[EISCONN] = -LINUX_EISCONN,
108	[ENOTCONN] = -LINUX_ENOTCONN,
109	[ESHUTDOWN] = -LINUX_ESHUTDOWN,
110	[ETOOMANYREFS] = -LINUX_ETOOMANYREFS,
111
112	/* [60, 69] */
113	[ETIMEDOUT] = -LINUX_ETIMEDOUT,
114	[ECONNREFUSED] = -LINUX_ECONNREFUSED,
115	[ELOOP] = -LINUX_ELOOP,
116	[ENAMETOOLONG] = -LINUX_ENAMETOOLONG,
117	[EHOSTDOWN] = -LINUX_EHOSTDOWN,
118	[EHOSTUNREACH] = -LINUX_EHOSTUNREACH,
119	[ENOTEMPTY] = -LINUX_ENOTEMPTY,
120	[EPROCLIM] = -LINUX_EAGAIN,	/* XXX */
121	[EUSERS] = -LINUX_EUSERS,
122	[EDQUOT] = -LINUX_EDQUOT,
123
124	/* [70, 79] */
125	[ESTALE] = -LINUX_ESTALE,
126	[EREMOTE] = -LINUX_EREMOTE,
127	[EBADRPC] = -LINUX_ENXIO,	/* XXX */
128	[ERPCMISMATCH] = -LINUX_ENXIO,	/* XXX */
129	[EPROGUNAVAIL] = -LINUX_ENXIO,	/* XXX */
130	[EPROGMISMATCH] = -LINUX_ENXIO,	/* XXX */
131	[EPROCUNAVAIL] = -LINUX_ENXIO,	/* XXX */
132	[ENOLCK] = -LINUX_ENOLCK,
133	[ENOSYS] = -LINUX_ENOSYS,
134	[EFTYPE] = -LINUX_EBADF,	/* XXX */
135
136	/* [80, 89] */
137	[EAUTH] = -LINUX_ENXIO,		/* XXX */
138	[ENEEDAUTH] = -LINUX_ENXIO,	/* XXX */
139	[EIDRM] = -LINUX_EIDRM,
140	[ENOMSG] = -LINUX_ENOMSG,
141	[EOVERFLOW] = -LINUX_EOVERFLOW,
142	[ECANCELED] = -LINUX_ECANCELED,
143	[EILSEQ] = -LINUX_EILSEQ,
144	[ENOATTR] = -LINUX_ENODATA,	/* XXX */
145	[EDOOFUS] = -LINUX_EINVAL,	/* XXX */
146	[EBADMSG] = -LINUX_EBADMSG,
147
148	/* [90, 99] */
149	[EMULTIHOP] = -LINUX_EMULTIHOP,
150	[ENOLINK] = -LINUX_ENOLINK,
151	[EPROTO] = -LINUX_EPROTO,
152	[ENOTCAPABLE] = -LINUX_EPERM,	/* XXX */
153	[ECAPMODE] = -LINUX_EPERM,	/* XXX */
154	[ENOTRECOVERABLE] = -LINUX_ENOTRECOVERABLE,
155	[EOWNERDEAD] = -LINUX_EOWNERDEAD,
156	[EINTEGRITY] = -LINUX_EINVAL,	/* XXX */
157};
158
159_Static_assert(ELAST == 97,
160    "missing errno entries in linux_errtbl");
161
162static const int linux_to_bsd_errtbl[LINUX_ELAST + 1] = {
163	/* [0, 9] */
164	[0] = 0,
165	[LINUX_EPERM] = EPERM,
166	[LINUX_ENOENT] = ENOENT,
167	[LINUX_ESRCH] = ESRCH,
168	[LINUX_EINTR] = EINTR,
169	[LINUX_EIO] = EIO,
170	[LINUX_ENXIO] = ENXIO,
171	[LINUX_E2BIG] = E2BIG,
172	[LINUX_ENOEXEC] = ENOENT,
173	[LINUX_EBADF] = EBADF,
174
175	/* [10, 19] */
176	[LINUX_ECHILD] = ECHILD,
177	[LINUX_EAGAIN] = EAGAIN,
178	[LINUX_ENOMEM] = ENOMEM,
179	[LINUX_EACCES] = EACCES,
180	[LINUX_EFAULT] = EFAULT,
181	[LINUX_ENOTBLK] = ENOTBLK,
182	[LINUX_EBUSY] = EBUSY,
183	[LINUX_EEXIST] = EEXIST,
184	[LINUX_EXDEV] = EXDEV,
185	[LINUX_ENODEV] = ENODEV,
186
187	/* [20, 29] */
188	[LINUX_ENOTDIR] = ENOTDIR,
189	[LINUX_EISDIR] = EISDIR,
190	[LINUX_EINVAL] = EINVAL,
191	[LINUX_ENFILE] = ENFILE,
192	[LINUX_EMFILE] = EMFILE,
193	[LINUX_ENOTTY] = ENOTTY,
194	[LINUX_ETXTBSY] = ETXTBSY,
195	[LINUX_EFBIG] = EFBIG,
196	[LINUX_ENOSPC] = ENOSPC,
197	[LINUX_ESPIPE] = ESPIPE,
198
199	/* [30, 39] */
200	[LINUX_EROFS] = EROFS,
201	[LINUX_EMLINK] = EMLINK,
202	[LINUX_EPIPE] = EPIPE,
203	[LINUX_EDOM] = EDOM,
204	[LINUX_ERANGE] = ERANGE,
205	[LINUX_EDEADLK] = EDEADLK,
206	[LINUX_ENAMETOOLONG] = ENAMETOOLONG,
207	[LINUX_ENOLCK] = ENOLCK,
208	[LINUX_ENOSYS] = ENOSYS,
209	[LINUX_ENOTEMPTY] = ENOTEMPTY,
210
211	/* [40, 49] */
212	[LINUX_ELOOP] = ELOOP,
213	[41] = EINVAL,
214	[LINUX_ENOMSG] = ENOMSG,
215	[LINUX_EIDRM] = EIDRM,
216	[LINUX_ECHRNG] = EINVAL,	/* XXX */
217	[LINUX_EL2NSYNC] = EINVAL,	/* XXX */
218	[LINUX_EL3HLT] = EINVAL,	/* XXX */
219	[LINUX_EL3RST] = EINVAL,	/* XXX */
220	[LINUX_ELNRNG] = EINVAL,	/* XXX */
221	[LINUX_EUNATCH] = EINVAL,	/* XXX */
222
223	/* [50, 59] */
224	[LINUX_ENOCSI] = EINVAL,	/* XXX */
225	[LINUX_EL2HLT] = EINVAL,	/* XXX */
226	[LINUX_EBADE] = EINVAL,		/* XXX */
227	[LINUX_EBADR] = EINVAL,		/* XXX */
228	[LINUX_EXFULL] = EINVAL,	/* XXX */
229	[LINUX_ENOANO] = EINVAL,	/* XXX */
230	[LINUX_EBADRQC] = EINVAL,	/* XXX */
231	[LINUX_EBADSLT] = EINVAL,	/* XXX */
232	[58] = EINVAL,
233	[LINUX_EBFONT] = EINVAL,	/* XXX */
234
235	/* [60, 69] */
236	[LINUX_ENOSTR] = EINVAL,	/* XXX */
237	[LINUX_ENODATA] = ENOATTR,	/* XXX */
238	[LINUX_ENOTIME] = EINVAL,	/* XXX */
239	[LINUX_ENOSR] = EINVAL,		/* XXX */
240	[LINUX_ENONET] = EINVAL,	/* XXX */
241	[LINUX_ENOPKG] = EINVAL,	/* XXX */
242	[LINUX_EREMOTE] = EREMOTE,
243	[LINUX_ENOLINK] = ENOLINK,
244	[LINUX_EADV] = EINVAL,		/* XXX */
245	[LINUX_ESRMNT] = EINVAL,	/* XXX */
246
247	/* [70, 79] */
248	[LINUX_ECOMM] = EINVAL,		/* XXX */
249	[LINUX_EPROTO] = EPROTO,
250	[LINUX_EMULTIHOP] = EMULTIHOP,
251	[LINUX_EDOTDOT] = EINVAL,	/* XXX */
252	[LINUX_EBADMSG] = EBADMSG,
253	[LINUX_EOVERFLOW] = EOVERFLOW,
254	[LINUX_ENOTUNIQ] = EINVAL,	/* XXX */
255	[LINUX_EBADFD] = EBADF,		/* XXX */
256	[LINUX_EREMCHG] = EINVAL,	/* XXX */
257	[LINUX_ELIBACC] = EINVAL,	/* XXX */
258
259	/* [80, 89] */
260	[LINUX_ELIBBAD] = EINVAL,	/* XXX */
261	[LINUX_ELIBSCN] = EINVAL,	/* XXX */
262	[LINUX_ELIBMAX] = EINVAL,	/* XXX */
263	[LINUX_ELIBEXEC] = EINVAL,	/* XXX */
264	[LINUX_EILSEQ] = EILSEQ,
265	[LINUX_ERESTART] = EAGAIN,	/* XXX */
266	[LINUX_ESTRPIPE] = EINVAL,	/* XXX */
267	[LINUX_EUSERS] = EUSERS,
268	[LINUX_ENOTSOCK] = ENOTSOCK,
269	[LINUX_EDESTADDRREQ] = EDESTADDRREQ,
270
271	/* [90, 99] */
272	[LINUX_EMSGSIZE] = EMSGSIZE,
273	[LINUX_EPROTOTYPE] = EPROTOTYPE,
274	[LINUX_ENOPROTOOPT] = ENOPROTOOPT,
275	[LINUX_EPROTONOTSUPPORT] = EPROTONOSUPPORT,
276	[LINUX_ESOCKNOTSUPPORT] = EPROTONOSUPPORT,	/* XXX */
277	[LINUX_EOPNOTSUPPORT] = EOPNOTSUPP,
278	[LINUX_EPFNOTSUPPORT] = EPFNOSUPPORT,
279	[LINUX_EAFNOTSUPPORT] = EAFNOSUPPORT,
280	[LINUX_EADDRINUSE] = EADDRINUSE,
281	[LINUX_EADDRNOTAVAIL] = EADDRNOTAVAIL,
282
283	/* [100, 109] */
284	[LINUX_ENETDOWN] = ENETDOWN,
285	[LINUX_ENETUNREACH] = ENETUNREACH,
286	[LINUX_ENETRESET] = ENETRESET,
287	[LINUX_ECONNABORTED] = ECONNABORTED,
288	[LINUX_ECONNRESET] = ECONNRESET,
289	[LINUX_ENOBUFS] = ENOBUFS,
290	[LINUX_EISCONN] = EISCONN,
291	[LINUX_ENOTCONN] = ENOTCONN,
292	[LINUX_ESHUTDOWN] = ESHUTDOWN,
293	[LINUX_ETOOMANYREFS] = ETOOMANYREFS,
294
295	/* [110, 119] */
296	[LINUX_ETIMEDOUT] = ETIMEDOUT,
297	[LINUX_ECONNREFUSED] = ECONNREFUSED,
298	[LINUX_EHOSTDOWN] = EHOSTDOWN,
299	[LINUX_EHOSTUNREACH] = EHOSTUNREACH,
300	[LINUX_EALREADY] = EALREADY,
301	[LINUX_EINPROGRESS] = EINPROGRESS,
302	[LINUX_ESTALE] = ESTALE,
303	[LINUX_EUCLEAN] = EINVAL,		/* XXX */
304	[LINUX_ENOTNAM] = EINVAL,		/* XXX */
305	[LINUX_ENAVAIL] = EINVAL,		/* XXX */
306
307	/* [120, 129] */
308	[LINUX_EISNAM] = EINVAL,		/* XXX */
309	[LINUX_EREMOTEIO] = EINVAL,		/* XXX */
310	[LINUX_EDQUOT] = EDQUOT,
311	[LINUX_ENOMEDIUM] = EIO,		/* XXX */
312	[LINUX_EMEDIUMTYPE] = EIO,		/* XXX */
313	[LINUX_ECANCELED] = ECANCELED,
314	[LINUX_ENOKEY] = EIO,			/* XXX */
315	[LINUX_EKEYEXPIRED] = EIO,		/* XXX */
316	[LINUX_EKEYREVOKED] = EIO,		/* XXX */
317	[LINUX_EKEYREJECTED] = EIO,		/* XXX */
318
319	/* [130, 139] */
320	[LINUX_EOWNERDEAD] = EOWNERDEAD,
321	[LINUX_ENOTRECOVERABLE] = ENOTRECOVERABLE,
322	[LINUX_ERFKILL] = ENETDOWN,		/* XXX */
323	[LINUX_EHWPOISON] = EINVAL,		/* XXX */
324};
325
326_Static_assert(LINUX_ELAST == 133,
327    "missing errno entries in linux_to_bsd_errtbl");
328