Merge branch 'stable/bug-fixes-rc1' of git://git.kernel.org/pub/scm/linux/kernel...
[pandora-kernel.git] / fs / cifs / cifspdu.h
1 /*
2  *   fs/cifs/cifspdu.h
3  *
4  *   Copyright (c) International Business Machines  Corp., 2002,2009
5  *   Author(s): Steve French (sfrench@us.ibm.com)
6  *
7  *   This library is free software; you can redistribute it and/or modify
8  *   it under the terms of the GNU Lesser General Public License as published
9  *   by the Free Software Foundation; either version 2.1 of the License, or
10  *   (at your option) any later version.
11  *
12  *   This library is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
15  *   the GNU Lesser General Public License for more details.
16  *
17  *   You should have received a copy of the GNU Lesser General Public License
18  *   along with this library; if not, write to the Free Software
19  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */
21
22 #ifndef _CIFSPDU_H
23 #define _CIFSPDU_H
24
25 #include <net/sock.h>
26 #include "smbfsctl.h"
27
28 #ifdef CONFIG_CIFS_WEAK_PW_HASH
29 #define LANMAN_PROT 0
30 #define LANMAN2_PROT 1
31 #define CIFS_PROT   2
32 #else
33 #define CIFS_PROT   0
34 #endif
35 #define POSIX_PROT  (CIFS_PROT+1)
36 #define BAD_PROT 0xFFFF
37
38 /* SMB command codes:
39  * Note some commands have minimal (wct=0,bcc=0), or uninteresting, responses
40  * (ie which include no useful data other than the SMB error code itself).
41  * This can allow us to avoid response buffer allocations and copy in some cases
42  */
43 #define SMB_COM_CREATE_DIRECTORY      0x00 /* trivial response */
44 #define SMB_COM_DELETE_DIRECTORY      0x01 /* trivial response */
45 #define SMB_COM_CLOSE                 0x04 /* triv req/rsp, timestamp ignored */
46 #define SMB_COM_FLUSH                 0x05 /* triv req/rsp */
47 #define SMB_COM_DELETE                0x06 /* trivial response */
48 #define SMB_COM_RENAME                0x07 /* trivial response */
49 #define SMB_COM_QUERY_INFORMATION     0x08 /* aka getattr */
50 #define SMB_COM_SETATTR               0x09 /* trivial response */
51 #define SMB_COM_LOCKING_ANDX          0x24 /* trivial response */
52 #define SMB_COM_COPY                  0x29 /* trivial rsp, fail filename ignrd*/
53 #define SMB_COM_ECHO                  0x2B /* echo request */
54 #define SMB_COM_OPEN_ANDX             0x2D /* Legacy open for old servers */
55 #define SMB_COM_READ_ANDX             0x2E
56 #define SMB_COM_WRITE_ANDX            0x2F
57 #define SMB_COM_TRANSACTION2          0x32
58 #define SMB_COM_TRANSACTION2_SECONDARY 0x33
59 #define SMB_COM_FIND_CLOSE2           0x34 /* trivial response */
60 #define SMB_COM_TREE_DISCONNECT       0x71 /* trivial response */
61 #define SMB_COM_NEGOTIATE             0x72
62 #define SMB_COM_SESSION_SETUP_ANDX    0x73
63 #define SMB_COM_LOGOFF_ANDX           0x74 /* trivial response */
64 #define SMB_COM_TREE_CONNECT_ANDX     0x75
65 #define SMB_COM_NT_TRANSACT           0xA0
66 #define SMB_COM_NT_TRANSACT_SECONDARY 0xA1
67 #define SMB_COM_NT_CREATE_ANDX        0xA2
68 #define SMB_COM_NT_CANCEL             0xA4 /* no response */
69 #define SMB_COM_NT_RENAME             0xA5 /* trivial response */
70
71 /* Transact2 subcommand codes */
72 #define TRANS2_OPEN                   0x00
73 #define TRANS2_FIND_FIRST             0x01
74 #define TRANS2_FIND_NEXT              0x02
75 #define TRANS2_QUERY_FS_INFORMATION   0x03
76 #define TRANS2_SET_FS_INFORMATION     0x04
77 #define TRANS2_QUERY_PATH_INFORMATION 0x05
78 #define TRANS2_SET_PATH_INFORMATION   0x06
79 #define TRANS2_QUERY_FILE_INFORMATION 0x07
80 #define TRANS2_SET_FILE_INFORMATION   0x08
81 #define TRANS2_GET_DFS_REFERRAL       0x10
82 #define TRANS2_REPORT_DFS_INCOSISTENCY 0x11
83
84 /* SMB Transact (Named Pipe) subcommand codes */
85 #define TRANS_SET_NMPIPE_STATE      0x0001
86 #define TRANS_RAW_READ_NMPIPE       0x0011
87 #define TRANS_QUERY_NMPIPE_STATE    0x0021
88 #define TRANS_QUERY_NMPIPE_INFO     0x0022
89 #define TRANS_PEEK_NMPIPE           0x0023
90 #define TRANS_TRANSACT_NMPIPE       0x0026
91 #define TRANS_RAW_WRITE_NMPIPE      0x0031
92 #define TRANS_READ_NMPIPE           0x0036
93 #define TRANS_WRITE_NMPIPE          0x0037
94 #define TRANS_WAIT_NMPIPE           0x0053
95 #define TRANS_CALL_NMPIPE           0x0054
96
97 /* NT Transact subcommand codes */
98 #define NT_TRANSACT_CREATE            0x01
99 #define NT_TRANSACT_IOCTL             0x02
100 #define NT_TRANSACT_SET_SECURITY_DESC 0x03
101 #define NT_TRANSACT_NOTIFY_CHANGE     0x04
102 #define NT_TRANSACT_RENAME            0x05
103 #define NT_TRANSACT_QUERY_SECURITY_DESC 0x06
104 #define NT_TRANSACT_GET_USER_QUOTA    0x07
105 #define NT_TRANSACT_SET_USER_QUOTA    0x08
106
107 #define MAX_CIFS_SMALL_BUFFER_SIZE 448 /* big enough for most */
108 /* future chained NTCreateXReadX bigger, but for time being NTCreateX biggest */
109 /* among the requests (NTCreateX response is bigger with wct of 34) */
110 #define MAX_CIFS_HDR_SIZE 0x58 /* 4 len + 32 hdr + (2*24 wct) + 2 bct + 2 pad */
111 #define CIFS_SMALL_PATH 120 /* allows for (448-88)/3 */
112
113 /* internal cifs vfs structures */
114 /*****************************************************************
115  * All constants go here
116  *****************************************************************
117  */
118
119 /*
120  * Starting value for maximum SMB size negotiation
121  */
122 #define CIFS_MAX_MSGSIZE (4*4096)
123
124 /*
125  * Size of encrypted user password in bytes
126  */
127 #define CIFS_ENCPWD_SIZE (16)
128
129 /*
130  * Size of the crypto key returned on the negotiate SMB in bytes
131  */
132 #define CIFS_CRYPTO_KEY_SIZE (8)
133
134 /*
135  * Size of the ntlm client response
136  */
137 #define CIFS_AUTH_RESP_SIZE (24)
138
139 /*
140  * Size of the session key (crypto key encrypted with the password
141  */
142 #define CIFS_SESS_KEY_SIZE (16)
143
144 #define CIFS_CLIENT_CHALLENGE_SIZE (8)
145 #define CIFS_SERVER_CHALLENGE_SIZE (8)
146 #define CIFS_HMAC_MD5_HASH_SIZE (16)
147 #define CIFS_CPHTXT_SIZE (16)
148 #define CIFS_NTHASH_SIZE (16)
149
150 /*
151  * Maximum user name length
152  */
153 #define CIFS_UNLEN (20)
154
155 /*
156  * Flags on SMB open
157  */
158 #define SMBOPEN_WRITE_THROUGH 0x4000
159 #define SMBOPEN_DENY_ALL      0x0010
160 #define SMBOPEN_DENY_WRITE    0x0020
161 #define SMBOPEN_DENY_READ     0x0030
162 #define SMBOPEN_DENY_NONE     0x0040
163 #define SMBOPEN_READ          0x0000
164 #define SMBOPEN_WRITE         0x0001
165 #define SMBOPEN_READWRITE     0x0002
166 #define SMBOPEN_EXECUTE       0x0003
167
168 #define SMBOPEN_OCREATE       0x0010
169 #define SMBOPEN_OTRUNC        0x0002
170 #define SMBOPEN_OAPPEND       0x0001
171
172 /*
173  * SMB flag definitions
174  */
175 #define SMBFLG_EXTD_LOCK 0x01   /* server supports lock-read write-unlock smb */
176 #define SMBFLG_RCV_POSTED 0x02  /* obsolete */
177 #define SMBFLG_RSVD 0x04
178 #define SMBFLG_CASELESS 0x08    /* all pathnames treated as caseless (off
179                                 implies case sensitive file handling request) */
180 #define SMBFLG_CANONICAL_PATH_FORMAT 0x10       /* obsolete */
181 #define SMBFLG_OLD_OPLOCK 0x20  /* obsolete */
182 #define SMBFLG_OLD_OPLOCK_NOTIFY 0x40   /* obsolete */
183 #define SMBFLG_RESPONSE 0x80    /* this PDU is a response from server */
184
185 /*
186  * SMB flag2 definitions
187  */
188 #define SMBFLG2_KNOWS_LONG_NAMES cpu_to_le16(1) /* can send long (non-8.3)
189                                                    path names in response */
190 #define SMBFLG2_KNOWS_EAS cpu_to_le16(2)
191 #define SMBFLG2_SECURITY_SIGNATURE cpu_to_le16(4)
192 #define SMBFLG2_COMPRESSED (8)
193 #define SMBFLG2_SECURITY_SIGNATURE_REQUIRED (0x10)
194 #define SMBFLG2_IS_LONG_NAME cpu_to_le16(0x40)
195 #define SMBFLG2_REPARSE_PATH (0x400)
196 #define SMBFLG2_EXT_SEC cpu_to_le16(0x800)
197 #define SMBFLG2_DFS cpu_to_le16(0x1000)
198 #define SMBFLG2_PAGING_IO cpu_to_le16(0x2000)
199 #define SMBFLG2_ERR_STATUS cpu_to_le16(0x4000)
200 #define SMBFLG2_UNICODE cpu_to_le16(0x8000)
201
202 /*
203  * These are the file access permission bits defined in CIFS for the
204  * NTCreateAndX as well as the level 0x107
205  * TRANS2_QUERY_PATH_INFORMATION API.  The level 0x107, SMB_QUERY_FILE_ALL_INFO
206  * responds with the AccessFlags.
207  * The AccessFlags specifies the access permissions a caller has to the
208  * file and can have any suitable combination of the following values:
209  */
210
211 #define FILE_READ_DATA        0x00000001  /* Data can be read from the file   */
212 #define FILE_WRITE_DATA       0x00000002  /* Data can be written to the file  */
213 #define FILE_APPEND_DATA      0x00000004  /* Data can be appended to the file */
214 #define FILE_READ_EA          0x00000008  /* Extended attributes associated   */
215                                           /* with the file can be read        */
216 #define FILE_WRITE_EA         0x00000010  /* Extended attributes associated   */
217                                           /* with the file can be written     */
218 #define FILE_EXECUTE          0x00000020  /*Data can be read into memory from */
219                                           /* the file using system paging I/O */
220 #define FILE_DELETE_CHILD     0x00000040
221 #define FILE_READ_ATTRIBUTES  0x00000080  /* Attributes associated with the   */
222                                           /* file can be read                 */
223 #define FILE_WRITE_ATTRIBUTES 0x00000100  /* Attributes associated with the   */
224                                           /* file can be written              */
225 #define DELETE                0x00010000  /* The file can be deleted          */
226 #define READ_CONTROL          0x00020000  /* The access control list and      */
227                                           /* ownership associated with the    */
228                                           /* file can be read                 */
229 #define WRITE_DAC             0x00040000  /* The access control list and      */
230                                           /* ownership associated with the    */
231                                           /* file can be written.             */
232 #define WRITE_OWNER           0x00080000  /* Ownership information associated */
233                                           /* with the file can be written     */
234 #define SYNCHRONIZE           0x00100000  /* The file handle can waited on to */
235                                           /* synchronize with the completion  */
236                                           /* of an input/output request       */
237 #define GENERIC_ALL           0x10000000
238 #define GENERIC_EXECUTE       0x20000000
239 #define GENERIC_WRITE         0x40000000
240 #define GENERIC_READ          0x80000000
241                                          /* In summary - Relevant file       */
242                                          /* access flags from CIFS are       */
243                                          /* file_read_data, file_write_data  */
244                                          /* file_execute, file_read_attributes*/
245                                          /* write_dac, and delete.           */
246
247 #define FILE_READ_RIGHTS (FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES)
248 #define FILE_WRITE_RIGHTS (FILE_WRITE_DATA | FILE_APPEND_DATA \
249                                 | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES)
250 #define FILE_EXEC_RIGHTS (FILE_EXECUTE)
251
252 #define SET_FILE_READ_RIGHTS (FILE_READ_DATA | FILE_READ_EA | FILE_WRITE_EA \
253                                 | FILE_READ_ATTRIBUTES \
254                                 | FILE_WRITE_ATTRIBUTES \
255                                 | DELETE | READ_CONTROL | WRITE_DAC \
256                                 | WRITE_OWNER | SYNCHRONIZE)
257 #define SET_FILE_WRITE_RIGHTS (FILE_WRITE_DATA | FILE_APPEND_DATA \
258                                 | FILE_READ_EA | FILE_WRITE_EA \
259                                 | FILE_DELETE_CHILD | FILE_READ_ATTRIBUTES \
260                                 | FILE_WRITE_ATTRIBUTES \
261                                 | DELETE | READ_CONTROL | WRITE_DAC \
262                                 | WRITE_OWNER | SYNCHRONIZE)
263 #define SET_FILE_EXEC_RIGHTS (FILE_READ_EA | FILE_WRITE_EA | FILE_EXECUTE \
264                                 | FILE_READ_ATTRIBUTES \
265                                 | FILE_WRITE_ATTRIBUTES \
266                                 | DELETE | READ_CONTROL | WRITE_DAC \
267                                 | WRITE_OWNER | SYNCHRONIZE)
268
269 #define SET_MINIMUM_RIGHTS (FILE_READ_EA | FILE_READ_ATTRIBUTES \
270                                 | READ_CONTROL | SYNCHRONIZE)
271
272
273 /*
274  * Invalid readdir handle
275  */
276 #define CIFS_NO_HANDLE        0xFFFF
277
278 #define NO_CHANGE_64          0xFFFFFFFFFFFFFFFFULL
279 #define NO_CHANGE_32          0xFFFFFFFFUL
280
281 /* IPC$ in ASCII */
282 #define CIFS_IPC_RESOURCE "\x49\x50\x43\x24"
283
284 /* IPC$ in Unicode */
285 #define CIFS_IPC_UNICODE_RESOURCE "\x00\x49\x00\x50\x00\x43\x00\x24\x00\x00"
286
287 /* Unicode Null terminate 2 bytes of 0 */
288 #define UNICODE_NULL "\x00\x00"
289 #define ASCII_NULL 0x00
290
291 /*
292  * Server type values (returned on EnumServer API
293  */
294 #define CIFS_SV_TYPE_DC     0x00000008
295 #define CIFS_SV_TYPE_BACKDC 0x00000010
296
297 /*
298  * Alias type flags (From EnumAlias API call
299  */
300 #define CIFS_ALIAS_TYPE_FILE 0x0001
301 #define CIFS_SHARE_TYPE_FILE 0x0000
302
303 /*
304  * File Attribute flags
305  */
306 #define ATTR_READONLY  0x0001
307 #define ATTR_HIDDEN    0x0002
308 #define ATTR_SYSTEM    0x0004
309 #define ATTR_VOLUME    0x0008
310 #define ATTR_DIRECTORY 0x0010
311 #define ATTR_ARCHIVE   0x0020
312 #define ATTR_DEVICE    0x0040
313 #define ATTR_NORMAL    0x0080
314 #define ATTR_TEMPORARY 0x0100
315 #define ATTR_SPARSE    0x0200
316 #define ATTR_REPARSE   0x0400
317 #define ATTR_COMPRESSED 0x0800
318 #define ATTR_OFFLINE    0x1000  /* ie file not immediately available -
319                                         on offline storage */
320 #define ATTR_NOT_CONTENT_INDEXED 0x2000
321 #define ATTR_ENCRYPTED  0x4000
322 #define ATTR_POSIX_SEMANTICS 0x01000000
323 #define ATTR_BACKUP_SEMANTICS 0x02000000
324 #define ATTR_DELETE_ON_CLOSE 0x04000000
325 #define ATTR_SEQUENTIAL_SCAN 0x08000000
326 #define ATTR_RANDOM_ACCESS   0x10000000
327 #define ATTR_NO_BUFFERING    0x20000000
328 #define ATTR_WRITE_THROUGH   0x80000000
329
330 /* ShareAccess flags */
331 #define FILE_NO_SHARE     0x00000000
332 #define FILE_SHARE_READ   0x00000001
333 #define FILE_SHARE_WRITE  0x00000002
334 #define FILE_SHARE_DELETE 0x00000004
335 #define FILE_SHARE_ALL    0x00000007
336
337 /* CreateDisposition flags, similar to CreateAction as well */
338 #define FILE_SUPERSEDE    0x00000000
339 #define FILE_OPEN         0x00000001
340 #define FILE_CREATE       0x00000002
341 #define FILE_OPEN_IF      0x00000003
342 #define FILE_OVERWRITE    0x00000004
343 #define FILE_OVERWRITE_IF 0x00000005
344
345 /* CreateOptions */
346 #define CREATE_NOT_FILE         0x00000001      /* if set must not be file */
347 #define CREATE_WRITE_THROUGH    0x00000002
348 #define CREATE_SEQUENTIAL       0x00000004
349 #define CREATE_NO_BUFFER        0x00000008      /* should not buffer on srv */
350 #define CREATE_SYNC_ALERT       0x00000010      /* MBZ */
351 #define CREATE_ASYNC_ALERT      0x00000020      /* MBZ */
352 #define CREATE_NOT_DIR          0x00000040    /* if set must not be directory */
353 #define CREATE_TREE_CONNECTION  0x00000080      /* should be zero */
354 #define CREATE_COMPLETE_IF_OPLK 0x00000100      /* should be zero */
355 #define CREATE_NO_EA_KNOWLEDGE  0x00000200
356 #define CREATE_EIGHT_DOT_THREE  0x00000400      /* doc says this is obsolete
357                                                  "open for recovery" flag should
358                                                  be zero in any case */
359 #define CREATE_OPEN_FOR_RECOVERY 0x00000400
360 #define CREATE_RANDOM_ACCESS    0x00000800
361 #define CREATE_DELETE_ON_CLOSE  0x00001000
362 #define CREATE_OPEN_BY_ID       0x00002000
363 #define CREATE_OPEN_BACKUP_INTENT 0x00004000
364 #define CREATE_NO_COMPRESSION   0x00008000
365 #define CREATE_RESERVE_OPFILTER 0x00100000      /* should be zero */
366 #define OPEN_REPARSE_POINT      0x00200000
367 #define OPEN_NO_RECALL          0x00400000
368 #define OPEN_FREE_SPACE_QUERY   0x00800000      /* should be zero */
369 #define CREATE_OPTIONS_MASK     0x007FFFFF
370 #define CREATE_OPTION_READONLY  0x10000000
371 #define CREATE_OPTION_SPECIAL   0x20000000   /* system. NB not sent over wire */
372
373 /* ImpersonationLevel flags */
374 #define SECURITY_ANONYMOUS      0
375 #define SECURITY_IDENTIFICATION 1
376 #define SECURITY_IMPERSONATION  2
377 #define SECURITY_DELEGATION     3
378
379 /* SecurityFlags */
380 #define SECURITY_CONTEXT_TRACKING 0x01
381 #define SECURITY_EFFECTIVE_ONLY   0x02
382
383 /*
384  * Default PID value, used in all SMBs where the PID is not important
385  */
386 #define CIFS_DFT_PID  0x1234
387
388 /*
389  * We use the same routine for Copy and Move SMBs.  This flag is used to
390  * distinguish
391  */
392 #define CIFS_COPY_OP 1
393 #define CIFS_RENAME_OP 2
394
395 #define GETU16(var)  (*((__u16 *)var))  /* BB check for endian issues */
396 #define GETU32(var)  (*((__u32 *)var))  /* BB check for endian issues */
397
398 struct smb_hdr {
399         __u32 smb_buf_length;   /* big endian on wire *//* BB length is only two
400                 or three bytes - with one or two byte type preceding it that are
401                 zero - we could mask the type byte off just in case BB */
402         __u8 Protocol[4];
403         __u8 Command;
404         union {
405                 struct {
406                         __u8 ErrorClass;
407                         __u8 Reserved;
408                         __le16 Error;
409                 } __attribute__((packed)) DosError;
410                 __le32 CifsError;
411         } __attribute__((packed)) Status;
412         __u8 Flags;
413         __le16 Flags2;          /* note: le */
414         __le16 PidHigh;
415         union {
416                 struct {
417                         __le32 SequenceNumber;  /* le */
418                         __u32 Reserved; /* zero */
419                 } __attribute__((packed)) Sequence;
420                 __u8 SecuritySignature[8];      /* le */
421         } __attribute__((packed)) Signature;
422         __u8 pad[2];
423         __u16 Tid;
424         __le16 Pid;
425         __u16 Uid;
426         __u16 Mid;
427         __u8 WordCount;
428 } __attribute__((packed));
429 /* given a pointer to an smb_hdr retrieve the value of byte count */
430 #define BCC(smb_var) (*(__u16 *)((char *)(smb_var) + sizeof(struct smb_hdr) + (2 * (smb_var)->WordCount)))
431 #define BCC_LE(smb_var) (*(__le16 *)((char *)(smb_var) + sizeof(struct smb_hdr) + (2 * (smb_var)->WordCount)))
432 /* given a pointer to an smb_hdr retrieve the pointer to the byte area */
433 #define pByteArea(smb_var) ((unsigned char *)(smb_var) + sizeof(struct smb_hdr) + (2 * (smb_var)->WordCount) + 2)
434
435 /*
436  * Computer Name Length (since Netbios name was length 16 with last byte 0x20)
437  * No longer as important, now that TCP names are more commonly used to
438  * resolve hosts.
439  */
440 #define CNLEN 15
441
442 /*
443  * Share Name Length (SNLEN)
444  * Note:  This length was limited by the SMB used to get
445  *        the Share info.   NetShareEnum only returned 13
446  *        chars, including the null termination.
447  * This was removed because it no longer is limiting.
448  */
449
450 /*
451  * Comment Length
452  */
453 #define MAXCOMMENTLEN 40
454
455 /*
456  * The OS/2 maximum path name
457  */
458 #define MAX_PATHCONF 256
459
460 /*
461  *  SMB frame definitions  (following must be packed structs)
462  *  See the SNIA CIFS Specification for details.
463  *
464  *  The Naming convention is the lower case version of the
465  *  smb command code name for the struct and this is typedef to the
466  *  uppercase version of the same name with the prefix SMB_ removed
467  *  for brevity.  Although typedefs are not commonly used for
468  *  structure definitions in the Linux kernel, their use in the
469  *  CIFS standards document, which this code is based on, may
470  *  make this one of the cases where typedefs for structures make
471  *  sense to improve readability for readers of the standards doc.
472  *  Typedefs can always be removed later if they are too distracting
473  *  and they are only used for the CIFSs PDUs themselves, not
474  *  internal cifs vfs structures
475  *
476  */
477
478 typedef struct negotiate_req {
479         struct smb_hdr hdr;     /* wct = 0 */
480         __le16 ByteCount;
481         unsigned char DialectsArray[1];
482 } __attribute__((packed)) NEGOTIATE_REQ;
483
484 /* Dialect index is 13 for LANMAN */
485
486 #define MIN_TZ_ADJ (15 * 60) /* minimum grid for timezones in seconds */
487
488 typedef struct lanman_neg_rsp {
489         struct smb_hdr hdr;     /* wct = 13 */
490         __le16 DialectIndex;
491         __le16 SecurityMode;
492         __le16 MaxBufSize;
493         __le16 MaxMpxCount;
494         __le16 MaxNumberVcs;
495         __le16 RawMode;
496         __le32 SessionKey;
497         struct {
498                 __le16 Time;
499                 __le16 Date;
500         } __attribute__((packed)) SrvTime;
501         __le16 ServerTimeZone;
502         __le16 EncryptionKeyLength;
503         __le16 Reserved;
504         __u16  ByteCount;
505         unsigned char EncryptionKey[1];
506 } __attribute__((packed)) LANMAN_NEG_RSP;
507
508 #define READ_RAW_ENABLE 1
509 #define WRITE_RAW_ENABLE 2
510 #define RAW_ENABLE (READ_RAW_ENABLE | WRITE_RAW_ENABLE)
511
512 typedef struct negotiate_rsp {
513         struct smb_hdr hdr;     /* wct = 17 */
514         __le16 DialectIndex; /* 0xFFFF = no dialect acceptable */
515         __u8 SecurityMode;
516         __le16 MaxMpxCount;
517         __le16 MaxNumberVcs;
518         __le32 MaxBufferSize;
519         __le32 MaxRawSize;
520         __le32 SessionKey;
521         __le32 Capabilities;    /* see below */
522         __le32 SystemTimeLow;
523         __le32 SystemTimeHigh;
524         __le16 ServerTimeZone;
525         __u8 EncryptionKeyLength;
526         __u16 ByteCount;
527         union {
528                 unsigned char EncryptionKey[1]; /* cap extended security off */
529                 /* followed by Domain name - if extended security is off */
530                 /* followed by 16 bytes of server GUID */
531                 /* then security blob if cap_extended_security negotiated */
532                 struct {
533                         unsigned char GUID[16];
534                         unsigned char SecurityBlob[1];
535                 } __attribute__((packed)) extended_response;
536         } __attribute__((packed)) u;
537 } __attribute__((packed)) NEGOTIATE_RSP;
538
539 /* SecurityMode bits */
540 #define SECMODE_USER          0x01      /* off indicates share level security */
541 #define SECMODE_PW_ENCRYPT    0x02
542 #define SECMODE_SIGN_ENABLED  0x04      /* SMB security signatures enabled */
543 #define SECMODE_SIGN_REQUIRED 0x08      /* SMB security signatures required */
544
545 /* Negotiate response Capabilities */
546 #define CAP_RAW_MODE           0x00000001
547 #define CAP_MPX_MODE           0x00000002
548 #define CAP_UNICODE            0x00000004
549 #define CAP_LARGE_FILES        0x00000008
550 #define CAP_NT_SMBS            0x00000010       /* implies CAP_NT_FIND */
551 #define CAP_RPC_REMOTE_APIS    0x00000020
552 #define CAP_STATUS32           0x00000040
553 #define CAP_LEVEL_II_OPLOCKS   0x00000080
554 #define CAP_LOCK_AND_READ      0x00000100
555 #define CAP_NT_FIND            0x00000200
556 #define CAP_DFS                0x00001000
557 #define CAP_INFOLEVEL_PASSTHRU 0x00002000
558 #define CAP_LARGE_READ_X       0x00004000
559 #define CAP_LARGE_WRITE_X      0x00008000
560 #define CAP_LWIO               0x00010000 /* support fctl_srv_req_resume_key */
561 #define CAP_UNIX               0x00800000
562 #define CAP_COMPRESSED_DATA    0x02000000
563 #define CAP_DYNAMIC_REAUTH     0x20000000
564 #define CAP_PERSISTENT_HANDLES 0x40000000
565 #define CAP_EXTENDED_SECURITY  0x80000000
566
567 typedef union smb_com_session_setup_andx {
568         struct {                /* request format */
569                 struct smb_hdr hdr;     /* wct = 12 */
570                 __u8 AndXCommand;
571                 __u8 AndXReserved;
572                 __le16 AndXOffset;
573                 __le16 MaxBufferSize;
574                 __le16 MaxMpxCount;
575                 __le16 VcNumber;
576                 __u32 SessionKey;
577                 __le16 SecurityBlobLength;
578                 __u32 Reserved;
579                 __le32 Capabilities;    /* see below */
580                 __le16 ByteCount;
581                 unsigned char SecurityBlob[1];  /* followed by */
582                 /* STRING NativeOS */
583                 /* STRING NativeLanMan */
584         } __attribute__((packed)) req;  /* NTLM request format (with
585                                         extended security */
586
587         struct {                /* request format */
588                 struct smb_hdr hdr;     /* wct = 13 */
589                 __u8 AndXCommand;
590                 __u8 AndXReserved;
591                 __le16 AndXOffset;
592                 __le16 MaxBufferSize;
593                 __le16 MaxMpxCount;
594                 __le16 VcNumber;
595                 __u32 SessionKey;
596                 __le16 CaseInsensitivePasswordLength; /* ASCII password len */
597                 __le16 CaseSensitivePasswordLength; /* Unicode password length*/
598                 __u32 Reserved; /* see below */
599                 __le32 Capabilities;
600                 __le16 ByteCount;
601                 unsigned char CaseInsensitivePassword[1];     /* followed by: */
602                 /* unsigned char * CaseSensitivePassword; */
603                 /* STRING AccountName */
604                 /* STRING PrimaryDomain */
605                 /* STRING NativeOS */
606                 /* STRING NativeLanMan */
607         } __attribute__((packed)) req_no_secext; /* NTLM request format (without
608                                                         extended security */
609
610         struct {                /* default (NTLM) response format */
611                 struct smb_hdr hdr;     /* wct = 4 */
612                 __u8 AndXCommand;
613                 __u8 AndXReserved;
614                 __le16 AndXOffset;
615                 __le16 Action;  /* see below */
616                 __le16 SecurityBlobLength;
617                 __u16 ByteCount;
618                 unsigned char SecurityBlob[1];  /* followed by */
619 /*      unsigned char  * NativeOS;      */
620 /*      unsigned char  * NativeLanMan;  */
621 /*      unsigned char  * PrimaryDomain; */
622         } __attribute__((packed)) resp; /* NTLM response
623                                            (with or without extended sec) */
624
625         struct {                /* request format */
626                 struct smb_hdr hdr;     /* wct = 10 */
627                 __u8 AndXCommand;
628                 __u8 AndXReserved;
629                 __le16 AndXOffset;
630                 __le16 MaxBufferSize;
631                 __le16 MaxMpxCount;
632                 __le16 VcNumber;
633                 __u32 SessionKey;
634                 __le16 PasswordLength;
635                 __u32 Reserved; /* encrypt key len and offset */
636                 __le16 ByteCount;
637                 unsigned char AccountPassword[1];       /* followed by */
638                 /* STRING AccountName */
639                 /* STRING PrimaryDomain */
640                 /* STRING NativeOS */
641                 /* STRING NativeLanMan */
642         } __attribute__((packed)) old_req; /* pre-NTLM (LANMAN2.1) req format */
643
644         struct {                /* default (NTLM) response format */
645                 struct smb_hdr hdr;     /* wct = 3 */
646                 __u8 AndXCommand;
647                 __u8 AndXReserved;
648                 __le16 AndXOffset;
649                 __le16 Action;  /* see below */
650                 __u16 ByteCount;
651                 unsigned char NativeOS[1];      /* followed by */
652 /*      unsigned char * NativeLanMan; */
653 /*      unsigned char * PrimaryDomain; */
654         } __attribute__((packed)) old_resp; /* pre-NTLM (LANMAN2.1) response */
655 } __attribute__((packed)) SESSION_SETUP_ANDX;
656
657 /* format of NLTMv2 Response ie "case sensitive password" hash when NTLMv2 */
658
659 #define NTLMSSP_SERVER_TYPE     1
660 #define NTLMSSP_DOMAIN_TYPE     2
661 #define NTLMSSP_FQ_DOMAIN_TYPE  3
662 #define NTLMSSP_DNS_DOMAIN_TYPE 4
663 #define NTLMSSP_DNS_PARENT_TYPE 5
664
665 struct ntlmssp2_name {
666         __le16 type;
667         __le16 length;
668 /*      char   name[length]; */
669 } __attribute__((packed));
670
671 struct ntlmv2_resp {
672         char ntlmv2_hash[CIFS_ENCPWD_SIZE];
673         __le32 blob_signature;
674         __u32  reserved;
675         __le64  time;
676         __u64  client_chal; /* random */
677         __u32  reserved2;
678         /* array of name entries could follow ending in minimum 4 byte struct */
679 } __attribute__((packed));
680
681
682 #define CIFS_NETWORK_OPSYS "CIFS VFS Client for Linux"
683
684 /* Capabilities bits (for NTLM SessSetup request) */
685 #define CAP_UNICODE            0x00000004
686 #define CAP_LARGE_FILES        0x00000008
687 #define CAP_NT_SMBS            0x00000010
688 #define CAP_STATUS32           0x00000040
689 #define CAP_LEVEL_II_OPLOCKS   0x00000080
690 #define CAP_NT_FIND            0x00000200       /* reserved should be zero
691                                 (because NT_SMBs implies the same thing?) */
692 #define CAP_BULK_TRANSFER      0x20000000
693 #define CAP_EXTENDED_SECURITY  0x80000000
694
695 /* Action bits */
696 #define GUEST_LOGIN 1
697
698 typedef struct smb_com_tconx_req {
699         struct smb_hdr hdr;     /* wct = 4 */
700         __u8 AndXCommand;
701         __u8 AndXReserved;
702         __le16 AndXOffset;
703         __le16 Flags;           /* see below */
704         __le16 PasswordLength;
705         __le16 ByteCount;
706         unsigned char Password[1];      /* followed by */
707 /* STRING Path    *//* \\server\share name */
708         /* STRING Service */
709 } __attribute__((packed)) TCONX_REQ;
710
711 typedef struct smb_com_tconx_rsp {
712         struct smb_hdr hdr;     /* wct = 3 , not extended response */
713         __u8 AndXCommand;
714         __u8 AndXReserved;
715         __le16 AndXOffset;
716         __le16 OptionalSupport; /* see below */
717         __u16 ByteCount;
718         unsigned char Service[1];       /* always ASCII, not Unicode */
719         /* STRING NativeFileSystem */
720 } __attribute__((packed)) TCONX_RSP;
721
722 typedef struct smb_com_tconx_rsp_ext {
723         struct smb_hdr hdr;     /* wct = 7, extended response */
724         __u8 AndXCommand;
725         __u8 AndXReserved;
726         __le16 AndXOffset;
727         __le16 OptionalSupport; /* see below */
728         __le32 MaximalShareAccessRights;
729         __le32 GuestMaximalShareAccessRights;
730         __u16 ByteCount;
731         unsigned char Service[1];       /* always ASCII, not Unicode */
732         /* STRING NativeFileSystem */
733 } __attribute__((packed)) TCONX_RSP_EXT;
734
735
736 /* tree connect Flags */
737 #define DISCONNECT_TID          0x0001
738 #define TCON_EXTENDED_SIGNATURES 0x0004
739 #define TCON_EXTENDED_SECINFO   0x0008
740
741 /* OptionalSupport bits */
742 #define SMB_SUPPORT_SEARCH_BITS 0x0001  /* "must have" directory search bits
743                                          (exclusive searches supported) */
744 #define SMB_SHARE_IS_IN_DFS     0x0002
745 #define SMB_CSC_MASK               0x000C
746 /* CSC flags defined as follows */
747 #define SMB_CSC_CACHE_MANUAL_REINT 0x0000
748 #define SMB_CSC_CACHE_AUTO_REINT   0x0004
749 #define SMB_CSC_CACHE_VDO          0x0008
750 #define SMB_CSC_NO_CACHING         0x000C
751 #define SMB_UNIQUE_FILE_NAME    0x0010
752 #define SMB_EXTENDED_SIGNATURES 0x0020
753
754 /* services
755  *
756  * A:       ie disk
757  * LPT1:    ie printer
758  * IPC      ie named pipe
759  * COMM
760  * ?????    ie any type
761  *
762  */
763
764 typedef struct smb_com_echo_req {
765         struct  smb_hdr hdr;
766         __le16  EchoCount;
767         __le16  ByteCount;
768         char    Data[1];
769 } __attribute__((packed)) ECHO_REQ;
770
771 typedef struct smb_com_echo_rsp {
772         struct  smb_hdr hdr;
773         __le16  SequenceNumber;
774         __le16  ByteCount;
775         char    Data[1];
776 } __attribute__((packed)) ECHO_RSP;
777
778 typedef struct smb_com_logoff_andx_req {
779         struct smb_hdr hdr;     /* wct = 2 */
780         __u8 AndXCommand;
781         __u8 AndXReserved;
782         __u16 AndXOffset;
783         __u16 ByteCount;
784 } __attribute__((packed)) LOGOFF_ANDX_REQ;
785
786 typedef struct smb_com_logoff_andx_rsp {
787         struct smb_hdr hdr;     /* wct = 2 */
788         __u8 AndXCommand;
789         __u8 AndXReserved;
790         __u16 AndXOffset;
791         __u16 ByteCount;
792 } __attribute__((packed)) LOGOFF_ANDX_RSP;
793
794 typedef union smb_com_tree_disconnect { /* as an altetnative can use flag on
795                                         tree_connect PDU to effect disconnect */
796                                         /* tdis is probably simplest SMB PDU */
797         struct {
798                 struct smb_hdr hdr;     /* wct = 0 */
799                 __u16 ByteCount;        /* bcc = 0 */
800         } __attribute__((packed)) req;
801         struct {
802                 struct smb_hdr hdr;     /* wct = 0 */
803                 __u16 ByteCount;        /* bcc = 0 */
804         } __attribute__((packed)) resp;
805 } __attribute__((packed)) TREE_DISCONNECT;
806
807 typedef struct smb_com_close_req {
808         struct smb_hdr hdr;     /* wct = 3 */
809         __u16 FileID;
810         __u32 LastWriteTime;    /* should be zero or -1 */
811         __u16 ByteCount;        /* 0 */
812 } __attribute__((packed)) CLOSE_REQ;
813
814 typedef struct smb_com_close_rsp {
815         struct smb_hdr hdr;     /* wct = 0 */
816         __u16 ByteCount;        /* bct = 0 */
817 } __attribute__((packed)) CLOSE_RSP;
818
819 typedef struct smb_com_flush_req {
820         struct smb_hdr hdr;     /* wct = 1 */
821         __u16 FileID;
822         __u16 ByteCount;        /* 0 */
823 } __attribute__((packed)) FLUSH_REQ;
824
825 typedef struct smb_com_findclose_req {
826         struct smb_hdr hdr; /* wct = 1 */
827         __u16 FileID;
828         __u16 ByteCount;    /* 0 */
829 } __attribute__((packed)) FINDCLOSE_REQ;
830
831 /* OpenFlags */
832 #define REQ_MORE_INFO      0x00000001  /* legacy (OPEN_AND_X) only */
833 #define REQ_OPLOCK         0x00000002
834 #define REQ_BATCHOPLOCK    0x00000004
835 #define REQ_OPENDIRONLY    0x00000008
836 #define REQ_EXTENDED_INFO  0x00000010
837
838 /* File type */
839 #define DISK_TYPE               0x0000
840 #define BYTE_PIPE_TYPE          0x0001
841 #define MESSAGE_PIPE_TYPE       0x0002
842 #define PRINTER_TYPE            0x0003
843 #define COMM_DEV_TYPE           0x0004
844 #define UNKNOWN_TYPE            0xFFFF
845
846 /* Device Type or File Status Flags */
847 #define NO_EAS                  0x0001
848 #define NO_SUBSTREAMS           0x0002
849 #define NO_REPARSETAG           0x0004
850 /* following flags can apply if pipe */
851 #define ICOUNT_MASK             0x00FF
852 #define PIPE_READ_MODE          0x0100
853 #define NAMED_PIPE_TYPE         0x0400
854 #define PIPE_END_POINT          0x4000
855 #define BLOCKING_NAMED_PIPE     0x8000
856
857 typedef struct smb_com_open_req {       /* also handles create */
858         struct smb_hdr hdr;     /* wct = 24 */
859         __u8 AndXCommand;
860         __u8 AndXReserved;
861         __le16 AndXOffset;
862         __u8 Reserved;          /* Must Be Zero */
863         __le16 NameLength;
864         __le32 OpenFlags;
865         __u32  RootDirectoryFid;
866         __le32 DesiredAccess;
867         __le64 AllocationSize;
868         __le32 FileAttributes;
869         __le32 ShareAccess;
870         __le32 CreateDisposition;
871         __le32 CreateOptions;
872         __le32 ImpersonationLevel;
873         __u8 SecurityFlags;
874         __le16 ByteCount;
875         char fileName[1];
876 } __attribute__((packed)) OPEN_REQ;
877
878 /* open response: oplock levels */
879 #define OPLOCK_NONE      0
880 #define OPLOCK_EXCLUSIVE 1
881 #define OPLOCK_BATCH     2
882 #define OPLOCK_READ      3  /* level 2 oplock */
883
884 /* open response for CreateAction shifted left */
885 #define CIFS_CREATE_ACTION 0x20000 /* file created */
886
887 typedef struct smb_com_open_rsp {
888         struct smb_hdr hdr;     /* wct = 34 BB */
889         __u8 AndXCommand;
890         __u8 AndXReserved;
891         __le16 AndXOffset;
892         __u8 OplockLevel;
893         __u16 Fid;
894         __le32 CreateAction;
895         __le64 CreationTime;
896         __le64 LastAccessTime;
897         __le64 LastWriteTime;
898         __le64 ChangeTime;
899         __le32 FileAttributes;
900         __le64 AllocationSize;
901         __le64 EndOfFile;
902         __le16 FileType;
903         __le16 DeviceState;
904         __u8 DirectoryFlag;
905         __u16 ByteCount;        /* bct = 0 */
906 } __attribute__((packed)) OPEN_RSP;
907
908 typedef struct smb_com_open_rsp_ext {
909         struct smb_hdr hdr;     /* wct = 42 but meaningless due to MS bug? */
910         __u8 AndXCommand;
911         __u8 AndXReserved;
912         __le16 AndXOffset;
913         __u8 OplockLevel;
914         __u16 Fid;
915         __le32 CreateAction;
916         __le64 CreationTime;
917         __le64 LastAccessTime;
918         __le64 LastWriteTime;
919         __le64 ChangeTime;
920         __le32 FileAttributes;
921         __le64 AllocationSize;
922         __le64 EndOfFile;
923         __le16 FileType;
924         __le16 DeviceState;
925         __u8 DirectoryFlag;
926         __u8 VolumeGUID[16];
927         __u64 FileId; /* note no endian conversion - is opaque UniqueID */
928         __le32 MaximalAccessRights;
929         __le32 GuestMaximalAccessRights;
930         __u16 ByteCount;        /* bct = 0 */
931 } __attribute__((packed)) OPEN_RSP_EXT;
932
933
934 /* format of legacy open request */
935 typedef struct smb_com_openx_req {
936         struct smb_hdr  hdr;    /* wct = 15 */
937         __u8 AndXCommand;
938         __u8 AndXReserved;
939         __le16 AndXOffset;
940         __le16 OpenFlags;
941         __le16 Mode;
942         __le16 Sattr; /* search attributes */
943         __le16 FileAttributes;  /* dos attrs */
944         __le32 CreateTime; /* os2 format */
945         __le16 OpenFunction;
946         __le32 EndOfFile;
947         __le32 Timeout;
948         __le32 Reserved;
949         __le16  ByteCount;  /* file name follows */
950         char   fileName[1];
951 } __attribute__((packed)) OPENX_REQ;
952
953 typedef struct smb_com_openx_rsp {
954         struct smb_hdr  hdr;    /* wct = 15 */
955         __u8 AndXCommand;
956         __u8 AndXReserved;
957         __le16 AndXOffset;
958         __u16  Fid;
959         __le16 FileAttributes;
960         __le32 LastWriteTime; /* os2 format */
961         __le32 EndOfFile;
962         __le16 Access;
963         __le16 FileType;
964         __le16 IPCState;
965         __le16 Action;
966         __u32  FileId;
967         __u16  Reserved;
968         __u16  ByteCount;
969 } __attribute__((packed)) OPENX_RSP;
970
971 /* For encoding of POSIX Open Request - see trans2 function 0x209 data struct */
972
973 /* Legacy write request for older servers */
974 typedef struct smb_com_writex_req {
975         struct smb_hdr hdr;     /* wct = 12 */
976         __u8 AndXCommand;
977         __u8 AndXReserved;
978         __le16 AndXOffset;
979         __u16 Fid;
980         __le32 OffsetLow;
981         __u32 Reserved; /* Timeout */
982         __le16 WriteMode; /* 1 = write through */
983         __le16 Remaining;
984         __le16 Reserved2;
985         __le16 DataLengthLow;
986         __le16 DataOffset;
987         __le16 ByteCount;
988         __u8 Pad;               /* BB check for whether padded to DWORD
989                                    boundary and optimum performance here */
990         char Data[0];
991 } __attribute__((packed)) WRITEX_REQ;
992
993 typedef struct smb_com_write_req {
994         struct smb_hdr hdr;     /* wct = 14 */
995         __u8 AndXCommand;
996         __u8 AndXReserved;
997         __le16 AndXOffset;
998         __u16 Fid;
999         __le32 OffsetLow;
1000         __u32 Reserved;
1001         __le16 WriteMode;
1002         __le16 Remaining;
1003         __le16 DataLengthHigh;
1004         __le16 DataLengthLow;
1005         __le16 DataOffset;
1006         __le32 OffsetHigh;
1007         __le16 ByteCount;
1008         __u8 Pad;               /* BB check for whether padded to DWORD
1009                                    boundary and optimum performance here */
1010         char Data[0];
1011 } __attribute__((packed)) WRITE_REQ;
1012
1013 typedef struct smb_com_write_rsp {
1014         struct smb_hdr hdr;     /* wct = 6 */
1015         __u8 AndXCommand;
1016         __u8 AndXReserved;
1017         __le16 AndXOffset;
1018         __le16 Count;
1019         __le16 Remaining;
1020         __le16 CountHigh;
1021         __u16  Reserved;
1022         __u16 ByteCount;
1023 } __attribute__((packed)) WRITE_RSP;
1024
1025 /* legacy read request for older servers */
1026 typedef struct smb_com_readx_req {
1027         struct smb_hdr hdr;     /* wct = 10 */
1028         __u8 AndXCommand;
1029         __u8 AndXReserved;
1030         __le16 AndXOffset;
1031         __u16 Fid;
1032         __le32 OffsetLow;
1033         __le16 MaxCount;
1034         __le16 MinCount;        /* obsolete */
1035         __le32 Reserved;
1036         __le16 Remaining;
1037         __le16 ByteCount;
1038 } __attribute__((packed)) READX_REQ;
1039
1040 typedef struct smb_com_read_req {
1041         struct smb_hdr hdr;     /* wct = 12 */
1042         __u8 AndXCommand;
1043         __u8 AndXReserved;
1044         __le16 AndXOffset;
1045         __u16 Fid;
1046         __le32 OffsetLow;
1047         __le16 MaxCount;
1048         __le16 MinCount;                /* obsolete */
1049         __le32 MaxCountHigh;
1050         __le16 Remaining;
1051         __le32 OffsetHigh;
1052         __le16 ByteCount;
1053 } __attribute__((packed)) READ_REQ;
1054
1055 typedef struct smb_com_read_rsp {
1056         struct smb_hdr hdr;     /* wct = 12 */
1057         __u8 AndXCommand;
1058         __u8 AndXReserved;
1059         __le16 AndXOffset;
1060         __le16 Remaining;
1061         __le16 DataCompactionMode;
1062         __le16 Reserved;
1063         __le16 DataLength;
1064         __le16 DataOffset;
1065         __le16 DataLengthHigh;
1066         __u64 Reserved2;
1067         __u16 ByteCount;
1068         __u8 Pad;               /* BB check for whether padded to DWORD
1069                                    boundary and optimum performance here */
1070         char Data[1];
1071 } __attribute__((packed)) READ_RSP;
1072
1073 typedef struct locking_andx_range {
1074         __le16 Pid;
1075         __le16 Pad;
1076         __le32 OffsetHigh;
1077         __le32 OffsetLow;
1078         __le32 LengthHigh;
1079         __le32 LengthLow;
1080 } __attribute__((packed)) LOCKING_ANDX_RANGE;
1081
1082 #define LOCKING_ANDX_SHARED_LOCK     0x01
1083 #define LOCKING_ANDX_OPLOCK_RELEASE  0x02
1084 #define LOCKING_ANDX_CHANGE_LOCKTYPE 0x04
1085 #define LOCKING_ANDX_CANCEL_LOCK     0x08
1086 #define LOCKING_ANDX_LARGE_FILES     0x10       /* always on for us */
1087
1088 typedef struct smb_com_lock_req {
1089         struct smb_hdr hdr;     /* wct = 8 */
1090         __u8 AndXCommand;
1091         __u8 AndXReserved;
1092         __le16 AndXOffset;
1093         __u16 Fid;
1094         __u8 LockType;
1095         __u8 OplockLevel;
1096         __le32 Timeout;
1097         __le16 NumberOfUnlocks;
1098         __le16 NumberOfLocks;
1099         __le16 ByteCount;
1100         LOCKING_ANDX_RANGE Locks[1];
1101 } __attribute__((packed)) LOCK_REQ;
1102
1103 /* lock type */
1104 #define CIFS_RDLCK      0
1105 #define CIFS_WRLCK      1
1106 #define CIFS_UNLCK      2
1107 typedef struct cifs_posix_lock {
1108         __le16  lock_type;  /* 0 = Read, 1 = Write, 2 = Unlock */
1109         __le16  lock_flags; /* 1 = Wait (only valid for setlock) */
1110         __le32  pid;
1111         __le64  start;
1112         __le64  length;
1113         /* BB what about additional owner info to identify network client */
1114 } __attribute__((packed)) CIFS_POSIX_LOCK;
1115
1116 typedef struct smb_com_lock_rsp {
1117         struct smb_hdr hdr;     /* wct = 2 */
1118         __u8 AndXCommand;
1119         __u8 AndXReserved;
1120         __le16 AndXOffset;
1121         __u16 ByteCount;
1122 } __attribute__((packed)) LOCK_RSP;
1123
1124 typedef struct smb_com_rename_req {
1125         struct smb_hdr hdr;     /* wct = 1 */
1126         __le16 SearchAttributes;        /* target file attributes */
1127         __le16 ByteCount;
1128         __u8 BufferFormat;      /* 4 = ASCII or Unicode */
1129         unsigned char OldFileName[1];
1130         /* followed by __u8 BufferFormat2 */
1131         /* followed by NewFileName */
1132 } __attribute__((packed)) RENAME_REQ;
1133
1134         /* copy request flags */
1135 #define COPY_MUST_BE_FILE      0x0001
1136 #define COPY_MUST_BE_DIR       0x0002
1137 #define COPY_TARGET_MODE_ASCII 0x0004 /* if not set, binary */
1138 #define COPY_SOURCE_MODE_ASCII 0x0008 /* if not set, binary */
1139 #define COPY_VERIFY_WRITES     0x0010
1140 #define COPY_TREE              0x0020
1141
1142 typedef struct smb_com_copy_req {
1143         struct smb_hdr hdr;     /* wct = 3 */
1144         __u16 Tid2;
1145         __le16 OpenFunction;
1146         __le16 Flags;
1147         __le16 ByteCount;
1148         __u8 BufferFormat;      /* 4 = ASCII or Unicode */
1149         unsigned char OldFileName[1];
1150         /* followed by __u8 BufferFormat2 */
1151         /* followed by NewFileName string */
1152 } __attribute__((packed)) COPY_REQ;
1153
1154 typedef struct smb_com_copy_rsp {
1155         struct smb_hdr hdr;     /* wct = 1 */
1156         __le16 CopyCount;    /* number of files copied */
1157         __u16 ByteCount;    /* may be zero */
1158         __u8 BufferFormat;  /* 0x04 - only present if errored file follows */
1159         unsigned char ErrorFileName[1]; /* only present if error in copy */
1160 } __attribute__((packed)) COPY_RSP;
1161
1162 #define CREATE_HARD_LINK                0x103
1163 #define MOVEFILE_COPY_ALLOWED           0x0002
1164 #define MOVEFILE_REPLACE_EXISTING       0x0001
1165
1166 typedef struct smb_com_nt_rename_req {  /* A5 - also used for create hardlink */
1167         struct smb_hdr hdr;     /* wct = 4 */
1168         __le16 SearchAttributes;        /* target file attributes */
1169         __le16 Flags;           /* spec says Information Level */
1170         __le32 ClusterCount;
1171         __le16 ByteCount;
1172         __u8 BufferFormat;      /* 4 = ASCII or Unicode */
1173         unsigned char OldFileName[1];
1174         /* followed by __u8 BufferFormat2 */
1175         /* followed by NewFileName */
1176 } __attribute__((packed)) NT_RENAME_REQ;
1177
1178 typedef struct smb_com_rename_rsp {
1179         struct smb_hdr hdr;     /* wct = 0 */
1180         __u16 ByteCount;        /* bct = 0 */
1181 } __attribute__((packed)) RENAME_RSP;
1182
1183 typedef struct smb_com_delete_file_req {
1184         struct smb_hdr hdr;     /* wct = 1 */
1185         __le16 SearchAttributes;
1186         __le16 ByteCount;
1187         __u8 BufferFormat;      /* 4 = ASCII */
1188         unsigned char fileName[1];
1189 } __attribute__((packed)) DELETE_FILE_REQ;
1190
1191 typedef struct smb_com_delete_file_rsp {
1192         struct smb_hdr hdr;     /* wct = 0 */
1193         __u16 ByteCount;        /* bct = 0 */
1194 } __attribute__((packed)) DELETE_FILE_RSP;
1195
1196 typedef struct smb_com_delete_directory_req {
1197         struct smb_hdr hdr;     /* wct = 0 */
1198         __le16 ByteCount;
1199         __u8 BufferFormat;      /* 4 = ASCII */
1200         unsigned char DirName[1];
1201 } __attribute__((packed)) DELETE_DIRECTORY_REQ;
1202
1203 typedef struct smb_com_delete_directory_rsp {
1204         struct smb_hdr hdr;     /* wct = 0 */
1205         __u16 ByteCount;        /* bct = 0 */
1206 } __attribute__((packed)) DELETE_DIRECTORY_RSP;
1207
1208 typedef struct smb_com_create_directory_req {
1209         struct smb_hdr hdr;     /* wct = 0 */
1210         __le16 ByteCount;
1211         __u8 BufferFormat;      /* 4 = ASCII */
1212         unsigned char DirName[1];
1213 } __attribute__((packed)) CREATE_DIRECTORY_REQ;
1214
1215 typedef struct smb_com_create_directory_rsp {
1216         struct smb_hdr hdr;     /* wct = 0 */
1217         __u16 ByteCount;        /* bct = 0 */
1218 } __attribute__((packed)) CREATE_DIRECTORY_RSP;
1219
1220 typedef struct smb_com_query_information_req {
1221         struct smb_hdr hdr;     /* wct = 0 */
1222         __le16 ByteCount;       /* 1 + namelen + 1 */
1223         __u8 BufferFormat;      /* 4 = ASCII */
1224         unsigned char FileName[1];
1225 } __attribute__((packed)) QUERY_INFORMATION_REQ;
1226
1227 typedef struct smb_com_query_information_rsp {
1228         struct smb_hdr hdr;     /* wct = 10 */
1229         __le16 attr;
1230         __le32  last_write_time;
1231         __le32 size;
1232         __u16  reserved[5];
1233         __le16 ByteCount;       /* bcc = 0 */
1234 } __attribute__((packed)) QUERY_INFORMATION_RSP;
1235
1236 typedef struct smb_com_setattr_req {
1237         struct smb_hdr hdr; /* wct = 8 */
1238         __le16 attr;
1239         __le16 time_low;
1240         __le16 time_high;
1241         __le16 reserved[5]; /* must be zero */
1242         __u16  ByteCount;
1243         __u8   BufferFormat; /* 4 = ASCII */
1244         unsigned char fileName[1];
1245 } __attribute__((packed)) SETATTR_REQ;
1246
1247 typedef struct smb_com_setattr_rsp {
1248         struct smb_hdr hdr;     /* wct = 0 */
1249         __u16 ByteCount;        /* bct = 0 */
1250 } __attribute__((packed)) SETATTR_RSP;
1251
1252 /* empty wct response to setattr */
1253
1254 /*******************************************************/
1255 /* NT Transact structure definitions follow            */
1256 /* Currently only ioctl, acl (get security descriptor) */
1257 /* and notify are implemented                          */
1258 /*******************************************************/
1259 typedef struct smb_com_ntransact_req {
1260         struct smb_hdr hdr; /* wct >= 19 */
1261         __u8 MaxSetupCount;
1262         __u16 Reserved;
1263         __le32 TotalParameterCount;
1264         __le32 TotalDataCount;
1265         __le32 MaxParameterCount;
1266         __le32 MaxDataCount;
1267         __le32 ParameterCount;
1268         __le32 ParameterOffset;
1269         __le32 DataCount;
1270         __le32 DataOffset;
1271         __u8 SetupCount; /* four setup words follow subcommand */
1272         /* SNIA spec incorrectly included spurious pad here */
1273         __le16 SubCommand; /* 2 = IOCTL/FSCTL */
1274         /* SetupCount words follow then */
1275         __le16 ByteCount;
1276         __u8 Pad[3];
1277         __u8 Parms[0];
1278 } __attribute__((packed)) NTRANSACT_REQ;
1279
1280 typedef struct smb_com_ntransact_rsp {
1281         struct smb_hdr hdr;     /* wct = 18 */
1282         __u8 Reserved[3];
1283         __le32 TotalParameterCount;
1284         __le32 TotalDataCount;
1285         __le32 ParameterCount;
1286         __le32 ParameterOffset;
1287         __le32 ParameterDisplacement;
1288         __le32 DataCount;
1289         __le32 DataOffset;
1290         __le32 DataDisplacement;
1291         __u8 SetupCount;   /* 0 */
1292         __u16 ByteCount;
1293         /* __u8 Pad[3]; */
1294         /* parms and data follow */
1295 } __attribute__((packed)) NTRANSACT_RSP;
1296
1297 typedef struct smb_com_transaction_ioctl_req {
1298         struct smb_hdr hdr;     /* wct = 23 */
1299         __u8 MaxSetupCount;
1300         __u16 Reserved;
1301         __le32 TotalParameterCount;
1302         __le32 TotalDataCount;
1303         __le32 MaxParameterCount;
1304         __le32 MaxDataCount;
1305         __le32 ParameterCount;
1306         __le32 ParameterOffset;
1307         __le32 DataCount;
1308         __le32 DataOffset;
1309         __u8 SetupCount; /* four setup words follow subcommand */
1310         /* SNIA spec incorrectly included spurious pad here */
1311         __le16 SubCommand; /* 2 = IOCTL/FSCTL */
1312         __le32 FunctionCode;
1313         __u16 Fid;
1314         __u8 IsFsctl;  /* 1 = File System Control 0 = device control (IOCTL) */
1315         __u8 IsRootFlag; /* 1 = apply command to root of share (must be DFS) */
1316         __le16 ByteCount;
1317         __u8 Pad[3];
1318         __u8 Data[1];
1319 } __attribute__((packed)) TRANSACT_IOCTL_REQ;
1320
1321 typedef struct smb_com_transaction_ioctl_rsp {
1322         struct smb_hdr hdr;     /* wct = 19 */
1323         __u8 Reserved[3];
1324         __le32 TotalParameterCount;
1325         __le32 TotalDataCount;
1326         __le32 ParameterCount;
1327         __le32 ParameterOffset;
1328         __le32 ParameterDisplacement;
1329         __le32 DataCount;
1330         __le32 DataOffset;
1331         __le32 DataDisplacement;
1332         __u8 SetupCount;        /* 1 */
1333         __le16 ReturnedDataLen;
1334         __u16 ByteCount;
1335 } __attribute__((packed)) TRANSACT_IOCTL_RSP;
1336
1337 #define CIFS_ACL_OWNER 1
1338 #define CIFS_ACL_GROUP 2
1339 #define CIFS_ACL_DACL  4
1340 #define CIFS_ACL_SACL  8
1341
1342 typedef struct smb_com_transaction_qsec_req {
1343         struct smb_hdr hdr;     /* wct = 19 */
1344         __u8 MaxSetupCount;
1345         __u16 Reserved;
1346         __le32 TotalParameterCount;
1347         __le32 TotalDataCount;
1348         __le32 MaxParameterCount;
1349         __le32 MaxDataCount;
1350         __le32 ParameterCount;
1351         __le32 ParameterOffset;
1352         __le32 DataCount;
1353         __le32 DataOffset;
1354         __u8 SetupCount; /* no setup words follow subcommand */
1355         /* SNIA spec incorrectly included spurious pad here */
1356         __le16 SubCommand; /* 6 = QUERY_SECURITY_DESC */
1357         __le16 ByteCount; /* bcc = 3 + 8 */
1358         __u8 Pad[3];
1359         __u16 Fid;
1360         __u16 Reserved2;
1361         __le32 AclFlags;
1362 } __attribute__((packed)) QUERY_SEC_DESC_REQ;
1363
1364
1365 typedef struct smb_com_transaction_ssec_req {
1366         struct smb_hdr hdr;     /* wct = 19 */
1367         __u8 MaxSetupCount;
1368         __u16 Reserved;
1369         __le32 TotalParameterCount;
1370         __le32 TotalDataCount;
1371         __le32 MaxParameterCount;
1372         __le32 MaxDataCount;
1373         __le32 ParameterCount;
1374         __le32 ParameterOffset;
1375         __le32 DataCount;
1376         __le32 DataOffset;
1377         __u8 SetupCount; /* no setup words follow subcommand */
1378         /* SNIA spec incorrectly included spurious pad here */
1379         __le16 SubCommand; /* 3 = SET_SECURITY_DESC */
1380         __le16 ByteCount; /* bcc = 3 + 8 */
1381         __u8 Pad[3];
1382         __u16 Fid;
1383         __u16 Reserved2;
1384         __le32 AclFlags;
1385 } __attribute__((packed)) SET_SEC_DESC_REQ;
1386
1387 typedef struct smb_com_transaction_change_notify_req {
1388         struct smb_hdr hdr;     /* wct = 23 */
1389         __u8 MaxSetupCount;
1390         __u16 Reserved;
1391         __le32 TotalParameterCount;
1392         __le32 TotalDataCount;
1393         __le32 MaxParameterCount;
1394         __le32 MaxDataCount;
1395         __le32 ParameterCount;
1396         __le32 ParameterOffset;
1397         __le32 DataCount;
1398         __le32 DataOffset;
1399         __u8 SetupCount; /* four setup words follow subcommand */
1400         /* SNIA spec incorrectly included spurious pad here */
1401         __le16 SubCommand;/* 4 = Change Notify */
1402         __le32 CompletionFilter;  /* operation to monitor */
1403         __u16 Fid;
1404         __u8 WatchTree;  /* 1 = Monitor subdirectories */
1405         __u8 Reserved2;
1406         __le16 ByteCount;
1407 /*      __u8 Pad[3];*/
1408 /*      __u8 Data[1];*/
1409 } __attribute__((packed)) TRANSACT_CHANGE_NOTIFY_REQ;
1410
1411 /* BB eventually change to use generic ntransact rsp struct
1412       and validation routine */
1413 typedef struct smb_com_transaction_change_notify_rsp {
1414         struct smb_hdr hdr;     /* wct = 18 */
1415         __u8 Reserved[3];
1416         __le32 TotalParameterCount;
1417         __le32 TotalDataCount;
1418         __le32 ParameterCount;
1419         __le32 ParameterOffset;
1420         __le32 ParameterDisplacement;
1421         __le32 DataCount;
1422         __le32 DataOffset;
1423         __le32 DataDisplacement;
1424         __u8 SetupCount;   /* 0 */
1425         __u16 ByteCount;
1426         /* __u8 Pad[3]; */
1427 } __attribute__((packed)) TRANSACT_CHANGE_NOTIFY_RSP;
1428 /* Completion Filter flags for Notify */
1429 #define FILE_NOTIFY_CHANGE_FILE_NAME    0x00000001
1430 #define FILE_NOTIFY_CHANGE_DIR_NAME     0x00000002
1431 #define FILE_NOTIFY_CHANGE_NAME         0x00000003
1432 #define FILE_NOTIFY_CHANGE_ATTRIBUTES   0x00000004
1433 #define FILE_NOTIFY_CHANGE_SIZE         0x00000008
1434 #define FILE_NOTIFY_CHANGE_LAST_WRITE   0x00000010
1435 #define FILE_NOTIFY_CHANGE_LAST_ACCESS  0x00000020
1436 #define FILE_NOTIFY_CHANGE_CREATION     0x00000040
1437 #define FILE_NOTIFY_CHANGE_EA           0x00000080
1438 #define FILE_NOTIFY_CHANGE_SECURITY     0x00000100
1439 #define FILE_NOTIFY_CHANGE_STREAM_NAME  0x00000200
1440 #define FILE_NOTIFY_CHANGE_STREAM_SIZE  0x00000400
1441 #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
1442
1443 #define FILE_ACTION_ADDED               0x00000001
1444 #define FILE_ACTION_REMOVED             0x00000002
1445 #define FILE_ACTION_MODIFIED            0x00000003
1446 #define FILE_ACTION_RENAMED_OLD_NAME    0x00000004
1447 #define FILE_ACTION_RENAMED_NEW_NAME    0x00000005
1448 #define FILE_ACTION_ADDED_STREAM        0x00000006
1449 #define FILE_ACTION_REMOVED_STREAM      0x00000007
1450 #define FILE_ACTION_MODIFIED_STREAM     0x00000008
1451
1452 /* response contains array of the following structures */
1453 struct file_notify_information {
1454         __le32 NextEntryOffset;
1455         __le32 Action;
1456         __le32 FileNameLength;
1457         __u8  FileName[0];
1458 } __attribute__((packed));
1459
1460 struct reparse_data {
1461         __u32   ReparseTag;
1462         __u16   ReparseDataLength;
1463         __u16   Reserved;
1464         __u16   AltNameOffset;
1465         __u16   AltNameLen;
1466         __u16   TargetNameOffset;
1467         __u16   TargetNameLen;
1468         char    LinkNamesBuf[1];
1469 } __attribute__((packed));
1470
1471 struct cifs_quota_data {
1472         __u32   rsrvd1;  /* 0 */
1473         __u32   sid_size;
1474         __u64   rsrvd2;  /* 0 */
1475         __u64   space_used;
1476         __u64   soft_limit;
1477         __u64   hard_limit;
1478         char    sid[1];  /* variable size? */
1479 } __attribute__((packed));
1480
1481 /* quota sub commands */
1482 #define QUOTA_LIST_CONTINUE         0
1483 #define QUOTA_LIST_START        0x100
1484 #define QUOTA_FOR_SID           0x101
1485
1486 struct trans2_req {
1487         /* struct smb_hdr hdr precedes. Set wct = 14+ */
1488         __le16 TotalParameterCount;
1489         __le16 TotalDataCount;
1490         __le16 MaxParameterCount;
1491         __le16 MaxDataCount;
1492         __u8 MaxSetupCount;
1493         __u8 Reserved;
1494         __le16 Flags;
1495         __le32 Timeout;
1496         __u16 Reserved2;
1497         __le16 ParameterCount;
1498         __le16 ParameterOffset;
1499         __le16 DataCount;
1500         __le16 DataOffset;
1501         __u8 SetupCount;
1502         __u8 Reserved3;
1503         __le16 SubCommand; /* 1st setup word - SetupCount words follow */
1504         __le16 ByteCount;
1505 } __attribute__((packed));
1506
1507 struct smb_t2_req {
1508         struct smb_hdr hdr;
1509         struct trans2_req t2_req;
1510 } __attribute__((packed));
1511
1512 struct trans2_resp {
1513         /* struct smb_hdr hdr precedes. Note wct = 10 + setup count */
1514         __le16 TotalParameterCount;
1515         __le16 TotalDataCount;
1516         __u16 Reserved;
1517         __le16 ParameterCount;
1518         __le16 ParameterOffset;
1519         __le16 ParameterDisplacement;
1520         __le16 DataCount;
1521         __le16 DataOffset;
1522         __le16 DataDisplacement;
1523         __u8 SetupCount;
1524         __u8 Reserved1;
1525         /* SetupWords[SetupCount];
1526         __u16 ByteCount;
1527         __u16 Reserved2;*/
1528         /* data area follows */
1529 } __attribute__((packed));
1530
1531 struct smb_t2_rsp {
1532         struct smb_hdr hdr;
1533         struct trans2_resp t2_rsp;
1534 } __attribute__((packed));
1535
1536 /* PathInfo/FileInfo infolevels */
1537 #define SMB_INFO_STANDARD                   1
1538 #define SMB_SET_FILE_EA                     2
1539 #define SMB_QUERY_FILE_EA_SIZE              2
1540 #define SMB_INFO_QUERY_EAS_FROM_LIST        3
1541 #define SMB_INFO_QUERY_ALL_EAS              4
1542 #define SMB_INFO_IS_NAME_VALID              6
1543 #define SMB_QUERY_FILE_BASIC_INFO       0x101
1544 #define SMB_QUERY_FILE_STANDARD_INFO    0x102
1545 #define SMB_QUERY_FILE_EA_INFO          0x103
1546 #define SMB_QUERY_FILE_NAME_INFO        0x104
1547 #define SMB_QUERY_FILE_ALLOCATION_INFO  0x105
1548 #define SMB_QUERY_FILE_END_OF_FILEINFO  0x106
1549 #define SMB_QUERY_FILE_ALL_INFO         0x107
1550 #define SMB_QUERY_ALT_NAME_INFO         0x108
1551 #define SMB_QUERY_FILE_STREAM_INFO      0x109
1552 #define SMB_QUERY_FILE_COMPRESSION_INFO 0x10B
1553 #define SMB_QUERY_FILE_UNIX_BASIC       0x200
1554 #define SMB_QUERY_FILE_UNIX_LINK        0x201
1555 #define SMB_QUERY_POSIX_ACL             0x204
1556 #define SMB_QUERY_XATTR                 0x205  /* e.g. system EA name space */
1557 #define SMB_QUERY_ATTR_FLAGS            0x206  /* append,immutable etc. */
1558 #define SMB_QUERY_POSIX_PERMISSION      0x207
1559 #define SMB_QUERY_POSIX_LOCK            0x208
1560 /* #define SMB_POSIX_OPEN               0x209 */
1561 /* #define SMB_POSIX_UNLINK             0x20a */
1562 #define SMB_QUERY_FILE__UNIX_INFO2      0x20b
1563 #define SMB_QUERY_FILE_INTERNAL_INFO    0x3ee
1564 #define SMB_QUERY_FILE_ACCESS_INFO      0x3f0
1565 #define SMB_QUERY_FILE_NAME_INFO2       0x3f1 /* 0x30 bytes */
1566 #define SMB_QUERY_FILE_POSITION_INFO    0x3f6
1567 #define SMB_QUERY_FILE_MODE_INFO        0x3f8
1568 #define SMB_QUERY_FILE_ALGN_INFO        0x3f9
1569
1570
1571 #define SMB_SET_FILE_BASIC_INFO         0x101
1572 #define SMB_SET_FILE_DISPOSITION_INFO   0x102
1573 #define SMB_SET_FILE_ALLOCATION_INFO    0x103
1574 #define SMB_SET_FILE_END_OF_FILE_INFO   0x104
1575 #define SMB_SET_FILE_UNIX_BASIC         0x200
1576 #define SMB_SET_FILE_UNIX_LINK          0x201
1577 #define SMB_SET_FILE_UNIX_HLINK         0x203
1578 #define SMB_SET_POSIX_ACL               0x204
1579 #define SMB_SET_XATTR                   0x205
1580 #define SMB_SET_ATTR_FLAGS              0x206  /* append, immutable etc. */
1581 #define SMB_SET_POSIX_LOCK              0x208
1582 #define SMB_POSIX_OPEN                  0x209
1583 #define SMB_POSIX_UNLINK                0x20a
1584 #define SMB_SET_FILE_UNIX_INFO2         0x20b
1585 #define SMB_SET_FILE_BASIC_INFO2        0x3ec
1586 #define SMB_SET_FILE_RENAME_INFORMATION 0x3f2 /* BB check if qpathinfo too */
1587 #define SMB_FILE_ALL_INFO2              0x3fa
1588 #define SMB_SET_FILE_ALLOCATION_INFO2   0x3fb
1589 #define SMB_SET_FILE_END_OF_FILE_INFO2  0x3fc
1590 #define SMB_FILE_MOVE_CLUSTER_INFO      0x407
1591 #define SMB_FILE_QUOTA_INFO             0x408
1592 #define SMB_FILE_REPARSEPOINT_INFO      0x409
1593 #define SMB_FILE_MAXIMUM_INFO           0x40d
1594
1595 /* Find File infolevels */
1596 #define SMB_FIND_FILE_INFO_STANDARD       0x001
1597 #define SMB_FIND_FILE_QUERY_EA_SIZE       0x002
1598 #define SMB_FIND_FILE_QUERY_EAS_FROM_LIST 0x003
1599 #define SMB_FIND_FILE_DIRECTORY_INFO      0x101
1600 #define SMB_FIND_FILE_FULL_DIRECTORY_INFO 0x102
1601 #define SMB_FIND_FILE_NAMES_INFO          0x103
1602 #define SMB_FIND_FILE_BOTH_DIRECTORY_INFO 0x104
1603 #define SMB_FIND_FILE_ID_FULL_DIR_INFO    0x105
1604 #define SMB_FIND_FILE_ID_BOTH_DIR_INFO    0x106
1605 #define SMB_FIND_FILE_UNIX                0x202
1606
1607 typedef struct smb_com_transaction2_qpi_req {
1608         struct smb_hdr hdr;     /* wct = 14+ */
1609         __le16 TotalParameterCount;
1610         __le16 TotalDataCount;
1611         __le16 MaxParameterCount;
1612         __le16 MaxDataCount;
1613         __u8 MaxSetupCount;
1614         __u8 Reserved;
1615         __le16 Flags;
1616         __le32 Timeout;
1617         __u16 Reserved2;
1618         __le16 ParameterCount;
1619         __le16 ParameterOffset;
1620         __le16 DataCount;
1621         __le16 DataOffset;
1622         __u8 SetupCount;
1623         __u8 Reserved3;
1624         __le16 SubCommand;      /* one setup word */
1625         __le16 ByteCount;
1626         __u8 Pad;
1627         __le16 InformationLevel;
1628         __u32 Reserved4;
1629         char FileName[1];
1630 } __attribute__((packed)) TRANSACTION2_QPI_REQ;
1631
1632 typedef struct smb_com_transaction2_qpi_rsp {
1633         struct smb_hdr hdr;     /* wct = 10 + SetupCount */
1634         struct trans2_resp t2;
1635         __u16 ByteCount;
1636         __u16 Reserved2; /* parameter word is present for infolevels > 100 */
1637 } __attribute__((packed)) TRANSACTION2_QPI_RSP;
1638
1639 typedef struct smb_com_transaction2_spi_req {
1640         struct smb_hdr hdr;     /* wct = 15 */
1641         __le16 TotalParameterCount;
1642         __le16 TotalDataCount;
1643         __le16 MaxParameterCount;
1644         __le16 MaxDataCount;
1645         __u8 MaxSetupCount;
1646         __u8 Reserved;
1647         __le16 Flags;
1648         __le32 Timeout;
1649         __u16 Reserved2;
1650         __le16 ParameterCount;
1651         __le16 ParameterOffset;
1652         __le16 DataCount;
1653         __le16 DataOffset;
1654         __u8 SetupCount;
1655         __u8 Reserved3;
1656         __le16 SubCommand;      /* one setup word */
1657         __le16 ByteCount;
1658         __u8 Pad;
1659         __u16 Pad1;
1660         __le16 InformationLevel;
1661         __u32 Reserved4;
1662         char FileName[1];
1663 } __attribute__((packed)) TRANSACTION2_SPI_REQ;
1664
1665 typedef struct smb_com_transaction2_spi_rsp {
1666         struct smb_hdr hdr;     /* wct = 10 + SetupCount */
1667         struct trans2_resp t2;
1668         __u16 ByteCount;
1669         __u16 Reserved2; /* parameter word is present for infolevels > 100 */
1670 } __attribute__((packed)) TRANSACTION2_SPI_RSP;
1671
1672 struct set_file_rename {
1673         __le32 overwrite;   /* 1 = overwrite dest */
1674         __u32 root_fid;   /* zero */
1675         __le32 target_name_len;
1676         char  target_name[0];  /* Must be unicode */
1677 } __attribute__((packed));
1678
1679 struct smb_com_transaction2_sfi_req {
1680         struct smb_hdr hdr;     /* wct = 15 */
1681         __le16 TotalParameterCount;
1682         __le16 TotalDataCount;
1683         __le16 MaxParameterCount;
1684         __le16 MaxDataCount;
1685         __u8 MaxSetupCount;
1686         __u8 Reserved;
1687         __le16 Flags;
1688         __le32 Timeout;
1689         __u16 Reserved2;
1690         __le16 ParameterCount;
1691         __le16 ParameterOffset;
1692         __le16 DataCount;
1693         __le16 DataOffset;
1694         __u8 SetupCount;
1695         __u8 Reserved3;
1696         __le16 SubCommand;      /* one setup word */
1697         __le16 ByteCount;
1698         __u8 Pad;
1699         __u16 Pad1;
1700         __u16 Fid;
1701         __le16 InformationLevel;
1702         __u16 Reserved4;
1703 } __attribute__((packed));
1704
1705 struct smb_com_transaction2_sfi_rsp {
1706         struct smb_hdr hdr;     /* wct = 10 + SetupCount */
1707         struct trans2_resp t2;
1708         __u16 ByteCount;
1709         __u16 Reserved2;        /* parameter word reserved -
1710                                         present for infolevels > 100 */
1711 } __attribute__((packed));
1712
1713 struct smb_t2_qfi_req {
1714         struct  smb_hdr hdr;
1715         struct  trans2_req t2;
1716         __u8    Pad;
1717         __u16   Fid;
1718         __le16  InformationLevel;
1719 } __attribute__((packed));
1720
1721 struct smb_t2_qfi_rsp {
1722         struct smb_hdr hdr;     /* wct = 10 + SetupCount */
1723         struct trans2_resp t2;
1724         __u16 ByteCount;
1725         __u16 Reserved2;        /* parameter word reserved -
1726                                    present for infolevels > 100 */
1727 } __attribute__((packed));
1728
1729 /*
1730  * Flags on T2 FINDFIRST and FINDNEXT
1731  */
1732 #define CIFS_SEARCH_CLOSE_ALWAYS  0x0001
1733 #define CIFS_SEARCH_CLOSE_AT_END  0x0002
1734 #define CIFS_SEARCH_RETURN_RESUME 0x0004
1735 #define CIFS_SEARCH_CONTINUE_FROM_LAST 0x0008
1736 #define CIFS_SEARCH_BACKUP_SEARCH 0x0010
1737
1738 /*
1739  * Size of the resume key on FINDFIRST and FINDNEXT calls
1740  */
1741 #define CIFS_SMB_RESUME_KEY_SIZE 4
1742
1743 typedef struct smb_com_transaction2_ffirst_req {
1744         struct smb_hdr hdr;     /* wct = 15 */
1745         __le16 TotalParameterCount;
1746         __le16 TotalDataCount;
1747         __le16 MaxParameterCount;
1748         __le16 MaxDataCount;
1749         __u8 MaxSetupCount;
1750         __u8 Reserved;
1751         __le16 Flags;
1752         __le32 Timeout;
1753         __u16 Reserved2;
1754         __le16 ParameterCount;
1755         __le16 ParameterOffset;
1756         __le16 DataCount;
1757         __le16 DataOffset;
1758         __u8 SetupCount;        /* one */
1759         __u8 Reserved3;
1760         __le16 SubCommand;      /* TRANS2_FIND_FIRST */
1761         __le16 ByteCount;
1762         __u8 Pad;
1763         __le16 SearchAttributes;
1764         __le16 SearchCount;
1765         __le16 SearchFlags;
1766         __le16 InformationLevel;
1767         __le32 SearchStorageType;
1768         char FileName[1];
1769 } __attribute__((packed)) TRANSACTION2_FFIRST_REQ;
1770
1771 typedef struct smb_com_transaction2_ffirst_rsp {
1772         struct smb_hdr hdr;     /* wct = 10 */
1773         struct trans2_resp t2;
1774         __u16 ByteCount;
1775 } __attribute__((packed)) TRANSACTION2_FFIRST_RSP;
1776
1777 typedef struct smb_com_transaction2_ffirst_rsp_parms {
1778         __u16 SearchHandle;
1779         __le16 SearchCount;
1780         __le16 EndofSearch;
1781         __le16 EAErrorOffset;
1782         __le16 LastNameOffset;
1783 } __attribute__((packed)) T2_FFIRST_RSP_PARMS;
1784
1785 typedef struct smb_com_transaction2_fnext_req {
1786         struct smb_hdr hdr;     /* wct = 15 */
1787         __le16 TotalParameterCount;
1788         __le16 TotalDataCount;
1789         __le16 MaxParameterCount;
1790         __le16 MaxDataCount;
1791         __u8 MaxSetupCount;
1792         __u8 Reserved;
1793         __le16 Flags;
1794         __le32 Timeout;
1795         __u16 Reserved2;
1796         __le16 ParameterCount;
1797         __le16 ParameterOffset;
1798         __le16 DataCount;
1799         __le16 DataOffset;
1800         __u8 SetupCount;        /* one */
1801         __u8 Reserved3;
1802         __le16 SubCommand;      /* TRANS2_FIND_NEXT */
1803         __le16 ByteCount;
1804         __u8 Pad;
1805         __u16 SearchHandle;
1806         __le16 SearchCount;
1807         __le16 InformationLevel;
1808         __u32 ResumeKey;
1809         __le16 SearchFlags;
1810         char ResumeFileName[1];
1811 } __attribute__((packed)) TRANSACTION2_FNEXT_REQ;
1812
1813 typedef struct smb_com_transaction2_fnext_rsp {
1814         struct smb_hdr hdr;     /* wct = 10 */
1815         struct trans2_resp t2;
1816         __u16 ByteCount;
1817 } __attribute__((packed)) TRANSACTION2_FNEXT_RSP;
1818
1819 typedef struct smb_com_transaction2_fnext_rsp_parms {
1820         __le16 SearchCount;
1821         __le16 EndofSearch;
1822         __le16 EAErrorOffset;
1823         __le16 LastNameOffset;
1824 } __attribute__((packed)) T2_FNEXT_RSP_PARMS;
1825
1826 /* QFSInfo Levels */
1827 #define SMB_INFO_ALLOCATION         1
1828 #define SMB_INFO_VOLUME             2
1829 #define SMB_QUERY_FS_VOLUME_INFO    0x102
1830 #define SMB_QUERY_FS_SIZE_INFO      0x103
1831 #define SMB_QUERY_FS_DEVICE_INFO    0x104
1832 #define SMB_QUERY_FS_ATTRIBUTE_INFO 0x105
1833 #define SMB_QUERY_CIFS_UNIX_INFO    0x200
1834 #define SMB_QUERY_POSIX_FS_INFO     0x201
1835 #define SMB_QUERY_POSIX_WHO_AM_I    0x202
1836 #define SMB_REQUEST_TRANSPORT_ENCRYPTION 0x203
1837 #define SMB_QUERY_FS_PROXY          0x204 /* WAFS enabled. Returns structure
1838                                             FILE_SYSTEM__UNIX_INFO to tell
1839                                             whether new NTIOCTL available
1840                                             (0xACE) for WAN friendly SMB
1841                                             operations to be carried */
1842 #define SMB_QUERY_LABEL_INFO        0x3ea
1843 #define SMB_QUERY_FS_QUOTA_INFO     0x3ee
1844 #define SMB_QUERY_FS_FULL_SIZE_INFO 0x3ef
1845 #define SMB_QUERY_OBJECTID_INFO     0x3f0
1846
1847 typedef struct smb_com_transaction2_qfsi_req {
1848         struct smb_hdr hdr;     /* wct = 14+ */
1849         __le16 TotalParameterCount;
1850         __le16 TotalDataCount;
1851         __le16 MaxParameterCount;
1852         __le16 MaxDataCount;
1853         __u8 MaxSetupCount;
1854         __u8 Reserved;
1855         __le16 Flags;
1856         __le32 Timeout;
1857         __u16 Reserved2;
1858         __le16 ParameterCount;
1859         __le16 ParameterOffset;
1860         __le16 DataCount;
1861         __le16 DataOffset;
1862         __u8 SetupCount;
1863         __u8 Reserved3;
1864         __le16 SubCommand;      /* one setup word */
1865         __le16 ByteCount;
1866         __u8 Pad;
1867         __le16 InformationLevel;
1868 } __attribute__((packed)) TRANSACTION2_QFSI_REQ;
1869
1870 typedef struct smb_com_transaction_qfsi_rsp {
1871         struct smb_hdr hdr;     /* wct = 10 + SetupCount */
1872         struct trans2_resp t2;
1873         __u16 ByteCount;
1874         __u8 Pad;       /* may be three bytes? *//* followed by data area */
1875 } __attribute__((packed)) TRANSACTION2_QFSI_RSP;
1876
1877 typedef struct whoami_rsp_data { /* Query level 0x202 */
1878         __u32 flags; /* 0 = Authenticated user 1 = GUEST */
1879         __u32 mask; /* which flags bits server understands ie 0x0001 */
1880         __u64 unix_user_id;
1881         __u64 unix_user_gid;
1882         __u32 number_of_supplementary_gids; /* may be zero */
1883         __u32 number_of_sids; /* may be zero */
1884         __u32 length_of_sid_array; /* in bytes - may be zero */
1885         __u32 pad; /* reserved - MBZ */
1886         /* __u64 gid_array[0]; */  /* may be empty */
1887         /* __u8 * psid_list */  /* may be empty */
1888 } __attribute__((packed)) WHOAMI_RSP_DATA;
1889
1890 /* SETFSInfo Levels */
1891 #define SMB_SET_CIFS_UNIX_INFO    0x200
1892 typedef struct smb_com_transaction2_setfsi_req {
1893         struct smb_hdr hdr;     /* wct = 15 */
1894         __le16 TotalParameterCount;
1895         __le16 TotalDataCount;
1896         __le16 MaxParameterCount;
1897         __le16 MaxDataCount;
1898         __u8 MaxSetupCount;
1899         __u8 Reserved;
1900         __le16 Flags;
1901         __le32 Timeout;
1902         __u16 Reserved2;
1903         __le16 ParameterCount;  /* 4 */
1904         __le16 ParameterOffset;
1905         __le16 DataCount;       /* 12 */
1906         __le16 DataOffset;
1907         __u8 SetupCount;        /* one */
1908         __u8 Reserved3;
1909         __le16 SubCommand;      /* TRANS2_SET_FS_INFORMATION */
1910         __le16 ByteCount;
1911         __u8 Pad;
1912         __u16 FileNum;          /* Parameters start. */
1913         __le16 InformationLevel;/* Parameters end. */
1914         __le16 ClientUnixMajor; /* Data start. */
1915         __le16 ClientUnixMinor;
1916         __le64 ClientUnixCap;   /* Data end */
1917 } __attribute__((packed)) TRANSACTION2_SETFSI_REQ;
1918
1919 typedef struct smb_com_transaction2_setfsi_rsp {
1920         struct smb_hdr hdr;     /* wct = 10 */
1921         struct trans2_resp t2;
1922         __u16 ByteCount;
1923 } __attribute__((packed)) TRANSACTION2_SETFSI_RSP;
1924
1925
1926 typedef struct smb_com_transaction2_get_dfs_refer_req {
1927         struct smb_hdr hdr;     /* wct = 15 */
1928         __le16 TotalParameterCount;
1929         __le16 TotalDataCount;
1930         __le16 MaxParameterCount;
1931         __le16 MaxDataCount;
1932         __u8 MaxSetupCount;
1933         __u8 Reserved;
1934         __le16 Flags;
1935         __le32 Timeout;
1936         __u16 Reserved2;
1937         __le16 ParameterCount;
1938         __le16 ParameterOffset;
1939         __le16 DataCount;
1940         __le16 DataOffset;
1941         __u8 SetupCount;
1942         __u8 Reserved3;
1943         __le16 SubCommand;      /* one setup word */
1944         __le16 ByteCount;
1945         __u8 Pad[3];            /* Win2K has sent 0x0F01 (max response length
1946                                    perhaps?) followed by one byte pad - doesn't
1947                                    seem to matter though */
1948         __le16 MaxReferralLevel;
1949         char RequestFileName[1];
1950 } __attribute__((packed)) TRANSACTION2_GET_DFS_REFER_REQ;
1951
1952 #define DFS_VERSION cpu_to_le16(0x0003)
1953
1954 /* DFS server target type */
1955 #define DFS_TYPE_LINK 0x0000  /* also for sysvol targets */
1956 #define DFS_TYPE_ROOT 0x0001
1957
1958 /* Referral Entry Flags */
1959 #define DFS_NAME_LIST_REF 0x0200 /* set for domain or DC referral responses */
1960 #define DFS_TARGET_SET_BOUNDARY 0x0400 /* only valid with version 4 dfs req */
1961
1962 typedef struct dfs_referral_level_3 { /* version 4 is same, + one flag bit */
1963         __le16 VersionNumber;  /* must be 3 or 4 */
1964         __le16 Size;
1965         __le16 ServerType; /* 0x0001 = root targets; 0x0000 = link targets */
1966         __le16 ReferralEntryFlags;
1967         __le32 TimeToLive;
1968         __le16 DfsPathOffset;
1969         __le16 DfsAlternatePathOffset;
1970         __le16 NetworkAddressOffset; /* offset of the link target */
1971         __u8   ServiceSiteGuid[16];  /* MBZ, ignored */
1972 } __attribute__((packed)) REFERRAL3;
1973
1974 typedef struct smb_com_transaction_get_dfs_refer_rsp {
1975         struct smb_hdr hdr;     /* wct = 10 */
1976         struct trans2_resp t2;
1977         __u16 ByteCount;
1978         __u8 Pad;
1979         __le16 PathConsumed;
1980         __le16 NumberOfReferrals;
1981         __le32 DFSFlags;
1982         REFERRAL3 referrals[1]; /* array of level 3 dfs_referral structures */
1983         /* followed by the strings pointed to by the referral structures */
1984 } __attribute__((packed)) TRANSACTION2_GET_DFS_REFER_RSP;
1985
1986 /* DFS Flags */
1987 #define DFSREF_REFERRAL_SERVER  0x00000001 /* all targets are DFS roots */
1988 #define DFSREF_STORAGE_SERVER   0x00000002 /* no further ref requests needed */
1989 #define DFSREF_TARGET_FAILBACK  0x00000004 /* only for DFS referral version 4 */
1990
1991 /*
1992  ************************************************************************
1993  * All structs for everything above the SMB PDUs themselves
1994  * (such as the T2 level specific data) go here
1995  ************************************************************************
1996  */
1997
1998 /*
1999  * Information on a server
2000  */
2001
2002 struct serverInfo {
2003         char name[16];
2004         unsigned char versionMajor;
2005         unsigned char versionMinor;
2006         unsigned long type;
2007         unsigned int commentOffset;
2008 } __attribute__((packed));
2009
2010 /*
2011  * The following structure is the format of the data returned on a NetShareEnum
2012  * with level "90" (x5A)
2013  */
2014
2015 struct shareInfo {
2016         char shareName[13];
2017         char pad;
2018         unsigned short type;
2019         unsigned int commentOffset;
2020 } __attribute__((packed));
2021
2022 struct aliasInfo {
2023         char aliasName[9];
2024         char pad;
2025         unsigned int commentOffset;
2026         unsigned char type[2];
2027 } __attribute__((packed));
2028
2029 struct aliasInfo92 {
2030         int aliasNameOffset;
2031         int serverNameOffset;
2032         int shareNameOffset;
2033 } __attribute__((packed));
2034
2035 typedef struct {
2036         __le64 TotalAllocationUnits;
2037         __le64 FreeAllocationUnits;
2038         __le32 SectorsPerAllocationUnit;
2039         __le32 BytesPerSector;
2040 } __attribute__((packed)) FILE_SYSTEM_INFO;     /* size info, level 0x103 */
2041
2042 typedef struct {
2043         __le32 fsid;
2044         __le32 SectorsPerAllocationUnit;
2045         __le32 TotalAllocationUnits;
2046         __le32 FreeAllocationUnits;
2047         __le16  BytesPerSector;
2048 } __attribute__((packed)) FILE_SYSTEM_ALLOC_INFO;
2049
2050 typedef struct {
2051         __le16 MajorVersionNumber;
2052         __le16 MinorVersionNumber;
2053         __le64 Capability;
2054 } __attribute__((packed)) FILE_SYSTEM_UNIX_INFO; /* Unix extension level 0x200*/
2055
2056 /* Version numbers for CIFS UNIX major and minor. */
2057 #define CIFS_UNIX_MAJOR_VERSION 1
2058 #define CIFS_UNIX_MINOR_VERSION 0
2059
2060 /* Linux/Unix extensions capability flags */
2061 #define CIFS_UNIX_FCNTL_CAP             0x00000001 /* support for fcntl locks */
2062 #define CIFS_UNIX_POSIX_ACL_CAP         0x00000002 /* support getfacl/setfacl */
2063 #define CIFS_UNIX_XATTR_CAP             0x00000004 /* support new namespace   */
2064 #define CIFS_UNIX_EXTATTR_CAP           0x00000008 /* support chattr/chflag   */
2065 #define CIFS_UNIX_POSIX_PATHNAMES_CAP   0x00000010 /* Allow POSIX path chars  */
2066 #define CIFS_UNIX_POSIX_PATH_OPS_CAP    0x00000020 /* Allow new POSIX path based
2067                                                       calls including posix open
2068                                                       and posix unlink */
2069 #define CIFS_UNIX_LARGE_READ_CAP        0x00000040 /* support reads >128K (up
2070                                                       to 0xFFFF00 */
2071 #define CIFS_UNIX_LARGE_WRITE_CAP       0x00000080
2072 #define CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP 0x00000100 /* can do SPNEGO crypt */
2073 #define CIFS_UNIX_TRANSPORT_ENCRYPTION_MANDATORY_CAP  0x00000200 /* must do  */
2074 #define CIFS_UNIX_PROXY_CAP             0x00000400 /* Proxy cap: 0xACE ioctl and
2075                                                       QFS PROXY call */
2076 #ifdef CONFIG_CIFS_POSIX
2077 /* Can not set pathnames cap yet until we send new posix create SMB since
2078    otherwise server can treat such handles opened with older ntcreatex
2079    (by a new client which knows how to send posix path ops)
2080    as non-posix handles (can affect write behavior with byte range locks.
2081    We can add back in POSIX_PATH_OPS cap when Posix Create/Mkdir finished */
2082 /* #define CIFS_UNIX_CAP_MASK              0x000000fb */
2083 #define CIFS_UNIX_CAP_MASK              0x000000db
2084 #else
2085 #define CIFS_UNIX_CAP_MASK              0x00000013
2086 #endif /* CONFIG_CIFS_POSIX */
2087
2088
2089 #define CIFS_POSIX_EXTENSIONS           0x00000010 /* support for new QFSInfo */
2090
2091 typedef struct {
2092         /* For undefined recommended transfer size return -1 in that field */
2093         __le32 OptimalTransferSize;  /* bsize on some os, iosize on other os */
2094         __le32 BlockSize;
2095     /* The next three fields are in terms of the block size.
2096         (above). If block size is unknown, 4096 would be a
2097         reasonable block size for a server to report.
2098         Note that returning the blocks/blocksavail removes need
2099         to make a second call (to QFSInfo level 0x103 to get this info.
2100         UserBlockAvail is typically less than or equal to BlocksAvail,
2101         if no distinction is made return the same value in each */
2102         __le64 TotalBlocks;
2103         __le64 BlocksAvail;       /* bfree */
2104         __le64 UserBlocksAvail;   /* bavail */
2105     /* For undefined Node fields or FSID return -1 */
2106         __le64 TotalFileNodes;
2107         __le64 FreeFileNodes;
2108         __le64 FileSysIdentifier;   /* fsid */
2109         /* NB Namelen comes from FILE_SYSTEM_ATTRIBUTE_INFO call */
2110         /* NB flags can come from FILE_SYSTEM_DEVICE_INFO call   */
2111 } __attribute__((packed)) FILE_SYSTEM_POSIX_INFO;
2112
2113 /* DeviceType Flags */
2114 #define FILE_DEVICE_CD_ROM              0x00000002
2115 #define FILE_DEVICE_CD_ROM_FILE_SYSTEM  0x00000003
2116 #define FILE_DEVICE_DFS                 0x00000006
2117 #define FILE_DEVICE_DISK                0x00000007
2118 #define FILE_DEVICE_DISK_FILE_SYSTEM    0x00000008
2119 #define FILE_DEVICE_FILE_SYSTEM         0x00000009
2120 #define FILE_DEVICE_NAMED_PIPE          0x00000011
2121 #define FILE_DEVICE_NETWORK             0x00000012
2122 #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
2123 #define FILE_DEVICE_NULL                0x00000015
2124 #define FILE_DEVICE_PARALLEL_PORT       0x00000016
2125 #define FILE_DEVICE_PRINTER             0x00000018
2126 #define FILE_DEVICE_SERIAL_PORT         0x0000001b
2127 #define FILE_DEVICE_STREAMS             0x0000001e
2128 #define FILE_DEVICE_TAPE                0x0000001f
2129 #define FILE_DEVICE_TAPE_FILE_SYSTEM    0x00000020
2130 #define FILE_DEVICE_VIRTUAL_DISK        0x00000024
2131 #define FILE_DEVICE_NETWORK_REDIRECTOR  0x00000028
2132
2133 typedef struct {
2134         __le32 DeviceType;
2135         __le32 DeviceCharacteristics;
2136 } __attribute__((packed)) FILE_SYSTEM_DEVICE_INFO; /* device info level 0x104 */
2137
2138 typedef struct {
2139         __le32 Attributes;
2140         __le32 MaxPathNameComponentLength;
2141         __le32 FileSystemNameLen;
2142         char FileSystemName[52]; /* do not have to save this - get subset? */
2143 } __attribute__((packed)) FILE_SYSTEM_ATTRIBUTE_INFO;
2144
2145 /******************************************************************************/
2146 /* QueryFileInfo/QueryPathinfo (also for SetPath/SetFile) data buffer formats */
2147 /******************************************************************************/
2148 typedef struct { /* data block encoding of response to level 263 QPathInfo */
2149         __le64 CreationTime;
2150         __le64 LastAccessTime;
2151         __le64 LastWriteTime;
2152         __le64 ChangeTime;
2153         __le32 Attributes;
2154         __u32 Pad1;
2155         __le64 AllocationSize;
2156         __le64 EndOfFile;       /* size ie offset to first free byte in file */
2157         __le32 NumberOfLinks;   /* hard links */
2158         __u8 DeletePending;
2159         __u8 Directory;
2160         __u16 Pad2;
2161         __u64 IndexNumber;
2162         __le32 EASize;
2163         __le32 AccessFlags;
2164         __u64 IndexNumber1;
2165         __le64 CurrentByteOffset;
2166         __le32 Mode;
2167         __le32 AlignmentRequirement;
2168         __le32 FileNameLength;
2169         char FileName[1];
2170 } __attribute__((packed)) FILE_ALL_INFO;        /* level 0x107 QPathInfo */
2171
2172 /* defines for enumerating possible values of the Unix type field below */
2173 #define UNIX_FILE      0
2174 #define UNIX_DIR       1
2175 #define UNIX_SYMLINK   2
2176 #define UNIX_CHARDEV   3
2177 #define UNIX_BLOCKDEV  4
2178 #define UNIX_FIFO      5
2179 #define UNIX_SOCKET    6
2180 typedef struct {
2181         __le64 EndOfFile;
2182         __le64 NumOfBytes;
2183         __le64 LastStatusChange; /*SNIA specs DCE time for the 3 time fields */
2184         __le64 LastAccessTime;
2185         __le64 LastModificationTime;
2186         __le64 Uid;
2187         __le64 Gid;
2188         __le32 Type;
2189         __le64 DevMajor;
2190         __le64 DevMinor;
2191         __le64 UniqueId;
2192         __le64 Permissions;
2193         __le64 Nlinks;
2194 } __attribute__((packed)) FILE_UNIX_BASIC_INFO; /* level 0x200 QPathInfo */
2195
2196 typedef struct {
2197         char LinkDest[1];
2198 } __attribute__((packed)) FILE_UNIX_LINK_INFO;  /* level 0x201 QPathInfo */
2199
2200 /* The following three structures are needed only for
2201         setting time to NT4 and some older servers via
2202         the primitive DOS time format */
2203 typedef struct {
2204         __u16 Day:5;
2205         __u16 Month:4;
2206         __u16 Year:7;
2207 } __attribute__((packed)) SMB_DATE;
2208
2209 typedef struct {
2210         __u16 TwoSeconds:5;
2211         __u16 Minutes:6;
2212         __u16 Hours:5;
2213 } __attribute__((packed)) SMB_TIME;
2214
2215 typedef struct {
2216         __le16 CreationDate; /* SMB Date see above */
2217         __le16 CreationTime; /* SMB Time */
2218         __le16 LastAccessDate;
2219         __le16 LastAccessTime;
2220         __le16 LastWriteDate;
2221         __le16 LastWriteTime;
2222         __le32 DataSize; /* File Size (EOF) */
2223         __le32 AllocationSize;
2224         __le16 Attributes; /* verify not u32 */
2225         __le32 EASize;
2226 } __attribute__((packed)) FILE_INFO_STANDARD;  /* level 1 SetPath/FileInfo */
2227
2228 typedef struct {
2229         __le64 CreationTime;
2230         __le64 LastAccessTime;
2231         __le64 LastWriteTime;
2232         __le64 ChangeTime;
2233         __le32 Attributes;
2234         __u32 Pad;
2235 } __attribute__((packed)) FILE_BASIC_INFO;      /* size info, level 0x101 */
2236
2237 struct file_allocation_info {
2238         __le64 AllocationSize; /* Note old Samba srvr rounds this up too much */
2239 } __attribute__((packed));      /* size used on disk, for level 0x103 for set,
2240                                    0x105 for query */
2241
2242 struct file_end_of_file_info {
2243         __le64 FileSize;                /* offset to end of file */
2244 } __attribute__((packed)); /* size info, level 0x104 for set, 0x106 for query */
2245
2246 struct file_alt_name_info {
2247         __u8   alt_name[1];
2248 } __attribute__((packed));      /* level 0x0108 */
2249
2250 struct file_stream_info {
2251         __le32 number_of_streams;  /* BB check sizes and verify location */
2252         /* followed by info on streams themselves
2253                 u64 size;
2254                 u64 allocation_size
2255                 stream info */
2256 };      /* level 0x109 */
2257
2258 struct file_compression_info {
2259         __le64 compressed_size;
2260         __le16 format;
2261         __u8   unit_shift;
2262         __u8   ch_shift;
2263         __u8   cl_shift;
2264         __u8   pad[3];
2265 } __attribute__((packed));      /* level 0x10b */
2266
2267 /* POSIX ACL set/query path info structures */
2268 #define CIFS_ACL_VERSION 1
2269 struct cifs_posix_ace { /* access control entry (ACE) */
2270         __u8  cifs_e_tag;
2271         __u8  cifs_e_perm;
2272         __le64 cifs_uid; /* or gid */
2273 } __attribute__((packed));
2274
2275 struct cifs_posix_acl { /* access conrol list  (ACL) */
2276         __le16  version;
2277         __le16  access_entry_count;  /* access ACL - count of entries */
2278         __le16  default_entry_count; /* default ACL - count of entries */
2279         struct cifs_posix_ace ace_array[0];
2280         /* followed by
2281         struct cifs_posix_ace default_ace_arraay[] */
2282 } __attribute__((packed));  /* level 0x204 */
2283
2284 /* types of access control entries already defined in posix_acl.h */
2285 /* #define CIFS_POSIX_ACL_USER_OBJ       0x01
2286 #define CIFS_POSIX_ACL_USER      0x02
2287 #define CIFS_POSIX_ACL_GROUP_OBJ 0x04
2288 #define CIFS_POSIX_ACL_GROUP     0x08
2289 #define CIFS_POSIX_ACL_MASK      0x10
2290 #define CIFS_POSIX_ACL_OTHER     0x20 */
2291
2292 /* types of perms */
2293 /* #define CIFS_POSIX_ACL_EXECUTE   0x01
2294 #define CIFS_POSIX_ACL_WRITE     0x02
2295 #define CIFS_POSIX_ACL_READ          0x04 */
2296
2297 /* end of POSIX ACL definitions */
2298
2299 /* POSIX Open Flags */
2300 #define SMB_O_RDONLY     0x1
2301 #define SMB_O_WRONLY    0x2
2302 #define SMB_O_RDWR      0x4
2303 #define SMB_O_CREAT     0x10
2304 #define SMB_O_EXCL      0x20
2305 #define SMB_O_TRUNC     0x40
2306 #define SMB_O_APPEND    0x80
2307 #define SMB_O_SYNC      0x100
2308 #define SMB_O_DIRECTORY 0x200
2309 #define SMB_O_NOFOLLOW  0x400
2310 #define SMB_O_DIRECT    0x800
2311
2312 typedef struct {
2313         __le32 OpenFlags; /* same as NT CreateX */
2314         __le32 PosixOpenFlags;
2315         __le64 Permissions;
2316         __le16 Level; /* reply level requested (see QPathInfo levels) */
2317 } __attribute__((packed)) OPEN_PSX_REQ; /* level 0x209 SetPathInfo data */
2318
2319 typedef struct {
2320         __le16 OplockFlags;
2321         __u16 Fid;
2322         __le32 CreateAction;
2323         __le16 ReturnedLevel;
2324         __le16 Pad;
2325         /* struct following varies based on requested level */
2326 } __attribute__((packed)) OPEN_PSX_RSP; /* level 0x209 SetPathInfo data */
2327
2328 #define SMB_POSIX_UNLINK_FILE_TARGET            0
2329 #define SMB_POSIX_UNLINK_DIRECTORY_TARGET       1
2330
2331 struct unlink_psx_rq { /* level 0x20a SetPathInfo */
2332         __le16 type;
2333 } __attribute__((packed));
2334
2335 struct file_internal_info {
2336         __le64  UniqueId; /* inode number */
2337 } __attribute__((packed));      /* level 0x3ee */
2338
2339 struct file_mode_info {
2340         __le32  Mode;
2341 } __attribute__((packed));      /* level 0x3f8 */
2342
2343 struct file_attrib_tag {
2344         __le32 Attribute;
2345         __le32 ReparseTag;
2346 } __attribute__((packed));      /* level 0x40b */
2347
2348
2349 /********************************************************/
2350 /*  FindFirst/FindNext transact2 data buffer formats    */
2351 /********************************************************/
2352
2353 typedef struct {
2354         __le32 NextEntryOffset;
2355         __u32 ResumeKey; /* as with FileIndex - no need to convert */
2356         FILE_UNIX_BASIC_INFO basic;
2357         char FileName[1];
2358 } __attribute__((packed)) FILE_UNIX_INFO; /* level 0x202 */
2359
2360 typedef struct {
2361         __le32 NextEntryOffset;
2362         __u32 FileIndex;
2363         __le64 CreationTime;
2364         __le64 LastAccessTime;
2365         __le64 LastWriteTime;
2366         __le64 ChangeTime;
2367         __le64 EndOfFile;
2368         __le64 AllocationSize;
2369         __le32 ExtFileAttributes;
2370         __le32 FileNameLength;
2371         char FileName[1];
2372 } __attribute__((packed)) FILE_DIRECTORY_INFO;   /* level 0x101 FF resp data */
2373
2374 typedef struct {
2375         __le32 NextEntryOffset;
2376         __u32 FileIndex;
2377         __le64 CreationTime;
2378         __le64 LastAccessTime;
2379         __le64 LastWriteTime;
2380         __le64 ChangeTime;
2381         __le64 EndOfFile;
2382         __le64 AllocationSize;
2383         __le32 ExtFileAttributes;
2384         __le32 FileNameLength;
2385         __le32 EaSize; /* length of the xattrs */
2386         char FileName[1];
2387 } __attribute__((packed)) FILE_FULL_DIRECTORY_INFO; /* level 0x102 rsp data */
2388
2389 typedef struct {
2390         __le32 NextEntryOffset;
2391         __u32 FileIndex;
2392         __le64 CreationTime;
2393         __le64 LastAccessTime;
2394         __le64 LastWriteTime;
2395         __le64 ChangeTime;
2396         __le64 EndOfFile;
2397         __le64 AllocationSize;
2398         __le32 ExtFileAttributes;
2399         __le32 FileNameLength;
2400         __le32 EaSize; /* EA size */
2401         __le32 Reserved;
2402         __le64 UniqueId; /* inode num - le since Samba puts ino in low 32 bit*/
2403         char FileName[1];
2404 } __attribute__((packed)) SEARCH_ID_FULL_DIR_INFO; /* level 0x105 FF rsp data */
2405
2406 typedef struct {
2407         __le32 NextEntryOffset;
2408         __u32 FileIndex;
2409         __le64 CreationTime;
2410         __le64 LastAccessTime;
2411         __le64 LastWriteTime;
2412         __le64 ChangeTime;
2413         __le64 EndOfFile;
2414         __le64 AllocationSize;
2415         __le32 ExtFileAttributes;
2416         __le32 FileNameLength;
2417         __le32 EaSize; /* length of the xattrs */
2418         __u8   ShortNameLength;
2419         __u8   Reserved;
2420         __u8   ShortName[12];
2421         char FileName[1];
2422 } __attribute__((packed)) FILE_BOTH_DIRECTORY_INFO; /* level 0x104 FFrsp data */
2423
2424 typedef struct {
2425         __u32  ResumeKey;
2426         __le16 CreationDate; /* SMB Date */
2427         __le16 CreationTime; /* SMB Time */
2428         __le16 LastAccessDate;
2429         __le16 LastAccessTime;
2430         __le16 LastWriteDate;
2431         __le16 LastWriteTime;
2432         __le32 DataSize; /* File Size (EOF) */
2433         __le32 AllocationSize;
2434         __le16 Attributes; /* verify not u32 */
2435         __u8   FileNameLength;
2436         char FileName[1];
2437 } __attribute__((packed)) FIND_FILE_STANDARD_INFO; /* level 0x1 FF resp data */
2438
2439
2440 struct win_dev {
2441         unsigned char type[8]; /* IntxCHR or IntxBLK */
2442         __le64 major;
2443         __le64 minor;
2444 } __attribute__((packed));
2445
2446 struct gea {
2447         unsigned char name_len;
2448         char name[1];
2449 } __attribute__((packed));
2450
2451 struct gealist {
2452         unsigned long list_len;
2453         struct gea list[1];
2454 } __attribute__((packed));
2455
2456 struct fea {
2457         unsigned char EA_flags;
2458         __u8 name_len;
2459         __le16 value_len;
2460         char name[1];
2461         /* optionally followed by value */
2462 } __attribute__((packed));
2463 /* flags for _FEA.fEA */
2464 #define FEA_NEEDEA         0x80 /* need EA bit */
2465
2466 struct fealist {
2467         __le32 list_len;
2468         struct fea list[1];
2469 } __attribute__((packed));
2470
2471 /* used to hold an arbitrary blob of data */
2472 struct data_blob {
2473         __u8 *data;
2474         size_t length;
2475         void (*free) (struct data_blob *data_blob);
2476 } __attribute__((packed));
2477
2478
2479 #ifdef CONFIG_CIFS_POSIX
2480 /*
2481         For better POSIX semantics from Linux client, (even better
2482         than the existing CIFS Unix Extensions) we need updated PDUs for:
2483
2484         1) PosixCreateX - to set and return the mode, inode#, device info and
2485         perhaps add a CreateDevice - to create Pipes and other special .inodes
2486         Also note POSIX open flags
2487         2) Close - to return the last write time to do cache across close
2488                 more safely
2489         3) FindFirst return unique inode number - what about resume key, two
2490         forms short (matches readdir) and full (enough info to cache inodes)
2491         4) Mkdir - set mode
2492
2493         And under consideration:
2494         5) FindClose2 (return nanosecond timestamp ??)
2495         6) Use nanosecond timestamps throughout all time fields if
2496            corresponding attribute flag is set
2497         7) sendfile - handle based copy
2498
2499         what about fixing 64 bit alignment
2500
2501         There are also various legacy SMB/CIFS requests used as is
2502
2503         From existing Lanman and NTLM dialects:
2504         --------------------------------------
2505         NEGOTIATE
2506         SESSION_SETUP_ANDX (BB which?)
2507         TREE_CONNECT_ANDX (BB which wct?)
2508         TREE_DISCONNECT (BB add volume timestamp on response)
2509         LOGOFF_ANDX
2510         DELETE (note delete open file behavior)
2511         DELETE_DIRECTORY
2512         READ_AND_X
2513         WRITE_AND_X
2514         LOCKING_AND_X (note posix lock semantics)
2515         RENAME (note rename across dirs and open file rename posix behaviors)
2516         NT_RENAME (for hardlinks) Is this good enough for all features?
2517         FIND_CLOSE2
2518         TRANSACTION2 (18 cases)
2519                 SMB_SET_FILE_END_OF_FILE_INFO2 SMB_SET_PATH_END_OF_FILE_INFO2
2520                 (BB verify that never need to set allocation size)
2521                 SMB_SET_FILE_BASIC_INFO2 (setting times - BB can it be done via
2522                          Unix ext?)
2523
2524         COPY (note support for copy across directories) - FUTURE, OPTIONAL
2525         setting/getting OS/2 EAs - FUTURE (BB can this handle
2526         setting Linux xattrs perfectly)         - OPTIONAL
2527         dnotify                                 - FUTURE, OPTIONAL
2528         quota                                   - FUTURE, OPTIONAL
2529
2530         Note that various requests implemented for NT interop such as
2531                 NT_TRANSACT (IOCTL) QueryReparseInfo
2532         are unneeded to servers compliant with the CIFS POSIX extensions
2533
2534         From CIFS Unix Extensions:
2535         -------------------------
2536         T2 SET_PATH_INFO (SMB_SET_FILE_UNIX_LINK) for symlinks
2537         T2 SET_PATH_INFO (SMB_SET_FILE_BASIC_INFO2)
2538         T2 QUERY_PATH_INFO (SMB_QUERY_FILE_UNIX_LINK)
2539         T2 QUERY_PATH_INFO (SMB_QUERY_FILE_UNIX_BASIC)  BB check for missing
2540                                                         inode fields
2541                                 Actually a need QUERY_FILE_UNIX_INFO
2542                                 since has inode num
2543                                 BB what about a) blksize/blkbits/blocks
2544                                                           b) i_version
2545                                                           c) i_rdev
2546                                                           d) notify mask?
2547                                                           e) generation
2548                                                           f) size_seqcount
2549         T2 FIND_FIRST/FIND_NEXT FIND_FILE_UNIX
2550         TRANS2_GET_DFS_REFERRAL               - OPTIONAL but recommended
2551         T2_QFS_INFO QueryDevice/AttributeInfo - OPTIONAL
2552  */
2553
2554 /* xsymlink is a symlink format (used by MacOS) that can be used
2555    to save symlink info in a regular file when
2556    mounted to operating systems that do not
2557    support the cifs Unix extensions or EAs (for xattr
2558    based symlinks).  For such a file to be recognized
2559    as containing symlink data:
2560
2561    1) file size must be 1067,
2562    2) signature must begin file data,
2563    3) length field must be set to ASCII representation
2564         of a number which is less than or equal to 1024,
2565    4) md5 must match that of the path data */
2566
2567 struct xsymlink {
2568         /* 1067 bytes */
2569         char signature[4]; /* XSym */ /* not null terminated */
2570         char cr0;         /* \n */
2571 /* ASCII representation of length (4 bytes decimal) terminated by \n not null */
2572         char length[4];
2573         char cr1;         /* \n */
2574 /* md5 of valid subset of path ie path[0] through path[length-1] */
2575         __u8 md5[32];
2576         char cr2;        /* \n */
2577 /* if room left, then end with \n then 0x20s by convention but not required */
2578         char path[1024];
2579 } __attribute__((packed));
2580
2581 typedef struct file_xattr_info {
2582         /* BB do we need another field for flags? BB */
2583         __u32 xattr_name_len;
2584         __u32 xattr_value_len;
2585         char  xattr_name[0];
2586         /* followed by xattr_value[xattr_value_len], no pad */
2587 } __attribute__((packed)) FILE_XATTR_INFO; /* extended attribute info
2588                                               level 0x205 */
2589
2590
2591 /* flags for chattr command */
2592 #define EXT_SECURE_DELETE               0x00000001 /* EXT3_SECRM_FL */
2593 #define EXT_ENABLE_UNDELETE             0x00000002 /* EXT3_UNRM_FL */
2594 /* Reserved for compress file 0x4 */
2595 #define EXT_SYNCHRONOUS                 0x00000008 /* EXT3_SYNC_FL */
2596 #define EXT_IMMUTABLE_FL                0x00000010 /* EXT3_IMMUTABLE_FL */
2597 #define EXT_OPEN_APPEND_ONLY            0x00000020 /* EXT3_APPEND_FL */
2598 #define EXT_DO_NOT_BACKUP               0x00000040 /* EXT3_NODUMP_FL */
2599 #define EXT_NO_UPDATE_ATIME             0x00000080 /* EXT3_NOATIME_FL */
2600 /* 0x100 through 0x800 reserved for compression flags and are GET-ONLY */
2601 #define EXT_HASH_TREE_INDEXED_DIR       0x00001000 /* GET-ONLY EXT3_INDEX_FL */
2602 /* 0x2000 reserved for IMAGIC_FL */
2603 #define EXT_JOURNAL_THIS_FILE   0x00004000 /* GET-ONLY EXT3_JOURNAL_DATA_FL */
2604 /* 0x8000 reserved for EXT3_NOTAIL_FL */
2605 #define EXT_SYNCHRONOUS_DIR             0x00010000 /* EXT3_DIRSYNC_FL */
2606 #define EXT_TOPDIR                      0x00020000 /* EXT3_TOPDIR_FL */
2607
2608 #define EXT_SET_MASK                    0x000300FF
2609 #define EXT_GET_MASK                    0x0003DFFF
2610
2611 typedef struct file_chattr_info {
2612         __le64  mask; /* list of all possible attribute bits */
2613         __le64  mode; /* list of actual attribute bits on this inode */
2614 } __attribute__((packed)) FILE_CHATTR_INFO;  /* ext attributes
2615                                                 (chattr, chflags) level 0x206 */
2616 #endif                          /* POSIX */
2617 #endif                          /* _CIFSPDU_H */