2 * SMB2 version specific operations
4 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
6 * This library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License v2 as published
8 * by the Free Software Foundation.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/pagemap.h>
21 #include <linux/vfs.h>
22 #include <linux/falloc.h>
23 #include <linux/scatterlist.h>
24 #include <linux/uuid.h>
25 #include <crypto/aead.h>
28 #include "smb2proto.h"
29 #include "cifsproto.h"
30 #include "cifs_debug.h"
31 #include "cifs_unicode.h"
32 #include "smb2status.h"
34 #include "cifs_ioctl.h"
37 change_conf(struct TCP_Server_Info
*server
)
39 server
->credits
+= server
->echo_credits
+ server
->oplock_credits
;
40 server
->oplock_credits
= server
->echo_credits
= 0;
41 switch (server
->credits
) {
45 server
->echoes
= false;
46 server
->oplocks
= false;
47 cifs_dbg(VFS
, "disabling echoes and oplocks\n");
50 server
->echoes
= true;
51 server
->oplocks
= false;
52 server
->echo_credits
= 1;
53 cifs_dbg(FYI
, "disabling oplocks\n");
56 server
->echoes
= true;
58 server
->oplocks
= true;
59 server
->oplock_credits
= 1;
61 server
->oplocks
= false;
63 server
->echo_credits
= 1;
65 server
->credits
-= server
->echo_credits
+ server
->oplock_credits
;
70 smb2_add_credits(struct TCP_Server_Info
*server
, const unsigned int add
,
74 spin_lock(&server
->req_lock
);
75 val
= server
->ops
->get_credits_field(server
, optype
);
78 *val
= 65000; /* Don't get near 64K credits, avoid srv bugs */
79 printk_once(KERN_WARNING
"server overflowed SMB3 credits\n");
82 if (server
->in_flight
== 0 && (optype
& CIFS_OP_MASK
) != CIFS_NEG_OP
)
83 rc
= change_conf(server
);
85 * Sometimes server returns 0 credits on oplock break ack - we need to
86 * rebalance credits in this case.
88 else if (server
->in_flight
> 0 && server
->oplock_credits
== 0 &&
90 if (server
->credits
> 1) {
92 server
->oplock_credits
++;
95 spin_unlock(&server
->req_lock
);
96 wake_up(&server
->request_q
);
98 cifs_reconnect(server
);
102 smb2_set_credits(struct TCP_Server_Info
*server
, const int val
)
104 spin_lock(&server
->req_lock
);
105 server
->credits
= val
;
106 spin_unlock(&server
->req_lock
);
110 smb2_get_credits_field(struct TCP_Server_Info
*server
, const int optype
)
114 return &server
->echo_credits
;
116 return &server
->oplock_credits
;
118 return &server
->credits
;
123 smb2_get_credits(struct mid_q_entry
*mid
)
125 struct smb2_sync_hdr
*shdr
= get_sync_hdr(mid
->resp_buf
);
127 return le16_to_cpu(shdr
->CreditRequest
);
131 smb2_wait_mtu_credits(struct TCP_Server_Info
*server
, unsigned int size
,
132 unsigned int *num
, unsigned int *credits
)
135 unsigned int scredits
;
137 spin_lock(&server
->req_lock
);
139 if (server
->credits
<= 0) {
140 spin_unlock(&server
->req_lock
);
141 cifs_num_waiters_inc(server
);
142 rc
= wait_event_killable(server
->request_q
,
143 has_credits(server
, &server
->credits
));
144 cifs_num_waiters_dec(server
);
147 spin_lock(&server
->req_lock
);
149 if (server
->tcpStatus
== CifsExiting
) {
150 spin_unlock(&server
->req_lock
);
154 scredits
= server
->credits
;
155 /* can deadlock with reopen */
157 *num
= SMB2_MAX_BUFFER_SIZE
;
162 /* leave one credit for a possible reopen */
164 *num
= min_t(unsigned int, size
,
165 scredits
* SMB2_MAX_BUFFER_SIZE
);
167 *credits
= DIV_ROUND_UP(*num
, SMB2_MAX_BUFFER_SIZE
);
168 server
->credits
-= *credits
;
173 spin_unlock(&server
->req_lock
);
178 smb2_get_next_mid(struct TCP_Server_Info
*server
)
181 /* for SMB2 we need the current value */
182 spin_lock(&GlobalMid_Lock
);
183 mid
= server
->CurrentMid
++;
184 spin_unlock(&GlobalMid_Lock
);
188 static struct mid_q_entry
*
189 smb2_find_mid(struct TCP_Server_Info
*server
, char *buf
)
191 struct mid_q_entry
*mid
;
192 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
193 __u64 wire_mid
= le64_to_cpu(shdr
->MessageId
);
195 if (shdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
) {
196 cifs_dbg(VFS
, "encrypted frame parsing not supported yet");
200 spin_lock(&GlobalMid_Lock
);
201 list_for_each_entry(mid
, &server
->pending_mid_q
, qhead
) {
202 if ((mid
->mid
== wire_mid
) &&
203 (mid
->mid_state
== MID_REQUEST_SUBMITTED
) &&
204 (mid
->command
== shdr
->Command
)) {
205 spin_unlock(&GlobalMid_Lock
);
209 spin_unlock(&GlobalMid_Lock
);
214 smb2_dump_detail(void *buf
)
216 #ifdef CONFIG_CIFS_DEBUG2
217 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
219 cifs_dbg(VFS
, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
220 shdr
->Command
, shdr
->Status
, shdr
->Flags
, shdr
->MessageId
,
222 cifs_dbg(VFS
, "smb buf %p len %u\n", buf
, smb2_calc_size(buf
));
227 smb2_need_neg(struct TCP_Server_Info
*server
)
229 return server
->max_read
== 0;
233 smb2_negotiate(const unsigned int xid
, struct cifs_ses
*ses
)
236 ses
->server
->CurrentMid
= 0;
237 rc
= SMB2_negotiate(xid
, ses
);
238 /* BB we probably don't need to retry with modern servers */
245 smb2_negotiate_wsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
247 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
250 /* start with specified wsize, or default */
251 wsize
= volume_info
->wsize
? volume_info
->wsize
: CIFS_DEFAULT_IOSIZE
;
252 wsize
= min_t(unsigned int, wsize
, server
->max_write
);
254 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
255 wsize
= min_t(unsigned int, wsize
, SMB2_MAX_BUFFER_SIZE
);
261 smb2_negotiate_rsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
263 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
266 /* start with specified rsize, or default */
267 rsize
= volume_info
->rsize
? volume_info
->rsize
: CIFS_DEFAULT_IOSIZE
;
268 rsize
= min_t(unsigned int, rsize
, server
->max_read
);
270 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
271 rsize
= min_t(unsigned int, rsize
, SMB2_MAX_BUFFER_SIZE
);
276 #ifdef CONFIG_CIFS_STATS2
278 SMB3_request_interfaces(const unsigned int xid
, struct cifs_tcon
*tcon
)
281 unsigned int ret_data_len
= 0;
282 struct network_interface_info_ioctl_rsp
*out_buf
;
284 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
285 FSCTL_QUERY_NETWORK_INTERFACE_INFO
, true /* is_fsctl */,
287 NULL
/* no data input */, 0 /* no data input */,
288 (char **)&out_buf
, &ret_data_len
);
290 cifs_dbg(VFS
, "error %d on ioctl to get interface list\n", rc
);
291 else if (ret_data_len
< sizeof(struct network_interface_info_ioctl_rsp
)) {
292 cifs_dbg(VFS
, "server returned bad net interface info buf\n");
295 /* Dump info on first interface */
296 cifs_dbg(FYI
, "Adapter Capability 0x%x\t",
297 le32_to_cpu(out_buf
->Capability
));
298 cifs_dbg(FYI
, "Link Speed %lld\n",
299 le64_to_cpu(out_buf
->LinkSpeed
));
307 smb3_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
310 __le16 srch_path
= 0; /* Null - open root of share */
311 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
312 struct cifs_open_parms oparms
;
316 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
317 oparms
.disposition
= FILE_OPEN
;
318 oparms
.create_options
= 0;
320 oparms
.reconnect
= false;
322 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
326 #ifdef CONFIG_CIFS_STATS2
327 SMB3_request_interfaces(xid
, tcon
);
330 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
331 FS_ATTRIBUTE_INFORMATION
);
332 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
333 FS_DEVICE_INFORMATION
);
334 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
335 FS_SECTOR_SIZE_INFORMATION
); /* SMB3 specific */
336 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
341 smb2_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
344 __le16 srch_path
= 0; /* Null - open root of share */
345 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
346 struct cifs_open_parms oparms
;
350 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
351 oparms
.disposition
= FILE_OPEN
;
352 oparms
.create_options
= 0;
354 oparms
.reconnect
= false;
356 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
360 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
361 FS_ATTRIBUTE_INFORMATION
);
362 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
363 FS_DEVICE_INFORMATION
);
364 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
369 smb2_is_path_accessible(const unsigned int xid
, struct cifs_tcon
*tcon
,
370 struct cifs_sb_info
*cifs_sb
, const char *full_path
)
374 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
375 struct cifs_open_parms oparms
;
378 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
383 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
384 oparms
.disposition
= FILE_OPEN
;
385 oparms
.create_options
= 0;
387 oparms
.reconnect
= false;
389 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
395 rc
= SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
401 smb2_get_srv_inum(const unsigned int xid
, struct cifs_tcon
*tcon
,
402 struct cifs_sb_info
*cifs_sb
, const char *full_path
,
403 u64
*uniqueid
, FILE_ALL_INFO
*data
)
405 *uniqueid
= le64_to_cpu(data
->IndexNumber
);
410 smb2_query_file_info(const unsigned int xid
, struct cifs_tcon
*tcon
,
411 struct cifs_fid
*fid
, FILE_ALL_INFO
*data
)
414 struct smb2_file_all_info
*smb2_data
;
416 smb2_data
= kzalloc(sizeof(struct smb2_file_all_info
) + PATH_MAX
* 2,
418 if (smb2_data
== NULL
)
421 rc
= SMB2_query_info(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
,
424 move_smb2_info_to_cifs(data
, smb2_data
);
429 #ifdef CONFIG_CIFS_XATTR
431 move_smb2_ea_to_cifs(char *dst
, size_t dst_size
,
432 struct smb2_file_full_ea_info
*src
, size_t src_size
,
433 const unsigned char *ea_name
)
436 unsigned int ea_name_len
= ea_name
? strlen(ea_name
) : 0;
438 size_t name_len
, value_len
, user_name_len
;
440 while (src_size
> 0) {
441 name
= &src
->ea_data
[0];
442 name_len
= (size_t)src
->ea_name_length
;
443 value
= &src
->ea_data
[src
->ea_name_length
+ 1];
444 value_len
= (size_t)le16_to_cpu(src
->ea_value_length
);
450 if (src_size
< 8 + name_len
+ 1 + value_len
) {
451 cifs_dbg(FYI
, "EA entry goes beyond length of list\n");
457 if (ea_name_len
== name_len
&&
458 memcmp(ea_name
, name
, name_len
) == 0) {
462 if (dst_size
< value_len
) {
466 memcpy(dst
, value
, value_len
);
470 /* 'user.' plus a terminating null */
471 user_name_len
= 5 + 1 + name_len
;
475 if (dst_size
>= user_name_len
) {
476 dst_size
-= user_name_len
;
477 memcpy(dst
, "user.", 5);
479 memcpy(dst
, src
->ea_data
, name_len
);
483 } else if (dst_size
== 0) {
484 /* skip copy - calc size only */
486 /* stop before overrun buffer */
492 if (!src
->next_entry_offset
)
495 if (src_size
< le32_to_cpu(src
->next_entry_offset
)) {
496 /* stop before overrun buffer */
500 src_size
-= le32_to_cpu(src
->next_entry_offset
);
501 src
= (void *)((char *)src
+
502 le32_to_cpu(src
->next_entry_offset
));
505 /* didn't find the named attribute */
514 smb2_query_eas(const unsigned int xid
, struct cifs_tcon
*tcon
,
515 const unsigned char *path
, const unsigned char *ea_name
,
516 char *ea_data
, size_t buf_size
,
517 struct cifs_sb_info
*cifs_sb
)
521 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
522 struct cifs_open_parms oparms
;
524 struct smb2_file_full_ea_info
*smb2_data
;
525 int ea_buf_size
= SMB2_MIN_EA_BUF
;
527 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
532 oparms
.desired_access
= FILE_READ_EA
;
533 oparms
.disposition
= FILE_OPEN
;
534 oparms
.create_options
= 0;
536 oparms
.reconnect
= false;
538 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
541 cifs_dbg(FYI
, "open failed rc=%d\n", rc
);
546 smb2_data
= kzalloc(ea_buf_size
, GFP_KERNEL
);
547 if (smb2_data
== NULL
) {
548 SMB2_close(xid
, tcon
, fid
.persistent_fid
,
553 rc
= SMB2_query_eas(xid
, tcon
, fid
.persistent_fid
,
555 ea_buf_size
, smb2_data
);
563 if (ea_buf_size
> SMB2_MAX_EA_BUF
) {
564 cifs_dbg(VFS
, "EA size is too large\n");
565 SMB2_close(xid
, tcon
, fid
.persistent_fid
,
571 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
574 rc
= move_smb2_ea_to_cifs(ea_data
, buf_size
, smb2_data
,
575 SMB2_MAX_EA_BUF
, ea_name
);
583 smb2_set_ea(const unsigned int xid
, struct cifs_tcon
*tcon
,
584 const char *path
, const char *ea_name
, const void *ea_value
,
585 const __u16 ea_value_len
, const struct nls_table
*nls_codepage
,
586 struct cifs_sb_info
*cifs_sb
)
590 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
591 struct cifs_open_parms oparms
;
593 struct smb2_file_full_ea_info
*ea
;
594 int ea_name_len
= strlen(ea_name
);
597 if (ea_name_len
> 255)
600 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
605 oparms
.desired_access
= FILE_WRITE_EA
;
606 oparms
.disposition
= FILE_OPEN
;
607 oparms
.create_options
= 0;
609 oparms
.reconnect
= false;
611 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
614 cifs_dbg(FYI
, "open failed rc=%d\n", rc
);
618 len
= sizeof(ea
) + ea_name_len
+ ea_value_len
+ 1;
619 ea
= kzalloc(len
, GFP_KERNEL
);
621 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
625 ea
->ea_name_length
= ea_name_len
;
626 ea
->ea_value_length
= cpu_to_le16(ea_value_len
);
627 memcpy(ea
->ea_data
, ea_name
, ea_name_len
+ 1);
628 memcpy(ea
->ea_data
+ ea_name_len
+ 1, ea_value
, ea_value_len
);
630 rc
= SMB2_set_ea(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
, ea
,
632 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
639 smb2_can_echo(struct TCP_Server_Info
*server
)
641 return server
->echoes
;
645 smb2_clear_stats(struct cifs_tcon
*tcon
)
647 #ifdef CONFIG_CIFS_STATS
649 for (i
= 0; i
< NUMBER_OF_SMB2_COMMANDS
; i
++) {
650 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_sent
[i
], 0);
651 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_failed
[i
], 0);
657 smb2_dump_share_caps(struct seq_file
*m
, struct cifs_tcon
*tcon
)
659 seq_puts(m
, "\n\tShare Capabilities:");
660 if (tcon
->capabilities
& SMB2_SHARE_CAP_DFS
)
661 seq_puts(m
, " DFS,");
662 if (tcon
->capabilities
& SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY
)
663 seq_puts(m
, " CONTINUOUS AVAILABILITY,");
664 if (tcon
->capabilities
& SMB2_SHARE_CAP_SCALEOUT
)
665 seq_puts(m
, " SCALEOUT,");
666 if (tcon
->capabilities
& SMB2_SHARE_CAP_CLUSTER
)
667 seq_puts(m
, " CLUSTER,");
668 if (tcon
->capabilities
& SMB2_SHARE_CAP_ASYMMETRIC
)
669 seq_puts(m
, " ASYMMETRIC,");
670 if (tcon
->capabilities
== 0)
671 seq_puts(m
, " None");
672 if (tcon
->ss_flags
& SSINFO_FLAGS_ALIGNED_DEVICE
)
673 seq_puts(m
, " Aligned,");
674 if (tcon
->ss_flags
& SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE
)
675 seq_puts(m
, " Partition Aligned,");
676 if (tcon
->ss_flags
& SSINFO_FLAGS_NO_SEEK_PENALTY
)
677 seq_puts(m
, " SSD,");
678 if (tcon
->ss_flags
& SSINFO_FLAGS_TRIM_ENABLED
)
679 seq_puts(m
, " TRIM-support,");
681 seq_printf(m
, "\tShare Flags: 0x%x", tcon
->share_flags
);
682 if (tcon
->perf_sector_size
)
683 seq_printf(m
, "\tOptimal sector size: 0x%x",
684 tcon
->perf_sector_size
);
688 smb2_print_stats(struct seq_file
*m
, struct cifs_tcon
*tcon
)
690 #ifdef CONFIG_CIFS_STATS
691 atomic_t
*sent
= tcon
->stats
.smb2_stats
.smb2_com_sent
;
692 atomic_t
*failed
= tcon
->stats
.smb2_stats
.smb2_com_failed
;
693 seq_printf(m
, "\nNegotiates: %d sent %d failed",
694 atomic_read(&sent
[SMB2_NEGOTIATE_HE
]),
695 atomic_read(&failed
[SMB2_NEGOTIATE_HE
]));
696 seq_printf(m
, "\nSessionSetups: %d sent %d failed",
697 atomic_read(&sent
[SMB2_SESSION_SETUP_HE
]),
698 atomic_read(&failed
[SMB2_SESSION_SETUP_HE
]));
699 seq_printf(m
, "\nLogoffs: %d sent %d failed",
700 atomic_read(&sent
[SMB2_LOGOFF_HE
]),
701 atomic_read(&failed
[SMB2_LOGOFF_HE
]));
702 seq_printf(m
, "\nTreeConnects: %d sent %d failed",
703 atomic_read(&sent
[SMB2_TREE_CONNECT_HE
]),
704 atomic_read(&failed
[SMB2_TREE_CONNECT_HE
]));
705 seq_printf(m
, "\nTreeDisconnects: %d sent %d failed",
706 atomic_read(&sent
[SMB2_TREE_DISCONNECT_HE
]),
707 atomic_read(&failed
[SMB2_TREE_DISCONNECT_HE
]));
708 seq_printf(m
, "\nCreates: %d sent %d failed",
709 atomic_read(&sent
[SMB2_CREATE_HE
]),
710 atomic_read(&failed
[SMB2_CREATE_HE
]));
711 seq_printf(m
, "\nCloses: %d sent %d failed",
712 atomic_read(&sent
[SMB2_CLOSE_HE
]),
713 atomic_read(&failed
[SMB2_CLOSE_HE
]));
714 seq_printf(m
, "\nFlushes: %d sent %d failed",
715 atomic_read(&sent
[SMB2_FLUSH_HE
]),
716 atomic_read(&failed
[SMB2_FLUSH_HE
]));
717 seq_printf(m
, "\nReads: %d sent %d failed",
718 atomic_read(&sent
[SMB2_READ_HE
]),
719 atomic_read(&failed
[SMB2_READ_HE
]));
720 seq_printf(m
, "\nWrites: %d sent %d failed",
721 atomic_read(&sent
[SMB2_WRITE_HE
]),
722 atomic_read(&failed
[SMB2_WRITE_HE
]));
723 seq_printf(m
, "\nLocks: %d sent %d failed",
724 atomic_read(&sent
[SMB2_LOCK_HE
]),
725 atomic_read(&failed
[SMB2_LOCK_HE
]));
726 seq_printf(m
, "\nIOCTLs: %d sent %d failed",
727 atomic_read(&sent
[SMB2_IOCTL_HE
]),
728 atomic_read(&failed
[SMB2_IOCTL_HE
]));
729 seq_printf(m
, "\nCancels: %d sent %d failed",
730 atomic_read(&sent
[SMB2_CANCEL_HE
]),
731 atomic_read(&failed
[SMB2_CANCEL_HE
]));
732 seq_printf(m
, "\nEchos: %d sent %d failed",
733 atomic_read(&sent
[SMB2_ECHO_HE
]),
734 atomic_read(&failed
[SMB2_ECHO_HE
]));
735 seq_printf(m
, "\nQueryDirectories: %d sent %d failed",
736 atomic_read(&sent
[SMB2_QUERY_DIRECTORY_HE
]),
737 atomic_read(&failed
[SMB2_QUERY_DIRECTORY_HE
]));
738 seq_printf(m
, "\nChangeNotifies: %d sent %d failed",
739 atomic_read(&sent
[SMB2_CHANGE_NOTIFY_HE
]),
740 atomic_read(&failed
[SMB2_CHANGE_NOTIFY_HE
]));
741 seq_printf(m
, "\nQueryInfos: %d sent %d failed",
742 atomic_read(&sent
[SMB2_QUERY_INFO_HE
]),
743 atomic_read(&failed
[SMB2_QUERY_INFO_HE
]));
744 seq_printf(m
, "\nSetInfos: %d sent %d failed",
745 atomic_read(&sent
[SMB2_SET_INFO_HE
]),
746 atomic_read(&failed
[SMB2_SET_INFO_HE
]));
747 seq_printf(m
, "\nOplockBreaks: %d sent %d failed",
748 atomic_read(&sent
[SMB2_OPLOCK_BREAK_HE
]),
749 atomic_read(&failed
[SMB2_OPLOCK_BREAK_HE
]));
754 smb2_set_fid(struct cifsFileInfo
*cfile
, struct cifs_fid
*fid
, __u32 oplock
)
756 struct cifsInodeInfo
*cinode
= CIFS_I(d_inode(cfile
->dentry
));
757 struct TCP_Server_Info
*server
= tlink_tcon(cfile
->tlink
)->ses
->server
;
759 cfile
->fid
.persistent_fid
= fid
->persistent_fid
;
760 cfile
->fid
.volatile_fid
= fid
->volatile_fid
;
761 server
->ops
->set_oplock_level(cinode
, oplock
, fid
->epoch
,
763 cinode
->can_cache_brlcks
= CIFS_CACHE_WRITE(cinode
);
764 memcpy(cfile
->fid
.create_guid
, fid
->create_guid
, 16);
768 smb2_close_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
769 struct cifs_fid
*fid
)
771 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
775 SMB2_request_res_key(const unsigned int xid
, struct cifs_tcon
*tcon
,
776 u64 persistent_fid
, u64 volatile_fid
,
777 struct copychunk_ioctl
*pcchunk
)
780 unsigned int ret_data_len
;
781 struct resume_key_req
*res_key
;
783 rc
= SMB2_ioctl(xid
, tcon
, persistent_fid
, volatile_fid
,
784 FSCTL_SRV_REQUEST_RESUME_KEY
, true /* is_fsctl */,
786 NULL
, 0 /* no input */,
787 (char **)&res_key
, &ret_data_len
);
790 cifs_dbg(VFS
, "refcpy ioctl error %d getting resume key\n", rc
);
791 goto req_res_key_exit
;
793 if (ret_data_len
< sizeof(struct resume_key_req
)) {
794 cifs_dbg(VFS
, "Invalid refcopy resume key length\n");
796 goto req_res_key_exit
;
798 memcpy(pcchunk
->SourceKey
, res_key
->ResumeKey
, COPY_CHUNK_RES_KEY_SIZE
);
806 smb2_copychunk_range(const unsigned int xid
,
807 struct cifsFileInfo
*srcfile
,
808 struct cifsFileInfo
*trgtfile
, u64 src_off
,
809 u64 len
, u64 dest_off
)
812 unsigned int ret_data_len
;
813 struct copychunk_ioctl
*pcchunk
;
814 struct copychunk_ioctl_rsp
*retbuf
= NULL
;
815 struct cifs_tcon
*tcon
;
816 int chunks_copied
= 0;
817 bool chunk_sizes_updated
= false;
818 ssize_t bytes_written
, total_bytes_written
= 0;
820 pcchunk
= kmalloc(sizeof(struct copychunk_ioctl
), GFP_KERNEL
);
825 cifs_dbg(FYI
, "in smb2_copychunk_range - about to call request res key\n");
826 /* Request a key from the server to identify the source of the copy */
827 rc
= SMB2_request_res_key(xid
, tlink_tcon(srcfile
->tlink
),
828 srcfile
->fid
.persistent_fid
,
829 srcfile
->fid
.volatile_fid
, pcchunk
);
831 /* Note: request_res_key sets res_key null only if rc !=0 */
835 /* For now array only one chunk long, will make more flexible later */
836 pcchunk
->ChunkCount
= cpu_to_le32(1);
837 pcchunk
->Reserved
= 0;
838 pcchunk
->Reserved2
= 0;
840 tcon
= tlink_tcon(trgtfile
->tlink
);
843 pcchunk
->SourceOffset
= cpu_to_le64(src_off
);
844 pcchunk
->TargetOffset
= cpu_to_le64(dest_off
);
846 cpu_to_le32(min_t(u32
, len
, tcon
->max_bytes_chunk
));
848 /* Request server copy to target from src identified by key */
849 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
850 trgtfile
->fid
.volatile_fid
, FSCTL_SRV_COPYCHUNK_WRITE
,
851 true /* is_fsctl */, false /* use_ipc */,
853 sizeof(struct copychunk_ioctl
), (char **)&retbuf
,
857 sizeof(struct copychunk_ioctl_rsp
)) {
858 cifs_dbg(VFS
, "invalid cchunk response size\n");
862 if (retbuf
->TotalBytesWritten
== 0) {
863 cifs_dbg(FYI
, "no bytes copied\n");
868 * Check if server claimed to write more than we asked
870 if (le32_to_cpu(retbuf
->TotalBytesWritten
) >
871 le32_to_cpu(pcchunk
->Length
)) {
872 cifs_dbg(VFS
, "invalid copy chunk response\n");
876 if (le32_to_cpu(retbuf
->ChunksWritten
) != 1) {
877 cifs_dbg(VFS
, "invalid num chunks written\n");
883 bytes_written
= le32_to_cpu(retbuf
->TotalBytesWritten
);
884 src_off
+= bytes_written
;
885 dest_off
+= bytes_written
;
886 len
-= bytes_written
;
887 total_bytes_written
+= bytes_written
;
889 cifs_dbg(FYI
, "Chunks %d PartialChunk %d Total %zu\n",
890 le32_to_cpu(retbuf
->ChunksWritten
),
891 le32_to_cpu(retbuf
->ChunkBytesWritten
),
893 } else if (rc
== -EINVAL
) {
894 if (ret_data_len
!= sizeof(struct copychunk_ioctl_rsp
))
897 cifs_dbg(FYI
, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
898 le32_to_cpu(retbuf
->ChunksWritten
),
899 le32_to_cpu(retbuf
->ChunkBytesWritten
),
900 le32_to_cpu(retbuf
->TotalBytesWritten
));
903 * Check if this is the first request using these sizes,
904 * (ie check if copy succeed once with original sizes
905 * and check if the server gave us different sizes after
906 * we already updated max sizes on previous request).
907 * if not then why is the server returning an error now
909 if ((chunks_copied
!= 0) || chunk_sizes_updated
)
912 /* Check that server is not asking us to grow size */
913 if (le32_to_cpu(retbuf
->ChunkBytesWritten
) <
914 tcon
->max_bytes_chunk
)
915 tcon
->max_bytes_chunk
=
916 le32_to_cpu(retbuf
->ChunkBytesWritten
);
918 goto cchunk_out
; /* server gave us bogus size */
920 /* No need to change MaxChunks since already set to 1 */
921 chunk_sizes_updated
= true;
932 return total_bytes_written
;
936 smb2_flush_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
937 struct cifs_fid
*fid
)
939 return SMB2_flush(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
943 smb2_read_data_offset(char *buf
)
945 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
946 return rsp
->DataOffset
;
950 smb2_read_data_length(char *buf
)
952 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
953 return le32_to_cpu(rsp
->DataLength
);
958 smb2_sync_read(const unsigned int xid
, struct cifs_fid
*pfid
,
959 struct cifs_io_parms
*parms
, unsigned int *bytes_read
,
960 char **buf
, int *buf_type
)
962 parms
->persistent_fid
= pfid
->persistent_fid
;
963 parms
->volatile_fid
= pfid
->volatile_fid
;
964 return SMB2_read(xid
, parms
, bytes_read
, buf
, buf_type
);
968 smb2_sync_write(const unsigned int xid
, struct cifs_fid
*pfid
,
969 struct cifs_io_parms
*parms
, unsigned int *written
,
970 struct kvec
*iov
, unsigned long nr_segs
)
973 parms
->persistent_fid
= pfid
->persistent_fid
;
974 parms
->volatile_fid
= pfid
->volatile_fid
;
975 return SMB2_write(xid
, parms
, written
, iov
, nr_segs
);
978 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
979 static bool smb2_set_sparse(const unsigned int xid
, struct cifs_tcon
*tcon
,
980 struct cifsFileInfo
*cfile
, struct inode
*inode
, __u8 setsparse
)
982 struct cifsInodeInfo
*cifsi
;
985 cifsi
= CIFS_I(inode
);
987 /* if file already sparse don't bother setting sparse again */
988 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && setsparse
)
989 return true; /* already sparse */
991 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && !setsparse
)
992 return true; /* already not sparse */
995 * Can't check for sparse support on share the usual way via the
996 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
997 * since Samba server doesn't set the flag on the share, yet
998 * supports the set sparse FSCTL and returns sparse correctly
999 * in the file attributes. If we fail setting sparse though we
1000 * mark that server does not support sparse files for this share
1001 * to avoid repeatedly sending the unsupported fsctl to server
1002 * if the file is repeatedly extended.
1004 if (tcon
->broken_sparse_sup
)
1007 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1008 cfile
->fid
.volatile_fid
, FSCTL_SET_SPARSE
,
1009 true /* is_fctl */, false /* use_ipc */,
1010 &setsparse
, 1, NULL
, NULL
);
1012 tcon
->broken_sparse_sup
= true;
1013 cifs_dbg(FYI
, "set sparse rc = %d\n", rc
);
1018 cifsi
->cifsAttrs
|= FILE_ATTRIBUTE_SPARSE_FILE
;
1020 cifsi
->cifsAttrs
&= (~FILE_ATTRIBUTE_SPARSE_FILE
);
1026 smb2_set_file_size(const unsigned int xid
, struct cifs_tcon
*tcon
,
1027 struct cifsFileInfo
*cfile
, __u64 size
, bool set_alloc
)
1029 __le64 eof
= cpu_to_le64(size
);
1030 struct inode
*inode
;
1033 * If extending file more than one page make sparse. Many Linux fs
1034 * make files sparse by default when extending via ftruncate
1036 inode
= d_inode(cfile
->dentry
);
1038 if (!set_alloc
&& (size
> inode
->i_size
+ 8192)) {
1039 __u8 set_sparse
= 1;
1041 /* whether set sparse succeeds or not, extend the file */
1042 smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
);
1045 return SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
1046 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
, false);
1050 smb2_duplicate_extents(const unsigned int xid
,
1051 struct cifsFileInfo
*srcfile
,
1052 struct cifsFileInfo
*trgtfile
, u64 src_off
,
1053 u64 len
, u64 dest_off
)
1056 unsigned int ret_data_len
;
1057 struct duplicate_extents_to_file dup_ext_buf
;
1058 struct cifs_tcon
*tcon
= tlink_tcon(trgtfile
->tlink
);
1060 /* server fileays advertise duplicate extent support with this flag */
1061 if ((le32_to_cpu(tcon
->fsAttrInfo
.Attributes
) &
1062 FILE_SUPPORTS_BLOCK_REFCOUNTING
) == 0)
1065 dup_ext_buf
.VolatileFileHandle
= srcfile
->fid
.volatile_fid
;
1066 dup_ext_buf
.PersistentFileHandle
= srcfile
->fid
.persistent_fid
;
1067 dup_ext_buf
.SourceFileOffset
= cpu_to_le64(src_off
);
1068 dup_ext_buf
.TargetFileOffset
= cpu_to_le64(dest_off
);
1069 dup_ext_buf
.ByteCount
= cpu_to_le64(len
);
1070 cifs_dbg(FYI
, "duplicate extents: src off %lld dst off %lld len %lld",
1071 src_off
, dest_off
, len
);
1073 rc
= smb2_set_file_size(xid
, tcon
, trgtfile
, dest_off
+ len
, false);
1075 goto duplicate_extents_out
;
1077 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
1078 trgtfile
->fid
.volatile_fid
,
1079 FSCTL_DUPLICATE_EXTENTS_TO_FILE
,
1080 true /* is_fsctl */, false /* use_ipc */,
1081 (char *)&dup_ext_buf
,
1082 sizeof(struct duplicate_extents_to_file
),
1086 if (ret_data_len
> 0)
1087 cifs_dbg(FYI
, "non-zero response length in duplicate extents");
1089 duplicate_extents_out
:
1094 smb2_set_compression(const unsigned int xid
, struct cifs_tcon
*tcon
,
1095 struct cifsFileInfo
*cfile
)
1097 return SMB2_set_compression(xid
, tcon
, cfile
->fid
.persistent_fid
,
1098 cfile
->fid
.volatile_fid
);
1102 smb3_set_integrity(const unsigned int xid
, struct cifs_tcon
*tcon
,
1103 struct cifsFileInfo
*cfile
)
1105 struct fsctl_set_integrity_information_req integr_info
;
1106 unsigned int ret_data_len
;
1108 integr_info
.ChecksumAlgorithm
= cpu_to_le16(CHECKSUM_TYPE_UNCHANGED
);
1109 integr_info
.Flags
= 0;
1110 integr_info
.Reserved
= 0;
1112 return SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1113 cfile
->fid
.volatile_fid
,
1114 FSCTL_SET_INTEGRITY_INFORMATION
,
1115 true /* is_fsctl */, false /* use_ipc */,
1116 (char *)&integr_info
,
1117 sizeof(struct fsctl_set_integrity_information_req
),
1124 smb3_enum_snapshots(const unsigned int xid
, struct cifs_tcon
*tcon
,
1125 struct cifsFileInfo
*cfile
, void __user
*ioc_buf
)
1127 char *retbuf
= NULL
;
1128 unsigned int ret_data_len
= 0;
1130 struct smb_snapshot_array snapshot_in
;
1132 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1133 cfile
->fid
.volatile_fid
,
1134 FSCTL_SRV_ENUMERATE_SNAPSHOTS
,
1135 true /* is_fsctl */, false /* use_ipc */,
1136 NULL
, 0 /* no input data */,
1139 cifs_dbg(FYI
, "enum snaphots ioctl returned %d and ret buflen is %d\n",
1144 if (ret_data_len
&& (ioc_buf
!= NULL
) && (retbuf
!= NULL
)) {
1146 if (copy_from_user(&snapshot_in
, ioc_buf
,
1147 sizeof(struct smb_snapshot_array
))) {
1152 if (snapshot_in
.snapshot_array_size
< sizeof(struct smb_snapshot_array
)) {
1158 if (ret_data_len
> snapshot_in
.snapshot_array_size
)
1159 ret_data_len
= snapshot_in
.snapshot_array_size
;
1161 if (copy_to_user(ioc_buf
, retbuf
, ret_data_len
))
1170 smb2_query_dir_first(const unsigned int xid
, struct cifs_tcon
*tcon
,
1171 const char *path
, struct cifs_sb_info
*cifs_sb
,
1172 struct cifs_fid
*fid
, __u16 search_flags
,
1173 struct cifs_search_info
*srch_inf
)
1177 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1178 struct cifs_open_parms oparms
;
1180 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
1185 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| FILE_READ_DATA
;
1186 oparms
.disposition
= FILE_OPEN
;
1187 oparms
.create_options
= 0;
1189 oparms
.reconnect
= false;
1191 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
1194 cifs_dbg(FYI
, "open dir failed rc=%d\n", rc
);
1198 srch_inf
->entries_in_buffer
= 0;
1199 srch_inf
->index_of_last_entry
= 0;
1201 rc
= SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
1202 fid
->volatile_fid
, 0, srch_inf
);
1204 cifs_dbg(FYI
, "query directory failed rc=%d\n", rc
);
1205 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1211 smb2_query_dir_next(const unsigned int xid
, struct cifs_tcon
*tcon
,
1212 struct cifs_fid
*fid
, __u16 search_flags
,
1213 struct cifs_search_info
*srch_inf
)
1215 return SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
1216 fid
->volatile_fid
, 0, srch_inf
);
1220 smb2_close_dir(const unsigned int xid
, struct cifs_tcon
*tcon
,
1221 struct cifs_fid
*fid
)
1223 return SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1227 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
1228 * the number of credits and return true. Otherwise - return false.
1231 smb2_is_status_pending(char *buf
, struct TCP_Server_Info
*server
, int length
)
1233 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
1235 if (shdr
->Status
!= STATUS_PENDING
)
1239 spin_lock(&server
->req_lock
);
1240 server
->credits
+= le16_to_cpu(shdr
->CreditRequest
);
1241 spin_unlock(&server
->req_lock
);
1242 wake_up(&server
->request_q
);
1249 smb2_is_session_expired(char *buf
)
1251 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
1253 if (shdr
->Status
!= STATUS_NETWORK_SESSION_EXPIRED
)
1256 cifs_dbg(FYI
, "Session expired\n");
1261 smb2_oplock_response(struct cifs_tcon
*tcon
, struct cifs_fid
*fid
,
1262 struct cifsInodeInfo
*cinode
)
1264 if (tcon
->ses
->server
->capabilities
& SMB2_GLOBAL_CAP_LEASING
)
1265 return SMB2_lease_break(0, tcon
, cinode
->lease_key
,
1266 smb2_get_lease_state(cinode
));
1268 return SMB2_oplock_break(0, tcon
, fid
->persistent_fid
,
1270 CIFS_CACHE_READ(cinode
) ? 1 : 0);
1274 smb2_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
1275 struct kstatfs
*buf
)
1278 __le16 srch_path
= 0; /* Null - open root of share */
1279 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1280 struct cifs_open_parms oparms
;
1281 struct cifs_fid fid
;
1284 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
1285 oparms
.disposition
= FILE_OPEN
;
1286 oparms
.create_options
= 0;
1288 oparms
.reconnect
= false;
1290 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
1293 buf
->f_type
= SMB2_MAGIC_NUMBER
;
1294 rc
= SMB2_QFS_info(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
1296 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
1301 smb2_compare_fids(struct cifsFileInfo
*ob1
, struct cifsFileInfo
*ob2
)
1303 return ob1
->fid
.persistent_fid
== ob2
->fid
.persistent_fid
&&
1304 ob1
->fid
.volatile_fid
== ob2
->fid
.volatile_fid
;
1308 smb2_mand_lock(const unsigned int xid
, struct cifsFileInfo
*cfile
, __u64 offset
,
1309 __u64 length
, __u32 type
, int lock
, int unlock
, bool wait
)
1311 if (unlock
&& !lock
)
1312 type
= SMB2_LOCKFLAG_UNLOCK
;
1313 return SMB2_lock(xid
, tlink_tcon(cfile
->tlink
),
1314 cfile
->fid
.persistent_fid
, cfile
->fid
.volatile_fid
,
1315 current
->tgid
, length
, offset
, type
, wait
);
1319 smb2_get_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
1321 memcpy(fid
->lease_key
, CIFS_I(inode
)->lease_key
, SMB2_LEASE_KEY_SIZE
);
1325 smb2_set_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
1327 memcpy(CIFS_I(inode
)->lease_key
, fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
1331 smb2_new_lease_key(struct cifs_fid
*fid
)
1333 generate_random_uuid(fid
->lease_key
);
1337 smb2_get_dfs_refer(const unsigned int xid
, struct cifs_ses
*ses
,
1338 const char *search_name
,
1339 struct dfs_info3_param
**target_nodes
,
1340 unsigned int *num_of_nodes
,
1341 const struct nls_table
*nls_codepage
, int remap
)
1344 __le16
*utf16_path
= NULL
;
1345 int utf16_path_len
= 0;
1346 struct cifs_tcon
*tcon
;
1347 struct fsctl_get_dfs_referral_req
*dfs_req
= NULL
;
1348 struct get_dfs_referral_rsp
*dfs_rsp
= NULL
;
1349 u32 dfs_req_size
= 0, dfs_rsp_size
= 0;
1351 cifs_dbg(FYI
, "smb2_get_dfs_refer path <%s>\n", search_name
);
1354 * Use any tcon from the current session. Here, the first one.
1356 spin_lock(&cifs_tcp_ses_lock
);
1357 tcon
= list_first_entry_or_null(&ses
->tcon_list
, struct cifs_tcon
,
1361 spin_unlock(&cifs_tcp_ses_lock
);
1364 cifs_dbg(VFS
, "session %p has no tcon available for a dfs referral request\n",
1370 utf16_path
= cifs_strndup_to_utf16(search_name
, PATH_MAX
,
1372 nls_codepage
, remap
);
1378 dfs_req_size
= sizeof(*dfs_req
) + utf16_path_len
;
1379 dfs_req
= kzalloc(dfs_req_size
, GFP_KERNEL
);
1385 /* Highest DFS referral version understood */
1386 dfs_req
->MaxReferralLevel
= DFS_VERSION
;
1388 /* Path to resolve in an UTF-16 null-terminated string */
1389 memcpy(dfs_req
->RequestFileName
, utf16_path
, utf16_path_len
);
1392 /* try first with IPC */
1393 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
1394 FSCTL_DFS_GET_REFERRALS
,
1395 true /* is_fsctl */, true /* use_ipc */,
1396 (char *)dfs_req
, dfs_req_size
,
1397 (char **)&dfs_rsp
, &dfs_rsp_size
);
1398 if (rc
== -ENOTCONN
) {
1399 /* try with normal tcon */
1400 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
1401 FSCTL_DFS_GET_REFERRALS
,
1402 true /* is_fsctl */, false /*use_ipc*/,
1403 (char *)dfs_req
, dfs_req_size
,
1404 (char **)&dfs_rsp
, &dfs_rsp_size
);
1406 } while (rc
== -EAGAIN
);
1409 cifs_dbg(VFS
, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc
);
1413 rc
= parse_dfs_referrals(dfs_rsp
, dfs_rsp_size
,
1414 num_of_nodes
, target_nodes
,
1415 nls_codepage
, remap
, search_name
,
1416 true /* is_unicode */);
1418 cifs_dbg(VFS
, "parse error in smb2_get_dfs_refer rc=%d\n", rc
);
1424 spin_lock(&cifs_tcp_ses_lock
);
1426 spin_unlock(&cifs_tcp_ses_lock
);
1433 #define SMB2_SYMLINK_STRUCT_SIZE \
1434 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
1437 smb2_query_symlink(const unsigned int xid
, struct cifs_tcon
*tcon
,
1438 const char *full_path
, char **target_path
,
1439 struct cifs_sb_info
*cifs_sb
)
1443 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1444 struct cifs_open_parms oparms
;
1445 struct cifs_fid fid
;
1446 struct smb2_err_rsp
*err_buf
= NULL
;
1447 struct smb2_symlink_err_rsp
*symlink
;
1448 unsigned int sub_len
;
1449 unsigned int sub_offset
;
1450 unsigned int print_len
;
1451 unsigned int print_offset
;
1453 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, full_path
);
1455 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
1460 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
1461 oparms
.disposition
= FILE_OPEN
;
1462 oparms
.create_options
= 0;
1464 oparms
.reconnect
= false;
1466 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, &err_buf
);
1468 if (!rc
|| !err_buf
) {
1473 if (le32_to_cpu(err_buf
->ByteCount
) < sizeof(struct smb2_symlink_err_rsp
) ||
1474 get_rfc1002_length(err_buf
) + 4 < SMB2_SYMLINK_STRUCT_SIZE
) {
1479 /* open must fail on symlink - reset rc */
1481 symlink
= (struct smb2_symlink_err_rsp
*)err_buf
->ErrorData
;
1482 sub_len
= le16_to_cpu(symlink
->SubstituteNameLength
);
1483 sub_offset
= le16_to_cpu(symlink
->SubstituteNameOffset
);
1484 print_len
= le16_to_cpu(symlink
->PrintNameLength
);
1485 print_offset
= le16_to_cpu(symlink
->PrintNameOffset
);
1487 if (get_rfc1002_length(err_buf
) + 4 <
1488 SMB2_SYMLINK_STRUCT_SIZE
+ sub_offset
+ sub_len
) {
1493 if (get_rfc1002_length(err_buf
) + 4 <
1494 SMB2_SYMLINK_STRUCT_SIZE
+ print_offset
+ print_len
) {
1499 *target_path
= cifs_strndup_from_utf16(
1500 (char *)symlink
->PathBuffer
+ sub_offset
,
1501 sub_len
, true, cifs_sb
->local_nls
);
1502 if (!(*target_path
)) {
1506 convert_delimiter(*target_path
, '/');
1507 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
1512 #ifdef CONFIG_CIFS_ACL
1513 static struct cifs_ntsd
*
1514 get_smb2_acl_by_fid(struct cifs_sb_info
*cifs_sb
,
1515 const struct cifs_fid
*cifsfid
, u32
*pacllen
)
1517 struct cifs_ntsd
*pntsd
= NULL
;
1519 int rc
= -EOPNOTSUPP
;
1520 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
1523 return ERR_CAST(tlink
);
1526 cifs_dbg(FYI
, "trying to get acl\n");
1528 rc
= SMB2_query_acl(xid
, tlink_tcon(tlink
), cifsfid
->persistent_fid
,
1529 cifsfid
->volatile_fid
, (void **)&pntsd
, pacllen
);
1532 cifs_put_tlink(tlink
);
1534 cifs_dbg(FYI
, "%s: rc = %d ACL len %d\n", __func__
, rc
, *pacllen
);
1541 static struct cifs_ntsd
*
1542 get_smb2_acl_by_path(struct cifs_sb_info
*cifs_sb
,
1543 const char *path
, u32
*pacllen
)
1545 struct cifs_ntsd
*pntsd
= NULL
;
1546 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1549 struct cifs_tcon
*tcon
;
1550 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
1551 struct cifs_fid fid
;
1552 struct cifs_open_parms oparms
;
1555 cifs_dbg(FYI
, "get smb3 acl for path %s\n", path
);
1557 return ERR_CAST(tlink
);
1559 tcon
= tlink_tcon(tlink
);
1562 if (backup_cred(cifs_sb
))
1563 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
1565 oparms
.create_options
= 0;
1567 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
1569 return ERR_PTR(-ENOMEM
);
1572 oparms
.desired_access
= READ_CONTROL
;
1573 oparms
.disposition
= FILE_OPEN
;
1575 oparms
.reconnect
= false;
1577 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
1580 rc
= SMB2_query_acl(xid
, tlink_tcon(tlink
), fid
.persistent_fid
,
1581 fid
.volatile_fid
, (void **)&pntsd
, pacllen
);
1582 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
1585 cifs_put_tlink(tlink
);
1588 cifs_dbg(FYI
, "%s: rc = %d ACL len %d\n", __func__
, rc
, *pacllen
);
1594 #ifdef CONFIG_CIFS_ACL
1596 set_smb2_acl(struct cifs_ntsd
*pnntsd
, __u32 acllen
,
1597 struct inode
*inode
, const char *path
, int aclflag
)
1599 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1601 int rc
, access_flags
= 0;
1602 struct cifs_tcon
*tcon
;
1603 struct cifs_sb_info
*cifs_sb
= CIFS_SB(inode
->i_sb
);
1604 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
1605 struct cifs_fid fid
;
1606 struct cifs_open_parms oparms
;
1609 cifs_dbg(FYI
, "set smb3 acl for path %s\n", path
);
1611 return PTR_ERR(tlink
);
1613 tcon
= tlink_tcon(tlink
);
1616 if (backup_cred(cifs_sb
))
1617 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
1619 oparms
.create_options
= 0;
1621 if (aclflag
== CIFS_ACL_OWNER
|| aclflag
== CIFS_ACL_GROUP
)
1622 access_flags
= WRITE_OWNER
;
1624 access_flags
= WRITE_DAC
;
1626 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
1631 oparms
.desired_access
= access_flags
;
1632 oparms
.disposition
= FILE_OPEN
;
1635 oparms
.reconnect
= false;
1637 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
1640 rc
= SMB2_set_acl(xid
, tlink_tcon(tlink
), fid
.persistent_fid
,
1641 fid
.volatile_fid
, pnntsd
, acllen
, aclflag
);
1642 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
1645 cifs_put_tlink(tlink
);
1649 #endif /* CIFS_ACL */
1651 /* Retrieve an ACL from the server */
1652 static struct cifs_ntsd
*
1653 get_smb2_acl(struct cifs_sb_info
*cifs_sb
,
1654 struct inode
*inode
, const char *path
,
1657 struct cifs_ntsd
*pntsd
= NULL
;
1658 struct cifsFileInfo
*open_file
= NULL
;
1661 open_file
= find_readable_file(CIFS_I(inode
), true);
1663 return get_smb2_acl_by_path(cifs_sb
, path
, pacllen
);
1665 pntsd
= get_smb2_acl_by_fid(cifs_sb
, &open_file
->fid
, pacllen
);
1666 cifsFileInfo_put(open_file
);
1671 static long smb3_zero_range(struct file
*file
, struct cifs_tcon
*tcon
,
1672 loff_t offset
, loff_t len
, bool keep_size
)
1674 struct inode
*inode
;
1675 struct cifsInodeInfo
*cifsi
;
1676 struct cifsFileInfo
*cfile
= file
->private_data
;
1677 struct file_zero_data_information fsctl_buf
;
1683 inode
= d_inode(cfile
->dentry
);
1684 cifsi
= CIFS_I(inode
);
1686 /* if file not oplocked can't be sure whether asking to extend size */
1687 if (!CIFS_CACHE_READ(cifsi
))
1688 if (keep_size
== false)
1692 * Must check if file sparse since fallocate -z (zero range) assumes
1693 * non-sparse allocation
1695 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
))
1699 * need to make sure we are not asked to extend the file since the SMB3
1700 * fsctl does not change the file size. In the future we could change
1701 * this to zero the first part of the range then set the file size
1702 * which for a non sparse file would zero the newly extended range
1704 if (keep_size
== false)
1705 if (i_size_read(inode
) < offset
+ len
)
1708 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1710 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1711 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1713 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1714 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1715 true /* is_fctl */, false /* use_ipc */,
1717 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1722 static long smb3_punch_hole(struct file
*file
, struct cifs_tcon
*tcon
,
1723 loff_t offset
, loff_t len
)
1725 struct inode
*inode
;
1726 struct cifsInodeInfo
*cifsi
;
1727 struct cifsFileInfo
*cfile
= file
->private_data
;
1728 struct file_zero_data_information fsctl_buf
;
1731 __u8 set_sparse
= 1;
1735 inode
= d_inode(cfile
->dentry
);
1736 cifsi
= CIFS_I(inode
);
1738 /* Need to make file sparse, if not already, before freeing range. */
1739 /* Consider adding equivalent for compressed since it could also work */
1740 if (!smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
))
1743 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1745 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1746 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1748 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1749 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1750 true /* is_fctl */, false /* use_ipc */,
1752 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1757 static long smb3_simple_falloc(struct file
*file
, struct cifs_tcon
*tcon
,
1758 loff_t off
, loff_t len
, bool keep_size
)
1760 struct inode
*inode
;
1761 struct cifsInodeInfo
*cifsi
;
1762 struct cifsFileInfo
*cfile
= file
->private_data
;
1763 long rc
= -EOPNOTSUPP
;
1768 inode
= d_inode(cfile
->dentry
);
1769 cifsi
= CIFS_I(inode
);
1771 /* if file not oplocked can't be sure whether asking to extend size */
1772 if (!CIFS_CACHE_READ(cifsi
))
1773 if (keep_size
== false)
1777 * Files are non-sparse by default so falloc may be a no-op
1778 * Must check if file sparse. If not sparse, and not extending
1779 * then no need to do anything since file already allocated
1781 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) == 0) {
1782 if (keep_size
== true)
1784 /* check if extending file */
1785 else if (i_size_read(inode
) >= off
+ len
)
1786 /* not extending file and already not sparse */
1788 /* BB: in future add else clause to extend file */
1793 if ((keep_size
== true) || (i_size_read(inode
) >= off
+ len
)) {
1795 * Check if falloc starts within first few pages of file
1796 * and ends within a few pages of the end of file to
1797 * ensure that most of file is being forced to be
1798 * fallocated now. If so then setting whole file sparse
1799 * ie potentially making a few extra pages at the beginning
1800 * or end of the file non-sparse via set_sparse is harmless.
1802 if ((off
> 8192) || (off
+ len
+ 8192 < i_size_read(inode
)))
1805 rc
= smb2_set_sparse(xid
, tcon
, cfile
, inode
, false);
1807 /* BB: else ... in future add code to extend file and set sparse */
1815 static long smb3_fallocate(struct file
*file
, struct cifs_tcon
*tcon
, int mode
,
1816 loff_t off
, loff_t len
)
1818 /* KEEP_SIZE already checked for by do_fallocate */
1819 if (mode
& FALLOC_FL_PUNCH_HOLE
)
1820 return smb3_punch_hole(file
, tcon
, off
, len
);
1821 else if (mode
& FALLOC_FL_ZERO_RANGE
) {
1822 if (mode
& FALLOC_FL_KEEP_SIZE
)
1823 return smb3_zero_range(file
, tcon
, off
, len
, true);
1824 return smb3_zero_range(file
, tcon
, off
, len
, false);
1825 } else if (mode
== FALLOC_FL_KEEP_SIZE
)
1826 return smb3_simple_falloc(file
, tcon
, off
, len
, true);
1828 return smb3_simple_falloc(file
, tcon
, off
, len
, false);
1834 smb2_downgrade_oplock(struct TCP_Server_Info
*server
,
1835 struct cifsInodeInfo
*cinode
, bool set_level2
)
1838 server
->ops
->set_oplock_level(cinode
, SMB2_OPLOCK_LEVEL_II
,
1841 server
->ops
->set_oplock_level(cinode
, 0, 0, NULL
);
1845 smb2_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1846 unsigned int epoch
, bool *purge_cache
)
1849 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1851 if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
) {
1852 cinode
->oplock
= CIFS_CACHE_RHW_FLG
;
1853 cifs_dbg(FYI
, "Batch Oplock granted on inode %p\n",
1854 &cinode
->vfs_inode
);
1855 } else if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
) {
1856 cinode
->oplock
= CIFS_CACHE_RW_FLG
;
1857 cifs_dbg(FYI
, "Exclusive Oplock granted on inode %p\n",
1858 &cinode
->vfs_inode
);
1859 } else if (oplock
== SMB2_OPLOCK_LEVEL_II
) {
1860 cinode
->oplock
= CIFS_CACHE_READ_FLG
;
1861 cifs_dbg(FYI
, "Level II Oplock granted on inode %p\n",
1862 &cinode
->vfs_inode
);
1868 smb21_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1869 unsigned int epoch
, bool *purge_cache
)
1871 char message
[5] = {0};
1874 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1878 if (oplock
& SMB2_LEASE_READ_CACHING_HE
) {
1879 cinode
->oplock
|= CIFS_CACHE_READ_FLG
;
1880 strcat(message
, "R");
1882 if (oplock
& SMB2_LEASE_HANDLE_CACHING_HE
) {
1883 cinode
->oplock
|= CIFS_CACHE_HANDLE_FLG
;
1884 strcat(message
, "H");
1886 if (oplock
& SMB2_LEASE_WRITE_CACHING_HE
) {
1887 cinode
->oplock
|= CIFS_CACHE_WRITE_FLG
;
1888 strcat(message
, "W");
1890 if (!cinode
->oplock
)
1891 strcat(message
, "None");
1892 cifs_dbg(FYI
, "%s Lease granted on inode %p\n", message
,
1893 &cinode
->vfs_inode
);
1897 smb3_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1898 unsigned int epoch
, bool *purge_cache
)
1900 unsigned int old_oplock
= cinode
->oplock
;
1902 smb21_set_oplock_level(cinode
, oplock
, epoch
, purge_cache
);
1905 *purge_cache
= false;
1906 if (old_oplock
== CIFS_CACHE_READ_FLG
) {
1907 if (cinode
->oplock
== CIFS_CACHE_READ_FLG
&&
1908 (epoch
- cinode
->epoch
> 0))
1909 *purge_cache
= true;
1910 else if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1911 (epoch
- cinode
->epoch
> 1))
1912 *purge_cache
= true;
1913 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1914 (epoch
- cinode
->epoch
> 1))
1915 *purge_cache
= true;
1916 else if (cinode
->oplock
== 0 &&
1917 (epoch
- cinode
->epoch
> 0))
1918 *purge_cache
= true;
1919 } else if (old_oplock
== CIFS_CACHE_RH_FLG
) {
1920 if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1921 (epoch
- cinode
->epoch
> 0))
1922 *purge_cache
= true;
1923 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1924 (epoch
- cinode
->epoch
> 1))
1925 *purge_cache
= true;
1927 cinode
->epoch
= epoch
;
1932 smb2_is_read_op(__u32 oplock
)
1934 return oplock
== SMB2_OPLOCK_LEVEL_II
;
1938 smb21_is_read_op(__u32 oplock
)
1940 return (oplock
& SMB2_LEASE_READ_CACHING_HE
) &&
1941 !(oplock
& SMB2_LEASE_WRITE_CACHING_HE
);
1945 map_oplock_to_lease(u8 oplock
)
1947 if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
)
1948 return SMB2_LEASE_WRITE_CACHING
| SMB2_LEASE_READ_CACHING
;
1949 else if (oplock
== SMB2_OPLOCK_LEVEL_II
)
1950 return SMB2_LEASE_READ_CACHING
;
1951 else if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
)
1952 return SMB2_LEASE_HANDLE_CACHING
| SMB2_LEASE_READ_CACHING
|
1953 SMB2_LEASE_WRITE_CACHING
;
1958 smb2_create_lease_buf(u8
*lease_key
, u8 oplock
)
1960 struct create_lease
*buf
;
1962 buf
= kzalloc(sizeof(struct create_lease
), GFP_KERNEL
);
1966 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1967 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1968 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1970 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1971 (struct create_lease
, lcontext
));
1972 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context
));
1973 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1974 (struct create_lease
, Name
));
1975 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1976 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1985 smb3_create_lease_buf(u8
*lease_key
, u8 oplock
)
1987 struct create_lease_v2
*buf
;
1989 buf
= kzalloc(sizeof(struct create_lease_v2
), GFP_KERNEL
);
1993 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1994 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1995 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1997 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1998 (struct create_lease_v2
, lcontext
));
1999 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context_v2
));
2000 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
2001 (struct create_lease_v2
, Name
));
2002 buf
->ccontext
.NameLength
= cpu_to_le16(4);
2003 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
2012 smb2_parse_lease_buf(void *buf
, unsigned int *epoch
)
2014 struct create_lease
*lc
= (struct create_lease
*)buf
;
2016 *epoch
= 0; /* not used */
2017 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
2018 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
2019 return le32_to_cpu(lc
->lcontext
.LeaseState
);
2023 smb3_parse_lease_buf(void *buf
, unsigned int *epoch
)
2025 struct create_lease_v2
*lc
= (struct create_lease_v2
*)buf
;
2027 *epoch
= le16_to_cpu(lc
->lcontext
.Epoch
);
2028 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
2029 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
2030 return le32_to_cpu(lc
->lcontext
.LeaseState
);
2034 smb2_wp_retry_size(struct inode
*inode
)
2036 return min_t(unsigned int, CIFS_SB(inode
->i_sb
)->wsize
,
2037 SMB2_MAX_BUFFER_SIZE
);
2041 smb2_dir_needs_close(struct cifsFileInfo
*cfile
)
2043 return !cfile
->invalidHandle
;
2047 fill_transform_hdr(struct smb2_transform_hdr
*tr_hdr
, struct smb_rqst
*old_rq
)
2049 struct smb2_sync_hdr
*shdr
=
2050 (struct smb2_sync_hdr
*)old_rq
->rq_iov
[1].iov_base
;
2051 unsigned int orig_len
= get_rfc1002_length(old_rq
->rq_iov
[0].iov_base
);
2053 memset(tr_hdr
, 0, sizeof(struct smb2_transform_hdr
));
2054 tr_hdr
->ProtocolId
= SMB2_TRANSFORM_PROTO_NUM
;
2055 tr_hdr
->OriginalMessageSize
= cpu_to_le32(orig_len
);
2056 tr_hdr
->Flags
= cpu_to_le16(0x01);
2057 get_random_bytes(&tr_hdr
->Nonce
, SMB3_AES128CMM_NONCE
);
2058 memcpy(&tr_hdr
->SessionId
, &shdr
->SessionId
, 8);
2059 inc_rfc1001_len(tr_hdr
, sizeof(struct smb2_transform_hdr
) - 4);
2060 inc_rfc1001_len(tr_hdr
, orig_len
);
2063 static struct scatterlist
*
2064 init_sg(struct smb_rqst
*rqst
, u8
*sign
)
2066 unsigned int sg_len
= rqst
->rq_nvec
+ rqst
->rq_npages
+ 1;
2067 unsigned int assoc_data_len
= sizeof(struct smb2_transform_hdr
) - 24;
2068 struct scatterlist
*sg
;
2072 sg
= kmalloc_array(sg_len
, sizeof(struct scatterlist
), GFP_KERNEL
);
2076 sg_init_table(sg
, sg_len
);
2077 sg_set_buf(&sg
[0], rqst
->rq_iov
[0].iov_base
+ 24, assoc_data_len
);
2078 for (i
= 1; i
< rqst
->rq_nvec
; i
++)
2079 sg_set_buf(&sg
[i
], rqst
->rq_iov
[i
].iov_base
,
2080 rqst
->rq_iov
[i
].iov_len
);
2081 for (j
= 0; i
< sg_len
- 1; i
++, j
++) {
2082 unsigned int len
= (j
< rqst
->rq_npages
- 1) ? rqst
->rq_pagesz
2084 sg_set_page(&sg
[i
], rqst
->rq_pages
[j
], len
, 0);
2086 sg_set_buf(&sg
[sg_len
- 1], sign
, SMB2_SIGNATURE_SIZE
);
2091 smb2_get_enc_key(struct TCP_Server_Info
*server
, __u64 ses_id
, int enc
, u8
*key
)
2093 struct cifs_ses
*ses
;
2096 spin_lock(&cifs_tcp_ses_lock
);
2097 list_for_each_entry(ses
, &server
->smb_ses_list
, smb_ses_list
) {
2098 if (ses
->Suid
!= ses_id
)
2100 ses_enc_key
= enc
? ses
->smb3encryptionkey
:
2101 ses
->smb3decryptionkey
;
2102 memcpy(key
, ses_enc_key
, SMB3_SIGN_KEY_SIZE
);
2103 spin_unlock(&cifs_tcp_ses_lock
);
2106 spin_unlock(&cifs_tcp_ses_lock
);
2111 * Encrypt or decrypt @rqst message. @rqst has the following format:
2112 * iov[0] - transform header (associate data),
2113 * iov[1-N] and pages - data to encrypt.
2114 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
2118 crypt_message(struct TCP_Server_Info
*server
, struct smb_rqst
*rqst
, int enc
)
2120 struct smb2_transform_hdr
*tr_hdr
=
2121 (struct smb2_transform_hdr
*)rqst
->rq_iov
[0].iov_base
;
2122 unsigned int assoc_data_len
= sizeof(struct smb2_transform_hdr
) - 24;
2124 struct scatterlist
*sg
;
2125 u8 sign
[SMB2_SIGNATURE_SIZE
] = {};
2126 u8 key
[SMB3_SIGN_KEY_SIZE
];
2127 struct aead_request
*req
;
2129 unsigned int iv_len
;
2130 DECLARE_CRYPTO_WAIT(wait
);
2131 struct crypto_aead
*tfm
;
2132 unsigned int crypt_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
2134 rc
= smb2_get_enc_key(server
, tr_hdr
->SessionId
, enc
, key
);
2136 cifs_dbg(VFS
, "%s: Could not get %scryption key\n", __func__
,
2141 rc
= smb3_crypto_aead_allocate(server
);
2143 cifs_dbg(VFS
, "%s: crypto alloc failed\n", __func__
);
2147 tfm
= enc
? server
->secmech
.ccmaesencrypt
:
2148 server
->secmech
.ccmaesdecrypt
;
2149 rc
= crypto_aead_setkey(tfm
, key
, SMB3_SIGN_KEY_SIZE
);
2151 cifs_dbg(VFS
, "%s: Failed to set aead key %d\n", __func__
, rc
);
2155 rc
= crypto_aead_setauthsize(tfm
, SMB2_SIGNATURE_SIZE
);
2157 cifs_dbg(VFS
, "%s: Failed to set authsize %d\n", __func__
, rc
);
2161 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
2163 cifs_dbg(VFS
, "%s: Failed to alloc aead request", __func__
);
2168 memcpy(sign
, &tr_hdr
->Signature
, SMB2_SIGNATURE_SIZE
);
2169 crypt_len
+= SMB2_SIGNATURE_SIZE
;
2172 sg
= init_sg(rqst
, sign
);
2174 cifs_dbg(VFS
, "%s: Failed to init sg", __func__
);
2179 iv_len
= crypto_aead_ivsize(tfm
);
2180 iv
= kzalloc(iv_len
, GFP_KERNEL
);
2182 cifs_dbg(VFS
, "%s: Failed to alloc IV", __func__
);
2187 memcpy(iv
+ 1, (char *)tr_hdr
->Nonce
, SMB3_AES128CMM_NONCE
);
2189 aead_request_set_crypt(req
, sg
, sg
, crypt_len
, iv
);
2190 aead_request_set_ad(req
, assoc_data_len
);
2192 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
2193 crypto_req_done
, &wait
);
2195 rc
= crypto_wait_req(enc
? crypto_aead_encrypt(req
)
2196 : crypto_aead_decrypt(req
), &wait
);
2199 memcpy(&tr_hdr
->Signature
, sign
, SMB2_SIGNATURE_SIZE
);
2210 smb3_init_transform_rq(struct TCP_Server_Info
*server
, struct smb_rqst
*new_rq
,
2211 struct smb_rqst
*old_rq
)
2214 struct page
**pages
;
2215 struct smb2_transform_hdr
*tr_hdr
;
2216 unsigned int npages
= old_rq
->rq_npages
;
2220 pages
= kmalloc_array(npages
, sizeof(struct page
*), GFP_KERNEL
);
2224 new_rq
->rq_pages
= pages
;
2225 new_rq
->rq_npages
= old_rq
->rq_npages
;
2226 new_rq
->rq_pagesz
= old_rq
->rq_pagesz
;
2227 new_rq
->rq_tailsz
= old_rq
->rq_tailsz
;
2229 for (i
= 0; i
< npages
; i
++) {
2230 pages
[i
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
2232 goto err_free_pages
;
2235 iov
= kmalloc_array(old_rq
->rq_nvec
, sizeof(struct kvec
), GFP_KERNEL
);
2237 goto err_free_pages
;
2239 /* copy all iovs from the old except the 1st one (rfc1002 length) */
2240 memcpy(&iov
[1], &old_rq
->rq_iov
[1],
2241 sizeof(struct kvec
) * (old_rq
->rq_nvec
- 1));
2242 new_rq
->rq_iov
= iov
;
2243 new_rq
->rq_nvec
= old_rq
->rq_nvec
;
2245 tr_hdr
= kmalloc(sizeof(struct smb2_transform_hdr
), GFP_KERNEL
);
2249 /* fill the 1st iov with a transform header */
2250 fill_transform_hdr(tr_hdr
, old_rq
);
2251 new_rq
->rq_iov
[0].iov_base
= tr_hdr
;
2252 new_rq
->rq_iov
[0].iov_len
= sizeof(struct smb2_transform_hdr
);
2254 /* copy pages form the old */
2255 for (i
= 0; i
< npages
; i
++) {
2256 char *dst
= kmap(new_rq
->rq_pages
[i
]);
2257 char *src
= kmap(old_rq
->rq_pages
[i
]);
2258 unsigned int len
= (i
< npages
- 1) ? new_rq
->rq_pagesz
:
2260 memcpy(dst
, src
, len
);
2261 kunmap(new_rq
->rq_pages
[i
]);
2262 kunmap(old_rq
->rq_pages
[i
]);
2265 rc
= crypt_message(server
, new_rq
, 1);
2266 cifs_dbg(FYI
, "encrypt message returned %d", rc
);
2268 goto err_free_tr_hdr
;
2277 for (i
= i
- 1; i
>= 0; i
--)
2284 smb3_free_transform_rq(struct smb_rqst
*rqst
)
2286 int i
= rqst
->rq_npages
- 1;
2289 put_page(rqst
->rq_pages
[i
]);
2290 kfree(rqst
->rq_pages
);
2291 /* free transform header */
2292 kfree(rqst
->rq_iov
[0].iov_base
);
2293 kfree(rqst
->rq_iov
);
2297 smb3_is_transform_hdr(void *buf
)
2299 struct smb2_transform_hdr
*trhdr
= buf
;
2301 return trhdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
;
2305 decrypt_raw_data(struct TCP_Server_Info
*server
, char *buf
,
2306 unsigned int buf_data_size
, struct page
**pages
,
2307 unsigned int npages
, unsigned int page_data_size
)
2310 struct smb_rqst rqst
= {NULL
};
2311 struct smb2_hdr
*hdr
;
2314 iov
[0].iov_base
= buf
;
2315 iov
[0].iov_len
= sizeof(struct smb2_transform_hdr
);
2316 iov
[1].iov_base
= buf
+ sizeof(struct smb2_transform_hdr
);
2317 iov
[1].iov_len
= buf_data_size
;
2321 rqst
.rq_pages
= pages
;
2322 rqst
.rq_npages
= npages
;
2323 rqst
.rq_pagesz
= PAGE_SIZE
;
2324 rqst
.rq_tailsz
= (page_data_size
% PAGE_SIZE
) ? : PAGE_SIZE
;
2326 rc
= crypt_message(server
, &rqst
, 0);
2327 cifs_dbg(FYI
, "decrypt message returned %d\n", rc
);
2332 memmove(buf
+ 4, iov
[1].iov_base
, buf_data_size
);
2333 hdr
= (struct smb2_hdr
*)buf
;
2334 hdr
->smb2_buf_length
= cpu_to_be32(buf_data_size
+ page_data_size
);
2335 server
->total_read
= buf_data_size
+ page_data_size
+ 4;
2341 read_data_into_pages(struct TCP_Server_Info
*server
, struct page
**pages
,
2342 unsigned int npages
, unsigned int len
)
2347 for (i
= 0; i
< npages
; i
++) {
2348 struct page
*page
= pages
[i
];
2352 if (len
>= PAGE_SIZE
) {
2353 /* enough data to fill the page */
2357 zero_user(page
, len
, PAGE_SIZE
- len
);
2360 length
= cifs_read_page_from_socket(server
, page
, n
);
2363 server
->total_read
+= length
;
2370 init_read_bvec(struct page
**pages
, unsigned int npages
, unsigned int data_size
,
2371 unsigned int cur_off
, struct bio_vec
**page_vec
)
2373 struct bio_vec
*bvec
;
2376 bvec
= kcalloc(npages
, sizeof(struct bio_vec
), GFP_KERNEL
);
2380 for (i
= 0; i
< npages
; i
++) {
2381 bvec
[i
].bv_page
= pages
[i
];
2382 bvec
[i
].bv_offset
= (i
== 0) ? cur_off
: 0;
2383 bvec
[i
].bv_len
= min_t(unsigned int, PAGE_SIZE
, data_size
);
2384 data_size
-= bvec
[i
].bv_len
;
2387 if (data_size
!= 0) {
2388 cifs_dbg(VFS
, "%s: something went wrong\n", __func__
);
2398 handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
,
2399 char *buf
, unsigned int buf_len
, struct page
**pages
,
2400 unsigned int npages
, unsigned int page_data_size
)
2402 unsigned int data_offset
;
2403 unsigned int data_len
;
2404 unsigned int cur_off
;
2405 unsigned int cur_page_idx
;
2406 unsigned int pad_len
;
2407 struct cifs_readdata
*rdata
= mid
->callback_data
;
2408 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
2409 struct bio_vec
*bvec
= NULL
;
2410 struct iov_iter iter
;
2414 if (shdr
->Command
!= SMB2_READ
) {
2415 cifs_dbg(VFS
, "only big read responses are supported\n");
2419 if (server
->ops
->is_session_expired
&&
2420 server
->ops
->is_session_expired(buf
)) {
2421 cifs_reconnect(server
);
2422 wake_up(&server
->response_q
);
2426 if (server
->ops
->is_status_pending
&&
2427 server
->ops
->is_status_pending(buf
, server
, 0))
2430 rdata
->result
= server
->ops
->map_error(buf
, false);
2431 if (rdata
->result
!= 0) {
2432 cifs_dbg(FYI
, "%s: server returned error %d\n",
2433 __func__
, rdata
->result
);
2434 dequeue_mid(mid
, rdata
->result
);
2438 data_offset
= server
->ops
->read_data_offset(buf
) + 4;
2439 data_len
= server
->ops
->read_data_length(buf
);
2441 if (data_offset
< server
->vals
->read_rsp_size
) {
2443 * win2k8 sometimes sends an offset of 0 when the read
2444 * is beyond the EOF. Treat it as if the data starts just after
2447 cifs_dbg(FYI
, "%s: data offset (%u) inside read response header\n",
2448 __func__
, data_offset
);
2449 data_offset
= server
->vals
->read_rsp_size
;
2450 } else if (data_offset
> MAX_CIFS_SMALL_BUFFER_SIZE
) {
2451 /* data_offset is beyond the end of smallbuf */
2452 cifs_dbg(FYI
, "%s: data offset (%u) beyond end of smallbuf\n",
2453 __func__
, data_offset
);
2454 rdata
->result
= -EIO
;
2455 dequeue_mid(mid
, rdata
->result
);
2459 pad_len
= data_offset
- server
->vals
->read_rsp_size
;
2461 if (buf_len
<= data_offset
) {
2462 /* read response payload is in pages */
2463 cur_page_idx
= pad_len
/ PAGE_SIZE
;
2464 cur_off
= pad_len
% PAGE_SIZE
;
2466 if (cur_page_idx
!= 0) {
2467 /* data offset is beyond the 1st page of response */
2468 cifs_dbg(FYI
, "%s: data offset (%u) beyond 1st page of response\n",
2469 __func__
, data_offset
);
2470 rdata
->result
= -EIO
;
2471 dequeue_mid(mid
, rdata
->result
);
2475 if (data_len
> page_data_size
- pad_len
) {
2476 /* data_len is corrupt -- discard frame */
2477 rdata
->result
= -EIO
;
2478 dequeue_mid(mid
, rdata
->result
);
2482 rdata
->result
= init_read_bvec(pages
, npages
, page_data_size
,
2484 if (rdata
->result
!= 0) {
2485 dequeue_mid(mid
, rdata
->result
);
2489 iov_iter_bvec(&iter
, WRITE
| ITER_BVEC
, bvec
, npages
, data_len
);
2490 } else if (buf_len
>= data_offset
+ data_len
) {
2491 /* read response payload is in buf */
2492 WARN_ONCE(npages
> 0, "read data can be either in buf or in pages");
2493 iov
.iov_base
= buf
+ data_offset
;
2494 iov
.iov_len
= data_len
;
2495 iov_iter_kvec(&iter
, WRITE
| ITER_KVEC
, &iov
, 1, data_len
);
2497 /* read response payload cannot be in both buf and pages */
2498 WARN_ONCE(1, "buf can not contain only a part of read data");
2499 rdata
->result
= -EIO
;
2500 dequeue_mid(mid
, rdata
->result
);
2504 /* set up first iov for signature check */
2505 rdata
->iov
[0].iov_base
= buf
;
2506 rdata
->iov
[0].iov_len
= 4;
2507 rdata
->iov
[1].iov_base
= buf
+ 4;
2508 rdata
->iov
[1].iov_len
= server
->vals
->read_rsp_size
- 4;
2509 cifs_dbg(FYI
, "0: iov_base=%p iov_len=%zu\n",
2510 rdata
->iov
[0].iov_base
, server
->vals
->read_rsp_size
);
2512 length
= rdata
->copy_into_pages(server
, rdata
, &iter
);
2519 dequeue_mid(mid
, false);
2524 receive_encrypted_read(struct TCP_Server_Info
*server
, struct mid_q_entry
**mid
)
2526 char *buf
= server
->smallbuf
;
2527 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
2528 unsigned int npages
;
2529 struct page
**pages
;
2531 unsigned int buflen
= get_rfc1002_length(buf
) + 4;
2535 len
= min_t(unsigned int, buflen
, server
->vals
->read_rsp_size
- 4 +
2536 sizeof(struct smb2_transform_hdr
)) - HEADER_SIZE(server
) + 1;
2538 rc
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1, len
);
2541 server
->total_read
+= rc
;
2543 len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
) + 4 -
2544 server
->vals
->read_rsp_size
;
2545 npages
= DIV_ROUND_UP(len
, PAGE_SIZE
);
2547 pages
= kmalloc_array(npages
, sizeof(struct page
*), GFP_KERNEL
);
2553 for (; i
< npages
; i
++) {
2554 pages
[i
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
2561 /* read read data into pages */
2562 rc
= read_data_into_pages(server
, pages
, npages
, len
);
2566 rc
= cifs_discard_remaining_data(server
);
2570 rc
= decrypt_raw_data(server
, buf
, server
->vals
->read_rsp_size
- 4,
2571 pages
, npages
, len
);
2575 *mid
= smb2_find_mid(server
, buf
);
2577 cifs_dbg(FYI
, "mid not found\n");
2579 cifs_dbg(FYI
, "mid found\n");
2580 (*mid
)->decrypted
= true;
2581 rc
= handle_read_data(server
, *mid
, buf
,
2582 server
->vals
->read_rsp_size
,
2583 pages
, npages
, len
);
2587 for (i
= i
- 1; i
>= 0; i
--)
2592 cifs_discard_remaining_data(server
);
2597 receive_encrypted_standard(struct TCP_Server_Info
*server
,
2598 struct mid_q_entry
**mid
)
2601 char *buf
= server
->smallbuf
;
2602 unsigned int pdu_length
= get_rfc1002_length(buf
);
2603 unsigned int buf_size
;
2604 struct mid_q_entry
*mid_entry
;
2606 /* switch to large buffer if too big for a small one */
2607 if (pdu_length
+ 4 > MAX_CIFS_SMALL_BUFFER_SIZE
) {
2608 server
->large_buf
= true;
2609 memcpy(server
->bigbuf
, buf
, server
->total_read
);
2610 buf
= server
->bigbuf
;
2613 /* now read the rest */
2614 length
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1,
2615 pdu_length
- HEADER_SIZE(server
) + 1 + 4);
2618 server
->total_read
+= length
;
2620 buf_size
= pdu_length
+ 4 - sizeof(struct smb2_transform_hdr
);
2621 length
= decrypt_raw_data(server
, buf
, buf_size
, NULL
, 0, 0);
2625 mid_entry
= smb2_find_mid(server
, buf
);
2626 if (mid_entry
== NULL
)
2627 cifs_dbg(FYI
, "mid not found\n");
2629 cifs_dbg(FYI
, "mid found\n");
2630 mid_entry
->decrypted
= true;
2635 if (mid_entry
&& mid_entry
->handle
)
2636 return mid_entry
->handle(server
, mid_entry
);
2638 return cifs_handle_standard(server
, mid_entry
);
2642 smb3_receive_transform(struct TCP_Server_Info
*server
, struct mid_q_entry
**mid
)
2644 char *buf
= server
->smallbuf
;
2645 unsigned int pdu_length
= get_rfc1002_length(buf
);
2646 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
2647 unsigned int orig_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
2649 if (pdu_length
+ 4 < sizeof(struct smb2_transform_hdr
) +
2650 sizeof(struct smb2_sync_hdr
)) {
2651 cifs_dbg(VFS
, "Transform message is too small (%u)\n",
2653 cifs_reconnect(server
);
2654 wake_up(&server
->response_q
);
2655 return -ECONNABORTED
;
2658 if (pdu_length
+ 4 < orig_len
+ sizeof(struct smb2_transform_hdr
)) {
2659 cifs_dbg(VFS
, "Transform message is broken\n");
2660 cifs_reconnect(server
);
2661 wake_up(&server
->response_q
);
2662 return -ECONNABORTED
;
2665 if (pdu_length
+ 4 > CIFSMaxBufSize
+ MAX_HEADER_SIZE(server
))
2666 return receive_encrypted_read(server
, mid
);
2668 return receive_encrypted_standard(server
, mid
);
2672 smb3_handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
)
2674 char *buf
= server
->large_buf
? server
->bigbuf
: server
->smallbuf
;
2676 return handle_read_data(server
, mid
, buf
, get_rfc1002_length(buf
) + 4,
2680 struct smb_version_operations smb20_operations
= {
2681 .compare_fids
= smb2_compare_fids
,
2682 .setup_request
= smb2_setup_request
,
2683 .setup_async_request
= smb2_setup_async_request
,
2684 .check_receive
= smb2_check_receive
,
2685 .add_credits
= smb2_add_credits
,
2686 .set_credits
= smb2_set_credits
,
2687 .get_credits_field
= smb2_get_credits_field
,
2688 .get_credits
= smb2_get_credits
,
2689 .wait_mtu_credits
= cifs_wait_mtu_credits
,
2690 .get_next_mid
= smb2_get_next_mid
,
2691 .read_data_offset
= smb2_read_data_offset
,
2692 .read_data_length
= smb2_read_data_length
,
2693 .map_error
= map_smb2_to_linux_error
,
2694 .find_mid
= smb2_find_mid
,
2695 .check_message
= smb2_check_message
,
2696 .dump_detail
= smb2_dump_detail
,
2697 .clear_stats
= smb2_clear_stats
,
2698 .print_stats
= smb2_print_stats
,
2699 .is_oplock_break
= smb2_is_valid_oplock_break
,
2700 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
2701 .downgrade_oplock
= smb2_downgrade_oplock
,
2702 .need_neg
= smb2_need_neg
,
2703 .negotiate
= smb2_negotiate
,
2704 .negotiate_wsize
= smb2_negotiate_wsize
,
2705 .negotiate_rsize
= smb2_negotiate_rsize
,
2706 .sess_setup
= SMB2_sess_setup
,
2707 .logoff
= SMB2_logoff
,
2708 .tree_connect
= SMB2_tcon
,
2709 .tree_disconnect
= SMB2_tdis
,
2710 .qfs_tcon
= smb2_qfs_tcon
,
2711 .is_path_accessible
= smb2_is_path_accessible
,
2712 .can_echo
= smb2_can_echo
,
2714 .query_path_info
= smb2_query_path_info
,
2715 .get_srv_inum
= smb2_get_srv_inum
,
2716 .query_file_info
= smb2_query_file_info
,
2717 .set_path_size
= smb2_set_path_size
,
2718 .set_file_size
= smb2_set_file_size
,
2719 .set_file_info
= smb2_set_file_info
,
2720 .set_compression
= smb2_set_compression
,
2721 .mkdir
= smb2_mkdir
,
2722 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2723 .rmdir
= smb2_rmdir
,
2724 .unlink
= smb2_unlink
,
2725 .rename
= smb2_rename_path
,
2726 .create_hardlink
= smb2_create_hardlink
,
2727 .query_symlink
= smb2_query_symlink
,
2728 .query_mf_symlink
= smb3_query_mf_symlink
,
2729 .create_mf_symlink
= smb3_create_mf_symlink
,
2730 .open
= smb2_open_file
,
2731 .set_fid
= smb2_set_fid
,
2732 .close
= smb2_close_file
,
2733 .flush
= smb2_flush_file
,
2734 .async_readv
= smb2_async_readv
,
2735 .async_writev
= smb2_async_writev
,
2736 .sync_read
= smb2_sync_read
,
2737 .sync_write
= smb2_sync_write
,
2738 .query_dir_first
= smb2_query_dir_first
,
2739 .query_dir_next
= smb2_query_dir_next
,
2740 .close_dir
= smb2_close_dir
,
2741 .calc_smb_size
= smb2_calc_size
,
2742 .is_status_pending
= smb2_is_status_pending
,
2743 .is_session_expired
= smb2_is_session_expired
,
2744 .oplock_response
= smb2_oplock_response
,
2745 .queryfs
= smb2_queryfs
,
2746 .mand_lock
= smb2_mand_lock
,
2747 .mand_unlock_range
= smb2_unlock_range
,
2748 .push_mand_locks
= smb2_push_mandatory_locks
,
2749 .get_lease_key
= smb2_get_lease_key
,
2750 .set_lease_key
= smb2_set_lease_key
,
2751 .new_lease_key
= smb2_new_lease_key
,
2752 .calc_signature
= smb2_calc_signature
,
2753 .is_read_op
= smb2_is_read_op
,
2754 .set_oplock_level
= smb2_set_oplock_level
,
2755 .create_lease_buf
= smb2_create_lease_buf
,
2756 .parse_lease_buf
= smb2_parse_lease_buf
,
2757 .copychunk_range
= smb2_copychunk_range
,
2758 .wp_retry_size
= smb2_wp_retry_size
,
2759 .dir_needs_close
= smb2_dir_needs_close
,
2760 .get_dfs_refer
= smb2_get_dfs_refer
,
2761 .select_sectype
= smb2_select_sectype
,
2762 #ifdef CONFIG_CIFS_XATTR
2763 .query_all_EAs
= smb2_query_eas
,
2764 .set_EA
= smb2_set_ea
,
2765 #endif /* CIFS_XATTR */
2766 #ifdef CONFIG_CIFS_ACL
2767 .get_acl
= get_smb2_acl
,
2768 .get_acl_by_fid
= get_smb2_acl_by_fid
,
2769 .set_acl
= set_smb2_acl
,
2770 #endif /* CIFS_ACL */
2773 struct smb_version_operations smb21_operations
= {
2774 .compare_fids
= smb2_compare_fids
,
2775 .setup_request
= smb2_setup_request
,
2776 .setup_async_request
= smb2_setup_async_request
,
2777 .check_receive
= smb2_check_receive
,
2778 .add_credits
= smb2_add_credits
,
2779 .set_credits
= smb2_set_credits
,
2780 .get_credits_field
= smb2_get_credits_field
,
2781 .get_credits
= smb2_get_credits
,
2782 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2783 .get_next_mid
= smb2_get_next_mid
,
2784 .read_data_offset
= smb2_read_data_offset
,
2785 .read_data_length
= smb2_read_data_length
,
2786 .map_error
= map_smb2_to_linux_error
,
2787 .find_mid
= smb2_find_mid
,
2788 .check_message
= smb2_check_message
,
2789 .dump_detail
= smb2_dump_detail
,
2790 .clear_stats
= smb2_clear_stats
,
2791 .print_stats
= smb2_print_stats
,
2792 .is_oplock_break
= smb2_is_valid_oplock_break
,
2793 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
2794 .downgrade_oplock
= smb2_downgrade_oplock
,
2795 .need_neg
= smb2_need_neg
,
2796 .negotiate
= smb2_negotiate
,
2797 .negotiate_wsize
= smb2_negotiate_wsize
,
2798 .negotiate_rsize
= smb2_negotiate_rsize
,
2799 .sess_setup
= SMB2_sess_setup
,
2800 .logoff
= SMB2_logoff
,
2801 .tree_connect
= SMB2_tcon
,
2802 .tree_disconnect
= SMB2_tdis
,
2803 .qfs_tcon
= smb2_qfs_tcon
,
2804 .is_path_accessible
= smb2_is_path_accessible
,
2805 .can_echo
= smb2_can_echo
,
2807 .query_path_info
= smb2_query_path_info
,
2808 .get_srv_inum
= smb2_get_srv_inum
,
2809 .query_file_info
= smb2_query_file_info
,
2810 .set_path_size
= smb2_set_path_size
,
2811 .set_file_size
= smb2_set_file_size
,
2812 .set_file_info
= smb2_set_file_info
,
2813 .set_compression
= smb2_set_compression
,
2814 .mkdir
= smb2_mkdir
,
2815 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2816 .rmdir
= smb2_rmdir
,
2817 .unlink
= smb2_unlink
,
2818 .rename
= smb2_rename_path
,
2819 .create_hardlink
= smb2_create_hardlink
,
2820 .query_symlink
= smb2_query_symlink
,
2821 .query_mf_symlink
= smb3_query_mf_symlink
,
2822 .create_mf_symlink
= smb3_create_mf_symlink
,
2823 .open
= smb2_open_file
,
2824 .set_fid
= smb2_set_fid
,
2825 .close
= smb2_close_file
,
2826 .flush
= smb2_flush_file
,
2827 .async_readv
= smb2_async_readv
,
2828 .async_writev
= smb2_async_writev
,
2829 .sync_read
= smb2_sync_read
,
2830 .sync_write
= smb2_sync_write
,
2831 .query_dir_first
= smb2_query_dir_first
,
2832 .query_dir_next
= smb2_query_dir_next
,
2833 .close_dir
= smb2_close_dir
,
2834 .calc_smb_size
= smb2_calc_size
,
2835 .is_status_pending
= smb2_is_status_pending
,
2836 .is_session_expired
= smb2_is_session_expired
,
2837 .oplock_response
= smb2_oplock_response
,
2838 .queryfs
= smb2_queryfs
,
2839 .mand_lock
= smb2_mand_lock
,
2840 .mand_unlock_range
= smb2_unlock_range
,
2841 .push_mand_locks
= smb2_push_mandatory_locks
,
2842 .get_lease_key
= smb2_get_lease_key
,
2843 .set_lease_key
= smb2_set_lease_key
,
2844 .new_lease_key
= smb2_new_lease_key
,
2845 .calc_signature
= smb2_calc_signature
,
2846 .is_read_op
= smb21_is_read_op
,
2847 .set_oplock_level
= smb21_set_oplock_level
,
2848 .create_lease_buf
= smb2_create_lease_buf
,
2849 .parse_lease_buf
= smb2_parse_lease_buf
,
2850 .copychunk_range
= smb2_copychunk_range
,
2851 .wp_retry_size
= smb2_wp_retry_size
,
2852 .dir_needs_close
= smb2_dir_needs_close
,
2853 .enum_snapshots
= smb3_enum_snapshots
,
2854 .get_dfs_refer
= smb2_get_dfs_refer
,
2855 .select_sectype
= smb2_select_sectype
,
2856 #ifdef CONFIG_CIFS_XATTR
2857 .query_all_EAs
= smb2_query_eas
,
2858 .set_EA
= smb2_set_ea
,
2859 #endif /* CIFS_XATTR */
2860 #ifdef CONFIG_CIFS_ACL
2861 .get_acl
= get_smb2_acl
,
2862 .get_acl_by_fid
= get_smb2_acl_by_fid
,
2863 .set_acl
= set_smb2_acl
,
2864 #endif /* CIFS_ACL */
2867 struct smb_version_operations smb30_operations
= {
2868 .compare_fids
= smb2_compare_fids
,
2869 .setup_request
= smb2_setup_request
,
2870 .setup_async_request
= smb2_setup_async_request
,
2871 .check_receive
= smb2_check_receive
,
2872 .add_credits
= smb2_add_credits
,
2873 .set_credits
= smb2_set_credits
,
2874 .get_credits_field
= smb2_get_credits_field
,
2875 .get_credits
= smb2_get_credits
,
2876 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2877 .get_next_mid
= smb2_get_next_mid
,
2878 .read_data_offset
= smb2_read_data_offset
,
2879 .read_data_length
= smb2_read_data_length
,
2880 .map_error
= map_smb2_to_linux_error
,
2881 .find_mid
= smb2_find_mid
,
2882 .check_message
= smb2_check_message
,
2883 .dump_detail
= smb2_dump_detail
,
2884 .clear_stats
= smb2_clear_stats
,
2885 .print_stats
= smb2_print_stats
,
2886 .dump_share_caps
= smb2_dump_share_caps
,
2887 .is_oplock_break
= smb2_is_valid_oplock_break
,
2888 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
2889 .downgrade_oplock
= smb2_downgrade_oplock
,
2890 .need_neg
= smb2_need_neg
,
2891 .negotiate
= smb2_negotiate
,
2892 .negotiate_wsize
= smb2_negotiate_wsize
,
2893 .negotiate_rsize
= smb2_negotiate_rsize
,
2894 .sess_setup
= SMB2_sess_setup
,
2895 .logoff
= SMB2_logoff
,
2896 .tree_connect
= SMB2_tcon
,
2897 .tree_disconnect
= SMB2_tdis
,
2898 .qfs_tcon
= smb3_qfs_tcon
,
2899 .is_path_accessible
= smb2_is_path_accessible
,
2900 .can_echo
= smb2_can_echo
,
2902 .query_path_info
= smb2_query_path_info
,
2903 .get_srv_inum
= smb2_get_srv_inum
,
2904 .query_file_info
= smb2_query_file_info
,
2905 .set_path_size
= smb2_set_path_size
,
2906 .set_file_size
= smb2_set_file_size
,
2907 .set_file_info
= smb2_set_file_info
,
2908 .set_compression
= smb2_set_compression
,
2909 .mkdir
= smb2_mkdir
,
2910 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2911 .rmdir
= smb2_rmdir
,
2912 .unlink
= smb2_unlink
,
2913 .rename
= smb2_rename_path
,
2914 .create_hardlink
= smb2_create_hardlink
,
2915 .query_symlink
= smb2_query_symlink
,
2916 .query_mf_symlink
= smb3_query_mf_symlink
,
2917 .create_mf_symlink
= smb3_create_mf_symlink
,
2918 .open
= smb2_open_file
,
2919 .set_fid
= smb2_set_fid
,
2920 .close
= smb2_close_file
,
2921 .flush
= smb2_flush_file
,
2922 .async_readv
= smb2_async_readv
,
2923 .async_writev
= smb2_async_writev
,
2924 .sync_read
= smb2_sync_read
,
2925 .sync_write
= smb2_sync_write
,
2926 .query_dir_first
= smb2_query_dir_first
,
2927 .query_dir_next
= smb2_query_dir_next
,
2928 .close_dir
= smb2_close_dir
,
2929 .calc_smb_size
= smb2_calc_size
,
2930 .is_status_pending
= smb2_is_status_pending
,
2931 .is_session_expired
= smb2_is_session_expired
,
2932 .oplock_response
= smb2_oplock_response
,
2933 .queryfs
= smb2_queryfs
,
2934 .mand_lock
= smb2_mand_lock
,
2935 .mand_unlock_range
= smb2_unlock_range
,
2936 .push_mand_locks
= smb2_push_mandatory_locks
,
2937 .get_lease_key
= smb2_get_lease_key
,
2938 .set_lease_key
= smb2_set_lease_key
,
2939 .new_lease_key
= smb2_new_lease_key
,
2940 .generate_signingkey
= generate_smb30signingkey
,
2941 .calc_signature
= smb3_calc_signature
,
2942 .set_integrity
= smb3_set_integrity
,
2943 .is_read_op
= smb21_is_read_op
,
2944 .set_oplock_level
= smb3_set_oplock_level
,
2945 .create_lease_buf
= smb3_create_lease_buf
,
2946 .parse_lease_buf
= smb3_parse_lease_buf
,
2947 .copychunk_range
= smb2_copychunk_range
,
2948 .duplicate_extents
= smb2_duplicate_extents
,
2949 .validate_negotiate
= smb3_validate_negotiate
,
2950 .wp_retry_size
= smb2_wp_retry_size
,
2951 .dir_needs_close
= smb2_dir_needs_close
,
2952 .fallocate
= smb3_fallocate
,
2953 .enum_snapshots
= smb3_enum_snapshots
,
2954 .init_transform_rq
= smb3_init_transform_rq
,
2955 .free_transform_rq
= smb3_free_transform_rq
,
2956 .is_transform_hdr
= smb3_is_transform_hdr
,
2957 .receive_transform
= smb3_receive_transform
,
2958 .get_dfs_refer
= smb2_get_dfs_refer
,
2959 .select_sectype
= smb2_select_sectype
,
2960 #ifdef CONFIG_CIFS_XATTR
2961 .query_all_EAs
= smb2_query_eas
,
2962 .set_EA
= smb2_set_ea
,
2963 #endif /* CIFS_XATTR */
2964 #ifdef CONFIG_CIFS_ACL
2965 .get_acl
= get_smb2_acl
,
2966 .get_acl_by_fid
= get_smb2_acl_by_fid
,
2967 .set_acl
= set_smb2_acl
,
2968 #endif /* CIFS_ACL */
2971 #ifdef CONFIG_CIFS_SMB311
2972 struct smb_version_operations smb311_operations
= {
2973 .compare_fids
= smb2_compare_fids
,
2974 .setup_request
= smb2_setup_request
,
2975 .setup_async_request
= smb2_setup_async_request
,
2976 .check_receive
= smb2_check_receive
,
2977 .add_credits
= smb2_add_credits
,
2978 .set_credits
= smb2_set_credits
,
2979 .get_credits_field
= smb2_get_credits_field
,
2980 .get_credits
= smb2_get_credits
,
2981 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2982 .get_next_mid
= smb2_get_next_mid
,
2983 .read_data_offset
= smb2_read_data_offset
,
2984 .read_data_length
= smb2_read_data_length
,
2985 .map_error
= map_smb2_to_linux_error
,
2986 .find_mid
= smb2_find_mid
,
2987 .check_message
= smb2_check_message
,
2988 .dump_detail
= smb2_dump_detail
,
2989 .clear_stats
= smb2_clear_stats
,
2990 .print_stats
= smb2_print_stats
,
2991 .dump_share_caps
= smb2_dump_share_caps
,
2992 .is_oplock_break
= smb2_is_valid_oplock_break
,
2993 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
2994 .downgrade_oplock
= smb2_downgrade_oplock
,
2995 .need_neg
= smb2_need_neg
,
2996 .negotiate
= smb2_negotiate
,
2997 .negotiate_wsize
= smb2_negotiate_wsize
,
2998 .negotiate_rsize
= smb2_negotiate_rsize
,
2999 .sess_setup
= SMB2_sess_setup
,
3000 .logoff
= SMB2_logoff
,
3001 .tree_connect
= SMB2_tcon
,
3002 .tree_disconnect
= SMB2_tdis
,
3003 .qfs_tcon
= smb3_qfs_tcon
,
3004 .is_path_accessible
= smb2_is_path_accessible
,
3005 .can_echo
= smb2_can_echo
,
3007 .query_path_info
= smb2_query_path_info
,
3008 .get_srv_inum
= smb2_get_srv_inum
,
3009 .query_file_info
= smb2_query_file_info
,
3010 .set_path_size
= smb2_set_path_size
,
3011 .set_file_size
= smb2_set_file_size
,
3012 .set_file_info
= smb2_set_file_info
,
3013 .set_compression
= smb2_set_compression
,
3014 .mkdir
= smb2_mkdir
,
3015 .mkdir_setinfo
= smb2_mkdir_setinfo
,
3016 .rmdir
= smb2_rmdir
,
3017 .unlink
= smb2_unlink
,
3018 .rename
= smb2_rename_path
,
3019 .create_hardlink
= smb2_create_hardlink
,
3020 .query_symlink
= smb2_query_symlink
,
3021 .query_mf_symlink
= smb3_query_mf_symlink
,
3022 .create_mf_symlink
= smb3_create_mf_symlink
,
3023 .open
= smb2_open_file
,
3024 .set_fid
= smb2_set_fid
,
3025 .close
= smb2_close_file
,
3026 .flush
= smb2_flush_file
,
3027 .async_readv
= smb2_async_readv
,
3028 .async_writev
= smb2_async_writev
,
3029 .sync_read
= smb2_sync_read
,
3030 .sync_write
= smb2_sync_write
,
3031 .query_dir_first
= smb2_query_dir_first
,
3032 .query_dir_next
= smb2_query_dir_next
,
3033 .close_dir
= smb2_close_dir
,
3034 .calc_smb_size
= smb2_calc_size
,
3035 .is_status_pending
= smb2_is_status_pending
,
3036 .is_session_expired
= smb2_is_session_expired
,
3037 .oplock_response
= smb2_oplock_response
,
3038 .queryfs
= smb2_queryfs
,
3039 .mand_lock
= smb2_mand_lock
,
3040 .mand_unlock_range
= smb2_unlock_range
,
3041 .push_mand_locks
= smb2_push_mandatory_locks
,
3042 .get_lease_key
= smb2_get_lease_key
,
3043 .set_lease_key
= smb2_set_lease_key
,
3044 .new_lease_key
= smb2_new_lease_key
,
3045 .generate_signingkey
= generate_smb311signingkey
,
3046 .calc_signature
= smb3_calc_signature
,
3047 .set_integrity
= smb3_set_integrity
,
3048 .is_read_op
= smb21_is_read_op
,
3049 .set_oplock_level
= smb3_set_oplock_level
,
3050 .create_lease_buf
= smb3_create_lease_buf
,
3051 .parse_lease_buf
= smb3_parse_lease_buf
,
3052 .copychunk_range
= smb2_copychunk_range
,
3053 .duplicate_extents
= smb2_duplicate_extents
,
3054 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
3055 .wp_retry_size
= smb2_wp_retry_size
,
3056 .dir_needs_close
= smb2_dir_needs_close
,
3057 .fallocate
= smb3_fallocate
,
3058 .enum_snapshots
= smb3_enum_snapshots
,
3059 .init_transform_rq
= smb3_init_transform_rq
,
3060 .free_transform_rq
= smb3_free_transform_rq
,
3061 .is_transform_hdr
= smb3_is_transform_hdr
,
3062 .receive_transform
= smb3_receive_transform
,
3063 .get_dfs_refer
= smb2_get_dfs_refer
,
3064 .select_sectype
= smb2_select_sectype
,
3065 #ifdef CONFIG_CIFS_XATTR
3066 .query_all_EAs
= smb2_query_eas
,
3067 .set_EA
= smb2_set_ea
,
3068 #endif /* CIFS_XATTR */
3070 #endif /* CIFS_SMB311 */
3072 struct smb_version_values smb20_values
= {
3073 .version_string
= SMB20_VERSION_STRING
,
3074 .protocol_id
= SMB20_PROT_ID
,
3075 .req_capabilities
= 0, /* MBZ */
3076 .large_lock_type
= 0,
3077 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3078 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3079 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3080 .header_size
= sizeof(struct smb2_hdr
),
3081 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3082 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3083 .lock_cmd
= SMB2_LOCK
,
3085 .cap_nt_find
= SMB2_NT_FIND
,
3086 .cap_large_files
= SMB2_LARGE_FILES
,
3087 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3088 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3089 .create_lease_size
= sizeof(struct create_lease
),
3092 struct smb_version_values smb21_values
= {
3093 .version_string
= SMB21_VERSION_STRING
,
3094 .protocol_id
= SMB21_PROT_ID
,
3095 .req_capabilities
= 0, /* MBZ on negotiate req until SMB3 dialect */
3096 .large_lock_type
= 0,
3097 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3098 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3099 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3100 .header_size
= sizeof(struct smb2_hdr
),
3101 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3102 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3103 .lock_cmd
= SMB2_LOCK
,
3105 .cap_nt_find
= SMB2_NT_FIND
,
3106 .cap_large_files
= SMB2_LARGE_FILES
,
3107 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3108 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3109 .create_lease_size
= sizeof(struct create_lease
),
3112 struct smb_version_values smb3any_values
= {
3113 .version_string
= SMB3ANY_VERSION_STRING
,
3114 .protocol_id
= SMB302_PROT_ID
, /* doesn't matter, send protocol array */
3115 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
3116 .large_lock_type
= 0,
3117 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3118 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3119 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3120 .header_size
= sizeof(struct smb2_hdr
),
3121 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3122 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3123 .lock_cmd
= SMB2_LOCK
,
3125 .cap_nt_find
= SMB2_NT_FIND
,
3126 .cap_large_files
= SMB2_LARGE_FILES
,
3127 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3128 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3129 .create_lease_size
= sizeof(struct create_lease_v2
),
3132 struct smb_version_values smbdefault_values
= {
3133 .version_string
= SMBDEFAULT_VERSION_STRING
,
3134 .protocol_id
= SMB302_PROT_ID
, /* doesn't matter, send protocol array */
3135 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
3136 .large_lock_type
= 0,
3137 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3138 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3139 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3140 .header_size
= sizeof(struct smb2_hdr
),
3141 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3142 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3143 .lock_cmd
= SMB2_LOCK
,
3145 .cap_nt_find
= SMB2_NT_FIND
,
3146 .cap_large_files
= SMB2_LARGE_FILES
,
3147 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3148 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3149 .create_lease_size
= sizeof(struct create_lease_v2
),
3152 struct smb_version_values smb30_values
= {
3153 .version_string
= SMB30_VERSION_STRING
,
3154 .protocol_id
= SMB30_PROT_ID
,
3155 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
3156 .large_lock_type
= 0,
3157 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3158 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3159 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3160 .header_size
= sizeof(struct smb2_hdr
),
3161 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3162 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3163 .lock_cmd
= SMB2_LOCK
,
3165 .cap_nt_find
= SMB2_NT_FIND
,
3166 .cap_large_files
= SMB2_LARGE_FILES
,
3167 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3168 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3169 .create_lease_size
= sizeof(struct create_lease_v2
),
3172 struct smb_version_values smb302_values
= {
3173 .version_string
= SMB302_VERSION_STRING
,
3174 .protocol_id
= SMB302_PROT_ID
,
3175 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
3176 .large_lock_type
= 0,
3177 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3178 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3179 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3180 .header_size
= sizeof(struct smb2_hdr
),
3181 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3182 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3183 .lock_cmd
= SMB2_LOCK
,
3185 .cap_nt_find
= SMB2_NT_FIND
,
3186 .cap_large_files
= SMB2_LARGE_FILES
,
3187 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3188 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3189 .create_lease_size
= sizeof(struct create_lease_v2
),
3192 #ifdef CONFIG_CIFS_SMB311
3193 struct smb_version_values smb311_values
= {
3194 .version_string
= SMB311_VERSION_STRING
,
3195 .protocol_id
= SMB311_PROT_ID
,
3196 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
3197 .large_lock_type
= 0,
3198 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3199 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3200 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3201 .header_size
= sizeof(struct smb2_hdr
),
3202 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3203 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3204 .lock_cmd
= SMB2_LOCK
,
3206 .cap_nt_find
= SMB2_NT_FIND
,
3207 .cap_large_files
= SMB2_LARGE_FILES
,
3208 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3209 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3210 .create_lease_size
= sizeof(struct create_lease_v2
),