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