VirtualBox

source: vbox/trunk/src/VBox/Runtime/RTErrConvertFromErrno.cpp@ 2397

Last change on this file since 2397 was 1532, checked in by vboxsync, 18 years ago

Handle EFBIG on Linux correctly (and try to detect the same situation on
Windows). Provide separate runtime error message, because disk full
doesn't describe the problem (file size limit exceeded). Happens mostly
if people store VDIs on FAT32 partitions.

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