2 * Unix SMB/CIFS implementation.
3 * error mapping functions
4 * Copyright (C) Andrew Tridgell 2001
5 * Copyright (C) Andrew Bartlett 2001
6 * Copyright (C) Tim Potter 2000
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
24 /* Mapping between Unix, and NT error numbers */
29 } unix_nt_errmap
[] = {
30 { EAGAIN
, STATUS_MORE_ENTRIES
},
31 { EINTR
, STATUS_MORE_ENTRIES
},
32 { ENOBUFS
, STATUS_MORE_ENTRIES
},
34 { EWOULDBLOCK
, STATUS_MORE_ENTRIES
},
36 { EINPROGRESS
, NT_STATUS_MORE_PROCESSING_REQUIRED
},
37 { EPERM
, NT_STATUS_ACCESS_DENIED
},
38 { EACCES
, NT_STATUS_ACCESS_DENIED
},
39 { ENOENT
, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
40 { ENOTDIR
, NT_STATUS_NOT_A_DIRECTORY
},
41 { EIO
, NT_STATUS_IO_DEVICE_ERROR
},
42 { EBADF
, NT_STATUS_INVALID_HANDLE
},
43 { EINVAL
, NT_STATUS_INVALID_PARAMETER
},
44 { EEXIST
, NT_STATUS_OBJECT_NAME_COLLISION
},
45 { ENFILE
, NT_STATUS_TOO_MANY_OPENED_FILES
},
46 { EMFILE
, NT_STATUS_TOO_MANY_OPENED_FILES
},
47 { ENOSPC
, NT_STATUS_DISK_FULL
},
48 { ENOTSOCK
, NT_STATUS_INVALID_HANDLE
},
49 { EFAULT
, NT_STATUS_INVALID_PARAMETER
},
50 { EMSGSIZE
, NT_STATUS_INVALID_BUFFER_SIZE
},
51 { ENOMEM
, NT_STATUS_NO_MEMORY
},
52 { EISDIR
, NT_STATUS_FILE_IS_A_DIRECTORY
},
54 { EPIPE
, NT_STATUS_CONNECTION_DISCONNECTED
},
56 { EBUSY
, NT_STATUS_SHARING_VIOLATION
},
57 { ENOSYS
, NT_STATUS_INVALID_SYSTEM_SERVICE
},
59 { EOPNOTSUPP
, NT_STATUS_NOT_SUPPORTED
},
61 { EMLINK
, NT_STATUS_TOO_MANY_LINKS
},
62 { ENOSYS
, NT_STATUS_NOT_SUPPORTED
},
64 { ELOOP
, NT_STATUS_OBJECT_PATH_NOT_FOUND
},
67 { ENODATA
, NT_STATUS_NOT_FOUND
},
70 { EFTYPE
, NT_STATUS_OBJECT_PATH_NOT_FOUND
},
73 { EDQUOT
, NT_STATUS_DISK_FULL
}, /* Windows apps need this, not NT_STATUS_QUOTA_EXCEEDED */
76 { ENOTEMPTY
, NT_STATUS_DIRECTORY_NOT_EMPTY
},
79 { EXDEV
, NT_STATUS_NOT_SAME_DEVICE
},
82 { EROFS
, NT_STATUS_MEDIA_WRITE_PROTECTED
},
85 { ENAMETOOLONG
, NT_STATUS_NAME_TOO_LONG
},
88 { EFBIG
, NT_STATUS_DISK_FULL
},
91 { EADDRINUSE
, NT_STATUS_ADDRESS_ALREADY_ASSOCIATED
},
94 { ENETUNREACH
, NT_STATUS_NETWORK_UNREACHABLE
},
97 { EHOSTUNREACH
, NT_STATUS_HOST_UNREACHABLE
},
100 { ECONNREFUSED
, NT_STATUS_CONNECTION_REFUSED
},
103 { EADDRNOTAVAIL
,NT_STATUS_ADDRESS_NOT_ASSOCIATED
},
106 { ETIMEDOUT
, NT_STATUS_IO_TIMEOUT
},
108 #ifdef ESOCKTNOSUPPORT
109 { ESOCKTNOSUPPORT
,NT_STATUS_INVALID_PARAMETER_MIX
},
112 { EAFNOSUPPORT
, NT_STATUS_INVALID_PARAMETER_MIX
},
115 { ECONNABORTED
, NT_STATUS_CONNECTION_ABORTED
},
118 { ECONNRESET
, NT_STATUS_CONNECTION_RESET
},
121 { ENOPROTOOPT
, NT_STATUS_INVALID_PARAMETER_MIX
},
124 { ENODEV
, NT_STATUS_NO_SUCH_DEVICE
},
127 { ENOATTR
, NT_STATUS_NOT_FOUND
},
130 { ECANCELED
, NT_STATUS_CANCELLED
},
133 { ENOTSUP
, NT_STATUS_NOT_SUPPORTED
},
136 { 0, NT_STATUS_UNSUCCESSFUL
}
140 /*********************************************************************
141 Map an NT error code from a Unix error code.
142 *********************************************************************/
143 NTSTATUS
map_nt_error_from_unix_common(int unix_error
)
147 /* Look through list */
148 for (i
=0;i
<ARRAY_SIZE(unix_nt_errmap
);i
++) {
149 if (unix_nt_errmap
[i
].unix_error
== unix_error
) {
150 return unix_nt_errmap
[i
].nt_error
;
155 return NT_STATUS_UNSUCCESSFUL
;
158 /* Return a UNIX errno from a NT status code */
159 static const struct {
163 {NT_STATUS_ACCESS_VIOLATION
, EACCES
},
164 {NT_STATUS_INVALID_HANDLE
, EBADF
},
165 {NT_STATUS_ACCESS_DENIED
, EACCES
},
166 {NT_STATUS_OBJECT_NAME_NOT_FOUND
, ENOENT
},
167 {NT_STATUS_OBJECT_PATH_NOT_FOUND
, ENOENT
},
168 {NT_STATUS_SHARING_VIOLATION
, EBUSY
},
169 {NT_STATUS_OBJECT_PATH_INVALID
, ENOTDIR
},
170 {NT_STATUS_OBJECT_NAME_COLLISION
, EEXIST
},
171 {NT_STATUS_PATH_NOT_COVERED
, ENOENT
},
172 {NT_STATUS_UNSUCCESSFUL
, EINVAL
},
173 {NT_STATUS_NOT_IMPLEMENTED
, ENOSYS
},
174 {NT_STATUS_IN_PAGE_ERROR
, EFAULT
},
175 {NT_STATUS_BAD_NETWORK_NAME
, ENOENT
},
177 {NT_STATUS_PAGEFILE_QUOTA
, EDQUOT
},
178 {NT_STATUS_QUOTA_EXCEEDED
, EDQUOT
},
179 {NT_STATUS_REGISTRY_QUOTA_LIMIT
, EDQUOT
},
180 {NT_STATUS_LICENSE_QUOTA_EXCEEDED
, EDQUOT
},
183 {NT_STATUS_TIMER_NOT_CANCELED
, ETIME
},
185 {NT_STATUS_INVALID_PARAMETER
, EINVAL
},
186 {NT_STATUS_NO_SUCH_DEVICE
, ENODEV
},
187 {NT_STATUS_NO_SUCH_FILE
, ENOENT
},
189 {NT_STATUS_END_OF_FILE
, ENODATA
},
192 {NT_STATUS_NO_MEDIA_IN_DEVICE
, ENOMEDIUM
},
193 {NT_STATUS_NO_MEDIA
, ENOMEDIUM
},
195 {NT_STATUS_NONEXISTENT_SECTOR
, ESPIPE
},
196 {NT_STATUS_NO_MEMORY
, ENOMEM
},
197 {NT_STATUS_CONFLICTING_ADDRESSES
, EADDRINUSE
},
198 {NT_STATUS_NOT_MAPPED_VIEW
, EINVAL
},
199 {NT_STATUS_UNABLE_TO_FREE_VM
, EADDRINUSE
},
200 {NT_STATUS_ACCESS_DENIED
, EACCES
},
201 {NT_STATUS_BUFFER_TOO_SMALL
, ENOBUFS
},
202 {NT_STATUS_WRONG_PASSWORD
, EACCES
},
203 {NT_STATUS_LOGON_FAILURE
, EACCES
},
204 {NT_STATUS_INVALID_WORKSTATION
, EACCES
},
205 {NT_STATUS_INVALID_LOGON_HOURS
, EACCES
},
206 {NT_STATUS_PASSWORD_EXPIRED
, EACCES
},
207 {NT_STATUS_ACCOUNT_DISABLED
, EACCES
},
208 {NT_STATUS_DISK_FULL
, ENOSPC
},
209 {NT_STATUS_INVALID_PIPE_STATE
, EPIPE
},
210 {NT_STATUS_PIPE_BUSY
, EPIPE
},
211 {NT_STATUS_PIPE_DISCONNECTED
, EPIPE
},
212 {NT_STATUS_PIPE_NOT_AVAILABLE
, ENOSYS
},
213 {NT_STATUS_FILE_IS_A_DIRECTORY
, EISDIR
},
214 {NT_STATUS_NOT_SUPPORTED
, ENOSYS
},
215 {NT_STATUS_NOT_A_DIRECTORY
, ENOTDIR
},
216 {NT_STATUS_DIRECTORY_NOT_EMPTY
, ENOTEMPTY
},
217 {NT_STATUS_NETWORK_UNREACHABLE
, ENETUNREACH
},
218 {NT_STATUS_HOST_UNREACHABLE
, EHOSTUNREACH
},
219 {NT_STATUS_CONNECTION_ABORTED
, ECONNABORTED
},
220 {NT_STATUS_CONNECTION_REFUSED
, ECONNREFUSED
},
221 {NT_STATUS_TOO_MANY_LINKS
, EMLINK
},
222 {NT_STATUS_NETWORK_BUSY
, EBUSY
},
223 {NT_STATUS_DEVICE_DOES_NOT_EXIST
, ENODEV
},
225 {NT_STATUS_DLL_NOT_FOUND
, ELIBACC
},
227 {NT_STATUS_PIPE_BROKEN
, EPIPE
},
228 {NT_STATUS_REMOTE_NOT_LISTENING
, ECONNREFUSED
},
229 {NT_STATUS_NETWORK_ACCESS_DENIED
, EACCES
},
230 {NT_STATUS_TOO_MANY_OPENED_FILES
, EMFILE
},
232 {NT_STATUS_DEVICE_PROTOCOL_ERROR
, EPROTO
},
234 {NT_STATUS_FLOAT_OVERFLOW
, ERANGE
},
235 {NT_STATUS_FLOAT_UNDERFLOW
, ERANGE
},
236 {NT_STATUS_INTEGER_OVERFLOW
, ERANGE
},
237 {NT_STATUS_MEDIA_WRITE_PROTECTED
, EROFS
},
238 {NT_STATUS_PIPE_CONNECTED
, EISCONN
},
239 {NT_STATUS_MEMORY_NOT_ALLOCATED
, EFAULT
},
240 {NT_STATUS_FLOAT_INEXACT_RESULT
, ERANGE
},
241 {NT_STATUS_ILL_FORMED_PASSWORD
, EACCES
},
242 {NT_STATUS_PASSWORD_RESTRICTION
, EACCES
},
243 {NT_STATUS_ACCOUNT_RESTRICTION
, EACCES
},
244 {NT_STATUS_PORT_CONNECTION_REFUSED
, ECONNREFUSED
},
245 {NT_STATUS_NAME_TOO_LONG
, ENAMETOOLONG
},
246 {NT_STATUS_REMOTE_DISCONNECT
, ESHUTDOWN
},
247 {NT_STATUS_CONNECTION_DISCONNECTED
, ECONNABORTED
},
248 {NT_STATUS_CONNECTION_RESET
, ENETRESET
},
250 {NT_STATUS_IP_ADDRESS_CONFLICT1
, ENOTUNIQ
},
251 {NT_STATUS_IP_ADDRESS_CONFLICT2
, ENOTUNIQ
},
253 {NT_STATUS_PORT_MESSAGE_TOO_LONG
, EMSGSIZE
},
254 {NT_STATUS_PROTOCOL_UNREACHABLE
, ENOPROTOOPT
},
255 {NT_STATUS_ADDRESS_ALREADY_EXISTS
, EADDRINUSE
},
256 {NT_STATUS_PORT_UNREACHABLE
, EHOSTUNREACH
},
257 {NT_STATUS_IO_TIMEOUT
, ETIMEDOUT
},
258 {NT_STATUS_RETRY
, EAGAIN
},
260 {NT_STATUS_DUPLICATE_NAME
, ENOTUNIQ
},
263 {NT_STATUS_NET_WRITE_FAULT
, ECOMM
},
266 {NT_STATUS_NOT_SAME_DEVICE
, EXDEV
},
269 {NT_STATUS_CANCELLED
, ECANCELED
},
273 /*********************************************************************
274 Map a Unix error code from a NT error code.
275 *********************************************************************/
276 int map_errno_from_nt_status(NTSTATUS status
)
280 DBG_DEBUG("32 bit codes: code=%08x\n", NT_STATUS_V(status
));
282 /* Status codes without this bit set are not errors */
284 if (!(NT_STATUS_V(status
) & 0xc0000000)) {
288 for (i
=0;i
<ARRAY_SIZE(nt_errno_map
);i
++) {
289 if (NT_STATUS_V(nt_errno_map
[i
].status
) ==
290 NT_STATUS_V(status
)) {
291 return nt_errno_map
[i
].error
;
295 /* for all other cases - a default code */