VirtualBox

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

Last change on this file since 23223 was 21542, checked in by vboxsync, 15 years ago

Runtime: separate error code for EBUSY, for getting better error message on OSX with raw disk/partition access

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