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