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