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 = (struct smb2_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 = (struct smb2_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 kref_get(&mid->refcount);
207 spin_unlock(&GlobalMid_Lock);
211 spin_unlock(&GlobalMid_Lock);
216 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
218 #ifdef CONFIG_CIFS_DEBUG2
219 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
221 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
222 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
224 cifs_dbg(VFS, "smb buf %p len %u\n", buf,
225 server->ops->calc_smb_size(buf, server));
230 smb2_need_neg(struct TCP_Server_Info *server)
232 return server->max_read == 0;
236 smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
239 ses->server->CurrentMid = 0;
240 rc = SMB2_negotiate(xid, ses);
241 /* BB we probably don't need to retry with modern servers */
248 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
250 struct TCP_Server_Info *server = tcon->ses->server;
253 /* start with specified wsize, or default */
254 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
255 wsize = min_t(unsigned int, wsize, server->max_write);
256 #ifdef CONFIG_CIFS_SMB_DIRECT
259 wsize = min_t(unsigned int,
260 wsize, server->smbd_conn->max_fragmented_send_size);
262 wsize = min_t(unsigned int,
263 wsize, server->smbd_conn->max_readwrite_size);
266 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
267 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
273 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
275 struct TCP_Server_Info *server = tcon->ses->server;
278 /* start with specified rsize, or default */
279 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
280 rsize = min_t(unsigned int, rsize, server->max_read);
281 #ifdef CONFIG_CIFS_SMB_DIRECT
284 rsize = min_t(unsigned int,
285 rsize, server->smbd_conn->max_fragmented_recv_size);
287 rsize = min_t(unsigned int,
288 rsize, server->smbd_conn->max_readwrite_size);
292 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
293 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
300 parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
302 struct cifs_server_iface **iface_list,
305 struct network_interface_info_ioctl_rsp *p;
306 struct sockaddr_in *addr4;
307 struct sockaddr_in6 *addr6;
308 struct iface_info_ipv4 *p4;
309 struct iface_info_ipv6 *p6;
310 struct cifs_server_iface *info;
320 * Fist pass: count and sanity check
323 bytes_left = buf_len;
325 while (bytes_left >= sizeof(*p)) {
327 next = le32_to_cpu(p->Next);
329 bytes_left -= sizeof(*p);
332 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
337 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
342 if (bytes_left || p->Next)
343 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
347 * Second pass: extract info to internal structure
350 *iface_list = kcalloc(nb_iface, sizeof(**iface_list), GFP_KERNEL);
357 bytes_left = buf_len;
359 while (bytes_left >= sizeof(*p)) {
360 info->speed = le64_to_cpu(p->LinkSpeed);
361 info->rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE);
362 info->rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE);
364 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, *iface_count);
365 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
366 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
367 le32_to_cpu(p->Capability));
371 * The kernel and wire socket structures have the same
372 * layout and use network byte order but make the
373 * conversion explicit in case either one changes.
376 addr4 = (struct sockaddr_in *)&info->sockaddr;
377 p4 = (struct iface_info_ipv4 *)p->Buffer;
378 addr4->sin_family = AF_INET;
379 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
381 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
382 addr4->sin_port = cpu_to_be16(CIFS_PORT);
384 cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
388 addr6 = (struct sockaddr_in6 *)&info->sockaddr;
389 p6 = (struct iface_info_ipv6 *)p->Buffer;
390 addr6->sin6_family = AF_INET6;
391 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
393 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
394 addr6->sin6_flowinfo = 0;
395 addr6->sin6_scope_id = 0;
396 addr6->sin6_port = cpu_to_be16(CIFS_PORT);
398 cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
403 "%s: skipping unsupported socket family\n",
411 next = le32_to_cpu(p->Next);
414 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
434 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
437 unsigned int ret_data_len = 0;
438 struct network_interface_info_ioctl_rsp *out_buf = NULL;
439 struct cifs_server_iface *iface_list;
441 struct cifs_ses *ses = tcon->ses;
443 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
444 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
445 NULL /* no data input */, 0 /* no data input */,
446 (char **)&out_buf, &ret_data_len);
447 if (rc == -EOPNOTSUPP) {
449 "server does not support query network interfaces\n");
451 } else if (rc != 0) {
452 cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
456 rc = parse_server_interfaces(out_buf, ret_data_len,
457 &iface_list, &iface_count);
461 spin_lock(&ses->iface_lock);
462 kfree(ses->iface_list);
463 ses->iface_list = iface_list;
464 ses->iface_count = iface_count;
465 ses->iface_last_update = jiffies;
466 spin_unlock(&ses->iface_lock);
474 smb2_close_cached_fid(struct kref *ref)
476 struct cached_fid *cfid = container_of(ref, struct cached_fid,
479 if (cfid->is_valid) {
480 cifs_dbg(FYI, "clear cached root file handle\n");
481 SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid,
482 cfid->fid->volatile_fid);
483 cfid->is_valid = false;
487 void close_shroot(struct cached_fid *cfid)
489 mutex_lock(&cfid->fid_mutex);
490 kref_put(&cfid->refcount, smb2_close_cached_fid);
491 mutex_unlock(&cfid->fid_mutex);
495 smb2_cached_lease_break(struct work_struct *work)
497 struct cached_fid *cfid = container_of(work,
498 struct cached_fid, lease_break);
504 * Open the directory at the root of a share
506 int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid)
508 struct cifs_open_parms oparams;
510 __le16 srch_path = 0; /* Null - since an open of top of share */
511 u8 oplock = SMB2_OPLOCK_LEVEL_II;
513 mutex_lock(&tcon->crfid.fid_mutex);
514 if (tcon->crfid.is_valid) {
515 cifs_dbg(FYI, "found a cached root file handle\n");
516 memcpy(pfid, tcon->crfid.fid, sizeof(struct cifs_fid));
517 kref_get(&tcon->crfid.refcount);
518 mutex_unlock(&tcon->crfid.fid_mutex);
523 oparams.create_options = 0;
524 oparams.desired_access = FILE_READ_ATTRIBUTES;
525 oparams.disposition = FILE_OPEN;
527 oparams.reconnect = false;
529 rc = SMB2_open(xid, &oparams, &srch_path, &oplock, NULL, NULL, NULL);
531 memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid));
532 tcon->crfid.tcon = tcon;
533 tcon->crfid.is_valid = true;
534 kref_init(&tcon->crfid.refcount);
535 kref_get(&tcon->crfid.refcount);
537 mutex_unlock(&tcon->crfid.fid_mutex);
542 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
545 __le16 srch_path = 0; /* Null - open root of share */
546 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
547 struct cifs_open_parms oparms;
549 bool no_cached_open = tcon->nohandlecache;
552 oparms.desired_access = FILE_READ_ATTRIBUTES;
553 oparms.disposition = FILE_OPEN;
554 oparms.create_options = 0;
556 oparms.reconnect = false;
559 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
562 rc = open_shroot(xid, tcon, &fid);
567 SMB3_request_interfaces(xid, tcon);
569 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
570 FS_ATTRIBUTE_INFORMATION);
571 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
572 FS_DEVICE_INFORMATION);
573 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
574 FS_VOLUME_INFORMATION);
575 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
576 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
578 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
580 close_shroot(&tcon->crfid);
586 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
589 __le16 srch_path = 0; /* Null - open root of share */
590 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
591 struct cifs_open_parms oparms;
595 oparms.desired_access = FILE_READ_ATTRIBUTES;
596 oparms.disposition = FILE_OPEN;
597 oparms.create_options = 0;
599 oparms.reconnect = false;
601 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
605 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
606 FS_ATTRIBUTE_INFORMATION);
607 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
608 FS_DEVICE_INFORMATION);
609 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
614 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
615 struct cifs_sb_info *cifs_sb, const char *full_path)
619 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
620 struct cifs_open_parms oparms;
623 if ((*full_path == 0) && tcon->crfid.is_valid)
626 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
631 oparms.desired_access = FILE_READ_ATTRIBUTES;
632 oparms.disposition = FILE_OPEN;
633 oparms.create_options = 0;
635 oparms.reconnect = false;
637 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
643 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
649 smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
650 struct cifs_sb_info *cifs_sb, const char *full_path,
651 u64 *uniqueid, FILE_ALL_INFO *data)
653 *uniqueid = le64_to_cpu(data->IndexNumber);
658 smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
659 struct cifs_fid *fid, FILE_ALL_INFO *data)
662 struct smb2_file_all_info *smb2_data;
664 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
666 if (smb2_data == NULL)
669 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
672 move_smb2_info_to_cifs(data, smb2_data);
677 #ifdef CONFIG_CIFS_XATTR
679 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
680 struct smb2_file_full_ea_info *src, size_t src_size,
681 const unsigned char *ea_name)
684 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
686 size_t name_len, value_len, user_name_len;
688 while (src_size > 0) {
689 name = &src->ea_data[0];
690 name_len = (size_t)src->ea_name_length;
691 value = &src->ea_data[src->ea_name_length + 1];
692 value_len = (size_t)le16_to_cpu(src->ea_value_length);
698 if (src_size < 8 + name_len + 1 + value_len) {
699 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
705 if (ea_name_len == name_len &&
706 memcmp(ea_name, name, name_len) == 0) {
710 if (dst_size < value_len) {
714 memcpy(dst, value, value_len);
718 /* 'user.' plus a terminating null */
719 user_name_len = 5 + 1 + name_len;
723 if (dst_size >= user_name_len) {
724 dst_size -= user_name_len;
725 memcpy(dst, "user.", 5);
727 memcpy(dst, src->ea_data, name_len);
731 } else if (dst_size == 0) {
732 /* skip copy - calc size only */
734 /* stop before overrun buffer */
740 if (!src->next_entry_offset)
743 if (src_size < le32_to_cpu(src->next_entry_offset)) {
744 /* stop before overrun buffer */
748 src_size -= le32_to_cpu(src->next_entry_offset);
749 src = (void *)((char *)src +
750 le32_to_cpu(src->next_entry_offset));
753 /* didn't find the named attribute */
762 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
763 const unsigned char *path, const unsigned char *ea_name,
764 char *ea_data, size_t buf_size,
765 struct cifs_sb_info *cifs_sb)
769 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
770 struct cifs_open_parms oparms;
772 struct smb2_file_full_ea_info *smb2_data;
773 int ea_buf_size = SMB2_MIN_EA_BUF;
775 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
780 oparms.desired_access = FILE_READ_EA;
781 oparms.disposition = FILE_OPEN;
782 oparms.create_options = 0;
784 oparms.reconnect = false;
786 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
789 cifs_dbg(FYI, "open failed rc=%d\n", rc);
794 smb2_data = kzalloc(ea_buf_size, GFP_KERNEL);
795 if (smb2_data == NULL) {
796 SMB2_close(xid, tcon, fid.persistent_fid,
801 rc = SMB2_query_eas(xid, tcon, fid.persistent_fid,
803 ea_buf_size, smb2_data);
811 if (ea_buf_size > SMB2_MAX_EA_BUF) {
812 cifs_dbg(VFS, "EA size is too large\n");
813 SMB2_close(xid, tcon, fid.persistent_fid,
819 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
822 * If ea_name is NULL (listxattr) and there are no EAs, return 0 as it's
823 * not an error. Otherwise, the specified ea_name was not found.
826 rc = move_smb2_ea_to_cifs(ea_data, buf_size, smb2_data,
827 SMB2_MAX_EA_BUF, ea_name);
828 else if (!ea_name && rc == -ENODATA)
837 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
838 const char *path, const char *ea_name, const void *ea_value,
839 const __u16 ea_value_len, const struct nls_table *nls_codepage,
840 struct cifs_sb_info *cifs_sb)
844 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
845 struct cifs_open_parms oparms;
847 struct smb2_file_full_ea_info *ea;
848 int ea_name_len = strlen(ea_name);
851 if (ea_name_len > 255)
854 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
859 oparms.desired_access = FILE_WRITE_EA;
860 oparms.disposition = FILE_OPEN;
861 oparms.create_options = 0;
863 oparms.reconnect = false;
865 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
868 cifs_dbg(FYI, "open failed rc=%d\n", rc);
872 len = sizeof(ea) + ea_name_len + ea_value_len + 1;
873 ea = kzalloc(len, GFP_KERNEL);
875 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
879 ea->ea_name_length = ea_name_len;
880 ea->ea_value_length = cpu_to_le16(ea_value_len);
881 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
882 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
884 rc = SMB2_set_ea(xid, tcon, fid.persistent_fid, fid.volatile_fid, ea,
888 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
895 smb2_can_echo(struct TCP_Server_Info *server)
897 return server->echoes;
901 smb2_clear_stats(struct cifs_tcon *tcon)
904 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
905 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
906 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
911 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
913 seq_puts(m, "\n\tShare Capabilities:");
914 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
915 seq_puts(m, " DFS,");
916 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
917 seq_puts(m, " CONTINUOUS AVAILABILITY,");
918 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
919 seq_puts(m, " SCALEOUT,");
920 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
921 seq_puts(m, " CLUSTER,");
922 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
923 seq_puts(m, " ASYMMETRIC,");
924 if (tcon->capabilities == 0)
925 seq_puts(m, " None");
926 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
927 seq_puts(m, " Aligned,");
928 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
929 seq_puts(m, " Partition Aligned,");
930 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
931 seq_puts(m, " SSD,");
932 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
933 seq_puts(m, " TRIM-support,");
935 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
936 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
937 if (tcon->perf_sector_size)
938 seq_printf(m, "\tOptimal sector size: 0x%x",
939 tcon->perf_sector_size);
940 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
944 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
946 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
947 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
950 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
951 * totals (requests sent) since those SMBs are per-session not per tcon
953 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
954 (long long)(tcon->bytes_read),
955 (long long)(tcon->bytes_written));
956 seq_printf(m, "\nTreeConnects: %d total %d failed",
957 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
958 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
959 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
960 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
961 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
962 seq_printf(m, "\nCreates: %d total %d failed",
963 atomic_read(&sent[SMB2_CREATE_HE]),
964 atomic_read(&failed[SMB2_CREATE_HE]));
965 seq_printf(m, "\nCloses: %d total %d failed",
966 atomic_read(&sent[SMB2_CLOSE_HE]),
967 atomic_read(&failed[SMB2_CLOSE_HE]));
968 seq_printf(m, "\nFlushes: %d total %d failed",
969 atomic_read(&sent[SMB2_FLUSH_HE]),
970 atomic_read(&failed[SMB2_FLUSH_HE]));
971 seq_printf(m, "\nReads: %d total %d failed",
972 atomic_read(&sent[SMB2_READ_HE]),
973 atomic_read(&failed[SMB2_READ_HE]));
974 seq_printf(m, "\nWrites: %d total %d failed",
975 atomic_read(&sent[SMB2_WRITE_HE]),
976 atomic_read(&failed[SMB2_WRITE_HE]));
977 seq_printf(m, "\nLocks: %d total %d failed",
978 atomic_read(&sent[SMB2_LOCK_HE]),
979 atomic_read(&failed[SMB2_LOCK_HE]));
980 seq_printf(m, "\nIOCTLs: %d total %d failed",
981 atomic_read(&sent[SMB2_IOCTL_HE]),
982 atomic_read(&failed[SMB2_IOCTL_HE]));
983 seq_printf(m, "\nQueryDirectories: %d total %d failed",
984 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
985 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
986 seq_printf(m, "\nChangeNotifies: %d total %d failed",
987 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
988 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
989 seq_printf(m, "\nQueryInfos: %d total %d failed",
990 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
991 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
992 seq_printf(m, "\nSetInfos: %d total %d failed",
993 atomic_read(&sent[SMB2_SET_INFO_HE]),
994 atomic_read(&failed[SMB2_SET_INFO_HE]));
995 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
996 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
997 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1001 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1003 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1004 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1006 cfile->fid.persistent_fid = fid->persistent_fid;
1007 cfile->fid.volatile_fid = fid->volatile_fid;
1008 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1010 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1011 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1015 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1016 struct cifs_fid *fid)
1018 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1022 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1023 u64 persistent_fid, u64 volatile_fid,
1024 struct copychunk_ioctl *pcchunk)
1027 unsigned int ret_data_len;
1028 struct resume_key_req *res_key;
1030 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1031 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
1032 NULL, 0 /* no input */,
1033 (char **)&res_key, &ret_data_len);
1036 cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1037 goto req_res_key_exit;
1039 if (ret_data_len < sizeof(struct resume_key_req)) {
1040 cifs_dbg(VFS, "Invalid refcopy resume key length\n");
1042 goto req_res_key_exit;
1044 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1052 smb2_copychunk_range(const unsigned int xid,
1053 struct cifsFileInfo *srcfile,
1054 struct cifsFileInfo *trgtfile, u64 src_off,
1055 u64 len, u64 dest_off)
1058 unsigned int ret_data_len;
1059 struct copychunk_ioctl *pcchunk;
1060 struct copychunk_ioctl_rsp *retbuf = NULL;
1061 struct cifs_tcon *tcon;
1062 int chunks_copied = 0;
1063 bool chunk_sizes_updated = false;
1064 ssize_t bytes_written, total_bytes_written = 0;
1066 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1068 if (pcchunk == NULL)
1071 cifs_dbg(FYI, "in smb2_copychunk_range - about to call request res key\n");
1072 /* Request a key from the server to identify the source of the copy */
1073 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1074 srcfile->fid.persistent_fid,
1075 srcfile->fid.volatile_fid, pcchunk);
1077 /* Note: request_res_key sets res_key null only if rc !=0 */
1081 /* For now array only one chunk long, will make more flexible later */
1082 pcchunk->ChunkCount = cpu_to_le32(1);
1083 pcchunk->Reserved = 0;
1084 pcchunk->Reserved2 = 0;
1086 tcon = tlink_tcon(trgtfile->tlink);
1089 pcchunk->SourceOffset = cpu_to_le64(src_off);
1090 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1092 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
1094 /* Request server copy to target from src identified by key */
1095 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1096 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1097 true /* is_fsctl */, (char *)pcchunk,
1098 sizeof(struct copychunk_ioctl), (char **)&retbuf,
1102 sizeof(struct copychunk_ioctl_rsp)) {
1103 cifs_dbg(VFS, "invalid cchunk response size\n");
1107 if (retbuf->TotalBytesWritten == 0) {
1108 cifs_dbg(FYI, "no bytes copied\n");
1113 * Check if server claimed to write more than we asked
1115 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1116 le32_to_cpu(pcchunk->Length)) {
1117 cifs_dbg(VFS, "invalid copy chunk response\n");
1121 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1122 cifs_dbg(VFS, "invalid num chunks written\n");
1128 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1129 src_off += bytes_written;
1130 dest_off += bytes_written;
1131 len -= bytes_written;
1132 total_bytes_written += bytes_written;
1134 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1135 le32_to_cpu(retbuf->ChunksWritten),
1136 le32_to_cpu(retbuf->ChunkBytesWritten),
1138 } else if (rc == -EINVAL) {
1139 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1142 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1143 le32_to_cpu(retbuf->ChunksWritten),
1144 le32_to_cpu(retbuf->ChunkBytesWritten),
1145 le32_to_cpu(retbuf->TotalBytesWritten));
1148 * Check if this is the first request using these sizes,
1149 * (ie check if copy succeed once with original sizes
1150 * and check if the server gave us different sizes after
1151 * we already updated max sizes on previous request).
1152 * if not then why is the server returning an error now
1154 if ((chunks_copied != 0) || chunk_sizes_updated)
1157 /* Check that server is not asking us to grow size */
1158 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1159 tcon->max_bytes_chunk)
1160 tcon->max_bytes_chunk =
1161 le32_to_cpu(retbuf->ChunkBytesWritten);
1163 goto cchunk_out; /* server gave us bogus size */
1165 /* No need to change MaxChunks since already set to 1 */
1166 chunk_sizes_updated = true;
1177 return total_bytes_written;
1181 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1182 struct cifs_fid *fid)
1184 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1188 smb2_read_data_offset(char *buf)
1190 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1191 return rsp->DataOffset;
1195 smb2_read_data_length(char *buf, bool in_remaining)
1197 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1200 return le32_to_cpu(rsp->DataRemaining);
1202 return le32_to_cpu(rsp->DataLength);
1207 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1208 struct cifs_io_parms *parms, unsigned int *bytes_read,
1209 char **buf, int *buf_type)
1211 parms->persistent_fid = pfid->persistent_fid;
1212 parms->volatile_fid = pfid->volatile_fid;
1213 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1217 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1218 struct cifs_io_parms *parms, unsigned int *written,
1219 struct kvec *iov, unsigned long nr_segs)
1222 parms->persistent_fid = pfid->persistent_fid;
1223 parms->volatile_fid = pfid->volatile_fid;
1224 return SMB2_write(xid, parms, written, iov, nr_segs);
1227 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1228 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1229 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1231 struct cifsInodeInfo *cifsi;
1234 cifsi = CIFS_I(inode);
1236 /* if file already sparse don't bother setting sparse again */
1237 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1238 return true; /* already sparse */
1240 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1241 return true; /* already not sparse */
1244 * Can't check for sparse support on share the usual way via the
1245 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1246 * since Samba server doesn't set the flag on the share, yet
1247 * supports the set sparse FSCTL and returns sparse correctly
1248 * in the file attributes. If we fail setting sparse though we
1249 * mark that server does not support sparse files for this share
1250 * to avoid repeatedly sending the unsupported fsctl to server
1251 * if the file is repeatedly extended.
1253 if (tcon->broken_sparse_sup)
1256 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1257 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1259 &setsparse, 1, NULL, NULL);
1261 tcon->broken_sparse_sup = true;
1262 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1267 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1269 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1275 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1276 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1278 __le64 eof = cpu_to_le64(size);
1279 struct inode *inode;
1282 * If extending file more than one page make sparse. Many Linux fs
1283 * make files sparse by default when extending via ftruncate
1285 inode = d_inode(cfile->dentry);
1287 if (!set_alloc && (size > inode->i_size + 8192)) {
1288 __u8 set_sparse = 1;
1290 /* whether set sparse succeeds or not, extend the file */
1291 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1294 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1295 cfile->fid.volatile_fid, cfile->pid, &eof, false);
1299 smb2_duplicate_extents(const unsigned int xid,
1300 struct cifsFileInfo *srcfile,
1301 struct cifsFileInfo *trgtfile, u64 src_off,
1302 u64 len, u64 dest_off)
1305 unsigned int ret_data_len;
1306 struct duplicate_extents_to_file dup_ext_buf;
1307 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1309 /* server fileays advertise duplicate extent support with this flag */
1310 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1311 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1314 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1315 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1316 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1317 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1318 dup_ext_buf.ByteCount = cpu_to_le64(len);
1319 cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld",
1320 src_off, dest_off, len);
1322 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1324 goto duplicate_extents_out;
1326 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1327 trgtfile->fid.volatile_fid,
1328 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1329 true /* is_fsctl */,
1330 (char *)&dup_ext_buf,
1331 sizeof(struct duplicate_extents_to_file),
1335 if (ret_data_len > 0)
1336 cifs_dbg(FYI, "non-zero response length in duplicate extents");
1338 duplicate_extents_out:
1343 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1344 struct cifsFileInfo *cfile)
1346 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1347 cfile->fid.volatile_fid);
1351 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
1352 struct cifsFileInfo *cfile)
1354 struct fsctl_set_integrity_information_req integr_info;
1355 unsigned int ret_data_len;
1357 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
1358 integr_info.Flags = 0;
1359 integr_info.Reserved = 0;
1361 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1362 cfile->fid.volatile_fid,
1363 FSCTL_SET_INTEGRITY_INFORMATION,
1364 true /* is_fsctl */,
1365 (char *)&integr_info,
1366 sizeof(struct fsctl_set_integrity_information_req),
1373 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
1374 struct cifsFileInfo *cfile, void __user *ioc_buf)
1376 char *retbuf = NULL;
1377 unsigned int ret_data_len = 0;
1379 struct smb_snapshot_array snapshot_in;
1381 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1382 cfile->fid.volatile_fid,
1383 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
1384 true /* is_fsctl */,
1385 NULL, 0 /* no input data */,
1388 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
1393 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
1395 if (copy_from_user(&snapshot_in, ioc_buf,
1396 sizeof(struct smb_snapshot_array))) {
1401 if (snapshot_in.snapshot_array_size < sizeof(struct smb_snapshot_array)) {
1407 if (ret_data_len > snapshot_in.snapshot_array_size)
1408 ret_data_len = snapshot_in.snapshot_array_size;
1410 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
1419 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
1420 const char *path, struct cifs_sb_info *cifs_sb,
1421 struct cifs_fid *fid, __u16 search_flags,
1422 struct cifs_search_info *srch_inf)
1426 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1427 struct cifs_open_parms oparms;
1429 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1434 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
1435 oparms.disposition = FILE_OPEN;
1436 oparms.create_options = 0;
1438 oparms.reconnect = false;
1440 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
1443 cifs_dbg(FYI, "open dir failed rc=%d\n", rc);
1447 srch_inf->entries_in_buffer = 0;
1448 srch_inf->index_of_last_entry = 0;
1450 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
1451 fid->volatile_fid, 0, srch_inf);
1453 cifs_dbg(FYI, "query directory failed rc=%d\n", rc);
1454 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1460 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
1461 struct cifs_fid *fid, __u16 search_flags,
1462 struct cifs_search_info *srch_inf)
1464 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
1465 fid->volatile_fid, 0, srch_inf);
1469 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
1470 struct cifs_fid *fid)
1472 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1476 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
1477 * the number of credits and return true. Otherwise - return false.
1480 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
1482 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
1484 if (shdr->Status != STATUS_PENDING)
1488 spin_lock(&server->req_lock);
1489 server->credits += le16_to_cpu(shdr->CreditRequest);
1490 spin_unlock(&server->req_lock);
1491 wake_up(&server->request_q);
1498 smb2_is_session_expired(char *buf)
1500 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
1502 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
1503 shdr->Status != STATUS_USER_SESSION_DELETED)
1506 trace_smb3_ses_expired(shdr->TreeId, shdr->SessionId,
1507 le16_to_cpu(shdr->Command),
1508 le64_to_cpu(shdr->MessageId));
1509 cifs_dbg(FYI, "Session expired or deleted\n");
1515 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
1516 struct cifsInodeInfo *cinode)
1518 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
1519 return SMB2_lease_break(0, tcon, cinode->lease_key,
1520 smb2_get_lease_state(cinode));
1522 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
1524 CIFS_CACHE_READ(cinode) ? 1 : 0);
1528 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
1529 struct kstatfs *buf)
1532 __le16 srch_path = 0; /* Null - open root of share */
1533 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1534 struct cifs_open_parms oparms;
1535 struct cifs_fid fid;
1538 oparms.desired_access = FILE_READ_ATTRIBUTES;
1539 oparms.disposition = FILE_OPEN;
1540 oparms.create_options = 0;
1542 oparms.reconnect = false;
1544 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
1547 buf->f_type = SMB2_MAGIC_NUMBER;
1548 rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
1550 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
1555 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
1556 struct kstatfs *buf)
1559 __le16 srch_path = 0; /* Null - open root of share */
1560 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1561 struct cifs_open_parms oparms;
1562 struct cifs_fid fid;
1564 if (!tcon->posix_extensions)
1565 return smb2_queryfs(xid, tcon, buf);
1568 oparms.desired_access = FILE_READ_ATTRIBUTES;
1569 oparms.disposition = FILE_OPEN;
1570 oparms.create_options = 0;
1572 oparms.reconnect = false;
1574 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
1578 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
1579 fid.volatile_fid, buf);
1580 buf->f_type = SMB2_MAGIC_NUMBER;
1581 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
1586 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
1588 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
1589 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
1593 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
1594 __u64 length, __u32 type, int lock, int unlock, bool wait)
1596 if (unlock && !lock)
1597 type = SMB2_LOCKFLAG_UNLOCK;
1598 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
1599 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
1600 current->tgid, length, offset, type, wait);
1604 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
1606 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
1610 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
1612 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
1616 smb2_new_lease_key(struct cifs_fid *fid)
1618 generate_random_uuid(fid->lease_key);
1622 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
1623 const char *search_name,
1624 struct dfs_info3_param **target_nodes,
1625 unsigned int *num_of_nodes,
1626 const struct nls_table *nls_codepage, int remap)
1629 __le16 *utf16_path = NULL;
1630 int utf16_path_len = 0;
1631 struct cifs_tcon *tcon;
1632 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
1633 struct get_dfs_referral_rsp *dfs_rsp = NULL;
1634 u32 dfs_req_size = 0, dfs_rsp_size = 0;
1636 cifs_dbg(FYI, "smb2_get_dfs_refer path <%s>\n", search_name);
1639 * Try to use the IPC tcon, otherwise just use any
1641 tcon = ses->tcon_ipc;
1643 spin_lock(&cifs_tcp_ses_lock);
1644 tcon = list_first_entry_or_null(&ses->tcon_list,
1649 spin_unlock(&cifs_tcp_ses_lock);
1653 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
1659 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
1661 nls_codepage, remap);
1667 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
1668 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
1674 /* Highest DFS referral version understood */
1675 dfs_req->MaxReferralLevel = DFS_VERSION;
1677 /* Path to resolve in an UTF-16 null-terminated string */
1678 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
1681 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
1682 FSCTL_DFS_GET_REFERRALS,
1683 true /* is_fsctl */,
1684 (char *)dfs_req, dfs_req_size,
1685 (char **)&dfs_rsp, &dfs_rsp_size);
1686 } while (rc == -EAGAIN);
1689 if ((rc != -ENOENT) && (rc != -EOPNOTSUPP))
1690 cifs_dbg(VFS, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc);
1694 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
1695 num_of_nodes, target_nodes,
1696 nls_codepage, remap, search_name,
1697 true /* is_unicode */);
1699 cifs_dbg(VFS, "parse error in smb2_get_dfs_refer rc=%d\n", rc);
1704 if (tcon && !tcon->ipc) {
1705 /* ipc tcons are not refcounted */
1706 spin_lock(&cifs_tcp_ses_lock);
1708 spin_unlock(&cifs_tcp_ses_lock);
1715 #define SMB2_SYMLINK_STRUCT_SIZE \
1716 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
1719 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
1720 const char *full_path, char **target_path,
1721 struct cifs_sb_info *cifs_sb)
1725 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1726 struct cifs_open_parms oparms;
1727 struct cifs_fid fid;
1728 struct kvec err_iov = {NULL, 0};
1729 struct smb2_err_rsp *err_buf = NULL;
1731 struct smb2_symlink_err_rsp *symlink;
1732 unsigned int sub_len;
1733 unsigned int sub_offset;
1734 unsigned int print_len;
1735 unsigned int print_offset;
1737 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
1739 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
1744 oparms.desired_access = FILE_READ_ATTRIBUTES;
1745 oparms.disposition = FILE_OPEN;
1746 oparms.create_options = 0;
1748 oparms.reconnect = false;
1750 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_iov,
1752 if (!rc || !err_iov.iov_base) {
1757 err_buf = err_iov.iov_base;
1758 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
1759 err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) {
1764 /* open must fail on symlink - reset rc */
1766 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
1767 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
1768 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
1769 print_len = le16_to_cpu(symlink->PrintNameLength);
1770 print_offset = le16_to_cpu(symlink->PrintNameOffset);
1772 if (err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
1777 if (err_iov.iov_len <
1778 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
1783 *target_path = cifs_strndup_from_utf16(
1784 (char *)symlink->PathBuffer + sub_offset,
1785 sub_len, true, cifs_sb->local_nls);
1786 if (!(*target_path)) {
1790 convert_delimiter(*target_path, '/');
1791 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
1794 free_rsp_buf(resp_buftype, err_buf);
1800 #ifdef CONFIG_CIFS_ACL
1801 static struct cifs_ntsd *
1802 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
1803 const struct cifs_fid *cifsfid, u32 *pacllen)
1805 struct cifs_ntsd *pntsd = NULL;
1807 int rc = -EOPNOTSUPP;
1808 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1811 return ERR_CAST(tlink);
1814 cifs_dbg(FYI, "trying to get acl\n");
1816 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
1817 cifsfid->volatile_fid, (void **)&pntsd, pacllen);
1820 cifs_put_tlink(tlink);
1822 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
1829 static struct cifs_ntsd *
1830 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
1831 const char *path, u32 *pacllen)
1833 struct cifs_ntsd *pntsd = NULL;
1834 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1837 struct cifs_tcon *tcon;
1838 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1839 struct cifs_fid fid;
1840 struct cifs_open_parms oparms;
1843 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
1845 return ERR_CAST(tlink);
1847 tcon = tlink_tcon(tlink);
1850 if (backup_cred(cifs_sb))
1851 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1853 oparms.create_options = 0;
1855 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1863 oparms.desired_access = READ_CONTROL;
1864 oparms.disposition = FILE_OPEN;
1866 oparms.reconnect = false;
1868 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
1871 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
1872 fid.volatile_fid, (void **)&pntsd, pacllen);
1873 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
1876 cifs_put_tlink(tlink);
1879 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
1885 #ifdef CONFIG_CIFS_ACL
1887 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
1888 struct inode *inode, const char *path, int aclflag)
1890 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1892 int rc, access_flags = 0;
1893 struct cifs_tcon *tcon;
1894 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
1895 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1896 struct cifs_fid fid;
1897 struct cifs_open_parms oparms;
1900 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
1902 return PTR_ERR(tlink);
1904 tcon = tlink_tcon(tlink);
1907 if (backup_cred(cifs_sb))
1908 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1910 oparms.create_options = 0;
1912 if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP)
1913 access_flags = WRITE_OWNER;
1915 access_flags = WRITE_DAC;
1917 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1925 oparms.desired_access = access_flags;
1926 oparms.disposition = FILE_OPEN;
1929 oparms.reconnect = false;
1931 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
1934 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
1935 fid.volatile_fid, pnntsd, acllen, aclflag);
1936 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
1939 cifs_put_tlink(tlink);
1943 #endif /* CIFS_ACL */
1945 /* Retrieve an ACL from the server */
1946 static struct cifs_ntsd *
1947 get_smb2_acl(struct cifs_sb_info *cifs_sb,
1948 struct inode *inode, const char *path,
1951 struct cifs_ntsd *pntsd = NULL;
1952 struct cifsFileInfo *open_file = NULL;
1955 open_file = find_readable_file(CIFS_I(inode), true);
1957 return get_smb2_acl_by_path(cifs_sb, path, pacllen);
1959 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen);
1960 cifsFileInfo_put(open_file);
1965 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
1966 loff_t offset, loff_t len, bool keep_size)
1968 struct inode *inode;
1969 struct cifsInodeInfo *cifsi;
1970 struct cifsFileInfo *cfile = file->private_data;
1971 struct file_zero_data_information fsctl_buf;
1977 inode = d_inode(cfile->dentry);
1978 cifsi = CIFS_I(inode);
1980 /* if file not oplocked can't be sure whether asking to extend size */
1981 if (!CIFS_CACHE_READ(cifsi))
1982 if (keep_size == false) {
1989 * Must check if file sparse since fallocate -z (zero range) assumes
1990 * non-sparse allocation
1992 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
1999 * need to make sure we are not asked to extend the file since the SMB3
2000 * fsctl does not change the file size. In the future we could change
2001 * this to zero the first part of the range then set the file size
2002 * which for a non sparse file would zero the newly extended range
2004 if (keep_size == false)
2005 if (i_size_read(inode) < offset + len) {
2011 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
2013 fsctl_buf.FileOffset = cpu_to_le64(offset);
2014 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
2016 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2017 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
2018 true /* is_fctl */, (char *)&fsctl_buf,
2019 sizeof(struct file_zero_data_information), NULL, NULL);
2024 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
2025 loff_t offset, loff_t len)
2027 struct inode *inode;
2028 struct cifsInodeInfo *cifsi;
2029 struct cifsFileInfo *cfile = file->private_data;
2030 struct file_zero_data_information fsctl_buf;
2033 __u8 set_sparse = 1;
2037 inode = d_inode(cfile->dentry);
2038 cifsi = CIFS_I(inode);
2040 /* Need to make file sparse, if not already, before freeing range. */
2041 /* Consider adding equivalent for compressed since it could also work */
2042 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
2048 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
2050 fsctl_buf.FileOffset = cpu_to_le64(offset);
2051 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
2053 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2054 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
2055 true /* is_fctl */, (char *)&fsctl_buf,
2056 sizeof(struct file_zero_data_information), NULL, NULL);
2061 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
2062 loff_t off, loff_t len, bool keep_size)
2064 struct inode *inode;
2065 struct cifsInodeInfo *cifsi;
2066 struct cifsFileInfo *cfile = file->private_data;
2067 long rc = -EOPNOTSUPP;
2072 inode = d_inode(cfile->dentry);
2073 cifsi = CIFS_I(inode);
2075 /* if file not oplocked can't be sure whether asking to extend size */
2076 if (!CIFS_CACHE_READ(cifsi))
2077 if (keep_size == false) {
2083 * Files are non-sparse by default so falloc may be a no-op
2084 * Must check if file sparse. If not sparse, and not extending
2085 * then no need to do anything since file already allocated
2087 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
2088 if (keep_size == true)
2090 /* check if extending file */
2091 else if (i_size_read(inode) >= off + len)
2092 /* not extending file and already not sparse */
2094 /* BB: in future add else clause to extend file */
2101 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
2103 * Check if falloc starts within first few pages of file
2104 * and ends within a few pages of the end of file to
2105 * ensure that most of file is being forced to be
2106 * fallocated now. If so then setting whole file sparse
2107 * ie potentially making a few extra pages at the beginning
2108 * or end of the file non-sparse via set_sparse is harmless.
2110 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
2116 rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
2118 /* BB: else ... in future add code to extend file and set sparse */
2126 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
2127 loff_t off, loff_t len)
2129 /* KEEP_SIZE already checked for by do_fallocate */
2130 if (mode & FALLOC_FL_PUNCH_HOLE)
2131 return smb3_punch_hole(file, tcon, off, len);
2132 else if (mode & FALLOC_FL_ZERO_RANGE) {
2133 if (mode & FALLOC_FL_KEEP_SIZE)
2134 return smb3_zero_range(file, tcon, off, len, true);
2135 return smb3_zero_range(file, tcon, off, len, false);
2136 } else if (mode == FALLOC_FL_KEEP_SIZE)
2137 return smb3_simple_falloc(file, tcon, off, len, true);
2139 return smb3_simple_falloc(file, tcon, off, len, false);
2145 smb2_downgrade_oplock(struct TCP_Server_Info *server,
2146 struct cifsInodeInfo *cinode, bool set_level2)
2149 server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
2152 server->ops->set_oplock_level(cinode, 0, 0, NULL);
2156 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
2157 unsigned int epoch, bool *purge_cache)
2160 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
2162 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
2163 cinode->oplock = CIFS_CACHE_RHW_FLG;
2164 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
2165 &cinode->vfs_inode);
2166 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
2167 cinode->oplock = CIFS_CACHE_RW_FLG;
2168 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
2169 &cinode->vfs_inode);
2170 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
2171 cinode->oplock = CIFS_CACHE_READ_FLG;
2172 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
2173 &cinode->vfs_inode);
2179 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
2180 unsigned int epoch, bool *purge_cache)
2182 char message[5] = {0};
2185 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
2189 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
2190 cinode->oplock |= CIFS_CACHE_READ_FLG;
2191 strcat(message, "R");
2193 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
2194 cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
2195 strcat(message, "H");
2197 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
2198 cinode->oplock |= CIFS_CACHE_WRITE_FLG;
2199 strcat(message, "W");
2201 if (!cinode->oplock)
2202 strcat(message, "None");
2203 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
2204 &cinode->vfs_inode);
2208 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
2209 unsigned int epoch, bool *purge_cache)
2211 unsigned int old_oplock = cinode->oplock;
2213 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
2216 *purge_cache = false;
2217 if (old_oplock == CIFS_CACHE_READ_FLG) {
2218 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
2219 (epoch - cinode->epoch > 0))
2220 *purge_cache = true;
2221 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
2222 (epoch - cinode->epoch > 1))
2223 *purge_cache = true;
2224 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
2225 (epoch - cinode->epoch > 1))
2226 *purge_cache = true;
2227 else if (cinode->oplock == 0 &&
2228 (epoch - cinode->epoch > 0))
2229 *purge_cache = true;
2230 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
2231 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
2232 (epoch - cinode->epoch > 0))
2233 *purge_cache = true;
2234 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
2235 (epoch - cinode->epoch > 1))
2236 *purge_cache = true;
2238 cinode->epoch = epoch;
2243 smb2_is_read_op(__u32 oplock)
2245 return oplock == SMB2_OPLOCK_LEVEL_II;
2249 smb21_is_read_op(__u32 oplock)
2251 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
2252 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
2256 map_oplock_to_lease(u8 oplock)
2258 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
2259 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
2260 else if (oplock == SMB2_OPLOCK_LEVEL_II)
2261 return SMB2_LEASE_READ_CACHING;
2262 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
2263 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
2264 SMB2_LEASE_WRITE_CACHING;
2269 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
2271 struct create_lease *buf;
2273 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
2277 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
2278 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
2280 buf->ccontext.DataOffset = cpu_to_le16(offsetof
2281 (struct create_lease, lcontext));
2282 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
2283 buf->ccontext.NameOffset = cpu_to_le16(offsetof
2284 (struct create_lease, Name));
2285 buf->ccontext.NameLength = cpu_to_le16(4);
2286 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
2295 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
2297 struct create_lease_v2 *buf;
2299 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
2303 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
2304 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
2306 buf->ccontext.DataOffset = cpu_to_le16(offsetof
2307 (struct create_lease_v2, lcontext));
2308 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
2309 buf->ccontext.NameOffset = cpu_to_le16(offsetof
2310 (struct create_lease_v2, Name));
2311 buf->ccontext.NameLength = cpu_to_le16(4);
2312 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
2321 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
2323 struct create_lease *lc = (struct create_lease *)buf;
2325 *epoch = 0; /* not used */
2326 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
2327 return SMB2_OPLOCK_LEVEL_NOCHANGE;
2328 return le32_to_cpu(lc->lcontext.LeaseState);
2332 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
2334 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
2336 *epoch = le16_to_cpu(lc->lcontext.Epoch);
2337 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
2338 return SMB2_OPLOCK_LEVEL_NOCHANGE;
2340 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
2341 return le32_to_cpu(lc->lcontext.LeaseState);
2345 smb2_wp_retry_size(struct inode *inode)
2347 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
2348 SMB2_MAX_BUFFER_SIZE);
2352 smb2_dir_needs_close(struct cifsFileInfo *cfile)
2354 return !cfile->invalidHandle;
2358 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
2359 struct smb_rqst *old_rq)
2361 struct smb2_sync_hdr *shdr =
2362 (struct smb2_sync_hdr *)old_rq->rq_iov[0].iov_base;
2364 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
2365 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
2366 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
2367 tr_hdr->Flags = cpu_to_le16(0x01);
2368 get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
2369 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
2372 /* We can not use the normal sg_set_buf() as we will sometimes pass a
2373 * stack object as buf.
2375 static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
2376 unsigned int buflen)
2378 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
2382 * rqst->rq_iov[0] is transform header
2383 * rqst->rq_iov[1+] data to be encrypted/decrypted
2385 static struct scatterlist *
2386 init_sg(struct smb_rqst *rqst, u8 *sign)
2388 unsigned int sg_len = rqst->rq_nvec + rqst->rq_npages + 1;
2389 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
2390 struct scatterlist *sg;
2394 sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
2398 sg_init_table(sg, sg_len);
2399 smb2_sg_set_buf(&sg[0], rqst->rq_iov[0].iov_base + 20, assoc_data_len);
2400 for (i = 1; i < rqst->rq_nvec; i++)
2401 smb2_sg_set_buf(&sg[i], rqst->rq_iov[i].iov_base,
2402 rqst->rq_iov[i].iov_len);
2403 for (j = 0; i < sg_len - 1; i++, j++) {
2404 unsigned int len, offset;
2406 rqst_page_get_length(rqst, j, &len, &offset);
2407 sg_set_page(&sg[i], rqst->rq_pages[j], len, offset);
2409 smb2_sg_set_buf(&sg[sg_len - 1], sign, SMB2_SIGNATURE_SIZE);
2414 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
2416 struct cifs_ses *ses;
2419 spin_lock(&cifs_tcp_ses_lock);
2420 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
2421 if (ses->Suid != ses_id)
2423 ses_enc_key = enc ? ses->smb3encryptionkey :
2424 ses->smb3decryptionkey;
2425 memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE);
2426 spin_unlock(&cifs_tcp_ses_lock);
2429 spin_unlock(&cifs_tcp_ses_lock);
2434 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
2435 * iov[0] - transform header (associate data),
2436 * iov[1-N] - SMB2 header and pages - data to encrypt.
2437 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
2441 crypt_message(struct TCP_Server_Info *server, struct smb_rqst *rqst, int enc)
2443 struct smb2_transform_hdr *tr_hdr =
2444 (struct smb2_transform_hdr *)rqst->rq_iov[0].iov_base;
2445 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
2447 struct scatterlist *sg;
2448 u8 sign[SMB2_SIGNATURE_SIZE] = {};
2449 u8 key[SMB3_SIGN_KEY_SIZE];
2450 struct aead_request *req;
2452 unsigned int iv_len;
2453 DECLARE_CRYPTO_WAIT(wait);
2454 struct crypto_aead *tfm;
2455 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
2457 rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key);
2459 cifs_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
2464 rc = smb3_crypto_aead_allocate(server);
2466 cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__);
2470 tfm = enc ? server->secmech.ccmaesencrypt :
2471 server->secmech.ccmaesdecrypt;
2472 rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
2474 cifs_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
2478 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
2480 cifs_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
2484 req = aead_request_alloc(tfm, GFP_KERNEL);
2486 cifs_dbg(VFS, "%s: Failed to alloc aead request", __func__);
2491 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
2492 crypt_len += SMB2_SIGNATURE_SIZE;
2495 sg = init_sg(rqst, sign);
2497 cifs_dbg(VFS, "%s: Failed to init sg", __func__);
2502 iv_len = crypto_aead_ivsize(tfm);
2503 iv = kzalloc(iv_len, GFP_KERNEL);
2505 cifs_dbg(VFS, "%s: Failed to alloc IV", __func__);
2510 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
2512 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
2513 aead_request_set_ad(req, assoc_data_len);
2515 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
2516 crypto_req_done, &wait);
2518 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
2519 : crypto_aead_decrypt(req), &wait);
2522 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
2533 smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq,
2534 struct smb_rqst *old_rq)
2537 struct page **pages;
2538 struct smb2_transform_hdr *tr_hdr;
2539 unsigned int npages = old_rq->rq_npages;
2540 unsigned int orig_len;
2544 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
2548 new_rq->rq_pages = pages;
2549 new_rq->rq_offset = old_rq->rq_offset;
2550 new_rq->rq_npages = old_rq->rq_npages;
2551 new_rq->rq_pagesz = old_rq->rq_pagesz;
2552 new_rq->rq_tailsz = old_rq->rq_tailsz;
2554 for (i = 0; i < npages; i++) {
2555 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
2557 goto err_free_pages;
2560 iov = kmalloc_array(old_rq->rq_nvec + 1, sizeof(struct kvec),
2563 goto err_free_pages;
2565 /* copy all iovs from the old */
2566 memcpy(&iov[1], &old_rq->rq_iov[0],
2567 sizeof(struct kvec) * old_rq->rq_nvec);
2569 new_rq->rq_iov = iov;
2570 new_rq->rq_nvec = old_rq->rq_nvec + 1;
2572 tr_hdr = kmalloc(sizeof(struct smb2_transform_hdr), GFP_KERNEL);
2576 orig_len = smb_rqst_len(server, old_rq);
2578 /* fill the 2nd iov with a transform header */
2579 fill_transform_hdr(tr_hdr, orig_len, old_rq);
2580 new_rq->rq_iov[0].iov_base = tr_hdr;
2581 new_rq->rq_iov[0].iov_len = sizeof(struct smb2_transform_hdr);
2583 /* copy pages form the old */
2584 for (i = 0; i < npages; i++) {
2586 unsigned int offset, len;
2588 rqst_page_get_length(new_rq, i, &len, &offset);
2590 dst = (char *) kmap(new_rq->rq_pages[i]) + offset;
2591 src = (char *) kmap(old_rq->rq_pages[i]) + offset;
2593 memcpy(dst, src, len);
2594 kunmap(new_rq->rq_pages[i]);
2595 kunmap(old_rq->rq_pages[i]);
2598 rc = crypt_message(server, new_rq, 1);
2599 cifs_dbg(FYI, "encrypt message returned %d", rc);
2601 goto err_free_tr_hdr;
2610 for (i = i - 1; i >= 0; i--)
2617 smb3_free_transform_rq(struct smb_rqst *rqst)
2619 int i = rqst->rq_npages - 1;
2622 put_page(rqst->rq_pages[i]);
2623 kfree(rqst->rq_pages);
2624 /* free transform header */
2625 kfree(rqst->rq_iov[0].iov_base);
2626 kfree(rqst->rq_iov);
2630 smb3_is_transform_hdr(void *buf)
2632 struct smb2_transform_hdr *trhdr = buf;
2634 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
2638 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
2639 unsigned int buf_data_size, struct page **pages,
2640 unsigned int npages, unsigned int page_data_size)
2643 struct smb_rqst rqst = {NULL};
2646 iov[0].iov_base = buf;
2647 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
2648 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
2649 iov[1].iov_len = buf_data_size;
2653 rqst.rq_pages = pages;
2654 rqst.rq_npages = npages;
2655 rqst.rq_pagesz = PAGE_SIZE;
2656 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
2658 rc = crypt_message(server, &rqst, 0);
2659 cifs_dbg(FYI, "decrypt message returned %d\n", rc);
2664 memmove(buf, iov[1].iov_base, buf_data_size);
2666 server->total_read = buf_data_size + page_data_size;
2672 read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
2673 unsigned int npages, unsigned int len)
2678 for (i = 0; i < npages; i++) {
2679 struct page *page = pages[i];
2683 if (len >= PAGE_SIZE) {
2684 /* enough data to fill the page */
2688 zero_user(page, len, PAGE_SIZE - len);
2691 length = cifs_read_page_from_socket(server, page, 0, n);
2694 server->total_read += length;
2701 init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
2702 unsigned int cur_off, struct bio_vec **page_vec)
2704 struct bio_vec *bvec;
2707 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
2711 for (i = 0; i < npages; i++) {
2712 bvec[i].bv_page = pages[i];
2713 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
2714 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
2715 data_size -= bvec[i].bv_len;
2718 if (data_size != 0) {
2719 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
2729 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
2730 char *buf, unsigned int buf_len, struct page **pages,
2731 unsigned int npages, unsigned int page_data_size)
2733 unsigned int data_offset;
2734 unsigned int data_len;
2735 unsigned int cur_off;
2736 unsigned int cur_page_idx;
2737 unsigned int pad_len;
2738 struct cifs_readdata *rdata = mid->callback_data;
2739 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2740 struct bio_vec *bvec = NULL;
2741 struct iov_iter iter;
2744 bool use_rdma_mr = false;
2746 if (shdr->Command != SMB2_READ) {
2747 cifs_dbg(VFS, "only big read responses are supported\n");
2751 if (server->ops->is_session_expired &&
2752 server->ops->is_session_expired(buf)) {
2753 cifs_reconnect(server);
2754 wake_up(&server->response_q);
2758 if (server->ops->is_status_pending &&
2759 server->ops->is_status_pending(buf, server, 0))
2762 rdata->result = server->ops->map_error(buf, false);
2763 if (rdata->result != 0) {
2764 cifs_dbg(FYI, "%s: server returned error %d\n",
2765 __func__, rdata->result);
2766 dequeue_mid(mid, rdata->result);
2770 data_offset = server->ops->read_data_offset(buf);
2771 #ifdef CONFIG_CIFS_SMB_DIRECT
2772 use_rdma_mr = rdata->mr;
2774 data_len = server->ops->read_data_length(buf, use_rdma_mr);
2776 if (data_offset < server->vals->read_rsp_size) {
2778 * win2k8 sometimes sends an offset of 0 when the read
2779 * is beyond the EOF. Treat it as if the data starts just after
2782 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
2783 __func__, data_offset);
2784 data_offset = server->vals->read_rsp_size;
2785 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
2786 /* data_offset is beyond the end of smallbuf */
2787 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
2788 __func__, data_offset);
2789 rdata->result = -EIO;
2790 dequeue_mid(mid, rdata->result);
2794 pad_len = data_offset - server->vals->read_rsp_size;
2796 if (buf_len <= data_offset) {
2797 /* read response payload is in pages */
2798 cur_page_idx = pad_len / PAGE_SIZE;
2799 cur_off = pad_len % PAGE_SIZE;
2801 if (cur_page_idx != 0) {
2802 /* data offset is beyond the 1st page of response */
2803 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
2804 __func__, data_offset);
2805 rdata->result = -EIO;
2806 dequeue_mid(mid, rdata->result);
2810 if (data_len > page_data_size - pad_len) {
2811 /* data_len is corrupt -- discard frame */
2812 rdata->result = -EIO;
2813 dequeue_mid(mid, rdata->result);
2817 rdata->result = init_read_bvec(pages, npages, page_data_size,
2819 if (rdata->result != 0) {
2820 dequeue_mid(mid, rdata->result);
2824 iov_iter_bvec(&iter, WRITE | ITER_BVEC, bvec, npages, data_len);
2825 } else if (buf_len >= data_offset + data_len) {
2826 /* read response payload is in buf */
2827 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
2828 iov.iov_base = buf + data_offset;
2829 iov.iov_len = data_len;
2830 iov_iter_kvec(&iter, WRITE | ITER_KVEC, &iov, 1, data_len);
2832 /* read response payload cannot be in both buf and pages */
2833 WARN_ONCE(1, "buf can not contain only a part of read data");
2834 rdata->result = -EIO;
2835 dequeue_mid(mid, rdata->result);
2839 /* set up first iov for signature check */
2840 rdata->iov[0].iov_base = buf;
2841 rdata->iov[0].iov_len = 4;
2842 rdata->iov[1].iov_base = buf + 4;
2843 rdata->iov[1].iov_len = server->vals->read_rsp_size - 4;
2844 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
2845 rdata->iov[0].iov_base, server->vals->read_rsp_size);
2847 length = rdata->copy_into_pages(server, rdata, &iter);
2854 dequeue_mid(mid, false);
2859 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid)
2861 char *buf = server->smallbuf;
2862 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
2863 unsigned int npages;
2864 struct page **pages;
2866 unsigned int buflen = server->pdu_size;
2870 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
2871 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
2873 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
2876 server->total_read += rc;
2878 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
2879 server->vals->read_rsp_size;
2880 npages = DIV_ROUND_UP(len, PAGE_SIZE);
2882 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
2888 for (; i < npages; i++) {
2889 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
2896 /* read read data into pages */
2897 rc = read_data_into_pages(server, pages, npages, len);
2901 rc = cifs_discard_remaining_data(server);
2905 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
2906 pages, npages, len);
2910 *mid = smb2_find_mid(server, buf);
2912 cifs_dbg(FYI, "mid not found\n");
2914 cifs_dbg(FYI, "mid found\n");
2915 (*mid)->decrypted = true;
2916 rc = handle_read_data(server, *mid, buf,
2917 server->vals->read_rsp_size,
2918 pages, npages, len);
2922 for (i = i - 1; i >= 0; i--)
2927 cifs_discard_remaining_data(server);
2932 receive_encrypted_standard(struct TCP_Server_Info *server,
2933 struct mid_q_entry **mid)
2936 char *buf = server->smallbuf;
2937 unsigned int pdu_length = server->pdu_size;
2938 unsigned int buf_size;
2939 struct mid_q_entry *mid_entry;
2941 /* switch to large buffer if too big for a small one */
2942 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
2943 server->large_buf = true;
2944 memcpy(server->bigbuf, buf, server->total_read);
2945 buf = server->bigbuf;
2948 /* now read the rest */
2949 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
2950 pdu_length - HEADER_SIZE(server) + 1);
2953 server->total_read += length;
2955 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
2956 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0);
2960 mid_entry = smb2_find_mid(server, buf);
2961 if (mid_entry == NULL)
2962 cifs_dbg(FYI, "mid not found\n");
2964 cifs_dbg(FYI, "mid found\n");
2965 mid_entry->decrypted = true;
2970 if (mid_entry && mid_entry->handle)
2971 return mid_entry->handle(server, mid_entry);
2973 return cifs_handle_standard(server, mid_entry);
2977 smb3_receive_transform(struct TCP_Server_Info *server, struct mid_q_entry **mid)
2979 char *buf = server->smallbuf;
2980 unsigned int pdu_length = server->pdu_size;
2981 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
2982 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
2984 if (pdu_length < sizeof(struct smb2_transform_hdr) +
2985 sizeof(struct smb2_sync_hdr)) {
2986 cifs_dbg(VFS, "Transform message is too small (%u)\n",
2988 cifs_reconnect(server);
2989 wake_up(&server->response_q);
2990 return -ECONNABORTED;
2993 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
2994 cifs_dbg(VFS, "Transform message is broken\n");
2995 cifs_reconnect(server);
2996 wake_up(&server->response_q);
2997 return -ECONNABORTED;
3000 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server))
3001 return receive_encrypted_read(server, mid);
3003 return receive_encrypted_standard(server, mid);
3007 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
3009 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
3011 return handle_read_data(server, mid, buf, server->pdu_size,
3016 smb2_next_header(char *buf)
3018 struct smb2_sync_hdr *hdr = (struct smb2_sync_hdr *)buf;
3019 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
3021 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
3022 return sizeof(struct smb2_transform_hdr) +
3023 le32_to_cpu(t_hdr->OriginalMessageSize);
3025 return le32_to_cpu(hdr->NextCommand);
3028 struct smb_version_operations smb20_operations = {
3029 .compare_fids = smb2_compare_fids,
3030 .setup_request = smb2_setup_request,
3031 .setup_async_request = smb2_setup_async_request,
3032 .check_receive = smb2_check_receive,
3033 .add_credits = smb2_add_credits,
3034 .set_credits = smb2_set_credits,
3035 .get_credits_field = smb2_get_credits_field,
3036 .get_credits = smb2_get_credits,
3037 .wait_mtu_credits = cifs_wait_mtu_credits,
3038 .get_next_mid = smb2_get_next_mid,
3039 .read_data_offset = smb2_read_data_offset,
3040 .read_data_length = smb2_read_data_length,
3041 .map_error = map_smb2_to_linux_error,
3042 .find_mid = smb2_find_mid,
3043 .check_message = smb2_check_message,
3044 .dump_detail = smb2_dump_detail,
3045 .clear_stats = smb2_clear_stats,
3046 .print_stats = smb2_print_stats,
3047 .is_oplock_break = smb2_is_valid_oplock_break,
3048 .handle_cancelled_mid = smb2_handle_cancelled_mid,
3049 .downgrade_oplock = smb2_downgrade_oplock,
3050 .need_neg = smb2_need_neg,
3051 .negotiate = smb2_negotiate,
3052 .negotiate_wsize = smb2_negotiate_wsize,
3053 .negotiate_rsize = smb2_negotiate_rsize,
3054 .sess_setup = SMB2_sess_setup,
3055 .logoff = SMB2_logoff,
3056 .tree_connect = SMB2_tcon,
3057 .tree_disconnect = SMB2_tdis,
3058 .qfs_tcon = smb2_qfs_tcon,
3059 .is_path_accessible = smb2_is_path_accessible,
3060 .can_echo = smb2_can_echo,
3062 .query_path_info = smb2_query_path_info,
3063 .get_srv_inum = smb2_get_srv_inum,
3064 .query_file_info = smb2_query_file_info,
3065 .set_path_size = smb2_set_path_size,
3066 .set_file_size = smb2_set_file_size,
3067 .set_file_info = smb2_set_file_info,
3068 .set_compression = smb2_set_compression,
3069 .mkdir = smb2_mkdir,
3070 .mkdir_setinfo = smb2_mkdir_setinfo,
3071 .rmdir = smb2_rmdir,
3072 .unlink = smb2_unlink,
3073 .rename = smb2_rename_path,
3074 .create_hardlink = smb2_create_hardlink,
3075 .query_symlink = smb2_query_symlink,
3076 .query_mf_symlink = smb3_query_mf_symlink,
3077 .create_mf_symlink = smb3_create_mf_symlink,
3078 .open = smb2_open_file,
3079 .set_fid = smb2_set_fid,
3080 .close = smb2_close_file,
3081 .flush = smb2_flush_file,
3082 .async_readv = smb2_async_readv,
3083 .async_writev = smb2_async_writev,
3084 .sync_read = smb2_sync_read,
3085 .sync_write = smb2_sync_write,
3086 .query_dir_first = smb2_query_dir_first,
3087 .query_dir_next = smb2_query_dir_next,
3088 .close_dir = smb2_close_dir,
3089 .calc_smb_size = smb2_calc_size,
3090 .is_status_pending = smb2_is_status_pending,
3091 .is_session_expired = smb2_is_session_expired,
3092 .oplock_response = smb2_oplock_response,
3093 .queryfs = smb2_queryfs,
3094 .mand_lock = smb2_mand_lock,
3095 .mand_unlock_range = smb2_unlock_range,
3096 .push_mand_locks = smb2_push_mandatory_locks,
3097 .get_lease_key = smb2_get_lease_key,
3098 .set_lease_key = smb2_set_lease_key,
3099 .new_lease_key = smb2_new_lease_key,
3100 .calc_signature = smb2_calc_signature,
3101 .is_read_op = smb2_is_read_op,
3102 .set_oplock_level = smb2_set_oplock_level,
3103 .create_lease_buf = smb2_create_lease_buf,
3104 .parse_lease_buf = smb2_parse_lease_buf,
3105 .copychunk_range = smb2_copychunk_range,
3106 .wp_retry_size = smb2_wp_retry_size,
3107 .dir_needs_close = smb2_dir_needs_close,
3108 .get_dfs_refer = smb2_get_dfs_refer,
3109 .select_sectype = smb2_select_sectype,
3110 #ifdef CONFIG_CIFS_XATTR
3111 .query_all_EAs = smb2_query_eas,
3112 .set_EA = smb2_set_ea,
3113 #endif /* CIFS_XATTR */
3114 #ifdef CONFIG_CIFS_ACL
3115 .get_acl = get_smb2_acl,
3116 .get_acl_by_fid = get_smb2_acl_by_fid,
3117 .set_acl = set_smb2_acl,
3118 #endif /* CIFS_ACL */
3119 .next_header = smb2_next_header,
3122 struct smb_version_operations smb21_operations = {
3123 .compare_fids = smb2_compare_fids,
3124 .setup_request = smb2_setup_request,
3125 .setup_async_request = smb2_setup_async_request,
3126 .check_receive = smb2_check_receive,
3127 .add_credits = smb2_add_credits,
3128 .set_credits = smb2_set_credits,
3129 .get_credits_field = smb2_get_credits_field,
3130 .get_credits = smb2_get_credits,
3131 .wait_mtu_credits = smb2_wait_mtu_credits,
3132 .get_next_mid = smb2_get_next_mid,
3133 .read_data_offset = smb2_read_data_offset,
3134 .read_data_length = smb2_read_data_length,
3135 .map_error = map_smb2_to_linux_error,
3136 .find_mid = smb2_find_mid,
3137 .check_message = smb2_check_message,
3138 .dump_detail = smb2_dump_detail,
3139 .clear_stats = smb2_clear_stats,
3140 .print_stats = smb2_print_stats,
3141 .is_oplock_break = smb2_is_valid_oplock_break,
3142 .handle_cancelled_mid = smb2_handle_cancelled_mid,
3143 .downgrade_oplock = smb2_downgrade_oplock,
3144 .need_neg = smb2_need_neg,
3145 .negotiate = smb2_negotiate,
3146 .negotiate_wsize = smb2_negotiate_wsize,
3147 .negotiate_rsize = smb2_negotiate_rsize,
3148 .sess_setup = SMB2_sess_setup,
3149 .logoff = SMB2_logoff,
3150 .tree_connect = SMB2_tcon,
3151 .tree_disconnect = SMB2_tdis,
3152 .qfs_tcon = smb2_qfs_tcon,
3153 .is_path_accessible = smb2_is_path_accessible,
3154 .can_echo = smb2_can_echo,
3156 .query_path_info = smb2_query_path_info,
3157 .get_srv_inum = smb2_get_srv_inum,
3158 .query_file_info = smb2_query_file_info,
3159 .set_path_size = smb2_set_path_size,
3160 .set_file_size = smb2_set_file_size,
3161 .set_file_info = smb2_set_file_info,
3162 .set_compression = smb2_set_compression,
3163 .mkdir = smb2_mkdir,
3164 .mkdir_setinfo = smb2_mkdir_setinfo,
3165 .rmdir = smb2_rmdir,
3166 .unlink = smb2_unlink,
3167 .rename = smb2_rename_path,
3168 .create_hardlink = smb2_create_hardlink,
3169 .query_symlink = smb2_query_symlink,
3170 .query_mf_symlink = smb3_query_mf_symlink,
3171 .create_mf_symlink = smb3_create_mf_symlink,
3172 .open = smb2_open_file,
3173 .set_fid = smb2_set_fid,
3174 .close = smb2_close_file,
3175 .flush = smb2_flush_file,
3176 .async_readv = smb2_async_readv,
3177 .async_writev = smb2_async_writev,
3178 .sync_read = smb2_sync_read,
3179 .sync_write = smb2_sync_write,
3180 .query_dir_first = smb2_query_dir_first,
3181 .query_dir_next = smb2_query_dir_next,
3182 .close_dir = smb2_close_dir,
3183 .calc_smb_size = smb2_calc_size,
3184 .is_status_pending = smb2_is_status_pending,
3185 .is_session_expired = smb2_is_session_expired,
3186 .oplock_response = smb2_oplock_response,
3187 .queryfs = smb2_queryfs,
3188 .mand_lock = smb2_mand_lock,
3189 .mand_unlock_range = smb2_unlock_range,
3190 .push_mand_locks = smb2_push_mandatory_locks,
3191 .get_lease_key = smb2_get_lease_key,
3192 .set_lease_key = smb2_set_lease_key,
3193 .new_lease_key = smb2_new_lease_key,
3194 .calc_signature = smb2_calc_signature,
3195 .is_read_op = smb21_is_read_op,
3196 .set_oplock_level = smb21_set_oplock_level,
3197 .create_lease_buf = smb2_create_lease_buf,
3198 .parse_lease_buf = smb2_parse_lease_buf,
3199 .copychunk_range = smb2_copychunk_range,
3200 .wp_retry_size = smb2_wp_retry_size,
3201 .dir_needs_close = smb2_dir_needs_close,
3202 .enum_snapshots = smb3_enum_snapshots,
3203 .get_dfs_refer = smb2_get_dfs_refer,
3204 .select_sectype = smb2_select_sectype,
3205 #ifdef CONFIG_CIFS_XATTR
3206 .query_all_EAs = smb2_query_eas,
3207 .set_EA = smb2_set_ea,
3208 #endif /* CIFS_XATTR */
3209 #ifdef CONFIG_CIFS_ACL
3210 .get_acl = get_smb2_acl,
3211 .get_acl_by_fid = get_smb2_acl_by_fid,
3212 .set_acl = set_smb2_acl,
3213 #endif /* CIFS_ACL */
3214 .next_header = smb2_next_header,
3217 struct smb_version_operations smb30_operations = {
3218 .compare_fids = smb2_compare_fids,
3219 .setup_request = smb2_setup_request,
3220 .setup_async_request = smb2_setup_async_request,
3221 .check_receive = smb2_check_receive,
3222 .add_credits = smb2_add_credits,
3223 .set_credits = smb2_set_credits,
3224 .get_credits_field = smb2_get_credits_field,
3225 .get_credits = smb2_get_credits,
3226 .wait_mtu_credits = smb2_wait_mtu_credits,
3227 .get_next_mid = smb2_get_next_mid,
3228 .read_data_offset = smb2_read_data_offset,
3229 .read_data_length = smb2_read_data_length,
3230 .map_error = map_smb2_to_linux_error,
3231 .find_mid = smb2_find_mid,
3232 .check_message = smb2_check_message,
3233 .dump_detail = smb2_dump_detail,
3234 .clear_stats = smb2_clear_stats,
3235 .print_stats = smb2_print_stats,
3236 .dump_share_caps = smb2_dump_share_caps,
3237 .is_oplock_break = smb2_is_valid_oplock_break,
3238 .handle_cancelled_mid = smb2_handle_cancelled_mid,
3239 .downgrade_oplock = smb2_downgrade_oplock,
3240 .need_neg = smb2_need_neg,
3241 .negotiate = smb2_negotiate,
3242 .negotiate_wsize = smb2_negotiate_wsize,
3243 .negotiate_rsize = smb2_negotiate_rsize,
3244 .sess_setup = SMB2_sess_setup,
3245 .logoff = SMB2_logoff,
3246 .tree_connect = SMB2_tcon,
3247 .tree_disconnect = SMB2_tdis,
3248 .qfs_tcon = smb3_qfs_tcon,
3249 .is_path_accessible = smb2_is_path_accessible,
3250 .can_echo = smb2_can_echo,
3252 .query_path_info = smb2_query_path_info,
3253 .get_srv_inum = smb2_get_srv_inum,
3254 .query_file_info = smb2_query_file_info,
3255 .set_path_size = smb2_set_path_size,
3256 .set_file_size = smb2_set_file_size,
3257 .set_file_info = smb2_set_file_info,
3258 .set_compression = smb2_set_compression,
3259 .mkdir = smb2_mkdir,
3260 .mkdir_setinfo = smb2_mkdir_setinfo,
3261 .rmdir = smb2_rmdir,
3262 .unlink = smb2_unlink,
3263 .rename = smb2_rename_path,
3264 .create_hardlink = smb2_create_hardlink,
3265 .query_symlink = smb2_query_symlink,
3266 .query_mf_symlink = smb3_query_mf_symlink,
3267 .create_mf_symlink = smb3_create_mf_symlink,
3268 .open = smb2_open_file,
3269 .set_fid = smb2_set_fid,
3270 .close = smb2_close_file,
3271 .flush = smb2_flush_file,
3272 .async_readv = smb2_async_readv,
3273 .async_writev = smb2_async_writev,
3274 .sync_read = smb2_sync_read,
3275 .sync_write = smb2_sync_write,
3276 .query_dir_first = smb2_query_dir_first,
3277 .query_dir_next = smb2_query_dir_next,
3278 .close_dir = smb2_close_dir,
3279 .calc_smb_size = smb2_calc_size,
3280 .is_status_pending = smb2_is_status_pending,
3281 .is_session_expired = smb2_is_session_expired,
3282 .oplock_response = smb2_oplock_response,
3283 .queryfs = smb2_queryfs,
3284 .mand_lock = smb2_mand_lock,
3285 .mand_unlock_range = smb2_unlock_range,
3286 .push_mand_locks = smb2_push_mandatory_locks,
3287 .get_lease_key = smb2_get_lease_key,
3288 .set_lease_key = smb2_set_lease_key,
3289 .new_lease_key = smb2_new_lease_key,
3290 .generate_signingkey = generate_smb30signingkey,
3291 .calc_signature = smb3_calc_signature,
3292 .set_integrity = smb3_set_integrity,
3293 .is_read_op = smb21_is_read_op,
3294 .set_oplock_level = smb3_set_oplock_level,
3295 .create_lease_buf = smb3_create_lease_buf,
3296 .parse_lease_buf = smb3_parse_lease_buf,
3297 .copychunk_range = smb2_copychunk_range,
3298 .duplicate_extents = smb2_duplicate_extents,
3299 .validate_negotiate = smb3_validate_negotiate,
3300 .wp_retry_size = smb2_wp_retry_size,
3301 .dir_needs_close = smb2_dir_needs_close,
3302 .fallocate = smb3_fallocate,
3303 .enum_snapshots = smb3_enum_snapshots,
3304 .init_transform_rq = smb3_init_transform_rq,
3305 .free_transform_rq = smb3_free_transform_rq,
3306 .is_transform_hdr = smb3_is_transform_hdr,
3307 .receive_transform = smb3_receive_transform,
3308 .get_dfs_refer = smb2_get_dfs_refer,
3309 .select_sectype = smb2_select_sectype,
3310 #ifdef CONFIG_CIFS_XATTR
3311 .query_all_EAs = smb2_query_eas,
3312 .set_EA = smb2_set_ea,
3313 #endif /* CIFS_XATTR */
3314 #ifdef CONFIG_CIFS_ACL
3315 .get_acl = get_smb2_acl,
3316 .get_acl_by_fid = get_smb2_acl_by_fid,
3317 .set_acl = set_smb2_acl,
3318 #endif /* CIFS_ACL */
3319 .next_header = smb2_next_header,
3322 struct smb_version_operations smb311_operations = {
3323 .compare_fids = smb2_compare_fids,
3324 .setup_request = smb2_setup_request,
3325 .setup_async_request = smb2_setup_async_request,
3326 .check_receive = smb2_check_receive,
3327 .add_credits = smb2_add_credits,
3328 .set_credits = smb2_set_credits,
3329 .get_credits_field = smb2_get_credits_field,
3330 .get_credits = smb2_get_credits,
3331 .wait_mtu_credits = smb2_wait_mtu_credits,
3332 .get_next_mid = smb2_get_next_mid,
3333 .read_data_offset = smb2_read_data_offset,
3334 .read_data_length = smb2_read_data_length,
3335 .map_error = map_smb2_to_linux_error,
3336 .find_mid = smb2_find_mid,
3337 .check_message = smb2_check_message,
3338 .dump_detail = smb2_dump_detail,
3339 .clear_stats = smb2_clear_stats,
3340 .print_stats = smb2_print_stats,
3341 .dump_share_caps = smb2_dump_share_caps,
3342 .is_oplock_break = smb2_is_valid_oplock_break,
3343 .handle_cancelled_mid = smb2_handle_cancelled_mid,
3344 .downgrade_oplock = smb2_downgrade_oplock,
3345 .need_neg = smb2_need_neg,
3346 .negotiate = smb2_negotiate,
3347 .negotiate_wsize = smb2_negotiate_wsize,
3348 .negotiate_rsize = smb2_negotiate_rsize,
3349 .sess_setup = SMB2_sess_setup,
3350 .logoff = SMB2_logoff,
3351 .tree_connect = SMB2_tcon,
3352 .tree_disconnect = SMB2_tdis,
3353 .qfs_tcon = smb3_qfs_tcon,
3354 .is_path_accessible = smb2_is_path_accessible,
3355 .can_echo = smb2_can_echo,
3357 .query_path_info = smb2_query_path_info,
3358 .get_srv_inum = smb2_get_srv_inum,
3359 .query_file_info = smb2_query_file_info,
3360 .set_path_size = smb2_set_path_size,
3361 .set_file_size = smb2_set_file_size,
3362 .set_file_info = smb2_set_file_info,
3363 .set_compression = smb2_set_compression,
3364 .mkdir = smb2_mkdir,
3365 .mkdir_setinfo = smb2_mkdir_setinfo,
3366 .posix_mkdir = smb311_posix_mkdir,
3367 .rmdir = smb2_rmdir,
3368 .unlink = smb2_unlink,
3369 .rename = smb2_rename_path,
3370 .create_hardlink = smb2_create_hardlink,
3371 .query_symlink = smb2_query_symlink,
3372 .query_mf_symlink = smb3_query_mf_symlink,
3373 .create_mf_symlink = smb3_create_mf_symlink,
3374 .open = smb2_open_file,
3375 .set_fid = smb2_set_fid,
3376 .close = smb2_close_file,
3377 .flush = smb2_flush_file,
3378 .async_readv = smb2_async_readv,
3379 .async_writev = smb2_async_writev,
3380 .sync_read = smb2_sync_read,
3381 .sync_write = smb2_sync_write,
3382 .query_dir_first = smb2_query_dir_first,
3383 .query_dir_next = smb2_query_dir_next,
3384 .close_dir = smb2_close_dir,
3385 .calc_smb_size = smb2_calc_size,
3386 .is_status_pending = smb2_is_status_pending,
3387 .is_session_expired = smb2_is_session_expired,
3388 .oplock_response = smb2_oplock_response,
3389 .queryfs = smb311_queryfs,
3390 .mand_lock = smb2_mand_lock,
3391 .mand_unlock_range = smb2_unlock_range,
3392 .push_mand_locks = smb2_push_mandatory_locks,
3393 .get_lease_key = smb2_get_lease_key,
3394 .set_lease_key = smb2_set_lease_key,
3395 .new_lease_key = smb2_new_lease_key,
3396 .generate_signingkey = generate_smb311signingkey,
3397 .calc_signature = smb3_calc_signature,
3398 .set_integrity = smb3_set_integrity,
3399 .is_read_op = smb21_is_read_op,
3400 .set_oplock_level = smb3_set_oplock_level,
3401 .create_lease_buf = smb3_create_lease_buf,
3402 .parse_lease_buf = smb3_parse_lease_buf,
3403 .copychunk_range = smb2_copychunk_range,
3404 .duplicate_extents = smb2_duplicate_extents,
3405 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
3406 .wp_retry_size = smb2_wp_retry_size,
3407 .dir_needs_close = smb2_dir_needs_close,
3408 .fallocate = smb3_fallocate,
3409 .enum_snapshots = smb3_enum_snapshots,
3410 .init_transform_rq = smb3_init_transform_rq,
3411 .free_transform_rq = smb3_free_transform_rq,
3412 .is_transform_hdr = smb3_is_transform_hdr,
3413 .receive_transform = smb3_receive_transform,
3414 .get_dfs_refer = smb2_get_dfs_refer,
3415 .select_sectype = smb2_select_sectype,
3416 #ifdef CONFIG_CIFS_XATTR
3417 .query_all_EAs = smb2_query_eas,
3418 .set_EA = smb2_set_ea,
3419 #endif /* CIFS_XATTR */
3420 .next_header = smb2_next_header,
3423 struct smb_version_values smb20_values = {
3424 .version_string = SMB20_VERSION_STRING,
3425 .protocol_id = SMB20_PROT_ID,
3426 .req_capabilities = 0, /* MBZ */
3427 .large_lock_type = 0,
3428 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3429 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3430 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3431 .header_size = sizeof(struct smb2_sync_hdr),
3432 .header_preamble_size = 0,
3433 .max_header_size = MAX_SMB2_HDR_SIZE,
3434 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3435 .lock_cmd = SMB2_LOCK,
3437 .cap_nt_find = SMB2_NT_FIND,
3438 .cap_large_files = SMB2_LARGE_FILES,
3439 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3440 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3441 .create_lease_size = sizeof(struct create_lease),
3444 struct smb_version_values smb21_values = {
3445 .version_string = SMB21_VERSION_STRING,
3446 .protocol_id = SMB21_PROT_ID,
3447 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
3448 .large_lock_type = 0,
3449 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3450 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3451 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3452 .header_size = sizeof(struct smb2_sync_hdr),
3453 .header_preamble_size = 0,
3454 .max_header_size = MAX_SMB2_HDR_SIZE,
3455 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3456 .lock_cmd = SMB2_LOCK,
3458 .cap_nt_find = SMB2_NT_FIND,
3459 .cap_large_files = SMB2_LARGE_FILES,
3460 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3461 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3462 .create_lease_size = sizeof(struct create_lease),
3465 struct smb_version_values smb3any_values = {
3466 .version_string = SMB3ANY_VERSION_STRING,
3467 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
3468 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
3469 .large_lock_type = 0,
3470 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3471 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3472 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3473 .header_size = sizeof(struct smb2_sync_hdr),
3474 .header_preamble_size = 0,
3475 .max_header_size = MAX_SMB2_HDR_SIZE,
3476 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3477 .lock_cmd = SMB2_LOCK,
3479 .cap_nt_find = SMB2_NT_FIND,
3480 .cap_large_files = SMB2_LARGE_FILES,
3481 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3482 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3483 .create_lease_size = sizeof(struct create_lease_v2),
3486 struct smb_version_values smbdefault_values = {
3487 .version_string = SMBDEFAULT_VERSION_STRING,
3488 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
3489 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
3490 .large_lock_type = 0,
3491 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3492 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3493 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3494 .header_size = sizeof(struct smb2_sync_hdr),
3495 .header_preamble_size = 0,
3496 .max_header_size = MAX_SMB2_HDR_SIZE,
3497 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3498 .lock_cmd = SMB2_LOCK,
3500 .cap_nt_find = SMB2_NT_FIND,
3501 .cap_large_files = SMB2_LARGE_FILES,
3502 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3503 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3504 .create_lease_size = sizeof(struct create_lease_v2),
3507 struct smb_version_values smb30_values = {
3508 .version_string = SMB30_VERSION_STRING,
3509 .protocol_id = SMB30_PROT_ID,
3510 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
3511 .large_lock_type = 0,
3512 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3513 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3514 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3515 .header_size = sizeof(struct smb2_sync_hdr),
3516 .header_preamble_size = 0,
3517 .max_header_size = MAX_SMB2_HDR_SIZE,
3518 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3519 .lock_cmd = SMB2_LOCK,
3521 .cap_nt_find = SMB2_NT_FIND,
3522 .cap_large_files = SMB2_LARGE_FILES,
3523 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3524 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3525 .create_lease_size = sizeof(struct create_lease_v2),
3528 struct smb_version_values smb302_values = {
3529 .version_string = SMB302_VERSION_STRING,
3530 .protocol_id = SMB302_PROT_ID,
3531 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
3532 .large_lock_type = 0,
3533 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3534 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3535 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3536 .header_size = sizeof(struct smb2_sync_hdr),
3537 .header_preamble_size = 0,
3538 .max_header_size = MAX_SMB2_HDR_SIZE,
3539 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3540 .lock_cmd = SMB2_LOCK,
3542 .cap_nt_find = SMB2_NT_FIND,
3543 .cap_large_files = SMB2_LARGE_FILES,
3544 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3545 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3546 .create_lease_size = sizeof(struct create_lease_v2),
3549 struct smb_version_values smb311_values = {
3550 .version_string = SMB311_VERSION_STRING,
3551 .protocol_id = SMB311_PROT_ID,
3552 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
3553 .large_lock_type = 0,
3554 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3555 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3556 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3557 .header_size = sizeof(struct smb2_sync_hdr),
3558 .header_preamble_size = 0,
3559 .max_header_size = MAX_SMB2_HDR_SIZE,
3560 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3561 .lock_cmd = SMB2_LOCK,
3563 .cap_nt_find = SMB2_NT_FIND,
3564 .cap_large_files = SMB2_LARGE_FILES,
3565 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3566 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3567 .create_lease_size = sizeof(struct create_lease_v2),