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