VirtualBox

source: vbox/trunk/src/VBox/Runtime/win32/RTErrConvertFromWin32.cpp@ 3125

Last change on this file since 3125 was 2981, checked in by vboxsync, 17 years ago

InnoTek -> innotek: all the headers and comments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 17.4 KB
Line 
1/* $Id: RTErrConvertFromWin32.cpp 2981 2007-06-01 16:01:28Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime - Convert win32 error codes to iprt status codes.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek 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* Header Files *
24*******************************************************************************/
25#include <Windows.h>
26
27#include <iprt/err.h>
28#include <iprt/assert.h>
29#include <iprt/err.h>
30
31
32RTR3DECL(int) RTErrConvertFromWin32(unsigned uNativeCode)
33{
34 /* very fast check for no error. */
35 if (uNativeCode == ERROR_SUCCESS)
36 return(VINF_SUCCESS);
37
38 /* process error codes. */
39 switch (uNativeCode)
40 {
41 case ERROR_INVALID_FUNCTION: return VERR_INVALID_FUNCTION;
42 case ERROR_FILE_NOT_FOUND: return VERR_FILE_NOT_FOUND;
43 case ERROR_PATH_NOT_FOUND: return VERR_PATH_NOT_FOUND;
44 case ERROR_TOO_MANY_OPEN_FILES: return VERR_TOO_MANY_OPEN_FILES;
45 case ERROR_ACCESS_DENIED: return VERR_ACCESS_DENIED;
46
47 case ERROR_INVALID_HANDLE:
48 case ERROR_DIRECT_ACCESS_HANDLE: return VERR_INVALID_HANDLE;
49
50 case ERROR_NO_SYSTEM_RESOURCES: /** @todo better translation */
51 case ERROR_NOT_ENOUGH_MEMORY:
52 case ERROR_OUTOFMEMORY: return VERR_NO_MEMORY;
53
54 case ERROR_INVALID_DRIVE: return VERR_INVALID_DRIVE;
55 case ERROR_CURRENT_DIRECTORY: return VERR_CANT_DELETE_DIRECTORY;
56 case ERROR_NOT_SAME_DEVICE: return VERR_NOT_SAME_DEVICE;
57 case ERROR_NO_MORE_FILES: return VERR_NO_MORE_FILES;
58 case ERROR_WRITE_PROTECT: return VERR_WRITE_PROTECT;
59 case ERROR_BAD_UNIT: return VERR_IO_BAD_UNIT;
60 case ERROR_NOT_READY: return VERR_IO_NOT_READY;
61 case ERROR_BAD_COMMAND: return VERR_IO_BAD_COMMAND;
62 case ERROR_CRC: return VERR_IO_CRC;
63 case ERROR_BAD_LENGTH: return VERR_IO_BAD_LENGTH;
64 case ERROR_SEEK: return VERR_SEEK;
65 case ERROR_NOT_DOS_DISK: return VERR_DISK_INVALID_FORMAT;
66 case ERROR_SECTOR_NOT_FOUND: return VERR_IO_SECTOR_NOT_FOUND;
67 case ERROR_WRITE_FAULT: return VERR_WRITE_ERROR;
68 case ERROR_READ_FAULT: return VERR_READ_ERROR;
69 case ERROR_GEN_FAILURE: return VERR_IO_GEN_FAILURE;
70 case ERROR_SHARING_VIOLATION: return VERR_SHARING_VIOLATION;
71 case ERROR_LOCK_VIOLATION: return VERR_FILE_LOCK_VIOLATION;
72 case ERROR_HANDLE_EOF: return VERR_EOF;
73 case ERROR_NOT_LOCKED: return VERR_FILE_NOT_LOCKED;
74 case ERROR_DIR_NOT_EMPTY: return VERR_DIR_NOT_EMPTY;
75
76 case ERROR_HANDLE_DISK_FULL:
77 case ERROR_DISK_FULL: return VERR_DISK_FULL;
78
79 case ERROR_NOT_SUPPORTED: return VERR_NOT_SUPPORTED;
80
81 case ERROR_INVALID_PARAMETER:
82 case ERROR_BAD_ARGUMENTS:
83 case ERROR_INVALID_FLAGS: return VERR_INVALID_PARAMETER;
84
85 case ERROR_REM_NOT_LIST: return VERR_NET_IO_ERROR;
86
87 case ERROR_BAD_NETPATH:
88 case ERROR_NETNAME_DELETED: return VERR_NET_HOST_NOT_FOUND;
89
90 case ERROR_BAD_NET_NAME:
91 case ERROR_DEV_NOT_EXIST: return VERR_NET_PATH_NOT_FOUND;
92
93 case ERROR_NETWORK_BUSY:
94 case ERROR_TOO_MANY_CMDS:
95 case ERROR_TOO_MANY_NAMES:
96 case ERROR_TOO_MANY_SESS:
97 case ERROR_OUT_OF_STRUCTURES: return VERR_NET_OUT_OF_RESOURCES;
98
99 case ERROR_PRINTQ_FULL:
100 case ERROR_NO_SPOOL_SPACE:
101 case ERROR_PRINT_CANCELLED: return VERR_NET_PRINT_ERROR;
102
103 case ERROR_DUP_NAME:
104 case ERROR_ADAP_HDW_ERR:
105 case ERROR_BAD_NET_RESP:
106 case ERROR_UNEXP_NET_ERR:
107 case ERROR_BAD_REM_ADAP:
108 case ERROR_NETWORK_ACCESS_DENIED:
109 case ERROR_BAD_DEV_TYPE:
110 case ERROR_SHARING_PAUSED:
111 case ERROR_REQ_NOT_ACCEP:
112 case ERROR_REDIR_PAUSED:
113 case ERROR_ALREADY_ASSIGNED:
114 case ERROR_INVALID_PASSWORD:
115 case ERROR_NET_WRITE_FAULT: return VERR_NET_IO_ERROR;
116
117 case ERROR_FILE_EXISTS:
118 case ERROR_ALREADY_EXISTS: return VERR_ALREADY_EXISTS;
119
120 case ERROR_CANNOT_MAKE: return VERR_CANT_CREATE;
121 case ERROR_NO_PROC_SLOTS: return VERR_MAX_PROCS_REACHED;
122 case ERROR_TOO_MANY_SEMAPHORES: return VERR_TOO_MANY_SEMAPHORES;
123 case ERROR_EXCL_SEM_ALREADY_OWNED: return VERR_EXCL_SEM_ALREADY_OWNED;
124 case ERROR_SEM_IS_SET: return VERR_SEM_IS_SET;
125 case ERROR_TOO_MANY_SEM_REQUESTS: return VERR_TOO_MANY_SEM_REQUESTS;
126 case ERROR_SEM_OWNER_DIED: return VERR_SEM_OWNER_DIED;
127 case ERROR_DRIVE_LOCKED: return VERR_DRIVE_LOCKED;
128 case ERROR_BROKEN_PIPE: return VERR_BROKEN_PIPE;
129 case ERROR_OPEN_FAILED: return VERR_OPEN_FAILED;
130
131 case ERROR_BUFFER_OVERFLOW:
132 case ERROR_INSUFFICIENT_BUFFER: return VERR_BUFFER_OVERFLOW;
133
134 case ERROR_NO_MORE_SEARCH_HANDLES: return VERR_NO_MORE_SEARCH_HANDLES;
135
136 case ERROR_SEM_TIMEOUT:
137 case WAIT_TIMEOUT:
138 case ERROR_SERVICE_REQUEST_TIMEOUT:
139 case ERROR_COUNTER_TIMEOUT:
140 case ERROR_TIMEOUT: return VERR_TIMEOUT;
141
142 case ERROR_INVALID_NAME:
143 case ERROR_BAD_PATHNAME: return VERR_INVALID_NAME;
144
145 case ERROR_NEGATIVE_SEEK: return VERR_NEGATIVE_SEEK;
146 case ERROR_SEEK_ON_DEVICE: return VERR_SEEK_ON_DEVICE;
147
148 case ERROR_SIGNAL_REFUSED:
149 case ERROR_NO_SIGNAL_SENT: return VERR_SIGNAL_REFUSED;
150
151 case ERROR_SIGNAL_PENDING: return VERR_SIGNAL_PENDING;
152 case ERROR_MAX_THRDS_REACHED: return VERR_MAX_THRDS_REACHED;
153 case ERROR_LOCK_FAILED: return VERR_FILE_LOCK_FAILED;
154 case ERROR_SEM_NOT_FOUND: return VERR_SEM_NOT_FOUND;
155 case ERROR_FILENAME_EXCED_RANGE: return VERR_FILENAME_TOO_LONG;
156 case ERROR_INVALID_SIGNAL_NUMBER: return VERR_SIGNAL_INVALID;
157
158 case ERROR_BAD_PIPE: return VERR_BAD_PIPE;
159 case ERROR_PIPE_BUSY: return VERR_PIPE_BUSY;
160 case ERROR_NO_DATA: return VERR_NO_DATA;
161 case ERROR_PIPE_NOT_CONNECTED: return VERR_PIPE_NOT_CONNECTED;
162 case ERROR_MORE_DATA: return VERR_MORE_DATA;
163 case ERROR_NOT_OWNER: return VERR_NOT_OWNER;
164 case ERROR_TOO_MANY_POSTS: return VERR_TOO_MANY_POSTS;
165
166 case ERROR_PIPE_CONNECTED:
167 case ERROR_PIPE_LISTENING: return VERR_PIPE_IO_ERROR;
168
169 case ERROR_OPERATION_ABORTED: return VERR_INTERRUPTED;
170 case ERROR_NO_UNICODE_TRANSLATION: return VERR_NO_TRANSLATION;
171
172 case RPC_S_INVALID_STRING_UUID: return VERR_INVALID_UUID_FORMAT;
173
174 case ERROR_PROC_NOT_FOUND: return VERR_SYMBOL_NOT_FOUND;
175 case ERROR_MOD_NOT_FOUND: return VERR_MODULE_NOT_FOUND;
176
177 case ERROR_INVALID_EXE_SIGNATURE: return VERR_INVALID_EXE_SIGNATURE;
178 case ERROR_BAD_EXE_FORMAT: return VERR_BAD_EXE_FORMAT;
179 case ERROR_RESOURCE_DATA_NOT_FOUND: return VERR_NO_DATA; ///@todo fix ERROR_RESOURCE_DATA_NOT_FOUND translation
180 case ERROR_INVALID_ADDRESS: return VERR_INVALID_POINTER; ///@todo fix ERROR_INVALID_ADDRESS translation - dbghelp returns it on some line number queries.
181
182 case ERROR_CANCELLED: return VERR_CANCELLED;
183
184 /*
185 * Winsocket errors are mostly BSD errno.h wrappers.
186 * This is copied from RTErrConvertFromErrno() and checked against winsock.h.
187 * Please, keep things in sync!
188 */
189#ifdef WSAEPERM
190 case WSAEPERM: return VERR_ACCESS_DENIED; /* 1 */
191#endif
192#ifdef WSAENOENT
193 case WSAENOENT: return VERR_FILE_NOT_FOUND;
194#endif
195#ifdef WSAESRCH
196 case WSAESRCH: return VERR_PROCESS_NOT_FOUND;
197#endif
198 case WSAEINTR: return VERR_INTERRUPTED;
199#ifdef WSAEIO
200 case WSAEIO: return VERR_DEV_IO_ERROR;
201#endif
202#ifdef WSAE2BIG
203 case WSAE2BIG: return VERR_TOO_MUCH_DATA;
204#endif
205#ifdef WSAENOEXEC
206 case WSAENOEXEC: return VERR_BAD_EXE_FORMAT;
207#endif
208 case WSAEBADF: return VERR_INVALID_HANDLE;
209#ifdef WSAECHILD
210 case WSAECHILD: return VERR_PROCESS_NOT_FOUND; //... /* 10 */
211#endif
212 case WSAEWOULDBLOCK: return VERR_TRY_AGAIN; /* EAGAIN */
213#ifdef WSAENOMEM
214 case WSAENOMEM: return VERR_NO_MEMORY;
215#endif
216 case WSAEACCES: return VERR_ACCESS_DENIED;
217 case WSAEFAULT: return VERR_INVALID_POINTER;
218 //case WSAENOTBLK: return VERR_;
219#ifdef WSAEBUSY
220 case WSAEBUSY: return VERR_DEV_IO_ERROR;
221#endif
222#ifdef WSAEEXIST
223 case WSAEEXIST: return VERR_ALREADY_EXISTS;
224#endif
225 //case WSAEXDEV:
226#ifdef WSAENODEV
227 case WSAENODEV: return VERR_NOT_SUPPORTED;
228#endif
229#ifdef WSAENOTDIR
230 case WSAENOTDIR: return VERR_PATH_NOT_FOUND; /* 20 */
231#endif
232#ifdef WSAEISDIR
233 case WSAEISDIR: return VERR_FILE_NOT_FOUND;
234#endif
235 case WSAEINVAL: return VERR_INVALID_PARAMETER;
236#ifdef WSAENFILE
237 case WSAENFILE: return VERR_TOO_MANY_OPEN_FILES;
238#endif
239 case WSAEMFILE: return VERR_TOO_MANY_OPEN_FILES;
240#ifdef WSAENOTTY
241 case WSAENOTTY: return VERR_INVALID_FUNCTION;
242#endif
243#ifdef WSAETXTBSY
244 case WSAETXTBSY: return VERR_SHARING_VIOLATION;
245#endif
246 //case WSAEFBIG:
247#ifdef WSAENOSPC
248 case WSAENOSPC: return VERR_DISK_FULL;
249#endif
250#ifdef WSAESPIPE
251 case WSAESPIPE: return VERR_SEEK_ON_DEVICE;
252#endif
253#ifdef WSAEROFS
254 case WSAEROFS: return VERR_WRITE_PROTECT; /* 30 */
255#endif
256 //case WSAEMLINK:
257#ifdef WSAEPIPE
258 case WSAEPIPE: return VERR_BROKEN_PIPE;
259#endif
260#ifdef WSAEDOM
261 case WSAEDOM: return VERR_INVALID_PARAMETER;
262#endif
263#ifdef WSAERANGE
264 case WSAERANGE: return VERR_INVALID_PARAMETER;
265#endif
266#ifdef WSAEDEADLK
267 case WSAEDEADLK: return VERR_DEADLOCK;
268#endif
269 case WSAENAMETOOLONG: return VERR_FILENAME_TOO_LONG;
270#ifdef WSAENOLCK
271 case WSAENOLCK: return VERR_FILE_LOCK_FAILED;
272#endif
273#ifdef WSAENOSYS
274 case WSAENOSYS: return VERR_NOT_SUPPORTED;
275#endif
276 case WSAENOTEMPTY: return VERR_CANT_DELETE_DIRECTORY;
277 case WSAELOOP: return VERR_TOO_MANY_SYMLINKS; /* 40 */
278 //case WSAENOMSG 42 /* No message of desired type */
279 //case WSAEIDRM 43 /* Identifier removed */
280 //case WSAECHRNG 44 /* Channel number out of range */
281 //case WSAEL2NSYNC 45 /* Level 2 not synchronized */
282 //case WSAEL3HLT 46 /* Level 3 halted */
283 //case WSAEL3RST 47 /* Level 3 reset */
284 //case WSAELNRNG 48 /* Link number out of range */
285 //case WSAEUNATCH 49 /* Protocol driver not attached */
286 //case WSAENOCSI 50 /* No CSI structure available */
287 //case WSAEL2HLT 51 /* Level 2 halted */
288 //case WSAEBADE 52 /* Invalid exchange */
289 //case WSAEBADR 53 /* Invalid request descriptor */
290 //case WSAEXFULL 54 /* Exchange full */
291 //case WSAENOANO 55 /* No anode */
292 //case WSAEBADRQC 56 /* Invalid request code */
293 //case WSAEBADSLT 57 /* Invalid slot */
294 //case 58:
295 //case WSAEBFONT 59 /* Bad font file format */
296 //case WSAENOSTR 60 /* Device not a stream */
297#ifdef WSAENODATA
298 case WSAENODATA: return VERR_NO_DATA;
299#endif
300 //case WSAETIME 62 /* Timer expired */
301 //case WSAENOSR 63 /* Out of streams resources */
302#ifdef WSAENONET
303 case WSAENONET: return VERR_NET_NO_NETWORK;
304#endif
305 //case WSAENOPKG 65 /* Package not installed */
306 //case WSAEREMOTE 66 /* Object is remote */
307 //case WSAENOLINK 67 /* Link has been severed */
308 //case WSAEADV 68 /* Advertise error */
309 //case WSAESRMNT 69 /* Srmount error */
310 //case WSAECOMM 70 /* Communication error on send */
311 //case WSAEPROTO 71 /* Protocol error */
312 //case WSAEMULTIHOP 72 /* Multihop attempted */
313 //case WSAEDOTDOT 73 /* RFS specific error */
314 //case WSAEBADMSG 74 /* Not a data message */
315#ifdef WSAEOVERFLOW
316 case WSAEOVERFLOW: return VERR_TOO_MUCH_DATA;
317#endif
318#ifdef WSAENOTUNIQ
319 case WSAENOTUNIQ: return VERR_NET_NOT_UNIQUE_NAME;
320#endif
321#ifdef WSAEBADFD
322 case WSAEBADFD: return VERR_INVALID_HANDLE;
323#endif
324 //case WSAEREMCHG 78 /* Remote address changed */
325 //case WSAELIBACC 79 /* Can not access a needed shared library */
326 //case WSAELIBBAD 80 /* Accessing a corrupted shared library */
327 //case WSAELIBSCN 81 /* .lib section in a.out corrupted */
328 //case WSAELIBMAX 82 /* Attempting to link in too many shared libraries */
329 //case WSAELIBEXEC 83 /* Cannot exec a shared library directly */
330#ifdef WSAEILSEQ
331 case WSAEILSEQ: return VERR_NO_TRANSLATION;
332#endif
333#ifdef WSAERESTART
334 case WSAERESTART: return VERR_INTERRUPTED;
335#endif
336 //case WSAESTRPIPE 86 /* Streams pipe error */
337 //case WSAEUSERS 87 /* Too many users */
338 case WSAENOTSOCK: return VERR_NET_NOT_SOCKET;
339 case WSAEDESTADDRREQ: return VERR_NET_DEST_ADDRESS_REQUIRED;
340 case WSAEMSGSIZE: return VERR_NET_MSG_SIZE;
341 case WSAEPROTOTYPE: return VERR_NET_PROTOCOL_TYPE;
342 case WSAENOPROTOOPT: return VERR_NET_PROTOCOL_NOT_AVAILABLE;
343 case WSAEPROTONOSUPPORT: return VERR_NET_PROTOCOL_NOT_SUPPORTED;
344 case WSAESOCKTNOSUPPORT: return VERR_NET_SOCKET_TYPE_NOT_SUPPORTED;
345 case WSAEOPNOTSUPP: return VERR_NET_OPERATION_NOT_SUPPORTED;
346 case WSAEPFNOSUPPORT: return VERR_NET_PROTOCOL_FAMILY_NOT_SUPPORTED;
347 case WSAEAFNOSUPPORT: return VERR_NET_ADDRESS_FAMILY_NOT_SUPPORTED;
348 case WSAEADDRINUSE: return VERR_NET_ADDRESS_IN_USE;
349 case WSAEADDRNOTAVAIL: return VERR_NET_ADDRESS_NOT_AVAILABLE;
350 case WSAENETDOWN: return VERR_NET_DOWN;
351 case WSAENETUNREACH: return VERR_NET_UNREACHABLE;
352 case WSAENETRESET: return VERR_NET_CONNECTION_RESET;
353 case WSAECONNABORTED: return VERR_NET_CONNECTION_ABORTED;
354 case WSAECONNRESET: return VERR_NET_CONNECTION_RESET_BY_PEER;
355 case WSAENOBUFS: return VERR_NET_NO_BUFFER_SPACE;
356 case WSAEISCONN: return VERR_NET_ALREADY_CONNECTED;
357 case WSAENOTCONN: return VERR_NET_NOT_CONNECTED;
358 case WSAESHUTDOWN: return VERR_NET_SHUTDOWN;
359 case WSAETOOMANYREFS: return VERR_NET_TOO_MANY_REFERENCES;
360 case WSAETIMEDOUT: return VERR_TIMEOUT;
361 case WSAECONNREFUSED: return VERR_NET_CONNECTION_REFUSED;
362 case WSAEHOSTDOWN: return VERR_NET_HOST_DOWN;
363 case WSAEHOSTUNREACH: return VERR_NET_HOST_UNREACHABLE;
364 case WSAEALREADY: return VERR_NET_ALREADY_IN_PROGRESS;
365 case WSAEINPROGRESS: return VERR_NET_IN_PROGRESS;
366 //case WSAESTALE 116 /* Stale NFS file handle */
367 //case WSAEUCLEAN 117 /* Structure needs cleaning */
368 //case WSAENOTNAM 118 /* Not a XENIX named type file */
369 //case WSAENAVAIL 119 /* No XENIX semaphores available */
370 //case WSAEISNAM 120 /* Is a named type file */
371 //case WSAEREMOTEIO 121 /* Remote I/O error */
372 case WSAEDQUOT: return VERR_DISK_FULL;
373#ifdef WSAENOMEDIUM
374 case WSAENOMEDIUM: return VERR_MEDIA_NOT_PRESENT;
375#endif
376#ifdef WSAEMEDIUMTYPE
377 case WSAEMEDIUMTYPE: return VERR_MEDIA_NOT_RECOGNIZED;
378#endif
379 case WSAEPROCLIM: return VERR_MAX_PROCS_REACHED;
380
381 //case WSAEDISCON: (WSABASEERR+101)
382 //case WSASYSNOTREADY (WSABASEERR+91)
383 //case WSAVERNOTSUPPORTED (WSABASEERR+92)
384 //case WSANOTINITIALISED (WSABASEERR+93)
385
386 //case WSAHOST_NOT_FOUND (WSABASEERR+1001)
387 //case WSATRY_AGAIN (WSABASEERR+1002)
388 //case WSANO_RECOVERY (WSABASEERR+1003)
389 //case WSANO_DATA (WSABASEERR+1004)
390 }
391
392 /* unknown error. */
393 AssertMsgFailed(("Unhandled error %u\n", uNativeCode));
394 return VERR_UNRESOLVED_ERROR;
395}
396
397
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