1 // SPDX-License-Identifier: GPL-2.0
3 * SMB2 version specific operations
8 #include <linux/pagemap.h>
10 #include <linux/falloc.h>
11 #include <linux/scatterlist.h>
12 #include <linux/uuid.h>
13 #include <crypto/aead.h>
16 #include "smb2proto.h"
17 #include "cifsproto.h"
18 #include "cifs_debug.h"
19 #include "cifs_unicode.h"
20 #include "smb2status.h"
22 #include "cifs_ioctl.h"
23 #include "smbdirect.h"
25 /* Change credits for different ops and return the total number of credits */
27 change_conf(struct TCP_Server_Info *server)
29 server->credits += server->echo_credits + server->oplock_credits;
30 server->oplock_credits = server->echo_credits = 0;
31 switch (server->credits) {
35 server->echoes = false;
36 server->oplocks = false;
39 server->echoes = true;
40 server->oplocks = false;
41 server->echo_credits = 1;
44 server->echoes = true;
46 server->oplocks = true;
47 server->oplock_credits = 1;
49 server->oplocks = false;
51 server->echo_credits = 1;
53 server->credits -= server->echo_credits + server->oplock_credits;
54 return server->credits + server->echo_credits + server->oplock_credits;
58 smb2_add_credits(struct TCP_Server_Info *server,
59 const struct cifs_credits *credits, const int optype)
62 unsigned int add = credits->value;
63 unsigned int instance = credits->instance;
64 bool reconnect_detected = false;
66 spin_lock(&server->req_lock);
67 val = server->ops->get_credits_field(server, optype);
69 /* eg found case where write overlapping reconnect messed up credits */
70 if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0))
71 trace_smb3_reconnect_with_invalid_credits(server->CurrentMid,
72 server->hostname, *val);
73 if ((instance == 0) || (instance == server->reconnect_instance))
76 reconnect_detected = true;
79 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
80 printk_once(KERN_WARNING "server overflowed SMB3 credits\n");
83 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
84 rc = change_conf(server);
86 * Sometimes server returns 0 credits on oplock break ack - we need to
87 * rebalance credits in this case.
89 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
91 if (server->credits > 1) {
93 server->oplock_credits++;
96 spin_unlock(&server->req_lock);
97 wake_up(&server->request_q);
99 if (reconnect_detected)
100 cifs_dbg(FYI, "trying to put %d credits from the old server instance %d\n",
103 if (server->tcpStatus == CifsNeedReconnect
104 || server->tcpStatus == CifsExiting)
109 /* change_conf hasn't been executed */
112 cifs_server_dbg(VFS, "Possible client or server bug - zero credits\n");
115 cifs_server_dbg(VFS, "disabling echoes and oplocks\n");
118 cifs_dbg(FYI, "disabling oplocks\n");
121 cifs_dbg(FYI, "add %u credits total=%d\n", add, rc);
126 smb2_set_credits(struct TCP_Server_Info *server, const int val)
128 spin_lock(&server->req_lock);
129 server->credits = val;
131 server->reconnect_instance++;
132 spin_unlock(&server->req_lock);
133 /* don't log while holding the lock */
135 cifs_dbg(FYI, "set credits to 1 due to smb2 reconnect\n");
139 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
143 return &server->echo_credits;
145 return &server->oplock_credits;
147 return &server->credits;
152 smb2_get_credits(struct mid_q_entry *mid)
154 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)mid->resp_buf;
156 if (mid->mid_state == MID_RESPONSE_RECEIVED
157 || mid->mid_state == MID_RESPONSE_MALFORMED)
158 return le16_to_cpu(shdr->CreditRequest);
164 smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
165 unsigned int *num, struct cifs_credits *credits)
168 unsigned int scredits;
170 spin_lock(&server->req_lock);
172 if (server->credits <= 0) {
173 spin_unlock(&server->req_lock);
174 cifs_num_waiters_inc(server);
175 rc = wait_event_killable(server->request_q,
176 has_credits(server, &server->credits, 1));
177 cifs_num_waiters_dec(server);
180 spin_lock(&server->req_lock);
182 if (server->tcpStatus == CifsExiting) {
183 spin_unlock(&server->req_lock);
187 scredits = server->credits;
188 /* can deadlock with reopen */
190 *num = SMB2_MAX_BUFFER_SIZE;
192 credits->instance = 0;
196 /* leave some credits for reopen and other ops */
198 *num = min_t(unsigned int, size,
199 scredits * SMB2_MAX_BUFFER_SIZE);
202 DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
203 credits->instance = server->reconnect_instance;
204 server->credits -= credits->value;
206 if (server->in_flight > server->max_in_flight)
207 server->max_in_flight = server->in_flight;
211 spin_unlock(&server->req_lock);
216 smb2_adjust_credits(struct TCP_Server_Info *server,
217 struct cifs_credits *credits,
218 const unsigned int payload_size)
220 int new_val = DIV_ROUND_UP(payload_size, SMB2_MAX_BUFFER_SIZE);
222 if (!credits->value || credits->value == new_val)
225 if (credits->value < new_val) {
226 WARN_ONCE(1, "request has less credits (%d) than required (%d)",
227 credits->value, new_val);
231 spin_lock(&server->req_lock);
233 if (server->reconnect_instance != credits->instance) {
234 spin_unlock(&server->req_lock);
235 cifs_server_dbg(VFS, "trying to return %d credits to old session\n",
236 credits->value - new_val);
240 server->credits += credits->value - new_val;
241 spin_unlock(&server->req_lock);
242 wake_up(&server->request_q);
243 credits->value = new_val;
248 smb2_get_next_mid(struct TCP_Server_Info *server)
251 /* for SMB2 we need the current value */
252 spin_lock(&GlobalMid_Lock);
253 mid = server->CurrentMid++;
254 spin_unlock(&GlobalMid_Lock);
259 smb2_revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
261 spin_lock(&GlobalMid_Lock);
262 if (server->CurrentMid >= val)
263 server->CurrentMid -= val;
264 spin_unlock(&GlobalMid_Lock);
267 static struct mid_q_entry *
268 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
270 struct mid_q_entry *mid;
271 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
272 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
274 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
275 cifs_server_dbg(VFS, "Encrypted frame parsing not supported yet\n");
279 spin_lock(&GlobalMid_Lock);
280 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
281 if ((mid->mid == wire_mid) &&
282 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
283 (mid->command == shdr->Command)) {
284 kref_get(&mid->refcount);
285 spin_unlock(&GlobalMid_Lock);
289 spin_unlock(&GlobalMid_Lock);
294 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
296 #ifdef CONFIG_CIFS_DEBUG2
297 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
299 cifs_server_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
300 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
302 cifs_server_dbg(VFS, "smb buf %p len %u\n", buf,
303 server->ops->calc_smb_size(buf, server));
308 smb2_need_neg(struct TCP_Server_Info *server)
310 return server->max_read == 0;
314 smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
318 ses->server->CurrentMid = 0;
319 rc = SMB2_negotiate(xid, ses);
320 /* BB we probably don't need to retry with modern servers */
327 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
329 struct TCP_Server_Info *server = tcon->ses->server;
332 /* start with specified wsize, or default */
333 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
334 wsize = min_t(unsigned int, wsize, server->max_write);
335 #ifdef CONFIG_CIFS_SMB_DIRECT
338 wsize = min_t(unsigned int,
339 wsize, server->smbd_conn->max_fragmented_send_size);
341 wsize = min_t(unsigned int,
342 wsize, server->smbd_conn->max_readwrite_size);
345 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
346 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
352 smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
354 struct TCP_Server_Info *server = tcon->ses->server;
357 /* start with specified wsize, or default */
358 wsize = volume_info->wsize ? volume_info->wsize : SMB3_DEFAULT_IOSIZE;
359 wsize = min_t(unsigned int, wsize, server->max_write);
360 #ifdef CONFIG_CIFS_SMB_DIRECT
363 wsize = min_t(unsigned int,
364 wsize, server->smbd_conn->max_fragmented_send_size);
366 wsize = min_t(unsigned int,
367 wsize, server->smbd_conn->max_readwrite_size);
370 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
371 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
377 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
379 struct TCP_Server_Info *server = tcon->ses->server;
382 /* start with specified rsize, or default */
383 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
384 rsize = min_t(unsigned int, rsize, server->max_read);
385 #ifdef CONFIG_CIFS_SMB_DIRECT
388 rsize = min_t(unsigned int,
389 rsize, server->smbd_conn->max_fragmented_recv_size);
391 rsize = min_t(unsigned int,
392 rsize, server->smbd_conn->max_readwrite_size);
396 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
397 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
403 smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
405 struct TCP_Server_Info *server = tcon->ses->server;
408 /* start with specified rsize, or default */
409 rsize = volume_info->rsize ? volume_info->rsize : SMB3_DEFAULT_IOSIZE;
410 rsize = min_t(unsigned int, rsize, server->max_read);
411 #ifdef CONFIG_CIFS_SMB_DIRECT
414 rsize = min_t(unsigned int,
415 rsize, server->smbd_conn->max_fragmented_recv_size);
417 rsize = min_t(unsigned int,
418 rsize, server->smbd_conn->max_readwrite_size);
422 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
423 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
429 parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
431 struct cifs_server_iface **iface_list,
434 struct network_interface_info_ioctl_rsp *p;
435 struct sockaddr_in *addr4;
436 struct sockaddr_in6 *addr6;
437 struct iface_info_ipv4 *p4;
438 struct iface_info_ipv6 *p6;
439 struct cifs_server_iface *info;
449 * Fist pass: count and sanity check
452 bytes_left = buf_len;
454 while (bytes_left >= sizeof(*p)) {
456 next = le32_to_cpu(p->Next);
458 bytes_left -= sizeof(*p);
461 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
466 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
471 if (bytes_left || p->Next)
472 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
476 * Second pass: extract info to internal structure
479 *iface_list = kcalloc(nb_iface, sizeof(**iface_list), GFP_KERNEL);
486 bytes_left = buf_len;
488 while (bytes_left >= sizeof(*p)) {
489 info->speed = le64_to_cpu(p->LinkSpeed);
490 info->rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE);
491 info->rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE);
493 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, *iface_count);
494 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
495 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
496 le32_to_cpu(p->Capability));
500 * The kernel and wire socket structures have the same
501 * layout and use network byte order but make the
502 * conversion explicit in case either one changes.
505 addr4 = (struct sockaddr_in *)&info->sockaddr;
506 p4 = (struct iface_info_ipv4 *)p->Buffer;
507 addr4->sin_family = AF_INET;
508 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
510 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
511 addr4->sin_port = cpu_to_be16(CIFS_PORT);
513 cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
517 addr6 = (struct sockaddr_in6 *)&info->sockaddr;
518 p6 = (struct iface_info_ipv6 *)p->Buffer;
519 addr6->sin6_family = AF_INET6;
520 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
522 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
523 addr6->sin6_flowinfo = 0;
524 addr6->sin6_scope_id = 0;
525 addr6->sin6_port = cpu_to_be16(CIFS_PORT);
527 cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
532 "%s: skipping unsupported socket family\n",
540 next = le32_to_cpu(p->Next);
543 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
563 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
566 unsigned int ret_data_len = 0;
567 struct network_interface_info_ioctl_rsp *out_buf = NULL;
568 struct cifs_server_iface *iface_list;
570 struct cifs_ses *ses = tcon->ses;
572 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
573 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
574 NULL /* no data input */, 0 /* no data input */,
575 CIFSMaxBufSize, (char **)&out_buf, &ret_data_len);
576 if (rc == -EOPNOTSUPP) {
578 "server does not support query network interfaces\n");
580 } else if (rc != 0) {
581 cifs_tcon_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
585 rc = parse_server_interfaces(out_buf, ret_data_len,
586 &iface_list, &iface_count);
590 spin_lock(&ses->iface_lock);
591 kfree(ses->iface_list);
592 ses->iface_list = iface_list;
593 ses->iface_count = iface_count;
594 ses->iface_last_update = jiffies;
595 spin_unlock(&ses->iface_lock);
603 smb2_close_cached_fid(struct kref *ref)
605 struct cached_fid *cfid = container_of(ref, struct cached_fid,
608 if (cfid->is_valid) {
609 cifs_dbg(FYI, "clear cached root file handle\n");
610 SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid,
611 cfid->fid->volatile_fid);
612 cfid->is_valid = false;
613 cfid->file_all_info_is_valid = false;
617 void close_shroot(struct cached_fid *cfid)
619 mutex_lock(&cfid->fid_mutex);
620 kref_put(&cfid->refcount, smb2_close_cached_fid);
621 mutex_unlock(&cfid->fid_mutex);
625 smb2_cached_lease_break(struct work_struct *work)
627 struct cached_fid *cfid = container_of(work,
628 struct cached_fid, lease_break);
634 * Open the directory at the root of a share
636 int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid)
638 struct cifs_ses *ses = tcon->ses;
639 struct TCP_Server_Info *server = ses->server;
640 struct cifs_open_parms oparms;
641 struct smb2_create_rsp *o_rsp = NULL;
642 struct smb2_query_info_rsp *qi_rsp = NULL;
644 struct smb_rqst rqst[2];
645 struct kvec rsp_iov[2];
646 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
647 struct kvec qi_iov[1];
649 __le16 utf16_path = 0; /* Null - since an open of top of share */
650 u8 oplock = SMB2_OPLOCK_LEVEL_II;
652 mutex_lock(&tcon->crfid.fid_mutex);
653 if (tcon->crfid.is_valid) {
654 cifs_dbg(FYI, "found a cached root file handle\n");
655 memcpy(pfid, tcon->crfid.fid, sizeof(struct cifs_fid));
656 kref_get(&tcon->crfid.refcount);
657 mutex_unlock(&tcon->crfid.fid_mutex);
662 * We do not hold the lock for the open because in case
663 * SMB2_open needs to reconnect, it will end up calling
664 * cifs_mark_open_files_invalid() which takes the lock again
665 * thus causing a deadlock
668 mutex_unlock(&tcon->crfid.fid_mutex);
670 if (smb3_encryption_required(tcon))
671 flags |= CIFS_TRANSFORM_REQ;
673 memset(rqst, 0, sizeof(rqst));
674 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
675 memset(rsp_iov, 0, sizeof(rsp_iov));
678 memset(&open_iov, 0, sizeof(open_iov));
679 rqst[0].rq_iov = open_iov;
680 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
683 oparms.create_options = 0;
684 oparms.desired_access = FILE_READ_ATTRIBUTES;
685 oparms.disposition = FILE_OPEN;
687 oparms.reconnect = false;
689 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, &utf16_path);
692 smb2_set_next_command(tcon, &rqst[0]);
694 memset(&qi_iov, 0, sizeof(qi_iov));
695 rqst[1].rq_iov = qi_iov;
698 rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID,
699 COMPOUND_FID, FILE_ALL_INFORMATION,
701 sizeof(struct smb2_file_all_info) +
702 PATH_MAX * 2, 0, NULL);
706 smb2_set_related(&rqst[1]);
708 rc = compound_send_recv(xid, ses, flags, 2, rqst,
709 resp_buftype, rsp_iov);
710 mutex_lock(&tcon->crfid.fid_mutex);
713 * Now we need to check again as the cached root might have
714 * been successfully re-opened from a concurrent process
717 if (tcon->crfid.is_valid) {
718 /* work was already done */
720 /* stash fids for close() later */
721 struct cifs_fid fid = {
722 .persistent_fid = pfid->persistent_fid,
723 .volatile_fid = pfid->volatile_fid,
727 * caller expects this func to set pfid to a valid
728 * cached root, so we copy the existing one and get a
731 memcpy(pfid, tcon->crfid.fid, sizeof(*pfid));
732 kref_get(&tcon->crfid.refcount);
734 mutex_unlock(&tcon->crfid.fid_mutex);
737 /* close extra handle outside of crit sec */
738 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
743 /* Cached root is still invalid, continue normaly */
746 if (rc == -EREMCHG) {
747 tcon->need_reconnect = true;
748 printk_once(KERN_WARNING "server share %s deleted\n",
754 atomic_inc(&tcon->num_remote_opens);
756 o_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
757 oparms.fid->persistent_fid = o_rsp->PersistentFileId;
758 oparms.fid->volatile_fid = o_rsp->VolatileFileId;
759 #ifdef CONFIG_CIFS_DEBUG2
760 oparms.fid->mid = le64_to_cpu(o_rsp->sync_hdr.MessageId);
761 #endif /* CIFS_DEBUG2 */
763 memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid));
764 tcon->crfid.tcon = tcon;
765 tcon->crfid.is_valid = true;
766 kref_init(&tcon->crfid.refcount);
768 /* BB TBD check to see if oplock level check can be removed below */
769 if (o_rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE) {
770 kref_get(&tcon->crfid.refcount);
771 smb2_parse_contexts(server, o_rsp,
773 oparms.fid->lease_key, &oplock, NULL);
777 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
778 if (le32_to_cpu(qi_rsp->OutputBufferLength) < sizeof(struct smb2_file_all_info))
780 if (!smb2_validate_and_copy_iov(
781 le16_to_cpu(qi_rsp->OutputBufferOffset),
782 sizeof(struct smb2_file_all_info),
783 &rsp_iov[1], sizeof(struct smb2_file_all_info),
784 (char *)&tcon->crfid.file_all_info))
785 tcon->crfid.file_all_info_is_valid = 1;
788 mutex_unlock(&tcon->crfid.fid_mutex);
790 SMB2_open_free(&rqst[0]);
791 SMB2_query_info_free(&rqst[1]);
792 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
793 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
798 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
801 __le16 srch_path = 0; /* Null - open root of share */
802 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
803 struct cifs_open_parms oparms;
805 bool no_cached_open = tcon->nohandlecache;
808 oparms.desired_access = FILE_READ_ATTRIBUTES;
809 oparms.disposition = FILE_OPEN;
810 oparms.create_options = 0;
812 oparms.reconnect = false;
815 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
818 rc = open_shroot(xid, tcon, &fid);
823 SMB3_request_interfaces(xid, tcon);
825 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
826 FS_ATTRIBUTE_INFORMATION);
827 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
828 FS_DEVICE_INFORMATION);
829 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
830 FS_VOLUME_INFORMATION);
831 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
832 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
834 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
836 close_shroot(&tcon->crfid);
840 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
843 __le16 srch_path = 0; /* Null - open root of share */
844 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
845 struct cifs_open_parms oparms;
849 oparms.desired_access = FILE_READ_ATTRIBUTES;
850 oparms.disposition = FILE_OPEN;
851 oparms.create_options = 0;
853 oparms.reconnect = false;
855 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
859 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
860 FS_ATTRIBUTE_INFORMATION);
861 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
862 FS_DEVICE_INFORMATION);
863 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
867 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
868 struct cifs_sb_info *cifs_sb, const char *full_path)
872 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
873 struct cifs_open_parms oparms;
876 if ((*full_path == 0) && tcon->crfid.is_valid)
879 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
884 oparms.desired_access = FILE_READ_ATTRIBUTES;
885 oparms.disposition = FILE_OPEN;
886 if (backup_cred(cifs_sb))
887 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
889 oparms.create_options = 0;
891 oparms.reconnect = false;
893 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
899 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
905 smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
906 struct cifs_sb_info *cifs_sb, const char *full_path,
907 u64 *uniqueid, FILE_ALL_INFO *data)
909 *uniqueid = le64_to_cpu(data->IndexNumber);
914 smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
915 struct cifs_fid *fid, FILE_ALL_INFO *data)
918 struct smb2_file_all_info *smb2_data;
920 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
922 if (smb2_data == NULL)
925 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
928 move_smb2_info_to_cifs(data, smb2_data);
933 #ifdef CONFIG_CIFS_XATTR
935 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
936 struct smb2_file_full_ea_info *src, size_t src_size,
937 const unsigned char *ea_name)
940 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
942 size_t buf_size = dst_size;
943 size_t name_len, value_len, user_name_len;
945 while (src_size > 0) {
946 name = &src->ea_data[0];
947 name_len = (size_t)src->ea_name_length;
948 value = &src->ea_data[src->ea_name_length + 1];
949 value_len = (size_t)le16_to_cpu(src->ea_value_length);
954 if (src_size < 8 + name_len + 1 + value_len) {
955 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
961 if (ea_name_len == name_len &&
962 memcmp(ea_name, name, name_len) == 0) {
966 if (dst_size < value_len) {
970 memcpy(dst, value, value_len);
974 /* 'user.' plus a terminating null */
975 user_name_len = 5 + 1 + name_len;
978 /* skip copy - calc size only */
980 } else if (dst_size >= user_name_len) {
981 dst_size -= user_name_len;
982 memcpy(dst, "user.", 5);
984 memcpy(dst, src->ea_data, name_len);
990 /* stop before overrun buffer */
996 if (!src->next_entry_offset)
999 if (src_size < le32_to_cpu(src->next_entry_offset)) {
1000 /* stop before overrun buffer */
1004 src_size -= le32_to_cpu(src->next_entry_offset);
1005 src = (void *)((char *)src +
1006 le32_to_cpu(src->next_entry_offset));
1009 /* didn't find the named attribute */
1018 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
1019 const unsigned char *path, const unsigned char *ea_name,
1020 char *ea_data, size_t buf_size,
1021 struct cifs_sb_info *cifs_sb)
1025 struct kvec rsp_iov = {NULL, 0};
1026 int buftype = CIFS_NO_BUFFER;
1027 struct smb2_query_info_rsp *rsp;
1028 struct smb2_file_full_ea_info *info = NULL;
1030 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1034 rc = smb2_query_info_compound(xid, tcon, utf16_path,
1036 FILE_FULL_EA_INFORMATION,
1039 MAX_SMB2_CREATE_RESPONSE_SIZE -
1040 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1041 &rsp_iov, &buftype, cifs_sb);
1044 * If ea_name is NULL (listxattr) and there are no EAs,
1045 * return 0 as it's not an error. Otherwise, the specified
1046 * ea_name was not found.
1048 if (!ea_name && rc == -ENODATA)
1053 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
1054 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1055 le32_to_cpu(rsp->OutputBufferLength),
1057 sizeof(struct smb2_file_full_ea_info));
1061 info = (struct smb2_file_full_ea_info *)(
1062 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1063 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
1064 le32_to_cpu(rsp->OutputBufferLength), ea_name);
1068 free_rsp_buf(buftype, rsp_iov.iov_base);
1074 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
1075 const char *path, const char *ea_name, const void *ea_value,
1076 const __u16 ea_value_len, const struct nls_table *nls_codepage,
1077 struct cifs_sb_info *cifs_sb)
1079 struct cifs_ses *ses = tcon->ses;
1080 __le16 *utf16_path = NULL;
1081 int ea_name_len = strlen(ea_name);
1084 struct smb_rqst rqst[3];
1085 int resp_buftype[3];
1086 struct kvec rsp_iov[3];
1087 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1088 struct cifs_open_parms oparms;
1089 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1090 struct cifs_fid fid;
1091 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1092 unsigned int size[1];
1094 struct smb2_file_full_ea_info *ea = NULL;
1095 struct kvec close_iov[1];
1098 if (smb3_encryption_required(tcon))
1099 flags |= CIFS_TRANSFORM_REQ;
1101 if (ea_name_len > 255)
1104 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1108 memset(rqst, 0, sizeof(rqst));
1109 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1110 memset(rsp_iov, 0, sizeof(rsp_iov));
1112 if (ses->server->ops->query_all_EAs) {
1114 rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1123 memset(&open_iov, 0, sizeof(open_iov));
1124 rqst[0].rq_iov = open_iov;
1125 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1127 memset(&oparms, 0, sizeof(oparms));
1129 oparms.desired_access = FILE_WRITE_EA;
1130 oparms.disposition = FILE_OPEN;
1131 if (backup_cred(cifs_sb))
1132 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1134 oparms.create_options = 0;
1136 oparms.reconnect = false;
1138 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, utf16_path);
1141 smb2_set_next_command(tcon, &rqst[0]);
1145 memset(&si_iov, 0, sizeof(si_iov));
1146 rqst[1].rq_iov = si_iov;
1147 rqst[1].rq_nvec = 1;
1149 len = sizeof(ea) + ea_name_len + ea_value_len + 1;
1150 ea = kzalloc(len, GFP_KERNEL);
1156 ea->ea_name_length = ea_name_len;
1157 ea->ea_value_length = cpu_to_le16(ea_value_len);
1158 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
1159 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
1164 rc = SMB2_set_info_init(tcon, &rqst[1], COMPOUND_FID,
1165 COMPOUND_FID, current->tgid,
1166 FILE_FULL_EA_INFORMATION,
1167 SMB2_O_INFO_FILE, 0, data, size);
1168 smb2_set_next_command(tcon, &rqst[1]);
1169 smb2_set_related(&rqst[1]);
1173 memset(&close_iov, 0, sizeof(close_iov));
1174 rqst[2].rq_iov = close_iov;
1175 rqst[2].rq_nvec = 1;
1176 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
1177 smb2_set_related(&rqst[2]);
1179 rc = compound_send_recv(xid, ses, flags, 3, rqst,
1180 resp_buftype, rsp_iov);
1181 /* no need to bump num_remote_opens because handle immediately closed */
1186 SMB2_open_free(&rqst[0]);
1187 SMB2_set_info_free(&rqst[1]);
1188 SMB2_close_free(&rqst[2]);
1189 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1190 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1191 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1197 smb2_can_echo(struct TCP_Server_Info *server)
1199 return server->echoes;
1203 smb2_clear_stats(struct cifs_tcon *tcon)
1207 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1208 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1209 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1214 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1216 seq_puts(m, "\n\tShare Capabilities:");
1217 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1218 seq_puts(m, " DFS,");
1219 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1220 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1221 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1222 seq_puts(m, " SCALEOUT,");
1223 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1224 seq_puts(m, " CLUSTER,");
1225 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1226 seq_puts(m, " ASYMMETRIC,");
1227 if (tcon->capabilities == 0)
1228 seq_puts(m, " None");
1229 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1230 seq_puts(m, " Aligned,");
1231 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1232 seq_puts(m, " Partition Aligned,");
1233 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1234 seq_puts(m, " SSD,");
1235 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1236 seq_puts(m, " TRIM-support,");
1238 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1239 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1240 if (tcon->perf_sector_size)
1241 seq_printf(m, "\tOptimal sector size: 0x%x",
1242 tcon->perf_sector_size);
1243 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1247 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1249 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1250 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1253 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1254 * totals (requests sent) since those SMBs are per-session not per tcon
1256 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1257 (long long)(tcon->bytes_read),
1258 (long long)(tcon->bytes_written));
1259 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1260 atomic_read(&tcon->num_local_opens),
1261 atomic_read(&tcon->num_remote_opens));
1262 seq_printf(m, "\nTreeConnects: %d total %d failed",
1263 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1264 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1265 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1266 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1267 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1268 seq_printf(m, "\nCreates: %d total %d failed",
1269 atomic_read(&sent[SMB2_CREATE_HE]),
1270 atomic_read(&failed[SMB2_CREATE_HE]));
1271 seq_printf(m, "\nCloses: %d total %d failed",
1272 atomic_read(&sent[SMB2_CLOSE_HE]),
1273 atomic_read(&failed[SMB2_CLOSE_HE]));
1274 seq_printf(m, "\nFlushes: %d total %d failed",
1275 atomic_read(&sent[SMB2_FLUSH_HE]),
1276 atomic_read(&failed[SMB2_FLUSH_HE]));
1277 seq_printf(m, "\nReads: %d total %d failed",
1278 atomic_read(&sent[SMB2_READ_HE]),
1279 atomic_read(&failed[SMB2_READ_HE]));
1280 seq_printf(m, "\nWrites: %d total %d failed",
1281 atomic_read(&sent[SMB2_WRITE_HE]),
1282 atomic_read(&failed[SMB2_WRITE_HE]));
1283 seq_printf(m, "\nLocks: %d total %d failed",
1284 atomic_read(&sent[SMB2_LOCK_HE]),
1285 atomic_read(&failed[SMB2_LOCK_HE]));
1286 seq_printf(m, "\nIOCTLs: %d total %d failed",
1287 atomic_read(&sent[SMB2_IOCTL_HE]),
1288 atomic_read(&failed[SMB2_IOCTL_HE]));
1289 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1290 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1291 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1292 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1293 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1294 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1295 seq_printf(m, "\nQueryInfos: %d total %d failed",
1296 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1297 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1298 seq_printf(m, "\nSetInfos: %d total %d failed",
1299 atomic_read(&sent[SMB2_SET_INFO_HE]),
1300 atomic_read(&failed[SMB2_SET_INFO_HE]));
1301 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1302 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1303 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1307 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1309 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1310 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1312 cfile->fid.persistent_fid = fid->persistent_fid;
1313 cfile->fid.volatile_fid = fid->volatile_fid;
1314 #ifdef CONFIG_CIFS_DEBUG2
1315 cfile->fid.mid = fid->mid;
1316 #endif /* CIFS_DEBUG2 */
1317 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1319 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1320 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1324 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1325 struct cifs_fid *fid)
1327 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1331 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1332 u64 persistent_fid, u64 volatile_fid,
1333 struct copychunk_ioctl *pcchunk)
1336 unsigned int ret_data_len;
1337 struct resume_key_req *res_key;
1339 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1340 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
1341 NULL, 0 /* no input */, CIFSMaxBufSize,
1342 (char **)&res_key, &ret_data_len);
1345 cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1346 goto req_res_key_exit;
1348 if (ret_data_len < sizeof(struct resume_key_req)) {
1349 cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n");
1351 goto req_res_key_exit;
1353 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1361 smb2_ioctl_query_info(const unsigned int xid,
1362 struct cifs_tcon *tcon,
1363 __le16 *path, int is_dir,
1366 struct cifs_ses *ses = tcon->ses;
1367 char __user *arg = (char __user *)p;
1368 struct smb_query_info qi;
1369 struct smb_query_info __user *pqi;
1372 struct smb2_query_info_rsp *qi_rsp = NULL;
1373 struct smb2_ioctl_rsp *io_rsp = NULL;
1374 void *buffer = NULL;
1375 struct smb_rqst rqst[3];
1376 int resp_buftype[3];
1377 struct kvec rsp_iov[3];
1378 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1379 struct cifs_open_parms oparms;
1380 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1381 struct cifs_fid fid;
1382 struct kvec qi_iov[1];
1383 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
1384 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1385 struct kvec close_iov[1];
1386 unsigned int size[2];
1389 memset(rqst, 0, sizeof(rqst));
1390 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1391 memset(rsp_iov, 0, sizeof(rsp_iov));
1393 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info)))
1396 if (qi.output_buffer_length > 1024)
1399 if (!ses || !(ses->server))
1402 if (smb3_encryption_required(tcon))
1403 flags |= CIFS_TRANSFORM_REQ;
1405 buffer = kmalloc(qi.output_buffer_length, GFP_KERNEL);
1409 if (copy_from_user(buffer, arg + sizeof(struct smb_query_info),
1410 qi.output_buffer_length)) {
1416 memset(&open_iov, 0, sizeof(open_iov));
1417 rqst[0].rq_iov = open_iov;
1418 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1420 memset(&oparms, 0, sizeof(oparms));
1422 oparms.disposition = FILE_OPEN;
1424 oparms.create_options = CREATE_NOT_FILE;
1426 oparms.create_options = CREATE_NOT_DIR;
1428 oparms.reconnect = false;
1430 if (qi.flags & PASSTHRU_FSCTL) {
1431 switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1432 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1433 oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1435 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1436 oparms.desired_access = GENERIC_ALL;
1438 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1439 oparms.desired_access = GENERIC_READ;
1441 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1442 oparms.desired_access = GENERIC_WRITE;
1445 } else if (qi.flags & PASSTHRU_SET_INFO) {
1446 oparms.desired_access = GENERIC_WRITE;
1448 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1451 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, path);
1454 smb2_set_next_command(tcon, &rqst[0]);
1457 if (qi.flags & PASSTHRU_FSCTL) {
1458 /* Can eventually relax perm check since server enforces too */
1459 if (!capable(CAP_SYS_ADMIN))
1462 memset(&io_iov, 0, sizeof(io_iov));
1463 rqst[1].rq_iov = io_iov;
1464 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1466 rc = SMB2_ioctl_init(tcon, &rqst[1],
1467 COMPOUND_FID, COMPOUND_FID,
1468 qi.info_type, true, buffer,
1469 qi.output_buffer_length,
1472 } else if (qi.flags == PASSTHRU_SET_INFO) {
1473 /* Can eventually relax perm check since server enforces too */
1474 if (!capable(CAP_SYS_ADMIN))
1477 memset(&si_iov, 0, sizeof(si_iov));
1478 rqst[1].rq_iov = si_iov;
1479 rqst[1].rq_nvec = 1;
1484 rc = SMB2_set_info_init(tcon, &rqst[1],
1485 COMPOUND_FID, COMPOUND_FID,
1487 FILE_END_OF_FILE_INFORMATION,
1488 SMB2_O_INFO_FILE, 0, data, size);
1490 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1491 memset(&qi_iov, 0, sizeof(qi_iov));
1492 rqst[1].rq_iov = qi_iov;
1493 rqst[1].rq_nvec = 1;
1495 rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID,
1496 COMPOUND_FID, qi.file_info_class,
1497 qi.info_type, qi.additional_information,
1498 qi.input_buffer_length,
1499 qi.output_buffer_length, buffer);
1500 } else { /* unknown flags */
1501 cifs_tcon_dbg(VFS, "invalid passthru query flags: 0x%x\n", qi.flags);
1507 smb2_set_next_command(tcon, &rqst[1]);
1508 smb2_set_related(&rqst[1]);
1511 memset(&close_iov, 0, sizeof(close_iov));
1512 rqst[2].rq_iov = close_iov;
1513 rqst[2].rq_nvec = 1;
1515 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
1518 smb2_set_related(&rqst[2]);
1520 rc = compound_send_recv(xid, ses, flags, 3, rqst,
1521 resp_buftype, rsp_iov);
1525 /* No need to bump num_remote_opens since handle immediately closed */
1526 if (qi.flags & PASSTHRU_FSCTL) {
1527 pqi = (struct smb_query_info __user *)arg;
1528 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1529 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1530 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1531 if (qi.input_buffer_length > 0 &&
1532 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length > rsp_iov[1].iov_len) {
1536 if (copy_to_user(&pqi->input_buffer_length, &qi.input_buffer_length,
1537 sizeof(qi.input_buffer_length))) {
1541 if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1542 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1543 qi.input_buffer_length)) {
1548 pqi = (struct smb_query_info __user *)arg;
1549 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1550 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1551 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1552 if (copy_to_user(&pqi->input_buffer_length, &qi.input_buffer_length,
1553 sizeof(qi.input_buffer_length))) {
1557 if (copy_to_user(pqi + 1, qi_rsp->Buffer, qi.input_buffer_length)) {
1565 SMB2_open_free(&rqst[0]);
1566 if (qi.flags & PASSTHRU_FSCTL)
1567 SMB2_ioctl_free(&rqst[1]);
1569 SMB2_query_info_free(&rqst[1]);
1571 SMB2_close_free(&rqst[2]);
1572 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1573 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1574 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1579 smb2_copychunk_range(const unsigned int xid,
1580 struct cifsFileInfo *srcfile,
1581 struct cifsFileInfo *trgtfile, u64 src_off,
1582 u64 len, u64 dest_off)
1585 unsigned int ret_data_len;
1586 struct copychunk_ioctl *pcchunk;
1587 struct copychunk_ioctl_rsp *retbuf = NULL;
1588 struct cifs_tcon *tcon;
1589 int chunks_copied = 0;
1590 bool chunk_sizes_updated = false;
1591 ssize_t bytes_written, total_bytes_written = 0;
1593 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1595 if (pcchunk == NULL)
1598 cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
1599 /* Request a key from the server to identify the source of the copy */
1600 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1601 srcfile->fid.persistent_fid,
1602 srcfile->fid.volatile_fid, pcchunk);
1604 /* Note: request_res_key sets res_key null only if rc !=0 */
1608 /* For now array only one chunk long, will make more flexible later */
1609 pcchunk->ChunkCount = cpu_to_le32(1);
1610 pcchunk->Reserved = 0;
1611 pcchunk->Reserved2 = 0;
1613 tcon = tlink_tcon(trgtfile->tlink);
1616 pcchunk->SourceOffset = cpu_to_le64(src_off);
1617 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1619 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
1621 /* Request server copy to target from src identified by key */
1622 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1623 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1624 true /* is_fsctl */, (char *)pcchunk,
1625 sizeof(struct copychunk_ioctl), CIFSMaxBufSize,
1626 (char **)&retbuf, &ret_data_len);
1629 sizeof(struct copychunk_ioctl_rsp)) {
1630 cifs_tcon_dbg(VFS, "invalid cchunk response size\n");
1634 if (retbuf->TotalBytesWritten == 0) {
1635 cifs_dbg(FYI, "no bytes copied\n");
1640 * Check if server claimed to write more than we asked
1642 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1643 le32_to_cpu(pcchunk->Length)) {
1644 cifs_tcon_dbg(VFS, "invalid copy chunk response\n");
1648 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1649 cifs_tcon_dbg(VFS, "invalid num chunks written\n");
1655 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1656 src_off += bytes_written;
1657 dest_off += bytes_written;
1658 len -= bytes_written;
1659 total_bytes_written += bytes_written;
1661 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1662 le32_to_cpu(retbuf->ChunksWritten),
1663 le32_to_cpu(retbuf->ChunkBytesWritten),
1665 } else if (rc == -EINVAL) {
1666 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1669 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1670 le32_to_cpu(retbuf->ChunksWritten),
1671 le32_to_cpu(retbuf->ChunkBytesWritten),
1672 le32_to_cpu(retbuf->TotalBytesWritten));
1675 * Check if this is the first request using these sizes,
1676 * (ie check if copy succeed once with original sizes
1677 * and check if the server gave us different sizes after
1678 * we already updated max sizes on previous request).
1679 * if not then why is the server returning an error now
1681 if ((chunks_copied != 0) || chunk_sizes_updated)
1684 /* Check that server is not asking us to grow size */
1685 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1686 tcon->max_bytes_chunk)
1687 tcon->max_bytes_chunk =
1688 le32_to_cpu(retbuf->ChunkBytesWritten);
1690 goto cchunk_out; /* server gave us bogus size */
1692 /* No need to change MaxChunks since already set to 1 */
1693 chunk_sizes_updated = true;
1704 return total_bytes_written;
1708 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1709 struct cifs_fid *fid)
1711 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1715 smb2_read_data_offset(char *buf)
1717 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1719 return rsp->DataOffset;
1723 smb2_read_data_length(char *buf, bool in_remaining)
1725 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1728 return le32_to_cpu(rsp->DataRemaining);
1730 return le32_to_cpu(rsp->DataLength);
1735 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1736 struct cifs_io_parms *parms, unsigned int *bytes_read,
1737 char **buf, int *buf_type)
1739 parms->persistent_fid = pfid->persistent_fid;
1740 parms->volatile_fid = pfid->volatile_fid;
1741 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1745 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1746 struct cifs_io_parms *parms, unsigned int *written,
1747 struct kvec *iov, unsigned long nr_segs)
1750 parms->persistent_fid = pfid->persistent_fid;
1751 parms->volatile_fid = pfid->volatile_fid;
1752 return SMB2_write(xid, parms, written, iov, nr_segs);
1755 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1756 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1757 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1759 struct cifsInodeInfo *cifsi;
1762 cifsi = CIFS_I(inode);
1764 /* if file already sparse don't bother setting sparse again */
1765 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1766 return true; /* already sparse */
1768 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1769 return true; /* already not sparse */
1772 * Can't check for sparse support on share the usual way via the
1773 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1774 * since Samba server doesn't set the flag on the share, yet
1775 * supports the set sparse FSCTL and returns sparse correctly
1776 * in the file attributes. If we fail setting sparse though we
1777 * mark that server does not support sparse files for this share
1778 * to avoid repeatedly sending the unsupported fsctl to server
1779 * if the file is repeatedly extended.
1781 if (tcon->broken_sparse_sup)
1784 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1785 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1787 &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
1789 tcon->broken_sparse_sup = true;
1790 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1795 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1797 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1803 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1804 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1806 __le64 eof = cpu_to_le64(size);
1807 struct inode *inode;
1810 * If extending file more than one page make sparse. Many Linux fs
1811 * make files sparse by default when extending via ftruncate
1813 inode = d_inode(cfile->dentry);
1815 if (!set_alloc && (size > inode->i_size + 8192)) {
1816 __u8 set_sparse = 1;
1818 /* whether set sparse succeeds or not, extend the file */
1819 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1822 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1823 cfile->fid.volatile_fid, cfile->pid, &eof);
1827 smb2_duplicate_extents(const unsigned int xid,
1828 struct cifsFileInfo *srcfile,
1829 struct cifsFileInfo *trgtfile, u64 src_off,
1830 u64 len, u64 dest_off)
1833 unsigned int ret_data_len;
1834 struct duplicate_extents_to_file dup_ext_buf;
1835 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1837 /* server fileays advertise duplicate extent support with this flag */
1838 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1839 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1842 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1843 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1844 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1845 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1846 dup_ext_buf.ByteCount = cpu_to_le64(len);
1847 cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
1848 src_off, dest_off, len);
1850 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1852 goto duplicate_extents_out;
1854 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1855 trgtfile->fid.volatile_fid,
1856 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1857 true /* is_fsctl */,
1858 (char *)&dup_ext_buf,
1859 sizeof(struct duplicate_extents_to_file),
1860 CIFSMaxBufSize, NULL,
1863 if (ret_data_len > 0)
1864 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
1866 duplicate_extents_out:
1871 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1872 struct cifsFileInfo *cfile)
1874 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1875 cfile->fid.volatile_fid);
1879 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
1880 struct cifsFileInfo *cfile)
1882 struct fsctl_set_integrity_information_req integr_info;
1883 unsigned int ret_data_len;
1885 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
1886 integr_info.Flags = 0;
1887 integr_info.Reserved = 0;
1889 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1890 cfile->fid.volatile_fid,
1891 FSCTL_SET_INTEGRITY_INFORMATION,
1892 true /* is_fsctl */,
1893 (char *)&integr_info,
1894 sizeof(struct fsctl_set_integrity_information_req),
1895 CIFSMaxBufSize, NULL,
1900 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
1901 #define GMT_TOKEN_SIZE 50
1903 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
1906 * Input buffer contains (empty) struct smb_snapshot array with size filled in
1907 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
1910 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
1911 struct cifsFileInfo *cfile, void __user *ioc_buf)
1913 char *retbuf = NULL;
1914 unsigned int ret_data_len = 0;
1916 u32 max_response_size;
1917 struct smb_snapshot_array snapshot_in;
1920 * On the first query to enumerate the list of snapshots available
1921 * for this volume the buffer begins with 0 (number of snapshots
1922 * which can be returned is zero since at that point we do not know
1923 * how big the buffer needs to be). On the second query,
1924 * it (ret_data_len) is set to number of snapshots so we can
1925 * know to set the maximum response size larger (see below).
1927 if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
1931 * Note that for snapshot queries that servers like Azure expect that
1932 * the first query be minimal size (and just used to get the number/size
1933 * of previous versions) so response size must be specified as EXACTLY
1934 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
1937 if (ret_data_len == 0)
1938 max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
1940 max_response_size = CIFSMaxBufSize;
1942 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1943 cfile->fid.volatile_fid,
1944 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
1945 true /* is_fsctl */,
1946 NULL, 0 /* no input data */, max_response_size,
1949 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
1954 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
1956 if (copy_from_user(&snapshot_in, ioc_buf,
1957 sizeof(struct smb_snapshot_array))) {
1964 * Check for min size, ie not large enough to fit even one GMT
1965 * token (snapshot). On the first ioctl some users may pass in
1966 * smaller size (or zero) to simply get the size of the array
1967 * so the user space caller can allocate sufficient memory
1968 * and retry the ioctl again with larger array size sufficient
1969 * to hold all of the snapshot GMT tokens on the second try.
1971 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
1972 ret_data_len = sizeof(struct smb_snapshot_array);
1975 * We return struct SRV_SNAPSHOT_ARRAY, followed by
1976 * the snapshot array (of 50 byte GMT tokens) each
1977 * representing an available previous version of the data
1979 if (ret_data_len > (snapshot_in.snapshot_array_size +
1980 sizeof(struct smb_snapshot_array)))
1981 ret_data_len = snapshot_in.snapshot_array_size +
1982 sizeof(struct smb_snapshot_array);
1984 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
1993 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
1994 const char *path, struct cifs_sb_info *cifs_sb,
1995 struct cifs_fid *fid, __u16 search_flags,
1996 struct cifs_search_info *srch_inf)
2000 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2001 struct cifs_open_parms oparms;
2003 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2008 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
2009 oparms.disposition = FILE_OPEN;
2010 if (backup_cred(cifs_sb))
2011 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2013 oparms.create_options = 0;
2015 oparms.reconnect = false;
2017 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
2020 cifs_dbg(FYI, "open dir failed rc=%d\n", rc);
2024 srch_inf->entries_in_buffer = 0;
2025 srch_inf->index_of_last_entry = 2;
2027 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
2028 fid->volatile_fid, 0, srch_inf);
2030 cifs_dbg(FYI, "query directory failed rc=%d\n", rc);
2031 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2037 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
2038 struct cifs_fid *fid, __u16 search_flags,
2039 struct cifs_search_info *srch_inf)
2041 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
2042 fid->volatile_fid, 0, srch_inf);
2046 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
2047 struct cifs_fid *fid)
2049 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2053 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2054 * the number of credits and return true. Otherwise - return false.
2057 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
2059 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2061 if (shdr->Status != STATUS_PENDING)
2064 if (shdr->CreditRequest) {
2065 spin_lock(&server->req_lock);
2066 server->credits += le16_to_cpu(shdr->CreditRequest);
2067 spin_unlock(&server->req_lock);
2068 wake_up(&server->request_q);
2075 smb2_is_session_expired(char *buf)
2077 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2079 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
2080 shdr->Status != STATUS_USER_SESSION_DELETED)
2083 trace_smb3_ses_expired(shdr->TreeId, shdr->SessionId,
2084 le16_to_cpu(shdr->Command),
2085 le64_to_cpu(shdr->MessageId));
2086 cifs_dbg(FYI, "Session expired or deleted\n");
2092 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
2093 struct cifsInodeInfo *cinode)
2095 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
2096 return SMB2_lease_break(0, tcon, cinode->lease_key,
2097 smb2_get_lease_state(cinode));
2099 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
2101 CIFS_CACHE_READ(cinode) ? 1 : 0);
2105 smb2_set_related(struct smb_rqst *rqst)
2107 struct smb2_sync_hdr *shdr;
2109 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
2111 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2114 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2117 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
2120 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
2122 struct smb2_sync_hdr *shdr;
2123 struct cifs_ses *ses = tcon->ses;
2124 struct TCP_Server_Info *server = ses->server;
2125 unsigned long len = smb_rqst_len(server, rqst);
2128 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
2130 cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2134 /* SMB headers in a compound are 8 byte aligned. */
2136 /* No padding needed */
2140 num_padding = 8 - (len & 7);
2141 if (!smb3_encryption_required(tcon)) {
2143 * If we do not have encryption then we can just add an extra
2144 * iov for the padding.
2146 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2147 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2152 * We can not add a small padding iov for the encryption case
2153 * because the encryption framework can not handle the padding
2155 * We have to flatten this into a single buffer and add
2156 * the padding to it.
2158 for (i = 1; i < rqst->rq_nvec; i++) {
2159 memcpy(rqst->rq_iov[0].iov_base +
2160 rqst->rq_iov[0].iov_len,
2161 rqst->rq_iov[i].iov_base,
2162 rqst->rq_iov[i].iov_len);
2163 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2165 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2167 rqst->rq_iov[0].iov_len += num_padding;
2173 shdr->NextCommand = cpu_to_le32(len);
2177 * Passes the query info response back to the caller on success.
2178 * Caller need to free this with free_rsp_buf().
2181 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2182 __le16 *utf16_path, u32 desired_access,
2183 u32 class, u32 type, u32 output_len,
2184 struct kvec *rsp, int *buftype,
2185 struct cifs_sb_info *cifs_sb)
2187 struct cifs_ses *ses = tcon->ses;
2189 struct smb_rqst rqst[3];
2190 int resp_buftype[3];
2191 struct kvec rsp_iov[3];
2192 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2193 struct kvec qi_iov[1];
2194 struct kvec close_iov[1];
2195 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2196 struct cifs_open_parms oparms;
2197 struct cifs_fid fid;
2200 if (smb3_encryption_required(tcon))
2201 flags |= CIFS_TRANSFORM_REQ;
2203 memset(rqst, 0, sizeof(rqst));
2204 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2205 memset(rsp_iov, 0, sizeof(rsp_iov));
2207 memset(&open_iov, 0, sizeof(open_iov));
2208 rqst[0].rq_iov = open_iov;
2209 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2212 oparms.desired_access = desired_access;
2213 oparms.disposition = FILE_OPEN;
2214 if (cifs_sb && backup_cred(cifs_sb))
2215 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2217 oparms.create_options = 0;
2219 oparms.reconnect = false;
2221 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, utf16_path);
2224 smb2_set_next_command(tcon, &rqst[0]);
2226 memset(&qi_iov, 0, sizeof(qi_iov));
2227 rqst[1].rq_iov = qi_iov;
2228 rqst[1].rq_nvec = 1;
2230 rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID, COMPOUND_FID,
2236 smb2_set_next_command(tcon, &rqst[1]);
2237 smb2_set_related(&rqst[1]);
2239 memset(&close_iov, 0, sizeof(close_iov));
2240 rqst[2].rq_iov = close_iov;
2241 rqst[2].rq_nvec = 1;
2243 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
2246 smb2_set_related(&rqst[2]);
2248 rc = compound_send_recv(xid, ses, flags, 3, rqst,
2249 resp_buftype, rsp_iov);
2251 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2252 if (rc == -EREMCHG) {
2253 tcon->need_reconnect = true;
2254 printk_once(KERN_WARNING "server share %s deleted\n",
2260 *buftype = resp_buftype[1];
2263 SMB2_open_free(&rqst[0]);
2264 SMB2_query_info_free(&rqst[1]);
2265 SMB2_close_free(&rqst[2]);
2266 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2267 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2272 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2273 struct kstatfs *buf)
2275 struct smb2_query_info_rsp *rsp;
2276 struct smb2_fs_full_size_info *info = NULL;
2277 __le16 utf16_path = 0; /* Null - open root of share */
2278 struct kvec rsp_iov = {NULL, 0};
2279 int buftype = CIFS_NO_BUFFER;
2283 rc = smb2_query_info_compound(xid, tcon, &utf16_path,
2284 FILE_READ_ATTRIBUTES,
2285 FS_FULL_SIZE_INFORMATION,
2286 SMB2_O_INFO_FILESYSTEM,
2287 sizeof(struct smb2_fs_full_size_info),
2288 &rsp_iov, &buftype, NULL);
2292 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2293 buf->f_type = SMB2_MAGIC_NUMBER;
2294 info = (struct smb2_fs_full_size_info *)(
2295 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2296 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2297 le32_to_cpu(rsp->OutputBufferLength),
2299 sizeof(struct smb2_fs_full_size_info));
2301 smb2_copy_fs_info_to_kstatfs(info, buf);
2304 free_rsp_buf(buftype, rsp_iov.iov_base);
2309 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2310 struct kstatfs *buf)
2313 __le16 srch_path = 0; /* Null - open root of share */
2314 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2315 struct cifs_open_parms oparms;
2316 struct cifs_fid fid;
2318 if (!tcon->posix_extensions)
2319 return smb2_queryfs(xid, tcon, buf);
2322 oparms.desired_access = FILE_READ_ATTRIBUTES;
2323 oparms.disposition = FILE_OPEN;
2324 oparms.create_options = 0;
2326 oparms.reconnect = false;
2328 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
2332 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2333 fid.volatile_fid, buf);
2334 buf->f_type = SMB2_MAGIC_NUMBER;
2335 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2340 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2342 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2343 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2347 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2348 __u64 length, __u32 type, int lock, int unlock, bool wait)
2350 if (unlock && !lock)
2351 type = SMB2_LOCKFLAG_UNLOCK;
2352 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2353 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2354 current->tgid, length, offset, type, wait);
2358 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2360 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2364 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2366 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2370 smb2_new_lease_key(struct cifs_fid *fid)
2372 generate_random_uuid(fid->lease_key);
2376 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2377 const char *search_name,
2378 struct dfs_info3_param **target_nodes,
2379 unsigned int *num_of_nodes,
2380 const struct nls_table *nls_codepage, int remap)
2383 __le16 *utf16_path = NULL;
2384 int utf16_path_len = 0;
2385 struct cifs_tcon *tcon;
2386 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2387 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2388 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2390 cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name);
2393 * Try to use the IPC tcon, otherwise just use any
2395 tcon = ses->tcon_ipc;
2397 spin_lock(&cifs_tcp_ses_lock);
2398 tcon = list_first_entry_or_null(&ses->tcon_list,
2403 spin_unlock(&cifs_tcp_ses_lock);
2407 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2413 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2415 nls_codepage, remap);
2421 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2422 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2428 /* Highest DFS referral version understood */
2429 dfs_req->MaxReferralLevel = DFS_VERSION;
2431 /* Path to resolve in an UTF-16 null-terminated string */
2432 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2435 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2436 FSCTL_DFS_GET_REFERRALS,
2437 true /* is_fsctl */,
2438 (char *)dfs_req, dfs_req_size, CIFSMaxBufSize,
2439 (char **)&dfs_rsp, &dfs_rsp_size);
2440 } while (rc == -EAGAIN);
2443 if ((rc != -ENOENT) && (rc != -EOPNOTSUPP))
2444 cifs_tcon_dbg(VFS, "ioctl error in %s rc=%d\n", __func__, rc);
2448 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
2449 num_of_nodes, target_nodes,
2450 nls_codepage, remap, search_name,
2451 true /* is_unicode */);
2453 cifs_tcon_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc);
2458 if (tcon && !tcon->ipc) {
2459 /* ipc tcons are not refcounted */
2460 spin_lock(&cifs_tcp_ses_lock);
2462 spin_unlock(&cifs_tcp_ses_lock);
2471 parse_reparse_posix(struct reparse_posix_data *symlink_buf,
2472 u32 plen, char **target_path,
2473 struct cifs_sb_info *cifs_sb)
2477 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
2478 len = le16_to_cpu(symlink_buf->ReparseDataLength);
2480 if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
2481 cifs_dbg(VFS, "%lld not a supported symlink type\n",
2482 le64_to_cpu(symlink_buf->InodeType));
2486 *target_path = cifs_strndup_from_utf16(
2487 symlink_buf->PathBuffer,
2488 len, true, cifs_sb->local_nls);
2489 if (!(*target_path))
2492 convert_delimiter(*target_path, '/');
2493 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2499 parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
2500 u32 plen, char **target_path,
2501 struct cifs_sb_info *cifs_sb)
2503 unsigned int sub_len;
2504 unsigned int sub_offset;
2506 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */
2508 sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset);
2509 sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength);
2510 if (sub_offset + 20 > plen ||
2511 sub_offset + sub_len + 20 > plen) {
2512 cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
2516 *target_path = cifs_strndup_from_utf16(
2517 symlink_buf->PathBuffer + sub_offset,
2518 sub_len, true, cifs_sb->local_nls);
2519 if (!(*target_path))
2522 convert_delimiter(*target_path, '/');
2523 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2529 parse_reparse_point(struct reparse_data_buffer *buf,
2530 u32 plen, char **target_path,
2531 struct cifs_sb_info *cifs_sb)
2533 if (plen < sizeof(struct reparse_data_buffer)) {
2534 cifs_dbg(VFS, "reparse buffer is too small. Must be "
2535 "at least 8 bytes but was %d\n", plen);
2539 if (plen < le16_to_cpu(buf->ReparseDataLength) +
2540 sizeof(struct reparse_data_buffer)) {
2541 cifs_dbg(VFS, "srv returned invalid reparse buf "
2542 "length: %d\n", plen);
2546 /* See MS-FSCC 2.1.2 */
2547 switch (le32_to_cpu(buf->ReparseTag)) {
2548 case IO_REPARSE_TAG_NFS:
2549 return parse_reparse_posix(
2550 (struct reparse_posix_data *)buf,
2551 plen, target_path, cifs_sb);
2552 case IO_REPARSE_TAG_SYMLINK:
2553 return parse_reparse_symlink(
2554 (struct reparse_symlink_data_buffer *)buf,
2555 plen, target_path, cifs_sb);
2557 cifs_dbg(VFS, "srv returned unknown symlink buffer "
2558 "tag:0x%08x\n", le32_to_cpu(buf->ReparseTag));
2563 #define SMB2_SYMLINK_STRUCT_SIZE \
2564 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
2567 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
2568 struct cifs_sb_info *cifs_sb, const char *full_path,
2569 char **target_path, bool is_reparse_point)
2572 __le16 *utf16_path = NULL;
2573 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2574 struct cifs_open_parms oparms;
2575 struct cifs_fid fid;
2576 struct kvec err_iov = {NULL, 0};
2577 struct smb2_err_rsp *err_buf = NULL;
2578 struct smb2_symlink_err_rsp *symlink;
2579 unsigned int sub_len;
2580 unsigned int sub_offset;
2581 unsigned int print_len;
2582 unsigned int print_offset;
2584 struct smb_rqst rqst[3];
2585 int resp_buftype[3];
2586 struct kvec rsp_iov[3];
2587 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2588 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2589 struct kvec close_iov[1];
2590 struct smb2_create_rsp *create_rsp;
2591 struct smb2_ioctl_rsp *ioctl_rsp;
2592 struct reparse_data_buffer *reparse_buf;
2595 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2597 *target_path = NULL;
2599 if (smb3_encryption_required(tcon))
2600 flags |= CIFS_TRANSFORM_REQ;
2602 memset(rqst, 0, sizeof(rqst));
2603 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2604 memset(rsp_iov, 0, sizeof(rsp_iov));
2606 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
2611 memset(&open_iov, 0, sizeof(open_iov));
2612 rqst[0].rq_iov = open_iov;
2613 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2615 memset(&oparms, 0, sizeof(oparms));
2617 oparms.desired_access = FILE_READ_ATTRIBUTES;
2618 oparms.disposition = FILE_OPEN;
2620 if (backup_cred(cifs_sb))
2621 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2623 oparms.create_options = 0;
2624 if (is_reparse_point)
2625 oparms.create_options = OPEN_REPARSE_POINT;
2628 oparms.reconnect = false;
2630 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, utf16_path);
2633 smb2_set_next_command(tcon, &rqst[0]);
2637 memset(&io_iov, 0, sizeof(io_iov));
2638 rqst[1].rq_iov = io_iov;
2639 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
2641 rc = SMB2_ioctl_init(tcon, &rqst[1], fid.persistent_fid,
2642 fid.volatile_fid, FSCTL_GET_REPARSE_POINT,
2643 true /* is_fctl */, NULL, 0, CIFSMaxBufSize);
2647 smb2_set_next_command(tcon, &rqst[1]);
2648 smb2_set_related(&rqst[1]);
2652 memset(&close_iov, 0, sizeof(close_iov));
2653 rqst[2].rq_iov = close_iov;
2654 rqst[2].rq_nvec = 1;
2656 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
2660 smb2_set_related(&rqst[2]);
2662 rc = compound_send_recv(xid, tcon->ses, flags, 3, rqst,
2663 resp_buftype, rsp_iov);
2665 create_rsp = rsp_iov[0].iov_base;
2666 if (create_rsp && create_rsp->sync_hdr.Status)
2667 err_iov = rsp_iov[0];
2668 ioctl_rsp = rsp_iov[1].iov_base;
2671 * Open was successful and we got an ioctl response.
2673 if ((rc == 0) && (is_reparse_point)) {
2674 /* See MS-FSCC 2.3.23 */
2676 reparse_buf = (struct reparse_data_buffer *)
2677 ((char *)ioctl_rsp +
2678 le32_to_cpu(ioctl_rsp->OutputOffset));
2679 plen = le32_to_cpu(ioctl_rsp->OutputCount);
2681 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
2682 rsp_iov[1].iov_len) {
2683 cifs_tcon_dbg(VFS, "srv returned invalid ioctl len: %d\n",
2689 rc = parse_reparse_point(reparse_buf, plen, target_path,
2694 if (!rc || !err_iov.iov_base) {
2699 err_buf = err_iov.iov_base;
2700 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
2701 err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) {
2706 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
2707 if (le32_to_cpu(symlink->SymLinkErrorTag) != SYMLINK_ERROR_TAG ||
2708 le32_to_cpu(symlink->ReparseTag) != IO_REPARSE_TAG_SYMLINK) {
2713 /* open must fail on symlink - reset rc */
2715 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
2716 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
2717 print_len = le16_to_cpu(symlink->PrintNameLength);
2718 print_offset = le16_to_cpu(symlink->PrintNameOffset);
2720 if (err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
2725 if (err_iov.iov_len <
2726 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
2731 *target_path = cifs_strndup_from_utf16(
2732 (char *)symlink->PathBuffer + sub_offset,
2733 sub_len, true, cifs_sb->local_nls);
2734 if (!(*target_path)) {
2738 convert_delimiter(*target_path, '/');
2739 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2742 cifs_dbg(FYI, "query symlink rc %d\n", rc);
2744 SMB2_open_free(&rqst[0]);
2745 SMB2_ioctl_free(&rqst[1]);
2746 SMB2_close_free(&rqst[2]);
2747 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2748 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2749 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2753 static struct cifs_ntsd *
2754 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
2755 const struct cifs_fid *cifsfid, u32 *pacllen)
2757 struct cifs_ntsd *pntsd = NULL;
2759 int rc = -EOPNOTSUPP;
2760 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
2763 return ERR_CAST(tlink);
2766 cifs_dbg(FYI, "trying to get acl\n");
2768 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
2769 cifsfid->volatile_fid, (void **)&pntsd, pacllen);
2772 cifs_put_tlink(tlink);
2774 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
2781 static struct cifs_ntsd *
2782 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
2783 const char *path, u32 *pacllen)
2785 struct cifs_ntsd *pntsd = NULL;
2786 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2789 struct cifs_tcon *tcon;
2790 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
2791 struct cifs_fid fid;
2792 struct cifs_open_parms oparms;
2795 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
2797 return ERR_CAST(tlink);
2799 tcon = tlink_tcon(tlink);
2802 if (backup_cred(cifs_sb))
2803 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2805 oparms.create_options = 0;
2807 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2815 oparms.desired_access = READ_CONTROL;
2816 oparms.disposition = FILE_OPEN;
2818 oparms.reconnect = false;
2820 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
2823 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
2824 fid.volatile_fid, (void **)&pntsd, pacllen);
2825 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2828 cifs_put_tlink(tlink);
2831 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
2838 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
2839 struct inode *inode, const char *path, int aclflag)
2841 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2843 int rc, access_flags = 0;
2844 struct cifs_tcon *tcon;
2845 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2846 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
2847 struct cifs_fid fid;
2848 struct cifs_open_parms oparms;
2851 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
2853 return PTR_ERR(tlink);
2855 tcon = tlink_tcon(tlink);
2858 if (backup_cred(cifs_sb))
2859 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2861 oparms.create_options = 0;
2863 if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP)
2864 access_flags = WRITE_OWNER;
2866 access_flags = WRITE_DAC;
2868 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2876 oparms.desired_access = access_flags;
2877 oparms.disposition = FILE_OPEN;
2880 oparms.reconnect = false;
2882 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
2885 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
2886 fid.volatile_fid, pnntsd, acllen, aclflag);
2887 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2890 cifs_put_tlink(tlink);
2895 /* Retrieve an ACL from the server */
2896 static struct cifs_ntsd *
2897 get_smb2_acl(struct cifs_sb_info *cifs_sb,
2898 struct inode *inode, const char *path,
2901 struct cifs_ntsd *pntsd = NULL;
2902 struct cifsFileInfo *open_file = NULL;
2905 open_file = find_readable_file(CIFS_I(inode), true);
2907 return get_smb2_acl_by_path(cifs_sb, path, pacllen);
2909 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen);
2910 cifsFileInfo_put(open_file);
2914 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
2915 loff_t offset, loff_t len, bool keep_size)
2917 struct cifs_ses *ses = tcon->ses;
2918 struct inode *inode;
2919 struct cifsInodeInfo *cifsi;
2920 struct cifsFileInfo *cfile = file->private_data;
2921 struct file_zero_data_information fsctl_buf;
2928 inode = d_inode(cfile->dentry);
2929 cifsi = CIFS_I(inode);
2931 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
2932 ses->Suid, offset, len);
2935 /* if file not oplocked can't be sure whether asking to extend size */
2936 if (!CIFS_CACHE_READ(cifsi))
2937 if (keep_size == false) {
2939 trace_smb3_zero_err(xid, cfile->fid.persistent_fid,
2940 tcon->tid, ses->Suid, offset, len, rc);
2945 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
2947 fsctl_buf.FileOffset = cpu_to_le64(offset);
2948 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
2950 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2951 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, true,
2953 sizeof(struct file_zero_data_information),
2956 goto zero_range_exit;
2959 * do we also need to change the size of the file?
2961 if (keep_size == false && i_size_read(inode) < offset + len) {
2962 eof = cpu_to_le64(offset + len);
2963 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
2964 cfile->fid.volatile_fid, cfile->pid, &eof);
2970 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
2971 ses->Suid, offset, len, rc);
2973 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
2974 ses->Suid, offset, len);
2978 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
2979 loff_t offset, loff_t len)
2981 struct inode *inode;
2982 struct cifsFileInfo *cfile = file->private_data;
2983 struct file_zero_data_information fsctl_buf;
2986 __u8 set_sparse = 1;
2990 inode = d_inode(cfile->dentry);
2992 /* Need to make file sparse, if not already, before freeing range. */
2993 /* Consider adding equivalent for compressed since it could also work */
2994 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
3000 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3002 fsctl_buf.FileOffset = cpu_to_le64(offset);
3003 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3005 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3006 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3007 true /* is_fctl */, (char *)&fsctl_buf,
3008 sizeof(struct file_zero_data_information),
3009 CIFSMaxBufSize, NULL, NULL);
3014 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3015 loff_t off, loff_t len, bool keep_size)
3017 struct inode *inode;
3018 struct cifsInodeInfo *cifsi;
3019 struct cifsFileInfo *cfile = file->private_data;
3020 long rc = -EOPNOTSUPP;
3026 inode = d_inode(cfile->dentry);
3027 cifsi = CIFS_I(inode);
3029 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3030 tcon->ses->Suid, off, len);
3031 /* if file not oplocked can't be sure whether asking to extend size */
3032 if (!CIFS_CACHE_READ(cifsi))
3033 if (keep_size == false) {
3034 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3035 tcon->tid, tcon->ses->Suid, off, len, rc);
3041 * Files are non-sparse by default so falloc may be a no-op
3042 * Must check if file sparse. If not sparse, and not extending
3043 * then no need to do anything since file already allocated
3045 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
3046 if (keep_size == true)
3048 /* check if extending file */
3049 else if (i_size_read(inode) >= off + len)
3050 /* not extending file and already not sparse */
3052 /* BB: in future add else clause to extend file */
3056 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3057 tcon->tid, tcon->ses->Suid, off, len, rc);
3059 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid,
3060 tcon->tid, tcon->ses->Suid, off, len);
3065 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3067 * Check if falloc starts within first few pages of file
3068 * and ends within a few pages of the end of file to
3069 * ensure that most of file is being forced to be
3070 * fallocated now. If so then setting whole file sparse
3071 * ie potentially making a few extra pages at the beginning
3072 * or end of the file non-sparse via set_sparse is harmless.
3074 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
3076 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3077 tcon->tid, tcon->ses->Suid, off, len, rc);
3082 smb2_set_sparse(xid, tcon, cfile, inode, false);
3085 smb2_set_sparse(xid, tcon, cfile, inode, false);
3087 if (i_size_read(inode) < off + len) {
3088 eof = cpu_to_le64(off + len);
3089 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3090 cfile->fid.volatile_fid, cfile->pid,
3096 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3097 tcon->ses->Suid, off, len, rc);
3099 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3100 tcon->ses->Suid, off, len);
3106 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3108 struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3109 struct cifsInodeInfo *cifsi;
3110 struct inode *inode;
3112 struct file_allocated_range_buffer in_data, *out_data = NULL;
3116 if (whence != SEEK_HOLE && whence != SEEK_DATA)
3117 return generic_file_llseek(file, offset, whence);
3119 inode = d_inode(cfile->dentry);
3120 cifsi = CIFS_I(inode);
3122 if (offset < 0 || offset >= i_size_read(inode))
3127 * We need to be sure that all dirty pages are written as they
3128 * might fill holes on the server.
3129 * Note that we also MUST flush any written pages since at least
3130 * some servers (Windows2016) will not reflect recent writes in
3131 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3133 wrcfile = find_writable_file(cifsi, false);
3135 filemap_write_and_wait(inode->i_mapping);
3136 smb2_flush_file(xid, tcon, &wrcfile->fid);
3137 cifsFileInfo_put(wrcfile);
3140 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3141 if (whence == SEEK_HOLE)
3142 offset = i_size_read(inode);
3146 in_data.file_offset = cpu_to_le64(offset);
3147 in_data.length = cpu_to_le64(i_size_read(inode));
3149 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3150 cfile->fid.volatile_fid,
3151 FSCTL_QUERY_ALLOCATED_RANGES, true,
3152 (char *)&in_data, sizeof(in_data),
3153 sizeof(struct file_allocated_range_buffer),
3154 (char **)&out_data, &out_data_len);
3160 if (whence == SEEK_HOLE && out_data_len == 0)
3163 if (whence == SEEK_DATA && out_data_len == 0) {
3168 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3172 if (whence == SEEK_DATA) {
3173 offset = le64_to_cpu(out_data->file_offset);
3176 if (offset < le64_to_cpu(out_data->file_offset))
3179 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3185 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3190 static int smb3_fiemap(struct cifs_tcon *tcon,
3191 struct cifsFileInfo *cfile,
3192 struct fiemap_extent_info *fei, u64 start, u64 len)
3195 struct file_allocated_range_buffer in_data, *out_data;
3197 int i, num, rc, flags, last_blob;
3200 if (fiemap_check_flags(fei, FIEMAP_FLAG_SYNC))
3205 in_data.file_offset = cpu_to_le64(start);
3206 in_data.length = cpu_to_le64(len);
3208 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3209 cfile->fid.volatile_fid,
3210 FSCTL_QUERY_ALLOCATED_RANGES, true,
3211 (char *)&in_data, sizeof(in_data),
3212 1024 * sizeof(struct file_allocated_range_buffer),
3213 (char **)&out_data, &out_data_len);
3222 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3226 if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3231 num = out_data_len / sizeof(struct file_allocated_range_buffer);
3232 for (i = 0; i < num; i++) {
3234 if (i == num - 1 && last_blob)
3235 flags |= FIEMAP_EXTENT_LAST;
3237 rc = fiemap_fill_next_extent(fei,
3238 le64_to_cpu(out_data[i].file_offset),
3239 le64_to_cpu(out_data[i].file_offset),
3240 le64_to_cpu(out_data[i].length),
3251 next = le64_to_cpu(out_data[num - 1].file_offset) +
3252 le64_to_cpu(out_data[num - 1].length);
3253 len = len - (next - start);
3264 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
3265 loff_t off, loff_t len)
3267 /* KEEP_SIZE already checked for by do_fallocate */
3268 if (mode & FALLOC_FL_PUNCH_HOLE)
3269 return smb3_punch_hole(file, tcon, off, len);
3270 else if (mode & FALLOC_FL_ZERO_RANGE) {
3271 if (mode & FALLOC_FL_KEEP_SIZE)
3272 return smb3_zero_range(file, tcon, off, len, true);
3273 return smb3_zero_range(file, tcon, off, len, false);
3274 } else if (mode == FALLOC_FL_KEEP_SIZE)
3275 return smb3_simple_falloc(file, tcon, off, len, true);
3277 return smb3_simple_falloc(file, tcon, off, len, false);
3283 smb2_downgrade_oplock(struct TCP_Server_Info *server,
3284 struct cifsInodeInfo *cinode, bool set_level2)
3287 server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
3290 server->ops->set_oplock_level(cinode, 0, 0, NULL);
3294 smb21_downgrade_oplock(struct TCP_Server_Info *server,
3295 struct cifsInodeInfo *cinode, bool set_level2)
3297 server->ops->set_oplock_level(cinode,
3298 set_level2 ? SMB2_LEASE_READ_CACHING_HE :
3303 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3304 unsigned int epoch, bool *purge_cache)
3307 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3309 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
3310 cinode->oplock = CIFS_CACHE_RHW_FLG;
3311 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
3312 &cinode->vfs_inode);
3313 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
3314 cinode->oplock = CIFS_CACHE_RW_FLG;
3315 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
3316 &cinode->vfs_inode);
3317 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
3318 cinode->oplock = CIFS_CACHE_READ_FLG;
3319 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
3320 &cinode->vfs_inode);
3326 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3327 unsigned int epoch, bool *purge_cache)
3329 char message[5] = {0};
3330 unsigned int new_oplock = 0;
3333 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3336 /* Check if the server granted an oplock rather than a lease */
3337 if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE)
3338 return smb2_set_oplock_level(cinode, oplock, epoch,
3341 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
3342 new_oplock |= CIFS_CACHE_READ_FLG;
3343 strcat(message, "R");
3345 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
3346 new_oplock |= CIFS_CACHE_HANDLE_FLG;
3347 strcat(message, "H");
3349 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
3350 new_oplock |= CIFS_CACHE_WRITE_FLG;
3351 strcat(message, "W");
3354 strncpy(message, "None", sizeof(message));
3356 cinode->oplock = new_oplock;
3357 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
3358 &cinode->vfs_inode);
3362 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3363 unsigned int epoch, bool *purge_cache)
3365 unsigned int old_oplock = cinode->oplock;
3367 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
3370 *purge_cache = false;
3371 if (old_oplock == CIFS_CACHE_READ_FLG) {
3372 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
3373 (epoch - cinode->epoch > 0))
3374 *purge_cache = true;
3375 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
3376 (epoch - cinode->epoch > 1))
3377 *purge_cache = true;
3378 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
3379 (epoch - cinode->epoch > 1))
3380 *purge_cache = true;
3381 else if (cinode->oplock == 0 &&
3382 (epoch - cinode->epoch > 0))
3383 *purge_cache = true;
3384 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
3385 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
3386 (epoch - cinode->epoch > 0))
3387 *purge_cache = true;
3388 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
3389 (epoch - cinode->epoch > 1))
3390 *purge_cache = true;
3392 cinode->epoch = epoch;
3397 smb2_is_read_op(__u32 oplock)
3399 return oplock == SMB2_OPLOCK_LEVEL_II;
3403 smb21_is_read_op(__u32 oplock)
3405 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
3406 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
3410 map_oplock_to_lease(u8 oplock)
3412 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
3413 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
3414 else if (oplock == SMB2_OPLOCK_LEVEL_II)
3415 return SMB2_LEASE_READ_CACHING;
3416 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
3417 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
3418 SMB2_LEASE_WRITE_CACHING;
3423 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
3425 struct create_lease *buf;
3427 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
3431 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
3432 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
3434 buf->ccontext.DataOffset = cpu_to_le16(offsetof
3435 (struct create_lease, lcontext));
3436 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
3437 buf->ccontext.NameOffset = cpu_to_le16(offsetof
3438 (struct create_lease, Name));
3439 buf->ccontext.NameLength = cpu_to_le16(4);
3440 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
3449 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
3451 struct create_lease_v2 *buf;
3453 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
3457 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
3458 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
3460 buf->ccontext.DataOffset = cpu_to_le16(offsetof
3461 (struct create_lease_v2, lcontext));
3462 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
3463 buf->ccontext.NameOffset = cpu_to_le16(offsetof
3464 (struct create_lease_v2, Name));
3465 buf->ccontext.NameLength = cpu_to_le16(4);
3466 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
3475 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
3477 struct create_lease *lc = (struct create_lease *)buf;
3479 *epoch = 0; /* not used */
3480 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
3481 return SMB2_OPLOCK_LEVEL_NOCHANGE;
3482 return le32_to_cpu(lc->lcontext.LeaseState);
3486 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
3488 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
3490 *epoch = le16_to_cpu(lc->lcontext.Epoch);
3491 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
3492 return SMB2_OPLOCK_LEVEL_NOCHANGE;
3494 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
3495 return le32_to_cpu(lc->lcontext.LeaseState);
3499 smb2_wp_retry_size(struct inode *inode)
3501 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
3502 SMB2_MAX_BUFFER_SIZE);
3506 smb2_dir_needs_close(struct cifsFileInfo *cfile)
3508 return !cfile->invalidHandle;
3512 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
3513 struct smb_rqst *old_rq, __le16 cipher_type)
3515 struct smb2_sync_hdr *shdr =
3516 (struct smb2_sync_hdr *)old_rq->rq_iov[0].iov_base;
3518 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
3519 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
3520 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
3521 tr_hdr->Flags = cpu_to_le16(0x01);
3522 if (cipher_type == SMB2_ENCRYPTION_AES128_GCM)
3523 get_random_bytes(&tr_hdr->Nonce, SMB3_AES128GCM_NONCE);
3525 get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CCM_NONCE);
3526 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
3529 /* We can not use the normal sg_set_buf() as we will sometimes pass a
3530 * stack object as buf.
3532 static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
3533 unsigned int buflen)
3537 * VMAP_STACK (at least) puts stack into the vmalloc address space
3539 if (is_vmalloc_addr(buf))
3540 addr = vmalloc_to_page(buf);
3542 addr = virt_to_page(buf);
3543 sg_set_page(sg, addr, buflen, offset_in_page(buf));
3546 /* Assumes the first rqst has a transform header as the first iov.
3548 * rqst[0].rq_iov[0] is transform header
3549 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
3550 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
3552 static struct scatterlist *
3553 init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign)
3555 unsigned int sg_len;
3556 struct scatterlist *sg;
3559 unsigned int idx = 0;
3563 for (i = 0; i < num_rqst; i++)
3564 sg_len += rqst[i].rq_nvec + rqst[i].rq_npages;
3566 sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
3570 sg_init_table(sg, sg_len);
3571 for (i = 0; i < num_rqst; i++) {
3572 for (j = 0; j < rqst[i].rq_nvec; j++) {
3574 * The first rqst has a transform header where the
3575 * first 20 bytes are not part of the encrypted blob
3577 skip = (i == 0) && (j == 0) ? 20 : 0;
3578 smb2_sg_set_buf(&sg[idx++],
3579 rqst[i].rq_iov[j].iov_base + skip,
3580 rqst[i].rq_iov[j].iov_len - skip);
3583 for (j = 0; j < rqst[i].rq_npages; j++) {
3584 unsigned int len, offset;
3586 rqst_page_get_length(&rqst[i], j, &len, &offset);
3587 sg_set_page(&sg[idx++], rqst[i].rq_pages[j], len, offset);
3590 smb2_sg_set_buf(&sg[idx], sign, SMB2_SIGNATURE_SIZE);
3595 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
3597 struct cifs_ses *ses;
3600 spin_lock(&cifs_tcp_ses_lock);
3601 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
3602 if (ses->Suid != ses_id)
3604 ses_enc_key = enc ? ses->smb3encryptionkey :
3605 ses->smb3decryptionkey;
3606 memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE);
3607 spin_unlock(&cifs_tcp_ses_lock);
3610 spin_unlock(&cifs_tcp_ses_lock);
3615 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
3616 * iov[0] - transform header (associate data),
3617 * iov[1-N] - SMB2 header and pages - data to encrypt.
3618 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
3622 crypt_message(struct TCP_Server_Info *server, int num_rqst,
3623 struct smb_rqst *rqst, int enc)
3625 struct smb2_transform_hdr *tr_hdr =
3626 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
3627 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
3629 struct scatterlist *sg;
3630 u8 sign[SMB2_SIGNATURE_SIZE] = {};
3631 u8 key[SMB3_SIGN_KEY_SIZE];
3632 struct aead_request *req;
3634 unsigned int iv_len;
3635 DECLARE_CRYPTO_WAIT(wait);
3636 struct crypto_aead *tfm;
3637 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
3639 rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key);
3641 cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
3646 rc = smb3_crypto_aead_allocate(server);
3648 cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
3652 tfm = enc ? server->secmech.ccmaesencrypt :
3653 server->secmech.ccmaesdecrypt;
3654 rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
3656 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
3660 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
3662 cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
3666 req = aead_request_alloc(tfm, GFP_KERNEL);
3668 cifs_server_dbg(VFS, "%s: Failed to alloc aead request\n", __func__);
3673 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
3674 crypt_len += SMB2_SIGNATURE_SIZE;
3677 sg = init_sg(num_rqst, rqst, sign);
3679 cifs_server_dbg(VFS, "%s: Failed to init sg\n", __func__);
3684 iv_len = crypto_aead_ivsize(tfm);
3685 iv = kzalloc(iv_len, GFP_KERNEL);
3687 cifs_server_dbg(VFS, "%s: Failed to alloc iv\n", __func__);
3692 if (server->cipher_type == SMB2_ENCRYPTION_AES128_GCM)
3693 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES128GCM_NONCE);
3696 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CCM_NONCE);
3699 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
3700 aead_request_set_ad(req, assoc_data_len);
3702 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
3703 crypto_req_done, &wait);
3705 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
3706 : crypto_aead_decrypt(req), &wait);
3709 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
3720 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
3724 for (i = 0; i < num_rqst; i++) {
3725 if (rqst[i].rq_pages) {
3726 for (j = rqst[i].rq_npages - 1; j >= 0; j--)
3727 put_page(rqst[i].rq_pages[j]);
3728 kfree(rqst[i].rq_pages);
3734 * This function will initialize new_rq and encrypt the content.
3735 * The first entry, new_rq[0], only contains a single iov which contains
3736 * a smb2_transform_hdr and is pre-allocated by the caller.
3737 * This function then populates new_rq[1+] with the content from olq_rq[0+].
3739 * The end result is an array of smb_rqst structures where the first structure
3740 * only contains a single iov for the transform header which we then can pass
3741 * to crypt_message().
3743 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
3744 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
3747 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
3748 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
3750 struct page **pages;
3751 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
3752 unsigned int npages;
3753 unsigned int orig_len = 0;
3757 for (i = 1; i < num_rqst; i++) {
3758 npages = old_rq[i - 1].rq_npages;
3759 pages = kmalloc_array(npages, sizeof(struct page *),
3764 new_rq[i].rq_pages = pages;
3765 new_rq[i].rq_npages = npages;
3766 new_rq[i].rq_offset = old_rq[i - 1].rq_offset;
3767 new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz;
3768 new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz;
3769 new_rq[i].rq_iov = old_rq[i - 1].rq_iov;
3770 new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec;
3772 orig_len += smb_rqst_len(server, &old_rq[i - 1]);
3774 for (j = 0; j < npages; j++) {
3775 pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
3780 /* copy pages form the old */
3781 for (j = 0; j < npages; j++) {
3783 unsigned int offset, len;
3785 rqst_page_get_length(&new_rq[i], j, &len, &offset);
3787 dst = (char *) kmap(new_rq[i].rq_pages[j]) + offset;
3788 src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset;
3790 memcpy(dst, src, len);
3791 kunmap(new_rq[i].rq_pages[j]);
3792 kunmap(old_rq[i - 1].rq_pages[j]);
3796 /* fill the 1st iov with a transform header */
3797 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
3799 rc = crypt_message(server, num_rqst, new_rq, 1);
3800 cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
3807 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
3812 smb3_is_transform_hdr(void *buf)
3814 struct smb2_transform_hdr *trhdr = buf;
3816 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
3820 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
3821 unsigned int buf_data_size, struct page **pages,
3822 unsigned int npages, unsigned int page_data_size)
3825 struct smb_rqst rqst = {NULL};
3828 iov[0].iov_base = buf;
3829 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
3830 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
3831 iov[1].iov_len = buf_data_size;
3835 rqst.rq_pages = pages;
3836 rqst.rq_npages = npages;
3837 rqst.rq_pagesz = PAGE_SIZE;
3838 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
3840 rc = crypt_message(server, 1, &rqst, 0);
3841 cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
3846 memmove(buf, iov[1].iov_base, buf_data_size);
3848 server->total_read = buf_data_size + page_data_size;
3854 read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
3855 unsigned int npages, unsigned int len)
3860 for (i = 0; i < npages; i++) {
3861 struct page *page = pages[i];
3865 if (len >= PAGE_SIZE) {
3866 /* enough data to fill the page */
3870 zero_user(page, len, PAGE_SIZE - len);
3873 length = cifs_read_page_from_socket(server, page, 0, n);
3876 server->total_read += length;
3883 init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
3884 unsigned int cur_off, struct bio_vec **page_vec)
3886 struct bio_vec *bvec;
3889 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
3893 for (i = 0; i < npages; i++) {
3894 bvec[i].bv_page = pages[i];
3895 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
3896 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
3897 data_size -= bvec[i].bv_len;
3900 if (data_size != 0) {
3901 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
3911 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
3912 char *buf, unsigned int buf_len, struct page **pages,
3913 unsigned int npages, unsigned int page_data_size)
3915 unsigned int data_offset;
3916 unsigned int data_len;
3917 unsigned int cur_off;
3918 unsigned int cur_page_idx;
3919 unsigned int pad_len;
3920 struct cifs_readdata *rdata = mid->callback_data;
3921 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
3922 struct bio_vec *bvec = NULL;
3923 struct iov_iter iter;
3926 bool use_rdma_mr = false;
3928 if (shdr->Command != SMB2_READ) {
3929 cifs_server_dbg(VFS, "only big read responses are supported\n");
3933 if (server->ops->is_session_expired &&
3934 server->ops->is_session_expired(buf)) {
3935 cifs_reconnect(server);
3936 wake_up(&server->response_q);
3940 if (server->ops->is_status_pending &&
3941 server->ops->is_status_pending(buf, server))
3944 /* set up first two iov to get credits */
3945 rdata->iov[0].iov_base = buf;
3946 rdata->iov[0].iov_len = 0;
3947 rdata->iov[1].iov_base = buf;
3948 rdata->iov[1].iov_len =
3949 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
3950 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
3951 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
3952 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
3953 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
3955 rdata->result = server->ops->map_error(buf, true);
3956 if (rdata->result != 0) {
3957 cifs_dbg(FYI, "%s: server returned error %d\n",
3958 __func__, rdata->result);
3959 /* normal error on read response */
3960 dequeue_mid(mid, false);
3964 data_offset = server->ops->read_data_offset(buf);
3965 #ifdef CONFIG_CIFS_SMB_DIRECT
3966 use_rdma_mr = rdata->mr;
3968 data_len = server->ops->read_data_length(buf, use_rdma_mr);
3970 if (data_offset < server->vals->read_rsp_size) {
3972 * win2k8 sometimes sends an offset of 0 when the read
3973 * is beyond the EOF. Treat it as if the data starts just after
3976 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
3977 __func__, data_offset);
3978 data_offset = server->vals->read_rsp_size;
3979 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
3980 /* data_offset is beyond the end of smallbuf */
3981 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
3982 __func__, data_offset);
3983 rdata->result = -EIO;
3984 dequeue_mid(mid, rdata->result);
3988 pad_len = data_offset - server->vals->read_rsp_size;
3990 if (buf_len <= data_offset) {
3991 /* read response payload is in pages */
3992 cur_page_idx = pad_len / PAGE_SIZE;
3993 cur_off = pad_len % PAGE_SIZE;
3995 if (cur_page_idx != 0) {
3996 /* data offset is beyond the 1st page of response */
3997 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
3998 __func__, data_offset);
3999 rdata->result = -EIO;
4000 dequeue_mid(mid, rdata->result);
4004 if (data_len > page_data_size - pad_len) {
4005 /* data_len is corrupt -- discard frame */
4006 rdata->result = -EIO;
4007 dequeue_mid(mid, rdata->result);
4011 rdata->result = init_read_bvec(pages, npages, page_data_size,
4013 if (rdata->result != 0) {
4014 dequeue_mid(mid, rdata->result);
4018 iov_iter_bvec(&iter, WRITE, bvec, npages, data_len);
4019 } else if (buf_len >= data_offset + data_len) {
4020 /* read response payload is in buf */
4021 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
4022 iov.iov_base = buf + data_offset;
4023 iov.iov_len = data_len;
4024 iov_iter_kvec(&iter, WRITE, &iov, 1, data_len);
4026 /* read response payload cannot be in both buf and pages */
4027 WARN_ONCE(1, "buf can not contain only a part of read data");
4028 rdata->result = -EIO;
4029 dequeue_mid(mid, rdata->result);
4033 length = rdata->copy_into_pages(server, rdata, &iter);
4040 dequeue_mid(mid, false);
4044 struct smb2_decrypt_work {
4045 struct work_struct decrypt;
4046 struct TCP_Server_Info *server;
4047 struct page **ppages;
4049 unsigned int npages;
4054 static void smb2_decrypt_offload(struct work_struct *work)
4056 struct smb2_decrypt_work *dw = container_of(work,
4057 struct smb2_decrypt_work, decrypt);
4059 struct mid_q_entry *mid;
4061 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
4062 dw->ppages, dw->npages, dw->len);
4064 cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
4068 dw->server->lstrp = jiffies;
4069 mid = smb2_find_mid(dw->server, dw->buf);
4071 cifs_dbg(FYI, "mid not found\n");
4073 mid->decrypted = true;
4074 rc = handle_read_data(dw->server, mid, dw->buf,
4075 dw->server->vals->read_rsp_size,
4076 dw->ppages, dw->npages, dw->len);
4078 cifs_mid_q_entry_release(mid);
4082 for (i = dw->npages-1; i >= 0; i--)
4083 put_page(dw->ppages[i]);
4086 cifs_small_buf_release(dw->buf);
4091 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
4094 char *buf = server->smallbuf;
4095 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4096 unsigned int npages;
4097 struct page **pages;
4099 unsigned int buflen = server->pdu_size;
4102 struct smb2_decrypt_work *dw;
4105 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
4106 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
4108 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
4111 server->total_read += rc;
4113 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
4114 server->vals->read_rsp_size;
4115 npages = DIV_ROUND_UP(len, PAGE_SIZE);
4117 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
4123 for (; i < npages; i++) {
4124 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4131 /* read read data into pages */
4132 rc = read_data_into_pages(server, pages, npages, len);
4136 rc = cifs_discard_remaining_data(server);
4141 * For large reads, offload to different thread for better performance,
4142 * use more cores decrypting which can be expensive
4145 if ((server->min_offload) && (server->in_flight > 1) &&
4146 (server->pdu_size >= server->min_offload)) {
4147 dw = kmalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL);
4149 goto non_offloaded_decrypt;
4151 dw->buf = server->smallbuf;
4152 server->smallbuf = (char *)cifs_small_buf_get();
4154 INIT_WORK(&dw->decrypt, smb2_decrypt_offload);
4156 dw->npages = npages;
4157 dw->server = server;
4160 queue_work(cifsiod_wq, &dw->decrypt);
4161 *num_mids = 0; /* worker thread takes care of finding mid */
4165 non_offloaded_decrypt:
4166 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
4167 pages, npages, len);
4171 *mid = smb2_find_mid(server, buf);
4173 cifs_dbg(FYI, "mid not found\n");
4175 cifs_dbg(FYI, "mid found\n");
4176 (*mid)->decrypted = true;
4177 rc = handle_read_data(server, *mid, buf,
4178 server->vals->read_rsp_size,
4179 pages, npages, len);
4183 for (i = i - 1; i >= 0; i--)
4188 cifs_discard_remaining_data(server);
4193 receive_encrypted_standard(struct TCP_Server_Info *server,
4194 struct mid_q_entry **mids, char **bufs,
4198 char *buf = server->smallbuf;
4199 struct smb2_sync_hdr *shdr;
4200 unsigned int pdu_length = server->pdu_size;
4201 unsigned int buf_size;
4202 struct mid_q_entry *mid_entry;
4204 char *next_buffer = NULL;
4208 /* switch to large buffer if too big for a small one */
4209 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
4210 server->large_buf = true;
4211 memcpy(server->bigbuf, buf, server->total_read);
4212 buf = server->bigbuf;
4215 /* now read the rest */
4216 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
4217 pdu_length - HEADER_SIZE(server) + 1);
4220 server->total_read += length;
4222 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
4223 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0);
4227 next_is_large = server->large_buf;
4229 shdr = (struct smb2_sync_hdr *)buf;
4230 if (shdr->NextCommand) {
4232 next_buffer = (char *)cifs_buf_get();
4234 next_buffer = (char *)cifs_small_buf_get();
4236 buf + le32_to_cpu(shdr->NextCommand),
4237 pdu_length - le32_to_cpu(shdr->NextCommand));
4240 mid_entry = smb2_find_mid(server, buf);
4241 if (mid_entry == NULL)
4242 cifs_dbg(FYI, "mid not found\n");
4244 cifs_dbg(FYI, "mid found\n");
4245 mid_entry->decrypted = true;
4246 mid_entry->resp_buf_size = server->pdu_size;
4249 if (*num_mids >= MAX_COMPOUND) {
4250 cifs_server_dbg(VFS, "too many PDUs in compound\n");
4253 bufs[*num_mids] = buf;
4254 mids[(*num_mids)++] = mid_entry;
4256 if (mid_entry && mid_entry->handle)
4257 ret = mid_entry->handle(server, mid_entry);
4259 ret = cifs_handle_standard(server, mid_entry);
4261 if (ret == 0 && shdr->NextCommand) {
4262 pdu_length -= le32_to_cpu(shdr->NextCommand);
4263 server->large_buf = next_is_large;
4265 server->bigbuf = buf = next_buffer;
4267 server->smallbuf = buf = next_buffer;
4269 } else if (ret != 0) {
4271 * ret != 0 here means that we didn't get to handle_mid() thus
4272 * server->smallbuf and server->bigbuf are still valid. We need
4273 * to free next_buffer because it is not going to be used
4277 free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer);
4279 free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer);
4286 smb3_receive_transform(struct TCP_Server_Info *server,
4287 struct mid_q_entry **mids, char **bufs, int *num_mids)
4289 char *buf = server->smallbuf;
4290 unsigned int pdu_length = server->pdu_size;
4291 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4292 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4294 if (pdu_length < sizeof(struct smb2_transform_hdr) +
4295 sizeof(struct smb2_sync_hdr)) {
4296 cifs_server_dbg(VFS, "Transform message is too small (%u)\n",
4298 cifs_reconnect(server);
4299 wake_up(&server->response_q);
4300 return -ECONNABORTED;
4303 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
4304 cifs_server_dbg(VFS, "Transform message is broken\n");
4305 cifs_reconnect(server);
4306 wake_up(&server->response_q);
4307 return -ECONNABORTED;
4310 /* TODO: add support for compounds containing READ. */
4311 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
4312 return receive_encrypted_read(server, &mids[0], num_mids);
4315 return receive_encrypted_standard(server, mids, bufs, num_mids);
4319 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
4321 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
4323 return handle_read_data(server, mid, buf, server->pdu_size,
4328 smb2_next_header(char *buf)
4330 struct smb2_sync_hdr *hdr = (struct smb2_sync_hdr *)buf;
4331 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
4333 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
4334 return sizeof(struct smb2_transform_hdr) +
4335 le32_to_cpu(t_hdr->OriginalMessageSize);
4337 return le32_to_cpu(hdr->NextCommand);
4341 smb2_make_node(unsigned int xid, struct inode *inode,
4342 struct dentry *dentry, struct cifs_tcon *tcon,
4343 char *full_path, umode_t mode, dev_t dev)
4345 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
4347 int create_options = CREATE_NOT_DIR | CREATE_OPTION_SPECIAL;
4348 FILE_ALL_INFO *buf = NULL;
4349 struct cifs_io_parms io_parms;
4351 struct cifs_fid fid;
4352 struct cifs_open_parms oparms;
4353 unsigned int bytes_written;
4354 struct win_dev *pdev;
4358 * Check if mounted with mount parm 'sfu' mount parm.
4359 * SFU emulation should work with all servers, but only
4360 * supports block and char device (no socket & fifo),
4361 * and was used by default in earlier versions of Windows
4363 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
4367 * TODO: Add ability to create instead via reparse point. Windows (e.g.
4368 * their current NFS server) uses this approach to expose special files
4369 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
4372 if (!S_ISCHR(mode) && !S_ISBLK(mode))
4375 cifs_dbg(FYI, "sfu compat create special file\n");
4377 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
4383 if (backup_cred(cifs_sb))
4384 create_options |= CREATE_OPEN_BACKUP_INTENT;
4387 oparms.cifs_sb = cifs_sb;
4388 oparms.desired_access = GENERIC_WRITE;
4389 oparms.create_options = create_options;
4390 oparms.disposition = FILE_CREATE;
4391 oparms.path = full_path;
4393 oparms.reconnect = false;
4395 if (tcon->ses->server->oplocks)
4396 oplock = REQ_OPLOCK;
4399 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf);
4404 * BB Do not bother to decode buf since no local inode yet to put
4405 * timestamps in, but we can reuse it safely.
4408 pdev = (struct win_dev *)buf;
4409 io_parms.pid = current->tgid;
4410 io_parms.tcon = tcon;
4411 io_parms.offset = 0;
4412 io_parms.length = sizeof(struct win_dev);
4413 iov[1].iov_base = buf;
4414 iov[1].iov_len = sizeof(struct win_dev);
4415 if (S_ISCHR(mode)) {
4416 memcpy(pdev->type, "IntxCHR", 8);
4417 pdev->major = cpu_to_le64(MAJOR(dev));
4418 pdev->minor = cpu_to_le64(MINOR(dev));
4419 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
4420 &bytes_written, iov, 1);
4421 } else if (S_ISBLK(mode)) {
4422 memcpy(pdev->type, "IntxBLK", 8);
4423 pdev->major = cpu_to_le64(MAJOR(dev));
4424 pdev->minor = cpu_to_le64(MINOR(dev));
4425 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
4426 &bytes_written, iov, 1);
4428 tcon->ses->server->ops->close(xid, tcon, &fid);
4431 /* FIXME: add code here to set EAs */
4438 struct smb_version_operations smb20_operations = {
4439 .compare_fids = smb2_compare_fids,
4440 .setup_request = smb2_setup_request,
4441 .setup_async_request = smb2_setup_async_request,
4442 .check_receive = smb2_check_receive,
4443 .add_credits = smb2_add_credits,
4444 .set_credits = smb2_set_credits,
4445 .get_credits_field = smb2_get_credits_field,
4446 .get_credits = smb2_get_credits,
4447 .wait_mtu_credits = cifs_wait_mtu_credits,
4448 .get_next_mid = smb2_get_next_mid,
4449 .revert_current_mid = smb2_revert_current_mid,
4450 .read_data_offset = smb2_read_data_offset,
4451 .read_data_length = smb2_read_data_length,
4452 .map_error = map_smb2_to_linux_error,
4453 .find_mid = smb2_find_mid,
4454 .check_message = smb2_check_message,
4455 .dump_detail = smb2_dump_detail,
4456 .clear_stats = smb2_clear_stats,
4457 .print_stats = smb2_print_stats,
4458 .is_oplock_break = smb2_is_valid_oplock_break,
4459 .handle_cancelled_mid = smb2_handle_cancelled_mid,
4460 .downgrade_oplock = smb2_downgrade_oplock,
4461 .need_neg = smb2_need_neg,
4462 .negotiate = smb2_negotiate,
4463 .negotiate_wsize = smb2_negotiate_wsize,
4464 .negotiate_rsize = smb2_negotiate_rsize,
4465 .sess_setup = SMB2_sess_setup,
4466 .logoff = SMB2_logoff,
4467 .tree_connect = SMB2_tcon,
4468 .tree_disconnect = SMB2_tdis,
4469 .qfs_tcon = smb2_qfs_tcon,
4470 .is_path_accessible = smb2_is_path_accessible,
4471 .can_echo = smb2_can_echo,
4473 .query_path_info = smb2_query_path_info,
4474 .get_srv_inum = smb2_get_srv_inum,
4475 .query_file_info = smb2_query_file_info,
4476 .set_path_size = smb2_set_path_size,
4477 .set_file_size = smb2_set_file_size,
4478 .set_file_info = smb2_set_file_info,
4479 .set_compression = smb2_set_compression,
4480 .mkdir = smb2_mkdir,
4481 .mkdir_setinfo = smb2_mkdir_setinfo,
4482 .rmdir = smb2_rmdir,
4483 .unlink = smb2_unlink,
4484 .rename = smb2_rename_path,
4485 .create_hardlink = smb2_create_hardlink,
4486 .query_symlink = smb2_query_symlink,
4487 .query_mf_symlink = smb3_query_mf_symlink,
4488 .create_mf_symlink = smb3_create_mf_symlink,
4489 .open = smb2_open_file,
4490 .set_fid = smb2_set_fid,
4491 .close = smb2_close_file,
4492 .flush = smb2_flush_file,
4493 .async_readv = smb2_async_readv,
4494 .async_writev = smb2_async_writev,
4495 .sync_read = smb2_sync_read,
4496 .sync_write = smb2_sync_write,
4497 .query_dir_first = smb2_query_dir_first,
4498 .query_dir_next = smb2_query_dir_next,
4499 .close_dir = smb2_close_dir,
4500 .calc_smb_size = smb2_calc_size,
4501 .is_status_pending = smb2_is_status_pending,
4502 .is_session_expired = smb2_is_session_expired,
4503 .oplock_response = smb2_oplock_response,
4504 .queryfs = smb2_queryfs,
4505 .mand_lock = smb2_mand_lock,
4506 .mand_unlock_range = smb2_unlock_range,
4507 .push_mand_locks = smb2_push_mandatory_locks,
4508 .get_lease_key = smb2_get_lease_key,
4509 .set_lease_key = smb2_set_lease_key,
4510 .new_lease_key = smb2_new_lease_key,
4511 .calc_signature = smb2_calc_signature,
4512 .is_read_op = smb2_is_read_op,
4513 .set_oplock_level = smb2_set_oplock_level,
4514 .create_lease_buf = smb2_create_lease_buf,
4515 .parse_lease_buf = smb2_parse_lease_buf,
4516 .copychunk_range = smb2_copychunk_range,
4517 .wp_retry_size = smb2_wp_retry_size,
4518 .dir_needs_close = smb2_dir_needs_close,
4519 .get_dfs_refer = smb2_get_dfs_refer,
4520 .select_sectype = smb2_select_sectype,
4521 #ifdef CONFIG_CIFS_XATTR
4522 .query_all_EAs = smb2_query_eas,
4523 .set_EA = smb2_set_ea,
4524 #endif /* CIFS_XATTR */
4525 .get_acl = get_smb2_acl,
4526 .get_acl_by_fid = get_smb2_acl_by_fid,
4527 .set_acl = set_smb2_acl,
4528 .next_header = smb2_next_header,
4529 .ioctl_query_info = smb2_ioctl_query_info,
4530 .make_node = smb2_make_node,
4531 .fiemap = smb3_fiemap,
4532 .llseek = smb3_llseek,
4535 struct smb_version_operations smb21_operations = {
4536 .compare_fids = smb2_compare_fids,
4537 .setup_request = smb2_setup_request,
4538 .setup_async_request = smb2_setup_async_request,
4539 .check_receive = smb2_check_receive,
4540 .add_credits = smb2_add_credits,
4541 .set_credits = smb2_set_credits,
4542 .get_credits_field = smb2_get_credits_field,
4543 .get_credits = smb2_get_credits,
4544 .wait_mtu_credits = smb2_wait_mtu_credits,
4545 .adjust_credits = smb2_adjust_credits,
4546 .get_next_mid = smb2_get_next_mid,
4547 .revert_current_mid = smb2_revert_current_mid,
4548 .read_data_offset = smb2_read_data_offset,
4549 .read_data_length = smb2_read_data_length,
4550 .map_error = map_smb2_to_linux_error,
4551 .find_mid = smb2_find_mid,
4552 .check_message = smb2_check_message,
4553 .dump_detail = smb2_dump_detail,
4554 .clear_stats = smb2_clear_stats,
4555 .print_stats = smb2_print_stats,
4556 .is_oplock_break = smb2_is_valid_oplock_break,
4557 .handle_cancelled_mid = smb2_handle_cancelled_mid,
4558 .downgrade_oplock = smb21_downgrade_oplock,
4559 .need_neg = smb2_need_neg,
4560 .negotiate = smb2_negotiate,
4561 .negotiate_wsize = smb2_negotiate_wsize,
4562 .negotiate_rsize = smb2_negotiate_rsize,
4563 .sess_setup = SMB2_sess_setup,
4564 .logoff = SMB2_logoff,
4565 .tree_connect = SMB2_tcon,
4566 .tree_disconnect = SMB2_tdis,
4567 .qfs_tcon = smb2_qfs_tcon,
4568 .is_path_accessible = smb2_is_path_accessible,
4569 .can_echo = smb2_can_echo,
4571 .query_path_info = smb2_query_path_info,
4572 .get_srv_inum = smb2_get_srv_inum,
4573 .query_file_info = smb2_query_file_info,
4574 .set_path_size = smb2_set_path_size,
4575 .set_file_size = smb2_set_file_size,
4576 .set_file_info = smb2_set_file_info,
4577 .set_compression = smb2_set_compression,
4578 .mkdir = smb2_mkdir,
4579 .mkdir_setinfo = smb2_mkdir_setinfo,
4580 .rmdir = smb2_rmdir,
4581 .unlink = smb2_unlink,
4582 .rename = smb2_rename_path,
4583 .create_hardlink = smb2_create_hardlink,
4584 .query_symlink = smb2_query_symlink,
4585 .query_mf_symlink = smb3_query_mf_symlink,
4586 .create_mf_symlink = smb3_create_mf_symlink,
4587 .open = smb2_open_file,
4588 .set_fid = smb2_set_fid,
4589 .close = smb2_close_file,
4590 .flush = smb2_flush_file,
4591 .async_readv = smb2_async_readv,
4592 .async_writev = smb2_async_writev,
4593 .sync_read = smb2_sync_read,
4594 .sync_write = smb2_sync_write,
4595 .query_dir_first = smb2_query_dir_first,
4596 .query_dir_next = smb2_query_dir_next,
4597 .close_dir = smb2_close_dir,
4598 .calc_smb_size = smb2_calc_size,
4599 .is_status_pending = smb2_is_status_pending,
4600 .is_session_expired = smb2_is_session_expired,
4601 .oplock_response = smb2_oplock_response,
4602 .queryfs = smb2_queryfs,
4603 .mand_lock = smb2_mand_lock,
4604 .mand_unlock_range = smb2_unlock_range,
4605 .push_mand_locks = smb2_push_mandatory_locks,
4606 .get_lease_key = smb2_get_lease_key,
4607 .set_lease_key = smb2_set_lease_key,
4608 .new_lease_key = smb2_new_lease_key,
4609 .calc_signature = smb2_calc_signature,
4610 .is_read_op = smb21_is_read_op,
4611 .set_oplock_level = smb21_set_oplock_level,
4612 .create_lease_buf = smb2_create_lease_buf,
4613 .parse_lease_buf = smb2_parse_lease_buf,
4614 .copychunk_range = smb2_copychunk_range,
4615 .wp_retry_size = smb2_wp_retry_size,
4616 .dir_needs_close = smb2_dir_needs_close,
4617 .enum_snapshots = smb3_enum_snapshots,
4618 .get_dfs_refer = smb2_get_dfs_refer,
4619 .select_sectype = smb2_select_sectype,
4620 #ifdef CONFIG_CIFS_XATTR
4621 .query_all_EAs = smb2_query_eas,
4622 .set_EA = smb2_set_ea,
4623 #endif /* CIFS_XATTR */
4624 .get_acl = get_smb2_acl,
4625 .get_acl_by_fid = get_smb2_acl_by_fid,
4626 .set_acl = set_smb2_acl,
4627 .next_header = smb2_next_header,
4628 .ioctl_query_info = smb2_ioctl_query_info,
4629 .make_node = smb2_make_node,
4630 .fiemap = smb3_fiemap,
4631 .llseek = smb3_llseek,
4634 struct smb_version_operations smb30_operations = {
4635 .compare_fids = smb2_compare_fids,
4636 .setup_request = smb2_setup_request,
4637 .setup_async_request = smb2_setup_async_request,
4638 .check_receive = smb2_check_receive,
4639 .add_credits = smb2_add_credits,
4640 .set_credits = smb2_set_credits,
4641 .get_credits_field = smb2_get_credits_field,
4642 .get_credits = smb2_get_credits,
4643 .wait_mtu_credits = smb2_wait_mtu_credits,
4644 .adjust_credits = smb2_adjust_credits,
4645 .get_next_mid = smb2_get_next_mid,
4646 .revert_current_mid = smb2_revert_current_mid,
4647 .read_data_offset = smb2_read_data_offset,
4648 .read_data_length = smb2_read_data_length,
4649 .map_error = map_smb2_to_linux_error,
4650 .find_mid = smb2_find_mid,
4651 .check_message = smb2_check_message,
4652 .dump_detail = smb2_dump_detail,
4653 .clear_stats = smb2_clear_stats,
4654 .print_stats = smb2_print_stats,
4655 .dump_share_caps = smb2_dump_share_caps,
4656 .is_oplock_break = smb2_is_valid_oplock_break,
4657 .handle_cancelled_mid = smb2_handle_cancelled_mid,
4658 .downgrade_oplock = smb21_downgrade_oplock,
4659 .need_neg = smb2_need_neg,
4660 .negotiate = smb2_negotiate,
4661 .negotiate_wsize = smb3_negotiate_wsize,
4662 .negotiate_rsize = smb3_negotiate_rsize,
4663 .sess_setup = SMB2_sess_setup,
4664 .logoff = SMB2_logoff,
4665 .tree_connect = SMB2_tcon,
4666 .tree_disconnect = SMB2_tdis,
4667 .qfs_tcon = smb3_qfs_tcon,
4668 .is_path_accessible = smb2_is_path_accessible,
4669 .can_echo = smb2_can_echo,
4671 .query_path_info = smb2_query_path_info,
4672 .get_srv_inum = smb2_get_srv_inum,
4673 .query_file_info = smb2_query_file_info,
4674 .set_path_size = smb2_set_path_size,
4675 .set_file_size = smb2_set_file_size,
4676 .set_file_info = smb2_set_file_info,
4677 .set_compression = smb2_set_compression,
4678 .mkdir = smb2_mkdir,
4679 .mkdir_setinfo = smb2_mkdir_setinfo,
4680 .rmdir = smb2_rmdir,
4681 .unlink = smb2_unlink,
4682 .rename = smb2_rename_path,
4683 .create_hardlink = smb2_create_hardlink,
4684 .query_symlink = smb2_query_symlink,
4685 .query_mf_symlink = smb3_query_mf_symlink,
4686 .create_mf_symlink = smb3_create_mf_symlink,
4687 .open = smb2_open_file,
4688 .set_fid = smb2_set_fid,
4689 .close = smb2_close_file,
4690 .flush = smb2_flush_file,
4691 .async_readv = smb2_async_readv,
4692 .async_writev = smb2_async_writev,
4693 .sync_read = smb2_sync_read,
4694 .sync_write = smb2_sync_write,
4695 .query_dir_first = smb2_query_dir_first,
4696 .query_dir_next = smb2_query_dir_next,
4697 .close_dir = smb2_close_dir,
4698 .calc_smb_size = smb2_calc_size,
4699 .is_status_pending = smb2_is_status_pending,
4700 .is_session_expired = smb2_is_session_expired,
4701 .oplock_response = smb2_oplock_response,
4702 .queryfs = smb2_queryfs,
4703 .mand_lock = smb2_mand_lock,
4704 .mand_unlock_range = smb2_unlock_range,
4705 .push_mand_locks = smb2_push_mandatory_locks,
4706 .get_lease_key = smb2_get_lease_key,
4707 .set_lease_key = smb2_set_lease_key,
4708 .new_lease_key = smb2_new_lease_key,
4709 .generate_signingkey = generate_smb30signingkey,
4710 .calc_signature = smb3_calc_signature,
4711 .set_integrity = smb3_set_integrity,
4712 .is_read_op = smb21_is_read_op,
4713 .set_oplock_level = smb3_set_oplock_level,
4714 .create_lease_buf = smb3_create_lease_buf,
4715 .parse_lease_buf = smb3_parse_lease_buf,
4716 .copychunk_range = smb2_copychunk_range,
4717 .duplicate_extents = smb2_duplicate_extents,
4718 .validate_negotiate = smb3_validate_negotiate,
4719 .wp_retry_size = smb2_wp_retry_size,
4720 .dir_needs_close = smb2_dir_needs_close,
4721 .fallocate = smb3_fallocate,
4722 .enum_snapshots = smb3_enum_snapshots,
4723 .init_transform_rq = smb3_init_transform_rq,
4724 .is_transform_hdr = smb3_is_transform_hdr,
4725 .receive_transform = smb3_receive_transform,
4726 .get_dfs_refer = smb2_get_dfs_refer,
4727 .select_sectype = smb2_select_sectype,
4728 #ifdef CONFIG_CIFS_XATTR
4729 .query_all_EAs = smb2_query_eas,
4730 .set_EA = smb2_set_ea,
4731 #endif /* CIFS_XATTR */
4732 .get_acl = get_smb2_acl,
4733 .get_acl_by_fid = get_smb2_acl_by_fid,
4734 .set_acl = set_smb2_acl,
4735 .next_header = smb2_next_header,
4736 .ioctl_query_info = smb2_ioctl_query_info,
4737 .make_node = smb2_make_node,
4738 .fiemap = smb3_fiemap,
4739 .llseek = smb3_llseek,
4742 struct smb_version_operations smb311_operations = {
4743 .compare_fids = smb2_compare_fids,
4744 .setup_request = smb2_setup_request,
4745 .setup_async_request = smb2_setup_async_request,
4746 .check_receive = smb2_check_receive,
4747 .add_credits = smb2_add_credits,
4748 .set_credits = smb2_set_credits,
4749 .get_credits_field = smb2_get_credits_field,
4750 .get_credits = smb2_get_credits,
4751 .wait_mtu_credits = smb2_wait_mtu_credits,
4752 .adjust_credits = smb2_adjust_credits,
4753 .get_next_mid = smb2_get_next_mid,
4754 .revert_current_mid = smb2_revert_current_mid,
4755 .read_data_offset = smb2_read_data_offset,
4756 .read_data_length = smb2_read_data_length,
4757 .map_error = map_smb2_to_linux_error,
4758 .find_mid = smb2_find_mid,
4759 .check_message = smb2_check_message,
4760 .dump_detail = smb2_dump_detail,
4761 .clear_stats = smb2_clear_stats,
4762 .print_stats = smb2_print_stats,
4763 .dump_share_caps = smb2_dump_share_caps,
4764 .is_oplock_break = smb2_is_valid_oplock_break,
4765 .handle_cancelled_mid = smb2_handle_cancelled_mid,
4766 .downgrade_oplock = smb21_downgrade_oplock,
4767 .need_neg = smb2_need_neg,
4768 .negotiate = smb2_negotiate,
4769 .negotiate_wsize = smb3_negotiate_wsize,
4770 .negotiate_rsize = smb3_negotiate_rsize,
4771 .sess_setup = SMB2_sess_setup,
4772 .logoff = SMB2_logoff,
4773 .tree_connect = SMB2_tcon,
4774 .tree_disconnect = SMB2_tdis,
4775 .qfs_tcon = smb3_qfs_tcon,
4776 .is_path_accessible = smb2_is_path_accessible,
4777 .can_echo = smb2_can_echo,
4779 .query_path_info = smb2_query_path_info,
4780 .get_srv_inum = smb2_get_srv_inum,
4781 .query_file_info = smb2_query_file_info,
4782 .set_path_size = smb2_set_path_size,
4783 .set_file_size = smb2_set_file_size,
4784 .set_file_info = smb2_set_file_info,
4785 .set_compression = smb2_set_compression,
4786 .mkdir = smb2_mkdir,
4787 .mkdir_setinfo = smb2_mkdir_setinfo,
4788 .posix_mkdir = smb311_posix_mkdir,
4789 .rmdir = smb2_rmdir,
4790 .unlink = smb2_unlink,
4791 .rename = smb2_rename_path,
4792 .create_hardlink = smb2_create_hardlink,
4793 .query_symlink = smb2_query_symlink,
4794 .query_mf_symlink = smb3_query_mf_symlink,
4795 .create_mf_symlink = smb3_create_mf_symlink,
4796 .open = smb2_open_file,
4797 .set_fid = smb2_set_fid,
4798 .close = smb2_close_file,
4799 .flush = smb2_flush_file,
4800 .async_readv = smb2_async_readv,
4801 .async_writev = smb2_async_writev,
4802 .sync_read = smb2_sync_read,
4803 .sync_write = smb2_sync_write,
4804 .query_dir_first = smb2_query_dir_first,
4805 .query_dir_next = smb2_query_dir_next,
4806 .close_dir = smb2_close_dir,
4807 .calc_smb_size = smb2_calc_size,
4808 .is_status_pending = smb2_is_status_pending,
4809 .is_session_expired = smb2_is_session_expired,
4810 .oplock_response = smb2_oplock_response,
4811 .queryfs = smb311_queryfs,
4812 .mand_lock = smb2_mand_lock,
4813 .mand_unlock_range = smb2_unlock_range,
4814 .push_mand_locks = smb2_push_mandatory_locks,
4815 .get_lease_key = smb2_get_lease_key,
4816 .set_lease_key = smb2_set_lease_key,
4817 .new_lease_key = smb2_new_lease_key,
4818 .generate_signingkey = generate_smb311signingkey,
4819 .calc_signature = smb3_calc_signature,
4820 .set_integrity = smb3_set_integrity,
4821 .is_read_op = smb21_is_read_op,
4822 .set_oplock_level = smb3_set_oplock_level,
4823 .create_lease_buf = smb3_create_lease_buf,
4824 .parse_lease_buf = smb3_parse_lease_buf,
4825 .copychunk_range = smb2_copychunk_range,
4826 .duplicate_extents = smb2_duplicate_extents,
4827 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
4828 .wp_retry_size = smb2_wp_retry_size,
4829 .dir_needs_close = smb2_dir_needs_close,
4830 .fallocate = smb3_fallocate,
4831 .enum_snapshots = smb3_enum_snapshots,
4832 .init_transform_rq = smb3_init_transform_rq,
4833 .is_transform_hdr = smb3_is_transform_hdr,
4834 .receive_transform = smb3_receive_transform,
4835 .get_dfs_refer = smb2_get_dfs_refer,
4836 .select_sectype = smb2_select_sectype,
4837 #ifdef CONFIG_CIFS_XATTR
4838 .query_all_EAs = smb2_query_eas,
4839 .set_EA = smb2_set_ea,
4840 #endif /* CIFS_XATTR */
4841 .get_acl = get_smb2_acl,
4842 .get_acl_by_fid = get_smb2_acl_by_fid,
4843 .set_acl = set_smb2_acl,
4844 .next_header = smb2_next_header,
4845 .ioctl_query_info = smb2_ioctl_query_info,
4846 .make_node = smb2_make_node,
4847 .fiemap = smb3_fiemap,
4848 .llseek = smb3_llseek,
4851 struct smb_version_values smb20_values = {
4852 .version_string = SMB20_VERSION_STRING,
4853 .protocol_id = SMB20_PROT_ID,
4854 .req_capabilities = 0, /* MBZ */
4855 .large_lock_type = 0,
4856 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4857 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4858 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4859 .header_size = sizeof(struct smb2_sync_hdr),
4860 .header_preamble_size = 0,
4861 .max_header_size = MAX_SMB2_HDR_SIZE,
4862 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4863 .lock_cmd = SMB2_LOCK,
4865 .cap_nt_find = SMB2_NT_FIND,
4866 .cap_large_files = SMB2_LARGE_FILES,
4867 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4868 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4869 .create_lease_size = sizeof(struct create_lease),
4872 struct smb_version_values smb21_values = {
4873 .version_string = SMB21_VERSION_STRING,
4874 .protocol_id = SMB21_PROT_ID,
4875 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
4876 .large_lock_type = 0,
4877 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4878 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4879 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4880 .header_size = sizeof(struct smb2_sync_hdr),
4881 .header_preamble_size = 0,
4882 .max_header_size = MAX_SMB2_HDR_SIZE,
4883 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4884 .lock_cmd = SMB2_LOCK,
4886 .cap_nt_find = SMB2_NT_FIND,
4887 .cap_large_files = SMB2_LARGE_FILES,
4888 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4889 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4890 .create_lease_size = sizeof(struct create_lease),
4893 struct smb_version_values smb3any_values = {
4894 .version_string = SMB3ANY_VERSION_STRING,
4895 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
4896 .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,
4897 .large_lock_type = 0,
4898 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4899 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4900 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4901 .header_size = sizeof(struct smb2_sync_hdr),
4902 .header_preamble_size = 0,
4903 .max_header_size = MAX_SMB2_HDR_SIZE,
4904 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4905 .lock_cmd = SMB2_LOCK,
4907 .cap_nt_find = SMB2_NT_FIND,
4908 .cap_large_files = SMB2_LARGE_FILES,
4909 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4910 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4911 .create_lease_size = sizeof(struct create_lease_v2),
4914 struct smb_version_values smbdefault_values = {
4915 .version_string = SMBDEFAULT_VERSION_STRING,
4916 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
4917 .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,
4918 .large_lock_type = 0,
4919 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4920 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4921 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4922 .header_size = sizeof(struct smb2_sync_hdr),
4923 .header_preamble_size = 0,
4924 .max_header_size = MAX_SMB2_HDR_SIZE,
4925 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4926 .lock_cmd = SMB2_LOCK,
4928 .cap_nt_find = SMB2_NT_FIND,
4929 .cap_large_files = SMB2_LARGE_FILES,
4930 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4931 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4932 .create_lease_size = sizeof(struct create_lease_v2),
4935 struct smb_version_values smb30_values = {
4936 .version_string = SMB30_VERSION_STRING,
4937 .protocol_id = SMB30_PROT_ID,
4938 .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,
4939 .large_lock_type = 0,
4940 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4941 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4942 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4943 .header_size = sizeof(struct smb2_sync_hdr),
4944 .header_preamble_size = 0,
4945 .max_header_size = MAX_SMB2_HDR_SIZE,
4946 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4947 .lock_cmd = SMB2_LOCK,
4949 .cap_nt_find = SMB2_NT_FIND,
4950 .cap_large_files = SMB2_LARGE_FILES,
4951 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4952 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4953 .create_lease_size = sizeof(struct create_lease_v2),
4956 struct smb_version_values smb302_values = {
4957 .version_string = SMB302_VERSION_STRING,
4958 .protocol_id = SMB302_PROT_ID,
4959 .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,
4960 .large_lock_type = 0,
4961 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4962 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4963 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4964 .header_size = sizeof(struct smb2_sync_hdr),
4965 .header_preamble_size = 0,
4966 .max_header_size = MAX_SMB2_HDR_SIZE,
4967 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4968 .lock_cmd = SMB2_LOCK,
4970 .cap_nt_find = SMB2_NT_FIND,
4971 .cap_large_files = SMB2_LARGE_FILES,
4972 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4973 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4974 .create_lease_size = sizeof(struct create_lease_v2),
4977 struct smb_version_values smb311_values = {
4978 .version_string = SMB311_VERSION_STRING,
4979 .protocol_id = SMB311_PROT_ID,
4980 .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,
4981 .large_lock_type = 0,
4982 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4983 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4984 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4985 .header_size = sizeof(struct smb2_sync_hdr),
4986 .header_preamble_size = 0,
4987 .max_header_size = MAX_SMB2_HDR_SIZE,
4988 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4989 .lock_cmd = SMB2_LOCK,
4991 .cap_nt_find = SMB2_NT_FIND,
4992 .cap_large_files = SMB2_LARGE_FILES,
4993 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4994 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4995 .create_lease_size = sizeof(struct create_lease_v2),