VirtualBox

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

Last change on this file since 35304 was 33437, checked in by vboxsync, 14 years ago

iprt: Made tstRTSymlink work on Windows.

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