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