blob: f9a54da97d3453395d09e7f519ba69d69168c553 [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},
64 {ERRbadshare, -ETXTBSY},
65 {ERRlock, -EACCES},
66 {ERRunsup, -EINVAL},
Steve French38702532007-07-08 15:40:40 +000067 {ERRnosuchshare, -ENXIO},
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 {ERRfilexists, -EEXIST},
69 {ERRinvparm, -EINVAL},
70 {ERRdiskfull, -ENOSPC},
71 {ERRinvname, -ENOENT},
Steve French38702532007-07-08 15:40:40 +000072 {ERRinvlevel, -EOPNOTSUPP},
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 {ERRdirnotempty, -ENOTEMPTY},
74 {ERRnotlocked, -ENOLCK},
Jeremy Allison7ee1af72006-08-02 21:56:33 +000075 {ERRcancelviolation, -ENOLCK},
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 {ERRalreadyexists, -EEXIST},
77 {ERRmoredata, -EOVERFLOW},
Steve French38702532007-07-08 15:40:40 +000078 {ERReasnotsupported, -EOPNOTSUPP},
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 {ErrQuota, -EDQUOT},
80 {ErrNotALink, -ENOLINK},
Steve French38702532007-07-08 15:40:40 +000081 {ERRnetlogonNotStarted, -ENOPROTOOPT},
Steve French9e39b0a2009-04-30 21:31:15 +000082 {ERRsymlink, -EOPNOTSUPP},
Steve French38702532007-07-08 15:40:40 +000083 {ErrTooManyLinks, -EMLINK},
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 {0, 0}
85};
86
87static const struct smb_to_posix_error mapping_table_ERRSRV[] = {
88 {ERRerror, -EIO},
Steve French7c7b25b2006-06-01 19:20:10 +000089 {ERRbadpw, -EACCES}, /* was EPERM */
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 {ERRbadtype, -EREMOTE},
91 {ERRaccess, -EACCES},
92 {ERRinvtid, -ENXIO},
Steve French43411d62006-06-02 18:17:11 +000093 {ERRinvnetname, -ENXIO},
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 {ERRinvdevice, -ENXIO},
95 {ERRqfull, -ENOSPC},
96 {ERRqtoobig, -ENOSPC},
97 {ERRqeof, -EIO},
98 {ERRinvpfid, -EBADF},
99 {ERRsmbcmd, -EBADRQC},
100 {ERRsrverror, -EIO},
101 {ERRbadBID, -EIO},
102 {ERRfilespecs, -EINVAL},
103 {ERRbadLink, -EIO},
104 {ERRbadpermits, -EINVAL},
105 {ERRbadPID, -ESRCH},
106 {ERRsetattrmode, -EINVAL},
107 {ERRpaused, -EHOSTDOWN},
108 {ERRmsgoff, -EHOSTDOWN},
109 {ERRnoroom, -ENOSPC},
110 {ERRrmuns, -EUSERS},
111 {ERRtimeout, -ETIME},
112 {ERRnoresource, -ENOBUFS},
113 {ERRtoomanyuids, -EUSERS},
114 {ERRbaduid, -EACCES},
115 {ERRusempx, -EIO},
116 {ERRusestd, -EIO},
117 {ERR_NOTIFY_ENUM_DIR, -ENOBUFS},
Steve Frencha761ac52007-10-18 21:45:27 +0000118 {ERRnoSuchUser, -EACCES},
119/* {ERRaccountexpired, -EACCES},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 {ERRbadclient, -EACCES},
121 {ERRbadLogonTime, -EACCES},
Steve Frencha761ac52007-10-18 21:45:27 +0000122 {ERRpasswordExpired, -EACCES},*/
123 {ERRaccountexpired, -EKEYEXPIRED},
124 {ERRbadclient, -EACCES},
125 {ERRbadLogonTime, -EACCES},
126 {ERRpasswordExpired, -EKEYEXPIRED},
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 {ERRnosupport, -EINVAL},
129 {0, 0}
130};
131
132static const struct smb_to_posix_error mapping_table_ERRHRD[] = {
133 {0, 0}
134};
135
Jeff Layton1e68b2b2009-06-11 10:27:30 -0400136/*
137 * Convert a string containing text IPv4 or IPv6 address to binary form.
138 *
139 * Returns 0 on failure.
140 */
141static int
Igor Mammedov7c5e6282008-05-08 20:48:42 +0000142cifs_inet_pton(const int address_family, const char *cp, void *dst)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
Steve French5858ae42007-04-25 11:59:10 +0000144 int ret = 0;
145
146 /* calculate length by finding first slash or NULL */
Steve French582d21e2008-05-13 04:54:12 +0000147 if (address_family == AF_INET)
Steve French1fb64bf2007-11-01 02:12:10 +0000148 ret = in4_pton(cp, -1 /* len */, dst, '\\', NULL);
Steve French582d21e2008-05-13 04:54:12 +0000149 else if (address_family == AF_INET6)
Steve French5858ae42007-04-25 11:59:10 +0000150 ret = in6_pton(cp, -1 /* len */, dst , '\\', NULL);
Steve French582d21e2008-05-13 04:54:12 +0000151
Steve French90c81e02008-02-12 20:32:36 +0000152 cFYI(DBG2, ("address conversion returned %d for %s", ret, cp));
Steve French5858ae42007-04-25 11:59:10 +0000153 if (ret > 0)
154 ret = 1;
155 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156}
157
Jeff Layton1e68b2b2009-06-11 10:27:30 -0400158/*
159 * Try to convert a string to an IPv4 address and then attempt to convert
160 * it to an IPv6 address if that fails. Set the family field if either
161 * succeeds.
162 *
163 * Returns 0 on failure.
164 */
165int
166cifs_convert_address(char *src, void *dst)
167{
168 struct sockaddr_in *s4 = (struct sockaddr_in *) dst;
Steve French361ea1a2009-06-15 13:46:12 +0000169 struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) dst;
Jeff Layton1e68b2b2009-06-11 10:27:30 -0400170
171 if (cifs_inet_pton(AF_INET, src, &s4->sin_addr.s_addr)) {
172 s4->sin_family = AF_INET;
173 return 1;
174 } else if (cifs_inet_pton(AF_INET6, src, &s6->sin6_addr.s6_addr)) {
175 s6->sin6_family = AF_INET6;
176 return 1;
177 }
178
179 return 0;
180}
181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182/*****************************************************************************
183convert a NT status code to a dos class/code
184 *****************************************************************************/
185/* NT status -> dos error map */
186static const struct {
187 __u8 dos_class;
188 __u16 dos_code;
189 __u32 ntstatus;
190} ntstatus_to_dos_map[] = {
191 {
192 ERRDOS, ERRgeneral, NT_STATUS_UNSUCCESSFUL}, {
193 ERRDOS, ERRbadfunc, NT_STATUS_NOT_IMPLEMENTED}, {
Steve French75cf6bd2005-04-28 22:41:04 -0700194 ERRDOS, ERRinvlevel, NT_STATUS_INVALID_INFO_CLASS}, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 ERRDOS, 24, NT_STATUS_INFO_LENGTH_MISMATCH}, {
196 ERRHRD, ERRgeneral, NT_STATUS_ACCESS_VIOLATION}, {
197 ERRHRD, ERRgeneral, NT_STATUS_IN_PAGE_ERROR}, {
198 ERRHRD, ERRgeneral, NT_STATUS_PAGEFILE_QUOTA}, {
199 ERRDOS, ERRbadfid, NT_STATUS_INVALID_HANDLE}, {
200 ERRHRD, ERRgeneral, NT_STATUS_BAD_INITIAL_STACK}, {
201 ERRDOS, 193, NT_STATUS_BAD_INITIAL_PC}, {
202 ERRDOS, 87, NT_STATUS_INVALID_CID}, {
203 ERRHRD, ERRgeneral, NT_STATUS_TIMER_NOT_CANCELED}, {
204 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER}, {
205 ERRDOS, ERRbadfile, NT_STATUS_NO_SUCH_DEVICE}, {
206 ERRDOS, ERRbadfile, NT_STATUS_NO_SUCH_FILE}, {
207 ERRDOS, ERRbadfunc, NT_STATUS_INVALID_DEVICE_REQUEST}, {
208 ERRDOS, 38, NT_STATUS_END_OF_FILE}, {
209 ERRDOS, 34, NT_STATUS_WRONG_VOLUME}, {
210 ERRDOS, 21, NT_STATUS_NO_MEDIA_IN_DEVICE}, {
211 ERRHRD, ERRgeneral, NT_STATUS_UNRECOGNIZED_MEDIA}, {
212 ERRDOS, 27, NT_STATUS_NONEXISTENT_SECTOR},
213/* { This NT error code was 'sqashed'
Steve French38702532007-07-08 15:40:40 +0000214 from NT_STATUS_MORE_PROCESSING_REQUIRED to NT_STATUS_OK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 during the session setup } */
216 {
217 ERRDOS, ERRnomem, NT_STATUS_NO_MEMORY}, {
218 ERRDOS, 487, NT_STATUS_CONFLICTING_ADDRESSES}, {
219 ERRDOS, 487, NT_STATUS_NOT_MAPPED_VIEW}, {
220 ERRDOS, 87, NT_STATUS_UNABLE_TO_FREE_VM}, {
221 ERRDOS, 87, NT_STATUS_UNABLE_TO_DELETE_SECTION}, {
222 ERRDOS, 2142, NT_STATUS_INVALID_SYSTEM_SERVICE}, {
223 ERRHRD, ERRgeneral, NT_STATUS_ILLEGAL_INSTRUCTION}, {
224 ERRDOS, ERRnoaccess, NT_STATUS_INVALID_LOCK_SEQUENCE}, {
225 ERRDOS, ERRnoaccess, NT_STATUS_INVALID_VIEW_SIZE}, {
226 ERRDOS, 193, NT_STATUS_INVALID_FILE_FOR_SECTION}, {
227 ERRDOS, ERRnoaccess, NT_STATUS_ALREADY_COMMITTED},
228/* { This NT error code was 'sqashed'
Steve French38702532007-07-08 15:40:40 +0000229 from NT_STATUS_ACCESS_DENIED to NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 during the session setup } */
231 {
232 ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED}, {
233 ERRDOS, 111, NT_STATUS_BUFFER_TOO_SMALL}, {
234 ERRDOS, ERRbadfid, NT_STATUS_OBJECT_TYPE_MISMATCH}, {
235 ERRHRD, ERRgeneral, NT_STATUS_NONCONTINUABLE_EXCEPTION}, {
236 ERRHRD, ERRgeneral, NT_STATUS_INVALID_DISPOSITION}, {
237 ERRHRD, ERRgeneral, NT_STATUS_UNWIND}, {
238 ERRHRD, ERRgeneral, NT_STATUS_BAD_STACK}, {
239 ERRHRD, ERRgeneral, NT_STATUS_INVALID_UNWIND_TARGET}, {
240 ERRDOS, 158, NT_STATUS_NOT_LOCKED}, {
241 ERRHRD, ERRgeneral, NT_STATUS_PARITY_ERROR}, {
242 ERRDOS, 487, NT_STATUS_UNABLE_TO_DECOMMIT_VM}, {
243 ERRDOS, 487, NT_STATUS_NOT_COMMITTED}, {
244 ERRHRD, ERRgeneral, NT_STATUS_INVALID_PORT_ATTRIBUTES}, {
245 ERRHRD, ERRgeneral, NT_STATUS_PORT_MESSAGE_TOO_LONG}, {
246 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_MIX}, {
247 ERRHRD, ERRgeneral, NT_STATUS_INVALID_QUOTA_LOWER}, {
248 ERRHRD, ERRgeneral, NT_STATUS_DISK_CORRUPT_ERROR}, {
Steve Frenchad7a2922008-02-07 23:25:02 +0000249 /* mapping changed since shell does lookup on * expects FileNotFound */
250 ERRDOS, ERRbadfile, NT_STATUS_OBJECT_NAME_INVALID}, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 ERRDOS, ERRbadfile, NT_STATUS_OBJECT_NAME_NOT_FOUND}, {
252 ERRDOS, ERRalreadyexists, NT_STATUS_OBJECT_NAME_COLLISION}, {
253 ERRHRD, ERRgeneral, NT_STATUS_HANDLE_NOT_WAITABLE}, {
254 ERRDOS, ERRbadfid, NT_STATUS_PORT_DISCONNECTED}, {
255 ERRHRD, ERRgeneral, NT_STATUS_DEVICE_ALREADY_ATTACHED}, {
256 ERRDOS, 161, NT_STATUS_OBJECT_PATH_INVALID}, {
257 ERRDOS, ERRbadpath, NT_STATUS_OBJECT_PATH_NOT_FOUND}, {
258 ERRDOS, 161, NT_STATUS_OBJECT_PATH_SYNTAX_BAD}, {
259 ERRHRD, ERRgeneral, NT_STATUS_DATA_OVERRUN}, {
260 ERRHRD, ERRgeneral, NT_STATUS_DATA_LATE_ERROR}, {
261 ERRDOS, 23, NT_STATUS_DATA_ERROR}, {
262 ERRDOS, 23, NT_STATUS_CRC_ERROR}, {
263 ERRDOS, ERRnomem, NT_STATUS_SECTION_TOO_BIG}, {
264 ERRDOS, ERRnoaccess, NT_STATUS_PORT_CONNECTION_REFUSED}, {
265 ERRDOS, ERRbadfid, NT_STATUS_INVALID_PORT_HANDLE}, {
266 ERRDOS, ERRbadshare, NT_STATUS_SHARING_VIOLATION}, {
267 ERRHRD, ERRgeneral, NT_STATUS_QUOTA_EXCEEDED}, {
268 ERRDOS, 87, NT_STATUS_INVALID_PAGE_PROTECTION}, {
269 ERRDOS, 288, NT_STATUS_MUTANT_NOT_OWNED}, {
270 ERRDOS, 298, NT_STATUS_SEMAPHORE_LIMIT_EXCEEDED}, {
271 ERRDOS, 87, NT_STATUS_PORT_ALREADY_SET}, {
272 ERRDOS, 87, NT_STATUS_SECTION_NOT_IMAGE}, {
273 ERRDOS, 156, NT_STATUS_SUSPEND_COUNT_EXCEEDED}, {
274 ERRDOS, ERRnoaccess, NT_STATUS_THREAD_IS_TERMINATING}, {
275 ERRDOS, 87, NT_STATUS_BAD_WORKING_SET_LIMIT}, {
276 ERRDOS, 87, NT_STATUS_INCOMPATIBLE_FILE_MAP}, {
277 ERRDOS, 87, NT_STATUS_SECTION_PROTECTION}, {
278 ERRDOS, ERReasnotsupported, NT_STATUS_EAS_NOT_SUPPORTED}, {
279 ERRDOS, 255, NT_STATUS_EA_TOO_LARGE}, {
280 ERRHRD, ERRgeneral, NT_STATUS_NONEXISTENT_EA_ENTRY}, {
281 ERRHRD, ERRgeneral, NT_STATUS_NO_EAS_ON_FILE}, {
282 ERRHRD, ERRgeneral, NT_STATUS_EA_CORRUPT_ERROR}, {
283 ERRDOS, ERRlock, NT_STATUS_FILE_LOCK_CONFLICT}, {
284 ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED}, {
285 ERRDOS, ERRbadfile, NT_STATUS_DELETE_PENDING}, {
286 ERRDOS, ERRunsup, NT_STATUS_CTL_FILE_NOT_SUPPORTED}, {
287 ERRHRD, ERRgeneral, NT_STATUS_UNKNOWN_REVISION}, {
288 ERRHRD, ERRgeneral, NT_STATUS_REVISION_MISMATCH}, {
289 ERRHRD, ERRgeneral, NT_STATUS_INVALID_OWNER}, {
290 ERRHRD, ERRgeneral, NT_STATUS_INVALID_PRIMARY_GROUP}, {
291 ERRHRD, ERRgeneral, NT_STATUS_NO_IMPERSONATION_TOKEN}, {
292 ERRHRD, ERRgeneral, NT_STATUS_CANT_DISABLE_MANDATORY}, {
293 ERRDOS, 2215, NT_STATUS_NO_LOGON_SERVERS}, {
294 ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_LOGON_SESSION}, {
295 ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_PRIVILEGE}, {
296 ERRDOS, ERRnoaccess, NT_STATUS_PRIVILEGE_NOT_HELD}, {
297 ERRHRD, ERRgeneral, NT_STATUS_INVALID_ACCOUNT_NAME}, {
298 ERRHRD, ERRgeneral, NT_STATUS_USER_EXISTS},
299/* { This NT error code was 'sqashed'
Steve French38702532007-07-08 15:40:40 +0000300 from NT_STATUS_NO_SUCH_USER to NT_STATUS_LOGON_FAILURE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 during the session setup } */
302 {
Steve Frencha761ac52007-10-18 21:45:27 +0000303 ERRDOS, ERRnoaccess, NT_STATUS_NO_SUCH_USER}, { /* could map to 2238 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 ERRHRD, ERRgeneral, NT_STATUS_GROUP_EXISTS}, {
305 ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_GROUP}, {
306 ERRHRD, ERRgeneral, NT_STATUS_MEMBER_IN_GROUP}, {
307 ERRHRD, ERRgeneral, NT_STATUS_MEMBER_NOT_IN_GROUP}, {
308 ERRHRD, ERRgeneral, NT_STATUS_LAST_ADMIN},
309/* { This NT error code was 'sqashed'
Steve French38702532007-07-08 15:40:40 +0000310 from NT_STATUS_WRONG_PASSWORD to NT_STATUS_LOGON_FAILURE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 during the session setup } */
312 {
313 ERRSRV, ERRbadpw, NT_STATUS_WRONG_PASSWORD}, {
314 ERRHRD, ERRgeneral, NT_STATUS_ILL_FORMED_PASSWORD}, {
315 ERRHRD, ERRgeneral, NT_STATUS_PASSWORD_RESTRICTION}, {
316 ERRDOS, ERRnoaccess, NT_STATUS_LOGON_FAILURE}, {
317 ERRHRD, ERRgeneral, NT_STATUS_ACCOUNT_RESTRICTION}, {
Steve Frencha761ac52007-10-18 21:45:27 +0000318 ERRSRV, ERRbadLogonTime, NT_STATUS_INVALID_LOGON_HOURS}, {
319 ERRSRV, ERRbadclient, NT_STATUS_INVALID_WORKSTATION}, {
Steve French6ab16d22005-11-29 20:55:11 -0800320 ERRSRV, ERRpasswordExpired, NT_STATUS_PASSWORD_EXPIRED}, {
Steve Frencha761ac52007-10-18 21:45:27 +0000321 ERRSRV, ERRaccountexpired, NT_STATUS_ACCOUNT_DISABLED}, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 ERRHRD, ERRgeneral, NT_STATUS_NONE_MAPPED}, {
323 ERRHRD, ERRgeneral, NT_STATUS_TOO_MANY_LUIDS_REQUESTED}, {
324 ERRHRD, ERRgeneral, NT_STATUS_LUIDS_EXHAUSTED}, {
325 ERRHRD, ERRgeneral, NT_STATUS_INVALID_SUB_AUTHORITY}, {
326 ERRHRD, ERRgeneral, NT_STATUS_INVALID_ACL}, {
327 ERRHRD, ERRgeneral, NT_STATUS_INVALID_SID}, {
328 ERRHRD, ERRgeneral, NT_STATUS_INVALID_SECURITY_DESCR}, {
329 ERRDOS, 127, NT_STATUS_PROCEDURE_NOT_FOUND}, {
330 ERRDOS, 193, NT_STATUS_INVALID_IMAGE_FORMAT}, {
331 ERRHRD, ERRgeneral, NT_STATUS_NO_TOKEN}, {
332 ERRHRD, ERRgeneral, NT_STATUS_BAD_INHERITANCE_ACL}, {
333 ERRDOS, 158, NT_STATUS_RANGE_NOT_LOCKED}, {
334 ERRDOS, 112, NT_STATUS_DISK_FULL}, {
335 ERRHRD, ERRgeneral, NT_STATUS_SERVER_DISABLED}, {
336 ERRHRD, ERRgeneral, NT_STATUS_SERVER_NOT_DISABLED}, {
337 ERRDOS, 68, NT_STATUS_TOO_MANY_GUIDS_REQUESTED}, {
338 ERRDOS, 259, NT_STATUS_GUIDS_EXHAUSTED}, {
339 ERRHRD, ERRgeneral, NT_STATUS_INVALID_ID_AUTHORITY}, {
340 ERRDOS, 259, NT_STATUS_AGENTS_EXHAUSTED}, {
341 ERRDOS, 154, NT_STATUS_INVALID_VOLUME_LABEL}, {
342 ERRDOS, 14, NT_STATUS_SECTION_NOT_EXTENDED}, {
343 ERRDOS, 487, NT_STATUS_NOT_MAPPED_DATA}, {
344 ERRHRD, ERRgeneral, NT_STATUS_RESOURCE_DATA_NOT_FOUND}, {
345 ERRHRD, ERRgeneral, NT_STATUS_RESOURCE_TYPE_NOT_FOUND}, {
346 ERRHRD, ERRgeneral, NT_STATUS_RESOURCE_NAME_NOT_FOUND}, {
347 ERRHRD, ERRgeneral, NT_STATUS_ARRAY_BOUNDS_EXCEEDED}, {
348 ERRHRD, ERRgeneral, NT_STATUS_FLOAT_DENORMAL_OPERAND}, {
349 ERRHRD, ERRgeneral, NT_STATUS_FLOAT_DIVIDE_BY_ZERO}, {
350 ERRHRD, ERRgeneral, NT_STATUS_FLOAT_INEXACT_RESULT}, {
351 ERRHRD, ERRgeneral, NT_STATUS_FLOAT_INVALID_OPERATION}, {
352 ERRHRD, ERRgeneral, NT_STATUS_FLOAT_OVERFLOW}, {
353 ERRHRD, ERRgeneral, NT_STATUS_FLOAT_STACK_CHECK}, {
354 ERRHRD, ERRgeneral, NT_STATUS_FLOAT_UNDERFLOW}, {
355 ERRHRD, ERRgeneral, NT_STATUS_INTEGER_DIVIDE_BY_ZERO}, {
356 ERRDOS, 534, NT_STATUS_INTEGER_OVERFLOW}, {
357 ERRHRD, ERRgeneral, NT_STATUS_PRIVILEGED_INSTRUCTION}, {
358 ERRDOS, ERRnomem, NT_STATUS_TOO_MANY_PAGING_FILES}, {
359 ERRHRD, ERRgeneral, NT_STATUS_FILE_INVALID}, {
360 ERRHRD, ERRgeneral, NT_STATUS_ALLOTTED_SPACE_EXCEEDED},
361/* { This NT error code was 'sqashed'
Steve French38702532007-07-08 15:40:40 +0000362 from NT_STATUS_INSUFFICIENT_RESOURCES to
363 NT_STATUS_INSUFF_SERVER_RESOURCES during the session setup } */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 {
365 ERRDOS, ERRnomem, NT_STATUS_INSUFFICIENT_RESOURCES}, {
366 ERRDOS, ERRbadpath, NT_STATUS_DFS_EXIT_PATH_FOUND}, {
367 ERRDOS, 23, NT_STATUS_DEVICE_DATA_ERROR}, {
368 ERRHRD, ERRgeneral, NT_STATUS_DEVICE_NOT_CONNECTED}, {
369 ERRDOS, 21, NT_STATUS_DEVICE_POWER_FAILURE}, {
370 ERRDOS, 487, NT_STATUS_FREE_VM_NOT_AT_BASE}, {
371 ERRDOS, 487, NT_STATUS_MEMORY_NOT_ALLOCATED}, {
372 ERRHRD, ERRgeneral, NT_STATUS_WORKING_SET_QUOTA}, {
373 ERRDOS, 19, NT_STATUS_MEDIA_WRITE_PROTECTED}, {
374 ERRDOS, 21, NT_STATUS_DEVICE_NOT_READY}, {
375 ERRHRD, ERRgeneral, NT_STATUS_INVALID_GROUP_ATTRIBUTES}, {
376 ERRHRD, ERRgeneral, NT_STATUS_BAD_IMPERSONATION_LEVEL}, {
377 ERRHRD, ERRgeneral, NT_STATUS_CANT_OPEN_ANONYMOUS}, {
378 ERRHRD, ERRgeneral, NT_STATUS_BAD_VALIDATION_CLASS}, {
379 ERRHRD, ERRgeneral, NT_STATUS_BAD_TOKEN_TYPE}, {
380 ERRDOS, 87, NT_STATUS_BAD_MASTER_BOOT_RECORD}, {
381 ERRHRD, ERRgeneral, NT_STATUS_INSTRUCTION_MISALIGNMENT}, {
382 ERRDOS, ERRpipebusy, NT_STATUS_INSTANCE_NOT_AVAILABLE}, {
383 ERRDOS, ERRpipebusy, NT_STATUS_PIPE_NOT_AVAILABLE}, {
384 ERRDOS, ERRbadpipe, NT_STATUS_INVALID_PIPE_STATE}, {
385 ERRDOS, ERRpipebusy, NT_STATUS_PIPE_BUSY}, {
386 ERRDOS, ERRbadfunc, NT_STATUS_ILLEGAL_FUNCTION}, {
387 ERRDOS, ERRnotconnected, NT_STATUS_PIPE_DISCONNECTED}, {
388 ERRDOS, ERRpipeclosing, NT_STATUS_PIPE_CLOSING}, {
389 ERRHRD, ERRgeneral, NT_STATUS_PIPE_CONNECTED}, {
390 ERRHRD, ERRgeneral, NT_STATUS_PIPE_LISTENING}, {
391 ERRDOS, ERRbadpipe, NT_STATUS_INVALID_READ_MODE}, {
392 ERRDOS, 121, NT_STATUS_IO_TIMEOUT}, {
393 ERRDOS, 38, NT_STATUS_FILE_FORCED_CLOSED}, {
394 ERRHRD, ERRgeneral, NT_STATUS_PROFILING_NOT_STARTED}, {
395 ERRHRD, ERRgeneral, NT_STATUS_PROFILING_NOT_STOPPED}, {
396 ERRHRD, ERRgeneral, NT_STATUS_COULD_NOT_INTERPRET}, {
397 ERRDOS, ERRnoaccess, NT_STATUS_FILE_IS_A_DIRECTORY}, {
398 ERRDOS, ERRunsup, NT_STATUS_NOT_SUPPORTED}, {
399 ERRDOS, 51, NT_STATUS_REMOTE_NOT_LISTENING}, {
400 ERRDOS, 52, NT_STATUS_DUPLICATE_NAME}, {
401 ERRDOS, 53, NT_STATUS_BAD_NETWORK_PATH}, {
402 ERRDOS, 54, NT_STATUS_NETWORK_BUSY}, {
403 ERRDOS, 55, NT_STATUS_DEVICE_DOES_NOT_EXIST}, {
404 ERRDOS, 56, NT_STATUS_TOO_MANY_COMMANDS}, {
405 ERRDOS, 57, NT_STATUS_ADAPTER_HARDWARE_ERROR}, {
406 ERRDOS, 58, NT_STATUS_INVALID_NETWORK_RESPONSE}, {
407 ERRDOS, 59, NT_STATUS_UNEXPECTED_NETWORK_ERROR}, {
408 ERRDOS, 60, NT_STATUS_BAD_REMOTE_ADAPTER}, {
409 ERRDOS, 61, NT_STATUS_PRINT_QUEUE_FULL}, {
410 ERRDOS, 62, NT_STATUS_NO_SPOOL_SPACE}, {
411 ERRDOS, 63, NT_STATUS_PRINT_CANCELLED}, {
412 ERRDOS, 64, NT_STATUS_NETWORK_NAME_DELETED}, {
413 ERRDOS, 65, NT_STATUS_NETWORK_ACCESS_DENIED}, {
414 ERRDOS, 66, NT_STATUS_BAD_DEVICE_TYPE}, {
415 ERRDOS, ERRnosuchshare, NT_STATUS_BAD_NETWORK_NAME}, {
416 ERRDOS, 68, NT_STATUS_TOO_MANY_NAMES}, {
417 ERRDOS, 69, NT_STATUS_TOO_MANY_SESSIONS}, {
418 ERRDOS, 70, NT_STATUS_SHARING_PAUSED}, {
419 ERRDOS, 71, NT_STATUS_REQUEST_NOT_ACCEPTED}, {
420 ERRDOS, 72, NT_STATUS_REDIRECTOR_PAUSED}, {
421 ERRDOS, 88, NT_STATUS_NET_WRITE_FAULT}, {
422 ERRHRD, ERRgeneral, NT_STATUS_PROFILING_AT_LIMIT}, {
423 ERRDOS, ERRdiffdevice, NT_STATUS_NOT_SAME_DEVICE}, {
424 ERRDOS, ERRnoaccess, NT_STATUS_FILE_RENAMED}, {
425 ERRDOS, 240, NT_STATUS_VIRTUAL_CIRCUIT_CLOSED}, {
426 ERRHRD, ERRgeneral, NT_STATUS_NO_SECURITY_ON_OBJECT}, {
427 ERRHRD, ERRgeneral, NT_STATUS_CANT_WAIT}, {
428 ERRDOS, ERRpipeclosing, NT_STATUS_PIPE_EMPTY}, {
429 ERRHRD, ERRgeneral, NT_STATUS_CANT_ACCESS_DOMAIN_INFO}, {
430 ERRHRD, ERRgeneral, NT_STATUS_CANT_TERMINATE_SELF}, {
431 ERRHRD, ERRgeneral, NT_STATUS_INVALID_SERVER_STATE}, {
432 ERRHRD, ERRgeneral, NT_STATUS_INVALID_DOMAIN_STATE}, {
433 ERRHRD, ERRgeneral, NT_STATUS_INVALID_DOMAIN_ROLE}, {
434 ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_DOMAIN}, {
435 ERRHRD, ERRgeneral, NT_STATUS_DOMAIN_EXISTS}, {
436 ERRHRD, ERRgeneral, NT_STATUS_DOMAIN_LIMIT_EXCEEDED}, {
437 ERRDOS, 300, NT_STATUS_OPLOCK_NOT_GRANTED}, {
438 ERRDOS, 301, NT_STATUS_INVALID_OPLOCK_PROTOCOL}, {
439 ERRHRD, ERRgeneral, NT_STATUS_INTERNAL_DB_CORRUPTION}, {
440 ERRHRD, ERRgeneral, NT_STATUS_INTERNAL_ERROR}, {
441 ERRHRD, ERRgeneral, NT_STATUS_GENERIC_NOT_MAPPED}, {
442 ERRHRD, ERRgeneral, NT_STATUS_BAD_DESCRIPTOR_FORMAT}, {
443 ERRHRD, ERRgeneral, NT_STATUS_INVALID_USER_BUFFER}, {
444 ERRHRD, ERRgeneral, NT_STATUS_UNEXPECTED_IO_ERROR}, {
445 ERRHRD, ERRgeneral, NT_STATUS_UNEXPECTED_MM_CREATE_ERR}, {
446 ERRHRD, ERRgeneral, NT_STATUS_UNEXPECTED_MM_MAP_ERROR}, {
447 ERRHRD, ERRgeneral, NT_STATUS_UNEXPECTED_MM_EXTEND_ERR}, {
448 ERRHRD, ERRgeneral, NT_STATUS_NOT_LOGON_PROCESS}, {
449 ERRHRD, ERRgeneral, NT_STATUS_LOGON_SESSION_EXISTS}, {
450 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_1}, {
451 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_2}, {
452 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_3}, {
453 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_4}, {
454 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_5}, {
455 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_6}, {
456 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_7}, {
457 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_8}, {
458 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_9}, {
459 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_10}, {
460 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_11}, {
461 ERRDOS, 87, NT_STATUS_INVALID_PARAMETER_12}, {
462 ERRDOS, ERRbadpath, NT_STATUS_REDIRECTOR_NOT_STARTED}, {
463 ERRHRD, ERRgeneral, NT_STATUS_REDIRECTOR_STARTED}, {
464 ERRHRD, ERRgeneral, NT_STATUS_STACK_OVERFLOW}, {
465 ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_PACKAGE}, {
466 ERRHRD, ERRgeneral, NT_STATUS_BAD_FUNCTION_TABLE}, {
467 ERRDOS, 203, 0xc0000100}, {
468 ERRDOS, 145, NT_STATUS_DIRECTORY_NOT_EMPTY}, {
469 ERRHRD, ERRgeneral, NT_STATUS_FILE_CORRUPT_ERROR}, {
470 ERRDOS, 267, NT_STATUS_NOT_A_DIRECTORY}, {
471 ERRHRD, ERRgeneral, NT_STATUS_BAD_LOGON_SESSION_STATE}, {
472 ERRHRD, ERRgeneral, NT_STATUS_LOGON_SESSION_COLLISION}, {
473 ERRDOS, 206, NT_STATUS_NAME_TOO_LONG}, {
474 ERRDOS, 2401, NT_STATUS_FILES_OPEN}, {
475 ERRDOS, 2404, NT_STATUS_CONNECTION_IN_USE}, {
476 ERRHRD, ERRgeneral, NT_STATUS_MESSAGE_NOT_FOUND}, {
477 ERRDOS, ERRnoaccess, NT_STATUS_PROCESS_IS_TERMINATING}, {
478 ERRHRD, ERRgeneral, NT_STATUS_INVALID_LOGON_TYPE}, {
479 ERRHRD, ERRgeneral, NT_STATUS_NO_GUID_TRANSLATION}, {
480 ERRHRD, ERRgeneral, NT_STATUS_CANNOT_IMPERSONATE}, {
481 ERRHRD, ERRgeneral, NT_STATUS_IMAGE_ALREADY_LOADED}, {
482 ERRHRD, ERRgeneral, NT_STATUS_ABIOS_NOT_PRESENT}, {
483 ERRHRD, ERRgeneral, NT_STATUS_ABIOS_LID_NOT_EXIST}, {
484 ERRHRD, ERRgeneral, NT_STATUS_ABIOS_LID_ALREADY_OWNED}, {
485 ERRHRD, ERRgeneral, NT_STATUS_ABIOS_NOT_LID_OWNER}, {
486 ERRHRD, ERRgeneral, NT_STATUS_ABIOS_INVALID_COMMAND}, {
487 ERRHRD, ERRgeneral, NT_STATUS_ABIOS_INVALID_LID}, {
488 ERRHRD, ERRgeneral, NT_STATUS_ABIOS_SELECTOR_NOT_AVAILABLE}, {
489 ERRHRD, ERRgeneral, NT_STATUS_ABIOS_INVALID_SELECTOR}, {
490 ERRHRD, ERRgeneral, NT_STATUS_NO_LDT}, {
491 ERRHRD, ERRgeneral, NT_STATUS_INVALID_LDT_SIZE}, {
492 ERRHRD, ERRgeneral, NT_STATUS_INVALID_LDT_OFFSET}, {
493 ERRHRD, ERRgeneral, NT_STATUS_INVALID_LDT_DESCRIPTOR}, {
494 ERRDOS, 193, NT_STATUS_INVALID_IMAGE_NE_FORMAT}, {
495 ERRHRD, ERRgeneral, NT_STATUS_RXACT_INVALID_STATE}, {
496 ERRHRD, ERRgeneral, NT_STATUS_RXACT_COMMIT_FAILURE}, {
497 ERRHRD, ERRgeneral, NT_STATUS_MAPPED_FILE_SIZE_ZERO}, {
498 ERRDOS, ERRnofids, NT_STATUS_TOO_MANY_OPENED_FILES}, {
499 ERRHRD, ERRgeneral, NT_STATUS_CANCELLED}, {
500 ERRDOS, ERRnoaccess, NT_STATUS_CANNOT_DELETE}, {
501 ERRHRD, ERRgeneral, NT_STATUS_INVALID_COMPUTER_NAME}, {
502 ERRDOS, ERRnoaccess, NT_STATUS_FILE_DELETED}, {
503 ERRHRD, ERRgeneral, NT_STATUS_SPECIAL_ACCOUNT}, {
504 ERRHRD, ERRgeneral, NT_STATUS_SPECIAL_GROUP}, {
505 ERRHRD, ERRgeneral, NT_STATUS_SPECIAL_USER}, {
506 ERRHRD, ERRgeneral, NT_STATUS_MEMBERS_PRIMARY_GROUP}, {
507 ERRDOS, ERRbadfid, NT_STATUS_FILE_CLOSED}, {
508 ERRHRD, ERRgeneral, NT_STATUS_TOO_MANY_THREADS}, {
509 ERRHRD, ERRgeneral, NT_STATUS_THREAD_NOT_IN_PROCESS}, {
510 ERRHRD, ERRgeneral, NT_STATUS_TOKEN_ALREADY_IN_USE}, {
511 ERRHRD, ERRgeneral, NT_STATUS_PAGEFILE_QUOTA_EXCEEDED}, {
512 ERRHRD, ERRgeneral, NT_STATUS_COMMITMENT_LIMIT}, {
513 ERRDOS, 193, NT_STATUS_INVALID_IMAGE_LE_FORMAT}, {
514 ERRDOS, 193, NT_STATUS_INVALID_IMAGE_NOT_MZ}, {
515 ERRDOS, 193, NT_STATUS_INVALID_IMAGE_PROTECT}, {
516 ERRDOS, 193, NT_STATUS_INVALID_IMAGE_WIN_16}, {
517 ERRHRD, ERRgeneral, NT_STATUS_LOGON_SERVER_CONFLICT}, {
518 ERRHRD, ERRgeneral, NT_STATUS_TIME_DIFFERENCE_AT_DC}, {
519 ERRHRD, ERRgeneral, NT_STATUS_SYNCHRONIZATION_REQUIRED}, {
520 ERRDOS, 126, NT_STATUS_DLL_NOT_FOUND}, {
521 ERRHRD, ERRgeneral, NT_STATUS_OPEN_FAILED}, {
522 ERRHRD, ERRgeneral, NT_STATUS_IO_PRIVILEGE_FAILED}, {
523 ERRDOS, 182, NT_STATUS_ORDINAL_NOT_FOUND}, {
524 ERRDOS, 127, NT_STATUS_ENTRYPOINT_NOT_FOUND}, {
525 ERRHRD, ERRgeneral, NT_STATUS_CONTROL_C_EXIT}, {
526 ERRDOS, 64, NT_STATUS_LOCAL_DISCONNECT}, {
527 ERRDOS, 64, NT_STATUS_REMOTE_DISCONNECT}, {
528 ERRDOS, 51, NT_STATUS_REMOTE_RESOURCES}, {
529 ERRDOS, 59, NT_STATUS_LINK_FAILED}, {
530 ERRDOS, 59, NT_STATUS_LINK_TIMEOUT}, {
531 ERRDOS, 59, NT_STATUS_INVALID_CONNECTION}, {
532 ERRDOS, 59, NT_STATUS_INVALID_ADDRESS}, {
533 ERRHRD, ERRgeneral, NT_STATUS_DLL_INIT_FAILED}, {
534 ERRHRD, ERRgeneral, NT_STATUS_MISSING_SYSTEMFILE}, {
535 ERRHRD, ERRgeneral, NT_STATUS_UNHANDLED_EXCEPTION}, {
536 ERRHRD, ERRgeneral, NT_STATUS_APP_INIT_FAILURE}, {
537 ERRHRD, ERRgeneral, NT_STATUS_PAGEFILE_CREATE_FAILED}, {
538 ERRHRD, ERRgeneral, NT_STATUS_NO_PAGEFILE}, {
539 ERRDOS, 124, NT_STATUS_INVALID_LEVEL}, {
540 ERRDOS, 86, NT_STATUS_WRONG_PASSWORD_CORE}, {
541 ERRHRD, ERRgeneral, NT_STATUS_ILLEGAL_FLOAT_CONTEXT}, {
542 ERRDOS, 109, NT_STATUS_PIPE_BROKEN}, {
543 ERRHRD, ERRgeneral, NT_STATUS_REGISTRY_CORRUPT}, {
544 ERRHRD, ERRgeneral, NT_STATUS_REGISTRY_IO_FAILED}, {
545 ERRHRD, ERRgeneral, NT_STATUS_NO_EVENT_PAIR}, {
546 ERRHRD, ERRgeneral, NT_STATUS_UNRECOGNIZED_VOLUME}, {
547 ERRHRD, ERRgeneral, NT_STATUS_SERIAL_NO_DEVICE_INITED}, {
548 ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_ALIAS}, {
549 ERRHRD, ERRgeneral, NT_STATUS_MEMBER_NOT_IN_ALIAS}, {
550 ERRHRD, ERRgeneral, NT_STATUS_MEMBER_IN_ALIAS}, {
551 ERRHRD, ERRgeneral, NT_STATUS_ALIAS_EXISTS}, {
552 ERRHRD, ERRgeneral, NT_STATUS_LOGON_NOT_GRANTED}, {
553 ERRHRD, ERRgeneral, NT_STATUS_TOO_MANY_SECRETS}, {
554 ERRHRD, ERRgeneral, NT_STATUS_SECRET_TOO_LONG}, {
555 ERRHRD, ERRgeneral, NT_STATUS_INTERNAL_DB_ERROR}, {
556 ERRHRD, ERRgeneral, NT_STATUS_FULLSCREEN_MODE}, {
557 ERRHRD, ERRgeneral, NT_STATUS_TOO_MANY_CONTEXT_IDS}, {
558 ERRDOS, ERRnoaccess, NT_STATUS_LOGON_TYPE_NOT_GRANTED}, {
559 ERRHRD, ERRgeneral, NT_STATUS_NOT_REGISTRY_FILE}, {
560 ERRHRD, ERRgeneral, NT_STATUS_NT_CROSS_ENCRYPTION_REQUIRED}, {
561 ERRHRD, ERRgeneral, NT_STATUS_DOMAIN_CTRLR_CONFIG_ERROR}, {
562 ERRHRD, ERRgeneral, NT_STATUS_FT_MISSING_MEMBER}, {
563 ERRHRD, ERRgeneral, NT_STATUS_ILL_FORMED_SERVICE_ENTRY}, {
564 ERRHRD, ERRgeneral, NT_STATUS_ILLEGAL_CHARACTER}, {
565 ERRHRD, ERRgeneral, NT_STATUS_UNMAPPABLE_CHARACTER}, {
566 ERRHRD, ERRgeneral, NT_STATUS_UNDEFINED_CHARACTER}, {
567 ERRHRD, ERRgeneral, NT_STATUS_FLOPPY_VOLUME}, {
568 ERRHRD, ERRgeneral, NT_STATUS_FLOPPY_ID_MARK_NOT_FOUND}, {
569 ERRHRD, ERRgeneral, NT_STATUS_FLOPPY_WRONG_CYLINDER}, {
570 ERRHRD, ERRgeneral, NT_STATUS_FLOPPY_UNKNOWN_ERROR}, {
571 ERRHRD, ERRgeneral, NT_STATUS_FLOPPY_BAD_REGISTERS}, {
572 ERRHRD, ERRgeneral, NT_STATUS_DISK_RECALIBRATE_FAILED}, {
573 ERRHRD, ERRgeneral, NT_STATUS_DISK_OPERATION_FAILED}, {
574 ERRHRD, ERRgeneral, NT_STATUS_DISK_RESET_FAILED}, {
575 ERRHRD, ERRgeneral, NT_STATUS_SHARED_IRQ_BUSY}, {
576 ERRHRD, ERRgeneral, NT_STATUS_FT_ORPHANING}, {
577 ERRHRD, ERRgeneral, 0xc000016e}, {
578 ERRHRD, ERRgeneral, 0xc000016f}, {
579 ERRHRD, ERRgeneral, 0xc0000170}, {
580 ERRHRD, ERRgeneral, 0xc0000171}, {
581 ERRHRD, ERRgeneral, NT_STATUS_PARTITION_FAILURE}, {
582 ERRHRD, ERRgeneral, NT_STATUS_INVALID_BLOCK_LENGTH}, {
583 ERRHRD, ERRgeneral, NT_STATUS_DEVICE_NOT_PARTITIONED}, {
584 ERRHRD, ERRgeneral, NT_STATUS_UNABLE_TO_LOCK_MEDIA}, {
585 ERRHRD, ERRgeneral, NT_STATUS_UNABLE_TO_UNLOAD_MEDIA}, {
586 ERRHRD, ERRgeneral, NT_STATUS_EOM_OVERFLOW}, {
587 ERRHRD, ERRgeneral, NT_STATUS_NO_MEDIA}, {
588 ERRHRD, ERRgeneral, 0xc0000179}, {
589 ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_MEMBER}, {
590 ERRHRD, ERRgeneral, NT_STATUS_INVALID_MEMBER}, {
591 ERRHRD, ERRgeneral, NT_STATUS_KEY_DELETED}, {
592 ERRHRD, ERRgeneral, NT_STATUS_NO_LOG_SPACE}, {
593 ERRHRD, ERRgeneral, NT_STATUS_TOO_MANY_SIDS}, {
594 ERRHRD, ERRgeneral, NT_STATUS_LM_CROSS_ENCRYPTION_REQUIRED}, {
595 ERRHRD, ERRgeneral, NT_STATUS_KEY_HAS_CHILDREN}, {
596 ERRHRD, ERRgeneral, NT_STATUS_CHILD_MUST_BE_VOLATILE}, {
597 ERRDOS, 87, NT_STATUS_DEVICE_CONFIGURATION_ERROR}, {
598 ERRHRD, ERRgeneral, NT_STATUS_DRIVER_INTERNAL_ERROR}, {
599 ERRDOS, 22, NT_STATUS_INVALID_DEVICE_STATE}, {
600 ERRHRD, ERRgeneral, NT_STATUS_IO_DEVICE_ERROR}, {
601 ERRHRD, ERRgeneral, NT_STATUS_DEVICE_PROTOCOL_ERROR}, {
602 ERRHRD, ERRgeneral, NT_STATUS_BACKUP_CONTROLLER}, {
603 ERRHRD, ERRgeneral, NT_STATUS_LOG_FILE_FULL}, {
604 ERRDOS, 19, NT_STATUS_TOO_LATE}, {
605 ERRDOS, ERRnoaccess, NT_STATUS_NO_TRUST_LSA_SECRET},
606/* { This NT error code was 'sqashed'
Steve French38702532007-07-08 15:40:40 +0000607 from NT_STATUS_NO_TRUST_SAM_ACCOUNT to
608 NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE during the session setup } */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 {
610 ERRDOS, ERRnoaccess, NT_STATUS_NO_TRUST_SAM_ACCOUNT}, {
611 ERRDOS, ERRnoaccess, NT_STATUS_TRUSTED_DOMAIN_FAILURE}, {
612 ERRDOS, ERRnoaccess, NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE}, {
613 ERRHRD, ERRgeneral, NT_STATUS_EVENTLOG_FILE_CORRUPT}, {
614 ERRHRD, ERRgeneral, NT_STATUS_EVENTLOG_CANT_START}, {
615 ERRDOS, ERRnoaccess, NT_STATUS_TRUST_FAILURE}, {
616 ERRHRD, ERRgeneral, NT_STATUS_MUTANT_LIMIT_EXCEEDED}, {
617 ERRDOS, ERRnetlogonNotStarted, NT_STATUS_NETLOGON_NOT_STARTED}, {
Steve Frencha761ac52007-10-18 21:45:27 +0000618 ERRSRV, ERRaccountexpired, NT_STATUS_ACCOUNT_EXPIRED}, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 ERRHRD, ERRgeneral, NT_STATUS_POSSIBLE_DEADLOCK}, {
620 ERRHRD, ERRgeneral, NT_STATUS_NETWORK_CREDENTIAL_CONFLICT}, {
621 ERRHRD, ERRgeneral, NT_STATUS_REMOTE_SESSION_LIMIT}, {
622 ERRHRD, ERRgeneral, NT_STATUS_EVENTLOG_FILE_CHANGED}, {
623 ERRDOS, ERRnoaccess, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT}, {
624 ERRDOS, ERRnoaccess, NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT}, {
625 ERRDOS, ERRnoaccess, NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT},
626/* { This NT error code was 'sqashed'
Steve French38702532007-07-08 15:40:40 +0000627 from NT_STATUS_DOMAIN_TRUST_INCONSISTENT to NT_STATUS_LOGON_FAILURE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 during the session setup } */
629 {
630 ERRDOS, ERRnoaccess, NT_STATUS_DOMAIN_TRUST_INCONSISTENT}, {
631 ERRHRD, ERRgeneral, NT_STATUS_FS_DRIVER_REQUIRED}, {
632 ERRHRD, ERRgeneral, NT_STATUS_NO_USER_SESSION_KEY}, {
633 ERRDOS, 59, NT_STATUS_USER_SESSION_DELETED}, {
634 ERRHRD, ERRgeneral, NT_STATUS_RESOURCE_LANG_NOT_FOUND}, {
635 ERRDOS, ERRnomem, NT_STATUS_INSUFF_SERVER_RESOURCES}, {
636 ERRHRD, ERRgeneral, NT_STATUS_INVALID_BUFFER_SIZE}, {
637 ERRHRD, ERRgeneral, NT_STATUS_INVALID_ADDRESS_COMPONENT}, {
638 ERRHRD, ERRgeneral, NT_STATUS_INVALID_ADDRESS_WILDCARD}, {
639 ERRDOS, 68, NT_STATUS_TOO_MANY_ADDRESSES}, {
640 ERRDOS, 52, NT_STATUS_ADDRESS_ALREADY_EXISTS}, {
641 ERRDOS, 64, NT_STATUS_ADDRESS_CLOSED}, {
642 ERRDOS, 64, NT_STATUS_CONNECTION_DISCONNECTED}, {
643 ERRDOS, 64, NT_STATUS_CONNECTION_RESET}, {
644 ERRDOS, 68, NT_STATUS_TOO_MANY_NODES}, {
645 ERRDOS, 59, NT_STATUS_TRANSACTION_ABORTED}, {
646 ERRDOS, 59, NT_STATUS_TRANSACTION_TIMED_OUT}, {
647 ERRDOS, 59, NT_STATUS_TRANSACTION_NO_RELEASE}, {
648 ERRDOS, 59, NT_STATUS_TRANSACTION_NO_MATCH}, {
649 ERRDOS, 59, NT_STATUS_TRANSACTION_RESPONDED}, {
650 ERRDOS, 59, NT_STATUS_TRANSACTION_INVALID_ID}, {
651 ERRDOS, 59, NT_STATUS_TRANSACTION_INVALID_TYPE}, {
652 ERRDOS, ERRunsup, NT_STATUS_NOT_SERVER_SESSION}, {
653 ERRDOS, ERRunsup, NT_STATUS_NOT_CLIENT_SESSION}, {
654 ERRHRD, ERRgeneral, NT_STATUS_CANNOT_LOAD_REGISTRY_FILE}, {
655 ERRHRD, ERRgeneral, NT_STATUS_DEBUG_ATTACH_FAILED}, {
656 ERRHRD, ERRgeneral, NT_STATUS_SYSTEM_PROCESS_TERMINATED}, {
657 ERRHRD, ERRgeneral, NT_STATUS_DATA_NOT_ACCEPTED}, {
658 ERRHRD, ERRgeneral, NT_STATUS_NO_BROWSER_SERVERS_FOUND}, {
659 ERRHRD, ERRgeneral, NT_STATUS_VDM_HARD_ERROR}, {
660 ERRHRD, ERRgeneral, NT_STATUS_DRIVER_CANCEL_TIMEOUT}, {
661 ERRHRD, ERRgeneral, NT_STATUS_REPLY_MESSAGE_MISMATCH}, {
662 ERRHRD, ERRgeneral, NT_STATUS_MAPPED_ALIGNMENT}, {
663 ERRDOS, 193, NT_STATUS_IMAGE_CHECKSUM_MISMATCH}, {
664 ERRHRD, ERRgeneral, NT_STATUS_LOST_WRITEBEHIND_DATA}, {
665 ERRHRD, ERRgeneral, NT_STATUS_CLIENT_SERVER_PARAMETERS_INVALID}, {
Steve French6ab16d22005-11-29 20:55:11 -0800666 ERRSRV, ERRpasswordExpired, NT_STATUS_PASSWORD_MUST_CHANGE}, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 ERRHRD, ERRgeneral, NT_STATUS_NOT_FOUND}, {
668 ERRHRD, ERRgeneral, NT_STATUS_NOT_TINY_STREAM}, {
669 ERRHRD, ERRgeneral, NT_STATUS_RECOVERY_FAILURE}, {
670 ERRHRD, ERRgeneral, NT_STATUS_STACK_OVERFLOW_READ}, {
671 ERRHRD, ERRgeneral, NT_STATUS_FAIL_CHECK}, {
672 ERRHRD, ERRgeneral, NT_STATUS_DUPLICATE_OBJECTID}, {
673 ERRHRD, ERRgeneral, NT_STATUS_OBJECTID_EXISTS}, {
674 ERRHRD, ERRgeneral, NT_STATUS_CONVERT_TO_LARGE}, {
675 ERRHRD, ERRgeneral, NT_STATUS_RETRY}, {
676 ERRHRD, ERRgeneral, NT_STATUS_FOUND_OUT_OF_SCOPE}, {
677 ERRHRD, ERRgeneral, NT_STATUS_ALLOCATE_BUCKET}, {
678 ERRHRD, ERRgeneral, NT_STATUS_PROPSET_NOT_FOUND}, {
679 ERRHRD, ERRgeneral, NT_STATUS_MARSHALL_OVERFLOW}, {
680 ERRHRD, ERRgeneral, NT_STATUS_INVALID_VARIANT}, {
681 ERRHRD, ERRgeneral, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND}, {
682 ERRDOS, ERRnoaccess, NT_STATUS_ACCOUNT_LOCKED_OUT}, {
683 ERRDOS, ERRbadfid, NT_STATUS_HANDLE_NOT_CLOSABLE}, {
684 ERRHRD, ERRgeneral, NT_STATUS_CONNECTION_REFUSED}, {
685 ERRHRD, ERRgeneral, NT_STATUS_GRACEFUL_DISCONNECT}, {
686 ERRHRD, ERRgeneral, NT_STATUS_ADDRESS_ALREADY_ASSOCIATED}, {
687 ERRHRD, ERRgeneral, NT_STATUS_ADDRESS_NOT_ASSOCIATED}, {
688 ERRHRD, ERRgeneral, NT_STATUS_CONNECTION_INVALID}, {
689 ERRHRD, ERRgeneral, NT_STATUS_CONNECTION_ACTIVE}, {
690 ERRHRD, ERRgeneral, NT_STATUS_NETWORK_UNREACHABLE}, {
691 ERRHRD, ERRgeneral, NT_STATUS_HOST_UNREACHABLE}, {
692 ERRHRD, ERRgeneral, NT_STATUS_PROTOCOL_UNREACHABLE}, {
693 ERRHRD, ERRgeneral, NT_STATUS_PORT_UNREACHABLE}, {
694 ERRHRD, ERRgeneral, NT_STATUS_REQUEST_ABORTED}, {
695 ERRHRD, ERRgeneral, NT_STATUS_CONNECTION_ABORTED}, {
696 ERRHRD, ERRgeneral, NT_STATUS_BAD_COMPRESSION_BUFFER}, {
697 ERRHRD, ERRgeneral, NT_STATUS_USER_MAPPED_FILE}, {
698 ERRHRD, ERRgeneral, NT_STATUS_AUDIT_FAILED}, {
699 ERRHRD, ERRgeneral, NT_STATUS_TIMER_RESOLUTION_NOT_SET}, {
700 ERRHRD, ERRgeneral, NT_STATUS_CONNECTION_COUNT_LIMIT}, {
701 ERRHRD, ERRgeneral, NT_STATUS_LOGIN_TIME_RESTRICTION}, {
702 ERRHRD, ERRgeneral, NT_STATUS_LOGIN_WKSTA_RESTRICTION}, {
703 ERRDOS, 193, NT_STATUS_IMAGE_MP_UP_MISMATCH}, {
704 ERRHRD, ERRgeneral, 0xc000024a}, {
705 ERRHRD, ERRgeneral, 0xc000024b}, {
706 ERRHRD, ERRgeneral, 0xc000024c}, {
707 ERRHRD, ERRgeneral, 0xc000024d}, {
708 ERRHRD, ERRgeneral, 0xc000024e}, {
709 ERRHRD, ERRgeneral, 0xc000024f}, {
710 ERRHRD, ERRgeneral, NT_STATUS_INSUFFICIENT_LOGON_INFO}, {
711 ERRHRD, ERRgeneral, NT_STATUS_BAD_DLL_ENTRYPOINT}, {
712 ERRHRD, ERRgeneral, NT_STATUS_BAD_SERVICE_ENTRYPOINT}, {
713 ERRHRD, ERRgeneral, NT_STATUS_LPC_REPLY_LOST}, {
714 ERRHRD, ERRgeneral, NT_STATUS_IP_ADDRESS_CONFLICT1}, {
715 ERRHRD, ERRgeneral, NT_STATUS_IP_ADDRESS_CONFLICT2}, {
716 ERRHRD, ERRgeneral, NT_STATUS_REGISTRY_QUOTA_LIMIT}, {
717 ERRSRV, 3, NT_STATUS_PATH_NOT_COVERED}, {
718 ERRHRD, ERRgeneral, NT_STATUS_NO_CALLBACK_ACTIVE}, {
719 ERRHRD, ERRgeneral, NT_STATUS_LICENSE_QUOTA_EXCEEDED}, {
720 ERRHRD, ERRgeneral, NT_STATUS_PWD_TOO_SHORT}, {
721 ERRHRD, ERRgeneral, NT_STATUS_PWD_TOO_RECENT}, {
722 ERRHRD, ERRgeneral, NT_STATUS_PWD_HISTORY_CONFLICT}, {
723 ERRHRD, ERRgeneral, 0xc000025d}, {
724 ERRHRD, ERRgeneral, NT_STATUS_PLUGPLAY_NO_DEVICE}, {
725 ERRHRD, ERRgeneral, NT_STATUS_UNSUPPORTED_COMPRESSION}, {
726 ERRHRD, ERRgeneral, NT_STATUS_INVALID_HW_PROFILE}, {
727 ERRHRD, ERRgeneral, NT_STATUS_INVALID_PLUGPLAY_DEVICE_PATH}, {
728 ERRDOS, 182, NT_STATUS_DRIVER_ORDINAL_NOT_FOUND}, {
729 ERRDOS, 127, NT_STATUS_DRIVER_ENTRYPOINT_NOT_FOUND}, {
730 ERRDOS, 288, NT_STATUS_RESOURCE_NOT_OWNED}, {
Steve French11aa0142005-04-28 22:41:10 -0700731 ERRDOS, ErrTooManyLinks, NT_STATUS_TOO_MANY_LINKS}, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 ERRHRD, ERRgeneral, NT_STATUS_QUOTA_LIST_INCONSISTENT}, {
733 ERRHRD, ERRgeneral, NT_STATUS_FILE_IS_OFFLINE}, {
734 ERRDOS, 21, 0xc000026e}, {
735 ERRDOS, 161, 0xc0000281}, {
736 ERRDOS, ERRnoaccess, 0xc000028a}, {
737 ERRDOS, ERRnoaccess, 0xc000028b}, {
738 ERRHRD, ERRgeneral, 0xc000028c}, {
739 ERRDOS, ERRnoaccess, 0xc000028d}, {
740 ERRDOS, ERRnoaccess, 0xc000028e}, {
741 ERRDOS, ERRnoaccess, 0xc000028f}, {
742 ERRDOS, ERRnoaccess, 0xc0000290}, {
743 ERRDOS, ERRbadfunc, 0xc000029c}, {
Steve French9e39b0a2009-04-30 21:31:15 +0000744 ERRDOS, ERRsymlink, NT_STATUS_STOPPED_ON_SYMLINK}, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 ERRDOS, ERRinvlevel, 0x007c0001}, };
746
747/*****************************************************************************
748 Print an error message from the status code
749 *****************************************************************************/
750static void
751cifs_print_status(__u32 status_code)
752{
753 int idx = 0;
754
755 while (nt_errs[idx].nt_errstr != NULL) {
756 if (((nt_errs[idx].nt_errcode) & 0xFFFFFF) ==
757 (status_code & 0xFFFFFF)) {
758 printk(KERN_NOTICE "Status code returned 0x%08x %s\n",
Steve French38702532007-07-08 15:40:40 +0000759 status_code, nt_errs[idx].nt_errstr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 }
761 idx++;
762 }
763 return;
764}
765
766
767static void
Steve French63d25832007-11-05 21:46:10 +0000768ntstatus_to_dos(__u32 ntstatus, __u8 *eclass, __u16 *ecode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769{
770 int i;
771 if (ntstatus == 0) {
772 *eclass = 0;
773 *ecode = 0;
774 return;
775 }
776 for (i = 0; ntstatus_to_dos_map[i].ntstatus; i++) {
777 if (ntstatus == ntstatus_to_dos_map[i].ntstatus) {
778 *eclass = ntstatus_to_dos_map[i].dos_class;
779 *ecode = ntstatus_to_dos_map[i].dos_code;
780 return;
781 }
782 }
783 *eclass = ERRHRD;
784 *ecode = ERRgeneral;
785}
786
787int
Steve Frencha761ac52007-10-18 21:45:27 +0000788map_smb_to_linux_error(struct smb_hdr *smb, int logErr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789{
790 unsigned int i;
Steve French38702532007-07-08 15:40:40 +0000791 int rc = -EIO; /* if transport error smb error may not be set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 __u8 smberrclass;
793 __u16 smberrcode;
794
795 /* BB if NT Status codes - map NT BB */
796
797 /* old style smb error codes */
798 if (smb->Status.CifsError == 0)
799 return 0;
800
801 if (smb->Flags2 & SMBFLG2_ERR_STATUS) {
Steve French38702532007-07-08 15:40:40 +0000802 /* translate the newer STATUS codes to old style SMB errors
803 * and then to POSIX errors */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 __u32 err = le32_to_cpu(smb->Status.CifsError);
Steve Frencha761ac52007-10-18 21:45:27 +0000805 if (logErr && (err != (NT_STATUS_MORE_PROCESSING_REQUIRED)))
806 cifs_print_status(err);
807 else if (cifsFYI & CIFS_RC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 cifs_print_status(err);
809 ntstatus_to_dos(err, &smberrclass, &smberrcode);
810 } else {
811 smberrclass = smb->Status.DosError.ErrorClass;
812 smberrcode = le16_to_cpu(smb->Status.DosError.Error);
813 }
814
815 /* old style errors */
816
817 /* DOS class smb error codes - map DOS */
Steve Frenchad7a2922008-02-07 23:25:02 +0000818 if (smberrclass == ERRDOS) {
819 /* 1 byte field no need to byte reverse */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 for (i = 0;
821 i <
Steve French630f3f0c2007-10-25 21:17:17 +0000822 sizeof(mapping_table_ERRDOS) /
823 sizeof(struct smb_to_posix_error); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 if (mapping_table_ERRDOS[i].smb_err == 0)
825 break;
Steve French63135e02007-07-17 17:34:02 +0000826 else if (mapping_table_ERRDOS[i].smb_err ==
827 smberrcode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 rc = mapping_table_ERRDOS[i].posix_code;
829 break;
830 }
Steve French38702532007-07-08 15:40:40 +0000831 /* else try next error mapping one to see if match */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 }
Steve Frenchad7a2922008-02-07 23:25:02 +0000833 } else if (smberrclass == ERRSRV) {
834 /* server class of error codes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 for (i = 0;
836 i <
Steve French630f3f0c2007-10-25 21:17:17 +0000837 sizeof(mapping_table_ERRSRV) /
838 sizeof(struct smb_to_posix_error); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 if (mapping_table_ERRSRV[i].smb_err == 0)
840 break;
Steve French63135e02007-07-17 17:34:02 +0000841 else if (mapping_table_ERRSRV[i].smb_err ==
842 smberrcode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 rc = mapping_table_ERRSRV[i].posix_code;
844 break;
845 }
Steve French38702532007-07-08 15:40:40 +0000846 /* else try next error mapping to see if match */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 }
848 }
849 /* else ERRHRD class errors or junk - return EIO */
850
Steve Frencha761ac52007-10-18 21:45:27 +0000851 cFYI(1, ("Mapping smb error code %d to POSIX err %d",
Steve French38702532007-07-08 15:40:40 +0000852 smberrcode, rc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
Steve French50c2f752007-07-13 00:33:32 +0000854 /* generic corrective action e.g. reconnect SMB session on
Steve French38702532007-07-08 15:40:40 +0000855 * ERRbaduid could be added */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
857 return rc;
858}
859
860/*
861 * calculate the size of the SMB message based on the fixed header
862 * portion, the number of word parameters and the data portion of the message
863 */
864unsigned int
865smbCalcSize(struct smb_hdr *ptr)
866{
Steve French630f3f0c2007-10-25 21:17:17 +0000867 return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) +
Steve French70ca7342005-09-22 16:32:06 -0700868 2 /* size of the bcc field */ + BCC(ptr));
869}
870
871unsigned int
872smbCalcSize_LE(struct smb_hdr *ptr)
873{
Steve French630f3f0c2007-10-25 21:17:17 +0000874 return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) +
Steve French70ca7342005-09-22 16:32:06 -0700875 2 /* size of the bcc field */ + le16_to_cpu(BCC_LE(ptr)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876}
877
878/* The following are taken from fs/ntfs/util.c */
879
880#define NTFS_TIME_OFFSET ((u64)(369*365 + 89) * 24 * 3600 * 10000000)
881
Jeff Layton07119a42009-05-27 09:37:33 -0400882/*
883 * Convert the NT UTC (based 1601-01-01, in hundred nanosecond units)
884 * into Unix UTC (based 1970-01-01, in seconds).
885 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886struct timespec
Jeff Layton07119a42009-05-27 09:37:33 -0400887cifs_NTtimeToUnix(__le64 ntutc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888{
Steve French38702532007-07-08 15:40:40 +0000889 struct timespec ts;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 /* BB what about the timezone? BB */
891
892 /* Subtract the NTFS time offset, then convert to 1s intervals. */
893 u64 t;
894
Jeff Layton07119a42009-05-27 09:37:33 -0400895 t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 ts.tv_nsec = do_div(t, 10000000) * 100;
Steve French38702532007-07-08 15:40:40 +0000897 ts.tv_sec = t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 return ts;
899}
900
901/* Convert the Unix UTC into NT UTC. */
902u64
903cifs_UnixTimeToNT(struct timespec t)
904{
905 /* Convert to 100ns intervals and then add the NTFS time offset. */
906 return (u64) t.tv_sec * 10000000 + t.tv_nsec/100 + NTFS_TIME_OFFSET;
907}
Steve French1bd5bbc2006-09-28 03:35:57 +0000908
909static int total_days_of_prev_months[] =
910{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
911
Jeff Laytonc4a2c082009-05-27 09:37:33 -0400912struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, int offset)
Steve French1bd5bbc2006-09-28 03:35:57 +0000913{
Steve French1bd5bbc2006-09-28 03:35:57 +0000914 struct timespec ts;
Steve French268f3be2006-10-06 21:47:09 +0000915 int sec, min, days, month, year;
Jeff Laytonc4a2c082009-05-27 09:37:33 -0400916 u16 date = le16_to_cpu(le_date);
917 u16 time = le16_to_cpu(le_time);
Steve Frenchad7a2922008-02-07 23:25:02 +0000918 SMB_TIME *st = (SMB_TIME *)&time;
919 SMB_DATE *sd = (SMB_DATE *)&date;
Steve French1bd5bbc2006-09-28 03:35:57 +0000920
Steve French38702532007-07-08 15:40:40 +0000921 cFYI(1, ("date %d time %d", date, time));
Steve French1bd5bbc2006-09-28 03:35:57 +0000922
Steve French268f3be2006-10-06 21:47:09 +0000923 sec = 2 * st->TwoSeconds;
924 min = st->Minutes;
Steve French790fe572007-07-07 19:25:05 +0000925 if ((sec > 59) || (min > 59))
Steve French38702532007-07-08 15:40:40 +0000926 cERROR(1, ("illegal time min %d sec %d", min, sec));
Steve French1bd5bbc2006-09-28 03:35:57 +0000927 sec += (min * 60);
Steve French268f3be2006-10-06 21:47:09 +0000928 sec += 60 * 60 * st->Hours;
Steve French790fe572007-07-07 19:25:05 +0000929 if (st->Hours > 24)
Steve French38702532007-07-08 15:40:40 +0000930 cERROR(1, ("illegal hours %d", st->Hours));
Steve French268f3be2006-10-06 21:47:09 +0000931 days = sd->Day;
932 month = sd->Month;
Steve Frenchd5d18502007-10-17 21:31:52 +0000933 if ((days > 31) || (month > 12)) {
Steve French38702532007-07-08 15:40:40 +0000934 cERROR(1, ("illegal date, month %d day: %d", month, days));
Steve Frenchd5d18502007-10-17 21:31:52 +0000935 if (month > 12)
936 month = 12;
937 }
Steve French1bd5bbc2006-09-28 03:35:57 +0000938 month -= 1;
939 days += total_days_of_prev_months[month];
Steve French533f90a2006-10-12 00:02:32 +0000940 days += 3652; /* account for difference in days between 1980 and 1970 */
Steve French268f3be2006-10-06 21:47:09 +0000941 year = sd->Year;
Steve French1bd5bbc2006-09-28 03:35:57 +0000942 days += year * 365;
943 days += (year/4); /* leap year */
Steve French438dd922006-10-11 03:49:30 +0000944 /* generalized leap year calculation is more complex, ie no leap year
945 for years/100 except for years/400, but since the maximum number for DOS
946 year is 2**7, the last year is 1980+127, which means we need only
947 consider 2 special case years, ie the years 2000 and 2100, and only
Steve French38702532007-07-08 15:40:40 +0000948 adjust for the lack of leap year for the year 2100, as 2000 was a
Steve French438dd922006-10-11 03:49:30 +0000949 leap year (divisable by 400) */
Steve French790fe572007-07-07 19:25:05 +0000950 if (year >= 120) /* the year 2100 */
Steve French438dd922006-10-11 03:49:30 +0000951 days = days - 1; /* do not count leap year for the year 2100 */
952
Steve French1bd5bbc2006-09-28 03:35:57 +0000953 /* adjust for leap year where we are still before leap day */
Steve French790fe572007-07-07 19:25:05 +0000954 if (year != 120)
Steve French70903ca2006-10-11 18:49:24 +0000955 days -= ((year & 0x03) == 0) && (month < 2 ? 1 : 0);
Steve French790fe572007-07-07 19:25:05 +0000956 sec += 24 * 60 * 60 * days;
Steve French1bd5bbc2006-09-28 03:35:57 +0000957
Jeff Laytonc4a2c082009-05-27 09:37:33 -0400958 ts.tv_sec = sec + offset;
Steve French1bd5bbc2006-09-28 03:35:57 +0000959
Steve French268f3be2006-10-06 21:47:09 +0000960 /* cFYI(1,("sec after cnvrt dos to unix time %d",sec)); */
961
Steve French1bd5bbc2006-09-28 03:35:57 +0000962 ts.tv_nsec = 0;
963 return ts;
Steve French38702532007-07-08 15:40:40 +0000964}