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);
448 cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
452 rc = parse_server_interfaces(out_buf, ret_data_len,
453 &iface_list, &iface_count);
457 spin_lock(&ses->iface_lock);
458 kfree(ses->iface_list);
459 ses->iface_list = iface_list;
460 ses->iface_count = iface_count;
461 ses->iface_last_update = jiffies;
462 spin_unlock(&ses->iface_lock);
470 smb2_cached_lease_break(struct work_struct *work)
472 struct cached_fid *cfid = container_of(work,
473 struct cached_fid, lease_break);
474 mutex_lock(&cfid->fid_mutex);
475 if (cfid->is_valid) {
476 cifs_dbg(FYI, "clear cached root file handle\n");
477 SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid,
478 cfid->fid->volatile_fid);
479 cfid->is_valid = false;
481 mutex_unlock(&cfid->fid_mutex);
485 * Open the directory at the root of a share
487 int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid)
489 struct cifs_open_parms oparams;
491 __le16 srch_path = 0; /* Null - since an open of top of share */
492 u8 oplock = SMB2_OPLOCK_LEVEL_II;
494 mutex_lock(&tcon->crfid.fid_mutex);
495 if (tcon->crfid.is_valid) {
496 cifs_dbg(FYI, "found a cached root file handle\n");
497 memcpy(pfid, tcon->crfid.fid, sizeof(struct cifs_fid));
498 mutex_unlock(&tcon->crfid.fid_mutex);
503 oparams.create_options = 0;
504 oparams.desired_access = FILE_READ_ATTRIBUTES;
505 oparams.disposition = FILE_OPEN;
507 oparams.reconnect = false;
509 rc = SMB2_open(xid, &oparams, &srch_path, &oplock, NULL, NULL, NULL);
511 memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid));
512 tcon->crfid.tcon = tcon;
513 tcon->crfid.is_valid = true;
515 mutex_unlock(&tcon->crfid.fid_mutex);
520 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
523 __le16 srch_path = 0; /* Null - open root of share */
524 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
525 struct cifs_open_parms oparms;
527 bool no_cached_open = tcon->nohandlecache;
530 oparms.desired_access = FILE_READ_ATTRIBUTES;
531 oparms.disposition = FILE_OPEN;
532 oparms.create_options = 0;
534 oparms.reconnect = false;
537 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
540 rc = open_shroot(xid, tcon, &fid);
545 SMB3_request_interfaces(xid, tcon);
547 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
548 FS_ATTRIBUTE_INFORMATION);
549 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
550 FS_DEVICE_INFORMATION);
551 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
552 FS_VOLUME_INFORMATION);
553 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
554 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
556 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
561 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
564 __le16 srch_path = 0; /* Null - open root of share */
565 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
566 struct cifs_open_parms oparms;
570 oparms.desired_access = FILE_READ_ATTRIBUTES;
571 oparms.disposition = FILE_OPEN;
572 oparms.create_options = 0;
574 oparms.reconnect = false;
576 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
580 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
581 FS_ATTRIBUTE_INFORMATION);
582 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
583 FS_DEVICE_INFORMATION);
584 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
589 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
590 struct cifs_sb_info *cifs_sb, const char *full_path)
594 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
595 struct cifs_open_parms oparms;
598 if ((*full_path == 0) && tcon->crfid.is_valid)
601 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
606 oparms.desired_access = FILE_READ_ATTRIBUTES;
607 oparms.disposition = FILE_OPEN;
608 oparms.create_options = 0;
610 oparms.reconnect = false;
612 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
618 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
624 smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
625 struct cifs_sb_info *cifs_sb, const char *full_path,
626 u64 *uniqueid, FILE_ALL_INFO *data)
628 *uniqueid = le64_to_cpu(data->IndexNumber);
633 smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
634 struct cifs_fid *fid, FILE_ALL_INFO *data)
637 struct smb2_file_all_info *smb2_data;
639 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
641 if (smb2_data == NULL)
644 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
647 move_smb2_info_to_cifs(data, smb2_data);
652 #ifdef CONFIG_CIFS_XATTR
654 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
655 struct smb2_file_full_ea_info *src, size_t src_size,
656 const unsigned char *ea_name)
659 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
661 size_t name_len, value_len, user_name_len;
663 while (src_size > 0) {
664 name = &src->ea_data[0];
665 name_len = (size_t)src->ea_name_length;
666 value = &src->ea_data[src->ea_name_length + 1];
667 value_len = (size_t)le16_to_cpu(src->ea_value_length);
673 if (src_size < 8 + name_len + 1 + value_len) {
674 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
680 if (ea_name_len == name_len &&
681 memcmp(ea_name, name, name_len) == 0) {
685 if (dst_size < value_len) {
689 memcpy(dst, value, value_len);
693 /* 'user.' plus a terminating null */
694 user_name_len = 5 + 1 + name_len;
698 if (dst_size >= user_name_len) {
699 dst_size -= user_name_len;
700 memcpy(dst, "user.", 5);
702 memcpy(dst, src->ea_data, name_len);
706 } else if (dst_size == 0) {
707 /* skip copy - calc size only */
709 /* stop before overrun buffer */
715 if (!src->next_entry_offset)
718 if (src_size < le32_to_cpu(src->next_entry_offset)) {
719 /* stop before overrun buffer */
723 src_size -= le32_to_cpu(src->next_entry_offset);
724 src = (void *)((char *)src +
725 le32_to_cpu(src->next_entry_offset));
728 /* didn't find the named attribute */
737 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
738 const unsigned char *path, const unsigned char *ea_name,
739 char *ea_data, size_t buf_size,
740 struct cifs_sb_info *cifs_sb)
744 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
745 struct cifs_open_parms oparms;
747 struct smb2_file_full_ea_info *smb2_data;
748 int ea_buf_size = SMB2_MIN_EA_BUF;
750 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
755 oparms.desired_access = FILE_READ_EA;
756 oparms.disposition = FILE_OPEN;
757 oparms.create_options = 0;
759 oparms.reconnect = false;
761 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
764 cifs_dbg(FYI, "open failed rc=%d\n", rc);
769 smb2_data = kzalloc(ea_buf_size, GFP_KERNEL);
770 if (smb2_data == NULL) {
771 SMB2_close(xid, tcon, fid.persistent_fid,
776 rc = SMB2_query_eas(xid, tcon, fid.persistent_fid,
778 ea_buf_size, smb2_data);
786 if (ea_buf_size > SMB2_MAX_EA_BUF) {
787 cifs_dbg(VFS, "EA size is too large\n");
788 SMB2_close(xid, tcon, fid.persistent_fid,
794 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
797 * If ea_name is NULL (listxattr) and there are no EAs, return 0 as it's
798 * not an error. Otherwise, the specified ea_name was not found.
801 rc = move_smb2_ea_to_cifs(ea_data, buf_size, smb2_data,
802 SMB2_MAX_EA_BUF, ea_name);
803 else if (!ea_name && rc == -ENODATA)
812 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
813 const char *path, const char *ea_name, const void *ea_value,
814 const __u16 ea_value_len, const struct nls_table *nls_codepage,
815 struct cifs_sb_info *cifs_sb)
819 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
820 struct cifs_open_parms oparms;
822 struct smb2_file_full_ea_info *ea;
823 int ea_name_len = strlen(ea_name);
826 if (ea_name_len > 255)
829 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
834 oparms.desired_access = FILE_WRITE_EA;
835 oparms.disposition = FILE_OPEN;
836 oparms.create_options = 0;
838 oparms.reconnect = false;
840 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
843 cifs_dbg(FYI, "open failed rc=%d\n", rc);
847 len = sizeof(ea) + ea_name_len + ea_value_len + 1;
848 ea = kzalloc(len, GFP_KERNEL);
850 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
854 ea->ea_name_length = ea_name_len;
855 ea->ea_value_length = cpu_to_le16(ea_value_len);
856 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
857 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
859 rc = SMB2_set_ea(xid, tcon, fid.persistent_fid, fid.volatile_fid, ea,
863 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
870 smb2_can_echo(struct TCP_Server_Info *server)
872 return server->echoes;
876 smb2_clear_stats(struct cifs_tcon *tcon)
878 #ifdef CONFIG_CIFS_STATS
880 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
881 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
882 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
888 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
890 seq_puts(m, "\n\tShare Capabilities:");
891 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
892 seq_puts(m, " DFS,");
893 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
894 seq_puts(m, " CONTINUOUS AVAILABILITY,");
895 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
896 seq_puts(m, " SCALEOUT,");
897 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
898 seq_puts(m, " CLUSTER,");
899 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
900 seq_puts(m, " ASYMMETRIC,");
901 if (tcon->capabilities == 0)
902 seq_puts(m, " None");
903 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
904 seq_puts(m, " Aligned,");
905 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
906 seq_puts(m, " Partition Aligned,");
907 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
908 seq_puts(m, " SSD,");
909 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
910 seq_puts(m, " TRIM-support,");
912 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
913 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
914 if (tcon->perf_sector_size)
915 seq_printf(m, "\tOptimal sector size: 0x%x",
916 tcon->perf_sector_size);
917 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
921 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
923 #ifdef CONFIG_CIFS_STATS
924 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
925 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
926 seq_printf(m, "\nNegotiates: %d sent %d failed",
927 atomic_read(&sent[SMB2_NEGOTIATE_HE]),
928 atomic_read(&failed[SMB2_NEGOTIATE_HE]));
929 seq_printf(m, "\nSessionSetups: %d sent %d failed",
930 atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
931 atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
932 seq_printf(m, "\nLogoffs: %d sent %d failed",
933 atomic_read(&sent[SMB2_LOGOFF_HE]),
934 atomic_read(&failed[SMB2_LOGOFF_HE]));
935 seq_printf(m, "\nTreeConnects: %d sent %d failed",
936 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
937 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
938 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
939 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
940 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
941 seq_printf(m, "\nCreates: %d sent %d failed",
942 atomic_read(&sent[SMB2_CREATE_HE]),
943 atomic_read(&failed[SMB2_CREATE_HE]));
944 seq_printf(m, "\nCloses: %d sent %d failed",
945 atomic_read(&sent[SMB2_CLOSE_HE]),
946 atomic_read(&failed[SMB2_CLOSE_HE]));
947 seq_printf(m, "\nFlushes: %d sent %d failed",
948 atomic_read(&sent[SMB2_FLUSH_HE]),
949 atomic_read(&failed[SMB2_FLUSH_HE]));
950 seq_printf(m, "\nReads: %d sent %d failed",
951 atomic_read(&sent[SMB2_READ_HE]),
952 atomic_read(&failed[SMB2_READ_HE]));
953 seq_printf(m, "\nWrites: %d sent %d failed",
954 atomic_read(&sent[SMB2_WRITE_HE]),
955 atomic_read(&failed[SMB2_WRITE_HE]));
956 seq_printf(m, "\nLocks: %d sent %d failed",
957 atomic_read(&sent[SMB2_LOCK_HE]),
958 atomic_read(&failed[SMB2_LOCK_HE]));
959 seq_printf(m, "\nIOCTLs: %d sent %d failed",
960 atomic_read(&sent[SMB2_IOCTL_HE]),
961 atomic_read(&failed[SMB2_IOCTL_HE]));
962 seq_printf(m, "\nCancels: %d sent %d failed",
963 atomic_read(&sent[SMB2_CANCEL_HE]),
964 atomic_read(&failed[SMB2_CANCEL_HE]));
965 seq_printf(m, "\nEchos: %d sent %d failed",
966 atomic_read(&sent[SMB2_ECHO_HE]),
967 atomic_read(&failed[SMB2_ECHO_HE]));
968 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
969 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
970 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
971 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
972 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
973 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
974 seq_printf(m, "\nQueryInfos: %d sent %d failed",
975 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
976 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
977 seq_printf(m, "\nSetInfos: %d sent %d failed",
978 atomic_read(&sent[SMB2_SET_INFO_HE]),
979 atomic_read(&failed[SMB2_SET_INFO_HE]));
980 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
981 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
982 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
987 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
989 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
990 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
992 cfile->fid.persistent_fid = fid->persistent_fid;
993 cfile->fid.volatile_fid = fid->volatile_fid;
994 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
996 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
997 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1001 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1002 struct cifs_fid *fid)
1004 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1008 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1009 u64 persistent_fid, u64 volatile_fid,
1010 struct copychunk_ioctl *pcchunk)
1013 unsigned int ret_data_len;
1014 struct resume_key_req *res_key;
1016 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1017 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
1018 NULL, 0 /* no input */,
1019 (char **)&res_key, &ret_data_len);
1022 cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1023 goto req_res_key_exit;
1025 if (ret_data_len < sizeof(struct resume_key_req)) {
1026 cifs_dbg(VFS, "Invalid refcopy resume key length\n");
1028 goto req_res_key_exit;
1030 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1038 smb2_copychunk_range(const unsigned int xid,
1039 struct cifsFileInfo *srcfile,
1040 struct cifsFileInfo *trgtfile, u64 src_off,
1041 u64 len, u64 dest_off)
1044 unsigned int ret_data_len;
1045 struct copychunk_ioctl *pcchunk;
1046 struct copychunk_ioctl_rsp *retbuf = NULL;
1047 struct cifs_tcon *tcon;
1048 int chunks_copied = 0;
1049 bool chunk_sizes_updated = false;
1050 ssize_t bytes_written, total_bytes_written = 0;
1052 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1054 if (pcchunk == NULL)
1057 cifs_dbg(FYI, "in smb2_copychunk_range - about to call request res key\n");
1058 /* Request a key from the server to identify the source of the copy */
1059 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1060 srcfile->fid.persistent_fid,
1061 srcfile->fid.volatile_fid, pcchunk);
1063 /* Note: request_res_key sets res_key null only if rc !=0 */
1067 /* For now array only one chunk long, will make more flexible later */
1068 pcchunk->ChunkCount = cpu_to_le32(1);
1069 pcchunk->Reserved = 0;
1070 pcchunk->Reserved2 = 0;
1072 tcon = tlink_tcon(trgtfile->tlink);
1075 pcchunk->SourceOffset = cpu_to_le64(src_off);
1076 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1078 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
1080 /* Request server copy to target from src identified by key */
1081 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1082 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1083 true /* is_fsctl */, (char *)pcchunk,
1084 sizeof(struct copychunk_ioctl), (char **)&retbuf,
1088 sizeof(struct copychunk_ioctl_rsp)) {
1089 cifs_dbg(VFS, "invalid cchunk response size\n");
1093 if (retbuf->TotalBytesWritten == 0) {
1094 cifs_dbg(FYI, "no bytes copied\n");
1099 * Check if server claimed to write more than we asked
1101 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1102 le32_to_cpu(pcchunk->Length)) {
1103 cifs_dbg(VFS, "invalid copy chunk response\n");
1107 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1108 cifs_dbg(VFS, "invalid num chunks written\n");
1114 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1115 src_off += bytes_written;
1116 dest_off += bytes_written;
1117 len -= bytes_written;
1118 total_bytes_written += bytes_written;
1120 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1121 le32_to_cpu(retbuf->ChunksWritten),
1122 le32_to_cpu(retbuf->ChunkBytesWritten),
1124 } else if (rc == -EINVAL) {
1125 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1128 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1129 le32_to_cpu(retbuf->ChunksWritten),
1130 le32_to_cpu(retbuf->ChunkBytesWritten),
1131 le32_to_cpu(retbuf->TotalBytesWritten));
1134 * Check if this is the first request using these sizes,
1135 * (ie check if copy succeed once with original sizes
1136 * and check if the server gave us different sizes after
1137 * we already updated max sizes on previous request).
1138 * if not then why is the server returning an error now
1140 if ((chunks_copied != 0) || chunk_sizes_updated)
1143 /* Check that server is not asking us to grow size */
1144 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1145 tcon->max_bytes_chunk)
1146 tcon->max_bytes_chunk =
1147 le32_to_cpu(retbuf->ChunkBytesWritten);
1149 goto cchunk_out; /* server gave us bogus size */
1151 /* No need to change MaxChunks since already set to 1 */
1152 chunk_sizes_updated = true;
1163 return total_bytes_written;
1167 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1168 struct cifs_fid *fid)
1170 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1174 smb2_read_data_offset(char *buf)
1176 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1177 return rsp->DataOffset;
1181 smb2_read_data_length(char *buf, bool in_remaining)
1183 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1186 return le32_to_cpu(rsp->DataRemaining);
1188 return le32_to_cpu(rsp->DataLength);
1193 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1194 struct cifs_io_parms *parms, unsigned int *bytes_read,
1195 char **buf, int *buf_type)
1197 parms->persistent_fid = pfid->persistent_fid;
1198 parms->volatile_fid = pfid->volatile_fid;
1199 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1203 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1204 struct cifs_io_parms *parms, unsigned int *written,
1205 struct kvec *iov, unsigned long nr_segs)
1208 parms->persistent_fid = pfid->persistent_fid;
1209 parms->volatile_fid = pfid->volatile_fid;
1210 return SMB2_write(xid, parms, written, iov, nr_segs);
1213 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1214 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1215 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1217 struct cifsInodeInfo *cifsi;
1220 cifsi = CIFS_I(inode);
1222 /* if file already sparse don't bother setting sparse again */
1223 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1224 return true; /* already sparse */
1226 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1227 return true; /* already not sparse */
1230 * Can't check for sparse support on share the usual way via the
1231 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1232 * since Samba server doesn't set the flag on the share, yet
1233 * supports the set sparse FSCTL and returns sparse correctly
1234 * in the file attributes. If we fail setting sparse though we
1235 * mark that server does not support sparse files for this share
1236 * to avoid repeatedly sending the unsupported fsctl to server
1237 * if the file is repeatedly extended.
1239 if (tcon->broken_sparse_sup)
1242 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1243 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1245 &setsparse, 1, NULL, NULL);
1247 tcon->broken_sparse_sup = true;
1248 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1253 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1255 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1261 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1262 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1264 __le64 eof = cpu_to_le64(size);
1265 struct inode *inode;
1268 * If extending file more than one page make sparse. Many Linux fs
1269 * make files sparse by default when extending via ftruncate
1271 inode = d_inode(cfile->dentry);
1273 if (!set_alloc && (size > inode->i_size + 8192)) {
1274 __u8 set_sparse = 1;
1276 /* whether set sparse succeeds or not, extend the file */
1277 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1280 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1281 cfile->fid.volatile_fid, cfile->pid, &eof, false);
1285 smb2_duplicate_extents(const unsigned int xid,
1286 struct cifsFileInfo *srcfile,
1287 struct cifsFileInfo *trgtfile, u64 src_off,
1288 u64 len, u64 dest_off)
1291 unsigned int ret_data_len;
1292 struct duplicate_extents_to_file dup_ext_buf;
1293 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1295 /* server fileays advertise duplicate extent support with this flag */
1296 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1297 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1300 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1301 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1302 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1303 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1304 dup_ext_buf.ByteCount = cpu_to_le64(len);
1305 cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld",
1306 src_off, dest_off, len);
1308 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1310 goto duplicate_extents_out;
1312 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1313 trgtfile->fid.volatile_fid,
1314 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1315 true /* is_fsctl */,
1316 (char *)&dup_ext_buf,
1317 sizeof(struct duplicate_extents_to_file),
1321 if (ret_data_len > 0)
1322 cifs_dbg(FYI, "non-zero response length in duplicate extents");
1324 duplicate_extents_out:
1329 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1330 struct cifsFileInfo *cfile)
1332 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1333 cfile->fid.volatile_fid);
1337 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
1338 struct cifsFileInfo *cfile)
1340 struct fsctl_set_integrity_information_req integr_info;
1341 unsigned int ret_data_len;
1343 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
1344 integr_info.Flags = 0;
1345 integr_info.Reserved = 0;
1347 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1348 cfile->fid.volatile_fid,
1349 FSCTL_SET_INTEGRITY_INFORMATION,
1350 true /* is_fsctl */,
1351 (char *)&integr_info,
1352 sizeof(struct fsctl_set_integrity_information_req),
1359 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
1360 struct cifsFileInfo *cfile, void __user *ioc_buf)
1362 char *retbuf = NULL;
1363 unsigned int ret_data_len = 0;
1365 struct smb_snapshot_array snapshot_in;
1367 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1368 cfile->fid.volatile_fid,
1369 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
1370 true /* is_fsctl */,
1371 NULL, 0 /* no input data */,
1374 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
1379 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
1381 if (copy_from_user(&snapshot_in, ioc_buf,
1382 sizeof(struct smb_snapshot_array))) {
1387 if (snapshot_in.snapshot_array_size < sizeof(struct smb_snapshot_array)) {
1393 if (ret_data_len > snapshot_in.snapshot_array_size)
1394 ret_data_len = snapshot_in.snapshot_array_size;
1396 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
1405 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
1406 const char *path, struct cifs_sb_info *cifs_sb,
1407 struct cifs_fid *fid, __u16 search_flags,
1408 struct cifs_search_info *srch_inf)
1412 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1413 struct cifs_open_parms oparms;
1415 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1420 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
1421 oparms.disposition = FILE_OPEN;
1422 oparms.create_options = 0;
1424 oparms.reconnect = false;
1426 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
1429 cifs_dbg(FYI, "open dir failed rc=%d\n", rc);
1433 srch_inf->entries_in_buffer = 0;
1434 srch_inf->index_of_last_entry = 0;
1436 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
1437 fid->volatile_fid, 0, srch_inf);
1439 cifs_dbg(FYI, "query directory failed rc=%d\n", rc);
1440 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1446 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
1447 struct cifs_fid *fid, __u16 search_flags,
1448 struct cifs_search_info *srch_inf)
1450 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
1451 fid->volatile_fid, 0, srch_inf);
1455 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
1456 struct cifs_fid *fid)
1458 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1462 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
1463 * the number of credits and return true. Otherwise - return false.
1466 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
1468 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
1470 if (shdr->Status != STATUS_PENDING)
1474 spin_lock(&server->req_lock);
1475 server->credits += le16_to_cpu(shdr->CreditRequest);
1476 spin_unlock(&server->req_lock);
1477 wake_up(&server->request_q);
1484 smb2_is_session_expired(char *buf)
1486 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
1488 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
1489 shdr->Status != STATUS_USER_SESSION_DELETED)
1492 cifs_dbg(FYI, "Session expired or deleted\n");
1497 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
1498 struct cifsInodeInfo *cinode)
1500 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
1501 return SMB2_lease_break(0, tcon, cinode->lease_key,
1502 smb2_get_lease_state(cinode));
1504 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
1506 CIFS_CACHE_READ(cinode) ? 1 : 0);
1510 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
1511 struct kstatfs *buf)
1514 __le16 srch_path = 0; /* Null - open root of share */
1515 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1516 struct cifs_open_parms oparms;
1517 struct cifs_fid fid;
1520 oparms.desired_access = FILE_READ_ATTRIBUTES;
1521 oparms.disposition = FILE_OPEN;
1522 oparms.create_options = 0;
1524 oparms.reconnect = false;
1526 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
1529 buf->f_type = SMB2_MAGIC_NUMBER;
1530 rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
1532 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
1537 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
1539 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
1540 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
1544 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
1545 __u64 length, __u32 type, int lock, int unlock, bool wait)
1547 if (unlock && !lock)
1548 type = SMB2_LOCKFLAG_UNLOCK;
1549 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
1550 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
1551 current->tgid, length, offset, type, wait);
1555 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
1557 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
1561 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
1563 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
1567 smb2_new_lease_key(struct cifs_fid *fid)
1569 generate_random_uuid(fid->lease_key);
1573 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
1574 const char *search_name,
1575 struct dfs_info3_param **target_nodes,
1576 unsigned int *num_of_nodes,
1577 const struct nls_table *nls_codepage, int remap)
1580 __le16 *utf16_path = NULL;
1581 int utf16_path_len = 0;
1582 struct cifs_tcon *tcon;
1583 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
1584 struct get_dfs_referral_rsp *dfs_rsp = NULL;
1585 u32 dfs_req_size = 0, dfs_rsp_size = 0;
1587 cifs_dbg(FYI, "smb2_get_dfs_refer path <%s>\n", search_name);
1590 * Try to use the IPC tcon, otherwise just use any
1592 tcon = ses->tcon_ipc;
1594 spin_lock(&cifs_tcp_ses_lock);
1595 tcon = list_first_entry_or_null(&ses->tcon_list,
1600 spin_unlock(&cifs_tcp_ses_lock);
1604 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
1610 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
1612 nls_codepage, remap);
1618 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
1619 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
1625 /* Highest DFS referral version understood */
1626 dfs_req->MaxReferralLevel = DFS_VERSION;
1628 /* Path to resolve in an UTF-16 null-terminated string */
1629 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
1632 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
1633 FSCTL_DFS_GET_REFERRALS,
1634 true /* is_fsctl */,
1635 (char *)dfs_req, dfs_req_size,
1636 (char **)&dfs_rsp, &dfs_rsp_size);
1637 } while (rc == -EAGAIN);
1640 if ((rc != -ENOENT) && (rc != -EOPNOTSUPP))
1641 cifs_dbg(VFS, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc);
1645 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
1646 num_of_nodes, target_nodes,
1647 nls_codepage, remap, search_name,
1648 true /* is_unicode */);
1650 cifs_dbg(VFS, "parse error in smb2_get_dfs_refer rc=%d\n", rc);
1655 if (tcon && !tcon->ipc) {
1656 /* ipc tcons are not refcounted */
1657 spin_lock(&cifs_tcp_ses_lock);
1659 spin_unlock(&cifs_tcp_ses_lock);
1666 #define SMB2_SYMLINK_STRUCT_SIZE \
1667 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
1670 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
1671 const char *full_path, char **target_path,
1672 struct cifs_sb_info *cifs_sb)
1676 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1677 struct cifs_open_parms oparms;
1678 struct cifs_fid fid;
1679 struct kvec err_iov = {NULL, 0};
1680 struct smb2_err_rsp *err_buf = NULL;
1682 struct smb2_symlink_err_rsp *symlink;
1683 unsigned int sub_len;
1684 unsigned int sub_offset;
1685 unsigned int print_len;
1686 unsigned int print_offset;
1688 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
1690 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
1695 oparms.desired_access = FILE_READ_ATTRIBUTES;
1696 oparms.disposition = FILE_OPEN;
1697 oparms.create_options = 0;
1699 oparms.reconnect = false;
1701 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_iov,
1703 if (!rc || !err_iov.iov_base) {
1708 err_buf = err_iov.iov_base;
1709 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
1710 err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) {
1715 /* open must fail on symlink - reset rc */
1717 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
1718 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
1719 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
1720 print_len = le16_to_cpu(symlink->PrintNameLength);
1721 print_offset = le16_to_cpu(symlink->PrintNameOffset);
1723 if (err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
1728 if (err_iov.iov_len <
1729 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
1734 *target_path = cifs_strndup_from_utf16(
1735 (char *)symlink->PathBuffer + sub_offset,
1736 sub_len, true, cifs_sb->local_nls);
1737 if (!(*target_path)) {
1741 convert_delimiter(*target_path, '/');
1742 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
1745 free_rsp_buf(resp_buftype, err_buf);
1751 #ifdef CONFIG_CIFS_ACL
1752 static struct cifs_ntsd *
1753 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
1754 const struct cifs_fid *cifsfid, u32 *pacllen)
1756 struct cifs_ntsd *pntsd = NULL;
1758 int rc = -EOPNOTSUPP;
1759 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1762 return ERR_CAST(tlink);
1765 cifs_dbg(FYI, "trying to get acl\n");
1767 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
1768 cifsfid->volatile_fid, (void **)&pntsd, pacllen);
1771 cifs_put_tlink(tlink);
1773 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
1780 static struct cifs_ntsd *
1781 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
1782 const char *path, u32 *pacllen)
1784 struct cifs_ntsd *pntsd = NULL;
1785 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1788 struct cifs_tcon *tcon;
1789 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1790 struct cifs_fid fid;
1791 struct cifs_open_parms oparms;
1794 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
1796 return ERR_CAST(tlink);
1798 tcon = tlink_tcon(tlink);
1801 if (backup_cred(cifs_sb))
1802 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1804 oparms.create_options = 0;
1806 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1814 oparms.desired_access = READ_CONTROL;
1815 oparms.disposition = FILE_OPEN;
1817 oparms.reconnect = false;
1819 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
1822 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
1823 fid.volatile_fid, (void **)&pntsd, pacllen);
1824 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
1827 cifs_put_tlink(tlink);
1830 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
1836 #ifdef CONFIG_CIFS_ACL
1838 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
1839 struct inode *inode, const char *path, int aclflag)
1841 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1843 int rc, access_flags = 0;
1844 struct cifs_tcon *tcon;
1845 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
1846 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1847 struct cifs_fid fid;
1848 struct cifs_open_parms oparms;
1851 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
1853 return PTR_ERR(tlink);
1855 tcon = tlink_tcon(tlink);
1858 if (backup_cred(cifs_sb))
1859 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1861 oparms.create_options = 0;
1863 if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP)
1864 access_flags = WRITE_OWNER;
1866 access_flags = WRITE_DAC;
1868 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1876 oparms.desired_access = access_flags;
1877 oparms.disposition = FILE_OPEN;
1880 oparms.reconnect = false;
1882 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
1885 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
1886 fid.volatile_fid, pnntsd, acllen, aclflag);
1887 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
1890 cifs_put_tlink(tlink);
1894 #endif /* CIFS_ACL */
1896 /* Retrieve an ACL from the server */
1897 static struct cifs_ntsd *
1898 get_smb2_acl(struct cifs_sb_info *cifs_sb,
1899 struct inode *inode, const char *path,
1902 struct cifs_ntsd *pntsd = NULL;
1903 struct cifsFileInfo *open_file = NULL;
1906 open_file = find_readable_file(CIFS_I(inode), true);
1908 return get_smb2_acl_by_path(cifs_sb, path, pacllen);
1910 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen);
1911 cifsFileInfo_put(open_file);
1916 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
1917 loff_t offset, loff_t len, bool keep_size)
1919 struct inode *inode;
1920 struct cifsInodeInfo *cifsi;
1921 struct cifsFileInfo *cfile = file->private_data;
1922 struct file_zero_data_information fsctl_buf;
1928 inode = d_inode(cfile->dentry);
1929 cifsi = CIFS_I(inode);
1931 /* if file not oplocked can't be sure whether asking to extend size */
1932 if (!CIFS_CACHE_READ(cifsi))
1933 if (keep_size == false) {
1940 * Must check if file sparse since fallocate -z (zero range) assumes
1941 * non-sparse allocation
1943 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
1950 * need to make sure we are not asked to extend the file since the SMB3
1951 * fsctl does not change the file size. In the future we could change
1952 * this to zero the first part of the range then set the file size
1953 * which for a non sparse file would zero the newly extended range
1955 if (keep_size == false)
1956 if (i_size_read(inode) < offset + len) {
1962 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1964 fsctl_buf.FileOffset = cpu_to_le64(offset);
1965 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1967 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1968 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
1969 true /* is_fctl */, (char *)&fsctl_buf,
1970 sizeof(struct file_zero_data_information), NULL, NULL);
1975 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
1976 loff_t offset, loff_t len)
1978 struct inode *inode;
1979 struct cifsInodeInfo *cifsi;
1980 struct cifsFileInfo *cfile = file->private_data;
1981 struct file_zero_data_information fsctl_buf;
1984 __u8 set_sparse = 1;
1988 inode = d_inode(cfile->dentry);
1989 cifsi = CIFS_I(inode);
1991 /* Need to make file sparse, if not already, before freeing range. */
1992 /* Consider adding equivalent for compressed since it could also work */
1993 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
1999 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
2001 fsctl_buf.FileOffset = cpu_to_le64(offset);
2002 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
2004 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2005 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
2006 true /* is_fctl */, (char *)&fsctl_buf,
2007 sizeof(struct file_zero_data_information), NULL, NULL);
2012 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
2013 loff_t off, loff_t len, bool keep_size)
2015 struct inode *inode;
2016 struct cifsInodeInfo *cifsi;
2017 struct cifsFileInfo *cfile = file->private_data;
2018 long rc = -EOPNOTSUPP;
2023 inode = d_inode(cfile->dentry);
2024 cifsi = CIFS_I(inode);
2026 /* if file not oplocked can't be sure whether asking to extend size */
2027 if (!CIFS_CACHE_READ(cifsi))
2028 if (keep_size == false) {
2034 * Files are non-sparse by default so falloc may be a no-op
2035 * Must check if file sparse. If not sparse, and not extending
2036 * then no need to do anything since file already allocated
2038 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
2039 if (keep_size == true)
2041 /* check if extending file */
2042 else if (i_size_read(inode) >= off + len)
2043 /* not extending file and already not sparse */
2045 /* BB: in future add else clause to extend file */
2052 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
2054 * Check if falloc starts within first few pages of file
2055 * and ends within a few pages of the end of file to
2056 * ensure that most of file is being forced to be
2057 * fallocated now. If so then setting whole file sparse
2058 * ie potentially making a few extra pages at the beginning
2059 * or end of the file non-sparse via set_sparse is harmless.
2061 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
2067 rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
2069 /* BB: else ... in future add code to extend file and set sparse */
2077 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
2078 loff_t off, loff_t len)
2080 /* KEEP_SIZE already checked for by do_fallocate */
2081 if (mode & FALLOC_FL_PUNCH_HOLE)
2082 return smb3_punch_hole(file, tcon, off, len);
2083 else if (mode & FALLOC_FL_ZERO_RANGE) {
2084 if (mode & FALLOC_FL_KEEP_SIZE)
2085 return smb3_zero_range(file, tcon, off, len, true);
2086 return smb3_zero_range(file, tcon, off, len, false);
2087 } else if (mode == FALLOC_FL_KEEP_SIZE)
2088 return smb3_simple_falloc(file, tcon, off, len, true);
2090 return smb3_simple_falloc(file, tcon, off, len, false);
2096 smb2_downgrade_oplock(struct TCP_Server_Info *server,
2097 struct cifsInodeInfo *cinode, bool set_level2)
2100 server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
2103 server->ops->set_oplock_level(cinode, 0, 0, NULL);
2107 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
2108 unsigned int epoch, bool *purge_cache)
2111 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
2113 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
2114 cinode->oplock = CIFS_CACHE_RHW_FLG;
2115 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
2116 &cinode->vfs_inode);
2117 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
2118 cinode->oplock = CIFS_CACHE_RW_FLG;
2119 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
2120 &cinode->vfs_inode);
2121 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
2122 cinode->oplock = CIFS_CACHE_READ_FLG;
2123 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
2124 &cinode->vfs_inode);
2130 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
2131 unsigned int epoch, bool *purge_cache)
2133 char message[5] = {0};
2136 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
2140 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
2141 cinode->oplock |= CIFS_CACHE_READ_FLG;
2142 strcat(message, "R");
2144 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
2145 cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
2146 strcat(message, "H");
2148 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
2149 cinode->oplock |= CIFS_CACHE_WRITE_FLG;
2150 strcat(message, "W");
2152 if (!cinode->oplock)
2153 strcat(message, "None");
2154 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
2155 &cinode->vfs_inode);
2159 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
2160 unsigned int epoch, bool *purge_cache)
2162 unsigned int old_oplock = cinode->oplock;
2164 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
2167 *purge_cache = false;
2168 if (old_oplock == CIFS_CACHE_READ_FLG) {
2169 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
2170 (epoch - cinode->epoch > 0))
2171 *purge_cache = true;
2172 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
2173 (epoch - cinode->epoch > 1))
2174 *purge_cache = true;
2175 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
2176 (epoch - cinode->epoch > 1))
2177 *purge_cache = true;
2178 else if (cinode->oplock == 0 &&
2179 (epoch - cinode->epoch > 0))
2180 *purge_cache = true;
2181 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
2182 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
2183 (epoch - cinode->epoch > 0))
2184 *purge_cache = true;
2185 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
2186 (epoch - cinode->epoch > 1))
2187 *purge_cache = true;
2189 cinode->epoch = epoch;
2194 smb2_is_read_op(__u32 oplock)
2196 return oplock == SMB2_OPLOCK_LEVEL_II;
2200 smb21_is_read_op(__u32 oplock)
2202 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
2203 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
2207 map_oplock_to_lease(u8 oplock)
2209 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
2210 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
2211 else if (oplock == SMB2_OPLOCK_LEVEL_II)
2212 return SMB2_LEASE_READ_CACHING;
2213 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
2214 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
2215 SMB2_LEASE_WRITE_CACHING;
2220 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
2222 struct create_lease *buf;
2224 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
2228 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
2229 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
2231 buf->ccontext.DataOffset = cpu_to_le16(offsetof
2232 (struct create_lease, lcontext));
2233 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
2234 buf->ccontext.NameOffset = cpu_to_le16(offsetof
2235 (struct create_lease, Name));
2236 buf->ccontext.NameLength = cpu_to_le16(4);
2237 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
2246 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
2248 struct create_lease_v2 *buf;
2250 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
2254 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
2255 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
2257 buf->ccontext.DataOffset = cpu_to_le16(offsetof
2258 (struct create_lease_v2, lcontext));
2259 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
2260 buf->ccontext.NameOffset = cpu_to_le16(offsetof
2261 (struct create_lease_v2, Name));
2262 buf->ccontext.NameLength = cpu_to_le16(4);
2263 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
2272 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
2274 struct create_lease *lc = (struct create_lease *)buf;
2276 *epoch = 0; /* not used */
2277 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
2278 return SMB2_OPLOCK_LEVEL_NOCHANGE;
2279 return le32_to_cpu(lc->lcontext.LeaseState);
2283 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
2285 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
2287 *epoch = le16_to_cpu(lc->lcontext.Epoch);
2288 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
2289 return SMB2_OPLOCK_LEVEL_NOCHANGE;
2291 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
2292 return le32_to_cpu(lc->lcontext.LeaseState);
2296 smb2_wp_retry_size(struct inode *inode)
2298 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
2299 SMB2_MAX_BUFFER_SIZE);
2303 smb2_dir_needs_close(struct cifsFileInfo *cfile)
2305 return !cfile->invalidHandle;
2309 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
2310 struct smb_rqst *old_rq)
2312 struct smb2_sync_hdr *shdr =
2313 (struct smb2_sync_hdr *)old_rq->rq_iov[0].iov_base;
2315 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
2316 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
2317 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
2318 tr_hdr->Flags = cpu_to_le16(0x01);
2319 get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
2320 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
2323 /* We can not use the normal sg_set_buf() as we will sometimes pass a
2324 * stack object as buf.
2326 static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
2327 unsigned int buflen)
2329 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
2333 * rqst->rq_iov[0] is transform header
2334 * rqst->rq_iov[1+] data to be encrypted/decrypted
2336 static struct scatterlist *
2337 init_sg(struct smb_rqst *rqst, u8 *sign)
2339 unsigned int sg_len = rqst->rq_nvec + rqst->rq_npages + 1;
2340 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
2341 struct scatterlist *sg;
2345 sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
2349 sg_init_table(sg, sg_len);
2350 smb2_sg_set_buf(&sg[0], rqst->rq_iov[0].iov_base + 20, assoc_data_len);
2351 for (i = 1; i < rqst->rq_nvec; i++)
2352 smb2_sg_set_buf(&sg[i], rqst->rq_iov[i].iov_base,
2353 rqst->rq_iov[i].iov_len);
2354 for (j = 0; i < sg_len - 1; i++, j++) {
2355 unsigned int len, offset;
2357 rqst_page_get_length(rqst, j, &len, &offset);
2358 sg_set_page(&sg[i], rqst->rq_pages[j], len, offset);
2360 smb2_sg_set_buf(&sg[sg_len - 1], sign, SMB2_SIGNATURE_SIZE);
2365 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
2367 struct cifs_ses *ses;
2370 spin_lock(&cifs_tcp_ses_lock);
2371 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
2372 if (ses->Suid != ses_id)
2374 ses_enc_key = enc ? ses->smb3encryptionkey :
2375 ses->smb3decryptionkey;
2376 memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE);
2377 spin_unlock(&cifs_tcp_ses_lock);
2380 spin_unlock(&cifs_tcp_ses_lock);
2385 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
2386 * iov[0] - transform header (associate data),
2387 * iov[1-N] - SMB2 header and pages - data to encrypt.
2388 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
2392 crypt_message(struct TCP_Server_Info *server, struct smb_rqst *rqst, int enc)
2394 struct smb2_transform_hdr *tr_hdr =
2395 (struct smb2_transform_hdr *)rqst->rq_iov[0].iov_base;
2396 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
2398 struct scatterlist *sg;
2399 u8 sign[SMB2_SIGNATURE_SIZE] = {};
2400 u8 key[SMB3_SIGN_KEY_SIZE];
2401 struct aead_request *req;
2403 unsigned int iv_len;
2404 DECLARE_CRYPTO_WAIT(wait);
2405 struct crypto_aead *tfm;
2406 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
2408 rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key);
2410 cifs_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
2415 rc = smb3_crypto_aead_allocate(server);
2417 cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__);
2421 tfm = enc ? server->secmech.ccmaesencrypt :
2422 server->secmech.ccmaesdecrypt;
2423 rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
2425 cifs_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
2429 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
2431 cifs_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
2435 req = aead_request_alloc(tfm, GFP_KERNEL);
2437 cifs_dbg(VFS, "%s: Failed to alloc aead request", __func__);
2442 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
2443 crypt_len += SMB2_SIGNATURE_SIZE;
2446 sg = init_sg(rqst, sign);
2448 cifs_dbg(VFS, "%s: Failed to init sg", __func__);
2453 iv_len = crypto_aead_ivsize(tfm);
2454 iv = kzalloc(iv_len, GFP_KERNEL);
2456 cifs_dbg(VFS, "%s: Failed to alloc IV", __func__);
2461 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
2463 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
2464 aead_request_set_ad(req, assoc_data_len);
2466 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
2467 crypto_req_done, &wait);
2469 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
2470 : crypto_aead_decrypt(req), &wait);
2473 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
2484 smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq,
2485 struct smb_rqst *old_rq)
2488 struct page **pages;
2489 struct smb2_transform_hdr *tr_hdr;
2490 unsigned int npages = old_rq->rq_npages;
2491 unsigned int orig_len;
2495 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
2499 new_rq->rq_pages = pages;
2500 new_rq->rq_offset = old_rq->rq_offset;
2501 new_rq->rq_npages = old_rq->rq_npages;
2502 new_rq->rq_pagesz = old_rq->rq_pagesz;
2503 new_rq->rq_tailsz = old_rq->rq_tailsz;
2505 for (i = 0; i < npages; i++) {
2506 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
2508 goto err_free_pages;
2511 iov = kmalloc_array(old_rq->rq_nvec + 1, sizeof(struct kvec),
2514 goto err_free_pages;
2516 /* copy all iovs from the old */
2517 memcpy(&iov[1], &old_rq->rq_iov[0],
2518 sizeof(struct kvec) * old_rq->rq_nvec);
2520 new_rq->rq_iov = iov;
2521 new_rq->rq_nvec = old_rq->rq_nvec + 1;
2523 tr_hdr = kmalloc(sizeof(struct smb2_transform_hdr), GFP_KERNEL);
2527 orig_len = smb_rqst_len(server, old_rq);
2529 /* fill the 2nd iov with a transform header */
2530 fill_transform_hdr(tr_hdr, orig_len, old_rq);
2531 new_rq->rq_iov[0].iov_base = tr_hdr;
2532 new_rq->rq_iov[0].iov_len = sizeof(struct smb2_transform_hdr);
2534 /* copy pages form the old */
2535 for (i = 0; i < npages; i++) {
2537 unsigned int offset, len;
2539 rqst_page_get_length(new_rq, i, &len, &offset);
2541 dst = (char *) kmap(new_rq->rq_pages[i]) + offset;
2542 src = (char *) kmap(old_rq->rq_pages[i]) + offset;
2544 memcpy(dst, src, len);
2545 kunmap(new_rq->rq_pages[i]);
2546 kunmap(old_rq->rq_pages[i]);
2549 rc = crypt_message(server, new_rq, 1);
2550 cifs_dbg(FYI, "encrypt message returned %d", rc);
2552 goto err_free_tr_hdr;
2561 for (i = i - 1; i >= 0; i--)
2568 smb3_free_transform_rq(struct smb_rqst *rqst)
2570 int i = rqst->rq_npages - 1;
2573 put_page(rqst->rq_pages[i]);
2574 kfree(rqst->rq_pages);
2575 /* free transform header */
2576 kfree(rqst->rq_iov[0].iov_base);
2577 kfree(rqst->rq_iov);
2581 smb3_is_transform_hdr(void *buf)
2583 struct smb2_transform_hdr *trhdr = buf;
2585 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
2589 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
2590 unsigned int buf_data_size, struct page **pages,
2591 unsigned int npages, unsigned int page_data_size)
2594 struct smb_rqst rqst = {NULL};
2597 iov[0].iov_base = buf;
2598 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
2599 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
2600 iov[1].iov_len = buf_data_size;
2604 rqst.rq_pages = pages;
2605 rqst.rq_npages = npages;
2606 rqst.rq_pagesz = PAGE_SIZE;
2607 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
2609 rc = crypt_message(server, &rqst, 0);
2610 cifs_dbg(FYI, "decrypt message returned %d\n", rc);
2615 memmove(buf, iov[1].iov_base, buf_data_size);
2617 server->total_read = buf_data_size + page_data_size;
2623 read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
2624 unsigned int npages, unsigned int len)
2629 for (i = 0; i < npages; i++) {
2630 struct page *page = pages[i];
2634 if (len >= PAGE_SIZE) {
2635 /* enough data to fill the page */
2639 zero_user(page, len, PAGE_SIZE - len);
2642 length = cifs_read_page_from_socket(server, page, 0, n);
2645 server->total_read += length;
2652 init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
2653 unsigned int cur_off, struct bio_vec **page_vec)
2655 struct bio_vec *bvec;
2658 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
2662 for (i = 0; i < npages; i++) {
2663 bvec[i].bv_page = pages[i];
2664 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
2665 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
2666 data_size -= bvec[i].bv_len;
2669 if (data_size != 0) {
2670 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
2680 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
2681 char *buf, unsigned int buf_len, struct page **pages,
2682 unsigned int npages, unsigned int page_data_size)
2684 unsigned int data_offset;
2685 unsigned int data_len;
2686 unsigned int cur_off;
2687 unsigned int cur_page_idx;
2688 unsigned int pad_len;
2689 struct cifs_readdata *rdata = mid->callback_data;
2690 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2691 struct bio_vec *bvec = NULL;
2692 struct iov_iter iter;
2695 bool use_rdma_mr = false;
2697 if (shdr->Command != SMB2_READ) {
2698 cifs_dbg(VFS, "only big read responses are supported\n");
2702 if (server->ops->is_session_expired &&
2703 server->ops->is_session_expired(buf)) {
2704 cifs_reconnect(server);
2705 wake_up(&server->response_q);
2709 if (server->ops->is_status_pending &&
2710 server->ops->is_status_pending(buf, server, 0))
2713 rdata->result = server->ops->map_error(buf, false);
2714 if (rdata->result != 0) {
2715 cifs_dbg(FYI, "%s: server returned error %d\n",
2716 __func__, rdata->result);
2717 dequeue_mid(mid, rdata->result);
2721 data_offset = server->ops->read_data_offset(buf);
2722 #ifdef CONFIG_CIFS_SMB_DIRECT
2723 use_rdma_mr = rdata->mr;
2725 data_len = server->ops->read_data_length(buf, use_rdma_mr);
2727 if (data_offset < server->vals->read_rsp_size) {
2729 * win2k8 sometimes sends an offset of 0 when the read
2730 * is beyond the EOF. Treat it as if the data starts just after
2733 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
2734 __func__, data_offset);
2735 data_offset = server->vals->read_rsp_size;
2736 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
2737 /* data_offset is beyond the end of smallbuf */
2738 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
2739 __func__, data_offset);
2740 rdata->result = -EIO;
2741 dequeue_mid(mid, rdata->result);
2745 pad_len = data_offset - server->vals->read_rsp_size;
2747 if (buf_len <= data_offset) {
2748 /* read response payload is in pages */
2749 cur_page_idx = pad_len / PAGE_SIZE;
2750 cur_off = pad_len % PAGE_SIZE;
2752 if (cur_page_idx != 0) {
2753 /* data offset is beyond the 1st page of response */
2754 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
2755 __func__, data_offset);
2756 rdata->result = -EIO;
2757 dequeue_mid(mid, rdata->result);
2761 if (data_len > page_data_size - pad_len) {
2762 /* data_len is corrupt -- discard frame */
2763 rdata->result = -EIO;
2764 dequeue_mid(mid, rdata->result);
2768 rdata->result = init_read_bvec(pages, npages, page_data_size,
2770 if (rdata->result != 0) {
2771 dequeue_mid(mid, rdata->result);
2775 iov_iter_bvec(&iter, WRITE | ITER_BVEC, bvec, npages, data_len);
2776 } else if (buf_len >= data_offset + data_len) {
2777 /* read response payload is in buf */
2778 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
2779 iov.iov_base = buf + data_offset;
2780 iov.iov_len = data_len;
2781 iov_iter_kvec(&iter, WRITE | ITER_KVEC, &iov, 1, data_len);
2783 /* read response payload cannot be in both buf and pages */
2784 WARN_ONCE(1, "buf can not contain only a part of read data");
2785 rdata->result = -EIO;
2786 dequeue_mid(mid, rdata->result);
2790 /* set up first iov for signature check */
2791 rdata->iov[0].iov_base = buf;
2792 rdata->iov[0].iov_len = 4;
2793 rdata->iov[1].iov_base = buf + 4;
2794 rdata->iov[1].iov_len = server->vals->read_rsp_size - 4;
2795 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
2796 rdata->iov[0].iov_base, server->vals->read_rsp_size);
2798 length = rdata->copy_into_pages(server, rdata, &iter);
2805 dequeue_mid(mid, false);
2810 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid)
2812 char *buf = server->smallbuf;
2813 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
2814 unsigned int npages;
2815 struct page **pages;
2817 unsigned int buflen = server->pdu_size;
2821 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
2822 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
2824 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
2827 server->total_read += rc;
2829 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
2830 server->vals->read_rsp_size;
2831 npages = DIV_ROUND_UP(len, PAGE_SIZE);
2833 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
2839 for (; i < npages; i++) {
2840 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
2847 /* read read data into pages */
2848 rc = read_data_into_pages(server, pages, npages, len);
2852 rc = cifs_discard_remaining_data(server);
2856 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
2857 pages, npages, len);
2861 *mid = smb2_find_mid(server, buf);
2863 cifs_dbg(FYI, "mid not found\n");
2865 cifs_dbg(FYI, "mid found\n");
2866 (*mid)->decrypted = true;
2867 rc = handle_read_data(server, *mid, buf,
2868 server->vals->read_rsp_size,
2869 pages, npages, len);
2873 for (i = i - 1; i >= 0; i--)
2878 cifs_discard_remaining_data(server);
2883 receive_encrypted_standard(struct TCP_Server_Info *server,
2884 struct mid_q_entry **mid)
2887 char *buf = server->smallbuf;
2888 unsigned int pdu_length = server->pdu_size;
2889 unsigned int buf_size;
2890 struct mid_q_entry *mid_entry;
2892 /* switch to large buffer if too big for a small one */
2893 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
2894 server->large_buf = true;
2895 memcpy(server->bigbuf, buf, server->total_read);
2896 buf = server->bigbuf;
2899 /* now read the rest */
2900 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
2901 pdu_length - HEADER_SIZE(server) + 1);
2904 server->total_read += length;
2906 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
2907 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0);
2911 mid_entry = smb2_find_mid(server, buf);
2912 if (mid_entry == NULL)
2913 cifs_dbg(FYI, "mid not found\n");
2915 cifs_dbg(FYI, "mid found\n");
2916 mid_entry->decrypted = true;
2921 if (mid_entry && mid_entry->handle)
2922 return mid_entry->handle(server, mid_entry);
2924 return cifs_handle_standard(server, mid_entry);
2928 smb3_receive_transform(struct TCP_Server_Info *server, struct mid_q_entry **mid)
2930 char *buf = server->smallbuf;
2931 unsigned int pdu_length = server->pdu_size;
2932 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
2933 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
2935 if (pdu_length < sizeof(struct smb2_transform_hdr) +
2936 sizeof(struct smb2_sync_hdr)) {
2937 cifs_dbg(VFS, "Transform message is too small (%u)\n",
2939 cifs_reconnect(server);
2940 wake_up(&server->response_q);
2941 return -ECONNABORTED;
2944 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
2945 cifs_dbg(VFS, "Transform message is broken\n");
2946 cifs_reconnect(server);
2947 wake_up(&server->response_q);
2948 return -ECONNABORTED;
2951 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server))
2952 return receive_encrypted_read(server, mid);
2954 return receive_encrypted_standard(server, mid);
2958 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
2960 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
2962 return handle_read_data(server, mid, buf, server->pdu_size,
2967 smb2_next_header(char *buf)
2969 struct smb2_sync_hdr *hdr = (struct smb2_sync_hdr *)buf;
2970 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
2972 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
2973 return sizeof(struct smb2_transform_hdr) +
2974 le32_to_cpu(t_hdr->OriginalMessageSize);
2976 return le32_to_cpu(hdr->NextCommand);
2979 struct smb_version_operations smb20_operations = {
2980 .compare_fids = smb2_compare_fids,
2981 .setup_request = smb2_setup_request,
2982 .setup_async_request = smb2_setup_async_request,
2983 .check_receive = smb2_check_receive,
2984 .add_credits = smb2_add_credits,
2985 .set_credits = smb2_set_credits,
2986 .get_credits_field = smb2_get_credits_field,
2987 .get_credits = smb2_get_credits,
2988 .wait_mtu_credits = cifs_wait_mtu_credits,
2989 .get_next_mid = smb2_get_next_mid,
2990 .read_data_offset = smb2_read_data_offset,
2991 .read_data_length = smb2_read_data_length,
2992 .map_error = map_smb2_to_linux_error,
2993 .find_mid = smb2_find_mid,
2994 .check_message = smb2_check_message,
2995 .dump_detail = smb2_dump_detail,
2996 .clear_stats = smb2_clear_stats,
2997 .print_stats = smb2_print_stats,
2998 .is_oplock_break = smb2_is_valid_oplock_break,
2999 .handle_cancelled_mid = smb2_handle_cancelled_mid,
3000 .downgrade_oplock = smb2_downgrade_oplock,
3001 .need_neg = smb2_need_neg,
3002 .negotiate = smb2_negotiate,
3003 .negotiate_wsize = smb2_negotiate_wsize,
3004 .negotiate_rsize = smb2_negotiate_rsize,
3005 .sess_setup = SMB2_sess_setup,
3006 .logoff = SMB2_logoff,
3007 .tree_connect = SMB2_tcon,
3008 .tree_disconnect = SMB2_tdis,
3009 .qfs_tcon = smb2_qfs_tcon,
3010 .is_path_accessible = smb2_is_path_accessible,
3011 .can_echo = smb2_can_echo,
3013 .query_path_info = smb2_query_path_info,
3014 .get_srv_inum = smb2_get_srv_inum,
3015 .query_file_info = smb2_query_file_info,
3016 .set_path_size = smb2_set_path_size,
3017 .set_file_size = smb2_set_file_size,
3018 .set_file_info = smb2_set_file_info,
3019 .set_compression = smb2_set_compression,
3020 .mkdir = smb2_mkdir,
3021 .mkdir_setinfo = smb2_mkdir_setinfo,
3022 .rmdir = smb2_rmdir,
3023 .unlink = smb2_unlink,
3024 .rename = smb2_rename_path,
3025 .create_hardlink = smb2_create_hardlink,
3026 .query_symlink = smb2_query_symlink,
3027 .query_mf_symlink = smb3_query_mf_symlink,
3028 .create_mf_symlink = smb3_create_mf_symlink,
3029 .open = smb2_open_file,
3030 .set_fid = smb2_set_fid,
3031 .close = smb2_close_file,
3032 .flush = smb2_flush_file,
3033 .async_readv = smb2_async_readv,
3034 .async_writev = smb2_async_writev,
3035 .sync_read = smb2_sync_read,
3036 .sync_write = smb2_sync_write,
3037 .query_dir_first = smb2_query_dir_first,
3038 .query_dir_next = smb2_query_dir_next,
3039 .close_dir = smb2_close_dir,
3040 .calc_smb_size = smb2_calc_size,
3041 .is_status_pending = smb2_is_status_pending,
3042 .is_session_expired = smb2_is_session_expired,
3043 .oplock_response = smb2_oplock_response,
3044 .queryfs = smb2_queryfs,
3045 .mand_lock = smb2_mand_lock,
3046 .mand_unlock_range = smb2_unlock_range,
3047 .push_mand_locks = smb2_push_mandatory_locks,
3048 .get_lease_key = smb2_get_lease_key,
3049 .set_lease_key = smb2_set_lease_key,
3050 .new_lease_key = smb2_new_lease_key,
3051 .calc_signature = smb2_calc_signature,
3052 .is_read_op = smb2_is_read_op,
3053 .set_oplock_level = smb2_set_oplock_level,
3054 .create_lease_buf = smb2_create_lease_buf,
3055 .parse_lease_buf = smb2_parse_lease_buf,
3056 .copychunk_range = smb2_copychunk_range,
3057 .wp_retry_size = smb2_wp_retry_size,
3058 .dir_needs_close = smb2_dir_needs_close,
3059 .get_dfs_refer = smb2_get_dfs_refer,
3060 .select_sectype = smb2_select_sectype,
3061 #ifdef CONFIG_CIFS_XATTR
3062 .query_all_EAs = smb2_query_eas,
3063 .set_EA = smb2_set_ea,
3064 #endif /* CIFS_XATTR */
3065 #ifdef CONFIG_CIFS_ACL
3066 .get_acl = get_smb2_acl,
3067 .get_acl_by_fid = get_smb2_acl_by_fid,
3068 .set_acl = set_smb2_acl,
3069 #endif /* CIFS_ACL */
3070 .next_header = smb2_next_header,
3073 struct smb_version_operations smb21_operations = {
3074 .compare_fids = smb2_compare_fids,
3075 .setup_request = smb2_setup_request,
3076 .setup_async_request = smb2_setup_async_request,
3077 .check_receive = smb2_check_receive,
3078 .add_credits = smb2_add_credits,
3079 .set_credits = smb2_set_credits,
3080 .get_credits_field = smb2_get_credits_field,
3081 .get_credits = smb2_get_credits,
3082 .wait_mtu_credits = smb2_wait_mtu_credits,
3083 .get_next_mid = smb2_get_next_mid,
3084 .read_data_offset = smb2_read_data_offset,
3085 .read_data_length = smb2_read_data_length,
3086 .map_error = map_smb2_to_linux_error,
3087 .find_mid = smb2_find_mid,
3088 .check_message = smb2_check_message,
3089 .dump_detail = smb2_dump_detail,
3090 .clear_stats = smb2_clear_stats,
3091 .print_stats = smb2_print_stats,
3092 .is_oplock_break = smb2_is_valid_oplock_break,
3093 .handle_cancelled_mid = smb2_handle_cancelled_mid,
3094 .downgrade_oplock = smb2_downgrade_oplock,
3095 .need_neg = smb2_need_neg,
3096 .negotiate = smb2_negotiate,
3097 .negotiate_wsize = smb2_negotiate_wsize,
3098 .negotiate_rsize = smb2_negotiate_rsize,
3099 .sess_setup = SMB2_sess_setup,
3100 .logoff = SMB2_logoff,
3101 .tree_connect = SMB2_tcon,
3102 .tree_disconnect = SMB2_tdis,
3103 .qfs_tcon = smb2_qfs_tcon,
3104 .is_path_accessible = smb2_is_path_accessible,
3105 .can_echo = smb2_can_echo,
3107 .query_path_info = smb2_query_path_info,
3108 .get_srv_inum = smb2_get_srv_inum,
3109 .query_file_info = smb2_query_file_info,
3110 .set_path_size = smb2_set_path_size,
3111 .set_file_size = smb2_set_file_size,
3112 .set_file_info = smb2_set_file_info,
3113 .set_compression = smb2_set_compression,
3114 .mkdir = smb2_mkdir,
3115 .mkdir_setinfo = smb2_mkdir_setinfo,
3116 .rmdir = smb2_rmdir,
3117 .unlink = smb2_unlink,
3118 .rename = smb2_rename_path,
3119 .create_hardlink = smb2_create_hardlink,
3120 .query_symlink = smb2_query_symlink,
3121 .query_mf_symlink = smb3_query_mf_symlink,
3122 .create_mf_symlink = smb3_create_mf_symlink,
3123 .open = smb2_open_file,
3124 .set_fid = smb2_set_fid,
3125 .close = smb2_close_file,
3126 .flush = smb2_flush_file,
3127 .async_readv = smb2_async_readv,
3128 .async_writev = smb2_async_writev,
3129 .sync_read = smb2_sync_read,
3130 .sync_write = smb2_sync_write,
3131 .query_dir_first = smb2_query_dir_first,
3132 .query_dir_next = smb2_query_dir_next,
3133 .close_dir = smb2_close_dir,
3134 .calc_smb_size = smb2_calc_size,
3135 .is_status_pending = smb2_is_status_pending,
3136 .is_session_expired = smb2_is_session_expired,
3137 .oplock_response = smb2_oplock_response,
3138 .queryfs = smb2_queryfs,
3139 .mand_lock = smb2_mand_lock,
3140 .mand_unlock_range = smb2_unlock_range,
3141 .push_mand_locks = smb2_push_mandatory_locks,
3142 .get_lease_key = smb2_get_lease_key,
3143 .set_lease_key = smb2_set_lease_key,
3144 .new_lease_key = smb2_new_lease_key,
3145 .calc_signature = smb2_calc_signature,
3146 .is_read_op = smb21_is_read_op,
3147 .set_oplock_level = smb21_set_oplock_level,
3148 .create_lease_buf = smb2_create_lease_buf,
3149 .parse_lease_buf = smb2_parse_lease_buf,
3150 .copychunk_range = smb2_copychunk_range,
3151 .wp_retry_size = smb2_wp_retry_size,
3152 .dir_needs_close = smb2_dir_needs_close,
3153 .enum_snapshots = smb3_enum_snapshots,
3154 .get_dfs_refer = smb2_get_dfs_refer,
3155 .select_sectype = smb2_select_sectype,
3156 #ifdef CONFIG_CIFS_XATTR
3157 .query_all_EAs = smb2_query_eas,
3158 .set_EA = smb2_set_ea,
3159 #endif /* CIFS_XATTR */
3160 #ifdef CONFIG_CIFS_ACL
3161 .get_acl = get_smb2_acl,
3162 .get_acl_by_fid = get_smb2_acl_by_fid,
3163 .set_acl = set_smb2_acl,
3164 #endif /* CIFS_ACL */
3165 .next_header = smb2_next_header,
3168 struct smb_version_operations smb30_operations = {
3169 .compare_fids = smb2_compare_fids,
3170 .setup_request = smb2_setup_request,
3171 .setup_async_request = smb2_setup_async_request,
3172 .check_receive = smb2_check_receive,
3173 .add_credits = smb2_add_credits,
3174 .set_credits = smb2_set_credits,
3175 .get_credits_field = smb2_get_credits_field,
3176 .get_credits = smb2_get_credits,
3177 .wait_mtu_credits = smb2_wait_mtu_credits,
3178 .get_next_mid = smb2_get_next_mid,
3179 .read_data_offset = smb2_read_data_offset,
3180 .read_data_length = smb2_read_data_length,
3181 .map_error = map_smb2_to_linux_error,
3182 .find_mid = smb2_find_mid,
3183 .check_message = smb2_check_message,
3184 .dump_detail = smb2_dump_detail,
3185 .clear_stats = smb2_clear_stats,
3186 .print_stats = smb2_print_stats,
3187 .dump_share_caps = smb2_dump_share_caps,
3188 .is_oplock_break = smb2_is_valid_oplock_break,
3189 .handle_cancelled_mid = smb2_handle_cancelled_mid,
3190 .downgrade_oplock = smb2_downgrade_oplock,
3191 .need_neg = smb2_need_neg,
3192 .negotiate = smb2_negotiate,
3193 .negotiate_wsize = smb2_negotiate_wsize,
3194 .negotiate_rsize = smb2_negotiate_rsize,
3195 .sess_setup = SMB2_sess_setup,
3196 .logoff = SMB2_logoff,
3197 .tree_connect = SMB2_tcon,
3198 .tree_disconnect = SMB2_tdis,
3199 .qfs_tcon = smb3_qfs_tcon,
3200 .is_path_accessible = smb2_is_path_accessible,
3201 .can_echo = smb2_can_echo,
3203 .query_path_info = smb2_query_path_info,
3204 .get_srv_inum = smb2_get_srv_inum,
3205 .query_file_info = smb2_query_file_info,
3206 .set_path_size = smb2_set_path_size,
3207 .set_file_size = smb2_set_file_size,
3208 .set_file_info = smb2_set_file_info,
3209 .set_compression = smb2_set_compression,
3210 .mkdir = smb2_mkdir,
3211 .mkdir_setinfo = smb2_mkdir_setinfo,
3212 .rmdir = smb2_rmdir,
3213 .unlink = smb2_unlink,
3214 .rename = smb2_rename_path,
3215 .create_hardlink = smb2_create_hardlink,
3216 .query_symlink = smb2_query_symlink,
3217 .query_mf_symlink = smb3_query_mf_symlink,
3218 .create_mf_symlink = smb3_create_mf_symlink,
3219 .open = smb2_open_file,
3220 .set_fid = smb2_set_fid,
3221 .close = smb2_close_file,
3222 .flush = smb2_flush_file,
3223 .async_readv = smb2_async_readv,
3224 .async_writev = smb2_async_writev,
3225 .sync_read = smb2_sync_read,
3226 .sync_write = smb2_sync_write,
3227 .query_dir_first = smb2_query_dir_first,
3228 .query_dir_next = smb2_query_dir_next,
3229 .close_dir = smb2_close_dir,
3230 .calc_smb_size = smb2_calc_size,
3231 .is_status_pending = smb2_is_status_pending,
3232 .is_session_expired = smb2_is_session_expired,
3233 .oplock_response = smb2_oplock_response,
3234 .queryfs = smb2_queryfs,
3235 .mand_lock = smb2_mand_lock,
3236 .mand_unlock_range = smb2_unlock_range,
3237 .push_mand_locks = smb2_push_mandatory_locks,
3238 .get_lease_key = smb2_get_lease_key,
3239 .set_lease_key = smb2_set_lease_key,
3240 .new_lease_key = smb2_new_lease_key,
3241 .generate_signingkey = generate_smb30signingkey,
3242 .calc_signature = smb3_calc_signature,
3243 .set_integrity = smb3_set_integrity,
3244 .is_read_op = smb21_is_read_op,
3245 .set_oplock_level = smb3_set_oplock_level,
3246 .create_lease_buf = smb3_create_lease_buf,
3247 .parse_lease_buf = smb3_parse_lease_buf,
3248 .copychunk_range = smb2_copychunk_range,
3249 .duplicate_extents = smb2_duplicate_extents,
3250 .validate_negotiate = smb3_validate_negotiate,
3251 .wp_retry_size = smb2_wp_retry_size,
3252 .dir_needs_close = smb2_dir_needs_close,
3253 .fallocate = smb3_fallocate,
3254 .enum_snapshots = smb3_enum_snapshots,
3255 .init_transform_rq = smb3_init_transform_rq,
3256 .free_transform_rq = smb3_free_transform_rq,
3257 .is_transform_hdr = smb3_is_transform_hdr,
3258 .receive_transform = smb3_receive_transform,
3259 .get_dfs_refer = smb2_get_dfs_refer,
3260 .select_sectype = smb2_select_sectype,
3261 #ifdef CONFIG_CIFS_XATTR
3262 .query_all_EAs = smb2_query_eas,
3263 .set_EA = smb2_set_ea,
3264 #endif /* CIFS_XATTR */
3265 #ifdef CONFIG_CIFS_ACL
3266 .get_acl = get_smb2_acl,
3267 .get_acl_by_fid = get_smb2_acl_by_fid,
3268 .set_acl = set_smb2_acl,
3269 #endif /* CIFS_ACL */
3270 .next_header = smb2_next_header,
3273 #ifdef CONFIG_CIFS_SMB311
3274 struct smb_version_operations smb311_operations = {
3275 .compare_fids = smb2_compare_fids,
3276 .setup_request = smb2_setup_request,
3277 .setup_async_request = smb2_setup_async_request,
3278 .check_receive = smb2_check_receive,
3279 .add_credits = smb2_add_credits,
3280 .set_credits = smb2_set_credits,
3281 .get_credits_field = smb2_get_credits_field,
3282 .get_credits = smb2_get_credits,
3283 .wait_mtu_credits = smb2_wait_mtu_credits,
3284 .get_next_mid = smb2_get_next_mid,
3285 .read_data_offset = smb2_read_data_offset,
3286 .read_data_length = smb2_read_data_length,
3287 .map_error = map_smb2_to_linux_error,
3288 .find_mid = smb2_find_mid,
3289 .check_message = smb2_check_message,
3290 .dump_detail = smb2_dump_detail,
3291 .clear_stats = smb2_clear_stats,
3292 .print_stats = smb2_print_stats,
3293 .dump_share_caps = smb2_dump_share_caps,
3294 .is_oplock_break = smb2_is_valid_oplock_break,
3295 .handle_cancelled_mid = smb2_handle_cancelled_mid,
3296 .downgrade_oplock = smb2_downgrade_oplock,
3297 .need_neg = smb2_need_neg,
3298 .negotiate = smb2_negotiate,
3299 .negotiate_wsize = smb2_negotiate_wsize,
3300 .negotiate_rsize = smb2_negotiate_rsize,
3301 .sess_setup = SMB2_sess_setup,
3302 .logoff = SMB2_logoff,
3303 .tree_connect = SMB2_tcon,
3304 .tree_disconnect = SMB2_tdis,
3305 .qfs_tcon = smb3_qfs_tcon,
3306 .is_path_accessible = smb2_is_path_accessible,
3307 .can_echo = smb2_can_echo,
3309 .query_path_info = smb2_query_path_info,
3310 .get_srv_inum = smb2_get_srv_inum,
3311 .query_file_info = smb2_query_file_info,
3312 .set_path_size = smb2_set_path_size,
3313 .set_file_size = smb2_set_file_size,
3314 .set_file_info = smb2_set_file_info,
3315 .set_compression = smb2_set_compression,
3316 .mkdir = smb2_mkdir,
3317 .mkdir_setinfo = smb2_mkdir_setinfo,
3318 .posix_mkdir = smb311_posix_mkdir,
3319 .rmdir = smb2_rmdir,
3320 .unlink = smb2_unlink,
3321 .rename = smb2_rename_path,
3322 .create_hardlink = smb2_create_hardlink,
3323 .query_symlink = smb2_query_symlink,
3324 .query_mf_symlink = smb3_query_mf_symlink,
3325 .create_mf_symlink = smb3_create_mf_symlink,
3326 .open = smb2_open_file,
3327 .set_fid = smb2_set_fid,
3328 .close = smb2_close_file,
3329 .flush = smb2_flush_file,
3330 .async_readv = smb2_async_readv,
3331 .async_writev = smb2_async_writev,
3332 .sync_read = smb2_sync_read,
3333 .sync_write = smb2_sync_write,
3334 .query_dir_first = smb2_query_dir_first,
3335 .query_dir_next = smb2_query_dir_next,
3336 .close_dir = smb2_close_dir,
3337 .calc_smb_size = smb2_calc_size,
3338 .is_status_pending = smb2_is_status_pending,
3339 .is_session_expired = smb2_is_session_expired,
3340 .oplock_response = smb2_oplock_response,
3341 .queryfs = smb2_queryfs,
3342 .mand_lock = smb2_mand_lock,
3343 .mand_unlock_range = smb2_unlock_range,
3344 .push_mand_locks = smb2_push_mandatory_locks,
3345 .get_lease_key = smb2_get_lease_key,
3346 .set_lease_key = smb2_set_lease_key,
3347 .new_lease_key = smb2_new_lease_key,
3348 .generate_signingkey = generate_smb311signingkey,
3349 .calc_signature = smb3_calc_signature,
3350 .set_integrity = smb3_set_integrity,
3351 .is_read_op = smb21_is_read_op,
3352 .set_oplock_level = smb3_set_oplock_level,
3353 .create_lease_buf = smb3_create_lease_buf,
3354 .parse_lease_buf = smb3_parse_lease_buf,
3355 .copychunk_range = smb2_copychunk_range,
3356 .duplicate_extents = smb2_duplicate_extents,
3357 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
3358 .wp_retry_size = smb2_wp_retry_size,
3359 .dir_needs_close = smb2_dir_needs_close,
3360 .fallocate = smb3_fallocate,
3361 .enum_snapshots = smb3_enum_snapshots,
3362 .init_transform_rq = smb3_init_transform_rq,
3363 .free_transform_rq = smb3_free_transform_rq,
3364 .is_transform_hdr = smb3_is_transform_hdr,
3365 .receive_transform = smb3_receive_transform,
3366 .get_dfs_refer = smb2_get_dfs_refer,
3367 .select_sectype = smb2_select_sectype,
3368 #ifdef CONFIG_CIFS_XATTR
3369 .query_all_EAs = smb2_query_eas,
3370 .set_EA = smb2_set_ea,
3371 #endif /* CIFS_XATTR */
3372 .next_header = smb2_next_header,
3374 #endif /* CIFS_SMB311 */
3376 struct smb_version_values smb20_values = {
3377 .version_string = SMB20_VERSION_STRING,
3378 .protocol_id = SMB20_PROT_ID,
3379 .req_capabilities = 0, /* MBZ */
3380 .large_lock_type = 0,
3381 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3382 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3383 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3384 .header_size = sizeof(struct smb2_sync_hdr),
3385 .header_preamble_size = 0,
3386 .max_header_size = MAX_SMB2_HDR_SIZE,
3387 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3388 .lock_cmd = SMB2_LOCK,
3390 .cap_nt_find = SMB2_NT_FIND,
3391 .cap_large_files = SMB2_LARGE_FILES,
3392 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3393 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3394 .create_lease_size = sizeof(struct create_lease),
3397 struct smb_version_values smb21_values = {
3398 .version_string = SMB21_VERSION_STRING,
3399 .protocol_id = SMB21_PROT_ID,
3400 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
3401 .large_lock_type = 0,
3402 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3403 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3404 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3405 .header_size = sizeof(struct smb2_sync_hdr),
3406 .header_preamble_size = 0,
3407 .max_header_size = MAX_SMB2_HDR_SIZE,
3408 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3409 .lock_cmd = SMB2_LOCK,
3411 .cap_nt_find = SMB2_NT_FIND,
3412 .cap_large_files = SMB2_LARGE_FILES,
3413 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3414 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3415 .create_lease_size = sizeof(struct create_lease),
3418 struct smb_version_values smb3any_values = {
3419 .version_string = SMB3ANY_VERSION_STRING,
3420 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
3421 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
3422 .large_lock_type = 0,
3423 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3424 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3425 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3426 .header_size = sizeof(struct smb2_sync_hdr),
3427 .header_preamble_size = 0,
3428 .max_header_size = MAX_SMB2_HDR_SIZE,
3429 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3430 .lock_cmd = SMB2_LOCK,
3432 .cap_nt_find = SMB2_NT_FIND,
3433 .cap_large_files = SMB2_LARGE_FILES,
3434 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3435 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3436 .create_lease_size = sizeof(struct create_lease_v2),
3439 struct smb_version_values smbdefault_values = {
3440 .version_string = SMBDEFAULT_VERSION_STRING,
3441 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
3442 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
3443 .large_lock_type = 0,
3444 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3445 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3446 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3447 .header_size = sizeof(struct smb2_sync_hdr),
3448 .header_preamble_size = 0,
3449 .max_header_size = MAX_SMB2_HDR_SIZE,
3450 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3451 .lock_cmd = SMB2_LOCK,
3453 .cap_nt_find = SMB2_NT_FIND,
3454 .cap_large_files = SMB2_LARGE_FILES,
3455 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3456 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3457 .create_lease_size = sizeof(struct create_lease_v2),
3460 struct smb_version_values smb30_values = {
3461 .version_string = SMB30_VERSION_STRING,
3462 .protocol_id = SMB30_PROT_ID,
3463 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
3464 .large_lock_type = 0,
3465 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3466 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3467 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3468 .header_size = sizeof(struct smb2_sync_hdr),
3469 .header_preamble_size = 0,
3470 .max_header_size = MAX_SMB2_HDR_SIZE,
3471 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3472 .lock_cmd = SMB2_LOCK,
3474 .cap_nt_find = SMB2_NT_FIND,
3475 .cap_large_files = SMB2_LARGE_FILES,
3476 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3477 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3478 .create_lease_size = sizeof(struct create_lease_v2),
3481 struct smb_version_values smb302_values = {
3482 .version_string = SMB302_VERSION_STRING,
3483 .protocol_id = SMB302_PROT_ID,
3484 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
3485 .large_lock_type = 0,
3486 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3487 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3488 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3489 .header_size = sizeof(struct smb2_sync_hdr),
3490 .header_preamble_size = 0,
3491 .max_header_size = MAX_SMB2_HDR_SIZE,
3492 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3493 .lock_cmd = SMB2_LOCK,
3495 .cap_nt_find = SMB2_NT_FIND,
3496 .cap_large_files = SMB2_LARGE_FILES,
3497 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3498 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3499 .create_lease_size = sizeof(struct create_lease_v2),
3502 #ifdef CONFIG_CIFS_SMB311
3503 struct smb_version_values smb311_values = {
3504 .version_string = SMB311_VERSION_STRING,
3505 .protocol_id = SMB311_PROT_ID,
3506 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
3507 .large_lock_type = 0,
3508 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3509 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3510 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3511 .header_size = sizeof(struct smb2_sync_hdr),
3512 .header_preamble_size = 0,
3513 .max_header_size = MAX_SMB2_HDR_SIZE,
3514 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3515 .lock_cmd = SMB2_LOCK,
3517 .cap_nt_find = SMB2_NT_FIND,
3518 .cap_large_files = SMB2_LARGE_FILES,
3519 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3520 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3521 .create_lease_size = sizeof(struct create_lease_v2),