1647f063dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3647f063dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4647f063dSAndrew Rist * or more contributor license agreements. See the NOTICE file
5647f063dSAndrew Rist * distributed with this work for additional information
6647f063dSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7647f063dSAndrew Rist * to you under the Apache License, Version 2.0 (the
8647f063dSAndrew Rist * "License"); you may not use this file except in compliance
9647f063dSAndrew Rist * with the License. You may obtain a copy of the License at
10647f063dSAndrew Rist *
11647f063dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12647f063dSAndrew Rist *
13647f063dSAndrew Rist * Unless required by applicable law or agreed to in writing,
14647f063dSAndrew Rist * software distributed under the License is distributed on an
15647f063dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16647f063dSAndrew Rist * KIND, either express or implied. See the License for the
17647f063dSAndrew Rist * specific language governing permissions and limitations
18647f063dSAndrew Rist * under the License.
19647f063dSAndrew Rist *
20647f063dSAndrew Rist *************************************************************/
21647f063dSAndrew Rist
22647f063dSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #define UNICODE
25cdf0e10cSrcweir #define _UNICODE
26cdf0e10cSrcweir #define _WIN32_WINNT_0x0500
27cdf0e10cSrcweir #include "systools/win32/uwinapi.h"
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include "file_error.h"
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include "osl/diagnose.h"
32cdf0e10cSrcweir #include "osl/thread.h"
33cdf0e10cSrcweir
34cdf0e10cSrcweir /* OS error to oslFileError values mapping table */
35cdf0e10cSrcweir struct osl_file_error_entry
36cdf0e10cSrcweir {
37cdf0e10cSrcweir unsigned long oscode; /* OS return value */
38cdf0e10cSrcweir int errnocode; /* oslFileError code */
39cdf0e10cSrcweir };
40cdf0e10cSrcweir
41cdf0e10cSrcweir static const struct osl_file_error_entry errtable[] = {
42cdf0e10cSrcweir { ERROR_SUCCESS, osl_File_E_None }, /* 0 */
43cdf0e10cSrcweir { ERROR_INVALID_FUNCTION, osl_File_E_INVAL }, /* 1 */
44cdf0e10cSrcweir { ERROR_FILE_NOT_FOUND, osl_File_E_NOENT }, /* 2 */
45cdf0e10cSrcweir { ERROR_PATH_NOT_FOUND, osl_File_E_NOENT }, /* 3 */
46cdf0e10cSrcweir { ERROR_TOO_MANY_OPEN_FILES, osl_File_E_MFILE }, /* 4 */
47cdf0e10cSrcweir { ERROR_ACCESS_DENIED, osl_File_E_ACCES }, /* 5 */
48cdf0e10cSrcweir { ERROR_INVALID_HANDLE, osl_File_E_BADF }, /* 6 */
49cdf0e10cSrcweir { ERROR_ARENA_TRASHED, osl_File_E_NOMEM }, /* 7 */
50cdf0e10cSrcweir { ERROR_NOT_ENOUGH_MEMORY, osl_File_E_NOMEM }, /* 8 */
51cdf0e10cSrcweir { ERROR_INVALID_BLOCK, osl_File_E_NOMEM }, /* 9 */
52cdf0e10cSrcweir { ERROR_BAD_ENVIRONMENT, osl_File_E_2BIG }, /* 10 */
53cdf0e10cSrcweir { ERROR_BAD_FORMAT, osl_File_E_NOEXEC }, /* 11 */
54cdf0e10cSrcweir { ERROR_INVALID_ACCESS, osl_File_E_INVAL }, /* 12 */
55cdf0e10cSrcweir { ERROR_INVALID_DATA, osl_File_E_INVAL }, /* 13 */
56cdf0e10cSrcweir { ERROR_INVALID_DRIVE, osl_File_E_NOENT }, /* 15 */
57cdf0e10cSrcweir { ERROR_CURRENT_DIRECTORY, osl_File_E_ACCES }, /* 16 */
58cdf0e10cSrcweir { ERROR_NOT_SAME_DEVICE, osl_File_E_XDEV }, /* 17 */
59cdf0e10cSrcweir { ERROR_NO_MORE_FILES, osl_File_E_NOENT }, /* 18 */
60cdf0e10cSrcweir { ERROR_NOT_READY, osl_File_E_NOTREADY }, /* 21 */
61cdf0e10cSrcweir { ERROR_LOCK_VIOLATION, osl_File_E_ACCES }, /* 33 */
62cdf0e10cSrcweir { ERROR_BAD_NETPATH, osl_File_E_NOENT }, /* 53 */
63cdf0e10cSrcweir { ERROR_NETWORK_ACCESS_DENIED, osl_File_E_ACCES }, /* 65 */
64cdf0e10cSrcweir { ERROR_BAD_NET_NAME, osl_File_E_NOENT }, /* 67 */
65cdf0e10cSrcweir { ERROR_FILE_EXISTS, osl_File_E_EXIST }, /* 80 */
66cdf0e10cSrcweir { ERROR_CANNOT_MAKE, osl_File_E_ACCES }, /* 82 */
67cdf0e10cSrcweir { ERROR_FAIL_I24, osl_File_E_ACCES }, /* 83 */
68cdf0e10cSrcweir { ERROR_INVALID_PARAMETER, osl_File_E_INVAL }, /* 87 */
69cdf0e10cSrcweir { ERROR_NO_PROC_SLOTS, osl_File_E_AGAIN }, /* 89 */
70cdf0e10cSrcweir { ERROR_DRIVE_LOCKED, osl_File_E_ACCES }, /* 108 */
71cdf0e10cSrcweir { ERROR_BROKEN_PIPE, osl_File_E_PIPE }, /* 109 */
72cdf0e10cSrcweir { ERROR_DISK_FULL, osl_File_E_NOSPC }, /* 112 */
73cdf0e10cSrcweir { ERROR_INVALID_TARGET_HANDLE, osl_File_E_BADF }, /* 114 */
74cdf0e10cSrcweir { ERROR_INVALID_HANDLE, osl_File_E_INVAL }, /* 124 */
75cdf0e10cSrcweir { ERROR_WAIT_NO_CHILDREN, osl_File_E_CHILD }, /* 128 */
76cdf0e10cSrcweir { ERROR_CHILD_NOT_COMPLETE, osl_File_E_CHILD }, /* 129 */
77cdf0e10cSrcweir { ERROR_DIRECT_ACCESS_HANDLE, osl_File_E_BADF }, /* 130 */
78cdf0e10cSrcweir { ERROR_NEGATIVE_SEEK, osl_File_E_INVAL }, /* 131 */
79cdf0e10cSrcweir { ERROR_SEEK_ON_DEVICE, osl_File_E_ACCES }, /* 132 */
80cdf0e10cSrcweir { ERROR_DIR_NOT_EMPTY, osl_File_E_NOTEMPTY }, /* 145 */
81cdf0e10cSrcweir { ERROR_NOT_LOCKED, osl_File_E_ACCES }, /* 158 */
82cdf0e10cSrcweir { ERROR_BAD_PATHNAME, osl_File_E_NOENT }, /* 161 */
83cdf0e10cSrcweir { ERROR_MAX_THRDS_REACHED, osl_File_E_AGAIN }, /* 164 */
84cdf0e10cSrcweir { ERROR_LOCK_FAILED, osl_File_E_ACCES }, /* 167 */
85cdf0e10cSrcweir { ERROR_ALREADY_EXISTS, osl_File_E_EXIST }, /* 183 */
86cdf0e10cSrcweir { ERROR_FILENAME_EXCED_RANGE, osl_File_E_NOENT }, /* 206 */
87cdf0e10cSrcweir { ERROR_NESTING_NOT_ALLOWED, osl_File_E_AGAIN }, /* 215 */
88cdf0e10cSrcweir { ERROR_DIRECTORY, osl_File_E_NOENT }, /* 267 */
89cdf0e10cSrcweir { ERROR_NOT_ENOUGH_QUOTA, osl_File_E_NOMEM }, /* 1816 */
90cbe9c442SAndrea Pescetti { ERROR_CANT_ACCESS_FILE, osl_File_E_ACCES }, /* 1920 */
919c0df323SAndrea Pescetti { ERROR_UNEXP_NET_ERR, osl_File_E_NETWORK }, /* 59 */
92*5efeadd1SAndrea Pescetti { ERROR_FILE_CHECKED_OUT, osl_File_E_ACCES }, /* 220 The file is locked or checked out by another user. */
939c0df323SAndrea Pescetti { ERROR_INVALID_NAME, osl_File_E_NOENT } /* 123 One or more of the names composing the file path has a wrong syntax. */
94cdf0e10cSrcweir };
95cdf0e10cSrcweir
96cdf0e10cSrcweir /* The following two constants must be the minimum and maximum
97cdf0e10cSrcweir values in the (contiguous) range of osl_File_E_xec Failure errors.
98cdf0e10cSrcweir */
99cdf0e10cSrcweir #define MIN_EXEC_ERROR ERROR_INVALID_STARTING_CODESEG
100cdf0e10cSrcweir #define MAX_EXEC_ERROR ERROR_INFLOOP_IN_RELOC_CHAIN
101cdf0e10cSrcweir
102cdf0e10cSrcweir /* These are the low and high value in the range of errors that are
103cdf0e10cSrcweir access violations
104cdf0e10cSrcweir */
105cdf0e10cSrcweir #define MIN_EACCES_RANGE ERROR_WRITE_PROTECT
106cdf0e10cSrcweir #define MAX_EACCES_RANGE ERROR_SHARING_BUFFER_EXCEEDED
107cdf0e10cSrcweir
oslTranslateFileError(unsigned long dwError)108cdf0e10cSrcweir oslFileError oslTranslateFileError (/*DWORD*/ unsigned long dwError)
109cdf0e10cSrcweir {
110cdf0e10cSrcweir static const int n = sizeof(errtable)/sizeof(errtable[0]);
111cdf0e10cSrcweir
112cdf0e10cSrcweir int i;
113cdf0e10cSrcweir for (i = 0; i < n; ++i )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir if (dwError == errtable[i].oscode)
116cdf0e10cSrcweir return (oslFileError)(errtable[i].errnocode);
117cdf0e10cSrcweir }
118cdf0e10cSrcweir
119cdf0e10cSrcweir /* The error code wasn't in the table. We check for a range of
120cdf0e10cSrcweir osl_File_E_ACCES errors or exec failure errors (ENOEXEC).
121cdf0e10cSrcweir Otherwise osl_File_E_INVAL is returned.
122cdf0e10cSrcweir */
123cdf0e10cSrcweir if ( (dwError >= MIN_EACCES_RANGE) && (dwError <= MAX_EACCES_RANGE) )
124cdf0e10cSrcweir return osl_File_E_ACCES;
125cdf0e10cSrcweir else if ( (dwError >= MIN_EXEC_ERROR) && (dwError <= MAX_EXEC_ERROR) )
126cdf0e10cSrcweir return osl_File_E_NOEXEC;
127cdf0e10cSrcweir else
128cdf0e10cSrcweir return osl_File_E_INVAL;
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
131cdf0e10cSrcweir //#####################################################
132cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
_osl_warnFile(const char * message,rtl_uString * ustrFile)133cdf0e10cSrcweir void _osl_warnFile( const char *message, rtl_uString *ustrFile )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir char szBuffer[2048];
136cdf0e10cSrcweir
137cdf0e10cSrcweir if (ustrFile)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir rtl_String *strFile = NULL;
140cdf0e10cSrcweir
141cdf0e10cSrcweir rtl_uString2String( &strFile, rtl_uString_getStr( ustrFile ), rtl_uString_getLength( ustrFile ),
142cdf0e10cSrcweir osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS );
143cdf0e10cSrcweir snprintf( szBuffer, sizeof(szBuffer), message, strFile->buffer );
144cdf0e10cSrcweir rtl_string_release( strFile );
145cdf0e10cSrcweir
146cdf0e10cSrcweir message = szBuffer;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir OSL_ENSURE( 0, message );
149cdf0e10cSrcweir }
150cdf0e10cSrcweir #endif /* OSL_DEBUG_LEVEL */
151