2 * Unix SMB/CIFS implementation.
3 * map unix to NT errors, an excerpt of libsmb/errormap.c
4 * Copyright (C) Andrew Tridgell 2001
5 * Copyright (C) Andrew Bartlett 2001
6 * Copyright (C) Tim Potter 2000
7 * Copyright (C) Jeremy Allison 2007
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, see <http://www.gnu.org/licenses/>.
25 /* Mapping from Unix, to NT error numbers */
30 } unix_nt_errmap
[] = {
31 { EAGAIN
, NT_STATUS_NETWORK_BUSY
},
32 { EINTR
, NT_STATUS_RETRY
},
34 { ENOBUFS
, NT_STATUS_INSUFFICIENT_RESOURCES
},
37 { EWOULDBLOCK
, NT_STATUS_NETWORK_BUSY
},
39 { EPERM
, NT_STATUS_ACCESS_DENIED
},
40 { EACCES
, NT_STATUS_ACCESS_DENIED
},
41 { ENOENT
, NT_STATUS_OBJECT_NAME_NOT_FOUND
},
42 { ENOTDIR
, NT_STATUS_NOT_A_DIRECTORY
},
43 { EIO
, NT_STATUS_IO_DEVICE_ERROR
},
44 { EBADF
, NT_STATUS_INVALID_HANDLE
},
45 { EINVAL
, NT_STATUS_INVALID_PARAMETER
},
46 { EEXIST
, NT_STATUS_OBJECT_NAME_COLLISION
},
47 { ENFILE
, NT_STATUS_TOO_MANY_OPENED_FILES
},
48 { EMFILE
, NT_STATUS_TOO_MANY_OPENED_FILES
},
49 { ENOSPC
, NT_STATUS_DISK_FULL
},
50 { ENOMEM
, NT_STATUS_NO_MEMORY
},
51 { EISDIR
, NT_STATUS_FILE_IS_A_DIRECTORY
},
52 { EMSGSIZE
, NT_STATUS_PORT_MESSAGE_TOO_LONG
},
54 { EPIPE
, NT_STATUS_CONNECTION_DISCONNECTED
},
56 { EMLINK
, NT_STATUS_TOO_MANY_LINKS
},
57 { ENOSYS
, NT_STATUS_NOT_SUPPORTED
},
59 { ELOOP
, NT_STATUS_OBJECT_PATH_NOT_FOUND
},
62 { EFTYPE
, NT_STATUS_OBJECT_PATH_NOT_FOUND
},
65 { EDQUOT
, NT_STATUS_DISK_FULL
}, /* Windows apps need this, not NT_STATUS_QUOTA_EXCEEDED */
68 { ENOTEMPTY
, NT_STATUS_DIRECTORY_NOT_EMPTY
},
71 { EXDEV
, NT_STATUS_NOT_SAME_DEVICE
},
74 { EROFS
, NT_STATUS_MEDIA_WRITE_PROTECTED
},
77 { ENAMETOOLONG
, NT_STATUS_OBJECT_NAME_INVALID
},
80 { EFBIG
, NT_STATUS_DISK_FULL
},
83 { EADDRINUSE
, NT_STATUS_ADDRESS_ALREADY_ASSOCIATED
},
86 { ENETUNREACH
, NT_STATUS_NETWORK_UNREACHABLE
},
89 { EHOSTUNREACH
, NT_STATUS_HOST_UNREACHABLE
},
92 { ECONNREFUSED
, NT_STATUS_CONNECTION_REFUSED
},
95 { ETIMEDOUT
, NT_STATUS_IO_TIMEOUT
},
98 { ECONNABORTED
, NT_STATUS_CONNECTION_ABORTED
},
101 { ECONNRESET
, NT_STATUS_CONNECTION_RESET
},
104 { ENODEV
, NT_STATUS_DEVICE_DOES_NOT_EXIST
},
107 { ENOATTR
, NT_STATUS_NOT_FOUND
},
110 { ECANCELED
, NT_STATUS_CANCELLED
},
113 { ENOTSUP
, NT_STATUS_NOT_SUPPORTED
},
116 { ETXTBSY
, NT_STATUS_SHARING_VIOLATION
},
119 { EOVERFLOW
, NT_STATUS_ALLOTTED_SPACE_EXCEEDED
},
121 { EINPROGRESS
, NT_STATUS_MORE_PROCESSING_REQUIRED
},
123 { ERANGE
, NT_STATUS_INTEGER_OVERFLOW
},
127 /*********************************************************************
128 Map an NT error code from a Unix error code.
129 *********************************************************************/
131 NTSTATUS
map_nt_error_from_unix(int unix_error
)
135 if (unix_error
== 0) {
136 /* we map this to an error, not success, as this
137 function is only called in an error path. Lots of
138 our virtualised functions may fail without making a
139 unix system call that fails (such as when they are
140 checking for some handle existing), so unix_error
143 return NT_STATUS_UNSUCCESSFUL
;
146 /* Look through list */
147 for (i
=0;i
<ARRAY_SIZE(unix_nt_errmap
);i
++) {
148 if (unix_nt_errmap
[i
].unix_error
== unix_error
) {
149 return unix_nt_errmap
[i
].nt_error
;
154 return NT_STATUS_ACCESS_DENIED
;