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"
35 #include "smbdirect.h"
38 change_conf(struct TCP_Server_Info
*server
)
40 server
->credits
+= server
->echo_credits
+ server
->oplock_credits
;
41 server
->oplock_credits
= server
->echo_credits
= 0;
42 switch (server
->credits
) {
46 server
->echoes
= false;
47 server
->oplocks
= false;
48 cifs_dbg(VFS
, "disabling echoes and oplocks\n");
51 server
->echoes
= true;
52 server
->oplocks
= false;
53 server
->echo_credits
= 1;
54 cifs_dbg(FYI
, "disabling oplocks\n");
57 server
->echoes
= true;
59 server
->oplocks
= true;
60 server
->oplock_credits
= 1;
62 server
->oplocks
= false;
64 server
->echo_credits
= 1;
66 server
->credits
-= server
->echo_credits
+ server
->oplock_credits
;
71 smb2_add_credits(struct TCP_Server_Info
*server
, const unsigned int add
,
75 spin_lock(&server
->req_lock
);
76 val
= server
->ops
->get_credits_field(server
, optype
);
79 *val
= 65000; /* Don't get near 64K credits, avoid srv bugs */
80 printk_once(KERN_WARNING
"server overflowed SMB3 credits\n");
83 if (server
->in_flight
== 0 && (optype
& CIFS_OP_MASK
) != CIFS_NEG_OP
)
84 rc
= change_conf(server
);
86 * Sometimes server returns 0 credits on oplock break ack - we need to
87 * rebalance credits in this case.
89 else if (server
->in_flight
> 0 && server
->oplock_credits
== 0 &&
91 if (server
->credits
> 1) {
93 server
->oplock_credits
++;
96 spin_unlock(&server
->req_lock
);
97 wake_up(&server
->request_q
);
99 cifs_reconnect(server
);
103 smb2_set_credits(struct TCP_Server_Info
*server
, const int val
)
105 spin_lock(&server
->req_lock
);
106 server
->credits
= val
;
107 spin_unlock(&server
->req_lock
);
111 smb2_get_credits_field(struct TCP_Server_Info
*server
, const int optype
)
115 return &server
->echo_credits
;
117 return &server
->oplock_credits
;
119 return &server
->credits
;
124 smb2_get_credits(struct mid_q_entry
*mid
)
126 struct smb2_sync_hdr
*shdr
= get_sync_hdr(mid
->resp_buf
);
128 return le16_to_cpu(shdr
->CreditRequest
);
132 smb2_wait_mtu_credits(struct TCP_Server_Info
*server
, unsigned int size
,
133 unsigned int *num
, unsigned int *credits
)
136 unsigned int scredits
;
138 spin_lock(&server
->req_lock
);
140 if (server
->credits
<= 0) {
141 spin_unlock(&server
->req_lock
);
142 cifs_num_waiters_inc(server
);
143 rc
= wait_event_killable(server
->request_q
,
144 has_credits(server
, &server
->credits
));
145 cifs_num_waiters_dec(server
);
148 spin_lock(&server
->req_lock
);
150 if (server
->tcpStatus
== CifsExiting
) {
151 spin_unlock(&server
->req_lock
);
155 scredits
= server
->credits
;
156 /* can deadlock with reopen */
158 *num
= SMB2_MAX_BUFFER_SIZE
;
163 /* leave one credit for a possible reopen */
165 *num
= min_t(unsigned int, size
,
166 scredits
* SMB2_MAX_BUFFER_SIZE
);
168 *credits
= DIV_ROUND_UP(*num
, SMB2_MAX_BUFFER_SIZE
);
169 server
->credits
-= *credits
;
174 spin_unlock(&server
->req_lock
);
179 smb2_get_next_mid(struct TCP_Server_Info
*server
)
182 /* for SMB2 we need the current value */
183 spin_lock(&GlobalMid_Lock
);
184 mid
= server
->CurrentMid
++;
185 spin_unlock(&GlobalMid_Lock
);
189 static struct mid_q_entry
*
190 smb2_find_mid(struct TCP_Server_Info
*server
, char *buf
)
192 struct mid_q_entry
*mid
;
193 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
194 __u64 wire_mid
= le64_to_cpu(shdr
->MessageId
);
196 if (shdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
) {
197 cifs_dbg(VFS
, "encrypted frame parsing not supported yet");
201 spin_lock(&GlobalMid_Lock
);
202 list_for_each_entry(mid
, &server
->pending_mid_q
, qhead
) {
203 if ((mid
->mid
== wire_mid
) &&
204 (mid
->mid_state
== MID_REQUEST_SUBMITTED
) &&
205 (mid
->command
== shdr
->Command
)) {
206 spin_unlock(&GlobalMid_Lock
);
210 spin_unlock(&GlobalMid_Lock
);
215 smb2_dump_detail(void *buf
)
217 #ifdef CONFIG_CIFS_DEBUG2
218 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
220 cifs_dbg(VFS
, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
221 shdr
->Command
, shdr
->Status
, shdr
->Flags
, shdr
->MessageId
,
223 cifs_dbg(VFS
, "smb buf %p len %u\n", buf
, smb2_calc_size(buf
));
228 smb2_need_neg(struct TCP_Server_Info
*server
)
230 return server
->max_read
== 0;
234 smb2_negotiate(const unsigned int xid
, struct cifs_ses
*ses
)
237 ses
->server
->CurrentMid
= 0;
238 rc
= SMB2_negotiate(xid
, ses
);
239 /* BB we probably don't need to retry with modern servers */
246 smb2_negotiate_wsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
248 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
251 /* start with specified wsize, or default */
252 wsize
= volume_info
->wsize
? volume_info
->wsize
: CIFS_DEFAULT_IOSIZE
;
253 wsize
= min_t(unsigned int, wsize
, server
->max_write
);
254 #ifdef CONFIG_CIFS_SMB_DIRECT
256 wsize
= min_t(unsigned int,
257 wsize
, server
->smbd_conn
->max_readwrite_size
);
259 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
260 wsize
= min_t(unsigned int, wsize
, SMB2_MAX_BUFFER_SIZE
);
266 smb2_negotiate_rsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
268 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
271 /* start with specified rsize, or default */
272 rsize
= volume_info
->rsize
? volume_info
->rsize
: CIFS_DEFAULT_IOSIZE
;
273 rsize
= min_t(unsigned int, rsize
, server
->max_read
);
274 #ifdef CONFIG_CIFS_SMB_DIRECT
276 rsize
= min_t(unsigned int,
277 rsize
, server
->smbd_conn
->max_readwrite_size
);
280 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
281 rsize
= min_t(unsigned int, rsize
, SMB2_MAX_BUFFER_SIZE
);
286 #ifdef CONFIG_CIFS_STATS2
288 SMB3_request_interfaces(const unsigned int xid
, struct cifs_tcon
*tcon
)
291 unsigned int ret_data_len
= 0;
292 struct network_interface_info_ioctl_rsp
*out_buf
;
294 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
295 FSCTL_QUERY_NETWORK_INTERFACE_INFO
, true /* is_fsctl */,
296 NULL
/* no data input */, 0 /* no data input */,
297 (char **)&out_buf
, &ret_data_len
);
299 cifs_dbg(VFS
, "error %d on ioctl to get interface list\n", rc
);
300 else if (ret_data_len
< sizeof(struct network_interface_info_ioctl_rsp
)) {
301 cifs_dbg(VFS
, "server returned bad net interface info buf\n");
304 /* Dump info on first interface */
305 cifs_dbg(FYI
, "Adapter Capability 0x%x\t",
306 le32_to_cpu(out_buf
->Capability
));
307 cifs_dbg(FYI
, "Link Speed %lld\n",
308 le64_to_cpu(out_buf
->LinkSpeed
));
316 smb3_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
319 __le16 srch_path
= 0; /* Null - open root of share */
320 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
321 struct cifs_open_parms oparms
;
325 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
326 oparms
.disposition
= FILE_OPEN
;
327 oparms
.create_options
= 0;
329 oparms
.reconnect
= false;
331 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
335 #ifdef CONFIG_CIFS_STATS2
336 SMB3_request_interfaces(xid
, tcon
);
339 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
340 FS_ATTRIBUTE_INFORMATION
);
341 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
342 FS_DEVICE_INFORMATION
);
343 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
344 FS_SECTOR_SIZE_INFORMATION
); /* SMB3 specific */
345 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
350 smb2_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
353 __le16 srch_path
= 0; /* Null - open root of share */
354 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
355 struct cifs_open_parms oparms
;
359 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
360 oparms
.disposition
= FILE_OPEN
;
361 oparms
.create_options
= 0;
363 oparms
.reconnect
= false;
365 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
369 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
370 FS_ATTRIBUTE_INFORMATION
);
371 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
372 FS_DEVICE_INFORMATION
);
373 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
378 smb2_is_path_accessible(const unsigned int xid
, struct cifs_tcon
*tcon
,
379 struct cifs_sb_info
*cifs_sb
, const char *full_path
)
383 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
384 struct cifs_open_parms oparms
;
387 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
392 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
393 oparms
.disposition
= FILE_OPEN
;
394 oparms
.create_options
= 0;
396 oparms
.reconnect
= false;
398 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
404 rc
= SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
410 smb2_get_srv_inum(const unsigned int xid
, struct cifs_tcon
*tcon
,
411 struct cifs_sb_info
*cifs_sb
, const char *full_path
,
412 u64
*uniqueid
, FILE_ALL_INFO
*data
)
414 *uniqueid
= le64_to_cpu(data
->IndexNumber
);
419 smb2_query_file_info(const unsigned int xid
, struct cifs_tcon
*tcon
,
420 struct cifs_fid
*fid
, FILE_ALL_INFO
*data
)
423 struct smb2_file_all_info
*smb2_data
;
425 smb2_data
= kzalloc(sizeof(struct smb2_file_all_info
) + PATH_MAX
* 2,
427 if (smb2_data
== NULL
)
430 rc
= SMB2_query_info(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
,
433 move_smb2_info_to_cifs(data
, smb2_data
);
438 #ifdef CONFIG_CIFS_XATTR
440 move_smb2_ea_to_cifs(char *dst
, size_t dst_size
,
441 struct smb2_file_full_ea_info
*src
, size_t src_size
,
442 const unsigned char *ea_name
)
445 unsigned int ea_name_len
= ea_name
? strlen(ea_name
) : 0;
447 size_t name_len
, value_len
, user_name_len
;
449 while (src_size
> 0) {
450 name
= &src
->ea_data
[0];
451 name_len
= (size_t)src
->ea_name_length
;
452 value
= &src
->ea_data
[src
->ea_name_length
+ 1];
453 value_len
= (size_t)le16_to_cpu(src
->ea_value_length
);
459 if (src_size
< 8 + name_len
+ 1 + value_len
) {
460 cifs_dbg(FYI
, "EA entry goes beyond length of list\n");
466 if (ea_name_len
== name_len
&&
467 memcmp(ea_name
, name
, name_len
) == 0) {
471 if (dst_size
< value_len
) {
475 memcpy(dst
, value
, value_len
);
479 /* 'user.' plus a terminating null */
480 user_name_len
= 5 + 1 + name_len
;
484 if (dst_size
>= user_name_len
) {
485 dst_size
-= user_name_len
;
486 memcpy(dst
, "user.", 5);
488 memcpy(dst
, src
->ea_data
, name_len
);
492 } else if (dst_size
== 0) {
493 /* skip copy - calc size only */
495 /* stop before overrun buffer */
501 if (!src
->next_entry_offset
)
504 if (src_size
< le32_to_cpu(src
->next_entry_offset
)) {
505 /* stop before overrun buffer */
509 src_size
-= le32_to_cpu(src
->next_entry_offset
);
510 src
= (void *)((char *)src
+
511 le32_to_cpu(src
->next_entry_offset
));
514 /* didn't find the named attribute */
523 smb2_query_eas(const unsigned int xid
, struct cifs_tcon
*tcon
,
524 const unsigned char *path
, const unsigned char *ea_name
,
525 char *ea_data
, size_t buf_size
,
526 struct cifs_sb_info
*cifs_sb
)
530 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
531 struct cifs_open_parms oparms
;
533 struct smb2_file_full_ea_info
*smb2_data
;
534 int ea_buf_size
= SMB2_MIN_EA_BUF
;
536 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
541 oparms
.desired_access
= FILE_READ_EA
;
542 oparms
.disposition
= FILE_OPEN
;
543 oparms
.create_options
= 0;
545 oparms
.reconnect
= false;
547 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
550 cifs_dbg(FYI
, "open failed rc=%d\n", rc
);
555 smb2_data
= kzalloc(ea_buf_size
, GFP_KERNEL
);
556 if (smb2_data
== NULL
) {
557 SMB2_close(xid
, tcon
, fid
.persistent_fid
,
562 rc
= SMB2_query_eas(xid
, tcon
, fid
.persistent_fid
,
564 ea_buf_size
, smb2_data
);
572 if (ea_buf_size
> SMB2_MAX_EA_BUF
) {
573 cifs_dbg(VFS
, "EA size is too large\n");
574 SMB2_close(xid
, tcon
, fid
.persistent_fid
,
580 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
583 rc
= move_smb2_ea_to_cifs(ea_data
, buf_size
, smb2_data
,
584 SMB2_MAX_EA_BUF
, ea_name
);
592 smb2_set_ea(const unsigned int xid
, struct cifs_tcon
*tcon
,
593 const char *path
, const char *ea_name
, const void *ea_value
,
594 const __u16 ea_value_len
, const struct nls_table
*nls_codepage
,
595 struct cifs_sb_info
*cifs_sb
)
599 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
600 struct cifs_open_parms oparms
;
602 struct smb2_file_full_ea_info
*ea
;
603 int ea_name_len
= strlen(ea_name
);
606 if (ea_name_len
> 255)
609 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
614 oparms
.desired_access
= FILE_WRITE_EA
;
615 oparms
.disposition
= FILE_OPEN
;
616 oparms
.create_options
= 0;
618 oparms
.reconnect
= false;
620 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
623 cifs_dbg(FYI
, "open failed rc=%d\n", rc
);
627 len
= sizeof(ea
) + ea_name_len
+ ea_value_len
+ 1;
628 ea
= kzalloc(len
, GFP_KERNEL
);
630 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
634 ea
->ea_name_length
= ea_name_len
;
635 ea
->ea_value_length
= cpu_to_le16(ea_value_len
);
636 memcpy(ea
->ea_data
, ea_name
, ea_name_len
+ 1);
637 memcpy(ea
->ea_data
+ ea_name_len
+ 1, ea_value
, ea_value_len
);
639 rc
= SMB2_set_ea(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
, ea
,
641 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
648 smb2_can_echo(struct TCP_Server_Info
*server
)
650 return server
->echoes
;
654 smb2_clear_stats(struct cifs_tcon
*tcon
)
656 #ifdef CONFIG_CIFS_STATS
658 for (i
= 0; i
< NUMBER_OF_SMB2_COMMANDS
; i
++) {
659 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_sent
[i
], 0);
660 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_failed
[i
], 0);
666 smb2_dump_share_caps(struct seq_file
*m
, struct cifs_tcon
*tcon
)
668 seq_puts(m
, "\n\tShare Capabilities:");
669 if (tcon
->capabilities
& SMB2_SHARE_CAP_DFS
)
670 seq_puts(m
, " DFS,");
671 if (tcon
->capabilities
& SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY
)
672 seq_puts(m
, " CONTINUOUS AVAILABILITY,");
673 if (tcon
->capabilities
& SMB2_SHARE_CAP_SCALEOUT
)
674 seq_puts(m
, " SCALEOUT,");
675 if (tcon
->capabilities
& SMB2_SHARE_CAP_CLUSTER
)
676 seq_puts(m
, " CLUSTER,");
677 if (tcon
->capabilities
& SMB2_SHARE_CAP_ASYMMETRIC
)
678 seq_puts(m
, " ASYMMETRIC,");
679 if (tcon
->capabilities
== 0)
680 seq_puts(m
, " None");
681 if (tcon
->ss_flags
& SSINFO_FLAGS_ALIGNED_DEVICE
)
682 seq_puts(m
, " Aligned,");
683 if (tcon
->ss_flags
& SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE
)
684 seq_puts(m
, " Partition Aligned,");
685 if (tcon
->ss_flags
& SSINFO_FLAGS_NO_SEEK_PENALTY
)
686 seq_puts(m
, " SSD,");
687 if (tcon
->ss_flags
& SSINFO_FLAGS_TRIM_ENABLED
)
688 seq_puts(m
, " TRIM-support,");
690 seq_printf(m
, "\tShare Flags: 0x%x", tcon
->share_flags
);
691 if (tcon
->perf_sector_size
)
692 seq_printf(m
, "\tOptimal sector size: 0x%x",
693 tcon
->perf_sector_size
);
697 smb2_print_stats(struct seq_file
*m
, struct cifs_tcon
*tcon
)
699 #ifdef CONFIG_CIFS_STATS
700 atomic_t
*sent
= tcon
->stats
.smb2_stats
.smb2_com_sent
;
701 atomic_t
*failed
= tcon
->stats
.smb2_stats
.smb2_com_failed
;
702 seq_printf(m
, "\nNegotiates: %d sent %d failed",
703 atomic_read(&sent
[SMB2_NEGOTIATE_HE
]),
704 atomic_read(&failed
[SMB2_NEGOTIATE_HE
]));
705 seq_printf(m
, "\nSessionSetups: %d sent %d failed",
706 atomic_read(&sent
[SMB2_SESSION_SETUP_HE
]),
707 atomic_read(&failed
[SMB2_SESSION_SETUP_HE
]));
708 seq_printf(m
, "\nLogoffs: %d sent %d failed",
709 atomic_read(&sent
[SMB2_LOGOFF_HE
]),
710 atomic_read(&failed
[SMB2_LOGOFF_HE
]));
711 seq_printf(m
, "\nTreeConnects: %d sent %d failed",
712 atomic_read(&sent
[SMB2_TREE_CONNECT_HE
]),
713 atomic_read(&failed
[SMB2_TREE_CONNECT_HE
]));
714 seq_printf(m
, "\nTreeDisconnects: %d sent %d failed",
715 atomic_read(&sent
[SMB2_TREE_DISCONNECT_HE
]),
716 atomic_read(&failed
[SMB2_TREE_DISCONNECT_HE
]));
717 seq_printf(m
, "\nCreates: %d sent %d failed",
718 atomic_read(&sent
[SMB2_CREATE_HE
]),
719 atomic_read(&failed
[SMB2_CREATE_HE
]));
720 seq_printf(m
, "\nCloses: %d sent %d failed",
721 atomic_read(&sent
[SMB2_CLOSE_HE
]),
722 atomic_read(&failed
[SMB2_CLOSE_HE
]));
723 seq_printf(m
, "\nFlushes: %d sent %d failed",
724 atomic_read(&sent
[SMB2_FLUSH_HE
]),
725 atomic_read(&failed
[SMB2_FLUSH_HE
]));
726 seq_printf(m
, "\nReads: %d sent %d failed",
727 atomic_read(&sent
[SMB2_READ_HE
]),
728 atomic_read(&failed
[SMB2_READ_HE
]));
729 seq_printf(m
, "\nWrites: %d sent %d failed",
730 atomic_read(&sent
[SMB2_WRITE_HE
]),
731 atomic_read(&failed
[SMB2_WRITE_HE
]));
732 seq_printf(m
, "\nLocks: %d sent %d failed",
733 atomic_read(&sent
[SMB2_LOCK_HE
]),
734 atomic_read(&failed
[SMB2_LOCK_HE
]));
735 seq_printf(m
, "\nIOCTLs: %d sent %d failed",
736 atomic_read(&sent
[SMB2_IOCTL_HE
]),
737 atomic_read(&failed
[SMB2_IOCTL_HE
]));
738 seq_printf(m
, "\nCancels: %d sent %d failed",
739 atomic_read(&sent
[SMB2_CANCEL_HE
]),
740 atomic_read(&failed
[SMB2_CANCEL_HE
]));
741 seq_printf(m
, "\nEchos: %d sent %d failed",
742 atomic_read(&sent
[SMB2_ECHO_HE
]),
743 atomic_read(&failed
[SMB2_ECHO_HE
]));
744 seq_printf(m
, "\nQueryDirectories: %d sent %d failed",
745 atomic_read(&sent
[SMB2_QUERY_DIRECTORY_HE
]),
746 atomic_read(&failed
[SMB2_QUERY_DIRECTORY_HE
]));
747 seq_printf(m
, "\nChangeNotifies: %d sent %d failed",
748 atomic_read(&sent
[SMB2_CHANGE_NOTIFY_HE
]),
749 atomic_read(&failed
[SMB2_CHANGE_NOTIFY_HE
]));
750 seq_printf(m
, "\nQueryInfos: %d sent %d failed",
751 atomic_read(&sent
[SMB2_QUERY_INFO_HE
]),
752 atomic_read(&failed
[SMB2_QUERY_INFO_HE
]));
753 seq_printf(m
, "\nSetInfos: %d sent %d failed",
754 atomic_read(&sent
[SMB2_SET_INFO_HE
]),
755 atomic_read(&failed
[SMB2_SET_INFO_HE
]));
756 seq_printf(m
, "\nOplockBreaks: %d sent %d failed",
757 atomic_read(&sent
[SMB2_OPLOCK_BREAK_HE
]),
758 atomic_read(&failed
[SMB2_OPLOCK_BREAK_HE
]));
763 smb2_set_fid(struct cifsFileInfo
*cfile
, struct cifs_fid
*fid
, __u32 oplock
)
765 struct cifsInodeInfo
*cinode
= CIFS_I(d_inode(cfile
->dentry
));
766 struct TCP_Server_Info
*server
= tlink_tcon(cfile
->tlink
)->ses
->server
;
768 cfile
->fid
.persistent_fid
= fid
->persistent_fid
;
769 cfile
->fid
.volatile_fid
= fid
->volatile_fid
;
770 server
->ops
->set_oplock_level(cinode
, oplock
, fid
->epoch
,
772 cinode
->can_cache_brlcks
= CIFS_CACHE_WRITE(cinode
);
773 memcpy(cfile
->fid
.create_guid
, fid
->create_guid
, 16);
777 smb2_close_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
778 struct cifs_fid
*fid
)
780 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
784 SMB2_request_res_key(const unsigned int xid
, struct cifs_tcon
*tcon
,
785 u64 persistent_fid
, u64 volatile_fid
,
786 struct copychunk_ioctl
*pcchunk
)
789 unsigned int ret_data_len
;
790 struct resume_key_req
*res_key
;
792 rc
= SMB2_ioctl(xid
, tcon
, persistent_fid
, volatile_fid
,
793 FSCTL_SRV_REQUEST_RESUME_KEY
, true /* is_fsctl */,
794 NULL
, 0 /* no input */,
795 (char **)&res_key
, &ret_data_len
);
798 cifs_dbg(VFS
, "refcpy ioctl error %d getting resume key\n", rc
);
799 goto req_res_key_exit
;
801 if (ret_data_len
< sizeof(struct resume_key_req
)) {
802 cifs_dbg(VFS
, "Invalid refcopy resume key length\n");
804 goto req_res_key_exit
;
806 memcpy(pcchunk
->SourceKey
, res_key
->ResumeKey
, COPY_CHUNK_RES_KEY_SIZE
);
814 smb2_copychunk_range(const unsigned int xid
,
815 struct cifsFileInfo
*srcfile
,
816 struct cifsFileInfo
*trgtfile
, u64 src_off
,
817 u64 len
, u64 dest_off
)
820 unsigned int ret_data_len
;
821 struct copychunk_ioctl
*pcchunk
;
822 struct copychunk_ioctl_rsp
*retbuf
= NULL
;
823 struct cifs_tcon
*tcon
;
824 int chunks_copied
= 0;
825 bool chunk_sizes_updated
= false;
826 ssize_t bytes_written
, total_bytes_written
= 0;
828 pcchunk
= kmalloc(sizeof(struct copychunk_ioctl
), GFP_KERNEL
);
833 cifs_dbg(FYI
, "in smb2_copychunk_range - about to call request res key\n");
834 /* Request a key from the server to identify the source of the copy */
835 rc
= SMB2_request_res_key(xid
, tlink_tcon(srcfile
->tlink
),
836 srcfile
->fid
.persistent_fid
,
837 srcfile
->fid
.volatile_fid
, pcchunk
);
839 /* Note: request_res_key sets res_key null only if rc !=0 */
843 /* For now array only one chunk long, will make more flexible later */
844 pcchunk
->ChunkCount
= cpu_to_le32(1);
845 pcchunk
->Reserved
= 0;
846 pcchunk
->Reserved2
= 0;
848 tcon
= tlink_tcon(trgtfile
->tlink
);
851 pcchunk
->SourceOffset
= cpu_to_le64(src_off
);
852 pcchunk
->TargetOffset
= cpu_to_le64(dest_off
);
854 cpu_to_le32(min_t(u32
, len
, tcon
->max_bytes_chunk
));
856 /* Request server copy to target from src identified by key */
857 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
858 trgtfile
->fid
.volatile_fid
, FSCTL_SRV_COPYCHUNK_WRITE
,
859 true /* is_fsctl */, (char *)pcchunk
,
860 sizeof(struct copychunk_ioctl
), (char **)&retbuf
,
864 sizeof(struct copychunk_ioctl_rsp
)) {
865 cifs_dbg(VFS
, "invalid cchunk response size\n");
869 if (retbuf
->TotalBytesWritten
== 0) {
870 cifs_dbg(FYI
, "no bytes copied\n");
875 * Check if server claimed to write more than we asked
877 if (le32_to_cpu(retbuf
->TotalBytesWritten
) >
878 le32_to_cpu(pcchunk
->Length
)) {
879 cifs_dbg(VFS
, "invalid copy chunk response\n");
883 if (le32_to_cpu(retbuf
->ChunksWritten
) != 1) {
884 cifs_dbg(VFS
, "invalid num chunks written\n");
890 bytes_written
= le32_to_cpu(retbuf
->TotalBytesWritten
);
891 src_off
+= bytes_written
;
892 dest_off
+= bytes_written
;
893 len
-= bytes_written
;
894 total_bytes_written
+= bytes_written
;
896 cifs_dbg(FYI
, "Chunks %d PartialChunk %d Total %zu\n",
897 le32_to_cpu(retbuf
->ChunksWritten
),
898 le32_to_cpu(retbuf
->ChunkBytesWritten
),
900 } else if (rc
== -EINVAL
) {
901 if (ret_data_len
!= sizeof(struct copychunk_ioctl_rsp
))
904 cifs_dbg(FYI
, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
905 le32_to_cpu(retbuf
->ChunksWritten
),
906 le32_to_cpu(retbuf
->ChunkBytesWritten
),
907 le32_to_cpu(retbuf
->TotalBytesWritten
));
910 * Check if this is the first request using these sizes,
911 * (ie check if copy succeed once with original sizes
912 * and check if the server gave us different sizes after
913 * we already updated max sizes on previous request).
914 * if not then why is the server returning an error now
916 if ((chunks_copied
!= 0) || chunk_sizes_updated
)
919 /* Check that server is not asking us to grow size */
920 if (le32_to_cpu(retbuf
->ChunkBytesWritten
) <
921 tcon
->max_bytes_chunk
)
922 tcon
->max_bytes_chunk
=
923 le32_to_cpu(retbuf
->ChunkBytesWritten
);
925 goto cchunk_out
; /* server gave us bogus size */
927 /* No need to change MaxChunks since already set to 1 */
928 chunk_sizes_updated
= true;
939 return total_bytes_written
;
943 smb2_flush_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
944 struct cifs_fid
*fid
)
946 return SMB2_flush(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
950 smb2_read_data_offset(char *buf
)
952 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
953 return rsp
->DataOffset
;
957 smb2_read_data_length(char *buf
, bool in_remaining
)
959 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
962 return le32_to_cpu(rsp
->DataRemaining
);
964 return le32_to_cpu(rsp
->DataLength
);
969 smb2_sync_read(const unsigned int xid
, struct cifs_fid
*pfid
,
970 struct cifs_io_parms
*parms
, unsigned int *bytes_read
,
971 char **buf
, int *buf_type
)
973 parms
->persistent_fid
= pfid
->persistent_fid
;
974 parms
->volatile_fid
= pfid
->volatile_fid
;
975 return SMB2_read(xid
, parms
, bytes_read
, buf
, buf_type
);
979 smb2_sync_write(const unsigned int xid
, struct cifs_fid
*pfid
,
980 struct cifs_io_parms
*parms
, unsigned int *written
,
981 struct kvec
*iov
, unsigned long nr_segs
)
984 parms
->persistent_fid
= pfid
->persistent_fid
;
985 parms
->volatile_fid
= pfid
->volatile_fid
;
986 return SMB2_write(xid
, parms
, written
, iov
, nr_segs
);
989 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
990 static bool smb2_set_sparse(const unsigned int xid
, struct cifs_tcon
*tcon
,
991 struct cifsFileInfo
*cfile
, struct inode
*inode
, __u8 setsparse
)
993 struct cifsInodeInfo
*cifsi
;
996 cifsi
= CIFS_I(inode
);
998 /* if file already sparse don't bother setting sparse again */
999 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && setsparse
)
1000 return true; /* already sparse */
1002 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && !setsparse
)
1003 return true; /* already not sparse */
1006 * Can't check for sparse support on share the usual way via the
1007 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1008 * since Samba server doesn't set the flag on the share, yet
1009 * supports the set sparse FSCTL and returns sparse correctly
1010 * in the file attributes. If we fail setting sparse though we
1011 * mark that server does not support sparse files for this share
1012 * to avoid repeatedly sending the unsupported fsctl to server
1013 * if the file is repeatedly extended.
1015 if (tcon
->broken_sparse_sup
)
1018 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1019 cfile
->fid
.volatile_fid
, FSCTL_SET_SPARSE
,
1021 &setsparse
, 1, NULL
, NULL
);
1023 tcon
->broken_sparse_sup
= true;
1024 cifs_dbg(FYI
, "set sparse rc = %d\n", rc
);
1029 cifsi
->cifsAttrs
|= FILE_ATTRIBUTE_SPARSE_FILE
;
1031 cifsi
->cifsAttrs
&= (~FILE_ATTRIBUTE_SPARSE_FILE
);
1037 smb2_set_file_size(const unsigned int xid
, struct cifs_tcon
*tcon
,
1038 struct cifsFileInfo
*cfile
, __u64 size
, bool set_alloc
)
1040 __le64 eof
= cpu_to_le64(size
);
1041 struct inode
*inode
;
1044 * If extending file more than one page make sparse. Many Linux fs
1045 * make files sparse by default when extending via ftruncate
1047 inode
= d_inode(cfile
->dentry
);
1049 if (!set_alloc
&& (size
> inode
->i_size
+ 8192)) {
1050 __u8 set_sparse
= 1;
1052 /* whether set sparse succeeds or not, extend the file */
1053 smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
);
1056 return SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
1057 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
, false);
1061 smb2_duplicate_extents(const unsigned int xid
,
1062 struct cifsFileInfo
*srcfile
,
1063 struct cifsFileInfo
*trgtfile
, u64 src_off
,
1064 u64 len
, u64 dest_off
)
1067 unsigned int ret_data_len
;
1068 struct duplicate_extents_to_file dup_ext_buf
;
1069 struct cifs_tcon
*tcon
= tlink_tcon(trgtfile
->tlink
);
1071 /* server fileays advertise duplicate extent support with this flag */
1072 if ((le32_to_cpu(tcon
->fsAttrInfo
.Attributes
) &
1073 FILE_SUPPORTS_BLOCK_REFCOUNTING
) == 0)
1076 dup_ext_buf
.VolatileFileHandle
= srcfile
->fid
.volatile_fid
;
1077 dup_ext_buf
.PersistentFileHandle
= srcfile
->fid
.persistent_fid
;
1078 dup_ext_buf
.SourceFileOffset
= cpu_to_le64(src_off
);
1079 dup_ext_buf
.TargetFileOffset
= cpu_to_le64(dest_off
);
1080 dup_ext_buf
.ByteCount
= cpu_to_le64(len
);
1081 cifs_dbg(FYI
, "duplicate extents: src off %lld dst off %lld len %lld",
1082 src_off
, dest_off
, len
);
1084 rc
= smb2_set_file_size(xid
, tcon
, trgtfile
, dest_off
+ len
, false);
1086 goto duplicate_extents_out
;
1088 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
1089 trgtfile
->fid
.volatile_fid
,
1090 FSCTL_DUPLICATE_EXTENTS_TO_FILE
,
1091 true /* is_fsctl */,
1092 (char *)&dup_ext_buf
,
1093 sizeof(struct duplicate_extents_to_file
),
1097 if (ret_data_len
> 0)
1098 cifs_dbg(FYI
, "non-zero response length in duplicate extents");
1100 duplicate_extents_out
:
1105 smb2_set_compression(const unsigned int xid
, struct cifs_tcon
*tcon
,
1106 struct cifsFileInfo
*cfile
)
1108 return SMB2_set_compression(xid
, tcon
, cfile
->fid
.persistent_fid
,
1109 cfile
->fid
.volatile_fid
);
1113 smb3_set_integrity(const unsigned int xid
, struct cifs_tcon
*tcon
,
1114 struct cifsFileInfo
*cfile
)
1116 struct fsctl_set_integrity_information_req integr_info
;
1117 unsigned int ret_data_len
;
1119 integr_info
.ChecksumAlgorithm
= cpu_to_le16(CHECKSUM_TYPE_UNCHANGED
);
1120 integr_info
.Flags
= 0;
1121 integr_info
.Reserved
= 0;
1123 return SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1124 cfile
->fid
.volatile_fid
,
1125 FSCTL_SET_INTEGRITY_INFORMATION
,
1126 true /* is_fsctl */,
1127 (char *)&integr_info
,
1128 sizeof(struct fsctl_set_integrity_information_req
),
1135 smb3_enum_snapshots(const unsigned int xid
, struct cifs_tcon
*tcon
,
1136 struct cifsFileInfo
*cfile
, void __user
*ioc_buf
)
1138 char *retbuf
= NULL
;
1139 unsigned int ret_data_len
= 0;
1141 struct smb_snapshot_array snapshot_in
;
1143 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1144 cfile
->fid
.volatile_fid
,
1145 FSCTL_SRV_ENUMERATE_SNAPSHOTS
,
1146 true /* is_fsctl */,
1147 NULL
, 0 /* no input data */,
1150 cifs_dbg(FYI
, "enum snaphots ioctl returned %d and ret buflen is %d\n",
1155 if (ret_data_len
&& (ioc_buf
!= NULL
) && (retbuf
!= NULL
)) {
1157 if (copy_from_user(&snapshot_in
, ioc_buf
,
1158 sizeof(struct smb_snapshot_array
))) {
1163 if (snapshot_in
.snapshot_array_size
< sizeof(struct smb_snapshot_array
)) {
1169 if (ret_data_len
> snapshot_in
.snapshot_array_size
)
1170 ret_data_len
= snapshot_in
.snapshot_array_size
;
1172 if (copy_to_user(ioc_buf
, retbuf
, ret_data_len
))
1181 smb2_query_dir_first(const unsigned int xid
, struct cifs_tcon
*tcon
,
1182 const char *path
, struct cifs_sb_info
*cifs_sb
,
1183 struct cifs_fid
*fid
, __u16 search_flags
,
1184 struct cifs_search_info
*srch_inf
)
1188 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1189 struct cifs_open_parms oparms
;
1191 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
1196 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| FILE_READ_DATA
;
1197 oparms
.disposition
= FILE_OPEN
;
1198 oparms
.create_options
= 0;
1200 oparms
.reconnect
= false;
1202 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
1205 cifs_dbg(FYI
, "open dir failed rc=%d\n", rc
);
1209 srch_inf
->entries_in_buffer
= 0;
1210 srch_inf
->index_of_last_entry
= 0;
1212 rc
= SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
1213 fid
->volatile_fid
, 0, srch_inf
);
1215 cifs_dbg(FYI
, "query directory failed rc=%d\n", rc
);
1216 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1222 smb2_query_dir_next(const unsigned int xid
, struct cifs_tcon
*tcon
,
1223 struct cifs_fid
*fid
, __u16 search_flags
,
1224 struct cifs_search_info
*srch_inf
)
1226 return SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
1227 fid
->volatile_fid
, 0, srch_inf
);
1231 smb2_close_dir(const unsigned int xid
, struct cifs_tcon
*tcon
,
1232 struct cifs_fid
*fid
)
1234 return SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1238 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
1239 * the number of credits and return true. Otherwise - return false.
1242 smb2_is_status_pending(char *buf
, struct TCP_Server_Info
*server
, int length
)
1244 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
1246 if (shdr
->Status
!= STATUS_PENDING
)
1250 spin_lock(&server
->req_lock
);
1251 server
->credits
+= le16_to_cpu(shdr
->CreditRequest
);
1252 spin_unlock(&server
->req_lock
);
1253 wake_up(&server
->request_q
);
1260 smb2_is_session_expired(char *buf
)
1262 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
1264 if (shdr
->Status
!= STATUS_NETWORK_SESSION_EXPIRED
)
1267 cifs_dbg(FYI
, "Session expired\n");
1272 smb2_oplock_response(struct cifs_tcon
*tcon
, struct cifs_fid
*fid
,
1273 struct cifsInodeInfo
*cinode
)
1275 if (tcon
->ses
->server
->capabilities
& SMB2_GLOBAL_CAP_LEASING
)
1276 return SMB2_lease_break(0, tcon
, cinode
->lease_key
,
1277 smb2_get_lease_state(cinode
));
1279 return SMB2_oplock_break(0, tcon
, fid
->persistent_fid
,
1281 CIFS_CACHE_READ(cinode
) ? 1 : 0);
1285 smb2_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
1286 struct kstatfs
*buf
)
1289 __le16 srch_path
= 0; /* Null - open root of share */
1290 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1291 struct cifs_open_parms oparms
;
1292 struct cifs_fid fid
;
1295 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
1296 oparms
.disposition
= FILE_OPEN
;
1297 oparms
.create_options
= 0;
1299 oparms
.reconnect
= false;
1301 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
1304 buf
->f_type
= SMB2_MAGIC_NUMBER
;
1305 rc
= SMB2_QFS_info(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
1307 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
1312 smb2_compare_fids(struct cifsFileInfo
*ob1
, struct cifsFileInfo
*ob2
)
1314 return ob1
->fid
.persistent_fid
== ob2
->fid
.persistent_fid
&&
1315 ob1
->fid
.volatile_fid
== ob2
->fid
.volatile_fid
;
1319 smb2_mand_lock(const unsigned int xid
, struct cifsFileInfo
*cfile
, __u64 offset
,
1320 __u64 length
, __u32 type
, int lock
, int unlock
, bool wait
)
1322 if (unlock
&& !lock
)
1323 type
= SMB2_LOCKFLAG_UNLOCK
;
1324 return SMB2_lock(xid
, tlink_tcon(cfile
->tlink
),
1325 cfile
->fid
.persistent_fid
, cfile
->fid
.volatile_fid
,
1326 current
->tgid
, length
, offset
, type
, wait
);
1330 smb2_get_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
1332 memcpy(fid
->lease_key
, CIFS_I(inode
)->lease_key
, SMB2_LEASE_KEY_SIZE
);
1336 smb2_set_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
1338 memcpy(CIFS_I(inode
)->lease_key
, fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
1342 smb2_new_lease_key(struct cifs_fid
*fid
)
1344 generate_random_uuid(fid
->lease_key
);
1348 smb2_get_dfs_refer(const unsigned int xid
, struct cifs_ses
*ses
,
1349 const char *search_name
,
1350 struct dfs_info3_param
**target_nodes
,
1351 unsigned int *num_of_nodes
,
1352 const struct nls_table
*nls_codepage
, int remap
)
1355 __le16
*utf16_path
= NULL
;
1356 int utf16_path_len
= 0;
1357 struct cifs_tcon
*tcon
;
1358 struct fsctl_get_dfs_referral_req
*dfs_req
= NULL
;
1359 struct get_dfs_referral_rsp
*dfs_rsp
= NULL
;
1360 u32 dfs_req_size
= 0, dfs_rsp_size
= 0;
1362 cifs_dbg(FYI
, "smb2_get_dfs_refer path <%s>\n", search_name
);
1365 * Try to use the IPC tcon, otherwise just use any
1367 tcon
= ses
->tcon_ipc
;
1369 spin_lock(&cifs_tcp_ses_lock
);
1370 tcon
= list_first_entry_or_null(&ses
->tcon_list
,
1375 spin_unlock(&cifs_tcp_ses_lock
);
1379 cifs_dbg(VFS
, "session %p has no tcon available for a dfs referral request\n",
1385 utf16_path
= cifs_strndup_to_utf16(search_name
, PATH_MAX
,
1387 nls_codepage
, remap
);
1393 dfs_req_size
= sizeof(*dfs_req
) + utf16_path_len
;
1394 dfs_req
= kzalloc(dfs_req_size
, GFP_KERNEL
);
1400 /* Highest DFS referral version understood */
1401 dfs_req
->MaxReferralLevel
= DFS_VERSION
;
1403 /* Path to resolve in an UTF-16 null-terminated string */
1404 memcpy(dfs_req
->RequestFileName
, utf16_path
, utf16_path_len
);
1407 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
1408 FSCTL_DFS_GET_REFERRALS
,
1409 true /* is_fsctl */,
1410 (char *)dfs_req
, dfs_req_size
,
1411 (char **)&dfs_rsp
, &dfs_rsp_size
);
1412 } while (rc
== -EAGAIN
);
1416 cifs_dbg(VFS
, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc
);
1420 rc
= parse_dfs_referrals(dfs_rsp
, dfs_rsp_size
,
1421 num_of_nodes
, target_nodes
,
1422 nls_codepage
, remap
, search_name
,
1423 true /* is_unicode */);
1425 cifs_dbg(VFS
, "parse error in smb2_get_dfs_refer rc=%d\n", rc
);
1430 if (tcon
&& !tcon
->ipc
) {
1431 /* ipc tcons are not refcounted */
1432 spin_lock(&cifs_tcp_ses_lock
);
1434 spin_unlock(&cifs_tcp_ses_lock
);
1441 #define SMB2_SYMLINK_STRUCT_SIZE \
1442 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
1445 smb2_query_symlink(const unsigned int xid
, struct cifs_tcon
*tcon
,
1446 const char *full_path
, char **target_path
,
1447 struct cifs_sb_info
*cifs_sb
)
1451 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1452 struct cifs_open_parms oparms
;
1453 struct cifs_fid fid
;
1454 struct smb2_err_rsp
*err_buf
= NULL
;
1455 struct smb2_symlink_err_rsp
*symlink
;
1456 unsigned int sub_len
;
1457 unsigned int sub_offset
;
1458 unsigned int print_len
;
1459 unsigned int print_offset
;
1461 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, full_path
);
1463 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
1468 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
1469 oparms
.disposition
= FILE_OPEN
;
1470 oparms
.create_options
= 0;
1472 oparms
.reconnect
= false;
1474 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, &err_buf
);
1476 if (!rc
|| !err_buf
) {
1481 if (le32_to_cpu(err_buf
->ByteCount
) < sizeof(struct smb2_symlink_err_rsp
) ||
1482 get_rfc1002_length(err_buf
) + 4 < SMB2_SYMLINK_STRUCT_SIZE
) {
1487 /* open must fail on symlink - reset rc */
1489 symlink
= (struct smb2_symlink_err_rsp
*)err_buf
->ErrorData
;
1490 sub_len
= le16_to_cpu(symlink
->SubstituteNameLength
);
1491 sub_offset
= le16_to_cpu(symlink
->SubstituteNameOffset
);
1492 print_len
= le16_to_cpu(symlink
->PrintNameLength
);
1493 print_offset
= le16_to_cpu(symlink
->PrintNameOffset
);
1495 if (get_rfc1002_length(err_buf
) + 4 <
1496 SMB2_SYMLINK_STRUCT_SIZE
+ sub_offset
+ sub_len
) {
1501 if (get_rfc1002_length(err_buf
) + 4 <
1502 SMB2_SYMLINK_STRUCT_SIZE
+ print_offset
+ print_len
) {
1507 *target_path
= cifs_strndup_from_utf16(
1508 (char *)symlink
->PathBuffer
+ sub_offset
,
1509 sub_len
, true, cifs_sb
->local_nls
);
1510 if (!(*target_path
)) {
1514 convert_delimiter(*target_path
, '/');
1515 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
1520 #ifdef CONFIG_CIFS_ACL
1521 static struct cifs_ntsd
*
1522 get_smb2_acl_by_fid(struct cifs_sb_info
*cifs_sb
,
1523 const struct cifs_fid
*cifsfid
, u32
*pacllen
)
1525 struct cifs_ntsd
*pntsd
= NULL
;
1527 int rc
= -EOPNOTSUPP
;
1528 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
1531 return ERR_CAST(tlink
);
1534 cifs_dbg(FYI
, "trying to get acl\n");
1536 rc
= SMB2_query_acl(xid
, tlink_tcon(tlink
), cifsfid
->persistent_fid
,
1537 cifsfid
->volatile_fid
, (void **)&pntsd
, pacllen
);
1540 cifs_put_tlink(tlink
);
1542 cifs_dbg(FYI
, "%s: rc = %d ACL len %d\n", __func__
, rc
, *pacllen
);
1549 static struct cifs_ntsd
*
1550 get_smb2_acl_by_path(struct cifs_sb_info
*cifs_sb
,
1551 const char *path
, u32
*pacllen
)
1553 struct cifs_ntsd
*pntsd
= NULL
;
1554 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1557 struct cifs_tcon
*tcon
;
1558 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
1559 struct cifs_fid fid
;
1560 struct cifs_open_parms oparms
;
1563 cifs_dbg(FYI
, "get smb3 acl for path %s\n", path
);
1565 return ERR_CAST(tlink
);
1567 tcon
= tlink_tcon(tlink
);
1570 if (backup_cred(cifs_sb
))
1571 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
1573 oparms
.create_options
= 0;
1575 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
1577 return ERR_PTR(-ENOMEM
);
1580 oparms
.desired_access
= READ_CONTROL
;
1581 oparms
.disposition
= FILE_OPEN
;
1583 oparms
.reconnect
= false;
1585 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
1588 rc
= SMB2_query_acl(xid
, tlink_tcon(tlink
), fid
.persistent_fid
,
1589 fid
.volatile_fid
, (void **)&pntsd
, pacllen
);
1590 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
1593 cifs_put_tlink(tlink
);
1596 cifs_dbg(FYI
, "%s: rc = %d ACL len %d\n", __func__
, rc
, *pacllen
);
1602 #ifdef CONFIG_CIFS_ACL
1604 set_smb2_acl(struct cifs_ntsd
*pnntsd
, __u32 acllen
,
1605 struct inode
*inode
, const char *path
, int aclflag
)
1607 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1609 int rc
, access_flags
= 0;
1610 struct cifs_tcon
*tcon
;
1611 struct cifs_sb_info
*cifs_sb
= CIFS_SB(inode
->i_sb
);
1612 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
1613 struct cifs_fid fid
;
1614 struct cifs_open_parms oparms
;
1617 cifs_dbg(FYI
, "set smb3 acl for path %s\n", path
);
1619 return PTR_ERR(tlink
);
1621 tcon
= tlink_tcon(tlink
);
1624 if (backup_cred(cifs_sb
))
1625 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
1627 oparms
.create_options
= 0;
1629 if (aclflag
== CIFS_ACL_OWNER
|| aclflag
== CIFS_ACL_GROUP
)
1630 access_flags
= WRITE_OWNER
;
1632 access_flags
= WRITE_DAC
;
1634 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
1639 oparms
.desired_access
= access_flags
;
1640 oparms
.disposition
= FILE_OPEN
;
1643 oparms
.reconnect
= false;
1645 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
1648 rc
= SMB2_set_acl(xid
, tlink_tcon(tlink
), fid
.persistent_fid
,
1649 fid
.volatile_fid
, pnntsd
, acllen
, aclflag
);
1650 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
1653 cifs_put_tlink(tlink
);
1657 #endif /* CIFS_ACL */
1659 /* Retrieve an ACL from the server */
1660 static struct cifs_ntsd
*
1661 get_smb2_acl(struct cifs_sb_info
*cifs_sb
,
1662 struct inode
*inode
, const char *path
,
1665 struct cifs_ntsd
*pntsd
= NULL
;
1666 struct cifsFileInfo
*open_file
= NULL
;
1669 open_file
= find_readable_file(CIFS_I(inode
), true);
1671 return get_smb2_acl_by_path(cifs_sb
, path
, pacllen
);
1673 pntsd
= get_smb2_acl_by_fid(cifs_sb
, &open_file
->fid
, pacllen
);
1674 cifsFileInfo_put(open_file
);
1679 static long smb3_zero_range(struct file
*file
, struct cifs_tcon
*tcon
,
1680 loff_t offset
, loff_t len
, bool keep_size
)
1682 struct inode
*inode
;
1683 struct cifsInodeInfo
*cifsi
;
1684 struct cifsFileInfo
*cfile
= file
->private_data
;
1685 struct file_zero_data_information fsctl_buf
;
1691 inode
= d_inode(cfile
->dentry
);
1692 cifsi
= CIFS_I(inode
);
1694 /* if file not oplocked can't be sure whether asking to extend size */
1695 if (!CIFS_CACHE_READ(cifsi
))
1696 if (keep_size
== false)
1700 * Must check if file sparse since fallocate -z (zero range) assumes
1701 * non-sparse allocation
1703 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
))
1707 * need to make sure we are not asked to extend the file since the SMB3
1708 * fsctl does not change the file size. In the future we could change
1709 * this to zero the first part of the range then set the file size
1710 * which for a non sparse file would zero the newly extended range
1712 if (keep_size
== false)
1713 if (i_size_read(inode
) < offset
+ len
)
1716 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1718 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1719 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1721 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1722 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1723 true /* is_fctl */, (char *)&fsctl_buf
,
1724 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1729 static long smb3_punch_hole(struct file
*file
, struct cifs_tcon
*tcon
,
1730 loff_t offset
, loff_t len
)
1732 struct inode
*inode
;
1733 struct cifsInodeInfo
*cifsi
;
1734 struct cifsFileInfo
*cfile
= file
->private_data
;
1735 struct file_zero_data_information fsctl_buf
;
1738 __u8 set_sparse
= 1;
1742 inode
= d_inode(cfile
->dentry
);
1743 cifsi
= CIFS_I(inode
);
1745 /* Need to make file sparse, if not already, before freeing range. */
1746 /* Consider adding equivalent for compressed since it could also work */
1747 if (!smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
))
1750 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1752 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1753 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1755 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1756 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1757 true /* is_fctl */, (char *)&fsctl_buf
,
1758 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1763 static long smb3_simple_falloc(struct file
*file
, struct cifs_tcon
*tcon
,
1764 loff_t off
, loff_t len
, bool keep_size
)
1766 struct inode
*inode
;
1767 struct cifsInodeInfo
*cifsi
;
1768 struct cifsFileInfo
*cfile
= file
->private_data
;
1769 long rc
= -EOPNOTSUPP
;
1774 inode
= d_inode(cfile
->dentry
);
1775 cifsi
= CIFS_I(inode
);
1777 /* if file not oplocked can't be sure whether asking to extend size */
1778 if (!CIFS_CACHE_READ(cifsi
))
1779 if (keep_size
== false)
1783 * Files are non-sparse by default so falloc may be a no-op
1784 * Must check if file sparse. If not sparse, and not extending
1785 * then no need to do anything since file already allocated
1787 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) == 0) {
1788 if (keep_size
== true)
1790 /* check if extending file */
1791 else if (i_size_read(inode
) >= off
+ len
)
1792 /* not extending file and already not sparse */
1794 /* BB: in future add else clause to extend file */
1799 if ((keep_size
== true) || (i_size_read(inode
) >= off
+ len
)) {
1801 * Check if falloc starts within first few pages of file
1802 * and ends within a few pages of the end of file to
1803 * ensure that most of file is being forced to be
1804 * fallocated now. If so then setting whole file sparse
1805 * ie potentially making a few extra pages at the beginning
1806 * or end of the file non-sparse via set_sparse is harmless.
1808 if ((off
> 8192) || (off
+ len
+ 8192 < i_size_read(inode
)))
1811 rc
= smb2_set_sparse(xid
, tcon
, cfile
, inode
, false);
1813 /* BB: else ... in future add code to extend file and set sparse */
1821 static long smb3_fallocate(struct file
*file
, struct cifs_tcon
*tcon
, int mode
,
1822 loff_t off
, loff_t len
)
1824 /* KEEP_SIZE already checked for by do_fallocate */
1825 if (mode
& FALLOC_FL_PUNCH_HOLE
)
1826 return smb3_punch_hole(file
, tcon
, off
, len
);
1827 else if (mode
& FALLOC_FL_ZERO_RANGE
) {
1828 if (mode
& FALLOC_FL_KEEP_SIZE
)
1829 return smb3_zero_range(file
, tcon
, off
, len
, true);
1830 return smb3_zero_range(file
, tcon
, off
, len
, false);
1831 } else if (mode
== FALLOC_FL_KEEP_SIZE
)
1832 return smb3_simple_falloc(file
, tcon
, off
, len
, true);
1834 return smb3_simple_falloc(file
, tcon
, off
, len
, false);
1840 smb2_downgrade_oplock(struct TCP_Server_Info
*server
,
1841 struct cifsInodeInfo
*cinode
, bool set_level2
)
1844 server
->ops
->set_oplock_level(cinode
, SMB2_OPLOCK_LEVEL_II
,
1847 server
->ops
->set_oplock_level(cinode
, 0, 0, NULL
);
1851 smb2_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1852 unsigned int epoch
, bool *purge_cache
)
1855 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1857 if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
) {
1858 cinode
->oplock
= CIFS_CACHE_RHW_FLG
;
1859 cifs_dbg(FYI
, "Batch Oplock granted on inode %p\n",
1860 &cinode
->vfs_inode
);
1861 } else if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
) {
1862 cinode
->oplock
= CIFS_CACHE_RW_FLG
;
1863 cifs_dbg(FYI
, "Exclusive Oplock granted on inode %p\n",
1864 &cinode
->vfs_inode
);
1865 } else if (oplock
== SMB2_OPLOCK_LEVEL_II
) {
1866 cinode
->oplock
= CIFS_CACHE_READ_FLG
;
1867 cifs_dbg(FYI
, "Level II Oplock granted on inode %p\n",
1868 &cinode
->vfs_inode
);
1874 smb21_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1875 unsigned int epoch
, bool *purge_cache
)
1877 char message
[5] = {0};
1880 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1884 if (oplock
& SMB2_LEASE_READ_CACHING_HE
) {
1885 cinode
->oplock
|= CIFS_CACHE_READ_FLG
;
1886 strcat(message
, "R");
1888 if (oplock
& SMB2_LEASE_HANDLE_CACHING_HE
) {
1889 cinode
->oplock
|= CIFS_CACHE_HANDLE_FLG
;
1890 strcat(message
, "H");
1892 if (oplock
& SMB2_LEASE_WRITE_CACHING_HE
) {
1893 cinode
->oplock
|= CIFS_CACHE_WRITE_FLG
;
1894 strcat(message
, "W");
1896 if (!cinode
->oplock
)
1897 strcat(message
, "None");
1898 cifs_dbg(FYI
, "%s Lease granted on inode %p\n", message
,
1899 &cinode
->vfs_inode
);
1903 smb3_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1904 unsigned int epoch
, bool *purge_cache
)
1906 unsigned int old_oplock
= cinode
->oplock
;
1908 smb21_set_oplock_level(cinode
, oplock
, epoch
, purge_cache
);
1911 *purge_cache
= false;
1912 if (old_oplock
== CIFS_CACHE_READ_FLG
) {
1913 if (cinode
->oplock
== CIFS_CACHE_READ_FLG
&&
1914 (epoch
- cinode
->epoch
> 0))
1915 *purge_cache
= true;
1916 else if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1917 (epoch
- cinode
->epoch
> 1))
1918 *purge_cache
= true;
1919 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1920 (epoch
- cinode
->epoch
> 1))
1921 *purge_cache
= true;
1922 else if (cinode
->oplock
== 0 &&
1923 (epoch
- cinode
->epoch
> 0))
1924 *purge_cache
= true;
1925 } else if (old_oplock
== CIFS_CACHE_RH_FLG
) {
1926 if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1927 (epoch
- cinode
->epoch
> 0))
1928 *purge_cache
= true;
1929 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1930 (epoch
- cinode
->epoch
> 1))
1931 *purge_cache
= true;
1933 cinode
->epoch
= epoch
;
1938 smb2_is_read_op(__u32 oplock
)
1940 return oplock
== SMB2_OPLOCK_LEVEL_II
;
1944 smb21_is_read_op(__u32 oplock
)
1946 return (oplock
& SMB2_LEASE_READ_CACHING_HE
) &&
1947 !(oplock
& SMB2_LEASE_WRITE_CACHING_HE
);
1951 map_oplock_to_lease(u8 oplock
)
1953 if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
)
1954 return SMB2_LEASE_WRITE_CACHING
| SMB2_LEASE_READ_CACHING
;
1955 else if (oplock
== SMB2_OPLOCK_LEVEL_II
)
1956 return SMB2_LEASE_READ_CACHING
;
1957 else if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
)
1958 return SMB2_LEASE_HANDLE_CACHING
| SMB2_LEASE_READ_CACHING
|
1959 SMB2_LEASE_WRITE_CACHING
;
1964 smb2_create_lease_buf(u8
*lease_key
, u8 oplock
)
1966 struct create_lease
*buf
;
1968 buf
= kzalloc(sizeof(struct create_lease
), GFP_KERNEL
);
1972 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1973 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1974 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1976 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1977 (struct create_lease
, lcontext
));
1978 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context
));
1979 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1980 (struct create_lease
, Name
));
1981 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1982 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1991 smb3_create_lease_buf(u8
*lease_key
, u8 oplock
)
1993 struct create_lease_v2
*buf
;
1995 buf
= kzalloc(sizeof(struct create_lease_v2
), GFP_KERNEL
);
1999 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
2000 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
2001 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
2003 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
2004 (struct create_lease_v2
, lcontext
));
2005 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context_v2
));
2006 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
2007 (struct create_lease_v2
, Name
));
2008 buf
->ccontext
.NameLength
= cpu_to_le16(4);
2009 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
2018 smb2_parse_lease_buf(void *buf
, unsigned int *epoch
)
2020 struct create_lease
*lc
= (struct create_lease
*)buf
;
2022 *epoch
= 0; /* not used */
2023 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
2024 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
2025 return le32_to_cpu(lc
->lcontext
.LeaseState
);
2029 smb3_parse_lease_buf(void *buf
, unsigned int *epoch
)
2031 struct create_lease_v2
*lc
= (struct create_lease_v2
*)buf
;
2033 *epoch
= le16_to_cpu(lc
->lcontext
.Epoch
);
2034 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
2035 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
2036 return le32_to_cpu(lc
->lcontext
.LeaseState
);
2040 smb2_wp_retry_size(struct inode
*inode
)
2042 return min_t(unsigned int, CIFS_SB(inode
->i_sb
)->wsize
,
2043 SMB2_MAX_BUFFER_SIZE
);
2047 smb2_dir_needs_close(struct cifsFileInfo
*cfile
)
2049 return !cfile
->invalidHandle
;
2053 fill_transform_hdr(struct smb2_transform_hdr
*tr_hdr
, struct smb_rqst
*old_rq
)
2055 struct smb2_sync_hdr
*shdr
=
2056 (struct smb2_sync_hdr
*)old_rq
->rq_iov
[1].iov_base
;
2057 unsigned int orig_len
= get_rfc1002_length(old_rq
->rq_iov
[0].iov_base
);
2059 memset(tr_hdr
, 0, sizeof(struct smb2_transform_hdr
));
2060 tr_hdr
->ProtocolId
= SMB2_TRANSFORM_PROTO_NUM
;
2061 tr_hdr
->OriginalMessageSize
= cpu_to_le32(orig_len
);
2062 tr_hdr
->Flags
= cpu_to_le16(0x01);
2063 get_random_bytes(&tr_hdr
->Nonce
, SMB3_AES128CMM_NONCE
);
2064 memcpy(&tr_hdr
->SessionId
, &shdr
->SessionId
, 8);
2065 inc_rfc1001_len(tr_hdr
, sizeof(struct smb2_transform_hdr
) - 4);
2066 inc_rfc1001_len(tr_hdr
, orig_len
);
2069 static struct scatterlist
*
2070 init_sg(struct smb_rqst
*rqst
, u8
*sign
)
2072 unsigned int sg_len
= rqst
->rq_nvec
+ rqst
->rq_npages
+ 1;
2073 unsigned int assoc_data_len
= sizeof(struct smb2_transform_hdr
) - 24;
2074 struct scatterlist
*sg
;
2078 sg
= kmalloc_array(sg_len
, sizeof(struct scatterlist
), GFP_KERNEL
);
2082 sg_init_table(sg
, sg_len
);
2083 sg_set_buf(&sg
[0], rqst
->rq_iov
[0].iov_base
+ 24, assoc_data_len
);
2084 for (i
= 1; i
< rqst
->rq_nvec
; i
++)
2085 sg_set_buf(&sg
[i
], rqst
->rq_iov
[i
].iov_base
,
2086 rqst
->rq_iov
[i
].iov_len
);
2087 for (j
= 0; i
< sg_len
- 1; i
++, j
++) {
2088 unsigned int len
= (j
< rqst
->rq_npages
- 1) ? rqst
->rq_pagesz
2090 sg_set_page(&sg
[i
], rqst
->rq_pages
[j
], len
, 0);
2092 sg_set_buf(&sg
[sg_len
- 1], sign
, SMB2_SIGNATURE_SIZE
);
2097 smb2_get_enc_key(struct TCP_Server_Info
*server
, __u64 ses_id
, int enc
, u8
*key
)
2099 struct cifs_ses
*ses
;
2102 spin_lock(&cifs_tcp_ses_lock
);
2103 list_for_each_entry(ses
, &server
->smb_ses_list
, smb_ses_list
) {
2104 if (ses
->Suid
!= ses_id
)
2106 ses_enc_key
= enc
? ses
->smb3encryptionkey
:
2107 ses
->smb3decryptionkey
;
2108 memcpy(key
, ses_enc_key
, SMB3_SIGN_KEY_SIZE
);
2109 spin_unlock(&cifs_tcp_ses_lock
);
2112 spin_unlock(&cifs_tcp_ses_lock
);
2117 * Encrypt or decrypt @rqst message. @rqst has the following format:
2118 * iov[0] - transform header (associate data),
2119 * iov[1-N] and pages - data to encrypt.
2120 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
2124 crypt_message(struct TCP_Server_Info
*server
, struct smb_rqst
*rqst
, int enc
)
2126 struct smb2_transform_hdr
*tr_hdr
=
2127 (struct smb2_transform_hdr
*)rqst
->rq_iov
[0].iov_base
;
2128 unsigned int assoc_data_len
= sizeof(struct smb2_transform_hdr
) - 24;
2130 struct scatterlist
*sg
;
2131 u8 sign
[SMB2_SIGNATURE_SIZE
] = {};
2132 u8 key
[SMB3_SIGN_KEY_SIZE
];
2133 struct aead_request
*req
;
2135 unsigned int iv_len
;
2136 DECLARE_CRYPTO_WAIT(wait
);
2137 struct crypto_aead
*tfm
;
2138 unsigned int crypt_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
2140 rc
= smb2_get_enc_key(server
, tr_hdr
->SessionId
, enc
, key
);
2142 cifs_dbg(VFS
, "%s: Could not get %scryption key\n", __func__
,
2147 rc
= smb3_crypto_aead_allocate(server
);
2149 cifs_dbg(VFS
, "%s: crypto alloc failed\n", __func__
);
2153 tfm
= enc
? server
->secmech
.ccmaesencrypt
:
2154 server
->secmech
.ccmaesdecrypt
;
2155 rc
= crypto_aead_setkey(tfm
, key
, SMB3_SIGN_KEY_SIZE
);
2157 cifs_dbg(VFS
, "%s: Failed to set aead key %d\n", __func__
, rc
);
2161 rc
= crypto_aead_setauthsize(tfm
, SMB2_SIGNATURE_SIZE
);
2163 cifs_dbg(VFS
, "%s: Failed to set authsize %d\n", __func__
, rc
);
2167 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
2169 cifs_dbg(VFS
, "%s: Failed to alloc aead request", __func__
);
2174 memcpy(sign
, &tr_hdr
->Signature
, SMB2_SIGNATURE_SIZE
);
2175 crypt_len
+= SMB2_SIGNATURE_SIZE
;
2178 sg
= init_sg(rqst
, sign
);
2180 cifs_dbg(VFS
, "%s: Failed to init sg", __func__
);
2185 iv_len
= crypto_aead_ivsize(tfm
);
2186 iv
= kzalloc(iv_len
, GFP_KERNEL
);
2188 cifs_dbg(VFS
, "%s: Failed to alloc IV", __func__
);
2193 memcpy(iv
+ 1, (char *)tr_hdr
->Nonce
, SMB3_AES128CMM_NONCE
);
2195 aead_request_set_crypt(req
, sg
, sg
, crypt_len
, iv
);
2196 aead_request_set_ad(req
, assoc_data_len
);
2198 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
2199 crypto_req_done
, &wait
);
2201 rc
= crypto_wait_req(enc
? crypto_aead_encrypt(req
)
2202 : crypto_aead_decrypt(req
), &wait
);
2205 memcpy(&tr_hdr
->Signature
, sign
, SMB2_SIGNATURE_SIZE
);
2216 smb3_init_transform_rq(struct TCP_Server_Info
*server
, struct smb_rqst
*new_rq
,
2217 struct smb_rqst
*old_rq
)
2220 struct page
**pages
;
2221 struct smb2_transform_hdr
*tr_hdr
;
2222 unsigned int npages
= old_rq
->rq_npages
;
2226 pages
= kmalloc_array(npages
, sizeof(struct page
*), GFP_KERNEL
);
2230 new_rq
->rq_pages
= pages
;
2231 new_rq
->rq_npages
= old_rq
->rq_npages
;
2232 new_rq
->rq_pagesz
= old_rq
->rq_pagesz
;
2233 new_rq
->rq_tailsz
= old_rq
->rq_tailsz
;
2235 for (i
= 0; i
< npages
; i
++) {
2236 pages
[i
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
2238 goto err_free_pages
;
2241 iov
= kmalloc_array(old_rq
->rq_nvec
, sizeof(struct kvec
), GFP_KERNEL
);
2243 goto err_free_pages
;
2245 /* copy all iovs from the old except the 1st one (rfc1002 length) */
2246 memcpy(&iov
[1], &old_rq
->rq_iov
[1],
2247 sizeof(struct kvec
) * (old_rq
->rq_nvec
- 1));
2248 new_rq
->rq_iov
= iov
;
2249 new_rq
->rq_nvec
= old_rq
->rq_nvec
;
2251 tr_hdr
= kmalloc(sizeof(struct smb2_transform_hdr
), GFP_KERNEL
);
2255 /* fill the 1st iov with a transform header */
2256 fill_transform_hdr(tr_hdr
, old_rq
);
2257 new_rq
->rq_iov
[0].iov_base
= tr_hdr
;
2258 new_rq
->rq_iov
[0].iov_len
= sizeof(struct smb2_transform_hdr
);
2260 /* copy pages form the old */
2261 for (i
= 0; i
< npages
; i
++) {
2262 char *dst
= kmap(new_rq
->rq_pages
[i
]);
2263 char *src
= kmap(old_rq
->rq_pages
[i
]);
2264 unsigned int len
= (i
< npages
- 1) ? new_rq
->rq_pagesz
:
2266 memcpy(dst
, src
, len
);
2267 kunmap(new_rq
->rq_pages
[i
]);
2268 kunmap(old_rq
->rq_pages
[i
]);
2271 rc
= crypt_message(server
, new_rq
, 1);
2272 cifs_dbg(FYI
, "encrypt message returned %d", rc
);
2274 goto err_free_tr_hdr
;
2283 for (i
= i
- 1; i
>= 0; i
--)
2290 smb3_free_transform_rq(struct smb_rqst
*rqst
)
2292 int i
= rqst
->rq_npages
- 1;
2295 put_page(rqst
->rq_pages
[i
]);
2296 kfree(rqst
->rq_pages
);
2297 /* free transform header */
2298 kfree(rqst
->rq_iov
[0].iov_base
);
2299 kfree(rqst
->rq_iov
);
2303 smb3_is_transform_hdr(void *buf
)
2305 struct smb2_transform_hdr
*trhdr
= buf
;
2307 return trhdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
;
2311 decrypt_raw_data(struct TCP_Server_Info
*server
, char *buf
,
2312 unsigned int buf_data_size
, struct page
**pages
,
2313 unsigned int npages
, unsigned int page_data_size
)
2316 struct smb_rqst rqst
= {NULL
};
2317 struct smb2_hdr
*hdr
;
2320 iov
[0].iov_base
= buf
;
2321 iov
[0].iov_len
= sizeof(struct smb2_transform_hdr
);
2322 iov
[1].iov_base
= buf
+ sizeof(struct smb2_transform_hdr
);
2323 iov
[1].iov_len
= buf_data_size
;
2327 rqst
.rq_pages
= pages
;
2328 rqst
.rq_npages
= npages
;
2329 rqst
.rq_pagesz
= PAGE_SIZE
;
2330 rqst
.rq_tailsz
= (page_data_size
% PAGE_SIZE
) ? : PAGE_SIZE
;
2332 rc
= crypt_message(server
, &rqst
, 0);
2333 cifs_dbg(FYI
, "decrypt message returned %d\n", rc
);
2338 memmove(buf
+ 4, iov
[1].iov_base
, buf_data_size
);
2339 hdr
= (struct smb2_hdr
*)buf
;
2340 hdr
->smb2_buf_length
= cpu_to_be32(buf_data_size
+ page_data_size
);
2341 server
->total_read
= buf_data_size
+ page_data_size
+ 4;
2347 read_data_into_pages(struct TCP_Server_Info
*server
, struct page
**pages
,
2348 unsigned int npages
, unsigned int len
)
2353 for (i
= 0; i
< npages
; i
++) {
2354 struct page
*page
= pages
[i
];
2358 if (len
>= PAGE_SIZE
) {
2359 /* enough data to fill the page */
2363 zero_user(page
, len
, PAGE_SIZE
- len
);
2366 length
= cifs_read_page_from_socket(server
, page
, n
);
2369 server
->total_read
+= length
;
2376 init_read_bvec(struct page
**pages
, unsigned int npages
, unsigned int data_size
,
2377 unsigned int cur_off
, struct bio_vec
**page_vec
)
2379 struct bio_vec
*bvec
;
2382 bvec
= kcalloc(npages
, sizeof(struct bio_vec
), GFP_KERNEL
);
2386 for (i
= 0; i
< npages
; i
++) {
2387 bvec
[i
].bv_page
= pages
[i
];
2388 bvec
[i
].bv_offset
= (i
== 0) ? cur_off
: 0;
2389 bvec
[i
].bv_len
= min_t(unsigned int, PAGE_SIZE
, data_size
);
2390 data_size
-= bvec
[i
].bv_len
;
2393 if (data_size
!= 0) {
2394 cifs_dbg(VFS
, "%s: something went wrong\n", __func__
);
2404 handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
,
2405 char *buf
, unsigned int buf_len
, struct page
**pages
,
2406 unsigned int npages
, unsigned int page_data_size
)
2408 unsigned int data_offset
;
2409 unsigned int data_len
;
2410 unsigned int cur_off
;
2411 unsigned int cur_page_idx
;
2412 unsigned int pad_len
;
2413 struct cifs_readdata
*rdata
= mid
->callback_data
;
2414 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
2415 struct bio_vec
*bvec
= NULL
;
2416 struct iov_iter iter
;
2419 bool use_rdma_mr
= false;
2421 if (shdr
->Command
!= SMB2_READ
) {
2422 cifs_dbg(VFS
, "only big read responses are supported\n");
2426 if (server
->ops
->is_session_expired
&&
2427 server
->ops
->is_session_expired(buf
)) {
2428 cifs_reconnect(server
);
2429 wake_up(&server
->response_q
);
2433 if (server
->ops
->is_status_pending
&&
2434 server
->ops
->is_status_pending(buf
, server
, 0))
2437 rdata
->result
= server
->ops
->map_error(buf
, false);
2438 if (rdata
->result
!= 0) {
2439 cifs_dbg(FYI
, "%s: server returned error %d\n",
2440 __func__
, rdata
->result
);
2441 dequeue_mid(mid
, rdata
->result
);
2445 data_offset
= server
->ops
->read_data_offset(buf
) + 4;
2446 #ifdef CONFIG_CIFS_SMB_DIRECT
2447 use_rdma_mr
= rdata
->mr
;
2449 data_len
= server
->ops
->read_data_length(buf
, use_rdma_mr
);
2451 if (data_offset
< server
->vals
->read_rsp_size
) {
2453 * win2k8 sometimes sends an offset of 0 when the read
2454 * is beyond the EOF. Treat it as if the data starts just after
2457 cifs_dbg(FYI
, "%s: data offset (%u) inside read response header\n",
2458 __func__
, data_offset
);
2459 data_offset
= server
->vals
->read_rsp_size
;
2460 } else if (data_offset
> MAX_CIFS_SMALL_BUFFER_SIZE
) {
2461 /* data_offset is beyond the end of smallbuf */
2462 cifs_dbg(FYI
, "%s: data offset (%u) beyond end of smallbuf\n",
2463 __func__
, data_offset
);
2464 rdata
->result
= -EIO
;
2465 dequeue_mid(mid
, rdata
->result
);
2469 pad_len
= data_offset
- server
->vals
->read_rsp_size
;
2471 if (buf_len
<= data_offset
) {
2472 /* read response payload is in pages */
2473 cur_page_idx
= pad_len
/ PAGE_SIZE
;
2474 cur_off
= pad_len
% PAGE_SIZE
;
2476 if (cur_page_idx
!= 0) {
2477 /* data offset is beyond the 1st page of response */
2478 cifs_dbg(FYI
, "%s: data offset (%u) beyond 1st page of response\n",
2479 __func__
, data_offset
);
2480 rdata
->result
= -EIO
;
2481 dequeue_mid(mid
, rdata
->result
);
2485 if (data_len
> page_data_size
- pad_len
) {
2486 /* data_len is corrupt -- discard frame */
2487 rdata
->result
= -EIO
;
2488 dequeue_mid(mid
, rdata
->result
);
2492 rdata
->result
= init_read_bvec(pages
, npages
, page_data_size
,
2494 if (rdata
->result
!= 0) {
2495 dequeue_mid(mid
, rdata
->result
);
2499 iov_iter_bvec(&iter
, WRITE
| ITER_BVEC
, bvec
, npages
, data_len
);
2500 } else if (buf_len
>= data_offset
+ data_len
) {
2501 /* read response payload is in buf */
2502 WARN_ONCE(npages
> 0, "read data can be either in buf or in pages");
2503 iov
.iov_base
= buf
+ data_offset
;
2504 iov
.iov_len
= data_len
;
2505 iov_iter_kvec(&iter
, WRITE
| ITER_KVEC
, &iov
, 1, data_len
);
2507 /* read response payload cannot be in both buf and pages */
2508 WARN_ONCE(1, "buf can not contain only a part of read data");
2509 rdata
->result
= -EIO
;
2510 dequeue_mid(mid
, rdata
->result
);
2514 /* set up first iov for signature check */
2515 rdata
->iov
[0].iov_base
= buf
;
2516 rdata
->iov
[0].iov_len
= 4;
2517 rdata
->iov
[1].iov_base
= buf
+ 4;
2518 rdata
->iov
[1].iov_len
= server
->vals
->read_rsp_size
- 4;
2519 cifs_dbg(FYI
, "0: iov_base=%p iov_len=%zu\n",
2520 rdata
->iov
[0].iov_base
, server
->vals
->read_rsp_size
);
2522 length
= rdata
->copy_into_pages(server
, rdata
, &iter
);
2529 dequeue_mid(mid
, false);
2534 receive_encrypted_read(struct TCP_Server_Info
*server
, struct mid_q_entry
**mid
)
2536 char *buf
= server
->smallbuf
;
2537 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
2538 unsigned int npages
;
2539 struct page
**pages
;
2541 unsigned int buflen
= get_rfc1002_length(buf
) + 4;
2545 len
= min_t(unsigned int, buflen
, server
->vals
->read_rsp_size
- 4 +
2546 sizeof(struct smb2_transform_hdr
)) - HEADER_SIZE(server
) + 1;
2548 rc
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1, len
);
2551 server
->total_read
+= rc
;
2553 len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
) + 4 -
2554 server
->vals
->read_rsp_size
;
2555 npages
= DIV_ROUND_UP(len
, PAGE_SIZE
);
2557 pages
= kmalloc_array(npages
, sizeof(struct page
*), GFP_KERNEL
);
2563 for (; i
< npages
; i
++) {
2564 pages
[i
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
2571 /* read read data into pages */
2572 rc
= read_data_into_pages(server
, pages
, npages
, len
);
2576 rc
= cifs_discard_remaining_data(server
);
2580 rc
= decrypt_raw_data(server
, buf
, server
->vals
->read_rsp_size
- 4,
2581 pages
, npages
, len
);
2585 *mid
= smb2_find_mid(server
, buf
);
2587 cifs_dbg(FYI
, "mid not found\n");
2589 cifs_dbg(FYI
, "mid found\n");
2590 (*mid
)->decrypted
= true;
2591 rc
= handle_read_data(server
, *mid
, buf
,
2592 server
->vals
->read_rsp_size
,
2593 pages
, npages
, len
);
2597 for (i
= i
- 1; i
>= 0; i
--)
2602 cifs_discard_remaining_data(server
);
2607 receive_encrypted_standard(struct TCP_Server_Info
*server
,
2608 struct mid_q_entry
**mid
)
2611 char *buf
= server
->smallbuf
;
2612 unsigned int pdu_length
= get_rfc1002_length(buf
);
2613 unsigned int buf_size
;
2614 struct mid_q_entry
*mid_entry
;
2616 /* switch to large buffer if too big for a small one */
2617 if (pdu_length
+ 4 > MAX_CIFS_SMALL_BUFFER_SIZE
) {
2618 server
->large_buf
= true;
2619 memcpy(server
->bigbuf
, buf
, server
->total_read
);
2620 buf
= server
->bigbuf
;
2623 /* now read the rest */
2624 length
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1,
2625 pdu_length
- HEADER_SIZE(server
) + 1 + 4);
2628 server
->total_read
+= length
;
2630 buf_size
= pdu_length
+ 4 - sizeof(struct smb2_transform_hdr
);
2631 length
= decrypt_raw_data(server
, buf
, buf_size
, NULL
, 0, 0);
2635 mid_entry
= smb2_find_mid(server
, buf
);
2636 if (mid_entry
== NULL
)
2637 cifs_dbg(FYI
, "mid not found\n");
2639 cifs_dbg(FYI
, "mid found\n");
2640 mid_entry
->decrypted
= true;
2645 if (mid_entry
&& mid_entry
->handle
)
2646 return mid_entry
->handle(server
, mid_entry
);
2648 return cifs_handle_standard(server
, mid_entry
);
2652 smb3_receive_transform(struct TCP_Server_Info
*server
, struct mid_q_entry
**mid
)
2654 char *buf
= server
->smallbuf
;
2655 unsigned int pdu_length
= get_rfc1002_length(buf
);
2656 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
2657 unsigned int orig_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
2659 if (pdu_length
+ 4 < sizeof(struct smb2_transform_hdr
) +
2660 sizeof(struct smb2_sync_hdr
)) {
2661 cifs_dbg(VFS
, "Transform message is too small (%u)\n",
2663 cifs_reconnect(server
);
2664 wake_up(&server
->response_q
);
2665 return -ECONNABORTED
;
2668 if (pdu_length
+ 4 < orig_len
+ sizeof(struct smb2_transform_hdr
)) {
2669 cifs_dbg(VFS
, "Transform message is broken\n");
2670 cifs_reconnect(server
);
2671 wake_up(&server
->response_q
);
2672 return -ECONNABORTED
;
2675 if (pdu_length
+ 4 > CIFSMaxBufSize
+ MAX_HEADER_SIZE(server
))
2676 return receive_encrypted_read(server
, mid
);
2678 return receive_encrypted_standard(server
, mid
);
2682 smb3_handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
)
2684 char *buf
= server
->large_buf
? server
->bigbuf
: server
->smallbuf
;
2686 return handle_read_data(server
, mid
, buf
, get_rfc1002_length(buf
) + 4,
2690 struct smb_version_operations smb20_operations
= {
2691 .compare_fids
= smb2_compare_fids
,
2692 .setup_request
= smb2_setup_request
,
2693 .setup_async_request
= smb2_setup_async_request
,
2694 .check_receive
= smb2_check_receive
,
2695 .add_credits
= smb2_add_credits
,
2696 .set_credits
= smb2_set_credits
,
2697 .get_credits_field
= smb2_get_credits_field
,
2698 .get_credits
= smb2_get_credits
,
2699 .wait_mtu_credits
= cifs_wait_mtu_credits
,
2700 .get_next_mid
= smb2_get_next_mid
,
2701 .read_data_offset
= smb2_read_data_offset
,
2702 .read_data_length
= smb2_read_data_length
,
2703 .map_error
= map_smb2_to_linux_error
,
2704 .find_mid
= smb2_find_mid
,
2705 .check_message
= smb2_check_message
,
2706 .dump_detail
= smb2_dump_detail
,
2707 .clear_stats
= smb2_clear_stats
,
2708 .print_stats
= smb2_print_stats
,
2709 .is_oplock_break
= smb2_is_valid_oplock_break
,
2710 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
2711 .downgrade_oplock
= smb2_downgrade_oplock
,
2712 .need_neg
= smb2_need_neg
,
2713 .negotiate
= smb2_negotiate
,
2714 .negotiate_wsize
= smb2_negotiate_wsize
,
2715 .negotiate_rsize
= smb2_negotiate_rsize
,
2716 .sess_setup
= SMB2_sess_setup
,
2717 .logoff
= SMB2_logoff
,
2718 .tree_connect
= SMB2_tcon
,
2719 .tree_disconnect
= SMB2_tdis
,
2720 .qfs_tcon
= smb2_qfs_tcon
,
2721 .is_path_accessible
= smb2_is_path_accessible
,
2722 .can_echo
= smb2_can_echo
,
2724 .query_path_info
= smb2_query_path_info
,
2725 .get_srv_inum
= smb2_get_srv_inum
,
2726 .query_file_info
= smb2_query_file_info
,
2727 .set_path_size
= smb2_set_path_size
,
2728 .set_file_size
= smb2_set_file_size
,
2729 .set_file_info
= smb2_set_file_info
,
2730 .set_compression
= smb2_set_compression
,
2731 .mkdir
= smb2_mkdir
,
2732 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2733 .rmdir
= smb2_rmdir
,
2734 .unlink
= smb2_unlink
,
2735 .rename
= smb2_rename_path
,
2736 .create_hardlink
= smb2_create_hardlink
,
2737 .query_symlink
= smb2_query_symlink
,
2738 .query_mf_symlink
= smb3_query_mf_symlink
,
2739 .create_mf_symlink
= smb3_create_mf_symlink
,
2740 .open
= smb2_open_file
,
2741 .set_fid
= smb2_set_fid
,
2742 .close
= smb2_close_file
,
2743 .flush
= smb2_flush_file
,
2744 .async_readv
= smb2_async_readv
,
2745 .async_writev
= smb2_async_writev
,
2746 .sync_read
= smb2_sync_read
,
2747 .sync_write
= smb2_sync_write
,
2748 .query_dir_first
= smb2_query_dir_first
,
2749 .query_dir_next
= smb2_query_dir_next
,
2750 .close_dir
= smb2_close_dir
,
2751 .calc_smb_size
= smb2_calc_size
,
2752 .is_status_pending
= smb2_is_status_pending
,
2753 .is_session_expired
= smb2_is_session_expired
,
2754 .oplock_response
= smb2_oplock_response
,
2755 .queryfs
= smb2_queryfs
,
2756 .mand_lock
= smb2_mand_lock
,
2757 .mand_unlock_range
= smb2_unlock_range
,
2758 .push_mand_locks
= smb2_push_mandatory_locks
,
2759 .get_lease_key
= smb2_get_lease_key
,
2760 .set_lease_key
= smb2_set_lease_key
,
2761 .new_lease_key
= smb2_new_lease_key
,
2762 .calc_signature
= smb2_calc_signature
,
2763 .is_read_op
= smb2_is_read_op
,
2764 .set_oplock_level
= smb2_set_oplock_level
,
2765 .create_lease_buf
= smb2_create_lease_buf
,
2766 .parse_lease_buf
= smb2_parse_lease_buf
,
2767 .copychunk_range
= smb2_copychunk_range
,
2768 .wp_retry_size
= smb2_wp_retry_size
,
2769 .dir_needs_close
= smb2_dir_needs_close
,
2770 .get_dfs_refer
= smb2_get_dfs_refer
,
2771 .select_sectype
= smb2_select_sectype
,
2772 #ifdef CONFIG_CIFS_XATTR
2773 .query_all_EAs
= smb2_query_eas
,
2774 .set_EA
= smb2_set_ea
,
2775 #endif /* CIFS_XATTR */
2776 #ifdef CONFIG_CIFS_ACL
2777 .get_acl
= get_smb2_acl
,
2778 .get_acl_by_fid
= get_smb2_acl_by_fid
,
2779 .set_acl
= set_smb2_acl
,
2780 #endif /* CIFS_ACL */
2783 struct smb_version_operations smb21_operations
= {
2784 .compare_fids
= smb2_compare_fids
,
2785 .setup_request
= smb2_setup_request
,
2786 .setup_async_request
= smb2_setup_async_request
,
2787 .check_receive
= smb2_check_receive
,
2788 .add_credits
= smb2_add_credits
,
2789 .set_credits
= smb2_set_credits
,
2790 .get_credits_field
= smb2_get_credits_field
,
2791 .get_credits
= smb2_get_credits
,
2792 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2793 .get_next_mid
= smb2_get_next_mid
,
2794 .read_data_offset
= smb2_read_data_offset
,
2795 .read_data_length
= smb2_read_data_length
,
2796 .map_error
= map_smb2_to_linux_error
,
2797 .find_mid
= smb2_find_mid
,
2798 .check_message
= smb2_check_message
,
2799 .dump_detail
= smb2_dump_detail
,
2800 .clear_stats
= smb2_clear_stats
,
2801 .print_stats
= smb2_print_stats
,
2802 .is_oplock_break
= smb2_is_valid_oplock_break
,
2803 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
2804 .downgrade_oplock
= smb2_downgrade_oplock
,
2805 .need_neg
= smb2_need_neg
,
2806 .negotiate
= smb2_negotiate
,
2807 .negotiate_wsize
= smb2_negotiate_wsize
,
2808 .negotiate_rsize
= smb2_negotiate_rsize
,
2809 .sess_setup
= SMB2_sess_setup
,
2810 .logoff
= SMB2_logoff
,
2811 .tree_connect
= SMB2_tcon
,
2812 .tree_disconnect
= SMB2_tdis
,
2813 .qfs_tcon
= smb2_qfs_tcon
,
2814 .is_path_accessible
= smb2_is_path_accessible
,
2815 .can_echo
= smb2_can_echo
,
2817 .query_path_info
= smb2_query_path_info
,
2818 .get_srv_inum
= smb2_get_srv_inum
,
2819 .query_file_info
= smb2_query_file_info
,
2820 .set_path_size
= smb2_set_path_size
,
2821 .set_file_size
= smb2_set_file_size
,
2822 .set_file_info
= smb2_set_file_info
,
2823 .set_compression
= smb2_set_compression
,
2824 .mkdir
= smb2_mkdir
,
2825 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2826 .rmdir
= smb2_rmdir
,
2827 .unlink
= smb2_unlink
,
2828 .rename
= smb2_rename_path
,
2829 .create_hardlink
= smb2_create_hardlink
,
2830 .query_symlink
= smb2_query_symlink
,
2831 .query_mf_symlink
= smb3_query_mf_symlink
,
2832 .create_mf_symlink
= smb3_create_mf_symlink
,
2833 .open
= smb2_open_file
,
2834 .set_fid
= smb2_set_fid
,
2835 .close
= smb2_close_file
,
2836 .flush
= smb2_flush_file
,
2837 .async_readv
= smb2_async_readv
,
2838 .async_writev
= smb2_async_writev
,
2839 .sync_read
= smb2_sync_read
,
2840 .sync_write
= smb2_sync_write
,
2841 .query_dir_first
= smb2_query_dir_first
,
2842 .query_dir_next
= smb2_query_dir_next
,
2843 .close_dir
= smb2_close_dir
,
2844 .calc_smb_size
= smb2_calc_size
,
2845 .is_status_pending
= smb2_is_status_pending
,
2846 .is_session_expired
= smb2_is_session_expired
,
2847 .oplock_response
= smb2_oplock_response
,
2848 .queryfs
= smb2_queryfs
,
2849 .mand_lock
= smb2_mand_lock
,
2850 .mand_unlock_range
= smb2_unlock_range
,
2851 .push_mand_locks
= smb2_push_mandatory_locks
,
2852 .get_lease_key
= smb2_get_lease_key
,
2853 .set_lease_key
= smb2_set_lease_key
,
2854 .new_lease_key
= smb2_new_lease_key
,
2855 .calc_signature
= smb2_calc_signature
,
2856 .is_read_op
= smb21_is_read_op
,
2857 .set_oplock_level
= smb21_set_oplock_level
,
2858 .create_lease_buf
= smb2_create_lease_buf
,
2859 .parse_lease_buf
= smb2_parse_lease_buf
,
2860 .copychunk_range
= smb2_copychunk_range
,
2861 .wp_retry_size
= smb2_wp_retry_size
,
2862 .dir_needs_close
= smb2_dir_needs_close
,
2863 .enum_snapshots
= smb3_enum_snapshots
,
2864 .get_dfs_refer
= smb2_get_dfs_refer
,
2865 .select_sectype
= smb2_select_sectype
,
2866 #ifdef CONFIG_CIFS_XATTR
2867 .query_all_EAs
= smb2_query_eas
,
2868 .set_EA
= smb2_set_ea
,
2869 #endif /* CIFS_XATTR */
2870 #ifdef CONFIG_CIFS_ACL
2871 .get_acl
= get_smb2_acl
,
2872 .get_acl_by_fid
= get_smb2_acl_by_fid
,
2873 .set_acl
= set_smb2_acl
,
2874 #endif /* CIFS_ACL */
2877 struct smb_version_operations smb30_operations
= {
2878 .compare_fids
= smb2_compare_fids
,
2879 .setup_request
= smb2_setup_request
,
2880 .setup_async_request
= smb2_setup_async_request
,
2881 .check_receive
= smb2_check_receive
,
2882 .add_credits
= smb2_add_credits
,
2883 .set_credits
= smb2_set_credits
,
2884 .get_credits_field
= smb2_get_credits_field
,
2885 .get_credits
= smb2_get_credits
,
2886 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2887 .get_next_mid
= smb2_get_next_mid
,
2888 .read_data_offset
= smb2_read_data_offset
,
2889 .read_data_length
= smb2_read_data_length
,
2890 .map_error
= map_smb2_to_linux_error
,
2891 .find_mid
= smb2_find_mid
,
2892 .check_message
= smb2_check_message
,
2893 .dump_detail
= smb2_dump_detail
,
2894 .clear_stats
= smb2_clear_stats
,
2895 .print_stats
= smb2_print_stats
,
2896 .dump_share_caps
= smb2_dump_share_caps
,
2897 .is_oplock_break
= smb2_is_valid_oplock_break
,
2898 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
2899 .downgrade_oplock
= smb2_downgrade_oplock
,
2900 .need_neg
= smb2_need_neg
,
2901 .negotiate
= smb2_negotiate
,
2902 .negotiate_wsize
= smb2_negotiate_wsize
,
2903 .negotiate_rsize
= smb2_negotiate_rsize
,
2904 .sess_setup
= SMB2_sess_setup
,
2905 .logoff
= SMB2_logoff
,
2906 .tree_connect
= SMB2_tcon
,
2907 .tree_disconnect
= SMB2_tdis
,
2908 .qfs_tcon
= smb3_qfs_tcon
,
2909 .is_path_accessible
= smb2_is_path_accessible
,
2910 .can_echo
= smb2_can_echo
,
2912 .query_path_info
= smb2_query_path_info
,
2913 .get_srv_inum
= smb2_get_srv_inum
,
2914 .query_file_info
= smb2_query_file_info
,
2915 .set_path_size
= smb2_set_path_size
,
2916 .set_file_size
= smb2_set_file_size
,
2917 .set_file_info
= smb2_set_file_info
,
2918 .set_compression
= smb2_set_compression
,
2919 .mkdir
= smb2_mkdir
,
2920 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2921 .rmdir
= smb2_rmdir
,
2922 .unlink
= smb2_unlink
,
2923 .rename
= smb2_rename_path
,
2924 .create_hardlink
= smb2_create_hardlink
,
2925 .query_symlink
= smb2_query_symlink
,
2926 .query_mf_symlink
= smb3_query_mf_symlink
,
2927 .create_mf_symlink
= smb3_create_mf_symlink
,
2928 .open
= smb2_open_file
,
2929 .set_fid
= smb2_set_fid
,
2930 .close
= smb2_close_file
,
2931 .flush
= smb2_flush_file
,
2932 .async_readv
= smb2_async_readv
,
2933 .async_writev
= smb2_async_writev
,
2934 .sync_read
= smb2_sync_read
,
2935 .sync_write
= smb2_sync_write
,
2936 .query_dir_first
= smb2_query_dir_first
,
2937 .query_dir_next
= smb2_query_dir_next
,
2938 .close_dir
= smb2_close_dir
,
2939 .calc_smb_size
= smb2_calc_size
,
2940 .is_status_pending
= smb2_is_status_pending
,
2941 .is_session_expired
= smb2_is_session_expired
,
2942 .oplock_response
= smb2_oplock_response
,
2943 .queryfs
= smb2_queryfs
,
2944 .mand_lock
= smb2_mand_lock
,
2945 .mand_unlock_range
= smb2_unlock_range
,
2946 .push_mand_locks
= smb2_push_mandatory_locks
,
2947 .get_lease_key
= smb2_get_lease_key
,
2948 .set_lease_key
= smb2_set_lease_key
,
2949 .new_lease_key
= smb2_new_lease_key
,
2950 .generate_signingkey
= generate_smb30signingkey
,
2951 .calc_signature
= smb3_calc_signature
,
2952 .set_integrity
= smb3_set_integrity
,
2953 .is_read_op
= smb21_is_read_op
,
2954 .set_oplock_level
= smb3_set_oplock_level
,
2955 .create_lease_buf
= smb3_create_lease_buf
,
2956 .parse_lease_buf
= smb3_parse_lease_buf
,
2957 .copychunk_range
= smb2_copychunk_range
,
2958 .duplicate_extents
= smb2_duplicate_extents
,
2959 .validate_negotiate
= smb3_validate_negotiate
,
2960 .wp_retry_size
= smb2_wp_retry_size
,
2961 .dir_needs_close
= smb2_dir_needs_close
,
2962 .fallocate
= smb3_fallocate
,
2963 .enum_snapshots
= smb3_enum_snapshots
,
2964 .init_transform_rq
= smb3_init_transform_rq
,
2965 .free_transform_rq
= smb3_free_transform_rq
,
2966 .is_transform_hdr
= smb3_is_transform_hdr
,
2967 .receive_transform
= smb3_receive_transform
,
2968 .get_dfs_refer
= smb2_get_dfs_refer
,
2969 .select_sectype
= smb2_select_sectype
,
2970 #ifdef CONFIG_CIFS_XATTR
2971 .query_all_EAs
= smb2_query_eas
,
2972 .set_EA
= smb2_set_ea
,
2973 #endif /* CIFS_XATTR */
2974 #ifdef CONFIG_CIFS_ACL
2975 .get_acl
= get_smb2_acl
,
2976 .get_acl_by_fid
= get_smb2_acl_by_fid
,
2977 .set_acl
= set_smb2_acl
,
2978 #endif /* CIFS_ACL */
2981 #ifdef CONFIG_CIFS_SMB311
2982 struct smb_version_operations smb311_operations
= {
2983 .compare_fids
= smb2_compare_fids
,
2984 .setup_request
= smb2_setup_request
,
2985 .setup_async_request
= smb2_setup_async_request
,
2986 .check_receive
= smb2_check_receive
,
2987 .add_credits
= smb2_add_credits
,
2988 .set_credits
= smb2_set_credits
,
2989 .get_credits_field
= smb2_get_credits_field
,
2990 .get_credits
= smb2_get_credits
,
2991 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2992 .get_next_mid
= smb2_get_next_mid
,
2993 .read_data_offset
= smb2_read_data_offset
,
2994 .read_data_length
= smb2_read_data_length
,
2995 .map_error
= map_smb2_to_linux_error
,
2996 .find_mid
= smb2_find_mid
,
2997 .check_message
= smb2_check_message
,
2998 .dump_detail
= smb2_dump_detail
,
2999 .clear_stats
= smb2_clear_stats
,
3000 .print_stats
= smb2_print_stats
,
3001 .dump_share_caps
= smb2_dump_share_caps
,
3002 .is_oplock_break
= smb2_is_valid_oplock_break
,
3003 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
3004 .downgrade_oplock
= smb2_downgrade_oplock
,
3005 .need_neg
= smb2_need_neg
,
3006 .negotiate
= smb2_negotiate
,
3007 .negotiate_wsize
= smb2_negotiate_wsize
,
3008 .negotiate_rsize
= smb2_negotiate_rsize
,
3009 .sess_setup
= SMB2_sess_setup
,
3010 .logoff
= SMB2_logoff
,
3011 .tree_connect
= SMB2_tcon
,
3012 .tree_disconnect
= SMB2_tdis
,
3013 .qfs_tcon
= smb3_qfs_tcon
,
3014 .is_path_accessible
= smb2_is_path_accessible
,
3015 .can_echo
= smb2_can_echo
,
3017 .query_path_info
= smb2_query_path_info
,
3018 .get_srv_inum
= smb2_get_srv_inum
,
3019 .query_file_info
= smb2_query_file_info
,
3020 .set_path_size
= smb2_set_path_size
,
3021 .set_file_size
= smb2_set_file_size
,
3022 .set_file_info
= smb2_set_file_info
,
3023 .set_compression
= smb2_set_compression
,
3024 .mkdir
= smb2_mkdir
,
3025 .mkdir_setinfo
= smb2_mkdir_setinfo
,
3026 .rmdir
= smb2_rmdir
,
3027 .unlink
= smb2_unlink
,
3028 .rename
= smb2_rename_path
,
3029 .create_hardlink
= smb2_create_hardlink
,
3030 .query_symlink
= smb2_query_symlink
,
3031 .query_mf_symlink
= smb3_query_mf_symlink
,
3032 .create_mf_symlink
= smb3_create_mf_symlink
,
3033 .open
= smb2_open_file
,
3034 .set_fid
= smb2_set_fid
,
3035 .close
= smb2_close_file
,
3036 .flush
= smb2_flush_file
,
3037 .async_readv
= smb2_async_readv
,
3038 .async_writev
= smb2_async_writev
,
3039 .sync_read
= smb2_sync_read
,
3040 .sync_write
= smb2_sync_write
,
3041 .query_dir_first
= smb2_query_dir_first
,
3042 .query_dir_next
= smb2_query_dir_next
,
3043 .close_dir
= smb2_close_dir
,
3044 .calc_smb_size
= smb2_calc_size
,
3045 .is_status_pending
= smb2_is_status_pending
,
3046 .is_session_expired
= smb2_is_session_expired
,
3047 .oplock_response
= smb2_oplock_response
,
3048 .queryfs
= smb2_queryfs
,
3049 .mand_lock
= smb2_mand_lock
,
3050 .mand_unlock_range
= smb2_unlock_range
,
3051 .push_mand_locks
= smb2_push_mandatory_locks
,
3052 .get_lease_key
= smb2_get_lease_key
,
3053 .set_lease_key
= smb2_set_lease_key
,
3054 .new_lease_key
= smb2_new_lease_key
,
3055 .generate_signingkey
= generate_smb311signingkey
,
3056 .calc_signature
= smb3_calc_signature
,
3057 .set_integrity
= smb3_set_integrity
,
3058 .is_read_op
= smb21_is_read_op
,
3059 .set_oplock_level
= smb3_set_oplock_level
,
3060 .create_lease_buf
= smb3_create_lease_buf
,
3061 .parse_lease_buf
= smb3_parse_lease_buf
,
3062 .copychunk_range
= smb2_copychunk_range
,
3063 .duplicate_extents
= smb2_duplicate_extents
,
3064 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
3065 .wp_retry_size
= smb2_wp_retry_size
,
3066 .dir_needs_close
= smb2_dir_needs_close
,
3067 .fallocate
= smb3_fallocate
,
3068 .enum_snapshots
= smb3_enum_snapshots
,
3069 .init_transform_rq
= smb3_init_transform_rq
,
3070 .free_transform_rq
= smb3_free_transform_rq
,
3071 .is_transform_hdr
= smb3_is_transform_hdr
,
3072 .receive_transform
= smb3_receive_transform
,
3073 .get_dfs_refer
= smb2_get_dfs_refer
,
3074 .select_sectype
= smb2_select_sectype
,
3075 #ifdef CONFIG_CIFS_XATTR
3076 .query_all_EAs
= smb2_query_eas
,
3077 .set_EA
= smb2_set_ea
,
3078 #endif /* CIFS_XATTR */
3080 #endif /* CIFS_SMB311 */
3082 struct smb_version_values smb20_values
= {
3083 .version_string
= SMB20_VERSION_STRING
,
3084 .protocol_id
= SMB20_PROT_ID
,
3085 .req_capabilities
= 0, /* MBZ */
3086 .large_lock_type
= 0,
3087 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3088 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3089 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3090 .header_size
= sizeof(struct smb2_hdr
),
3091 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3092 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3093 .lock_cmd
= SMB2_LOCK
,
3095 .cap_nt_find
= SMB2_NT_FIND
,
3096 .cap_large_files
= SMB2_LARGE_FILES
,
3097 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3098 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3099 .create_lease_size
= sizeof(struct create_lease
),
3102 struct smb_version_values smb21_values
= {
3103 .version_string
= SMB21_VERSION_STRING
,
3104 .protocol_id
= SMB21_PROT_ID
,
3105 .req_capabilities
= 0, /* MBZ on negotiate req until SMB3 dialect */
3106 .large_lock_type
= 0,
3107 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3108 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3109 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3110 .header_size
= sizeof(struct smb2_hdr
),
3111 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3112 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3113 .lock_cmd
= SMB2_LOCK
,
3115 .cap_nt_find
= SMB2_NT_FIND
,
3116 .cap_large_files
= SMB2_LARGE_FILES
,
3117 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3118 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3119 .create_lease_size
= sizeof(struct create_lease
),
3122 struct smb_version_values smb3any_values
= {
3123 .version_string
= SMB3ANY_VERSION_STRING
,
3124 .protocol_id
= SMB302_PROT_ID
, /* doesn't matter, send protocol array */
3125 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
3126 .large_lock_type
= 0,
3127 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3128 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3129 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3130 .header_size
= sizeof(struct smb2_hdr
),
3131 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3132 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3133 .lock_cmd
= SMB2_LOCK
,
3135 .cap_nt_find
= SMB2_NT_FIND
,
3136 .cap_large_files
= SMB2_LARGE_FILES
,
3137 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3138 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3139 .create_lease_size
= sizeof(struct create_lease_v2
),
3142 struct smb_version_values smbdefault_values
= {
3143 .version_string
= SMBDEFAULT_VERSION_STRING
,
3144 .protocol_id
= SMB302_PROT_ID
, /* doesn't matter, send protocol array */
3145 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
3146 .large_lock_type
= 0,
3147 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3148 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3149 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3150 .header_size
= sizeof(struct smb2_hdr
),
3151 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3152 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3153 .lock_cmd
= SMB2_LOCK
,
3155 .cap_nt_find
= SMB2_NT_FIND
,
3156 .cap_large_files
= SMB2_LARGE_FILES
,
3157 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3158 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3159 .create_lease_size
= sizeof(struct create_lease_v2
),
3162 struct smb_version_values smb30_values
= {
3163 .version_string
= SMB30_VERSION_STRING
,
3164 .protocol_id
= SMB30_PROT_ID
,
3165 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
3166 .large_lock_type
= 0,
3167 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3168 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3169 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3170 .header_size
= sizeof(struct smb2_hdr
),
3171 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3172 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3173 .lock_cmd
= SMB2_LOCK
,
3175 .cap_nt_find
= SMB2_NT_FIND
,
3176 .cap_large_files
= SMB2_LARGE_FILES
,
3177 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3178 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3179 .create_lease_size
= sizeof(struct create_lease_v2
),
3182 struct smb_version_values smb302_values
= {
3183 .version_string
= SMB302_VERSION_STRING
,
3184 .protocol_id
= SMB302_PROT_ID
,
3185 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
3186 .large_lock_type
= 0,
3187 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3188 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3189 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3190 .header_size
= sizeof(struct smb2_hdr
),
3191 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3192 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3193 .lock_cmd
= SMB2_LOCK
,
3195 .cap_nt_find
= SMB2_NT_FIND
,
3196 .cap_large_files
= SMB2_LARGE_FILES
,
3197 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3198 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3199 .create_lease_size
= sizeof(struct create_lease_v2
),
3202 #ifdef CONFIG_CIFS_SMB311
3203 struct smb_version_values smb311_values
= {
3204 .version_string
= SMB311_VERSION_STRING
,
3205 .protocol_id
= SMB311_PROT_ID
,
3206 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
3207 .large_lock_type
= 0,
3208 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3209 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3210 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3211 .header_size
= sizeof(struct smb2_hdr
),
3212 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3213 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3214 .lock_cmd
= SMB2_LOCK
,
3216 .cap_nt_find
= SMB2_NT_FIND
,
3217 .cap_large_files
= SMB2_LARGE_FILES
,
3218 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3219 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3220 .create_lease_size
= sizeof(struct create_lease_v2
),