VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/err/RTErrConvertFromErrno.cpp@ 18426

Last change on this file since 18426 was 18329, checked in by vboxsync, 16 years ago

iprt/err.h: Added VERR_INTERNAL_ERROR_2 and VERR_INTERNAL_ERROR_3 for debugging purposes (too many VERR_INTERNAL_ERROR returns around). Translate the BSD EDOOFUS to VERR_INTERNAL_ERROR (just for kicks).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 13.0 KB
Line 
1/* $Id: RTErrConvertFromErrno.cpp 18329 2009-03-26 17:20:09Z vboxsync $ */
2/** @file
3 * IPRT - Convert errno to iprt status codes.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include <iprt/err.h>
36#include <iprt/assert.h>
37#include <iprt/err.h>
38
39#if defined(RT_OS_DARWIN) && defined(KERNEL)
40# include <sys/errno.h>
41#elif defined(RT_OS_LINUX) && defined(__KERNEL__)
42# include <linux/errno.h>
43#else
44# include <errno.h>
45#endif
46
47
48RTDECL(int) RTErrConvertFromErrno(unsigned uNativeCode)
49{
50 /* very fast check for no error. */
51 if (uNativeCode == 0)
52 return VINF_SUCCESS;
53
54 /*
55 * Process error codes.
56 *
57 * (Use a switch and not a table since the numbers vary among compilers
58 * and OSes. So we let the compiler switch optimizer handle speed issues.)
59 *
60 * This switch is arranged like the Linux i386 errno.h! This switch is mirrored
61 * by RTErrConvertToErrno.
62 */
63 switch (uNativeCode)
64 { /* Linux number */
65#ifdef EPERM
66 case EPERM: return VERR_ACCESS_DENIED; /* 1 */
67#endif
68#ifdef ENOENT
69 case ENOENT: return VERR_FILE_NOT_FOUND;
70#endif
71#ifdef ESRCH
72 case ESRCH: return VERR_PROCESS_NOT_FOUND;
73#endif
74#ifdef EINTR
75 case EINTR: return VERR_INTERRUPTED;
76#endif
77#ifdef EIO
78 case EIO: return VERR_DEV_IO_ERROR;
79#endif
80#ifdef ENXIO
81 case ENXIO: return VERR_DEV_IO_ERROR; /**@todo fix this duplicate error */
82#endif
83#ifdef E2BIG
84 case E2BIG: return VERR_TOO_MUCH_DATA;
85#endif
86#ifdef ENOEXEC
87 case ENOEXEC: return VERR_BAD_EXE_FORMAT;
88#endif
89#ifdef EBADF
90 case EBADF: return VERR_INVALID_HANDLE;
91#endif
92#ifdef ECHILD
93 case ECHILD: return VERR_PROCESS_NOT_FOUND; /* 10 */ /**@todo fix duplicate error */
94#endif
95#ifdef EAGAIN
96 case EAGAIN: return VERR_TRY_AGAIN;
97#endif
98#ifdef ENOMEM
99 case ENOMEM: return VERR_NO_MEMORY;
100#endif
101#ifdef EACCES
102 case EACCES: return VERR_ACCESS_DENIED; /**@todo fix duplicate error */
103#endif
104#ifdef EFAULT
105 case EFAULT: return VERR_INVALID_POINTER;
106#endif
107#ifdef ENOTBLK
108 //case ENOTBLK: return VERR_;
109#endif
110#ifdef EBUSY
111 case EBUSY: return VERR_DEV_IO_ERROR; /**@todo fix duplicate error */
112#endif
113#ifdef EEXIST
114 case EEXIST: return VERR_ALREADY_EXISTS;
115#endif
116#ifdef EXDEV
117 case EXDEV: return VERR_NOT_SAME_DEVICE;
118#endif
119#ifdef ENODEV
120 case ENODEV: return VERR_NOT_SUPPORTED; /**@todo fix duplicate error */
121#endif
122#ifdef ENOTDIR
123 case ENOTDIR: return VERR_PATH_NOT_FOUND; /* 20 */
124#endif
125#ifdef EISDIR
126 case EISDIR: return VERR_IS_A_DIRECTORY;
127#endif
128#ifdef EINVAL
129 case EINVAL: return VERR_INVALID_PARAMETER;
130#endif
131#ifdef ENFILE
132 case ENFILE: return VERR_TOO_MANY_OPEN_FILES; /**@Todo fix duplicate error */
133#endif
134#ifdef EMFILE
135 case EMFILE: return VERR_TOO_MANY_OPEN_FILES;
136#endif
137#ifdef ENOTTY
138 case ENOTTY: return VERR_INVALID_FUNCTION;
139#endif
140#ifdef ETXTBSY
141 case ETXTBSY: return VERR_SHARING_VIOLATION;
142#endif
143#ifdef EFBIG
144 case EFBIG: return VERR_FILE_TOO_BIG;
145#endif
146#ifdef ENOSPC
147 case ENOSPC: return VERR_DISK_FULL;
148#endif
149#ifdef ESPIPE
150 case ESPIPE: return VERR_SEEK_ON_DEVICE;
151#endif
152#ifdef EROFS
153 case EROFS: return VERR_WRITE_PROTECT; /* 30 */
154#endif
155#ifdef EMLINK
156 //case EMLINK:
157#endif
158#ifdef EPIPE
159 case EPIPE: return VERR_BROKEN_PIPE;
160#endif
161#ifdef EDOM
162 case EDOM: return VERR_INVALID_PARAMETER; /**@todo fix duplicate error */
163#endif
164#ifdef ERANGE
165 case ERANGE: return VERR_INVALID_PARAMETER; /**@todo fix duplicate error */
166#endif
167#ifdef EDEADLK
168 case EDEADLK: return VERR_DEADLOCK;
169#endif
170#ifdef ENAMETOOLONG
171 case ENAMETOOLONG: return VERR_FILENAME_TOO_LONG;
172#endif
173#ifdef ENOLCK
174 case ENOLCK: return VERR_FILE_LOCK_FAILED;
175#endif
176#ifdef ENOSYS /** @todo map this differently on solaris. */
177 case ENOSYS: return VERR_NOT_SUPPORTED;
178#endif
179#ifdef ENOTEMPTY
180 case ENOTEMPTY: return VERR_DIR_NOT_EMPTY;
181#endif
182#ifdef ELOOP
183 case ELOOP: return VERR_TOO_MANY_SYMLINKS; /* 40 */
184#endif
185 //41??
186#ifdef ENOMSG
187 //case ENOMSG 42 /* No message of desired type */
188#endif
189#ifdef EIDRM
190 //case EIDRM 43 /* Identifier removed */
191#endif
192#ifdef ECHRNG
193 //case ECHRNG 44 /* Channel number out of range */
194#endif
195#ifdef EL2NSYNC
196 //case EL2NSYNC 45 /* Level 2 not synchronized */
197#endif
198#ifdef EL3HLT
199 //case EL3HLT 46 /* Level 3 halted */
200#endif
201#ifdef EL3RST
202 //case EL3RST 47 /* Level 3 reset */
203#endif
204#ifdef ELNRNG
205 //case ELNRNG 48 /* Link number out of range */
206#endif
207#ifdef EUNATCH
208 //case EUNATCH 49 /* Protocol driver not attached */
209#endif
210#ifdef ENOCSI
211 //case ENOCSI 50 /* No CSI structure available */
212#endif
213#ifdef EL2HLT
214 //case EL2HLT 51 /* Level 2 halted */
215#endif
216#ifdef EBADE
217 //case EBADE 52 /* Invalid exchange */
218#endif
219#ifdef EBADR
220 //case EBADR 53 /* Invalid request descriptor */
221#endif
222#ifdef EXFULL
223 //case EXFULL 54 /* Exchange full */
224#endif
225#ifdef ENOANO
226 //case ENOANO 55 /* No anode */
227#endif
228#ifdef EBADRQC
229 //case EBADRQC 56 /* Invalid request code */
230#endif
231#ifdef EBADSLT
232 //case EBADSLT 57 /* Invalid slot */
233#endif
234 //case 58:
235#ifdef EBFONT
236 //case EBFONT 59 /* Bad font file format */
237#endif
238#ifdef ENOSTR
239 //case ENOSTR 60 /* Device not a stream */
240#endif
241#ifdef ENODATA
242 case ENODATA: return VERR_NO_DATA;
243#endif
244#ifdef ETIME
245 //case ETIME 62 /* Timer expired */
246#endif
247#ifdef ENOSR
248 //case ENOSR 63 /* Out of streams resources */
249#endif
250#ifdef ENONET
251 case ENONET: return VERR_NET_NO_NETWORK;
252#endif
253#ifdef ENOPKG
254 //case ENOPKG 65 /* Package not installed */
255#endif
256#ifdef EREMOTE
257 //case EREMOTE 66 /* Object is remote */
258#endif
259#ifdef ENOLINK
260 //case ENOLINK 67 /* Link has been severed */
261#endif
262#ifdef EADV
263 //case EADV 68 /* Advertise error */
264#endif
265#ifdef ESRMNT
266 //case ESRMNT 69 /* Srmount error */
267#endif
268#ifdef ECOMM
269 //case ECOMM 70 /* Communication error on send */
270#endif
271#ifdef EPROTO
272 case EPROTO: return VERR_NET_PROTOCOL_ERROR;
273#endif
274#ifdef EMULTIHOP
275 //case EMULTIHOP 72 /* Multihop attempted */
276#endif
277#ifdef EDOTDOT
278 //case EDOTDOT 73 /* RFS specific error */
279#endif
280#ifdef EBADMSG
281 //case EBADMSG 74 /* Not a data message */
282#endif
283#ifdef EOVERFLOW
284 case EOVERFLOW: return VERR_TOO_MUCH_DATA; /**@todo fix duplicate error */
285#endif
286#ifdef ENOTUNIQ
287 case ENOTUNIQ: return VERR_NET_NOT_UNIQUE_NAME;
288#endif
289#ifdef EBADFD
290 case EBADFD: return VERR_INVALID_HANDLE; /**@todo fix duplicate error? */
291#endif
292#ifdef EREMCHG
293 //case EREMCHG 78 /* Remote address changed */
294#endif
295#ifdef ELIBACC
296 //case ELIBACC 79 /* Can not access a needed shared library */
297#endif
298#ifdef ELIBBAD
299 //case ELIBBAD 80 /* Accessing a corrupted shared library */
300#endif
301#ifdef ELIBSCN
302 //case ELIBSCN 81 /* .lib section in a.out corrupted */
303#endif
304#ifdef ELIBMAX
305 //case ELIBMAX 82 /* Attempting to link in too many shared libraries */
306#endif
307#ifdef ELIBEXEC
308 //case ELIBEXEC 83 /* Cannot exec a shared library directly */
309#endif
310#ifdef EILSEQ
311 case EILSEQ: return VERR_NO_TRANSLATION;
312#endif
313#ifdef ERESTART
314 case ERESTART: return VERR_INTERRUPTED;/**@todo fix duplicate error?*/
315#endif
316#ifdef ESTRPIPE
317 //case ESTRPIPE 86 /* Streams pipe error */
318#endif
319#ifdef EUSERS
320 //case EUSERS 87 /* Too many users */
321#endif
322#ifdef ENOTSOCK
323 case ENOTSOCK: return VERR_NET_NOT_SOCKET;
324#endif
325#ifdef EDESTADDRREQ
326 case EDESTADDRREQ: return VERR_NET_DEST_ADDRESS_REQUIRED;
327#endif
328#ifdef EMSGSIZE
329 case EMSGSIZE: return VERR_NET_MSG_SIZE;
330#endif
331#ifdef EPROTOTYPE
332 case EPROTOTYPE: return VERR_NET_PROTOCOL_TYPE;
333#endif
334#ifdef ENOPROTOOPT
335 case ENOPROTOOPT: return VERR_NET_PROTOCOL_NOT_AVAILABLE;
336#endif
337#ifdef EPROTONOSUPPORT
338 case EPROTONOSUPPORT: return VERR_NET_PROTOCOL_NOT_SUPPORTED;
339#endif
340#ifdef ESOCKTNOSUPPORT
341 case ESOCKTNOSUPPORT: return VERR_NET_SOCKET_TYPE_NOT_SUPPORTED;
342#endif
343#ifdef EOPNOTSUPP /** @todo map this differently on solaris. */
344 case EOPNOTSUPP: return VERR_NET_OPERATION_NOT_SUPPORTED;
345#endif
346#ifdef EPFNOSUPPORT
347 case EPFNOSUPPORT: return VERR_NET_PROTOCOL_FAMILY_NOT_SUPPORTED;
348#endif
349#ifdef EAFNOSUPPORT
350 case EAFNOSUPPORT: return VERR_NET_ADDRESS_FAMILY_NOT_SUPPORTED;
351#endif
352#ifdef EADDRINUSE
353 case EADDRINUSE: return VERR_NET_ADDRESS_IN_USE;
354#endif
355#ifdef EADDRNOTAVAIL
356 case EADDRNOTAVAIL: return VERR_NET_ADDRESS_NOT_AVAILABLE;
357#endif
358#ifdef ENETDOWN
359 case ENETDOWN: return VERR_NET_DOWN;
360#endif
361#ifdef ENETUNREACH
362 case ENETUNREACH: return VERR_NET_UNREACHABLE;
363#endif
364#ifdef ENETRESET
365 case ENETRESET: return VERR_NET_CONNECTION_RESET;
366#endif
367#ifdef ECONNABORTED
368 case ECONNABORTED: return VERR_NET_CONNECTION_ABORTED;
369#endif
370#ifdef ECONNRESET
371 case ECONNRESET: return VERR_NET_CONNECTION_RESET_BY_PEER;
372#endif
373#ifdef ENOBUFS
374 case ENOBUFS: return VERR_NET_NO_BUFFER_SPACE;
375#endif
376#ifdef EISCONN
377 case EISCONN: return VERR_NET_ALREADY_CONNECTED;
378#endif
379#ifdef ENOTCONN
380 case ENOTCONN: return VERR_NET_NOT_CONNECTED;
381#endif
382#ifdef ESHUTDOWN
383 case ESHUTDOWN: return VERR_NET_SHUTDOWN;
384#endif
385#ifdef ETOOMANYREFS
386 case ETOOMANYREFS: return VERR_NET_TOO_MANY_REFERENCES;
387#endif
388#ifdef ETIMEDOUT
389 case ETIMEDOUT: return VERR_TIMEOUT;
390#endif
391#ifdef ECONNREFUSED
392 case ECONNREFUSED: return VERR_NET_CONNECTION_REFUSED;
393#endif
394#ifdef EHOSTDOWN
395 case EHOSTDOWN: return VERR_NET_HOST_DOWN;
396#endif
397#ifdef EHOSTUNREACH
398 case EHOSTUNREACH: return VERR_NET_HOST_UNREACHABLE;
399#endif
400#ifdef EALREADY
401 case EALREADY: return VERR_NET_ALREADY_IN_PROGRESS;
402#endif
403#ifdef EINPROGRESS
404 case EINPROGRESS: return VERR_NET_IN_PROGRESS;
405#endif
406#ifdef ESTALE
407 //case ESTALE 116 /* Stale NFS file handle */
408#endif
409#ifdef EUCLEAN
410 //case EUCLEAN 117 /* Structure needs cleaning */
411#endif
412#ifdef ENOTNAM
413 //case ENOTNAM 118 /* Not a XENIX named type file */
414#endif
415#ifdef ENAVAIL
416 //case ENAVAIL 119 /* No XENIX semaphores available */
417#endif
418#ifdef EISNAM
419 //case EISNAM 120 /* Is a named type file */
420#endif
421#ifdef EREMOTEIO
422 //case EREMOTEIO 121 /* Remote I/O error */
423#endif
424#ifdef EDQUOT
425 case EDQUOT: return VERR_DISK_FULL; /**@todo fix duplicate error */
426#endif
427#ifdef ENOMEDIUM
428 case ENOMEDIUM: return VERR_MEDIA_NOT_PRESENT;
429#endif
430#ifdef EMEDIUMTYPE
431 case EMEDIUMTYPE: return VERR_MEDIA_NOT_RECOGNIZED;
432#endif
433
434 /* Non-linux */
435
436#ifdef EPROCLIM
437 case EPROCLIM: return VERR_MAX_PROCS_REACHED;
438#endif
439#ifdef EDOOFUS
440 case EDOOFUS: return VERR_INTERNAL_ERROR;
441#endif
442
443 default:
444 AssertMsgFailed(("Unhandled error code %d\n", uNativeCode));
445 return VERR_UNRESOLVED_ERROR;
446 }
447}
448
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette