VirtualBox

source: vbox/trunk/src/VBox/Runtime/win/RTErrConvertFromWin32.cpp@ 49971

Last change on this file since 49971 was 48935, checked in by vboxsync, 11 years ago

Runtime: Whitespace and svn:keyword cleanups by scm.

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