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);
78 /* eg found case where write overlapping reconnect messed up credits */
79 if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0))
80 trace_smb3_reconnect_with_invalid_credits(server->CurrentMid,
81 server->hostname, *val);
85 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
86 printk_once(KERN_WARNING "server overflowed SMB3 credits\n");
89 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
90 rc = change_conf(server);
92 * Sometimes server returns 0 credits on oplock break ack - we need to
93 * rebalance credits in this case.
95 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
97 if (server->credits > 1) {
99 server->oplock_credits++;
102 spin_unlock(&server->req_lock);
103 wake_up(&server->request_q);
105 cifs_reconnect(server);
109 smb2_set_credits(struct TCP_Server_Info *server, const int val)
111 spin_lock(&server->req_lock);
112 server->credits = val;
114 server->reconnect_instance++;
115 spin_unlock(&server->req_lock);
119 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
123 return &server->echo_credits;
125 return &server->oplock_credits;
127 return &server->credits;
132 smb2_get_credits(struct mid_q_entry *mid)
134 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)mid->resp_buf;
136 return le16_to_cpu(shdr->CreditRequest);
140 smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
141 unsigned int *num, unsigned int *credits)
144 unsigned int scredits;
146 spin_lock(&server->req_lock);
148 if (server->credits <= 0) {
149 spin_unlock(&server->req_lock);
150 cifs_num_waiters_inc(server);
151 rc = wait_event_killable(server->request_q,
152 has_credits(server, &server->credits));
153 cifs_num_waiters_dec(server);
156 spin_lock(&server->req_lock);
158 if (server->tcpStatus == CifsExiting) {
159 spin_unlock(&server->req_lock);
163 scredits = server->credits;
164 /* can deadlock with reopen */
166 *num = SMB2_MAX_BUFFER_SIZE;
171 /* leave one credit for a possible reopen */
173 *num = min_t(unsigned int, size,
174 scredits * SMB2_MAX_BUFFER_SIZE);
176 *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
177 server->credits -= *credits;
182 spin_unlock(&server->req_lock);
187 smb2_get_next_mid(struct TCP_Server_Info *server)
190 /* for SMB2 we need the current value */
191 spin_lock(&GlobalMid_Lock);
192 mid = server->CurrentMid++;
193 spin_unlock(&GlobalMid_Lock);
197 static struct mid_q_entry *
198 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
200 struct mid_q_entry *mid;
201 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
202 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
204 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
205 cifs_dbg(VFS, "encrypted frame parsing not supported yet");
209 spin_lock(&GlobalMid_Lock);
210 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
211 if ((mid->mid == wire_mid) &&
212 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
213 (mid->command == shdr->Command)) {
214 kref_get(&mid->refcount);
215 spin_unlock(&GlobalMid_Lock);
219 spin_unlock(&GlobalMid_Lock);
224 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
226 #ifdef CONFIG_CIFS_DEBUG2
227 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
229 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
230 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
232 cifs_dbg(VFS, "smb buf %p len %u\n", buf,
233 server->ops->calc_smb_size(buf, server));
238 smb2_need_neg(struct TCP_Server_Info *server)
240 return server->max_read == 0;
244 smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
247 ses->server->CurrentMid = 0;
248 rc = SMB2_negotiate(xid, ses);
249 /* BB we probably don't need to retry with modern servers */
256 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
258 struct TCP_Server_Info *server = tcon->ses->server;
261 /* start with specified wsize, or default */
262 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
263 wsize = min_t(unsigned int, wsize, server->max_write);
264 #ifdef CONFIG_CIFS_SMB_DIRECT
267 wsize = min_t(unsigned int,
268 wsize, server->smbd_conn->max_fragmented_send_size);
270 wsize = min_t(unsigned int,
271 wsize, server->smbd_conn->max_readwrite_size);
274 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
275 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
281 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
283 struct TCP_Server_Info *server = tcon->ses->server;
286 /* start with specified rsize, or default */
287 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
288 rsize = min_t(unsigned int, rsize, server->max_read);
289 #ifdef CONFIG_CIFS_SMB_DIRECT
292 rsize = min_t(unsigned int,
293 rsize, server->smbd_conn->max_fragmented_recv_size);
295 rsize = min_t(unsigned int,
296 rsize, server->smbd_conn->max_readwrite_size);
300 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
301 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
308 parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
310 struct cifs_server_iface **iface_list,
313 struct network_interface_info_ioctl_rsp *p;
314 struct sockaddr_in *addr4;
315 struct sockaddr_in6 *addr6;
316 struct iface_info_ipv4 *p4;
317 struct iface_info_ipv6 *p6;
318 struct cifs_server_iface *info;
328 * Fist pass: count and sanity check
331 bytes_left = buf_len;
333 while (bytes_left >= sizeof(*p)) {
335 next = le32_to_cpu(p->Next);
337 bytes_left -= sizeof(*p);
340 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
345 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
350 if (bytes_left || p->Next)
351 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
355 * Second pass: extract info to internal structure
358 *iface_list = kcalloc(nb_iface, sizeof(**iface_list), GFP_KERNEL);
365 bytes_left = buf_len;
367 while (bytes_left >= sizeof(*p)) {
368 info->speed = le64_to_cpu(p->LinkSpeed);
369 info->rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE);
370 info->rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE);
372 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, *iface_count);
373 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
374 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
375 le32_to_cpu(p->Capability));
379 * The kernel and wire socket structures have the same
380 * layout and use network byte order but make the
381 * conversion explicit in case either one changes.
384 addr4 = (struct sockaddr_in *)&info->sockaddr;
385 p4 = (struct iface_info_ipv4 *)p->Buffer;
386 addr4->sin_family = AF_INET;
387 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
389 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
390 addr4->sin_port = cpu_to_be16(CIFS_PORT);
392 cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
396 addr6 = (struct sockaddr_in6 *)&info->sockaddr;
397 p6 = (struct iface_info_ipv6 *)p->Buffer;
398 addr6->sin6_family = AF_INET6;
399 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
401 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
402 addr6->sin6_flowinfo = 0;
403 addr6->sin6_scope_id = 0;
404 addr6->sin6_port = cpu_to_be16(CIFS_PORT);
406 cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
411 "%s: skipping unsupported socket family\n",
419 next = le32_to_cpu(p->Next);
422 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
442 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
445 unsigned int ret_data_len = 0;
446 struct network_interface_info_ioctl_rsp *out_buf = NULL;
447 struct cifs_server_iface *iface_list;
449 struct cifs_ses *ses = tcon->ses;
451 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
452 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
453 NULL /* no data input */, 0 /* no data input */,
454 (char **)&out_buf, &ret_data_len);
455 if (rc == -EOPNOTSUPP) {
457 "server does not support query network interfaces\n");
459 } else if (rc != 0) {
460 cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
464 rc = parse_server_interfaces(out_buf, ret_data_len,
465 &iface_list, &iface_count);
469 spin_lock(&ses->iface_lock);
470 kfree(ses->iface_list);
471 ses->iface_list = iface_list;
472 ses->iface_count = iface_count;
473 ses->iface_last_update = jiffies;
474 spin_unlock(&ses->iface_lock);
482 smb2_close_cached_fid(struct kref *ref)
484 struct cached_fid *cfid = container_of(ref, struct cached_fid,
487 if (cfid->is_valid) {
488 cifs_dbg(FYI, "clear cached root file handle\n");
489 SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid,
490 cfid->fid->volatile_fid);
491 cfid->is_valid = false;
495 void close_shroot(struct cached_fid *cfid)
497 mutex_lock(&cfid->fid_mutex);
498 kref_put(&cfid->refcount, smb2_close_cached_fid);
499 mutex_unlock(&cfid->fid_mutex);
503 smb2_cached_lease_break(struct work_struct *work)
505 struct cached_fid *cfid = container_of(work,
506 struct cached_fid, lease_break);
512 * Open the directory at the root of a share
514 int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid)
516 struct cifs_open_parms oparams;
518 __le16 srch_path = 0; /* Null - since an open of top of share */
519 u8 oplock = SMB2_OPLOCK_LEVEL_II;
521 mutex_lock(&tcon->crfid.fid_mutex);
522 if (tcon->crfid.is_valid) {
523 cifs_dbg(FYI, "found a cached root file handle\n");
524 memcpy(pfid, tcon->crfid.fid, sizeof(struct cifs_fid));
525 kref_get(&tcon->crfid.refcount);
526 mutex_unlock(&tcon->crfid.fid_mutex);
531 oparams.create_options = 0;
532 oparams.desired_access = FILE_READ_ATTRIBUTES;
533 oparams.disposition = FILE_OPEN;
535 oparams.reconnect = false;
537 rc = SMB2_open(xid, &oparams, &srch_path, &oplock, NULL, NULL, NULL);
539 memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid));
540 tcon->crfid.tcon = tcon;
541 tcon->crfid.is_valid = true;
542 kref_init(&tcon->crfid.refcount);
543 kref_get(&tcon->crfid.refcount);
545 mutex_unlock(&tcon->crfid.fid_mutex);
550 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
553 __le16 srch_path = 0; /* Null - open root of share */
554 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
555 struct cifs_open_parms oparms;
557 bool no_cached_open = tcon->nohandlecache;
560 oparms.desired_access = FILE_READ_ATTRIBUTES;
561 oparms.disposition = FILE_OPEN;
562 oparms.create_options = 0;
564 oparms.reconnect = false;
567 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
570 rc = open_shroot(xid, tcon, &fid);
575 SMB3_request_interfaces(xid, tcon);
577 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
578 FS_ATTRIBUTE_INFORMATION);
579 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
580 FS_DEVICE_INFORMATION);
581 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
582 FS_VOLUME_INFORMATION);
583 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
584 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
586 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
588 close_shroot(&tcon->crfid);
594 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
597 __le16 srch_path = 0; /* Null - open root of share */
598 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
599 struct cifs_open_parms oparms;
603 oparms.desired_access = FILE_READ_ATTRIBUTES;
604 oparms.disposition = FILE_OPEN;
605 oparms.create_options = 0;
607 oparms.reconnect = false;
609 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
613 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
614 FS_ATTRIBUTE_INFORMATION);
615 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
616 FS_DEVICE_INFORMATION);
617 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
622 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
623 struct cifs_sb_info *cifs_sb, const char *full_path)
627 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
628 struct cifs_open_parms oparms;
631 if ((*full_path == 0) && tcon->crfid.is_valid)
634 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
639 oparms.desired_access = FILE_READ_ATTRIBUTES;
640 oparms.disposition = FILE_OPEN;
641 if (backup_cred(cifs_sb))
642 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
644 oparms.create_options = 0;
646 oparms.reconnect = false;
648 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
654 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
660 smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
661 struct cifs_sb_info *cifs_sb, const char *full_path,
662 u64 *uniqueid, FILE_ALL_INFO *data)
664 *uniqueid = le64_to_cpu(data->IndexNumber);
669 smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
670 struct cifs_fid *fid, FILE_ALL_INFO *data)
673 struct smb2_file_all_info *smb2_data;
675 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
677 if (smb2_data == NULL)
680 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
683 move_smb2_info_to_cifs(data, smb2_data);
688 #ifdef CONFIG_CIFS_XATTR
690 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
691 struct smb2_file_full_ea_info *src, size_t src_size,
692 const unsigned char *ea_name)
695 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
697 size_t name_len, value_len, user_name_len;
699 while (src_size > 0) {
700 name = &src->ea_data[0];
701 name_len = (size_t)src->ea_name_length;
702 value = &src->ea_data[src->ea_name_length + 1];
703 value_len = (size_t)le16_to_cpu(src->ea_value_length);
709 if (src_size < 8 + name_len + 1 + value_len) {
710 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
716 if (ea_name_len == name_len &&
717 memcmp(ea_name, name, name_len) == 0) {
721 if (dst_size < value_len) {
725 memcpy(dst, value, value_len);
729 /* 'user.' plus a terminating null */
730 user_name_len = 5 + 1 + name_len;
734 if (dst_size >= user_name_len) {
735 dst_size -= user_name_len;
736 memcpy(dst, "user.", 5);
738 memcpy(dst, src->ea_data, name_len);
742 } else if (dst_size == 0) {
743 /* skip copy - calc size only */
745 /* stop before overrun buffer */
751 if (!src->next_entry_offset)
754 if (src_size < le32_to_cpu(src->next_entry_offset)) {
755 /* stop before overrun buffer */
759 src_size -= le32_to_cpu(src->next_entry_offset);
760 src = (void *)((char *)src +
761 le32_to_cpu(src->next_entry_offset));
764 /* didn't find the named attribute */
773 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
774 const unsigned char *path, const unsigned char *ea_name,
775 char *ea_data, size_t buf_size,
776 struct cifs_sb_info *cifs_sb)
780 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
781 struct cifs_open_parms oparms;
783 struct smb2_file_full_ea_info *smb2_data;
784 int ea_buf_size = SMB2_MIN_EA_BUF;
786 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
791 oparms.desired_access = FILE_READ_EA;
792 oparms.disposition = FILE_OPEN;
793 if (backup_cred(cifs_sb))
794 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
796 oparms.create_options = 0;
798 oparms.reconnect = false;
800 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
803 cifs_dbg(FYI, "open failed rc=%d\n", rc);
808 smb2_data = kzalloc(ea_buf_size, GFP_KERNEL);
809 if (smb2_data == NULL) {
810 SMB2_close(xid, tcon, fid.persistent_fid,
815 rc = SMB2_query_eas(xid, tcon, fid.persistent_fid,
817 ea_buf_size, smb2_data);
825 if (ea_buf_size > SMB2_MAX_EA_BUF) {
826 cifs_dbg(VFS, "EA size is too large\n");
827 SMB2_close(xid, tcon, fid.persistent_fid,
833 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
836 * If ea_name is NULL (listxattr) and there are no EAs, return 0 as it's
837 * not an error. Otherwise, the specified ea_name was not found.
840 rc = move_smb2_ea_to_cifs(ea_data, buf_size, smb2_data,
841 SMB2_MAX_EA_BUF, ea_name);
842 else if (!ea_name && rc == -ENODATA)
851 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
852 const char *path, const char *ea_name, const void *ea_value,
853 const __u16 ea_value_len, const struct nls_table *nls_codepage,
854 struct cifs_sb_info *cifs_sb)
858 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
859 struct cifs_open_parms oparms;
861 struct smb2_file_full_ea_info *ea;
862 int ea_name_len = strlen(ea_name);
865 if (ea_name_len > 255)
868 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
873 oparms.desired_access = FILE_WRITE_EA;
874 oparms.disposition = FILE_OPEN;
875 if (backup_cred(cifs_sb))
876 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
878 oparms.create_options = 0;
880 oparms.reconnect = false;
882 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
885 cifs_dbg(FYI, "open failed rc=%d\n", rc);
889 len = sizeof(ea) + ea_name_len + ea_value_len + 1;
890 ea = kzalloc(len, GFP_KERNEL);
892 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
896 ea->ea_name_length = ea_name_len;
897 ea->ea_value_length = cpu_to_le16(ea_value_len);
898 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
899 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
901 rc = SMB2_set_ea(xid, tcon, fid.persistent_fid, fid.volatile_fid, ea,
905 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
912 smb2_can_echo(struct TCP_Server_Info *server)
914 return server->echoes;
918 smb2_clear_stats(struct cifs_tcon *tcon)
921 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
922 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
923 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
928 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
930 seq_puts(m, "\n\tShare Capabilities:");
931 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
932 seq_puts(m, " DFS,");
933 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
934 seq_puts(m, " CONTINUOUS AVAILABILITY,");
935 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
936 seq_puts(m, " SCALEOUT,");
937 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
938 seq_puts(m, " CLUSTER,");
939 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
940 seq_puts(m, " ASYMMETRIC,");
941 if (tcon->capabilities == 0)
942 seq_puts(m, " None");
943 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
944 seq_puts(m, " Aligned,");
945 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
946 seq_puts(m, " Partition Aligned,");
947 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
948 seq_puts(m, " SSD,");
949 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
950 seq_puts(m, " TRIM-support,");
952 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
953 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
954 if (tcon->perf_sector_size)
955 seq_printf(m, "\tOptimal sector size: 0x%x",
956 tcon->perf_sector_size);
957 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
961 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
963 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
964 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
967 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
968 * totals (requests sent) since those SMBs are per-session not per tcon
970 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
971 (long long)(tcon->bytes_read),
972 (long long)(tcon->bytes_written));
973 seq_printf(m, "\nTreeConnects: %d total %d failed",
974 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
975 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
976 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
977 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
978 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
979 seq_printf(m, "\nCreates: %d total %d failed",
980 atomic_read(&sent[SMB2_CREATE_HE]),
981 atomic_read(&failed[SMB2_CREATE_HE]));
982 seq_printf(m, "\nCloses: %d total %d failed",
983 atomic_read(&sent[SMB2_CLOSE_HE]),
984 atomic_read(&failed[SMB2_CLOSE_HE]));
985 seq_printf(m, "\nFlushes: %d total %d failed",
986 atomic_read(&sent[SMB2_FLUSH_HE]),
987 atomic_read(&failed[SMB2_FLUSH_HE]));
988 seq_printf(m, "\nReads: %d total %d failed",
989 atomic_read(&sent[SMB2_READ_HE]),
990 atomic_read(&failed[SMB2_READ_HE]));
991 seq_printf(m, "\nWrites: %d total %d failed",
992 atomic_read(&sent[SMB2_WRITE_HE]),
993 atomic_read(&failed[SMB2_WRITE_HE]));
994 seq_printf(m, "\nLocks: %d total %d failed",
995 atomic_read(&sent[SMB2_LOCK_HE]),
996 atomic_read(&failed[SMB2_LOCK_HE]));
997 seq_printf(m, "\nIOCTLs: %d total %d failed",
998 atomic_read(&sent[SMB2_IOCTL_HE]),
999 atomic_read(&failed[SMB2_IOCTL_HE]));
1000 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1001 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1002 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1003 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1004 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1005 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1006 seq_printf(m, "\nQueryInfos: %d total %d failed",
1007 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1008 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1009 seq_printf(m, "\nSetInfos: %d total %d failed",
1010 atomic_read(&sent[SMB2_SET_INFO_HE]),
1011 atomic_read(&failed[SMB2_SET_INFO_HE]));
1012 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1013 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1014 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1018 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1020 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1021 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1023 cfile->fid.persistent_fid = fid->persistent_fid;
1024 cfile->fid.volatile_fid = fid->volatile_fid;
1025 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1027 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1028 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1032 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1033 struct cifs_fid *fid)
1035 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1039 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1040 u64 persistent_fid, u64 volatile_fid,
1041 struct copychunk_ioctl *pcchunk)
1044 unsigned int ret_data_len;
1045 struct resume_key_req *res_key;
1047 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1048 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
1049 NULL, 0 /* no input */,
1050 (char **)&res_key, &ret_data_len);
1053 cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1054 goto req_res_key_exit;
1056 if (ret_data_len < sizeof(struct resume_key_req)) {
1057 cifs_dbg(VFS, "Invalid refcopy resume key length\n");
1059 goto req_res_key_exit;
1061 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1069 smb2_copychunk_range(const unsigned int xid,
1070 struct cifsFileInfo *srcfile,
1071 struct cifsFileInfo *trgtfile, u64 src_off,
1072 u64 len, u64 dest_off)
1075 unsigned int ret_data_len;
1076 struct copychunk_ioctl *pcchunk;
1077 struct copychunk_ioctl_rsp *retbuf = NULL;
1078 struct cifs_tcon *tcon;
1079 int chunks_copied = 0;
1080 bool chunk_sizes_updated = false;
1081 ssize_t bytes_written, total_bytes_written = 0;
1083 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1085 if (pcchunk == NULL)
1088 cifs_dbg(FYI, "in smb2_copychunk_range - about to call request res key\n");
1089 /* Request a key from the server to identify the source of the copy */
1090 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1091 srcfile->fid.persistent_fid,
1092 srcfile->fid.volatile_fid, pcchunk);
1094 /* Note: request_res_key sets res_key null only if rc !=0 */
1098 /* For now array only one chunk long, will make more flexible later */
1099 pcchunk->ChunkCount = cpu_to_le32(1);
1100 pcchunk->Reserved = 0;
1101 pcchunk->Reserved2 = 0;
1103 tcon = tlink_tcon(trgtfile->tlink);
1106 pcchunk->SourceOffset = cpu_to_le64(src_off);
1107 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1109 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
1111 /* Request server copy to target from src identified by key */
1112 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1113 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1114 true /* is_fsctl */, (char *)pcchunk,
1115 sizeof(struct copychunk_ioctl), (char **)&retbuf,
1119 sizeof(struct copychunk_ioctl_rsp)) {
1120 cifs_dbg(VFS, "invalid cchunk response size\n");
1124 if (retbuf->TotalBytesWritten == 0) {
1125 cifs_dbg(FYI, "no bytes copied\n");
1130 * Check if server claimed to write more than we asked
1132 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1133 le32_to_cpu(pcchunk->Length)) {
1134 cifs_dbg(VFS, "invalid copy chunk response\n");
1138 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1139 cifs_dbg(VFS, "invalid num chunks written\n");
1145 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1146 src_off += bytes_written;
1147 dest_off += bytes_written;
1148 len -= bytes_written;
1149 total_bytes_written += bytes_written;
1151 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1152 le32_to_cpu(retbuf->ChunksWritten),
1153 le32_to_cpu(retbuf->ChunkBytesWritten),
1155 } else if (rc == -EINVAL) {
1156 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1159 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1160 le32_to_cpu(retbuf->ChunksWritten),
1161 le32_to_cpu(retbuf->ChunkBytesWritten),
1162 le32_to_cpu(retbuf->TotalBytesWritten));
1165 * Check if this is the first request using these sizes,
1166 * (ie check if copy succeed once with original sizes
1167 * and check if the server gave us different sizes after
1168 * we already updated max sizes on previous request).
1169 * if not then why is the server returning an error now
1171 if ((chunks_copied != 0) || chunk_sizes_updated)
1174 /* Check that server is not asking us to grow size */
1175 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1176 tcon->max_bytes_chunk)
1177 tcon->max_bytes_chunk =
1178 le32_to_cpu(retbuf->ChunkBytesWritten);
1180 goto cchunk_out; /* server gave us bogus size */
1182 /* No need to change MaxChunks since already set to 1 */
1183 chunk_sizes_updated = true;
1194 return total_bytes_written;
1198 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1199 struct cifs_fid *fid)
1201 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1205 smb2_read_data_offset(char *buf)
1207 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1208 return rsp->DataOffset;
1212 smb2_read_data_length(char *buf, bool in_remaining)
1214 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1217 return le32_to_cpu(rsp->DataRemaining);
1219 return le32_to_cpu(rsp->DataLength);
1224 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1225 struct cifs_io_parms *parms, unsigned int *bytes_read,
1226 char **buf, int *buf_type)
1228 parms->persistent_fid = pfid->persistent_fid;
1229 parms->volatile_fid = pfid->volatile_fid;
1230 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1234 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1235 struct cifs_io_parms *parms, unsigned int *written,
1236 struct kvec *iov, unsigned long nr_segs)
1239 parms->persistent_fid = pfid->persistent_fid;
1240 parms->volatile_fid = pfid->volatile_fid;
1241 return SMB2_write(xid, parms, written, iov, nr_segs);
1244 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1245 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1246 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1248 struct cifsInodeInfo *cifsi;
1251 cifsi = CIFS_I(inode);
1253 /* if file already sparse don't bother setting sparse again */
1254 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1255 return true; /* already sparse */
1257 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1258 return true; /* already not sparse */
1261 * Can't check for sparse support on share the usual way via the
1262 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1263 * since Samba server doesn't set the flag on the share, yet
1264 * supports the set sparse FSCTL and returns sparse correctly
1265 * in the file attributes. If we fail setting sparse though we
1266 * mark that server does not support sparse files for this share
1267 * to avoid repeatedly sending the unsupported fsctl to server
1268 * if the file is repeatedly extended.
1270 if (tcon->broken_sparse_sup)
1273 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1274 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1276 &setsparse, 1, NULL, NULL);
1278 tcon->broken_sparse_sup = true;
1279 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1284 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1286 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1292 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1293 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1295 __le64 eof = cpu_to_le64(size);
1296 struct inode *inode;
1299 * If extending file more than one page make sparse. Many Linux fs
1300 * make files sparse by default when extending via ftruncate
1302 inode = d_inode(cfile->dentry);
1304 if (!set_alloc && (size > inode->i_size + 8192)) {
1305 __u8 set_sparse = 1;
1307 /* whether set sparse succeeds or not, extend the file */
1308 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1311 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1312 cfile->fid.volatile_fid, cfile->pid, &eof);
1316 smb2_duplicate_extents(const unsigned int xid,
1317 struct cifsFileInfo *srcfile,
1318 struct cifsFileInfo *trgtfile, u64 src_off,
1319 u64 len, u64 dest_off)
1322 unsigned int ret_data_len;
1323 struct duplicate_extents_to_file dup_ext_buf;
1324 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1326 /* server fileays advertise duplicate extent support with this flag */
1327 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1328 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1331 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1332 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1333 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1334 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1335 dup_ext_buf.ByteCount = cpu_to_le64(len);
1336 cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld",
1337 src_off, dest_off, len);
1339 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1341 goto duplicate_extents_out;
1343 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1344 trgtfile->fid.volatile_fid,
1345 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1346 true /* is_fsctl */,
1347 (char *)&dup_ext_buf,
1348 sizeof(struct duplicate_extents_to_file),
1352 if (ret_data_len > 0)
1353 cifs_dbg(FYI, "non-zero response length in duplicate extents");
1355 duplicate_extents_out:
1360 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1361 struct cifsFileInfo *cfile)
1363 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1364 cfile->fid.volatile_fid);
1368 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
1369 struct cifsFileInfo *cfile)
1371 struct fsctl_set_integrity_information_req integr_info;
1372 unsigned int ret_data_len;
1374 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
1375 integr_info.Flags = 0;
1376 integr_info.Reserved = 0;
1378 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1379 cfile->fid.volatile_fid,
1380 FSCTL_SET_INTEGRITY_INFORMATION,
1381 true /* is_fsctl */,
1382 (char *)&integr_info,
1383 sizeof(struct fsctl_set_integrity_information_req),
1389 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
1390 #define GMT_TOKEN_SIZE 50
1393 * Input buffer contains (empty) struct smb_snapshot array with size filled in
1394 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
1397 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
1398 struct cifsFileInfo *cfile, void __user *ioc_buf)
1400 char *retbuf = NULL;
1401 unsigned int ret_data_len = 0;
1403 struct smb_snapshot_array snapshot_in;
1405 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1406 cfile->fid.volatile_fid,
1407 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
1408 true /* is_fsctl */,
1409 NULL, 0 /* no input data */,
1412 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
1417 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
1419 if (copy_from_user(&snapshot_in, ioc_buf,
1420 sizeof(struct smb_snapshot_array))) {
1427 * Check for min size, ie not large enough to fit even one GMT
1428 * token (snapshot). On the first ioctl some users may pass in
1429 * smaller size (or zero) to simply get the size of the array
1430 * so the user space caller can allocate sufficient memory
1431 * and retry the ioctl again with larger array size sufficient
1432 * to hold all of the snapshot GMT tokens on the second try.
1434 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
1435 ret_data_len = sizeof(struct smb_snapshot_array);
1438 * We return struct SRV_SNAPSHOT_ARRAY, followed by
1439 * the snapshot array (of 50 byte GMT tokens) each
1440 * representing an available previous version of the data
1442 if (ret_data_len > (snapshot_in.snapshot_array_size +
1443 sizeof(struct smb_snapshot_array)))
1444 ret_data_len = snapshot_in.snapshot_array_size +
1445 sizeof(struct smb_snapshot_array);
1447 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
1456 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
1457 const char *path, struct cifs_sb_info *cifs_sb,
1458 struct cifs_fid *fid, __u16 search_flags,
1459 struct cifs_search_info *srch_inf)
1463 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1464 struct cifs_open_parms oparms;
1466 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1471 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
1472 oparms.disposition = FILE_OPEN;
1473 if (backup_cred(cifs_sb))
1474 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1476 oparms.create_options = 0;
1478 oparms.reconnect = false;
1480 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
1483 cifs_dbg(FYI, "open dir failed rc=%d\n", rc);
1487 srch_inf->entries_in_buffer = 0;
1488 srch_inf->index_of_last_entry = 2;
1490 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
1491 fid->volatile_fid, 0, srch_inf);
1493 cifs_dbg(FYI, "query directory failed rc=%d\n", rc);
1494 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1500 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
1501 struct cifs_fid *fid, __u16 search_flags,
1502 struct cifs_search_info *srch_inf)
1504 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
1505 fid->volatile_fid, 0, srch_inf);
1509 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
1510 struct cifs_fid *fid)
1512 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1516 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
1517 * the number of credits and return true. Otherwise - return false.
1520 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
1522 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
1524 if (shdr->Status != STATUS_PENDING)
1528 spin_lock(&server->req_lock);
1529 server->credits += le16_to_cpu(shdr->CreditRequest);
1530 spin_unlock(&server->req_lock);
1531 wake_up(&server->request_q);
1538 smb2_is_session_expired(char *buf)
1540 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
1542 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
1543 shdr->Status != STATUS_USER_SESSION_DELETED)
1546 trace_smb3_ses_expired(shdr->TreeId, shdr->SessionId,
1547 le16_to_cpu(shdr->Command),
1548 le64_to_cpu(shdr->MessageId));
1549 cifs_dbg(FYI, "Session expired or deleted\n");
1555 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
1556 struct cifsInodeInfo *cinode)
1558 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
1559 return SMB2_lease_break(0, tcon, cinode->lease_key,
1560 smb2_get_lease_state(cinode));
1562 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
1564 CIFS_CACHE_READ(cinode) ? 1 : 0);
1568 smb2_set_related(struct smb_rqst *rqst)
1570 struct smb2_sync_hdr *shdr;
1572 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
1573 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
1576 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
1579 smb2_set_next_command(struct TCP_Server_Info *server, struct smb_rqst *rqst)
1581 struct smb2_sync_hdr *shdr;
1582 unsigned long len = smb_rqst_len(server, rqst);
1584 /* SMB headers in a compound are 8 byte aligned. */
1586 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
1587 rqst->rq_iov[rqst->rq_nvec].iov_len = 8 - (len & 7);
1589 len = smb_rqst_len(server, rqst);
1592 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
1593 shdr->NextCommand = cpu_to_le32(len);
1597 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
1598 struct kstatfs *buf)
1600 struct smb2_query_info_rsp *rsp;
1601 struct smb2_fs_full_size_info *info = NULL;
1602 struct smb_rqst rqst[3];
1603 int resp_buftype[3];
1604 struct kvec rsp_iov[3];
1605 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1606 struct kvec qi_iov[1];
1607 struct kvec close_iov[1];
1608 struct cifs_ses *ses = tcon->ses;
1609 struct TCP_Server_Info *server = ses->server;
1610 __le16 srch_path = 0; /* Null - open root of share */
1611 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1612 struct cifs_open_parms oparms;
1613 struct cifs_fid fid;
1617 if (smb3_encryption_required(tcon))
1618 flags |= CIFS_TRANSFORM_REQ;
1620 memset(rqst, 0, sizeof(rqst));
1621 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1622 memset(rsp_iov, 0, sizeof(rsp_iov));
1624 memset(&open_iov, 0, sizeof(open_iov));
1625 rqst[0].rq_iov = open_iov;
1626 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1629 oparms.desired_access = FILE_READ_ATTRIBUTES;
1630 oparms.disposition = FILE_OPEN;
1631 oparms.create_options = 0;
1633 oparms.reconnect = false;
1635 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, &srch_path);
1638 smb2_set_next_command(server, &rqst[0]);
1640 memset(&qi_iov, 0, sizeof(qi_iov));
1641 rqst[1].rq_iov = qi_iov;
1642 rqst[1].rq_nvec = 1;
1644 rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1645 FS_FULL_SIZE_INFORMATION,
1646 SMB2_O_INFO_FILESYSTEM, 0,
1647 sizeof(struct smb2_fs_full_size_info));
1650 smb2_set_next_command(server, &rqst[1]);
1651 smb2_set_related(&rqst[1]);
1653 memset(&close_iov, 0, sizeof(close_iov));
1654 rqst[2].rq_iov = close_iov;
1655 rqst[2].rq_nvec = 1;
1657 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
1660 smb2_set_related(&rqst[2]);
1662 rc = compound_send_recv(xid, ses, flags, 3, rqst,
1663 resp_buftype, rsp_iov);
1667 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1668 buf->f_type = SMB2_MAGIC_NUMBER;
1669 info = (struct smb2_fs_full_size_info *)(
1670 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1671 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1672 le32_to_cpu(rsp->OutputBufferLength),
1674 sizeof(struct smb2_fs_full_size_info));
1676 smb2_copy_fs_info_to_kstatfs(info, buf);
1679 SMB2_open_free(&rqst[0]);
1680 SMB2_query_info_free(&rqst[1]);
1681 SMB2_close_free(&rqst[2]);
1682 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1683 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1684 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1689 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
1690 struct kstatfs *buf)
1693 __le16 srch_path = 0; /* Null - open root of share */
1694 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1695 struct cifs_open_parms oparms;
1696 struct cifs_fid fid;
1698 if (!tcon->posix_extensions)
1699 return smb2_queryfs(xid, tcon, buf);
1702 oparms.desired_access = FILE_READ_ATTRIBUTES;
1703 oparms.disposition = FILE_OPEN;
1704 oparms.create_options = 0;
1706 oparms.reconnect = false;
1708 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
1712 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
1713 fid.volatile_fid, buf);
1714 buf->f_type = SMB2_MAGIC_NUMBER;
1715 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
1720 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
1722 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
1723 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
1727 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
1728 __u64 length, __u32 type, int lock, int unlock, bool wait)
1730 if (unlock && !lock)
1731 type = SMB2_LOCKFLAG_UNLOCK;
1732 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
1733 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
1734 current->tgid, length, offset, type, wait);
1738 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
1740 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
1744 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
1746 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
1750 smb2_new_lease_key(struct cifs_fid *fid)
1752 generate_random_uuid(fid->lease_key);
1756 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
1757 const char *search_name,
1758 struct dfs_info3_param **target_nodes,
1759 unsigned int *num_of_nodes,
1760 const struct nls_table *nls_codepage, int remap)
1763 __le16 *utf16_path = NULL;
1764 int utf16_path_len = 0;
1765 struct cifs_tcon *tcon;
1766 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
1767 struct get_dfs_referral_rsp *dfs_rsp = NULL;
1768 u32 dfs_req_size = 0, dfs_rsp_size = 0;
1770 cifs_dbg(FYI, "smb2_get_dfs_refer path <%s>\n", search_name);
1773 * Try to use the IPC tcon, otherwise just use any
1775 tcon = ses->tcon_ipc;
1777 spin_lock(&cifs_tcp_ses_lock);
1778 tcon = list_first_entry_or_null(&ses->tcon_list,
1783 spin_unlock(&cifs_tcp_ses_lock);
1787 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
1793 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
1795 nls_codepage, remap);
1801 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
1802 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
1808 /* Highest DFS referral version understood */
1809 dfs_req->MaxReferralLevel = DFS_VERSION;
1811 /* Path to resolve in an UTF-16 null-terminated string */
1812 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
1815 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
1816 FSCTL_DFS_GET_REFERRALS,
1817 true /* is_fsctl */,
1818 (char *)dfs_req, dfs_req_size,
1819 (char **)&dfs_rsp, &dfs_rsp_size);
1820 } while (rc == -EAGAIN);
1823 if ((rc != -ENOENT) && (rc != -EOPNOTSUPP))
1824 cifs_dbg(VFS, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc);
1828 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
1829 num_of_nodes, target_nodes,
1830 nls_codepage, remap, search_name,
1831 true /* is_unicode */);
1833 cifs_dbg(VFS, "parse error in smb2_get_dfs_refer rc=%d\n", rc);
1838 if (tcon && !tcon->ipc) {
1839 /* ipc tcons are not refcounted */
1840 spin_lock(&cifs_tcp_ses_lock);
1842 spin_unlock(&cifs_tcp_ses_lock);
1849 #define SMB2_SYMLINK_STRUCT_SIZE \
1850 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
1853 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
1854 const char *full_path, char **target_path,
1855 struct cifs_sb_info *cifs_sb)
1859 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1860 struct cifs_open_parms oparms;
1861 struct cifs_fid fid;
1862 struct kvec err_iov = {NULL, 0};
1863 struct smb2_err_rsp *err_buf = NULL;
1865 struct smb2_symlink_err_rsp *symlink;
1866 unsigned int sub_len;
1867 unsigned int sub_offset;
1868 unsigned int print_len;
1869 unsigned int print_offset;
1871 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
1873 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
1878 oparms.desired_access = FILE_READ_ATTRIBUTES;
1879 oparms.disposition = FILE_OPEN;
1880 if (backup_cred(cifs_sb))
1881 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1883 oparms.create_options = 0;
1885 oparms.reconnect = false;
1887 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_iov,
1889 if (!rc || !err_iov.iov_base) {
1894 err_buf = err_iov.iov_base;
1895 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
1896 err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) {
1901 /* open must fail on symlink - reset rc */
1903 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
1904 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
1905 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
1906 print_len = le16_to_cpu(symlink->PrintNameLength);
1907 print_offset = le16_to_cpu(symlink->PrintNameOffset);
1909 if (err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
1914 if (err_iov.iov_len <
1915 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
1920 *target_path = cifs_strndup_from_utf16(
1921 (char *)symlink->PathBuffer + sub_offset,
1922 sub_len, true, cifs_sb->local_nls);
1923 if (!(*target_path)) {
1927 convert_delimiter(*target_path, '/');
1928 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
1931 free_rsp_buf(resp_buftype, err_buf);
1937 #ifdef CONFIG_CIFS_ACL
1938 static struct cifs_ntsd *
1939 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
1940 const struct cifs_fid *cifsfid, u32 *pacllen)
1942 struct cifs_ntsd *pntsd = NULL;
1944 int rc = -EOPNOTSUPP;
1945 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1948 return ERR_CAST(tlink);
1951 cifs_dbg(FYI, "trying to get acl\n");
1953 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
1954 cifsfid->volatile_fid, (void **)&pntsd, pacllen);
1957 cifs_put_tlink(tlink);
1959 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
1966 static struct cifs_ntsd *
1967 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
1968 const char *path, u32 *pacllen)
1970 struct cifs_ntsd *pntsd = NULL;
1971 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1974 struct cifs_tcon *tcon;
1975 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
1976 struct cifs_fid fid;
1977 struct cifs_open_parms oparms;
1980 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
1982 return ERR_CAST(tlink);
1984 tcon = tlink_tcon(tlink);
1987 if (backup_cred(cifs_sb))
1988 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1990 oparms.create_options = 0;
1992 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2000 oparms.desired_access = READ_CONTROL;
2001 oparms.disposition = FILE_OPEN;
2003 oparms.reconnect = false;
2005 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
2008 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
2009 fid.volatile_fid, (void **)&pntsd, pacllen);
2010 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2013 cifs_put_tlink(tlink);
2016 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
2022 #ifdef CONFIG_CIFS_ACL
2024 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
2025 struct inode *inode, const char *path, int aclflag)
2027 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2029 int rc, access_flags = 0;
2030 struct cifs_tcon *tcon;
2031 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2032 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
2033 struct cifs_fid fid;
2034 struct cifs_open_parms oparms;
2037 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
2039 return PTR_ERR(tlink);
2041 tcon = tlink_tcon(tlink);
2044 if (backup_cred(cifs_sb))
2045 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2047 oparms.create_options = 0;
2049 if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP)
2050 access_flags = WRITE_OWNER;
2052 access_flags = WRITE_DAC;
2054 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2062 oparms.desired_access = access_flags;
2063 oparms.disposition = FILE_OPEN;
2066 oparms.reconnect = false;
2068 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
2071 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
2072 fid.volatile_fid, pnntsd, acllen, aclflag);
2073 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2076 cifs_put_tlink(tlink);
2080 #endif /* CIFS_ACL */
2082 /* Retrieve an ACL from the server */
2083 static struct cifs_ntsd *
2084 get_smb2_acl(struct cifs_sb_info *cifs_sb,
2085 struct inode *inode, const char *path,
2088 struct cifs_ntsd *pntsd = NULL;
2089 struct cifsFileInfo *open_file = NULL;
2092 open_file = find_readable_file(CIFS_I(inode), true);
2094 return get_smb2_acl_by_path(cifs_sb, path, pacllen);
2096 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen);
2097 cifsFileInfo_put(open_file);
2102 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
2103 loff_t offset, loff_t len, bool keep_size)
2105 struct inode *inode;
2106 struct cifsInodeInfo *cifsi;
2107 struct cifsFileInfo *cfile = file->private_data;
2108 struct file_zero_data_information fsctl_buf;
2114 inode = d_inode(cfile->dentry);
2115 cifsi = CIFS_I(inode);
2117 /* if file not oplocked can't be sure whether asking to extend size */
2118 if (!CIFS_CACHE_READ(cifsi))
2119 if (keep_size == false) {
2126 * Must check if file sparse since fallocate -z (zero range) assumes
2127 * non-sparse allocation
2129 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
2136 * need to make sure we are not asked to extend the file since the SMB3
2137 * fsctl does not change the file size. In the future we could change
2138 * this to zero the first part of the range then set the file size
2139 * which for a non sparse file would zero the newly extended range
2141 if (keep_size == false)
2142 if (i_size_read(inode) < offset + len) {
2148 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
2150 fsctl_buf.FileOffset = cpu_to_le64(offset);
2151 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
2153 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2154 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
2155 true /* is_fctl */, (char *)&fsctl_buf,
2156 sizeof(struct file_zero_data_information), NULL, NULL);
2161 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
2162 loff_t offset, loff_t len)
2164 struct inode *inode;
2165 struct cifsInodeInfo *cifsi;
2166 struct cifsFileInfo *cfile = file->private_data;
2167 struct file_zero_data_information fsctl_buf;
2170 __u8 set_sparse = 1;
2174 inode = d_inode(cfile->dentry);
2175 cifsi = CIFS_I(inode);
2177 /* Need to make file sparse, if not already, before freeing range. */
2178 /* Consider adding equivalent for compressed since it could also work */
2179 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
2185 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
2187 fsctl_buf.FileOffset = cpu_to_le64(offset);
2188 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
2190 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2191 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
2192 true /* is_fctl */, (char *)&fsctl_buf,
2193 sizeof(struct file_zero_data_information), NULL, NULL);
2198 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
2199 loff_t off, loff_t len, bool keep_size)
2201 struct inode *inode;
2202 struct cifsInodeInfo *cifsi;
2203 struct cifsFileInfo *cfile = file->private_data;
2204 long rc = -EOPNOTSUPP;
2209 inode = d_inode(cfile->dentry);
2210 cifsi = CIFS_I(inode);
2212 /* if file not oplocked can't be sure whether asking to extend size */
2213 if (!CIFS_CACHE_READ(cifsi))
2214 if (keep_size == false) {
2220 * Files are non-sparse by default so falloc may be a no-op
2221 * Must check if file sparse. If not sparse, and not extending
2222 * then no need to do anything since file already allocated
2224 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
2225 if (keep_size == true)
2227 /* check if extending file */
2228 else if (i_size_read(inode) >= off + len)
2229 /* not extending file and already not sparse */
2231 /* BB: in future add else clause to extend file */
2238 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
2240 * Check if falloc starts within first few pages of file
2241 * and ends within a few pages of the end of file to
2242 * ensure that most of file is being forced to be
2243 * fallocated now. If so then setting whole file sparse
2244 * ie potentially making a few extra pages at the beginning
2245 * or end of the file non-sparse via set_sparse is harmless.
2247 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
2253 rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
2255 /* BB: else ... in future add code to extend file and set sparse */
2263 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
2264 loff_t off, loff_t len)
2266 /* KEEP_SIZE already checked for by do_fallocate */
2267 if (mode & FALLOC_FL_PUNCH_HOLE)
2268 return smb3_punch_hole(file, tcon, off, len);
2269 else if (mode & FALLOC_FL_ZERO_RANGE) {
2270 if (mode & FALLOC_FL_KEEP_SIZE)
2271 return smb3_zero_range(file, tcon, off, len, true);
2272 return smb3_zero_range(file, tcon, off, len, false);
2273 } else if (mode == FALLOC_FL_KEEP_SIZE)
2274 return smb3_simple_falloc(file, tcon, off, len, true);
2276 return smb3_simple_falloc(file, tcon, off, len, false);
2282 smb2_downgrade_oplock(struct TCP_Server_Info *server,
2283 struct cifsInodeInfo *cinode, bool set_level2)
2286 server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
2289 server->ops->set_oplock_level(cinode, 0, 0, NULL);
2293 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
2294 unsigned int epoch, bool *purge_cache)
2297 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
2299 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
2300 cinode->oplock = CIFS_CACHE_RHW_FLG;
2301 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
2302 &cinode->vfs_inode);
2303 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
2304 cinode->oplock = CIFS_CACHE_RW_FLG;
2305 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
2306 &cinode->vfs_inode);
2307 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
2308 cinode->oplock = CIFS_CACHE_READ_FLG;
2309 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
2310 &cinode->vfs_inode);
2316 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
2317 unsigned int epoch, bool *purge_cache)
2319 char message[5] = {0};
2322 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
2326 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
2327 cinode->oplock |= CIFS_CACHE_READ_FLG;
2328 strcat(message, "R");
2330 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
2331 cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
2332 strcat(message, "H");
2334 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
2335 cinode->oplock |= CIFS_CACHE_WRITE_FLG;
2336 strcat(message, "W");
2338 if (!cinode->oplock)
2339 strcat(message, "None");
2340 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
2341 &cinode->vfs_inode);
2345 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
2346 unsigned int epoch, bool *purge_cache)
2348 unsigned int old_oplock = cinode->oplock;
2350 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
2353 *purge_cache = false;
2354 if (old_oplock == CIFS_CACHE_READ_FLG) {
2355 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
2356 (epoch - cinode->epoch > 0))
2357 *purge_cache = true;
2358 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
2359 (epoch - cinode->epoch > 1))
2360 *purge_cache = true;
2361 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
2362 (epoch - cinode->epoch > 1))
2363 *purge_cache = true;
2364 else if (cinode->oplock == 0 &&
2365 (epoch - cinode->epoch > 0))
2366 *purge_cache = true;
2367 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
2368 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
2369 (epoch - cinode->epoch > 0))
2370 *purge_cache = true;
2371 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
2372 (epoch - cinode->epoch > 1))
2373 *purge_cache = true;
2375 cinode->epoch = epoch;
2380 smb2_is_read_op(__u32 oplock)
2382 return oplock == SMB2_OPLOCK_LEVEL_II;
2386 smb21_is_read_op(__u32 oplock)
2388 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
2389 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
2393 map_oplock_to_lease(u8 oplock)
2395 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
2396 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
2397 else if (oplock == SMB2_OPLOCK_LEVEL_II)
2398 return SMB2_LEASE_READ_CACHING;
2399 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
2400 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
2401 SMB2_LEASE_WRITE_CACHING;
2406 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
2408 struct create_lease *buf;
2410 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
2414 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
2415 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
2417 buf->ccontext.DataOffset = cpu_to_le16(offsetof
2418 (struct create_lease, lcontext));
2419 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
2420 buf->ccontext.NameOffset = cpu_to_le16(offsetof
2421 (struct create_lease, Name));
2422 buf->ccontext.NameLength = cpu_to_le16(4);
2423 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
2432 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
2434 struct create_lease_v2 *buf;
2436 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
2440 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
2441 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
2443 buf->ccontext.DataOffset = cpu_to_le16(offsetof
2444 (struct create_lease_v2, lcontext));
2445 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
2446 buf->ccontext.NameOffset = cpu_to_le16(offsetof
2447 (struct create_lease_v2, Name));
2448 buf->ccontext.NameLength = cpu_to_le16(4);
2449 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
2458 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
2460 struct create_lease *lc = (struct create_lease *)buf;
2462 *epoch = 0; /* not used */
2463 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
2464 return SMB2_OPLOCK_LEVEL_NOCHANGE;
2465 return le32_to_cpu(lc->lcontext.LeaseState);
2469 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
2471 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
2473 *epoch = le16_to_cpu(lc->lcontext.Epoch);
2474 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
2475 return SMB2_OPLOCK_LEVEL_NOCHANGE;
2477 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
2478 return le32_to_cpu(lc->lcontext.LeaseState);
2482 smb2_wp_retry_size(struct inode *inode)
2484 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
2485 SMB2_MAX_BUFFER_SIZE);
2489 smb2_dir_needs_close(struct cifsFileInfo *cfile)
2491 return !cfile->invalidHandle;
2495 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
2496 struct smb_rqst *old_rq)
2498 struct smb2_sync_hdr *shdr =
2499 (struct smb2_sync_hdr *)old_rq->rq_iov[0].iov_base;
2501 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
2502 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
2503 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
2504 tr_hdr->Flags = cpu_to_le16(0x01);
2505 get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
2506 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
2509 /* We can not use the normal sg_set_buf() as we will sometimes pass a
2510 * stack object as buf.
2512 static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
2513 unsigned int buflen)
2515 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
2518 /* Assumes the first rqst has a transform header as the first iov.
2520 * rqst[0].rq_iov[0] is transform header
2521 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
2522 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
2524 static struct scatterlist *
2525 init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign)
2527 unsigned int sg_len;
2528 struct scatterlist *sg;
2531 unsigned int idx = 0;
2535 for (i = 0; i < num_rqst; i++)
2536 sg_len += rqst[i].rq_nvec + rqst[i].rq_npages;
2538 sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
2542 sg_init_table(sg, sg_len);
2543 for (i = 0; i < num_rqst; i++) {
2544 for (j = 0; j < rqst[i].rq_nvec; j++) {
2546 * The first rqst has a transform header where the
2547 * first 20 bytes are not part of the encrypted blob
2549 skip = (i == 0) && (j == 0) ? 20 : 0;
2550 smb2_sg_set_buf(&sg[idx++],
2551 rqst[i].rq_iov[j].iov_base + skip,
2552 rqst[i].rq_iov[j].iov_len - skip);
2555 for (j = 0; j < rqst[i].rq_npages; j++) {
2556 unsigned int len, offset;
2558 rqst_page_get_length(&rqst[i], j, &len, &offset);
2559 sg_set_page(&sg[idx++], rqst[i].rq_pages[j], len, offset);
2562 smb2_sg_set_buf(&sg[idx], sign, SMB2_SIGNATURE_SIZE);
2567 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
2569 struct cifs_ses *ses;
2572 spin_lock(&cifs_tcp_ses_lock);
2573 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
2574 if (ses->Suid != ses_id)
2576 ses_enc_key = enc ? ses->smb3encryptionkey :
2577 ses->smb3decryptionkey;
2578 memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE);
2579 spin_unlock(&cifs_tcp_ses_lock);
2582 spin_unlock(&cifs_tcp_ses_lock);
2587 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
2588 * iov[0] - transform header (associate data),
2589 * iov[1-N] - SMB2 header and pages - data to encrypt.
2590 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
2594 crypt_message(struct TCP_Server_Info *server, int num_rqst,
2595 struct smb_rqst *rqst, int enc)
2597 struct smb2_transform_hdr *tr_hdr =
2598 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
2599 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
2601 struct scatterlist *sg;
2602 u8 sign[SMB2_SIGNATURE_SIZE] = {};
2603 u8 key[SMB3_SIGN_KEY_SIZE];
2604 struct aead_request *req;
2606 unsigned int iv_len;
2607 DECLARE_CRYPTO_WAIT(wait);
2608 struct crypto_aead *tfm;
2609 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
2611 rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key);
2613 cifs_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
2618 rc = smb3_crypto_aead_allocate(server);
2620 cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__);
2624 tfm = enc ? server->secmech.ccmaesencrypt :
2625 server->secmech.ccmaesdecrypt;
2626 rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
2628 cifs_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
2632 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
2634 cifs_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
2638 req = aead_request_alloc(tfm, GFP_KERNEL);
2640 cifs_dbg(VFS, "%s: Failed to alloc aead request", __func__);
2645 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
2646 crypt_len += SMB2_SIGNATURE_SIZE;
2649 sg = init_sg(num_rqst, rqst, sign);
2651 cifs_dbg(VFS, "%s: Failed to init sg", __func__);
2656 iv_len = crypto_aead_ivsize(tfm);
2657 iv = kzalloc(iv_len, GFP_KERNEL);
2659 cifs_dbg(VFS, "%s: Failed to alloc IV", __func__);
2664 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
2666 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
2667 aead_request_set_ad(req, assoc_data_len);
2669 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
2670 crypto_req_done, &wait);
2672 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
2673 : crypto_aead_decrypt(req), &wait);
2676 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
2687 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
2691 for (i = 0; i < num_rqst; i++) {
2692 if (rqst[i].rq_pages) {
2693 for (j = rqst[i].rq_npages - 1; j >= 0; j--)
2694 put_page(rqst[i].rq_pages[j]);
2695 kfree(rqst[i].rq_pages);
2701 * This function will initialize new_rq and encrypt the content.
2702 * The first entry, new_rq[0], only contains a single iov which contains
2703 * a smb2_transform_hdr and is pre-allocated by the caller.
2704 * This function then populates new_rq[1+] with the content from olq_rq[0+].
2706 * The end result is an array of smb_rqst structures where the first structure
2707 * only contains a single iov for the transform header which we then can pass
2708 * to crypt_message().
2710 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
2711 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
2714 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
2715 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
2717 struct page **pages;
2718 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
2719 unsigned int npages;
2720 unsigned int orig_len = 0;
2724 for (i = 1; i < num_rqst; i++) {
2725 npages = old_rq[i - 1].rq_npages;
2726 pages = kmalloc_array(npages, sizeof(struct page *),
2731 new_rq[i].rq_pages = pages;
2732 new_rq[i].rq_npages = npages;
2733 new_rq[i].rq_offset = old_rq[i - 1].rq_offset;
2734 new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz;
2735 new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz;
2736 new_rq[i].rq_iov = old_rq[i - 1].rq_iov;
2737 new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec;
2739 orig_len += smb_rqst_len(server, &old_rq[i - 1]);
2741 for (j = 0; j < npages; j++) {
2742 pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
2747 /* copy pages form the old */
2748 for (j = 0; j < npages; j++) {
2750 unsigned int offset, len;
2752 rqst_page_get_length(&new_rq[i], j, &len, &offset);
2754 dst = (char *) kmap(new_rq[i].rq_pages[j]) + offset;
2755 src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset;
2757 memcpy(dst, src, len);
2758 kunmap(new_rq[i].rq_pages[j]);
2759 kunmap(old_rq[i - 1].rq_pages[j]);
2763 /* fill the 1st iov with a transform header */
2764 fill_transform_hdr(tr_hdr, orig_len, old_rq);
2766 rc = crypt_message(server, num_rqst, new_rq, 1);
2767 cifs_dbg(FYI, "encrypt message returned %d", rc);
2774 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
2779 smb3_is_transform_hdr(void *buf)
2781 struct smb2_transform_hdr *trhdr = buf;
2783 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
2787 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
2788 unsigned int buf_data_size, struct page **pages,
2789 unsigned int npages, unsigned int page_data_size)
2792 struct smb_rqst rqst = {NULL};
2795 iov[0].iov_base = buf;
2796 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
2797 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
2798 iov[1].iov_len = buf_data_size;
2802 rqst.rq_pages = pages;
2803 rqst.rq_npages = npages;
2804 rqst.rq_pagesz = PAGE_SIZE;
2805 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
2807 rc = crypt_message(server, 1, &rqst, 0);
2808 cifs_dbg(FYI, "decrypt message returned %d\n", rc);
2813 memmove(buf, iov[1].iov_base, buf_data_size);
2815 server->total_read = buf_data_size + page_data_size;
2821 read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
2822 unsigned int npages, unsigned int len)
2827 for (i = 0; i < npages; i++) {
2828 struct page *page = pages[i];
2832 if (len >= PAGE_SIZE) {
2833 /* enough data to fill the page */
2837 zero_user(page, len, PAGE_SIZE - len);
2840 length = cifs_read_page_from_socket(server, page, 0, n);
2843 server->total_read += length;
2850 init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
2851 unsigned int cur_off, struct bio_vec **page_vec)
2853 struct bio_vec *bvec;
2856 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
2860 for (i = 0; i < npages; i++) {
2861 bvec[i].bv_page = pages[i];
2862 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
2863 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
2864 data_size -= bvec[i].bv_len;
2867 if (data_size != 0) {
2868 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
2878 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
2879 char *buf, unsigned int buf_len, struct page **pages,
2880 unsigned int npages, unsigned int page_data_size)
2882 unsigned int data_offset;
2883 unsigned int data_len;
2884 unsigned int cur_off;
2885 unsigned int cur_page_idx;
2886 unsigned int pad_len;
2887 struct cifs_readdata *rdata = mid->callback_data;
2888 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2889 struct bio_vec *bvec = NULL;
2890 struct iov_iter iter;
2893 bool use_rdma_mr = false;
2895 if (shdr->Command != SMB2_READ) {
2896 cifs_dbg(VFS, "only big read responses are supported\n");
2900 if (server->ops->is_session_expired &&
2901 server->ops->is_session_expired(buf)) {
2902 cifs_reconnect(server);
2903 wake_up(&server->response_q);
2907 if (server->ops->is_status_pending &&
2908 server->ops->is_status_pending(buf, server, 0))
2911 rdata->result = server->ops->map_error(buf, false);
2912 if (rdata->result != 0) {
2913 cifs_dbg(FYI, "%s: server returned error %d\n",
2914 __func__, rdata->result);
2915 dequeue_mid(mid, rdata->result);
2919 data_offset = server->ops->read_data_offset(buf);
2920 #ifdef CONFIG_CIFS_SMB_DIRECT
2921 use_rdma_mr = rdata->mr;
2923 data_len = server->ops->read_data_length(buf, use_rdma_mr);
2925 if (data_offset < server->vals->read_rsp_size) {
2927 * win2k8 sometimes sends an offset of 0 when the read
2928 * is beyond the EOF. Treat it as if the data starts just after
2931 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
2932 __func__, data_offset);
2933 data_offset = server->vals->read_rsp_size;
2934 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
2935 /* data_offset is beyond the end of smallbuf */
2936 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
2937 __func__, data_offset);
2938 rdata->result = -EIO;
2939 dequeue_mid(mid, rdata->result);
2943 pad_len = data_offset - server->vals->read_rsp_size;
2945 if (buf_len <= data_offset) {
2946 /* read response payload is in pages */
2947 cur_page_idx = pad_len / PAGE_SIZE;
2948 cur_off = pad_len % PAGE_SIZE;
2950 if (cur_page_idx != 0) {
2951 /* data offset is beyond the 1st page of response */
2952 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
2953 __func__, data_offset);
2954 rdata->result = -EIO;
2955 dequeue_mid(mid, rdata->result);
2959 if (data_len > page_data_size - pad_len) {
2960 /* data_len is corrupt -- discard frame */
2961 rdata->result = -EIO;
2962 dequeue_mid(mid, rdata->result);
2966 rdata->result = init_read_bvec(pages, npages, page_data_size,
2968 if (rdata->result != 0) {
2969 dequeue_mid(mid, rdata->result);
2973 iov_iter_bvec(&iter, WRITE | ITER_BVEC, bvec, npages, data_len);
2974 } else if (buf_len >= data_offset + data_len) {
2975 /* read response payload is in buf */
2976 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
2977 iov.iov_base = buf + data_offset;
2978 iov.iov_len = data_len;
2979 iov_iter_kvec(&iter, WRITE | ITER_KVEC, &iov, 1, data_len);
2981 /* read response payload cannot be in both buf and pages */
2982 WARN_ONCE(1, "buf can not contain only a part of read data");
2983 rdata->result = -EIO;
2984 dequeue_mid(mid, rdata->result);
2988 /* set up first iov for signature check */
2989 rdata->iov[0].iov_base = buf;
2990 rdata->iov[0].iov_len = 4;
2991 rdata->iov[1].iov_base = buf + 4;
2992 rdata->iov[1].iov_len = server->vals->read_rsp_size - 4;
2993 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
2994 rdata->iov[0].iov_base, server->vals->read_rsp_size);
2996 length = rdata->copy_into_pages(server, rdata, &iter);
3003 dequeue_mid(mid, false);
3008 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid)
3010 char *buf = server->smallbuf;
3011 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
3012 unsigned int npages;
3013 struct page **pages;
3015 unsigned int buflen = server->pdu_size;
3019 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
3020 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
3022 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
3025 server->total_read += rc;
3027 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
3028 server->vals->read_rsp_size;
3029 npages = DIV_ROUND_UP(len, PAGE_SIZE);
3031 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
3037 for (; i < npages; i++) {
3038 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
3045 /* read read data into pages */
3046 rc = read_data_into_pages(server, pages, npages, len);
3050 rc = cifs_discard_remaining_data(server);
3054 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
3055 pages, npages, len);
3059 *mid = smb2_find_mid(server, buf);
3061 cifs_dbg(FYI, "mid not found\n");
3063 cifs_dbg(FYI, "mid found\n");
3064 (*mid)->decrypted = true;
3065 rc = handle_read_data(server, *mid, buf,
3066 server->vals->read_rsp_size,
3067 pages, npages, len);
3071 for (i = i - 1; i >= 0; i--)
3076 cifs_discard_remaining_data(server);
3081 receive_encrypted_standard(struct TCP_Server_Info *server,
3082 struct mid_q_entry **mids, char **bufs,
3086 char *buf = server->smallbuf;
3088 struct smb2_sync_hdr *shdr;
3089 unsigned int pdu_length = server->pdu_size;
3090 unsigned int buf_size;
3091 struct mid_q_entry *mid_entry;
3093 char *next_buffer = NULL;
3097 /* switch to large buffer if too big for a small one */
3098 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
3099 server->large_buf = true;
3100 memcpy(server->bigbuf, buf, server->total_read);
3101 buf = server->bigbuf;
3104 /* now read the rest */
3105 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
3106 pdu_length - HEADER_SIZE(server) + 1);
3109 server->total_read += length;
3111 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
3112 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0);
3116 next_is_large = server->large_buf;
3118 shdr = (struct smb2_sync_hdr *)buf;
3119 if (shdr->NextCommand) {
3120 if (next_is_large) {
3121 tmpbuf = server->bigbuf;
3122 next_buffer = (char *)cifs_buf_get();
3124 tmpbuf = server->smallbuf;
3125 next_buffer = (char *)cifs_small_buf_get();
3128 tmpbuf + le32_to_cpu(shdr->NextCommand),
3129 pdu_length - le32_to_cpu(shdr->NextCommand));
3132 mid_entry = smb2_find_mid(server, buf);
3133 if (mid_entry == NULL)
3134 cifs_dbg(FYI, "mid not found\n");
3136 cifs_dbg(FYI, "mid found\n");
3137 mid_entry->decrypted = true;
3138 mid_entry->resp_buf_size = server->pdu_size;
3141 if (*num_mids >= MAX_COMPOUND) {
3142 cifs_dbg(VFS, "too many PDUs in compound\n");
3145 bufs[*num_mids] = buf;
3146 mids[(*num_mids)++] = mid_entry;
3148 if (mid_entry && mid_entry->handle)
3149 ret = mid_entry->handle(server, mid_entry);
3151 ret = cifs_handle_standard(server, mid_entry);
3153 if (ret == 0 && shdr->NextCommand) {
3154 pdu_length -= le32_to_cpu(shdr->NextCommand);
3155 server->large_buf = next_is_large;
3157 server->bigbuf = next_buffer;
3159 server->smallbuf = next_buffer;
3161 buf += le32_to_cpu(shdr->NextCommand);
3169 smb3_receive_transform(struct TCP_Server_Info *server,
3170 struct mid_q_entry **mids, char **bufs, int *num_mids)
3172 char *buf = server->smallbuf;
3173 unsigned int pdu_length = server->pdu_size;
3174 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
3175 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
3177 if (pdu_length < sizeof(struct smb2_transform_hdr) +
3178 sizeof(struct smb2_sync_hdr)) {
3179 cifs_dbg(VFS, "Transform message is too small (%u)\n",
3181 cifs_reconnect(server);
3182 wake_up(&server->response_q);
3183 return -ECONNABORTED;
3186 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
3187 cifs_dbg(VFS, "Transform message is broken\n");
3188 cifs_reconnect(server);
3189 wake_up(&server->response_q);
3190 return -ECONNABORTED;
3193 /* TODO: add support for compounds containing READ. */
3194 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server))
3195 return receive_encrypted_read(server, &mids[0]);
3197 return receive_encrypted_standard(server, mids, bufs, num_mids);
3201 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
3203 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
3205 return handle_read_data(server, mid, buf, server->pdu_size,
3210 smb2_next_header(char *buf)
3212 struct smb2_sync_hdr *hdr = (struct smb2_sync_hdr *)buf;
3213 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
3215 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
3216 return sizeof(struct smb2_transform_hdr) +
3217 le32_to_cpu(t_hdr->OriginalMessageSize);
3219 return le32_to_cpu(hdr->NextCommand);
3222 struct smb_version_operations smb20_operations = {
3223 .compare_fids = smb2_compare_fids,
3224 .setup_request = smb2_setup_request,
3225 .setup_async_request = smb2_setup_async_request,
3226 .check_receive = smb2_check_receive,
3227 .add_credits = smb2_add_credits,
3228 .set_credits = smb2_set_credits,
3229 .get_credits_field = smb2_get_credits_field,
3230 .get_credits = smb2_get_credits,
3231 .wait_mtu_credits = cifs_wait_mtu_credits,
3232 .get_next_mid = smb2_get_next_mid,
3233 .read_data_offset = smb2_read_data_offset,
3234 .read_data_length = smb2_read_data_length,
3235 .map_error = map_smb2_to_linux_error,
3236 .find_mid = smb2_find_mid,
3237 .check_message = smb2_check_message,
3238 .dump_detail = smb2_dump_detail,
3239 .clear_stats = smb2_clear_stats,
3240 .print_stats = smb2_print_stats,
3241 .is_oplock_break = smb2_is_valid_oplock_break,
3242 .handle_cancelled_mid = smb2_handle_cancelled_mid,
3243 .downgrade_oplock = smb2_downgrade_oplock,
3244 .need_neg = smb2_need_neg,
3245 .negotiate = smb2_negotiate,
3246 .negotiate_wsize = smb2_negotiate_wsize,
3247 .negotiate_rsize = smb2_negotiate_rsize,
3248 .sess_setup = SMB2_sess_setup,
3249 .logoff = SMB2_logoff,
3250 .tree_connect = SMB2_tcon,
3251 .tree_disconnect = SMB2_tdis,
3252 .qfs_tcon = smb2_qfs_tcon,
3253 .is_path_accessible = smb2_is_path_accessible,
3254 .can_echo = smb2_can_echo,
3256 .query_path_info = smb2_query_path_info,
3257 .get_srv_inum = smb2_get_srv_inum,
3258 .query_file_info = smb2_query_file_info,
3259 .set_path_size = smb2_set_path_size,
3260 .set_file_size = smb2_set_file_size,
3261 .set_file_info = smb2_set_file_info,
3262 .set_compression = smb2_set_compression,
3263 .mkdir = smb2_mkdir,
3264 .mkdir_setinfo = smb2_mkdir_setinfo,
3265 .rmdir = smb2_rmdir,
3266 .unlink = smb2_unlink,
3267 .rename = smb2_rename_path,
3268 .create_hardlink = smb2_create_hardlink,
3269 .query_symlink = smb2_query_symlink,
3270 .query_mf_symlink = smb3_query_mf_symlink,
3271 .create_mf_symlink = smb3_create_mf_symlink,
3272 .open = smb2_open_file,
3273 .set_fid = smb2_set_fid,
3274 .close = smb2_close_file,
3275 .flush = smb2_flush_file,
3276 .async_readv = smb2_async_readv,
3277 .async_writev = smb2_async_writev,
3278 .sync_read = smb2_sync_read,
3279 .sync_write = smb2_sync_write,
3280 .query_dir_first = smb2_query_dir_first,
3281 .query_dir_next = smb2_query_dir_next,
3282 .close_dir = smb2_close_dir,
3283 .calc_smb_size = smb2_calc_size,
3284 .is_status_pending = smb2_is_status_pending,
3285 .is_session_expired = smb2_is_session_expired,
3286 .oplock_response = smb2_oplock_response,
3287 .queryfs = smb2_queryfs,
3288 .mand_lock = smb2_mand_lock,
3289 .mand_unlock_range = smb2_unlock_range,
3290 .push_mand_locks = smb2_push_mandatory_locks,
3291 .get_lease_key = smb2_get_lease_key,
3292 .set_lease_key = smb2_set_lease_key,
3293 .new_lease_key = smb2_new_lease_key,
3294 .calc_signature = smb2_calc_signature,
3295 .is_read_op = smb2_is_read_op,
3296 .set_oplock_level = smb2_set_oplock_level,
3297 .create_lease_buf = smb2_create_lease_buf,
3298 .parse_lease_buf = smb2_parse_lease_buf,
3299 .copychunk_range = smb2_copychunk_range,
3300 .wp_retry_size = smb2_wp_retry_size,
3301 .dir_needs_close = smb2_dir_needs_close,
3302 .get_dfs_refer = smb2_get_dfs_refer,
3303 .select_sectype = smb2_select_sectype,
3304 #ifdef CONFIG_CIFS_XATTR
3305 .query_all_EAs = smb2_query_eas,
3306 .set_EA = smb2_set_ea,
3307 #endif /* CIFS_XATTR */
3308 #ifdef CONFIG_CIFS_ACL
3309 .get_acl = get_smb2_acl,
3310 .get_acl_by_fid = get_smb2_acl_by_fid,
3311 .set_acl = set_smb2_acl,
3312 #endif /* CIFS_ACL */
3313 .next_header = smb2_next_header,
3316 struct smb_version_operations smb21_operations = {
3317 .compare_fids = smb2_compare_fids,
3318 .setup_request = smb2_setup_request,
3319 .setup_async_request = smb2_setup_async_request,
3320 .check_receive = smb2_check_receive,
3321 .add_credits = smb2_add_credits,
3322 .set_credits = smb2_set_credits,
3323 .get_credits_field = smb2_get_credits_field,
3324 .get_credits = smb2_get_credits,
3325 .wait_mtu_credits = smb2_wait_mtu_credits,
3326 .get_next_mid = smb2_get_next_mid,
3327 .read_data_offset = smb2_read_data_offset,
3328 .read_data_length = smb2_read_data_length,
3329 .map_error = map_smb2_to_linux_error,
3330 .find_mid = smb2_find_mid,
3331 .check_message = smb2_check_message,
3332 .dump_detail = smb2_dump_detail,
3333 .clear_stats = smb2_clear_stats,
3334 .print_stats = smb2_print_stats,
3335 .is_oplock_break = smb2_is_valid_oplock_break,
3336 .handle_cancelled_mid = smb2_handle_cancelled_mid,
3337 .downgrade_oplock = smb2_downgrade_oplock,
3338 .need_neg = smb2_need_neg,
3339 .negotiate = smb2_negotiate,
3340 .negotiate_wsize = smb2_negotiate_wsize,
3341 .negotiate_rsize = smb2_negotiate_rsize,
3342 .sess_setup = SMB2_sess_setup,
3343 .logoff = SMB2_logoff,
3344 .tree_connect = SMB2_tcon,
3345 .tree_disconnect = SMB2_tdis,
3346 .qfs_tcon = smb2_qfs_tcon,
3347 .is_path_accessible = smb2_is_path_accessible,
3348 .can_echo = smb2_can_echo,
3350 .query_path_info = smb2_query_path_info,
3351 .get_srv_inum = smb2_get_srv_inum,
3352 .query_file_info = smb2_query_file_info,
3353 .set_path_size = smb2_set_path_size,
3354 .set_file_size = smb2_set_file_size,
3355 .set_file_info = smb2_set_file_info,
3356 .set_compression = smb2_set_compression,
3357 .mkdir = smb2_mkdir,
3358 .mkdir_setinfo = smb2_mkdir_setinfo,
3359 .rmdir = smb2_rmdir,
3360 .unlink = smb2_unlink,
3361 .rename = smb2_rename_path,
3362 .create_hardlink = smb2_create_hardlink,
3363 .query_symlink = smb2_query_symlink,
3364 .query_mf_symlink = smb3_query_mf_symlink,
3365 .create_mf_symlink = smb3_create_mf_symlink,
3366 .open = smb2_open_file,
3367 .set_fid = smb2_set_fid,
3368 .close = smb2_close_file,
3369 .flush = smb2_flush_file,
3370 .async_readv = smb2_async_readv,
3371 .async_writev = smb2_async_writev,
3372 .sync_read = smb2_sync_read,
3373 .sync_write = smb2_sync_write,
3374 .query_dir_first = smb2_query_dir_first,
3375 .query_dir_next = smb2_query_dir_next,
3376 .close_dir = smb2_close_dir,
3377 .calc_smb_size = smb2_calc_size,
3378 .is_status_pending = smb2_is_status_pending,
3379 .is_session_expired = smb2_is_session_expired,
3380 .oplock_response = smb2_oplock_response,
3381 .queryfs = smb2_queryfs,
3382 .mand_lock = smb2_mand_lock,
3383 .mand_unlock_range = smb2_unlock_range,
3384 .push_mand_locks = smb2_push_mandatory_locks,
3385 .get_lease_key = smb2_get_lease_key,
3386 .set_lease_key = smb2_set_lease_key,
3387 .new_lease_key = smb2_new_lease_key,
3388 .calc_signature = smb2_calc_signature,
3389 .is_read_op = smb21_is_read_op,
3390 .set_oplock_level = smb21_set_oplock_level,
3391 .create_lease_buf = smb2_create_lease_buf,
3392 .parse_lease_buf = smb2_parse_lease_buf,
3393 .copychunk_range = smb2_copychunk_range,
3394 .wp_retry_size = smb2_wp_retry_size,
3395 .dir_needs_close = smb2_dir_needs_close,
3396 .enum_snapshots = smb3_enum_snapshots,
3397 .get_dfs_refer = smb2_get_dfs_refer,
3398 .select_sectype = smb2_select_sectype,
3399 #ifdef CONFIG_CIFS_XATTR
3400 .query_all_EAs = smb2_query_eas,
3401 .set_EA = smb2_set_ea,
3402 #endif /* CIFS_XATTR */
3403 #ifdef CONFIG_CIFS_ACL
3404 .get_acl = get_smb2_acl,
3405 .get_acl_by_fid = get_smb2_acl_by_fid,
3406 .set_acl = set_smb2_acl,
3407 #endif /* CIFS_ACL */
3408 .next_header = smb2_next_header,
3411 struct smb_version_operations smb30_operations = {
3412 .compare_fids = smb2_compare_fids,
3413 .setup_request = smb2_setup_request,
3414 .setup_async_request = smb2_setup_async_request,
3415 .check_receive = smb2_check_receive,
3416 .add_credits = smb2_add_credits,
3417 .set_credits = smb2_set_credits,
3418 .get_credits_field = smb2_get_credits_field,
3419 .get_credits = smb2_get_credits,
3420 .wait_mtu_credits = smb2_wait_mtu_credits,
3421 .get_next_mid = smb2_get_next_mid,
3422 .read_data_offset = smb2_read_data_offset,
3423 .read_data_length = smb2_read_data_length,
3424 .map_error = map_smb2_to_linux_error,
3425 .find_mid = smb2_find_mid,
3426 .check_message = smb2_check_message,
3427 .dump_detail = smb2_dump_detail,
3428 .clear_stats = smb2_clear_stats,
3429 .print_stats = smb2_print_stats,
3430 .dump_share_caps = smb2_dump_share_caps,
3431 .is_oplock_break = smb2_is_valid_oplock_break,
3432 .handle_cancelled_mid = smb2_handle_cancelled_mid,
3433 .downgrade_oplock = smb2_downgrade_oplock,
3434 .need_neg = smb2_need_neg,
3435 .negotiate = smb2_negotiate,
3436 .negotiate_wsize = smb2_negotiate_wsize,
3437 .negotiate_rsize = smb2_negotiate_rsize,
3438 .sess_setup = SMB2_sess_setup,
3439 .logoff = SMB2_logoff,
3440 .tree_connect = SMB2_tcon,
3441 .tree_disconnect = SMB2_tdis,
3442 .qfs_tcon = smb3_qfs_tcon,
3443 .is_path_accessible = smb2_is_path_accessible,
3444 .can_echo = smb2_can_echo,
3446 .query_path_info = smb2_query_path_info,
3447 .get_srv_inum = smb2_get_srv_inum,
3448 .query_file_info = smb2_query_file_info,
3449 .set_path_size = smb2_set_path_size,
3450 .set_file_size = smb2_set_file_size,
3451 .set_file_info = smb2_set_file_info,
3452 .set_compression = smb2_set_compression,
3453 .mkdir = smb2_mkdir,
3454 .mkdir_setinfo = smb2_mkdir_setinfo,
3455 .rmdir = smb2_rmdir,
3456 .unlink = smb2_unlink,
3457 .rename = smb2_rename_path,
3458 .create_hardlink = smb2_create_hardlink,
3459 .query_symlink = smb2_query_symlink,
3460 .query_mf_symlink = smb3_query_mf_symlink,
3461 .create_mf_symlink = smb3_create_mf_symlink,
3462 .open = smb2_open_file,
3463 .set_fid = smb2_set_fid,
3464 .close = smb2_close_file,
3465 .flush = smb2_flush_file,
3466 .async_readv = smb2_async_readv,
3467 .async_writev = smb2_async_writev,
3468 .sync_read = smb2_sync_read,
3469 .sync_write = smb2_sync_write,
3470 .query_dir_first = smb2_query_dir_first,
3471 .query_dir_next = smb2_query_dir_next,
3472 .close_dir = smb2_close_dir,
3473 .calc_smb_size = smb2_calc_size,
3474 .is_status_pending = smb2_is_status_pending,
3475 .is_session_expired = smb2_is_session_expired,
3476 .oplock_response = smb2_oplock_response,
3477 .queryfs = smb2_queryfs,
3478 .mand_lock = smb2_mand_lock,
3479 .mand_unlock_range = smb2_unlock_range,
3480 .push_mand_locks = smb2_push_mandatory_locks,
3481 .get_lease_key = smb2_get_lease_key,
3482 .set_lease_key = smb2_set_lease_key,
3483 .new_lease_key = smb2_new_lease_key,
3484 .generate_signingkey = generate_smb30signingkey,
3485 .calc_signature = smb3_calc_signature,
3486 .set_integrity = smb3_set_integrity,
3487 .is_read_op = smb21_is_read_op,
3488 .set_oplock_level = smb3_set_oplock_level,
3489 .create_lease_buf = smb3_create_lease_buf,
3490 .parse_lease_buf = smb3_parse_lease_buf,
3491 .copychunk_range = smb2_copychunk_range,
3492 .duplicate_extents = smb2_duplicate_extents,
3493 .validate_negotiate = smb3_validate_negotiate,
3494 .wp_retry_size = smb2_wp_retry_size,
3495 .dir_needs_close = smb2_dir_needs_close,
3496 .fallocate = smb3_fallocate,
3497 .enum_snapshots = smb3_enum_snapshots,
3498 .init_transform_rq = smb3_init_transform_rq,
3499 .is_transform_hdr = smb3_is_transform_hdr,
3500 .receive_transform = smb3_receive_transform,
3501 .get_dfs_refer = smb2_get_dfs_refer,
3502 .select_sectype = smb2_select_sectype,
3503 #ifdef CONFIG_CIFS_XATTR
3504 .query_all_EAs = smb2_query_eas,
3505 .set_EA = smb2_set_ea,
3506 #endif /* CIFS_XATTR */
3507 #ifdef CONFIG_CIFS_ACL
3508 .get_acl = get_smb2_acl,
3509 .get_acl_by_fid = get_smb2_acl_by_fid,
3510 .set_acl = set_smb2_acl,
3511 #endif /* CIFS_ACL */
3512 .next_header = smb2_next_header,
3515 struct smb_version_operations smb311_operations = {
3516 .compare_fids = smb2_compare_fids,
3517 .setup_request = smb2_setup_request,
3518 .setup_async_request = smb2_setup_async_request,
3519 .check_receive = smb2_check_receive,
3520 .add_credits = smb2_add_credits,
3521 .set_credits = smb2_set_credits,
3522 .get_credits_field = smb2_get_credits_field,
3523 .get_credits = smb2_get_credits,
3524 .wait_mtu_credits = smb2_wait_mtu_credits,
3525 .get_next_mid = smb2_get_next_mid,
3526 .read_data_offset = smb2_read_data_offset,
3527 .read_data_length = smb2_read_data_length,
3528 .map_error = map_smb2_to_linux_error,
3529 .find_mid = smb2_find_mid,
3530 .check_message = smb2_check_message,
3531 .dump_detail = smb2_dump_detail,
3532 .clear_stats = smb2_clear_stats,
3533 .print_stats = smb2_print_stats,
3534 .dump_share_caps = smb2_dump_share_caps,
3535 .is_oplock_break = smb2_is_valid_oplock_break,
3536 .handle_cancelled_mid = smb2_handle_cancelled_mid,
3537 .downgrade_oplock = smb2_downgrade_oplock,
3538 .need_neg = smb2_need_neg,
3539 .negotiate = smb2_negotiate,
3540 .negotiate_wsize = smb2_negotiate_wsize,
3541 .negotiate_rsize = smb2_negotiate_rsize,
3542 .sess_setup = SMB2_sess_setup,
3543 .logoff = SMB2_logoff,
3544 .tree_connect = SMB2_tcon,
3545 .tree_disconnect = SMB2_tdis,
3546 .qfs_tcon = smb3_qfs_tcon,
3547 .is_path_accessible = smb2_is_path_accessible,
3548 .can_echo = smb2_can_echo,
3550 .query_path_info = smb2_query_path_info,
3551 .get_srv_inum = smb2_get_srv_inum,
3552 .query_file_info = smb2_query_file_info,
3553 .set_path_size = smb2_set_path_size,
3554 .set_file_size = smb2_set_file_size,
3555 .set_file_info = smb2_set_file_info,
3556 .set_compression = smb2_set_compression,
3557 .mkdir = smb2_mkdir,
3558 .mkdir_setinfo = smb2_mkdir_setinfo,
3559 .posix_mkdir = smb311_posix_mkdir,
3560 .rmdir = smb2_rmdir,
3561 .unlink = smb2_unlink,
3562 .rename = smb2_rename_path,
3563 .create_hardlink = smb2_create_hardlink,
3564 .query_symlink = smb2_query_symlink,
3565 .query_mf_symlink = smb3_query_mf_symlink,
3566 .create_mf_symlink = smb3_create_mf_symlink,
3567 .open = smb2_open_file,
3568 .set_fid = smb2_set_fid,
3569 .close = smb2_close_file,
3570 .flush = smb2_flush_file,
3571 .async_readv = smb2_async_readv,
3572 .async_writev = smb2_async_writev,
3573 .sync_read = smb2_sync_read,
3574 .sync_write = smb2_sync_write,
3575 .query_dir_first = smb2_query_dir_first,
3576 .query_dir_next = smb2_query_dir_next,
3577 .close_dir = smb2_close_dir,
3578 .calc_smb_size = smb2_calc_size,
3579 .is_status_pending = smb2_is_status_pending,
3580 .is_session_expired = smb2_is_session_expired,
3581 .oplock_response = smb2_oplock_response,
3582 .queryfs = smb311_queryfs,
3583 .mand_lock = smb2_mand_lock,
3584 .mand_unlock_range = smb2_unlock_range,
3585 .push_mand_locks = smb2_push_mandatory_locks,
3586 .get_lease_key = smb2_get_lease_key,
3587 .set_lease_key = smb2_set_lease_key,
3588 .new_lease_key = smb2_new_lease_key,
3589 .generate_signingkey = generate_smb311signingkey,
3590 .calc_signature = smb3_calc_signature,
3591 .set_integrity = smb3_set_integrity,
3592 .is_read_op = smb21_is_read_op,
3593 .set_oplock_level = smb3_set_oplock_level,
3594 .create_lease_buf = smb3_create_lease_buf,
3595 .parse_lease_buf = smb3_parse_lease_buf,
3596 .copychunk_range = smb2_copychunk_range,
3597 .duplicate_extents = smb2_duplicate_extents,
3598 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
3599 .wp_retry_size = smb2_wp_retry_size,
3600 .dir_needs_close = smb2_dir_needs_close,
3601 .fallocate = smb3_fallocate,
3602 .enum_snapshots = smb3_enum_snapshots,
3603 .init_transform_rq = smb3_init_transform_rq,
3604 .is_transform_hdr = smb3_is_transform_hdr,
3605 .receive_transform = smb3_receive_transform,
3606 .get_dfs_refer = smb2_get_dfs_refer,
3607 .select_sectype = smb2_select_sectype,
3608 #ifdef CONFIG_CIFS_XATTR
3609 .query_all_EAs = smb2_query_eas,
3610 .set_EA = smb2_set_ea,
3611 #endif /* CIFS_XATTR */
3612 #ifdef CONFIG_CIFS_ACL
3613 .get_acl = get_smb2_acl,
3614 .get_acl_by_fid = get_smb2_acl_by_fid,
3615 .set_acl = set_smb2_acl,
3616 #endif /* CIFS_ACL */
3617 .next_header = smb2_next_header,
3620 struct smb_version_values smb20_values = {
3621 .version_string = SMB20_VERSION_STRING,
3622 .protocol_id = SMB20_PROT_ID,
3623 .req_capabilities = 0, /* MBZ */
3624 .large_lock_type = 0,
3625 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3626 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3627 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3628 .header_size = sizeof(struct smb2_sync_hdr),
3629 .header_preamble_size = 0,
3630 .max_header_size = MAX_SMB2_HDR_SIZE,
3631 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3632 .lock_cmd = SMB2_LOCK,
3634 .cap_nt_find = SMB2_NT_FIND,
3635 .cap_large_files = SMB2_LARGE_FILES,
3636 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3637 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3638 .create_lease_size = sizeof(struct create_lease),
3641 struct smb_version_values smb21_values = {
3642 .version_string = SMB21_VERSION_STRING,
3643 .protocol_id = SMB21_PROT_ID,
3644 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
3645 .large_lock_type = 0,
3646 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3647 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3648 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3649 .header_size = sizeof(struct smb2_sync_hdr),
3650 .header_preamble_size = 0,
3651 .max_header_size = MAX_SMB2_HDR_SIZE,
3652 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3653 .lock_cmd = SMB2_LOCK,
3655 .cap_nt_find = SMB2_NT_FIND,
3656 .cap_large_files = SMB2_LARGE_FILES,
3657 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3658 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3659 .create_lease_size = sizeof(struct create_lease),
3662 struct smb_version_values smb3any_values = {
3663 .version_string = SMB3ANY_VERSION_STRING,
3664 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
3665 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
3666 .large_lock_type = 0,
3667 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3668 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3669 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3670 .header_size = sizeof(struct smb2_sync_hdr),
3671 .header_preamble_size = 0,
3672 .max_header_size = MAX_SMB2_HDR_SIZE,
3673 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3674 .lock_cmd = SMB2_LOCK,
3676 .cap_nt_find = SMB2_NT_FIND,
3677 .cap_large_files = SMB2_LARGE_FILES,
3678 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3679 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3680 .create_lease_size = sizeof(struct create_lease_v2),
3683 struct smb_version_values smbdefault_values = {
3684 .version_string = SMBDEFAULT_VERSION_STRING,
3685 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
3686 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
3687 .large_lock_type = 0,
3688 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3689 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3690 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3691 .header_size = sizeof(struct smb2_sync_hdr),
3692 .header_preamble_size = 0,
3693 .max_header_size = MAX_SMB2_HDR_SIZE,
3694 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3695 .lock_cmd = SMB2_LOCK,
3697 .cap_nt_find = SMB2_NT_FIND,
3698 .cap_large_files = SMB2_LARGE_FILES,
3699 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3700 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3701 .create_lease_size = sizeof(struct create_lease_v2),
3704 struct smb_version_values smb30_values = {
3705 .version_string = SMB30_VERSION_STRING,
3706 .protocol_id = SMB30_PROT_ID,
3707 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
3708 .large_lock_type = 0,
3709 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3710 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3711 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3712 .header_size = sizeof(struct smb2_sync_hdr),
3713 .header_preamble_size = 0,
3714 .max_header_size = MAX_SMB2_HDR_SIZE,
3715 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3716 .lock_cmd = SMB2_LOCK,
3718 .cap_nt_find = SMB2_NT_FIND,
3719 .cap_large_files = SMB2_LARGE_FILES,
3720 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3721 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3722 .create_lease_size = sizeof(struct create_lease_v2),
3725 struct smb_version_values smb302_values = {
3726 .version_string = SMB302_VERSION_STRING,
3727 .protocol_id = SMB302_PROT_ID,
3728 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
3729 .large_lock_type = 0,
3730 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3731 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3732 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3733 .header_size = sizeof(struct smb2_sync_hdr),
3734 .header_preamble_size = 0,
3735 .max_header_size = MAX_SMB2_HDR_SIZE,
3736 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3737 .lock_cmd = SMB2_LOCK,
3739 .cap_nt_find = SMB2_NT_FIND,
3740 .cap_large_files = SMB2_LARGE_FILES,
3741 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3742 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3743 .create_lease_size = sizeof(struct create_lease_v2),
3746 struct smb_version_values smb311_values = {
3747 .version_string = SMB311_VERSION_STRING,
3748 .protocol_id = SMB311_PROT_ID,
3749 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION | SMB2_GLOBAL_CAP_DIRECTORY_LEASING,
3750 .large_lock_type = 0,
3751 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
3752 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
3753 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
3754 .header_size = sizeof(struct smb2_sync_hdr),
3755 .header_preamble_size = 0,
3756 .max_header_size = MAX_SMB2_HDR_SIZE,
3757 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
3758 .lock_cmd = SMB2_LOCK,
3760 .cap_nt_find = SMB2_NT_FIND,
3761 .cap_large_files = SMB2_LARGE_FILES,
3762 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
3763 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
3764 .create_lease_size = sizeof(struct create_lease_v2),