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