blob: c0b25b28be6ccc1079185bc3effd6672c56976de [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/cifs/netmisc.c
3 *
Steve Frenchad7a2922008-02-07 23:25:02 +00004 * Copyright (c) International Business Machines Corp., 2002,2008
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Author(s): Steve French (sfrench@us.ibm.com)
Steve French38702532007-07-08 15:40:40 +00006 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Error mapping routines from Samba libsmb/errormap.c
8 * Copyright (C) Andrew Tridgell 2001
9 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
Steve French38702532007-07-08 15:40:40 +000012 * the Free Software Foundation; either version 2 of the License, or
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * (at your option) any later version.
Steve French38702532007-07-08 15:40:40 +000014 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
18 * the GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
Steve French38702532007-07-08 15:40:40 +000021 * along with this program; if not, write to the Free Software
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25#include <linux/net.h>
26#include <linux/string.h>
27#include <linux/in.h>
28#include <linux/ctype.h>
29#include <linux/fs.h>
30#include <asm/div64.h>
31#include <asm/byteorder.h>
Steve French5858ae42007-04-25 11:59:10 +000032#include <linux/inet.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "cifsfs.h"
34#include "cifspdu.h"
35#include "cifsglob.h"
36#include "cifsproto.h"
37#include "smberr.h"
38#include "cifs_debug.h"
39#include "nterr.h"
40
41struct smb_to_posix_error {
42 __u16 smb_err;
43 int posix_code;
44};
45
46static const struct smb_to_posix_error mapping_table_ERRDOS[] = {
47 {ERRbadfunc, -EINVAL},
48 {ERRbadfile, -ENOENT},
49 {ERRbadpath, -ENOTDIR},
50 {ERRnofids, -EMFILE},
51 {ERRnoaccess, -EACCES},
52 {ERRbadfid, -EBADF},
53 {ERRbadmcb, -EIO},
54 {ERRnomem, -ENOMEM},
55 {ERRbadmem, -EFAULT},
56 {ERRbadenv, -EFAULT},
57 {ERRbadformat, -EINVAL},
58 {ERRbadaccess, -EACCES},
59 {ERRbaddata, -EIO},
60 {ERRbaddrive, -ENXIO},
61 {ERRremcd, -EACCES},
62 {ERRdiffdevice, -EXDEV},
63 {ERRnofiles, -ENOENT},
Jeff Layton3572d282010-07-26 10:29:57 -040064 {ERRwriteprot, -EROFS},
Sachin Prabhu47c78f42013-03-11 13:08:49 +000065 {ERRbadshare, -EBUSY},
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 {ERRlock, -EACCES},
67 {ERRunsup, -EINVAL},
Steve French38702532007-07-08 15:40:40 +000068 {ERRnosuchshare, -ENXIO},
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 {ERRfilexists, -EEXIST},
70 {ERRinvparm, -EINVAL},
71 {ERRdiskfull, -ENOSPC},
72 {ERRinvname, -ENOENT},
Steve French38702532007-07-08 15:40:40 +000073 {ERRinvlevel, -EOPNOTSUPP},
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 {ERRdirnotempty, -ENOTEMPTY},
75 {ERRnotlocked, -ENOLCK},
Jeremy Allison7ee1af72006-08-02 21:56:33 +000076 {ERRcancelviolation, -ENOLCK},
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 {ERRalreadyexists, -EEXIST},
78 {ERRmoredata, -EOVERFLOW},
Steve French38702532007-07-08 15:40:40 +000079 {ERReasnotsupported, -EOPNOTSUPP},
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 {ErrQuota, -EDQUOT},
81 {ErrNotALink, -ENOLINK},
Steve French38702532007-07-08 15:40:40 +000082 {ERRnetlogonNotStarted, -ENOPROTOOPT},
Steve French9e39b0a2009-04-30 21:31:15 +000083 {ERRsymlink, -EOPNOTSUPP},
Steve French38702532007-07-08 15:40:40 +000084 {ErrTooManyLinks, -EMLINK},
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 {0, 0}
86};
87
88static const struct smb_to_posix_error mapping_table_ERRSRV[] = {
89 {ERRerror, -EIO},
Steve French7c7b25b2006-06-01 19:20:10 +000090 {ERRbadpw, -EACCES}, /* was EPERM */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 {ERRbadtype, -EREMOTE},
92 {ERRaccess, -EACCES},
93 {ERRinvtid, -ENXIO},
Steve French43411d62006-06-02 18:17:11 +000094 {ERRinvnetname, -ENXIO},
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 {ERRinvdevice, -ENXIO},
96 {ERRqfull, -ENOSPC},
97 {ERRqtoobig, -ENOSPC},
98 {ERRqeof, -EIO},
99 {ERRinvpfid, -EBADF},
100 {ERRsmbcmd, -EBADRQC},
101 {ERRsrverror, -EIO},
102 {ERRbadBID, -EIO},
103 {ERRfilespecs, -EINVAL},
104 {ERRbadLink, -EIO},
105 {ERRbadpermits, -EINVAL},
106 {ERRbadPID, -ESRCH},
107 {ERRsetattrmode, -EINVAL},
108 {ERRpaused, -EHOSTDOWN},
109 {ERRmsgoff, -EHOSTDOWN},
110 {ERRnoroom, -ENOSPC},
111 {ERRrmuns, -EUSERS},
112 {ERRtimeout, -ETIME},
Jeff Layton4f2b86a2012-09-24 09:33:40 -0400113 {ERRnoresource, -EREMOTEIO},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 {ERRtoomanyuids, -EUSERS},
115 {ERRbaduid, -EACCES},
116 {ERRusempx, -EIO},
117 {ERRusestd, -EIO},
118 {ERR_NOTIFY_ENUM_DIR, -ENOBUFS},
Steve Frencha761ac52007-10-18 21:45:27 +0000119 {ERRnoSuchUser, -EACCES},
120/* {ERRaccountexpired, -EACCES},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 {ERRbadclient, -EACCES},
122 {ERRbadLogonTime, -EACCES},
Steve Frencha761ac52007-10-18 21:45:27 +0000123 {ERRpasswordExpired, -EACCES},*/
124 {ERRaccountexpired, -EKEYEXPIRED},
125 {ERRbadclient, -EACCES},
126 {ERRbadLogonTime, -EACCES},
127 {ERRpasswordExpired, -EKEYEXPIRED},
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 {ERRnosupport, -EINVAL},
130 {0, 0}
131};
132
133static const struct smb_to_posix_error mapping_table_ERRHRD[] = {
134 {0, 0}
135};
136
Jeff Layton1e68b2b2009-06-11 10:27:30 -0400137/*
138 * Convert a string containing text IPv4 or IPv6 address to binary form.
139 *
140 * Returns 0 on failure.
141 */
142static int
David Howells67b76262010-07-22 18:33:01 +0100143cifs_inet_pton(const int address_family, const char *cp, int len, void *dst)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
Steve French5858ae42007-04-25 11:59:10 +0000145 int ret = 0;
146
147 /* calculate length by finding first slash or NULL */
Steve French582d21e2008-05-13 04:54:12 +0000148 if (address_family == AF_INET)
David Howells67b76262010-07-22 18:33:01 +0100149 ret = in4_pton(cp, len, dst, '\\', NULL);
Steve French582d21e2008-05-13 04:54:12 +0000150 else if (address_family == AF_INET6)
David Howells67b76262010-07-22 18:33:01 +0100151 ret = in6_pton(cp, len, dst , '\\', NULL);
Steve French582d21e2008-05-13 04:54:12 +0000152
David Howells67b76262010-07-22 18:33:01 +0100153 cFYI(DBG2, "address conversion returned %d for %*.*s",
154 ret, len, len, cp);
Steve French5858ae42007-04-25 11:59:10 +0000155 if (ret > 0)
156 ret = 1;
157 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158}
159
Jeff Layton1e68b2b2009-06-11 10:27:30 -0400160/*
161 * Try to convert a string to an IPv4 address and then attempt to convert
162 * it to an IPv6 address if that fails. Set the family field if either
Jeff Layton681bf722009-06-11 10:27:31 -0400163 * succeeds. If it's an IPv6 address and it has a '%' sign in it, try to
164 * treat the part following it as a numeric sin6_scope_id.
Jeff Layton1e68b2b2009-06-11 10:27:30 -0400165 *
166 * Returns 0 on failure.
167 */
168int
David Howells67b76262010-07-22 18:33:01 +0100169cifs_convert_address(struct sockaddr *dst, const char *src, int len)
Jeff Layton1e68b2b2009-06-11 10:27:30 -0400170{
David Howells67b76262010-07-22 18:33:01 +0100171 int rc, alen, slen;
172 const char *pct;
Jeff Layton96161252011-02-16 09:34:16 -0500173 char scope_id[13];
Jeff Layton1e68b2b2009-06-11 10:27:30 -0400174 struct sockaddr_in *s4 = (struct sockaddr_in *) dst;
Steve French361ea1a2009-06-15 13:46:12 +0000175 struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) dst;
Jeff Layton1e68b2b2009-06-11 10:27:30 -0400176
Jeff Layton681bf722009-06-11 10:27:31 -0400177 /* IPv4 address */
David Howells67b76262010-07-22 18:33:01 +0100178 if (cifs_inet_pton(AF_INET, src, len, &s4->sin_addr.s_addr)) {
Jeff Layton1e68b2b2009-06-11 10:27:30 -0400179 s4->sin_family = AF_INET;
180 return 1;
Jeff Layton1e68b2b2009-06-11 10:27:30 -0400181 }
182
David Howells67b76262010-07-22 18:33:01 +0100183 /* attempt to exclude the scope ID from the address part */
184 pct = memchr(src, '%', len);
185 alen = pct ? pct - src : len;
Jeff Layton681bf722009-06-11 10:27:31 -0400186
David Howells67b76262010-07-22 18:33:01 +0100187 rc = cifs_inet_pton(AF_INET6, src, alen, &s6->sin6_addr.s6_addr);
Jeff Layton681bf722009-06-11 10:27:31 -0400188 if (!rc)
189 return rc;
190
191 s6->sin6_family = AF_INET6;
192 if (pct) {
David Howells67b76262010-07-22 18:33:01 +0100193 /* grab the scope ID */
194 slen = len - (alen + 1);
195 if (slen <= 0 || slen > 12)
196 return 0;
197 memcpy(scope_id, pct + 1, slen);
198 scope_id[slen] = '\0';
199
Dan Carpenter2545e072012-03-01 10:06:52 +0300200 rc = kstrtouint(scope_id, 0, &s6->sin6_scope_id);
Jeff Layton96161252011-02-16 09:34:16 -0500201 rc = (rc == 0) ? 1 : 0;
Jeff Layton681bf722009-06-11 10:27:31 -0400202 }
203
204 return rc;
Jeff Layton1e68b2b2009-06-11 10:27:30 -0400205}
206
Jeff Laytonb979aaa2012-11-26 11:09:55 -0500207void
Jeff Layton32670392010-09-03 12:00:50 -0400208cifs_set_port(struct sockaddr *addr, const unsigned short int port)
209{
210 switch (addr->sa_family) {
211 case AF_INET:
212 ((struct sockaddr_in *)addr)->sin_port = htons(port);
213 break;
214 case AF_INET6:
215 ((struct sockaddr_in6 *)addr)->sin6_port = htons(port);
216 break;
Jeff Layton32670392010-09-03 12:00:50 -0400217 }
Jeff Layton50d97162010-07-06 20:43:01 -0400218}
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220/*****************************************************************************
221convert a NT status code to a dos class/code
222 *****************************************************************************/
223/* NT status -> dos error map */
224static const struct {
225 __u8 dos_class;
226 __u16 dos_code;
227 __u32 ntstatus;
228} ntstatus_to_dos_map[] = {
229 {
230 ERRDOS, ERRgeneral, NT_STATUS_UNSUCCESSFUL}, {
231 ERRDOS, ERRbadfunc, NT_STATUS_NOT_IMPLEMENTED}, {
Steve French75cf6bd2005-04-28 22:41:04 -0700232 ERRDOS, ERRinvlevel, NT_STATUS_INVALID_INFO_CLASS}, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 ERRDOS, 24, NT_STATUS_INFO_LENGTH_MISMATCH}, {
234 ERRHRD, ERRgeneral, NT_STATUS_ACCESS_VIOLATION}, {
235 ERRHRD, ERRgeneral, NT_STATUS_IN_PAGE_ERROR}, {
236 ERRHRD, ERRgeneral, NT_STATUS_PAGEFILE_QUOTA}, {
237 ERRDOS, ERRbadfid, NT_STATUS_INVALID_HANDLE}, {
238 ERRHRD, ERRgeneral, NT_STATUS_BAD_INITIAL_STACK}, {
239 ERRDOS, 193, NT_STATUS_BAD_INITIAL_PC}, {
240 ERRDOS, 87, NT_STATUS_INVALID_CID}, {
241 ERRHRD, ERRgeneral, NT_STATUS_TIMER_NOT_CANCELED}, {
242 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER}, {
243 ERRDOS, ERRbadfile, NT_STATUS_NO_SUCH_DEVICE}, {
244 ERRDOS, ERRbadfile, NT_STATUS_NO_SUCH_FILE}, {
245 ERRDOS, ERRbadfunc, NT_STATUS_INVALID_DEVICE_REQUEST}, {
246 ERRDOS, 38, NT_STATUS_END_OF_FILE}, {
247 ERRDOS, 34, NT_STATUS_WRONG_VOLUME}, {
248 ERRDOS, 21, NT_STATUS_NO_MEDIA_IN_DEVICE}, {
249 ERRHRD, ERRgeneral, NT_STATUS_UNRECOGNIZED_MEDIA}, {
250 ERRDOS, 27, NT_STATUS_NONEXISTENT_SECTOR},
251/* { This NT error code was 'sqashed'
Steve French38702532007-07-08 15:40:40 +0000252 from NT_STATUS_MORE_PROCESSING_REQUIRED to NT_STATUS_OK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 during the session setup } */
254 {
255 ERRDOS, ERRnomem, NT_STATUS_NO_MEMORY}, {
256 ERRDOS, 487, NT_STATUS_CONFLICTING_ADDRESSES}, {
257 ERRDOS, 487, NT_STATUS_NOT_MAPPED_VIEW}, {
258 ERRDOS, 87, NT_STATUS_UNABLE_TO_FREE_VM}, {
259 ERRDOS, 87, NT_STATUS_UNABLE_TO_DELETE_SECTION}, {
260 ERRDOS, 2142, NT_STATUS_INVALID_SYSTEM_SERVICE}, {
261 ERRHRD, ERRgeneral, NT_STATUS_ILLEGAL_INSTRUCTION}, {
262 ERRDOS, ERRnoaccess, NT_STATUS_INVALID_LOCK_SEQUENCE}, {
263 ERRDOS, ERRnoaccess, NT_STATUS_INVALID_VIEW_SIZE}, {
264 ERRDOS, 193, NT_STATUS_INVALID_FILE_FOR_SECTION}, {
265 ERRDOS, ERRnoaccess, NT_STATUS_ALREADY_COMMITTED},
266/* { This NT error code was 'sqashed'
Steve French38702532007-07-08 15:40:40 +0000267 from NT_STATUS_ACCESS_DENIED to NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 during the session setup } */
269 {
270 ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED}, {
271 ERRDOS, 111, NT_STATUS_BUFFER_TOO_SMALL}, {
272 ERRDOS, ERRbadfid, NT_STATUS_OBJECT_TYPE_MISMATCH}, {
273 ERRHRD, ERRgeneral, NT_STATUS_NONCONTINUABLE_EXCEPTION}, {
274 ERRHRD, ERRgeneral, NT_STATUS_INVALID_DISPOSITION}, {
275 ERRHRD, ERRgeneral, NT_STATUS_UNWIND}, {
276 ERRHRD, ERRgeneral, NT_STATUS_BAD_STACK}, {
277 ERRHRD, ERRgeneral, NT_STATUS_INVALID_UNWIND_TARGET}, {
278 ERRDOS, 158, NT_STATUS_NOT_LOCKED}, {
279 ERRHRD, ERRgeneral, NT_STATUS_PARITY_ERROR}, {
280 ERRDOS, 487, NT_STATUS_UNABLE_TO_DECOMMIT_VM}, {
281 ERRDOS, 487, NT_STATUS_NOT_COMMITTED}, {
282 ERRHRD, ERRgeneral, NT_STATUS_INVALID_PORT_ATTRIBUTES}, {
283 ERRHRD, ERRgeneral, NT_STATUS_PORT_MESSAGE_TOO_LONG}, {
284 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_MIX}, {
285 ERRHRD, ERRgeneral, NT_STATUS_INVALID_QUOTA_LOWER}, {
286 ERRHRD, ERRgeneral, NT_STATUS_DISK_CORRUPT_ERROR}, {
Steve Frenchad7a2922008-02-07 23:25:02 +0000287 /* mapping changed since shell does lookup on * expects FileNotFound */
288 ERRDOS, ERRbadfile, NT_STATUS_OBJECT_NAME_INVALID}, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 ERRDOS, ERRbadfile, NT_STATUS_OBJECT_NAME_NOT_FOUND}, {
290 ERRDOS, ERRalreadyexists, NT_STATUS_OBJECT_NAME_COLLISION}, {
291 ERRHRD, ERRgeneral, NT_STATUS_HANDLE_NOT_WAITABLE}, {
292 ERRDOS, ERRbadfid, NT_STATUS_PORT_DISCONNECTED}, {
293 ERRHRD, ERRgeneral, NT_STATUS_DEVICE_ALREADY_ATTACHED}, {
294 ERRDOS, 161, NT_STATUS_OBJECT_PATH_INVALID}, {
295 ERRDOS, ERRbadpath, NT_STATUS_OBJECT_PATH_NOT_FOUND}, {
296 ERRDOS, 161, NT_STATUS_OBJECT_PATH_SYNTAX_BAD}, {
297 ERRHRD, ERRgeneral, NT_STATUS_DATA_OVERRUN}, {
298 ERRHRD, ERRgeneral, NT_STATUS_DATA_LATE_ERROR}, {
299 ERRDOS, 23, NT_STATUS_DATA_ERROR}, {
300 ERRDOS, 23, NT_STATUS_CRC_ERROR}, {
301 ERRDOS, ERRnomem, NT_STATUS_SECTION_TOO_BIG}, {
302 ERRDOS, ERRnoaccess, NT_STATUS_PORT_CONNECTION_REFUSED}, {
303 ERRDOS, ERRbadfid, NT_STATUS_INVALID_PORT_HANDLE}, {
304 ERRDOS, ERRbadshare, NT_STATUS_SHARING_VIOLATION}, {
305 ERRHRD, ERRgeneral, NT_STATUS_QUOTA_EXCEEDED}, {
306 ERRDOS, 87, NT_STATUS_INVALID_PAGE_PROTECTION}, {
307 ERRDOS, 288, NT_STATUS_MUTANT_NOT_OWNED}, {
308 ERRDOS, 298, NT_STATUS_SEMAPHORE_LIMIT_EXCEEDED}, {
309 ERRDOS, 87, NT_STATUS_PORT_ALREADY_SET}, {
310 ERRDOS, 87, NT_STATUS_SECTION_NOT_IMAGE}, {
311 ERRDOS, 156, NT_STATUS_SUSPEND_COUNT_EXCEEDED}, {
312 ERRDOS, ERRnoaccess, NT_STATUS_THREAD_IS_TERMINATING}, {
313 ERRDOS, 87, NT_STATUS_BAD_WORKING_SET_LIMIT}, {
314 ERRDOS, 87, NT_STATUS_INCOMPATIBLE_FILE_MAP}, {
315 ERRDOS, 87, NT_STATUS_SECTION_PROTECTION}, {
316 ERRDOS, ERReasnotsupported, NT_STATUS_EAS_NOT_SUPPORTED}, {
317 ERRDOS, 255, NT_STATUS_EA_TOO_LARGE}, {
318 ERRHRD, ERRgeneral, NT_STATUS_NONEXISTENT_EA_ENTRY}, {
319 ERRHRD, ERRgeneral, NT_STATUS_NO_EAS_ON_FILE}, {
320 ERRHRD, ERRgeneral, NT_STATUS_EA_CORRUPT_ERROR}, {
321 ERRDOS, ERRlock, NT_STATUS_FILE_LOCK_CONFLICT}, {
322 ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED}, {
323 ERRDOS, ERRbadfile, NT_STATUS_DELETE_PENDING}, {
324 ERRDOS, ERRunsup, NT_STATUS_CTL_FILE_NOT_SUPPORTED}, {
325 ERRHRD, ERRgeneral, NT_STATUS_UNKNOWN_REVISION}, {
326 ERRHRD, ERRgeneral, NT_STATUS_REVISION_MISMATCH}, {
327 ERRHRD, ERRgeneral, NT_STATUS_INVALID_OWNER}, {
328 ERRHRD, ERRgeneral, NT_STATUS_INVALID_PRIMARY_GROUP}, {
329 ERRHRD, ERRgeneral, NT_STATUS_NO_IMPERSONATION_TOKEN}, {
330 ERRHRD, ERRgeneral, NT_STATUS_CANT_DISABLE_MANDATORY}, {
331 ERRDOS, 2215, NT_STATUS_NO_LOGON_SERVERS}, {
332 ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_LOGON_SESSION}, {
333 ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_PRIVILEGE}, {
334 ERRDOS, ERRnoaccess, NT_STATUS_PRIVILEGE_NOT_HELD}, {
335 ERRHRD, ERRgeneral, NT_STATUS_INVALID_ACCOUNT_NAME}, {
336 ERRHRD, ERRgeneral, NT_STATUS_USER_EXISTS},
337/* { This NT error code was 'sqashed'
Steve French38702532007-07-08 15:40:40 +0000338 from NT_STATUS_NO_SUCH_USER to NT_STATUS_LOGON_FAILURE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 during the session setup } */
340 {
Steve Frencha761ac52007-10-18 21:45:27 +0000341 ERRDOS, ERRnoaccess, NT_STATUS_NO_SUCH_USER}, { /* could map to 2238 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 ERRHRD, ERRgeneral, NT_STATUS_GROUP_EXISTS}, {
343 ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_GROUP}, {
344 ERRHRD, ERRgeneral, NT_STATUS_MEMBER_IN_GROUP}, {
345 ERRHRD, ERRgeneral, NT_STATUS_MEMBER_NOT_IN_GROUP}, {
346 ERRHRD, ERRgeneral, NT_STATUS_LAST_ADMIN},
347/* { This NT error code was 'sqashed'
Steve French38702532007-07-08 15:40:40 +0000348 from NT_STATUS_WRONG_PASSWORD to NT_STATUS_LOGON_FAILURE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 during the session setup } */
350 {
351 ERRSRV, ERRbadpw, NT_STATUS_WRONG_PASSWORD}, {
352 ERRHRD, ERRgeneral, NT_STATUS_ILL_FORMED_PASSWORD}, {
353 ERRHRD, ERRgeneral, NT_STATUS_PASSWORD_RESTRICTION}, {
354 ERRDOS, ERRnoaccess, NT_STATUS_LOGON_FAILURE}, {
355 ERRHRD, ERRgeneral, NT_STATUS_ACCOUNT_RESTRICTION}, {
Steve Frencha761ac52007-10-18 21:45:27 +0000356 ERRSRV, ERRbadLogonTime, NT_STATUS_INVALID_LOGON_HOURS}, {
357 ERRSRV, ERRbadclient, NT_STATUS_INVALID_WORKSTATION}, {
Steve French6ab16d22005-11-29 20:55:11 -0800358 ERRSRV, ERRpasswordExpired, NT_STATUS_PASSWORD_EXPIRED}, {
Steve Frencha761ac52007-10-18 21:45:27 +0000359 ERRSRV, ERRaccountexpired, NT_STATUS_ACCOUNT_DISABLED}, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 ERRHRD, ERRgeneral, NT_STATUS_NONE_MAPPED}, {
361 ERRHRD, ERRgeneral, NT_STATUS_TOO_MANY_LUIDS_REQUESTED}, {
362 ERRHRD, ERRgeneral, NT_STATUS_LUIDS_EXHAUSTED}, {
363 ERRHRD, ERRgeneral, NT_STATUS_INVALID_SUB_AUTHORITY}, {
364 ERRHRD, ERRgeneral, NT_STATUS_INVALID_ACL}, {
365 ERRHRD, ERRgeneral, NT_STATUS_INVALID_SID}, {
366 ERRHRD, ERRgeneral, NT_STATUS_INVALID_SECURITY_DESCR}, {
367 ERRDOS, 127, NT_STATUS_PROCEDURE_NOT_FOUND}, {
368 ERRDOS, 193, NT_STATUS_INVALID_IMAGE_FORMAT}, {
369 ERRHRD, ERRgeneral, NT_STATUS_NO_TOKEN}, {
370 ERRHRD, ERRgeneral, NT_STATUS_BAD_INHERITANCE_ACL}, {
371 ERRDOS, 158, NT_STATUS_RANGE_NOT_LOCKED}, {
372 ERRDOS, 112, NT_STATUS_DISK_FULL}, {
373 ERRHRD, ERRgeneral, NT_STATUS_SERVER_DISABLED}, {
374 ERRHRD, ERRgeneral, NT_STATUS_SERVER_NOT_DISABLED}, {
375 ERRDOS, 68, NT_STATUS_TOO_MANY_GUIDS_REQUESTED}, {
376 ERRDOS, 259, NT_STATUS_GUIDS_EXHAUSTED}, {
377 ERRHRD, ERRgeneral, NT_STATUS_INVALID_ID_AUTHORITY}, {
378 ERRDOS, 259, NT_STATUS_AGENTS_EXHAUSTED}, {
379 ERRDOS, 154, NT_STATUS_INVALID_VOLUME_LABEL}, {
380 ERRDOS, 14, NT_STATUS_SECTION_NOT_EXTENDED}, {
381 ERRDOS, 487, NT_STATUS_NOT_MAPPED_DATA}, {
382 ERRHRD, ERRgeneral, NT_STATUS_RESOURCE_DATA_NOT_FOUND}, {
383 ERRHRD, ERRgeneral, NT_STATUS_RESOURCE_TYPE_NOT_FOUND}, {
384 ERRHRD, ERRgeneral, NT_STATUS_RESOURCE_NAME_NOT_FOUND}, {
385 ERRHRD, ERRgeneral, NT_STATUS_ARRAY_BOUNDS_EXCEEDED}, {
386 ERRHRD, ERRgeneral, NT_STATUS_FLOAT_DENORMAL_OPERAND}, {
387 ERRHRD, ERRgeneral, NT_STATUS_FLOAT_DIVIDE_BY_ZERO}, {
388 ERRHRD, ERRgeneral, NT_STATUS_FLOAT_INEXACT_RESULT}, {
389 ERRHRD, ERRgeneral, NT_STATUS_FLOAT_INVALID_OPERATION}, {
390 ERRHRD, ERRgeneral, NT_STATUS_FLOAT_OVERFLOW}, {
391 ERRHRD, ERRgeneral, NT_STATUS_FLOAT_STACK_CHECK}, {
392 ERRHRD, ERRgeneral, NT_STATUS_FLOAT_UNDERFLOW}, {
393 ERRHRD, ERRgeneral, NT_STATUS_INTEGER_DIVIDE_BY_ZERO}, {
394 ERRDOS, 534, NT_STATUS_INTEGER_OVERFLOW}, {
395 ERRHRD, ERRgeneral, NT_STATUS_PRIVILEGED_INSTRUCTION}, {
396 ERRDOS, ERRnomem, NT_STATUS_TOO_MANY_PAGING_FILES}, {
397 ERRHRD, ERRgeneral, NT_STATUS_FILE_INVALID}, {
398 ERRHRD, ERRgeneral, NT_STATUS_ALLOTTED_SPACE_EXCEEDED},
399/* { This NT error code was 'sqashed'
Steve French38702532007-07-08 15:40:40 +0000400 from NT_STATUS_INSUFFICIENT_RESOURCES to
401 NT_STATUS_INSUFF_SERVER_RESOURCES during the session setup } */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 {
Jeff Layton4f2b86a2012-09-24 09:33:40 -0400403 ERRDOS, ERRnoresource, NT_STATUS_INSUFFICIENT_RESOURCES}, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 ERRDOS, ERRbadpath, NT_STATUS_DFS_EXIT_PATH_FOUND}, {
405 ERRDOS, 23, NT_STATUS_DEVICE_DATA_ERROR}, {
406 ERRHRD, ERRgeneral, NT_STATUS_DEVICE_NOT_CONNECTED}, {
407 ERRDOS, 21, NT_STATUS_DEVICE_POWER_FAILURE}, {
408 ERRDOS, 487, NT_STATUS_FREE_VM_NOT_AT_BASE}, {
409 ERRDOS, 487, NT_STATUS_MEMORY_NOT_ALLOCATED}, {
410 ERRHRD, ERRgeneral, NT_STATUS_WORKING_SET_QUOTA}, {
411 ERRDOS, 19, NT_STATUS_MEDIA_WRITE_PROTECTED}, {
412 ERRDOS, 21, NT_STATUS_DEVICE_NOT_READY}, {
413 ERRHRD, ERRgeneral, NT_STATUS_INVALID_GROUP_ATTRIBUTES}, {
414 ERRHRD, ERRgeneral, NT_STATUS_BAD_IMPERSONATION_LEVEL}, {
415 ERRHRD, ERRgeneral, NT_STATUS_CANT_OPEN_ANONYMOUS}, {
416 ERRHRD, ERRgeneral, NT_STATUS_BAD_VALIDATION_CLASS}, {
417 ERRHRD, ERRgeneral, NT_STATUS_BAD_TOKEN_TYPE}, {
418 ERRDOS, 87, NT_STATUS_BAD_MASTER_BOOT_RECORD}, {
419 ERRHRD, ERRgeneral, NT_STATUS_INSTRUCTION_MISALIGNMENT}, {
420 ERRDOS, ERRpipebusy, NT_STATUS_INSTANCE_NOT_AVAILABLE}, {
421 ERRDOS, ERRpipebusy, NT_STATUS_PIPE_NOT_AVAILABLE}, {
422 ERRDOS, ERRbadpipe, NT_STATUS_INVALID_PIPE_STATE}, {
423 ERRDOS, ERRpipebusy, NT_STATUS_PIPE_BUSY}, {
424 ERRDOS, ERRbadfunc, NT_STATUS_ILLEGAL_FUNCTION}, {
425 ERRDOS, ERRnotconnected, NT_STATUS_PIPE_DISCONNECTED}, {
426 ERRDOS, ERRpipeclosing, NT_STATUS_PIPE_CLOSING}, {
427 ERRHRD, ERRgeneral, NT_STATUS_PIPE_CONNECTED}, {
428 ERRHRD, ERRgeneral, NT_STATUS_PIPE_LISTENING}, {
429 ERRDOS, ERRbadpipe, NT_STATUS_INVALID_READ_MODE}, {
430 ERRDOS, 121, NT_STATUS_IO_TIMEOUT}, {
431 ERRDOS, 38, NT_STATUS_FILE_FORCED_CLOSED}, {
432 ERRHRD, ERRgeneral, NT_STATUS_PROFILING_NOT_STARTED}, {
433 ERRHRD, ERRgeneral, NT_STATUS_PROFILING_NOT_STOPPED}, {
434 ERRHRD, ERRgeneral, NT_STATUS_COULD_NOT_INTERPRET}, {
435 ERRDOS, ERRnoaccess, NT_STATUS_FILE_IS_A_DIRECTORY}, {
436 ERRDOS, ERRunsup, NT_STATUS_NOT_SUPPORTED}, {
437 ERRDOS, 51, NT_STATUS_REMOTE_NOT_LISTENING}, {
438 ERRDOS, 52, NT_STATUS_DUPLICATE_NAME}, {
439 ERRDOS, 53, NT_STATUS_BAD_NETWORK_PATH}, {
440 ERRDOS, 54, NT_STATUS_NETWORK_BUSY}, {
441 ERRDOS, 55, NT_STATUS_DEVICE_DOES_NOT_EXIST}, {
442 ERRDOS, 56, NT_STATUS_TOO_MANY_COMMANDS}, {
443 ERRDOS, 57, NT_STATUS_ADAPTER_HARDWARE_ERROR}, {
444 ERRDOS, 58, NT_STATUS_INVALID_NETWORK_RESPONSE}, {
445 ERRDOS, 59, NT_STATUS_UNEXPECTED_NETWORK_ERROR}, {
446 ERRDOS, 60, NT_STATUS_BAD_REMOTE_ADAPTER}, {
447 ERRDOS, 61, NT_STATUS_PRINT_QUEUE_FULL}, {
448 ERRDOS, 62, NT_STATUS_NO_SPOOL_SPACE}, {
449 ERRDOS, 63, NT_STATUS_PRINT_CANCELLED}, {
450 ERRDOS, 64, NT_STATUS_NETWORK_NAME_DELETED}, {
451 ERRDOS, 65, NT_STATUS_NETWORK_ACCESS_DENIED}, {
452 ERRDOS, 66, NT_STATUS_BAD_DEVICE_TYPE}, {
453 ERRDOS, ERRnosuchshare, NT_STATUS_BAD_NETWORK_NAME}, {
454 ERRDOS, 68, NT_STATUS_TOO_MANY_NAMES}, {
455 ERRDOS, 69, NT_STATUS_TOO_MANY_SESSIONS}, {
456 ERRDOS, 70, NT_STATUS_SHARING_PAUSED}, {
457 ERRDOS, 71, NT_STATUS_REQUEST_NOT_ACCEPTED}, {
458 ERRDOS, 72, NT_STATUS_REDIRECTOR_PAUSED}, {
459 ERRDOS, 88, NT_STATUS_NET_WRITE_FAULT}, {
460 ERRHRD, ERRgeneral, NT_STATUS_PROFILING_AT_LIMIT}, {
461 ERRDOS, ERRdiffdevice, NT_STATUS_NOT_SAME_DEVICE}, {
462 ERRDOS, ERRnoaccess, NT_STATUS_FILE_RENAMED}, {
463 ERRDOS, 240, NT_STATUS_VIRTUAL_CIRCUIT_CLOSED}, {
464 ERRHRD, ERRgeneral, NT_STATUS_NO_SECURITY_ON_OBJECT}, {
465 ERRHRD, ERRgeneral, NT_STATUS_CANT_WAIT}, {
466 ERRDOS, ERRpipeclosing, NT_STATUS_PIPE_EMPTY}, {
467 ERRHRD, ERRgeneral, NT_STATUS_CANT_ACCESS_DOMAIN_INFO}, {
468 ERRHRD, ERRgeneral, NT_STATUS_CANT_TERMINATE_SELF}, {
469 ERRHRD, ERRgeneral, NT_STATUS_INVALID_SERVER_STATE}, {
470 ERRHRD, ERRgeneral, NT_STATUS_INVALID_DOMAIN_STATE}, {
471 ERRHRD, ERRgeneral, NT_STATUS_INVALID_DOMAIN_ROLE}, {
472 ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_DOMAIN}, {
473 ERRHRD, ERRgeneral, NT_STATUS_DOMAIN_EXISTS}, {
474 ERRHRD, ERRgeneral, NT_STATUS_DOMAIN_LIMIT_EXCEEDED}, {
475 ERRDOS, 300, NT_STATUS_OPLOCK_NOT_GRANTED}, {
476 ERRDOS, 301, NT_STATUS_INVALID_OPLOCK_PROTOCOL}, {
477 ERRHRD, ERRgeneral, NT_STATUS_INTERNAL_DB_CORRUPTION}, {
478 ERRHRD, ERRgeneral, NT_STATUS_INTERNAL_ERROR}, {
479 ERRHRD, ERRgeneral, NT_STATUS_GENERIC_NOT_MAPPED}, {
480 ERRHRD, ERRgeneral, NT_STATUS_BAD_DESCRIPTOR_FORMAT}, {
481 ERRHRD, ERRgeneral, NT_STATUS_INVALID_USER_BUFFER}, {
482 ERRHRD, ERRgeneral, NT_STATUS_UNEXPECTED_IO_ERROR}, {
483 ERRHRD, ERRgeneral, NT_STATUS_UNEXPECTED_MM_CREATE_ERR}, {
484 ERRHRD, ERRgeneral, NT_STATUS_UNEXPECTED_MM_MAP_ERROR}, {
485 ERRHRD, ERRgeneral, NT_STATUS_UNEXPECTED_MM_EXTEND_ERR}, {
486 ERRHRD, ERRgeneral, NT_STATUS_NOT_LOGON_PROCESS}, {
487 ERRHRD, ERRgeneral, NT_STATUS_LOGON_SESSION_EXISTS}, {
488 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_1}, {
489 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_2}, {
490 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_3}, {
491 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_4}, {
492 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_5}, {
493 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_6}, {
494 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_7}, {
495 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_8}, {
496 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_9}, {
497 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_10}, {
498 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_11}, {
499 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_12}, {
500 ERRDOS, ERRbadpath, NT_STATUS_REDIRECTOR_NOT_STARTED}, {
501 ERRHRD, ERRgeneral, NT_STATUS_REDIRECTOR_STARTED}, {
502 ERRHRD, ERRgeneral, NT_STATUS_STACK_OVERFLOW}, {
503 ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_PACKAGE}, {
504 ERRHRD, ERRgeneral, NT_STATUS_BAD_FUNCTION_TABLE}, {
505 ERRDOS, 203, 0xc0000100}, {
506 ERRDOS, 145, NT_STATUS_DIRECTORY_NOT_EMPTY}, {
507 ERRHRD, ERRgeneral, NT_STATUS_FILE_CORRUPT_ERROR}, {
508 ERRDOS, 267, NT_STATUS_NOT_A_DIRECTORY}, {
509 ERRHRD, ERRgeneral, NT_STATUS_BAD_LOGON_SESSION_STATE}, {
510 ERRHRD, ERRgeneral, NT_STATUS_LOGON_SESSION_COLLISION}, {
511 ERRDOS, 206, NT_STATUS_NAME_TOO_LONG}, {
512 ERRDOS, 2401, NT_STATUS_FILES_OPEN}, {
513 ERRDOS, 2404, NT_STATUS_CONNECTION_IN_USE}, {
514 ERRHRD, ERRgeneral, NT_STATUS_MESSAGE_NOT_FOUND}, {
515 ERRDOS, ERRnoaccess, NT_STATUS_PROCESS_IS_TERMINATING}, {
516 ERRHRD, ERRgeneral, NT_STATUS_INVALID_LOGON_TYPE}, {
517 ERRHRD, ERRgeneral, NT_STATUS_NO_GUID_TRANSLATION}, {
518 ERRHRD, ERRgeneral, NT_STATUS_CANNOT_IMPERSONATE}, {
519 ERRHRD, ERRgeneral, NT_STATUS_IMAGE_ALREADY_LOADED}, {
520 ERRHRD, ERRgeneral, NT_STATUS_ABIOS_NOT_PRESENT}, {
521 ERRHRD, ERRgeneral, NT_STATUS_ABIOS_LID_NOT_EXIST}, {
522 ERRHRD, ERRgeneral, NT_STATUS_ABIOS_LID_ALREADY_OWNED}, {
523 ERRHRD, ERRgeneral, NT_STATUS_ABIOS_NOT_LID_OWNER}, {
524 ERRHRD, ERRgeneral, NT_STATUS_ABIOS_INVALID_COMMAND}, {
525 ERRHRD, ERRgeneral, NT_STATUS_ABIOS_INVALID_LID}, {
526 ERRHRD, ERRgeneral, NT_STATUS_ABIOS_SELECTOR_NOT_AVAILABLE}, {
527 ERRHRD, ERRgeneral, NT_STATUS_ABIOS_INVALID_SELECTOR}, {
528 ERRHRD, ERRgeneral, NT_STATUS_NO_LDT}, {
529 ERRHRD, ERRgeneral, NT_STATUS_INVALID_LDT_SIZE}, {
530 ERRHRD, ERRgeneral, NT_STATUS_INVALID_LDT_OFFSET}, {
531 ERRHRD, ERRgeneral, NT_STATUS_INVALID_LDT_DESCRIPTOR}, {
532 ERRDOS, 193, NT_STATUS_INVALID_IMAGE_NE_FORMAT}, {
533 ERRHRD, ERRgeneral, NT_STATUS_RXACT_INVALID_STATE}, {
534 ERRHRD, ERRgeneral, NT_STATUS_RXACT_COMMIT_FAILURE}, {
535 ERRHRD, ERRgeneral, NT_STATUS_MAPPED_FILE_SIZE_ZERO}, {
536 ERRDOS, ERRnofids, NT_STATUS_TOO_MANY_OPENED_FILES}, {
537 ERRHRD, ERRgeneral, NT_STATUS_CANCELLED}, {
538 ERRDOS, ERRnoaccess, NT_STATUS_CANNOT_DELETE}, {
539 ERRHRD, ERRgeneral, NT_STATUS_INVALID_COMPUTER_NAME}, {
540 ERRDOS, ERRnoaccess, NT_STATUS_FILE_DELETED}, {
541 ERRHRD, ERRgeneral, NT_STATUS_SPECIAL_ACCOUNT}, {
542 ERRHRD, ERRgeneral, NT_STATUS_SPECIAL_GROUP}, {
543 ERRHRD, ERRgeneral, NT_STATUS_SPECIAL_USER}, {
544 ERRHRD, ERRgeneral, NT_STATUS_MEMBERS_PRIMARY_GROUP}, {
545 ERRDOS, ERRbadfid, NT_STATUS_FILE_CLOSED}, {
546 ERRHRD, ERRgeneral, NT_STATUS_TOO_MANY_THREADS}, {
547 ERRHRD, ERRgeneral, NT_STATUS_THREAD_NOT_IN_PROCESS}, {
548 ERRHRD, ERRgeneral, NT_STATUS_TOKEN_ALREADY_IN_USE}, {
549 ERRHRD, ERRgeneral, NT_STATUS_PAGEFILE_QUOTA_EXCEEDED}, {
550 ERRHRD, ERRgeneral, NT_STATUS_COMMITMENT_LIMIT}, {
551 ERRDOS, 193, NT_STATUS_INVALID_IMAGE_LE_FORMAT}, {
552 ERRDOS, 193, NT_STATUS_INVALID_IMAGE_NOT_MZ}, {
553 ERRDOS, 193, NT_STATUS_INVALID_IMAGE_PROTECT}, {
554 ERRDOS, 193, NT_STATUS_INVALID_IMAGE_WIN_16}, {
555 ERRHRD, ERRgeneral, NT_STATUS_LOGON_SERVER_CONFLICT}, {
556 ERRHRD, ERRgeneral, NT_STATUS_TIME_DIFFERENCE_AT_DC}, {
557 ERRHRD, ERRgeneral, NT_STATUS_SYNCHRONIZATION_REQUIRED}, {
558 ERRDOS, 126, NT_STATUS_DLL_NOT_FOUND}, {
559 ERRHRD, ERRgeneral, NT_STATUS_OPEN_FAILED}, {
560 ERRHRD, ERRgeneral, NT_STATUS_IO_PRIVILEGE_FAILED}, {
561 ERRDOS, 182, NT_STATUS_ORDINAL_NOT_FOUND}, {
562 ERRDOS, 127, NT_STATUS_ENTRYPOINT_NOT_FOUND}, {
563 ERRHRD, ERRgeneral, NT_STATUS_CONTROL_C_EXIT}, {
564 ERRDOS, 64, NT_STATUS_LOCAL_DISCONNECT}, {
565 ERRDOS, 64, NT_STATUS_REMOTE_DISCONNECT}, {
566 ERRDOS, 51, NT_STATUS_REMOTE_RESOURCES}, {
567 ERRDOS, 59, NT_STATUS_LINK_FAILED}, {
568 ERRDOS, 59, NT_STATUS_LINK_TIMEOUT}, {
569 ERRDOS, 59, NT_STATUS_INVALID_CONNECTION}, {
570 ERRDOS, 59, NT_STATUS_INVALID_ADDRESS}, {
571 ERRHRD, ERRgeneral, NT_STATUS_DLL_INIT_FAILED}, {
572 ERRHRD, ERRgeneral, NT_STATUS_MISSING_SYSTEMFILE}, {
573 ERRHRD, ERRgeneral, NT_STATUS_UNHANDLED_EXCEPTION}, {
574 ERRHRD, ERRgeneral, NT_STATUS_APP_INIT_FAILURE}, {
575 ERRHRD, ERRgeneral, NT_STATUS_PAGEFILE_CREATE_FAILED}, {
576 ERRHRD, ERRgeneral, NT_STATUS_NO_PAGEFILE}, {
577 ERRDOS, 124, NT_STATUS_INVALID_LEVEL}, {
578 ERRDOS, 86, NT_STATUS_WRONG_PASSWORD_CORE}, {
579 ERRHRD, ERRgeneral, NT_STATUS_ILLEGAL_FLOAT_CONTEXT}, {
580 ERRDOS, 109, NT_STATUS_PIPE_BROKEN}, {
581 ERRHRD, ERRgeneral, NT_STATUS_REGISTRY_CORRUPT}, {
582 ERRHRD, ERRgeneral, NT_STATUS_REGISTRY_IO_FAILED}, {
583 ERRHRD, ERRgeneral, NT_STATUS_NO_EVENT_PAIR}, {
584 ERRHRD, ERRgeneral, NT_STATUS_UNRECOGNIZED_VOLUME}, {
585 ERRHRD, ERRgeneral, NT_STATUS_SERIAL_NO_DEVICE_INITED}, {
586 ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_ALIAS}, {
587 ERRHRD, ERRgeneral, NT_STATUS_MEMBER_NOT_IN_ALIAS}, {
588 ERRHRD, ERRgeneral, NT_STATUS_MEMBER_IN_ALIAS}, {
589 ERRHRD, ERRgeneral, NT_STATUS_ALIAS_EXISTS}, {
590 ERRHRD, ERRgeneral, NT_STATUS_LOGON_NOT_GRANTED}, {
591 ERRHRD, ERRgeneral, NT_STATUS_TOO_MANY_SECRETS}, {
592 ERRHRD, ERRgeneral, NT_STATUS_SECRET_TOO_LONG}, {
593 ERRHRD, ERRgeneral, NT_STATUS_INTERNAL_DB_ERROR}, {
594 ERRHRD, ERRgeneral, NT_STATUS_FULLSCREEN_MODE}, {
595 ERRHRD, ERRgeneral, NT_STATUS_TOO_MANY_CONTEXT_IDS}, {
596 ERRDOS, ERRnoaccess, NT_STATUS_LOGON_TYPE_NOT_GRANTED}, {
597 ERRHRD, ERRgeneral, NT_STATUS_NOT_REGISTRY_FILE}, {
598 ERRHRD, ERRgeneral, NT_STATUS_NT_CROSS_ENCRYPTION_REQUIRED}, {
599 ERRHRD, ERRgeneral, NT_STATUS_DOMAIN_CTRLR_CONFIG_ERROR}, {
600 ERRHRD, ERRgeneral, NT_STATUS_FT_MISSING_MEMBER}, {
601 ERRHRD, ERRgeneral, NT_STATUS_ILL_FORMED_SERVICE_ENTRY}, {
602 ERRHRD, ERRgeneral, NT_STATUS_ILLEGAL_CHARACTER}, {
603 ERRHRD, ERRgeneral, NT_STATUS_UNMAPPABLE_CHARACTER}, {
604 ERRHRD, ERRgeneral, NT_STATUS_UNDEFINED_CHARACTER}, {
605 ERRHRD, ERRgeneral, NT_STATUS_FLOPPY_VOLUME}, {
606 ERRHRD, ERRgeneral, NT_STATUS_FLOPPY_ID_MARK_NOT_FOUND}, {
607 ERRHRD, ERRgeneral, NT_STATUS_FLOPPY_WRONG_CYLINDER}, {
608 ERRHRD, ERRgeneral, NT_STATUS_FLOPPY_UNKNOWN_ERROR}, {
609 ERRHRD, ERRgeneral, NT_STATUS_FLOPPY_BAD_REGISTERS}, {
610 ERRHRD, ERRgeneral, NT_STATUS_DISK_RECALIBRATE_FAILED}, {
611 ERRHRD, ERRgeneral, NT_STATUS_DISK_OPERATION_FAILED}, {
612 ERRHRD, ERRgeneral, NT_STATUS_DISK_RESET_FAILED}, {
613 ERRHRD, ERRgeneral, NT_STATUS_SHARED_IRQ_BUSY}, {
614 ERRHRD, ERRgeneral, NT_STATUS_FT_ORPHANING}, {
615 ERRHRD, ERRgeneral, 0xc000016e}, {
616 ERRHRD, ERRgeneral, 0xc000016f}, {
617 ERRHRD, ERRgeneral, 0xc0000170}, {
618 ERRHRD, ERRgeneral, 0xc0000171}, {
619 ERRHRD, ERRgeneral, NT_STATUS_PARTITION_FAILURE}, {
620 ERRHRD, ERRgeneral, NT_STATUS_INVALID_BLOCK_LENGTH}, {
621 ERRHRD, ERRgeneral, NT_STATUS_DEVICE_NOT_PARTITIONED}, {
622 ERRHRD, ERRgeneral, NT_STATUS_UNABLE_TO_LOCK_MEDIA}, {
623 ERRHRD, ERRgeneral, NT_STATUS_UNABLE_TO_UNLOAD_MEDIA}, {
624 ERRHRD, ERRgeneral, NT_STATUS_EOM_OVERFLOW}, {
625 ERRHRD, ERRgeneral, NT_STATUS_NO_MEDIA}, {
626 ERRHRD, ERRgeneral, 0xc0000179}, {
627 ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_MEMBER}, {
628 ERRHRD, ERRgeneral, NT_STATUS_INVALID_MEMBER}, {
629 ERRHRD, ERRgeneral, NT_STATUS_KEY_DELETED}, {
630 ERRHRD, ERRgeneral, NT_STATUS_NO_LOG_SPACE}, {
631 ERRHRD, ERRgeneral, NT_STATUS_TOO_MANY_SIDS}, {
632 ERRHRD, ERRgeneral, NT_STATUS_LM_CROSS_ENCRYPTION_REQUIRED}, {
633 ERRHRD, ERRgeneral, NT_STATUS_KEY_HAS_CHILDREN}, {
634 ERRHRD, ERRgeneral, NT_STATUS_CHILD_MUST_BE_VOLATILE}, {
635 ERRDOS, 87, NT_STATUS_DEVICE_CONFIGURATION_ERROR}, {
636 ERRHRD, ERRgeneral, NT_STATUS_DRIVER_INTERNAL_ERROR}, {
637 ERRDOS, 22, NT_STATUS_INVALID_DEVICE_STATE}, {
638 ERRHRD, ERRgeneral, NT_STATUS_IO_DEVICE_ERROR}, {
639 ERRHRD, ERRgeneral, NT_STATUS_DEVICE_PROTOCOL_ERROR}, {
640 ERRHRD, ERRgeneral, NT_STATUS_BACKUP_CONTROLLER}, {
641 ERRHRD, ERRgeneral, NT_STATUS_LOG_FILE_FULL}, {
642 ERRDOS, 19, NT_STATUS_TOO_LATE}, {
643 ERRDOS, ERRnoaccess, NT_STATUS_NO_TRUST_LSA_SECRET},
644/* { This NT error code was 'sqashed'
Steve French38702532007-07-08 15:40:40 +0000645 from NT_STATUS_NO_TRUST_SAM_ACCOUNT to
646 NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE during the session setup } */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 {
648 ERRDOS, ERRnoaccess, NT_STATUS_NO_TRUST_SAM_ACCOUNT}, {
649 ERRDOS, ERRnoaccess, NT_STATUS_TRUSTED_DOMAIN_FAILURE}, {
650 ERRDOS, ERRnoaccess, NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE}, {
651 ERRHRD, ERRgeneral, NT_STATUS_EVENTLOG_FILE_CORRUPT}, {
652 ERRHRD, ERRgeneral, NT_STATUS_EVENTLOG_CANT_START}, {
653 ERRDOS, ERRnoaccess, NT_STATUS_TRUST_FAILURE}, {
654 ERRHRD, ERRgeneral, NT_STATUS_MUTANT_LIMIT_EXCEEDED}, {
655 ERRDOS, ERRnetlogonNotStarted, NT_STATUS_NETLOGON_NOT_STARTED}, {
Steve Frencha761ac52007-10-18 21:45:27 +0000656 ERRSRV, ERRaccountexpired, NT_STATUS_ACCOUNT_EXPIRED}, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 ERRHRD, ERRgeneral, NT_STATUS_POSSIBLE_DEADLOCK}, {
658 ERRHRD, ERRgeneral, NT_STATUS_NETWORK_CREDENTIAL_CONFLICT}, {
659 ERRHRD, ERRgeneral, NT_STATUS_REMOTE_SESSION_LIMIT}, {
660 ERRHRD, ERRgeneral, NT_STATUS_EVENTLOG_FILE_CHANGED}, {
661 ERRDOS, ERRnoaccess, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT}, {
662 ERRDOS, ERRnoaccess, NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT}, {
663 ERRDOS, ERRnoaccess, NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT},
664/* { This NT error code was 'sqashed'
Steve French38702532007-07-08 15:40:40 +0000665 from NT_STATUS_DOMAIN_TRUST_INCONSISTENT to NT_STATUS_LOGON_FAILURE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 during the session setup } */
667 {
668 ERRDOS, ERRnoaccess, NT_STATUS_DOMAIN_TRUST_INCONSISTENT}, {
669 ERRHRD, ERRgeneral, NT_STATUS_FS_DRIVER_REQUIRED}, {
670 ERRHRD, ERRgeneral, NT_STATUS_NO_USER_SESSION_KEY}, {
671 ERRDOS, 59, NT_STATUS_USER_SESSION_DELETED}, {
672 ERRHRD, ERRgeneral, NT_STATUS_RESOURCE_LANG_NOT_FOUND}, {
Jeff Layton4f2b86a2012-09-24 09:33:40 -0400673 ERRDOS, ERRnoresource, NT_STATUS_INSUFF_SERVER_RESOURCES}, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 ERRHRD, ERRgeneral, NT_STATUS_INVALID_BUFFER_SIZE}, {
675 ERRHRD, ERRgeneral, NT_STATUS_INVALID_ADDRESS_COMPONENT}, {
676 ERRHRD, ERRgeneral, NT_STATUS_INVALID_ADDRESS_WILDCARD}, {
677 ERRDOS, 68, NT_STATUS_TOO_MANY_ADDRESSES}, {
678 ERRDOS, 52, NT_STATUS_ADDRESS_ALREADY_EXISTS}, {
679 ERRDOS, 64, NT_STATUS_ADDRESS_CLOSED}, {
680 ERRDOS, 64, NT_STATUS_CONNECTION_DISCONNECTED}, {
681 ERRDOS, 64, NT_STATUS_CONNECTION_RESET}, {
682 ERRDOS, 68, NT_STATUS_TOO_MANY_NODES}, {
683 ERRDOS, 59, NT_STATUS_TRANSACTION_ABORTED}, {
684 ERRDOS, 59, NT_STATUS_TRANSACTION_TIMED_OUT}, {
685 ERRDOS, 59, NT_STATUS_TRANSACTION_NO_RELEASE}, {
686 ERRDOS, 59, NT_STATUS_TRANSACTION_NO_MATCH}, {
687 ERRDOS, 59, NT_STATUS_TRANSACTION_RESPONDED}, {
688 ERRDOS, 59, NT_STATUS_TRANSACTION_INVALID_ID}, {
689 ERRDOS, 59, NT_STATUS_TRANSACTION_INVALID_TYPE}, {
690 ERRDOS, ERRunsup, NT_STATUS_NOT_SERVER_SESSION}, {
691 ERRDOS, ERRunsup, NT_STATUS_NOT_CLIENT_SESSION}, {
692 ERRHRD, ERRgeneral, NT_STATUS_CANNOT_LOAD_REGISTRY_FILE}, {
693 ERRHRD, ERRgeneral, NT_STATUS_DEBUG_ATTACH_FAILED}, {
694 ERRHRD, ERRgeneral, NT_STATUS_SYSTEM_PROCESS_TERMINATED}, {
695 ERRHRD, ERRgeneral, NT_STATUS_DATA_NOT_ACCEPTED}, {
696 ERRHRD, ERRgeneral, NT_STATUS_NO_BROWSER_SERVERS_FOUND}, {
697 ERRHRD, ERRgeneral, NT_STATUS_VDM_HARD_ERROR}, {
698 ERRHRD, ERRgeneral, NT_STATUS_DRIVER_CANCEL_TIMEOUT}, {
699 ERRHRD, ERRgeneral, NT_STATUS_REPLY_MESSAGE_MISMATCH}, {
700 ERRHRD, ERRgeneral, NT_STATUS_MAPPED_ALIGNMENT}, {
701 ERRDOS, 193, NT_STATUS_IMAGE_CHECKSUM_MISMATCH}, {
702 ERRHRD, ERRgeneral, NT_STATUS_LOST_WRITEBEHIND_DATA}, {
703 ERRHRD, ERRgeneral, NT_STATUS_CLIENT_SERVER_PARAMETERS_INVALID}, {
Steve French6ab16d22005-11-29 20:55:11 -0800704 ERRSRV, ERRpasswordExpired, NT_STATUS_PASSWORD_MUST_CHANGE}, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 ERRHRD, ERRgeneral, NT_STATUS_NOT_FOUND}, {
706 ERRHRD, ERRgeneral, NT_STATUS_NOT_TINY_STREAM}, {
707 ERRHRD, ERRgeneral, NT_STATUS_RECOVERY_FAILURE}, {
708 ERRHRD, ERRgeneral, NT_STATUS_STACK_OVERFLOW_READ}, {
709 ERRHRD, ERRgeneral, NT_STATUS_FAIL_CHECK}, {
710 ERRHRD, ERRgeneral, NT_STATUS_DUPLICATE_OBJECTID}, {
711 ERRHRD, ERRgeneral, NT_STATUS_OBJECTID_EXISTS}, {
712 ERRHRD, ERRgeneral, NT_STATUS_CONVERT_TO_LARGE}, {
713 ERRHRD, ERRgeneral, NT_STATUS_RETRY}, {
714 ERRHRD, ERRgeneral, NT_STATUS_FOUND_OUT_OF_SCOPE}, {
715 ERRHRD, ERRgeneral, NT_STATUS_ALLOCATE_BUCKET}, {
716 ERRHRD, ERRgeneral, NT_STATUS_PROPSET_NOT_FOUND}, {
717 ERRHRD, ERRgeneral, NT_STATUS_MARSHALL_OVERFLOW}, {
718 ERRHRD, ERRgeneral, NT_STATUS_INVALID_VARIANT}, {
719 ERRHRD, ERRgeneral, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND}, {
720 ERRDOS, ERRnoaccess, NT_STATUS_ACCOUNT_LOCKED_OUT}, {
721 ERRDOS, ERRbadfid, NT_STATUS_HANDLE_NOT_CLOSABLE}, {
722 ERRHRD, ERRgeneral, NT_STATUS_CONNECTION_REFUSED}, {
723 ERRHRD, ERRgeneral, NT_STATUS_GRACEFUL_DISCONNECT}, {
724 ERRHRD, ERRgeneral, NT_STATUS_ADDRESS_ALREADY_ASSOCIATED}, {
725 ERRHRD, ERRgeneral, NT_STATUS_ADDRESS_NOT_ASSOCIATED}, {
726 ERRHRD, ERRgeneral, NT_STATUS_CONNECTION_INVALID}, {
727 ERRHRD, ERRgeneral, NT_STATUS_CONNECTION_ACTIVE}, {
728 ERRHRD, ERRgeneral, NT_STATUS_NETWORK_UNREACHABLE}, {
729 ERRHRD, ERRgeneral, NT_STATUS_HOST_UNREACHABLE}, {
730 ERRHRD, ERRgeneral, NT_STATUS_PROTOCOL_UNREACHABLE}, {
731 ERRHRD, ERRgeneral, NT_STATUS_PORT_UNREACHABLE}, {
732 ERRHRD, ERRgeneral, NT_STATUS_REQUEST_ABORTED}, {
733 ERRHRD, ERRgeneral, NT_STATUS_CONNECTION_ABORTED}, {
734 ERRHRD, ERRgeneral, NT_STATUS_BAD_COMPRESSION_BUFFER}, {
735 ERRHRD, ERRgeneral, NT_STATUS_USER_MAPPED_FILE}, {
736 ERRHRD, ERRgeneral, NT_STATUS_AUDIT_FAILED}, {
737 ERRHRD, ERRgeneral, NT_STATUS_TIMER_RESOLUTION_NOT_SET}, {
738 ERRHRD, ERRgeneral, NT_STATUS_CONNECTION_COUNT_LIMIT}, {
739 ERRHRD, ERRgeneral, NT_STATUS_LOGIN_TIME_RESTRICTION}, {
740 ERRHRD, ERRgeneral, NT_STATUS_LOGIN_WKSTA_RESTRICTION}, {
741 ERRDOS, 193, NT_STATUS_IMAGE_MP_UP_MISMATCH}, {
742 ERRHRD, ERRgeneral, 0xc000024a}, {
743 ERRHRD, ERRgeneral, 0xc000024b}, {
744 ERRHRD, ERRgeneral, 0xc000024c}, {
745 ERRHRD, ERRgeneral, 0xc000024d}, {
746 ERRHRD, ERRgeneral, 0xc000024e}, {
747 ERRHRD, ERRgeneral, 0xc000024f}, {
748 ERRHRD, ERRgeneral, NT_STATUS_INSUFFICIENT_LOGON_INFO}, {
749 ERRHRD, ERRgeneral, NT_STATUS_BAD_DLL_ENTRYPOINT}, {
750 ERRHRD, ERRgeneral, NT_STATUS_BAD_SERVICE_ENTRYPOINT}, {
751 ERRHRD, ERRgeneral, NT_STATUS_LPC_REPLY_LOST}, {
752 ERRHRD, ERRgeneral, NT_STATUS_IP_ADDRESS_CONFLICT1}, {
753 ERRHRD, ERRgeneral, NT_STATUS_IP_ADDRESS_CONFLICT2}, {
754 ERRHRD, ERRgeneral, NT_STATUS_REGISTRY_QUOTA_LIMIT}, {
755 ERRSRV, 3, NT_STATUS_PATH_NOT_COVERED}, {
756 ERRHRD, ERRgeneral, NT_STATUS_NO_CALLBACK_ACTIVE}, {
757 ERRHRD, ERRgeneral, NT_STATUS_LICENSE_QUOTA_EXCEEDED}, {
758 ERRHRD, ERRgeneral, NT_STATUS_PWD_TOO_SHORT}, {
759 ERRHRD, ERRgeneral, NT_STATUS_PWD_TOO_RECENT}, {
760 ERRHRD, ERRgeneral, NT_STATUS_PWD_HISTORY_CONFLICT}, {
761 ERRHRD, ERRgeneral, 0xc000025d}, {
762 ERRHRD, ERRgeneral, NT_STATUS_PLUGPLAY_NO_DEVICE}, {
763 ERRHRD, ERRgeneral, NT_STATUS_UNSUPPORTED_COMPRESSION}, {
764 ERRHRD, ERRgeneral, NT_STATUS_INVALID_HW_PROFILE}, {
765 ERRHRD, ERRgeneral, NT_STATUS_INVALID_PLUGPLAY_DEVICE_PATH}, {
766 ERRDOS, 182, NT_STATUS_DRIVER_ORDINAL_NOT_FOUND}, {
767 ERRDOS, 127, NT_STATUS_DRIVER_ENTRYPOINT_NOT_FOUND}, {
768 ERRDOS, 288, NT_STATUS_RESOURCE_NOT_OWNED}, {
Steve French11aa0142005-04-28 22:41:10 -0700769 ERRDOS, ErrTooManyLinks, NT_STATUS_TOO_MANY_LINKS}, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 ERRHRD, ERRgeneral, NT_STATUS_QUOTA_LIST_INCONSISTENT}, {
771 ERRHRD, ERRgeneral, NT_STATUS_FILE_IS_OFFLINE}, {
772 ERRDOS, 21, 0xc000026e}, {
773 ERRDOS, 161, 0xc0000281}, {
774 ERRDOS, ERRnoaccess, 0xc000028a}, {
775 ERRDOS, ERRnoaccess, 0xc000028b}, {
776 ERRHRD, ERRgeneral, 0xc000028c}, {
777 ERRDOS, ERRnoaccess, 0xc000028d}, {
778 ERRDOS, ERRnoaccess, 0xc000028e}, {
779 ERRDOS, ERRnoaccess, 0xc000028f}, {
780 ERRDOS, ERRnoaccess, 0xc0000290}, {
781 ERRDOS, ERRbadfunc, 0xc000029c}, {
Steve French9e39b0a2009-04-30 21:31:15 +0000782 ERRDOS, ERRsymlink, NT_STATUS_STOPPED_ON_SYMLINK}, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 ERRDOS, ERRinvlevel, 0x007c0001}, };
784
785/*****************************************************************************
786 Print an error message from the status code
787 *****************************************************************************/
788static void
789cifs_print_status(__u32 status_code)
790{
791 int idx = 0;
792
793 while (nt_errs[idx].nt_errstr != NULL) {
794 if (((nt_errs[idx].nt_errcode) & 0xFFFFFF) ==
795 (status_code & 0xFFFFFF)) {
796 printk(KERN_NOTICE "Status code returned 0x%08x %s\n",
Steve French38702532007-07-08 15:40:40 +0000797 status_code, nt_errs[idx].nt_errstr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 }
799 idx++;
800 }
801 return;
802}
803
804
805static void
Steve French63d25832007-11-05 21:46:10 +0000806ntstatus_to_dos(__u32 ntstatus, __u8 *eclass, __u16 *ecode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807{
808 int i;
809 if (ntstatus == 0) {
810 *eclass = 0;
811 *ecode = 0;
812 return;
813 }
814 for (i = 0; ntstatus_to_dos_map[i].ntstatus; i++) {
815 if (ntstatus == ntstatus_to_dos_map[i].ntstatus) {
816 *eclass = ntstatus_to_dos_map[i].dos_class;
817 *ecode = ntstatus_to_dos_map[i].dos_code;
818 return;
819 }
820 }
821 *eclass = ERRHRD;
822 *ecode = ERRgeneral;
823}
824
825int
Pavel Shilovsky5ffef7b2012-03-23 14:28:03 -0400826map_smb_to_linux_error(char *buf, bool logErr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827{
Pavel Shilovsky5ffef7b2012-03-23 14:28:03 -0400828 struct smb_hdr *smb = (struct smb_hdr *)buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 unsigned int i;
Steve French38702532007-07-08 15:40:40 +0000830 int rc = -EIO; /* if transport error smb error may not be set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 __u8 smberrclass;
832 __u16 smberrcode;
833
834 /* BB if NT Status codes - map NT BB */
835
836 /* old style smb error codes */
837 if (smb->Status.CifsError == 0)
838 return 0;
839
840 if (smb->Flags2 & SMBFLG2_ERR_STATUS) {
Steve French38702532007-07-08 15:40:40 +0000841 /* translate the newer STATUS codes to old style SMB errors
842 * and then to POSIX errors */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 __u32 err = le32_to_cpu(smb->Status.CifsError);
Steve Frencha761ac52007-10-18 21:45:27 +0000844 if (logErr && (err != (NT_STATUS_MORE_PROCESSING_REQUIRED)))
845 cifs_print_status(err);
846 else if (cifsFYI & CIFS_RC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 cifs_print_status(err);
848 ntstatus_to_dos(err, &smberrclass, &smberrcode);
849 } else {
850 smberrclass = smb->Status.DosError.ErrorClass;
851 smberrcode = le16_to_cpu(smb->Status.DosError.Error);
852 }
853
854 /* old style errors */
855
856 /* DOS class smb error codes - map DOS */
Steve Frenchad7a2922008-02-07 23:25:02 +0000857 if (smberrclass == ERRDOS) {
858 /* 1 byte field no need to byte reverse */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 for (i = 0;
860 i <
Steve French630f3f0c2007-10-25 21:17:17 +0000861 sizeof(mapping_table_ERRDOS) /
862 sizeof(struct smb_to_posix_error); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 if (mapping_table_ERRDOS[i].smb_err == 0)
864 break;
Steve French63135e02007-07-17 17:34:02 +0000865 else if (mapping_table_ERRDOS[i].smb_err ==
866 smberrcode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 rc = mapping_table_ERRDOS[i].posix_code;
868 break;
869 }
Steve French38702532007-07-08 15:40:40 +0000870 /* else try next error mapping one to see if match */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 }
Steve Frenchad7a2922008-02-07 23:25:02 +0000872 } else if (smberrclass == ERRSRV) {
873 /* server class of error codes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 for (i = 0;
875 i <
Steve French630f3f0c2007-10-25 21:17:17 +0000876 sizeof(mapping_table_ERRSRV) /
877 sizeof(struct smb_to_posix_error); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 if (mapping_table_ERRSRV[i].smb_err == 0)
879 break;
Steve French63135e02007-07-17 17:34:02 +0000880 else if (mapping_table_ERRSRV[i].smb_err ==
881 smberrcode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 rc = mapping_table_ERRSRV[i].posix_code;
883 break;
884 }
Steve French38702532007-07-08 15:40:40 +0000885 /* else try next error mapping to see if match */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 }
887 }
888 /* else ERRHRD class errors or junk - return EIO */
889
Jeff Layton56c24302011-01-11 07:24:25 -0500890 cFYI(1, "Mapping smb error code 0x%x to POSIX err %d",
891 le32_to_cpu(smb->Status.CifsError), rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
Steve French50c2f752007-07-13 00:33:32 +0000893 /* generic corrective action e.g. reconnect SMB session on
Steve French38702532007-07-08 15:40:40 +0000894 * ERRbaduid could be added */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
896 return rc;
897}
898
899/*
900 * calculate the size of the SMB message based on the fixed header
901 * portion, the number of word parameters and the data portion of the message
902 */
903unsigned int
Pavel Shilovsky92fc65a2012-09-18 16:20:32 -0700904smbCalcSize(void *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905{
Pavel Shilovsky92fc65a2012-09-18 16:20:32 -0700906 struct smb_hdr *ptr = (struct smb_hdr *)buf;
Steve French630f3f0c2007-10-25 21:17:17 +0000907 return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) +
Jeff Layton690c5222011-01-20 13:36:51 -0500908 2 /* size of the bcc field */ + get_bcc(ptr));
Steve French70ca7342005-09-22 16:32:06 -0700909}
910
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911/* The following are taken from fs/ntfs/util.c */
912
913#define NTFS_TIME_OFFSET ((u64)(369*365 + 89) * 24 * 3600 * 10000000)
914
Jeff Layton07119a42009-05-27 09:37:33 -0400915/*
916 * Convert the NT UTC (based 1601-01-01, in hundred nanosecond units)
917 * into Unix UTC (based 1970-01-01, in seconds).
918 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919struct timespec
Jeff Layton07119a42009-05-27 09:37:33 -0400920cifs_NTtimeToUnix(__le64 ntutc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921{
Steve French38702532007-07-08 15:40:40 +0000922 struct timespec ts;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 /* BB what about the timezone? BB */
924
925 /* Subtract the NTFS time offset, then convert to 1s intervals. */
926 u64 t;
927
Jeff Layton07119a42009-05-27 09:37:33 -0400928 t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 ts.tv_nsec = do_div(t, 10000000) * 100;
Steve French38702532007-07-08 15:40:40 +0000930 ts.tv_sec = t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 return ts;
932}
933
934/* Convert the Unix UTC into NT UTC. */
935u64
936cifs_UnixTimeToNT(struct timespec t)
937{
938 /* Convert to 100ns intervals and then add the NTFS time offset. */
939 return (u64) t.tv_sec * 10000000 + t.tv_nsec/100 + NTFS_TIME_OFFSET;
940}
Steve French1bd5bbc2006-09-28 03:35:57 +0000941
942static int total_days_of_prev_months[] =
943{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
944
Jeff Laytonc4a2c082009-05-27 09:37:33 -0400945struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, int offset)
Steve French1bd5bbc2006-09-28 03:35:57 +0000946{
Steve French1bd5bbc2006-09-28 03:35:57 +0000947 struct timespec ts;
Steve French268f3be2006-10-06 21:47:09 +0000948 int sec, min, days, month, year;
Jeff Laytonc4a2c082009-05-27 09:37:33 -0400949 u16 date = le16_to_cpu(le_date);
950 u16 time = le16_to_cpu(le_time);
Steve Frenchad7a2922008-02-07 23:25:02 +0000951 SMB_TIME *st = (SMB_TIME *)&time;
952 SMB_DATE *sd = (SMB_DATE *)&date;
Steve French1bd5bbc2006-09-28 03:35:57 +0000953
Joe Perchesb6b38f72010-04-21 03:50:45 +0000954 cFYI(1, "date %d time %d", date, time);
Steve French1bd5bbc2006-09-28 03:35:57 +0000955
Steve French268f3be2006-10-06 21:47:09 +0000956 sec = 2 * st->TwoSeconds;
957 min = st->Minutes;
Steve French790fe572007-07-07 19:25:05 +0000958 if ((sec > 59) || (min > 59))
Joe Perchesb6b38f72010-04-21 03:50:45 +0000959 cERROR(1, "illegal time min %d sec %d", min, sec);
Steve French1bd5bbc2006-09-28 03:35:57 +0000960 sec += (min * 60);
Steve French268f3be2006-10-06 21:47:09 +0000961 sec += 60 * 60 * st->Hours;
Steve French790fe572007-07-07 19:25:05 +0000962 if (st->Hours > 24)
Joe Perchesb6b38f72010-04-21 03:50:45 +0000963 cERROR(1, "illegal hours %d", st->Hours);
Steve French268f3be2006-10-06 21:47:09 +0000964 days = sd->Day;
965 month = sd->Month;
Steve Frenchd5d18502007-10-17 21:31:52 +0000966 if ((days > 31) || (month > 12)) {
Joe Perchesb6b38f72010-04-21 03:50:45 +0000967 cERROR(1, "illegal date, month %d day: %d", month, days);
Steve Frenchd5d18502007-10-17 21:31:52 +0000968 if (month > 12)
969 month = 12;
970 }
Steve French1bd5bbc2006-09-28 03:35:57 +0000971 month -= 1;
972 days += total_days_of_prev_months[month];
Steve French533f90a2006-10-12 00:02:32 +0000973 days += 3652; /* account for difference in days between 1980 and 1970 */
Steve French268f3be2006-10-06 21:47:09 +0000974 year = sd->Year;
Steve French1bd5bbc2006-09-28 03:35:57 +0000975 days += year * 365;
976 days += (year/4); /* leap year */
Steve French438dd922006-10-11 03:49:30 +0000977 /* generalized leap year calculation is more complex, ie no leap year
978 for years/100 except for years/400, but since the maximum number for DOS
979 year is 2**7, the last year is 1980+127, which means we need only
980 consider 2 special case years, ie the years 2000 and 2100, and only
Steve French38702532007-07-08 15:40:40 +0000981 adjust for the lack of leap year for the year 2100, as 2000 was a
Steve French438dd922006-10-11 03:49:30 +0000982 leap year (divisable by 400) */
Steve French790fe572007-07-07 19:25:05 +0000983 if (year >= 120) /* the year 2100 */
Steve French438dd922006-10-11 03:49:30 +0000984 days = days - 1; /* do not count leap year for the year 2100 */
985
Steve French1bd5bbc2006-09-28 03:35:57 +0000986 /* adjust for leap year where we are still before leap day */
Steve French790fe572007-07-07 19:25:05 +0000987 if (year != 120)
Steve French70903ca2006-10-11 18:49:24 +0000988 days -= ((year & 0x03) == 0) && (month < 2 ? 1 : 0);
Steve French790fe572007-07-07 19:25:05 +0000989 sec += 24 * 60 * 60 * days;
Steve French1bd5bbc2006-09-28 03:35:57 +0000990
Jeff Laytonc4a2c082009-05-27 09:37:33 -0400991 ts.tv_sec = sec + offset;
Steve French1bd5bbc2006-09-28 03:35:57 +0000992
Joe Perchesb6b38f72010-04-21 03:50:45 +0000993 /* cFYI(1, "sec after cnvrt dos to unix time %d",sec); */
Steve French268f3be2006-10-06 21:47:09 +0000994
Steve French1bd5bbc2006-09-28 03:35:57 +0000995 ts.tv_nsec = 0;
996 return ts;
Steve French38702532007-07-08 15:40:40 +0000997}