1 // SPDX-License-Identifier: GPL-2.0
3 * SMB2 version specific operations
5 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
8 #include <linux/pagemap.h>
10 #include <linux/falloc.h>
11 #include <linux/scatterlist.h>
12 #include <linux/uuid.h>
13 #include <linux/sort.h>
14 #include <crypto/aead.h>
15 #include <linux/fiemap.h>
19 #include "smb2proto.h"
20 #include "cifsproto.h"
21 #include "cifs_debug.h"
22 #include "cifs_unicode.h"
23 #include "smb2status.h"
25 #include "cifs_ioctl.h"
26 #include "smbdirect.h"
28 /* Change credits for different ops and return the total number of credits */
30 change_conf(struct TCP_Server_Info *server)
32 server->credits += server->echo_credits + server->oplock_credits;
33 server->oplock_credits = server->echo_credits = 0;
34 switch (server->credits) {
38 server->echoes = false;
39 server->oplocks = false;
42 server->echoes = true;
43 server->oplocks = false;
44 server->echo_credits = 1;
47 server->echoes = true;
49 server->oplocks = true;
50 server->oplock_credits = 1;
52 server->oplocks = false;
54 server->echo_credits = 1;
56 server->credits -= server->echo_credits + server->oplock_credits;
57 return server->credits + server->echo_credits + server->oplock_credits;
61 smb2_add_credits(struct TCP_Server_Info *server,
62 const struct cifs_credits *credits, const int optype)
65 unsigned int add = credits->value;
66 unsigned int instance = credits->instance;
67 bool reconnect_detected = false;
69 spin_lock(&server->req_lock);
70 val = server->ops->get_credits_field(server, optype);
72 /* eg found case where write overlapping reconnect messed up credits */
73 if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0))
74 trace_smb3_reconnect_with_invalid_credits(server->CurrentMid,
75 server->hostname, *val, add);
76 if ((instance == 0) || (instance == server->reconnect_instance))
79 reconnect_detected = true;
82 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
83 pr_warn_once("server overflowed SMB3 credits\n");
85 WARN_ON_ONCE(server->in_flight == 0);
87 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
88 rc = change_conf(server);
90 * Sometimes server returns 0 credits on oplock break ack - we need to
91 * rebalance credits in this case.
93 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
95 if (server->credits > 1) {
97 server->oplock_credits++;
100 spin_unlock(&server->req_lock);
101 wake_up(&server->request_q);
103 if (reconnect_detected)
104 cifs_dbg(FYI, "trying to put %d credits from the old server instance %d\n",
107 if (server->tcpStatus == CifsNeedReconnect
108 || server->tcpStatus == CifsExiting)
113 /* change_conf hasn't been executed */
116 cifs_server_dbg(VFS, "Possible client or server bug - zero credits\n");
119 cifs_server_dbg(VFS, "disabling echoes and oplocks\n");
122 cifs_dbg(FYI, "disabling oplocks\n");
125 trace_smb3_add_credits(server->CurrentMid,
126 server->hostname, rc, add);
127 cifs_dbg(FYI, "add %u credits total=%d\n", add, rc);
132 smb2_set_credits(struct TCP_Server_Info *server, const int val)
134 spin_lock(&server->req_lock);
135 server->credits = val;
137 server->reconnect_instance++;
138 spin_unlock(&server->req_lock);
139 /* don't log while holding the lock */
141 cifs_dbg(FYI, "set credits to 1 due to smb2 reconnect\n");
145 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
149 return &server->echo_credits;
151 return &server->oplock_credits;
153 return &server->credits;
158 smb2_get_credits(struct mid_q_entry *mid)
160 return mid->credits_received;
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, bool dequeue)
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);
286 list_del_init(&mid->qhead);
287 mid->mid_flags |= MID_DELETED;
289 spin_unlock(&GlobalMid_Lock);
293 spin_unlock(&GlobalMid_Lock);
297 static struct mid_q_entry *
298 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
300 return __smb2_find_mid(server, buf, false);
303 static struct mid_q_entry *
304 smb2_find_dequeue_mid(struct TCP_Server_Info *server, char *buf)
306 return __smb2_find_mid(server, buf, true);
310 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
312 #ifdef CONFIG_CIFS_DEBUG2
313 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
315 cifs_server_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
316 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
318 cifs_server_dbg(VFS, "smb buf %p len %u\n", buf,
319 server->ops->calc_smb_size(buf, server));
324 smb2_need_neg(struct TCP_Server_Info *server)
326 return server->max_read == 0;
330 smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
334 cifs_ses_server(ses)->CurrentMid = 0;
335 rc = SMB2_negotiate(xid, ses);
336 /* BB we probably don't need to retry with modern servers */
343 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
345 struct TCP_Server_Info *server = tcon->ses->server;
348 /* start with specified wsize, or default */
349 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
350 wsize = min_t(unsigned int, wsize, server->max_write);
351 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
352 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
358 smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
360 struct TCP_Server_Info *server = tcon->ses->server;
363 /* start with specified wsize, or default */
364 wsize = volume_info->wsize ? volume_info->wsize : SMB3_DEFAULT_IOSIZE;
365 wsize = min_t(unsigned int, wsize, server->max_write);
366 #ifdef CONFIG_CIFS_SMB_DIRECT
370 * Account for SMB2 data transfer packet header and
371 * possible encryption header
373 wsize = min_t(unsigned int,
375 server->smbd_conn->max_fragmented_send_size -
376 SMB2_READWRITE_PDU_HEADER_SIZE -
377 sizeof(struct smb2_transform_hdr));
379 wsize = min_t(unsigned int,
380 wsize, server->smbd_conn->max_readwrite_size);
383 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
384 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
390 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
392 struct TCP_Server_Info *server = tcon->ses->server;
395 /* start with specified rsize, or default */
396 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
397 rsize = min_t(unsigned int, rsize, server->max_read);
399 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
400 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
406 smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
408 struct TCP_Server_Info *server = tcon->ses->server;
411 /* start with specified rsize, or default */
412 rsize = volume_info->rsize ? volume_info->rsize : SMB3_DEFAULT_IOSIZE;
413 rsize = min_t(unsigned int, rsize, server->max_read);
414 #ifdef CONFIG_CIFS_SMB_DIRECT
418 * Account for SMB2 data transfer packet header and
419 * possible encryption header
421 rsize = min_t(unsigned int,
423 server->smbd_conn->max_fragmented_recv_size -
424 SMB2_READWRITE_PDU_HEADER_SIZE -
425 sizeof(struct smb2_transform_hdr));
427 rsize = min_t(unsigned int,
428 rsize, server->smbd_conn->max_readwrite_size);
432 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
433 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
439 parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
441 struct cifs_server_iface **iface_list,
444 struct network_interface_info_ioctl_rsp *p;
445 struct sockaddr_in *addr4;
446 struct sockaddr_in6 *addr6;
447 struct iface_info_ipv4 *p4;
448 struct iface_info_ipv6 *p6;
449 struct cifs_server_iface *info;
459 * Fist pass: count and sanity check
462 bytes_left = buf_len;
464 while (bytes_left >= sizeof(*p)) {
466 next = le32_to_cpu(p->Next);
468 bytes_left -= sizeof(*p);
471 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
476 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
481 /* Azure rounds the buffer size up 8, to a 16 byte boundary */
482 if ((bytes_left > 8) || p->Next)
483 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
487 * Second pass: extract info to internal structure
490 *iface_list = kcalloc(nb_iface, sizeof(**iface_list), GFP_KERNEL);
497 bytes_left = buf_len;
499 while (bytes_left >= sizeof(*p)) {
500 info->speed = le64_to_cpu(p->LinkSpeed);
501 info->rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE) ? 1 : 0;
502 info->rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE) ? 1 : 0;
504 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, *iface_count);
505 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
506 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
507 le32_to_cpu(p->Capability));
511 * The kernel and wire socket structures have the same
512 * layout and use network byte order but make the
513 * conversion explicit in case either one changes.
516 addr4 = (struct sockaddr_in *)&info->sockaddr;
517 p4 = (struct iface_info_ipv4 *)p->Buffer;
518 addr4->sin_family = AF_INET;
519 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
521 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
522 addr4->sin_port = cpu_to_be16(CIFS_PORT);
524 cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
528 addr6 = (struct sockaddr_in6 *)&info->sockaddr;
529 p6 = (struct iface_info_ipv6 *)p->Buffer;
530 addr6->sin6_family = AF_INET6;
531 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
533 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
534 addr6->sin6_flowinfo = 0;
535 addr6->sin6_scope_id = 0;
536 addr6->sin6_port = cpu_to_be16(CIFS_PORT);
538 cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
543 "%s: skipping unsupported socket family\n",
551 next = le32_to_cpu(p->Next);
554 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
572 static int compare_iface(const void *ia, const void *ib)
574 const struct cifs_server_iface *a = (struct cifs_server_iface *)ia;
575 const struct cifs_server_iface *b = (struct cifs_server_iface *)ib;
577 return a->speed == b->speed ? 0 : (a->speed > b->speed ? -1 : 1);
581 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
584 unsigned int ret_data_len = 0;
585 struct network_interface_info_ioctl_rsp *out_buf = NULL;
586 struct cifs_server_iface *iface_list;
588 struct cifs_ses *ses = tcon->ses;
590 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
591 FSCTL_QUERY_NETWORK_INTERFACE_INFO,
592 NULL /* no data input */, 0 /* no data input */,
593 CIFSMaxBufSize, (char **)&out_buf, &ret_data_len);
594 if (rc == -EOPNOTSUPP) {
596 "server does not support query network interfaces\n");
598 } else if (rc != 0) {
599 cifs_tcon_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
603 rc = parse_server_interfaces(out_buf, ret_data_len,
604 &iface_list, &iface_count);
608 /* sort interfaces from fastest to slowest */
609 sort(iface_list, iface_count, sizeof(*iface_list), compare_iface, NULL);
611 spin_lock(&ses->iface_lock);
612 kfree(ses->iface_list);
613 ses->iface_list = iface_list;
614 ses->iface_count = iface_count;
615 ses->iface_last_update = jiffies;
616 spin_unlock(&ses->iface_lock);
624 smb2_close_cached_fid(struct kref *ref)
626 struct cached_fid *cfid = container_of(ref, struct cached_fid,
629 if (cfid->is_valid) {
630 cifs_dbg(FYI, "clear cached root file handle\n");
631 SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid,
632 cfid->fid->volatile_fid);
633 cfid->is_valid = false;
634 cfid->file_all_info_is_valid = false;
635 cfid->has_lease = false;
639 void close_shroot(struct cached_fid *cfid)
641 mutex_lock(&cfid->fid_mutex);
642 kref_put(&cfid->refcount, smb2_close_cached_fid);
643 mutex_unlock(&cfid->fid_mutex);
646 void close_shroot_lease_locked(struct cached_fid *cfid)
648 if (cfid->has_lease) {
649 cfid->has_lease = false;
650 kref_put(&cfid->refcount, smb2_close_cached_fid);
654 void close_shroot_lease(struct cached_fid *cfid)
656 mutex_lock(&cfid->fid_mutex);
657 close_shroot_lease_locked(cfid);
658 mutex_unlock(&cfid->fid_mutex);
662 smb2_cached_lease_break(struct work_struct *work)
664 struct cached_fid *cfid = container_of(work,
665 struct cached_fid, lease_break);
667 close_shroot_lease(cfid);
671 * Open the directory at the root of a share
673 int open_shroot(unsigned int xid, struct cifs_tcon *tcon,
674 struct cifs_sb_info *cifs_sb,
675 struct cached_fid **cfid)
677 struct cifs_ses *ses = tcon->ses;
678 struct TCP_Server_Info *server = ses->server;
679 struct cifs_open_parms oparms;
680 struct smb2_create_rsp *o_rsp = NULL;
681 struct smb2_query_info_rsp *qi_rsp = NULL;
683 struct smb_rqst rqst[2];
684 struct kvec rsp_iov[2];
685 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
686 struct kvec qi_iov[1];
688 __le16 utf16_path = 0; /* Null - since an open of top of share */
689 u8 oplock = SMB2_OPLOCK_LEVEL_II;
690 struct cifs_fid *pfid;
692 mutex_lock(&tcon->crfid.fid_mutex);
693 if (tcon->crfid.is_valid) {
694 cifs_dbg(FYI, "found a cached root file handle\n");
695 *cfid = &tcon->crfid;
696 kref_get(&tcon->crfid.refcount);
697 mutex_unlock(&tcon->crfid.fid_mutex);
702 * We do not hold the lock for the open because in case
703 * SMB2_open needs to reconnect, it will end up calling
704 * cifs_mark_open_files_invalid() which takes the lock again
705 * thus causing a deadlock
708 mutex_unlock(&tcon->crfid.fid_mutex);
710 if (smb3_encryption_required(tcon))
711 flags |= CIFS_TRANSFORM_REQ;
713 if (!server->ops->new_lease_key)
716 pfid = tcon->crfid.fid;
717 server->ops->new_lease_key(pfid);
719 memset(rqst, 0, sizeof(rqst));
720 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
721 memset(rsp_iov, 0, sizeof(rsp_iov));
724 memset(&open_iov, 0, sizeof(open_iov));
725 rqst[0].rq_iov = open_iov;
726 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
729 oparms.create_options = cifs_create_options(cifs_sb, 0);
730 oparms.desired_access = FILE_READ_ATTRIBUTES;
731 oparms.disposition = FILE_OPEN;
733 oparms.reconnect = false;
735 rc = SMB2_open_init(tcon, server,
736 &rqst[0], &oplock, &oparms, &utf16_path);
739 smb2_set_next_command(tcon, &rqst[0]);
741 memset(&qi_iov, 0, sizeof(qi_iov));
742 rqst[1].rq_iov = qi_iov;
745 rc = SMB2_query_info_init(tcon, server,
746 &rqst[1], COMPOUND_FID,
747 COMPOUND_FID, FILE_ALL_INFORMATION,
749 sizeof(struct smb2_file_all_info) +
750 PATH_MAX * 2, 0, NULL);
754 smb2_set_related(&rqst[1]);
756 rc = compound_send_recv(xid, ses, server,
758 resp_buftype, rsp_iov);
759 mutex_lock(&tcon->crfid.fid_mutex);
762 * Now we need to check again as the cached root might have
763 * been successfully re-opened from a concurrent process
766 if (tcon->crfid.is_valid) {
767 /* work was already done */
769 /* stash fids for close() later */
770 struct cifs_fid fid = {
771 .persistent_fid = pfid->persistent_fid,
772 .volatile_fid = pfid->volatile_fid,
776 * caller expects this func to set pfid to a valid
777 * cached root, so we copy the existing one and get a
780 memcpy(pfid, tcon->crfid.fid, sizeof(*pfid));
781 kref_get(&tcon->crfid.refcount);
783 mutex_unlock(&tcon->crfid.fid_mutex);
786 /* close extra handle outside of crit sec */
787 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
793 /* Cached root is still invalid, continue normaly */
796 if (rc == -EREMCHG) {
797 tcon->need_reconnect = true;
798 pr_warn_once("server share %s deleted\n",
804 atomic_inc(&tcon->num_remote_opens);
806 o_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
807 oparms.fid->persistent_fid = o_rsp->PersistentFileId;
808 oparms.fid->volatile_fid = o_rsp->VolatileFileId;
809 #ifdef CONFIG_CIFS_DEBUG2
810 oparms.fid->mid = le64_to_cpu(o_rsp->sync_hdr.MessageId);
811 #endif /* CIFS_DEBUG2 */
813 memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid));
814 tcon->crfid.tcon = tcon;
815 tcon->crfid.is_valid = true;
816 kref_init(&tcon->crfid.refcount);
818 /* BB TBD check to see if oplock level check can be removed below */
819 if (o_rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE) {
820 kref_get(&tcon->crfid.refcount);
821 tcon->crfid.has_lease = true;
822 rc = smb2_parse_contexts(server, rsp_iov,
824 oparms.fid->lease_key, &oplock,
831 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
832 if (le32_to_cpu(qi_rsp->OutputBufferLength) < sizeof(struct smb2_file_all_info))
834 if (!smb2_validate_and_copy_iov(
835 le16_to_cpu(qi_rsp->OutputBufferOffset),
836 sizeof(struct smb2_file_all_info),
837 &rsp_iov[1], sizeof(struct smb2_file_all_info),
838 (char *)&tcon->crfid.file_all_info))
839 tcon->crfid.file_all_info_is_valid = true;
842 mutex_unlock(&tcon->crfid.fid_mutex);
844 SMB2_open_free(&rqst[0]);
845 SMB2_query_info_free(&rqst[1]);
846 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
847 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
849 *cfid = &tcon->crfid;
854 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
855 struct cifs_sb_info *cifs_sb)
858 __le16 srch_path = 0; /* Null - open root of share */
859 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
860 struct cifs_open_parms oparms;
862 bool no_cached_open = tcon->nohandlecache;
863 struct cached_fid *cfid = NULL;
865 oparms = (struct cifs_open_parms) {
867 .desired_access = FILE_READ_ATTRIBUTES,
868 .disposition = FILE_OPEN,
869 .create_options = cifs_create_options(cifs_sb, 0),
873 if (no_cached_open) {
874 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
877 rc = open_shroot(xid, tcon, cifs_sb, &cfid);
879 memcpy(&fid, cfid->fid, sizeof(struct cifs_fid));
884 SMB3_request_interfaces(xid, tcon);
886 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
887 FS_ATTRIBUTE_INFORMATION);
888 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
889 FS_DEVICE_INFORMATION);
890 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
891 FS_VOLUME_INFORMATION);
892 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
893 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
895 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
901 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
902 struct cifs_sb_info *cifs_sb)
905 __le16 srch_path = 0; /* Null - open root of share */
906 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
907 struct cifs_open_parms oparms;
911 oparms.desired_access = FILE_READ_ATTRIBUTES;
912 oparms.disposition = FILE_OPEN;
913 oparms.create_options = cifs_create_options(cifs_sb, 0);
915 oparms.reconnect = false;
917 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
922 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
923 FS_ATTRIBUTE_INFORMATION);
924 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
925 FS_DEVICE_INFORMATION);
926 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
930 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
931 struct cifs_sb_info *cifs_sb, const char *full_path)
935 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
936 struct cifs_open_parms oparms;
939 if ((*full_path == 0) && tcon->crfid.is_valid)
942 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
947 oparms.desired_access = FILE_READ_ATTRIBUTES;
948 oparms.disposition = FILE_OPEN;
949 oparms.create_options = cifs_create_options(cifs_sb, 0);
951 oparms.reconnect = false;
953 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
960 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
966 smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
967 struct cifs_sb_info *cifs_sb, const char *full_path,
968 u64 *uniqueid, FILE_ALL_INFO *data)
970 *uniqueid = le64_to_cpu(data->IndexNumber);
975 smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
976 struct cifs_fid *fid, FILE_ALL_INFO *data)
979 struct smb2_file_all_info *smb2_data;
981 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
983 if (smb2_data == NULL)
986 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
989 move_smb2_info_to_cifs(data, smb2_data);
994 #ifdef CONFIG_CIFS_XATTR
996 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
997 struct smb2_file_full_ea_info *src, size_t src_size,
998 const unsigned char *ea_name)
1001 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
1003 size_t buf_size = dst_size;
1004 size_t name_len, value_len, user_name_len;
1006 while (src_size > 0) {
1007 name_len = (size_t)src->ea_name_length;
1008 value_len = (size_t)le16_to_cpu(src->ea_value_length);
1013 if (src_size < 8 + name_len + 1 + value_len) {
1014 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
1019 name = &src->ea_data[0];
1020 value = &src->ea_data[src->ea_name_length + 1];
1023 if (ea_name_len == name_len &&
1024 memcmp(ea_name, name, name_len) == 0) {
1028 if (dst_size < value_len) {
1032 memcpy(dst, value, value_len);
1036 /* 'user.' plus a terminating null */
1037 user_name_len = 5 + 1 + name_len;
1039 if (buf_size == 0) {
1040 /* skip copy - calc size only */
1041 rc += user_name_len;
1042 } else if (dst_size >= user_name_len) {
1043 dst_size -= user_name_len;
1044 memcpy(dst, "user.", 5);
1046 memcpy(dst, src->ea_data, name_len);
1050 rc += user_name_len;
1052 /* stop before overrun buffer */
1058 if (!src->next_entry_offset)
1061 if (src_size < le32_to_cpu(src->next_entry_offset)) {
1062 /* stop before overrun buffer */
1066 src_size -= le32_to_cpu(src->next_entry_offset);
1067 src = (void *)((char *)src +
1068 le32_to_cpu(src->next_entry_offset));
1071 /* didn't find the named attribute */
1080 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
1081 const unsigned char *path, const unsigned char *ea_name,
1082 char *ea_data, size_t buf_size,
1083 struct cifs_sb_info *cifs_sb)
1087 struct kvec rsp_iov = {NULL, 0};
1088 int buftype = CIFS_NO_BUFFER;
1089 struct smb2_query_info_rsp *rsp;
1090 struct smb2_file_full_ea_info *info = NULL;
1092 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1096 rc = smb2_query_info_compound(xid, tcon, utf16_path,
1098 FILE_FULL_EA_INFORMATION,
1101 MAX_SMB2_CREATE_RESPONSE_SIZE -
1102 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1103 &rsp_iov, &buftype, cifs_sb);
1106 * If ea_name is NULL (listxattr) and there are no EAs,
1107 * return 0 as it's not an error. Otherwise, the specified
1108 * ea_name was not found.
1110 if (!ea_name && rc == -ENODATA)
1115 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
1116 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1117 le32_to_cpu(rsp->OutputBufferLength),
1119 sizeof(struct smb2_file_full_ea_info));
1123 info = (struct smb2_file_full_ea_info *)(
1124 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1125 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
1126 le32_to_cpu(rsp->OutputBufferLength), ea_name);
1130 free_rsp_buf(buftype, rsp_iov.iov_base);
1136 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
1137 const char *path, const char *ea_name, const void *ea_value,
1138 const __u16 ea_value_len, const struct nls_table *nls_codepage,
1139 struct cifs_sb_info *cifs_sb)
1141 struct cifs_ses *ses = tcon->ses;
1142 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1143 __le16 *utf16_path = NULL;
1144 int ea_name_len = strlen(ea_name);
1145 int flags = CIFS_CP_CREATE_CLOSE_OP;
1147 struct smb_rqst rqst[3];
1148 int resp_buftype[3];
1149 struct kvec rsp_iov[3];
1150 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1151 struct cifs_open_parms oparms;
1152 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1153 struct cifs_fid fid;
1154 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1155 unsigned int size[1];
1157 struct smb2_file_full_ea_info *ea = NULL;
1158 struct kvec close_iov[1];
1159 struct smb2_query_info_rsp *rsp;
1160 int rc, used_len = 0;
1162 if (smb3_encryption_required(tcon))
1163 flags |= CIFS_TRANSFORM_REQ;
1165 if (ea_name_len > 255)
1168 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1172 memset(rqst, 0, sizeof(rqst));
1173 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1174 memset(rsp_iov, 0, sizeof(rsp_iov));
1176 if (ses->server->ops->query_all_EAs) {
1178 rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1184 /* If we are adding a attribute we should first check
1185 * if there will be enough space available to store
1186 * the new EA. If not we should not add it since we
1187 * would not be able to even read the EAs back.
1189 rc = smb2_query_info_compound(xid, tcon, utf16_path,
1191 FILE_FULL_EA_INFORMATION,
1194 MAX_SMB2_CREATE_RESPONSE_SIZE -
1195 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1196 &rsp_iov[1], &resp_buftype[1], cifs_sb);
1198 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1199 used_len = le32_to_cpu(rsp->OutputBufferLength);
1201 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1202 resp_buftype[1] = CIFS_NO_BUFFER;
1203 memset(&rsp_iov[1], 0, sizeof(rsp_iov[1]));
1206 /* Use a fudge factor of 256 bytes in case we collide
1207 * with a different set_EAs command.
1209 if(CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1210 MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 <
1211 used_len + ea_name_len + ea_value_len + 1) {
1219 memset(&open_iov, 0, sizeof(open_iov));
1220 rqst[0].rq_iov = open_iov;
1221 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1223 memset(&oparms, 0, sizeof(oparms));
1225 oparms.desired_access = FILE_WRITE_EA;
1226 oparms.disposition = FILE_OPEN;
1227 oparms.create_options = cifs_create_options(cifs_sb, 0);
1229 oparms.reconnect = false;
1231 rc = SMB2_open_init(tcon, server,
1232 &rqst[0], &oplock, &oparms, utf16_path);
1235 smb2_set_next_command(tcon, &rqst[0]);
1239 memset(&si_iov, 0, sizeof(si_iov));
1240 rqst[1].rq_iov = si_iov;
1241 rqst[1].rq_nvec = 1;
1243 len = sizeof(*ea) + ea_name_len + ea_value_len + 1;
1244 ea = kzalloc(len, GFP_KERNEL);
1250 ea->ea_name_length = ea_name_len;
1251 ea->ea_value_length = cpu_to_le16(ea_value_len);
1252 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
1253 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
1258 rc = SMB2_set_info_init(tcon, server,
1259 &rqst[1], COMPOUND_FID,
1260 COMPOUND_FID, current->tgid,
1261 FILE_FULL_EA_INFORMATION,
1262 SMB2_O_INFO_FILE, 0, data, size);
1265 smb2_set_next_command(tcon, &rqst[1]);
1266 smb2_set_related(&rqst[1]);
1270 memset(&close_iov, 0, sizeof(close_iov));
1271 rqst[2].rq_iov = close_iov;
1272 rqst[2].rq_nvec = 1;
1273 rc = SMB2_close_init(tcon, server,
1274 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1277 smb2_set_related(&rqst[2]);
1279 rc = compound_send_recv(xid, ses, server,
1281 resp_buftype, rsp_iov);
1282 /* no need to bump num_remote_opens because handle immediately closed */
1287 SMB2_open_free(&rqst[0]);
1288 SMB2_set_info_free(&rqst[1]);
1289 SMB2_close_free(&rqst[2]);
1290 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1291 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1292 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1298 smb2_can_echo(struct TCP_Server_Info *server)
1300 return server->echoes;
1304 smb2_clear_stats(struct cifs_tcon *tcon)
1308 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1309 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1310 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1315 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1317 seq_puts(m, "\n\tShare Capabilities:");
1318 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1319 seq_puts(m, " DFS,");
1320 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1321 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1322 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1323 seq_puts(m, " SCALEOUT,");
1324 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1325 seq_puts(m, " CLUSTER,");
1326 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1327 seq_puts(m, " ASYMMETRIC,");
1328 if (tcon->capabilities == 0)
1329 seq_puts(m, " None");
1330 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1331 seq_puts(m, " Aligned,");
1332 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1333 seq_puts(m, " Partition Aligned,");
1334 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1335 seq_puts(m, " SSD,");
1336 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1337 seq_puts(m, " TRIM-support,");
1339 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1340 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1341 if (tcon->perf_sector_size)
1342 seq_printf(m, "\tOptimal sector size: 0x%x",
1343 tcon->perf_sector_size);
1344 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1348 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1350 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1351 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1354 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1355 * totals (requests sent) since those SMBs are per-session not per tcon
1357 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1358 (long long)(tcon->bytes_read),
1359 (long long)(tcon->bytes_written));
1360 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1361 atomic_read(&tcon->num_local_opens),
1362 atomic_read(&tcon->num_remote_opens));
1363 seq_printf(m, "\nTreeConnects: %d total %d failed",
1364 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1365 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1366 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1367 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1368 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1369 seq_printf(m, "\nCreates: %d total %d failed",
1370 atomic_read(&sent[SMB2_CREATE_HE]),
1371 atomic_read(&failed[SMB2_CREATE_HE]));
1372 seq_printf(m, "\nCloses: %d total %d failed",
1373 atomic_read(&sent[SMB2_CLOSE_HE]),
1374 atomic_read(&failed[SMB2_CLOSE_HE]));
1375 seq_printf(m, "\nFlushes: %d total %d failed",
1376 atomic_read(&sent[SMB2_FLUSH_HE]),
1377 atomic_read(&failed[SMB2_FLUSH_HE]));
1378 seq_printf(m, "\nReads: %d total %d failed",
1379 atomic_read(&sent[SMB2_READ_HE]),
1380 atomic_read(&failed[SMB2_READ_HE]));
1381 seq_printf(m, "\nWrites: %d total %d failed",
1382 atomic_read(&sent[SMB2_WRITE_HE]),
1383 atomic_read(&failed[SMB2_WRITE_HE]));
1384 seq_printf(m, "\nLocks: %d total %d failed",
1385 atomic_read(&sent[SMB2_LOCK_HE]),
1386 atomic_read(&failed[SMB2_LOCK_HE]));
1387 seq_printf(m, "\nIOCTLs: %d total %d failed",
1388 atomic_read(&sent[SMB2_IOCTL_HE]),
1389 atomic_read(&failed[SMB2_IOCTL_HE]));
1390 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1391 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1392 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1393 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1394 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1395 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1396 seq_printf(m, "\nQueryInfos: %d total %d failed",
1397 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1398 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1399 seq_printf(m, "\nSetInfos: %d total %d failed",
1400 atomic_read(&sent[SMB2_SET_INFO_HE]),
1401 atomic_read(&failed[SMB2_SET_INFO_HE]));
1402 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1403 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1404 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1408 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1410 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1411 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1413 cfile->fid.persistent_fid = fid->persistent_fid;
1414 cfile->fid.volatile_fid = fid->volatile_fid;
1415 cfile->fid.access = fid->access;
1416 #ifdef CONFIG_CIFS_DEBUG2
1417 cfile->fid.mid = fid->mid;
1418 #endif /* CIFS_DEBUG2 */
1419 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1421 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1422 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1426 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1427 struct cifs_fid *fid)
1429 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1433 smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon,
1434 struct cifsFileInfo *cfile)
1436 struct smb2_file_network_open_info file_inf;
1437 struct inode *inode;
1440 rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid,
1441 cfile->fid.volatile_fid, &file_inf);
1445 inode = d_inode(cfile->dentry);
1447 spin_lock(&inode->i_lock);
1448 CIFS_I(inode)->time = jiffies;
1450 /* Creation time should not need to be updated on close */
1451 if (file_inf.LastWriteTime)
1452 inode->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime);
1453 if (file_inf.ChangeTime)
1454 inode->i_ctime = cifs_NTtimeToUnix(file_inf.ChangeTime);
1455 if (file_inf.LastAccessTime)
1456 inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime);
1459 * i_blocks is not related to (i_size / i_blksize),
1460 * but instead 512 byte (2**9) size is required for
1461 * calculating num blocks.
1463 if (le64_to_cpu(file_inf.AllocationSize) > 4096)
1465 (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9;
1467 /* End of file and Attributes should not have to be updated on close */
1468 spin_unlock(&inode->i_lock);
1472 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1473 u64 persistent_fid, u64 volatile_fid,
1474 struct copychunk_ioctl *pcchunk)
1477 unsigned int ret_data_len;
1478 struct resume_key_req *res_key;
1480 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1481 FSCTL_SRV_REQUEST_RESUME_KEY, NULL, 0 /* no input */,
1482 CIFSMaxBufSize, (char **)&res_key, &ret_data_len);
1485 cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1486 goto req_res_key_exit;
1488 if (ret_data_len < sizeof(struct resume_key_req)) {
1489 cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n");
1491 goto req_res_key_exit;
1493 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1501 struct smb_rqst rqst[3];
1502 struct kvec rsp_iov[3];
1503 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1504 struct kvec qi_iov[1];
1505 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
1506 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1507 struct kvec close_iov[1];
1511 smb2_ioctl_query_info(const unsigned int xid,
1512 struct cifs_tcon *tcon,
1513 struct cifs_sb_info *cifs_sb,
1514 __le16 *path, int is_dir,
1517 struct iqi_vars *vars;
1518 struct smb_rqst *rqst;
1519 struct kvec *rsp_iov;
1520 struct cifs_ses *ses = tcon->ses;
1521 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1522 char __user *arg = (char __user *)p;
1523 struct smb_query_info qi;
1524 struct smb_query_info __user *pqi;
1526 int flags = CIFS_CP_CREATE_CLOSE_OP;
1527 struct smb2_query_info_rsp *qi_rsp = NULL;
1528 struct smb2_ioctl_rsp *io_rsp = NULL;
1529 void *buffer = NULL;
1530 int resp_buftype[3];
1531 struct cifs_open_parms oparms;
1532 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1533 struct cifs_fid fid;
1534 unsigned int size[2];
1536 int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR;
1537 void (*free_req1_func)(struct smb_rqst *r);
1539 vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
1542 rqst = &vars->rqst[0];
1543 rsp_iov = &vars->rsp_iov[0];
1545 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1547 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info))) {
1551 if (qi.output_buffer_length > 1024) {
1556 if (!ses || !server) {
1561 if (smb3_encryption_required(tcon))
1562 flags |= CIFS_TRANSFORM_REQ;
1564 if (qi.output_buffer_length) {
1565 buffer = memdup_user(arg + sizeof(struct smb_query_info), qi.output_buffer_length);
1566 if (IS_ERR(buffer)) {
1567 rc = PTR_ERR(buffer);
1573 rqst[0].rq_iov = &vars->open_iov[0];
1574 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1576 memset(&oparms, 0, sizeof(oparms));
1578 oparms.disposition = FILE_OPEN;
1579 oparms.create_options = cifs_create_options(cifs_sb, create_options);
1581 oparms.reconnect = false;
1583 if (qi.flags & PASSTHRU_FSCTL) {
1584 switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1585 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1586 oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1588 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1589 oparms.desired_access = GENERIC_ALL;
1591 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1592 oparms.desired_access = GENERIC_READ;
1594 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1595 oparms.desired_access = GENERIC_WRITE;
1598 } else if (qi.flags & PASSTHRU_SET_INFO) {
1599 oparms.desired_access = GENERIC_WRITE;
1601 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1604 rc = SMB2_open_init(tcon, server,
1605 &rqst[0], &oplock, &oparms, path);
1607 goto free_output_buffer;
1608 smb2_set_next_command(tcon, &rqst[0]);
1611 if (qi.flags & PASSTHRU_FSCTL) {
1612 /* Can eventually relax perm check since server enforces too */
1613 if (!capable(CAP_SYS_ADMIN)) {
1617 rqst[1].rq_iov = &vars->io_iov[0];
1618 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1620 rc = SMB2_ioctl_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1621 qi.info_type, buffer, qi.output_buffer_length,
1622 CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1623 MAX_SMB2_CLOSE_RESPONSE_SIZE);
1624 free_req1_func = SMB2_ioctl_free;
1625 } else if (qi.flags == PASSTHRU_SET_INFO) {
1626 /* Can eventually relax perm check since server enforces too */
1627 if (!capable(CAP_SYS_ADMIN)) {
1631 if (qi.output_buffer_length < 8) {
1635 rqst[1].rq_iov = &vars->si_iov[0];
1636 rqst[1].rq_nvec = 1;
1638 /* MS-FSCC 2.4.13 FileEndOfFileInformation */
1642 rc = SMB2_set_info_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1643 current->tgid, FILE_END_OF_FILE_INFORMATION,
1644 SMB2_O_INFO_FILE, 0, data, size);
1645 free_req1_func = SMB2_set_info_free;
1646 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1647 rqst[1].rq_iov = &vars->qi_iov[0];
1648 rqst[1].rq_nvec = 1;
1650 rc = SMB2_query_info_init(tcon, server,
1651 &rqst[1], COMPOUND_FID,
1652 COMPOUND_FID, qi.file_info_class,
1653 qi.info_type, qi.additional_information,
1654 qi.input_buffer_length,
1655 qi.output_buffer_length, buffer);
1656 free_req1_func = SMB2_query_info_free;
1657 } else { /* unknown flags */
1658 cifs_tcon_dbg(VFS, "Invalid passthru query flags: 0x%x\n",
1665 smb2_set_next_command(tcon, &rqst[1]);
1666 smb2_set_related(&rqst[1]);
1669 rqst[2].rq_iov = &vars->close_iov[0];
1670 rqst[2].rq_nvec = 1;
1672 rc = SMB2_close_init(tcon, server,
1673 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1676 smb2_set_related(&rqst[2]);
1678 rc = compound_send_recv(xid, ses, server,
1680 resp_buftype, rsp_iov);
1684 /* No need to bump num_remote_opens since handle immediately closed */
1685 if (qi.flags & PASSTHRU_FSCTL) {
1686 pqi = (struct smb_query_info __user *)arg;
1687 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1688 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1689 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1690 if (qi.input_buffer_length > 0 &&
1691 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length
1692 > rsp_iov[1].iov_len) {
1697 if (copy_to_user(&pqi->input_buffer_length,
1698 &qi.input_buffer_length,
1699 sizeof(qi.input_buffer_length))) {
1704 if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1705 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1706 qi.input_buffer_length))
1709 pqi = (struct smb_query_info __user *)arg;
1710 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1711 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1712 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1713 if (copy_to_user(&pqi->input_buffer_length,
1714 &qi.input_buffer_length,
1715 sizeof(qi.input_buffer_length))) {
1720 if (copy_to_user(pqi + 1, qi_rsp->Buffer,
1721 qi.input_buffer_length))
1726 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1727 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1728 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1729 SMB2_close_free(&rqst[2]);
1731 free_req1_func(&rqst[1]);
1733 SMB2_open_free(&rqst[0]);
1742 smb2_copychunk_range(const unsigned int xid,
1743 struct cifsFileInfo *srcfile,
1744 struct cifsFileInfo *trgtfile, u64 src_off,
1745 u64 len, u64 dest_off)
1748 unsigned int ret_data_len;
1749 struct copychunk_ioctl *pcchunk;
1750 struct copychunk_ioctl_rsp *retbuf = NULL;
1751 struct cifs_tcon *tcon;
1752 int chunks_copied = 0;
1753 bool chunk_sizes_updated = false;
1754 ssize_t bytes_written, total_bytes_written = 0;
1755 struct inode *inode;
1757 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1760 * We need to flush all unwritten data before we can send the
1761 * copychunk ioctl to the server.
1763 inode = d_inode(trgtfile->dentry);
1764 filemap_write_and_wait(inode->i_mapping);
1766 if (pcchunk == NULL)
1769 cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
1770 /* Request a key from the server to identify the source of the copy */
1771 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1772 srcfile->fid.persistent_fid,
1773 srcfile->fid.volatile_fid, pcchunk);
1775 /* Note: request_res_key sets res_key null only if rc !=0 */
1779 /* For now array only one chunk long, will make more flexible later */
1780 pcchunk->ChunkCount = cpu_to_le32(1);
1781 pcchunk->Reserved = 0;
1782 pcchunk->Reserved2 = 0;
1784 tcon = tlink_tcon(trgtfile->tlink);
1787 pcchunk->SourceOffset = cpu_to_le64(src_off);
1788 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1790 cpu_to_le32(min_t(u64, len, tcon->max_bytes_chunk));
1792 /* Request server copy to target from src identified by key */
1795 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1796 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1797 (char *)pcchunk, sizeof(struct copychunk_ioctl),
1798 CIFSMaxBufSize, (char **)&retbuf, &ret_data_len);
1801 sizeof(struct copychunk_ioctl_rsp)) {
1802 cifs_tcon_dbg(VFS, "Invalid cchunk response size\n");
1806 if (retbuf->TotalBytesWritten == 0) {
1807 cifs_dbg(FYI, "no bytes copied\n");
1812 * Check if server claimed to write more than we asked
1814 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1815 le32_to_cpu(pcchunk->Length)) {
1816 cifs_tcon_dbg(VFS, "Invalid copy chunk response\n");
1820 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1821 cifs_tcon_dbg(VFS, "Invalid num chunks written\n");
1827 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1828 src_off += bytes_written;
1829 dest_off += bytes_written;
1830 len -= bytes_written;
1831 total_bytes_written += bytes_written;
1833 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1834 le32_to_cpu(retbuf->ChunksWritten),
1835 le32_to_cpu(retbuf->ChunkBytesWritten),
1837 } else if (rc == -EINVAL) {
1838 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1841 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1842 le32_to_cpu(retbuf->ChunksWritten),
1843 le32_to_cpu(retbuf->ChunkBytesWritten),
1844 le32_to_cpu(retbuf->TotalBytesWritten));
1847 * Check if this is the first request using these sizes,
1848 * (ie check if copy succeed once with original sizes
1849 * and check if the server gave us different sizes after
1850 * we already updated max sizes on previous request).
1851 * if not then why is the server returning an error now
1853 if ((chunks_copied != 0) || chunk_sizes_updated)
1856 /* Check that server is not asking us to grow size */
1857 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1858 tcon->max_bytes_chunk)
1859 tcon->max_bytes_chunk =
1860 le32_to_cpu(retbuf->ChunkBytesWritten);
1862 goto cchunk_out; /* server gave us bogus size */
1864 /* No need to change MaxChunks since already set to 1 */
1865 chunk_sizes_updated = true;
1876 return total_bytes_written;
1880 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1881 struct cifs_fid *fid)
1883 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1887 smb2_read_data_offset(char *buf)
1889 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1891 return rsp->DataOffset;
1895 smb2_read_data_length(char *buf, bool in_remaining)
1897 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1900 return le32_to_cpu(rsp->DataRemaining);
1902 return le32_to_cpu(rsp->DataLength);
1907 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1908 struct cifs_io_parms *parms, unsigned int *bytes_read,
1909 char **buf, int *buf_type)
1911 parms->persistent_fid = pfid->persistent_fid;
1912 parms->volatile_fid = pfid->volatile_fid;
1913 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1917 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1918 struct cifs_io_parms *parms, unsigned int *written,
1919 struct kvec *iov, unsigned long nr_segs)
1922 parms->persistent_fid = pfid->persistent_fid;
1923 parms->volatile_fid = pfid->volatile_fid;
1924 return SMB2_write(xid, parms, written, iov, nr_segs);
1927 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1928 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1929 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1931 struct cifsInodeInfo *cifsi;
1934 cifsi = CIFS_I(inode);
1936 /* if file already sparse don't bother setting sparse again */
1937 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1938 return true; /* already sparse */
1940 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1941 return true; /* already not sparse */
1944 * Can't check for sparse support on share the usual way via the
1945 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1946 * since Samba server doesn't set the flag on the share, yet
1947 * supports the set sparse FSCTL and returns sparse correctly
1948 * in the file attributes. If we fail setting sparse though we
1949 * mark that server does not support sparse files for this share
1950 * to avoid repeatedly sending the unsupported fsctl to server
1951 * if the file is repeatedly extended.
1953 if (tcon->broken_sparse_sup)
1956 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1957 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1958 &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
1960 tcon->broken_sparse_sup = true;
1961 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1966 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1968 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1974 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1975 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1977 __le64 eof = cpu_to_le64(size);
1978 struct inode *inode;
1981 * If extending file more than one page make sparse. Many Linux fs
1982 * make files sparse by default when extending via ftruncate
1984 inode = d_inode(cfile->dentry);
1986 if (!set_alloc && (size > inode->i_size + 8192)) {
1987 __u8 set_sparse = 1;
1989 /* whether set sparse succeeds or not, extend the file */
1990 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1993 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1994 cfile->fid.volatile_fid, cfile->pid, &eof);
1998 smb2_duplicate_extents(const unsigned int xid,
1999 struct cifsFileInfo *srcfile,
2000 struct cifsFileInfo *trgtfile, u64 src_off,
2001 u64 len, u64 dest_off)
2004 unsigned int ret_data_len;
2005 struct inode *inode;
2006 struct duplicate_extents_to_file dup_ext_buf;
2007 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
2009 /* server fileays advertise duplicate extent support with this flag */
2010 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
2011 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
2014 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
2015 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
2016 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
2017 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
2018 dup_ext_buf.ByteCount = cpu_to_le64(len);
2019 cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
2020 src_off, dest_off, len);
2022 inode = d_inode(trgtfile->dentry);
2023 if (inode->i_size < dest_off + len) {
2024 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
2026 goto duplicate_extents_out;
2029 * Although also could set plausible allocation size (i_blocks)
2030 * here in addition to setting the file size, in reflink
2031 * it is likely that the target file is sparse. Its allocation
2032 * size will be queried on next revalidate, but it is important
2033 * to make sure that file's cached size is updated immediately
2035 cifs_setsize(inode, dest_off + len);
2037 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
2038 trgtfile->fid.volatile_fid,
2039 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
2040 (char *)&dup_ext_buf,
2041 sizeof(struct duplicate_extents_to_file),
2042 CIFSMaxBufSize, NULL,
2045 if (ret_data_len > 0)
2046 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
2048 duplicate_extents_out:
2053 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
2054 struct cifsFileInfo *cfile)
2056 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
2057 cfile->fid.volatile_fid);
2061 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
2062 struct cifsFileInfo *cfile)
2064 struct fsctl_set_integrity_information_req integr_info;
2065 unsigned int ret_data_len;
2067 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
2068 integr_info.Flags = 0;
2069 integr_info.Reserved = 0;
2071 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2072 cfile->fid.volatile_fid,
2073 FSCTL_SET_INTEGRITY_INFORMATION,
2074 (char *)&integr_info,
2075 sizeof(struct fsctl_set_integrity_information_req),
2076 CIFSMaxBufSize, NULL,
2081 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
2082 #define GMT_TOKEN_SIZE 50
2084 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
2087 * Input buffer contains (empty) struct smb_snapshot array with size filled in
2088 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
2091 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
2092 struct cifsFileInfo *cfile, void __user *ioc_buf)
2094 char *retbuf = NULL;
2095 unsigned int ret_data_len = 0;
2097 u32 max_response_size;
2098 struct smb_snapshot_array snapshot_in;
2101 * On the first query to enumerate the list of snapshots available
2102 * for this volume the buffer begins with 0 (number of snapshots
2103 * which can be returned is zero since at that point we do not know
2104 * how big the buffer needs to be). On the second query,
2105 * it (ret_data_len) is set to number of snapshots so we can
2106 * know to set the maximum response size larger (see below).
2108 if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
2112 * Note that for snapshot queries that servers like Azure expect that
2113 * the first query be minimal size (and just used to get the number/size
2114 * of previous versions) so response size must be specified as EXACTLY
2115 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
2118 if (ret_data_len == 0)
2119 max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
2121 max_response_size = CIFSMaxBufSize;
2123 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2124 cfile->fid.volatile_fid,
2125 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
2126 NULL, 0 /* no input data */, max_response_size,
2129 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
2134 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
2136 if (copy_from_user(&snapshot_in, ioc_buf,
2137 sizeof(struct smb_snapshot_array))) {
2144 * Check for min size, ie not large enough to fit even one GMT
2145 * token (snapshot). On the first ioctl some users may pass in
2146 * smaller size (or zero) to simply get the size of the array
2147 * so the user space caller can allocate sufficient memory
2148 * and retry the ioctl again with larger array size sufficient
2149 * to hold all of the snapshot GMT tokens on the second try.
2151 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
2152 ret_data_len = sizeof(struct smb_snapshot_array);
2155 * We return struct SRV_SNAPSHOT_ARRAY, followed by
2156 * the snapshot array (of 50 byte GMT tokens) each
2157 * representing an available previous version of the data
2159 if (ret_data_len > (snapshot_in.snapshot_array_size +
2160 sizeof(struct smb_snapshot_array)))
2161 ret_data_len = snapshot_in.snapshot_array_size +
2162 sizeof(struct smb_snapshot_array);
2164 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
2175 smb3_notify(const unsigned int xid, struct file *pfile,
2176 void __user *ioc_buf)
2178 struct smb3_notify notify;
2179 struct dentry *dentry = pfile->f_path.dentry;
2180 struct inode *inode = file_inode(pfile);
2181 struct cifs_sb_info *cifs_sb;
2182 struct cifs_open_parms oparms;
2183 struct cifs_fid fid;
2184 struct cifs_tcon *tcon;
2185 unsigned char *path = NULL;
2186 __le16 *utf16_path = NULL;
2187 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2190 path = build_path_from_dentry(dentry);
2194 cifs_sb = CIFS_SB(inode->i_sb);
2196 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2197 if (utf16_path == NULL) {
2202 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify))) {
2207 tcon = cifs_sb_master_tcon(cifs_sb);
2209 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
2210 oparms.disposition = FILE_OPEN;
2211 oparms.create_options = cifs_create_options(cifs_sb, 0);
2213 oparms.reconnect = false;
2215 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
2220 rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid,
2221 notify.watch_tree, notify.completion_filter);
2223 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2225 cifs_dbg(FYI, "change notify for path %s rc %d\n", path, rc);
2234 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
2235 const char *path, struct cifs_sb_info *cifs_sb,
2236 struct cifs_fid *fid, __u16 search_flags,
2237 struct cifs_search_info *srch_inf)
2240 struct smb_rqst rqst[2];
2241 struct kvec rsp_iov[2];
2242 int resp_buftype[2];
2243 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2244 struct kvec qd_iov[SMB2_QUERY_DIRECTORY_IOV_SIZE];
2246 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2247 struct cifs_open_parms oparms;
2248 struct smb2_query_directory_rsp *qd_rsp = NULL;
2249 struct smb2_create_rsp *op_rsp = NULL;
2250 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2252 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2256 if (smb3_encryption_required(tcon))
2257 flags |= CIFS_TRANSFORM_REQ;
2259 memset(rqst, 0, sizeof(rqst));
2260 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
2261 memset(rsp_iov, 0, sizeof(rsp_iov));
2264 memset(&open_iov, 0, sizeof(open_iov));
2265 rqst[0].rq_iov = open_iov;
2266 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2269 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
2270 oparms.disposition = FILE_OPEN;
2271 oparms.create_options = cifs_create_options(cifs_sb, 0);
2273 oparms.reconnect = false;
2275 rc = SMB2_open_init(tcon, server,
2276 &rqst[0], &oplock, &oparms, utf16_path);
2279 smb2_set_next_command(tcon, &rqst[0]);
2281 /* Query directory */
2282 srch_inf->entries_in_buffer = 0;
2283 srch_inf->index_of_last_entry = 2;
2285 memset(&qd_iov, 0, sizeof(qd_iov));
2286 rqst[1].rq_iov = qd_iov;
2287 rqst[1].rq_nvec = SMB2_QUERY_DIRECTORY_IOV_SIZE;
2289 rc = SMB2_query_directory_init(xid, tcon, server,
2291 COMPOUND_FID, COMPOUND_FID,
2292 0, srch_inf->info_level);
2296 smb2_set_related(&rqst[1]);
2298 rc = compound_send_recv(xid, tcon->ses, server,
2300 resp_buftype, rsp_iov);
2302 /* If the open failed there is nothing to do */
2303 op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
2304 if (op_rsp == NULL || op_rsp->sync_hdr.Status != STATUS_SUCCESS) {
2305 cifs_dbg(FYI, "query_dir_first: open failed rc=%d\n", rc);
2308 fid->persistent_fid = op_rsp->PersistentFileId;
2309 fid->volatile_fid = op_rsp->VolatileFileId;
2311 /* Anything else than ENODATA means a genuine error */
2312 if (rc && rc != -ENODATA) {
2313 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2314 cifs_dbg(FYI, "query_dir_first: query directory failed rc=%d\n", rc);
2315 trace_smb3_query_dir_err(xid, fid->persistent_fid,
2316 tcon->tid, tcon->ses->Suid, 0, 0, rc);
2320 atomic_inc(&tcon->num_remote_opens);
2322 qd_rsp = (struct smb2_query_directory_rsp *)rsp_iov[1].iov_base;
2323 if (qd_rsp->sync_hdr.Status == STATUS_NO_MORE_FILES) {
2324 trace_smb3_query_dir_done(xid, fid->persistent_fid,
2325 tcon->tid, tcon->ses->Suid, 0, 0);
2326 srch_inf->endOfSearch = true;
2331 rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1],
2334 trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid,
2335 tcon->ses->Suid, 0, 0, rc);
2338 resp_buftype[1] = CIFS_NO_BUFFER;
2340 trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid,
2341 tcon->ses->Suid, 0, srch_inf->entries_in_buffer);
2345 SMB2_open_free(&rqst[0]);
2346 SMB2_query_directory_free(&rqst[1]);
2347 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2348 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2353 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
2354 struct cifs_fid *fid, __u16 search_flags,
2355 struct cifs_search_info *srch_inf)
2357 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
2358 fid->volatile_fid, 0, srch_inf);
2362 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
2363 struct cifs_fid *fid)
2365 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2369 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2370 * the number of credits and return true. Otherwise - return false.
2373 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
2375 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2377 if (shdr->Status != STATUS_PENDING)
2380 if (shdr->CreditRequest) {
2381 spin_lock(&server->req_lock);
2382 server->credits += le16_to_cpu(shdr->CreditRequest);
2383 spin_unlock(&server->req_lock);
2384 wake_up(&server->request_q);
2391 smb2_is_session_expired(char *buf)
2393 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2395 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
2396 shdr->Status != STATUS_USER_SESSION_DELETED)
2399 trace_smb3_ses_expired(shdr->TreeId, shdr->SessionId,
2400 le16_to_cpu(shdr->Command),
2401 le64_to_cpu(shdr->MessageId));
2402 cifs_dbg(FYI, "Session expired or deleted\n");
2408 smb2_is_status_io_timeout(char *buf)
2410 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2412 if (shdr->Status == STATUS_IO_TIMEOUT)
2419 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
2420 struct cifsInodeInfo *cinode)
2422 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
2423 return SMB2_lease_break(0, tcon, cinode->lease_key,
2424 smb2_get_lease_state(cinode));
2426 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
2428 CIFS_CACHE_READ(cinode) ? 1 : 0);
2432 smb2_set_related(struct smb_rqst *rqst)
2434 struct smb2_sync_hdr *shdr;
2436 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
2438 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2441 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2444 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
2447 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
2449 struct smb2_sync_hdr *shdr;
2450 struct cifs_ses *ses = tcon->ses;
2451 struct TCP_Server_Info *server = ses->server;
2452 unsigned long len = smb_rqst_len(server, rqst);
2455 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
2457 cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2461 /* SMB headers in a compound are 8 byte aligned. */
2463 /* No padding needed */
2467 num_padding = 8 - (len & 7);
2468 if (!smb3_encryption_required(tcon)) {
2470 * If we do not have encryption then we can just add an extra
2471 * iov for the padding.
2473 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2474 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2479 * We can not add a small padding iov for the encryption case
2480 * because the encryption framework can not handle the padding
2482 * We have to flatten this into a single buffer and add
2483 * the padding to it.
2485 for (i = 1; i < rqst->rq_nvec; i++) {
2486 memcpy(rqst->rq_iov[0].iov_base +
2487 rqst->rq_iov[0].iov_len,
2488 rqst->rq_iov[i].iov_base,
2489 rqst->rq_iov[i].iov_len);
2490 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2492 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2494 rqst->rq_iov[0].iov_len += num_padding;
2500 shdr->NextCommand = cpu_to_le32(len);
2504 * Passes the query info response back to the caller on success.
2505 * Caller need to free this with free_rsp_buf().
2508 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2509 __le16 *utf16_path, u32 desired_access,
2510 u32 class, u32 type, u32 output_len,
2511 struct kvec *rsp, int *buftype,
2512 struct cifs_sb_info *cifs_sb)
2514 struct cifs_ses *ses = tcon->ses;
2515 struct TCP_Server_Info *server = cifs_pick_channel(ses);
2516 int flags = CIFS_CP_CREATE_CLOSE_OP;
2517 struct smb_rqst rqst[3];
2518 int resp_buftype[3];
2519 struct kvec rsp_iov[3];
2520 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2521 struct kvec qi_iov[1];
2522 struct kvec close_iov[1];
2523 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2524 struct cifs_open_parms oparms;
2525 struct cifs_fid fid;
2528 if (smb3_encryption_required(tcon))
2529 flags |= CIFS_TRANSFORM_REQ;
2531 memset(rqst, 0, sizeof(rqst));
2532 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2533 memset(rsp_iov, 0, sizeof(rsp_iov));
2535 memset(&open_iov, 0, sizeof(open_iov));
2536 rqst[0].rq_iov = open_iov;
2537 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2540 oparms.desired_access = desired_access;
2541 oparms.disposition = FILE_OPEN;
2542 oparms.create_options = cifs_create_options(cifs_sb, 0);
2544 oparms.reconnect = false;
2546 rc = SMB2_open_init(tcon, server,
2547 &rqst[0], &oplock, &oparms, utf16_path);
2550 smb2_set_next_command(tcon, &rqst[0]);
2552 memset(&qi_iov, 0, sizeof(qi_iov));
2553 rqst[1].rq_iov = qi_iov;
2554 rqst[1].rq_nvec = 1;
2556 rc = SMB2_query_info_init(tcon, server,
2557 &rqst[1], COMPOUND_FID, COMPOUND_FID,
2563 smb2_set_next_command(tcon, &rqst[1]);
2564 smb2_set_related(&rqst[1]);
2566 memset(&close_iov, 0, sizeof(close_iov));
2567 rqst[2].rq_iov = close_iov;
2568 rqst[2].rq_nvec = 1;
2570 rc = SMB2_close_init(tcon, server,
2571 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2574 smb2_set_related(&rqst[2]);
2576 rc = compound_send_recv(xid, ses, server,
2578 resp_buftype, rsp_iov);
2580 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2581 if (rc == -EREMCHG) {
2582 tcon->need_reconnect = true;
2583 pr_warn_once("server share %s deleted\n",
2589 *buftype = resp_buftype[1];
2592 SMB2_open_free(&rqst[0]);
2593 SMB2_query_info_free(&rqst[1]);
2594 SMB2_close_free(&rqst[2]);
2595 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2596 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2601 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2602 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2604 struct smb2_query_info_rsp *rsp;
2605 struct smb2_fs_full_size_info *info = NULL;
2606 __le16 utf16_path = 0; /* Null - open root of share */
2607 struct kvec rsp_iov = {NULL, 0};
2608 int buftype = CIFS_NO_BUFFER;
2612 rc = smb2_query_info_compound(xid, tcon, &utf16_path,
2613 FILE_READ_ATTRIBUTES,
2614 FS_FULL_SIZE_INFORMATION,
2615 SMB2_O_INFO_FILESYSTEM,
2616 sizeof(struct smb2_fs_full_size_info),
2617 &rsp_iov, &buftype, cifs_sb);
2621 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2622 buf->f_type = SMB2_MAGIC_NUMBER;
2623 info = (struct smb2_fs_full_size_info *)(
2624 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2625 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2626 le32_to_cpu(rsp->OutputBufferLength),
2628 sizeof(struct smb2_fs_full_size_info));
2630 smb2_copy_fs_info_to_kstatfs(info, buf);
2633 free_rsp_buf(buftype, rsp_iov.iov_base);
2638 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2639 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2642 __le16 srch_path = 0; /* Null - open root of share */
2643 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2644 struct cifs_open_parms oparms;
2645 struct cifs_fid fid;
2647 if (!tcon->posix_extensions)
2648 return smb2_queryfs(xid, tcon, cifs_sb, buf);
2651 oparms.desired_access = FILE_READ_ATTRIBUTES;
2652 oparms.disposition = FILE_OPEN;
2653 oparms.create_options = cifs_create_options(cifs_sb, 0);
2655 oparms.reconnect = false;
2657 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
2662 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2663 fid.volatile_fid, buf);
2664 buf->f_type = SMB2_MAGIC_NUMBER;
2665 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2670 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2672 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2673 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2677 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2678 __u64 length, __u32 type, int lock, int unlock, bool wait)
2680 if (unlock && !lock)
2681 type = SMB2_LOCKFLAG_UNLOCK;
2682 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2683 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2684 current->tgid, length, offset, type, wait);
2688 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2690 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2694 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2696 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2700 smb2_new_lease_key(struct cifs_fid *fid)
2702 generate_random_uuid(fid->lease_key);
2706 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2707 const char *search_name,
2708 struct dfs_info3_param **target_nodes,
2709 unsigned int *num_of_nodes,
2710 const struct nls_table *nls_codepage, int remap)
2713 __le16 *utf16_path = NULL;
2714 int utf16_path_len = 0;
2715 struct cifs_tcon *tcon;
2716 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2717 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2718 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2720 cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name);
2723 * Try to use the IPC tcon, otherwise just use any
2725 tcon = ses->tcon_ipc;
2727 spin_lock(&cifs_tcp_ses_lock);
2728 tcon = list_first_entry_or_null(&ses->tcon_list,
2733 spin_unlock(&cifs_tcp_ses_lock);
2737 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2743 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2745 nls_codepage, remap);
2751 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2752 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2758 /* Highest DFS referral version understood */
2759 dfs_req->MaxReferralLevel = DFS_VERSION;
2761 /* Path to resolve in an UTF-16 null-terminated string */
2762 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2765 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2766 FSCTL_DFS_GET_REFERRALS,
2767 (char *)dfs_req, dfs_req_size, CIFSMaxBufSize,
2768 (char **)&dfs_rsp, &dfs_rsp_size);
2769 } while (rc == -EAGAIN);
2771 if (!rc && !dfs_rsp)
2774 if ((rc != -ENOENT) && (rc != -EOPNOTSUPP))
2775 cifs_tcon_dbg(VFS, "ioctl error in %s rc=%d\n", __func__, rc);
2779 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
2780 num_of_nodes, target_nodes,
2781 nls_codepage, remap, search_name,
2782 true /* is_unicode */);
2784 cifs_tcon_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc);
2789 if (tcon && !tcon->ipc) {
2790 /* ipc tcons are not refcounted */
2791 spin_lock(&cifs_tcp_ses_lock);
2793 spin_unlock(&cifs_tcp_ses_lock);
2802 parse_reparse_posix(struct reparse_posix_data *symlink_buf,
2803 u32 plen, char **target_path,
2804 struct cifs_sb_info *cifs_sb)
2808 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
2809 len = le16_to_cpu(symlink_buf->ReparseDataLength);
2811 if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
2812 cifs_dbg(VFS, "%lld not a supported symlink type\n",
2813 le64_to_cpu(symlink_buf->InodeType));
2817 *target_path = cifs_strndup_from_utf16(
2818 symlink_buf->PathBuffer,
2819 len, true, cifs_sb->local_nls);
2820 if (!(*target_path))
2823 convert_delimiter(*target_path, '/');
2824 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2830 parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
2831 u32 plen, char **target_path,
2832 struct cifs_sb_info *cifs_sb)
2834 unsigned int sub_len;
2835 unsigned int sub_offset;
2837 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */
2839 sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset);
2840 sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength);
2841 if (sub_offset + 20 > plen ||
2842 sub_offset + sub_len + 20 > plen) {
2843 cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
2847 *target_path = cifs_strndup_from_utf16(
2848 symlink_buf->PathBuffer + sub_offset,
2849 sub_len, true, cifs_sb->local_nls);
2850 if (!(*target_path))
2853 convert_delimiter(*target_path, '/');
2854 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2860 parse_reparse_point(struct reparse_data_buffer *buf,
2861 u32 plen, char **target_path,
2862 struct cifs_sb_info *cifs_sb)
2864 if (plen < sizeof(struct reparse_data_buffer)) {
2865 cifs_dbg(VFS, "reparse buffer is too small. Must be at least 8 bytes but was %d\n",
2870 if (plen < le16_to_cpu(buf->ReparseDataLength) +
2871 sizeof(struct reparse_data_buffer)) {
2872 cifs_dbg(VFS, "srv returned invalid reparse buf length: %d\n",
2877 /* See MS-FSCC 2.1.2 */
2878 switch (le32_to_cpu(buf->ReparseTag)) {
2879 case IO_REPARSE_TAG_NFS:
2880 return parse_reparse_posix(
2881 (struct reparse_posix_data *)buf,
2882 plen, target_path, cifs_sb);
2883 case IO_REPARSE_TAG_SYMLINK:
2884 return parse_reparse_symlink(
2885 (struct reparse_symlink_data_buffer *)buf,
2886 plen, target_path, cifs_sb);
2888 cifs_dbg(VFS, "srv returned unknown symlink buffer tag:0x%08x\n",
2889 le32_to_cpu(buf->ReparseTag));
2894 #define SMB2_SYMLINK_STRUCT_SIZE \
2895 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
2898 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
2899 struct cifs_sb_info *cifs_sb, const char *full_path,
2900 char **target_path, bool is_reparse_point)
2903 __le16 *utf16_path = NULL;
2904 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2905 struct cifs_open_parms oparms;
2906 struct cifs_fid fid;
2907 struct kvec err_iov = {NULL, 0};
2908 struct smb2_err_rsp *err_buf = NULL;
2909 struct smb2_symlink_err_rsp *symlink;
2910 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2911 unsigned int sub_len;
2912 unsigned int sub_offset;
2913 unsigned int print_len;
2914 unsigned int print_offset;
2915 int flags = CIFS_CP_CREATE_CLOSE_OP;
2916 struct smb_rqst rqst[3];
2917 int resp_buftype[3];
2918 struct kvec rsp_iov[3];
2919 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2920 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2921 struct kvec close_iov[1];
2922 struct smb2_create_rsp *create_rsp;
2923 struct smb2_ioctl_rsp *ioctl_rsp;
2924 struct reparse_data_buffer *reparse_buf;
2925 int create_options = is_reparse_point ? OPEN_REPARSE_POINT : 0;
2928 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2930 *target_path = NULL;
2932 if (smb3_encryption_required(tcon))
2933 flags |= CIFS_TRANSFORM_REQ;
2935 memset(rqst, 0, sizeof(rqst));
2936 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2937 memset(rsp_iov, 0, sizeof(rsp_iov));
2939 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
2944 memset(&open_iov, 0, sizeof(open_iov));
2945 rqst[0].rq_iov = open_iov;
2946 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2948 memset(&oparms, 0, sizeof(oparms));
2950 oparms.desired_access = FILE_READ_ATTRIBUTES;
2951 oparms.disposition = FILE_OPEN;
2952 oparms.create_options = cifs_create_options(cifs_sb, create_options);
2954 oparms.reconnect = false;
2956 rc = SMB2_open_init(tcon, server,
2957 &rqst[0], &oplock, &oparms, utf16_path);
2960 smb2_set_next_command(tcon, &rqst[0]);
2964 memset(&io_iov, 0, sizeof(io_iov));
2965 rqst[1].rq_iov = io_iov;
2966 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
2968 rc = SMB2_ioctl_init(tcon, server,
2969 &rqst[1], fid.persistent_fid,
2970 fid.volatile_fid, FSCTL_GET_REPARSE_POINT, NULL, 0,
2972 MAX_SMB2_CREATE_RESPONSE_SIZE -
2973 MAX_SMB2_CLOSE_RESPONSE_SIZE);
2977 smb2_set_next_command(tcon, &rqst[1]);
2978 smb2_set_related(&rqst[1]);
2982 memset(&close_iov, 0, sizeof(close_iov));
2983 rqst[2].rq_iov = close_iov;
2984 rqst[2].rq_nvec = 1;
2986 rc = SMB2_close_init(tcon, server,
2987 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2991 smb2_set_related(&rqst[2]);
2993 rc = compound_send_recv(xid, tcon->ses, server,
2995 resp_buftype, rsp_iov);
2997 create_rsp = rsp_iov[0].iov_base;
2998 if (create_rsp && create_rsp->sync_hdr.Status)
2999 err_iov = rsp_iov[0];
3000 ioctl_rsp = rsp_iov[1].iov_base;
3003 * Open was successful and we got an ioctl response.
3005 if ((rc == 0) && (is_reparse_point)) {
3006 /* See MS-FSCC 2.3.23 */
3008 reparse_buf = (struct reparse_data_buffer *)
3009 ((char *)ioctl_rsp +
3010 le32_to_cpu(ioctl_rsp->OutputOffset));
3011 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3013 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3014 rsp_iov[1].iov_len) {
3015 cifs_tcon_dbg(VFS, "srv returned invalid ioctl len: %d\n",
3021 rc = parse_reparse_point(reparse_buf, plen, target_path,
3026 if (!rc || !err_iov.iov_base) {
3031 err_buf = err_iov.iov_base;
3032 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
3033 err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) {
3038 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
3039 if (le32_to_cpu(symlink->SymLinkErrorTag) != SYMLINK_ERROR_TAG ||
3040 le32_to_cpu(symlink->ReparseTag) != IO_REPARSE_TAG_SYMLINK) {
3045 /* open must fail on symlink - reset rc */
3047 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
3048 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
3049 print_len = le16_to_cpu(symlink->PrintNameLength);
3050 print_offset = le16_to_cpu(symlink->PrintNameOffset);
3052 if (err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
3057 if (err_iov.iov_len <
3058 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
3063 *target_path = cifs_strndup_from_utf16(
3064 (char *)symlink->PathBuffer + sub_offset,
3065 sub_len, true, cifs_sb->local_nls);
3066 if (!(*target_path)) {
3070 convert_delimiter(*target_path, '/');
3071 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
3074 cifs_dbg(FYI, "query symlink rc %d\n", rc);
3076 SMB2_open_free(&rqst[0]);
3077 SMB2_ioctl_free(&rqst[1]);
3078 SMB2_close_free(&rqst[2]);
3079 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3080 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3081 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3086 smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
3087 struct cifs_sb_info *cifs_sb, const char *full_path,
3091 __le16 *utf16_path = NULL;
3092 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3093 struct cifs_open_parms oparms;
3094 struct cifs_fid fid;
3095 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
3096 int flags = CIFS_CP_CREATE_CLOSE_OP;
3097 struct smb_rqst rqst[3];
3098 int resp_buftype[3];
3099 struct kvec rsp_iov[3];
3100 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
3101 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
3102 struct kvec close_iov[1];
3103 struct smb2_ioctl_rsp *ioctl_rsp;
3104 struct reparse_data_buffer *reparse_buf;
3105 u32 off, count, len;
3107 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
3109 if (smb3_encryption_required(tcon))
3110 flags |= CIFS_TRANSFORM_REQ;
3112 memset(rqst, 0, sizeof(rqst));
3113 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
3114 memset(rsp_iov, 0, sizeof(rsp_iov));
3116 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
3121 * setup smb2open - TODO add optimization to call cifs_get_readable_path
3122 * to see if there is a handle already open that we can use
3124 memset(&open_iov, 0, sizeof(open_iov));
3125 rqst[0].rq_iov = open_iov;
3126 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
3128 memset(&oparms, 0, sizeof(oparms));
3130 oparms.desired_access = FILE_READ_ATTRIBUTES;
3131 oparms.disposition = FILE_OPEN;
3132 oparms.create_options = cifs_create_options(cifs_sb, OPEN_REPARSE_POINT);
3134 oparms.reconnect = false;
3136 rc = SMB2_open_init(tcon, server,
3137 &rqst[0], &oplock, &oparms, utf16_path);
3140 smb2_set_next_command(tcon, &rqst[0]);
3144 memset(&io_iov, 0, sizeof(io_iov));
3145 rqst[1].rq_iov = io_iov;
3146 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3148 rc = SMB2_ioctl_init(tcon, server,
3149 &rqst[1], COMPOUND_FID,
3150 COMPOUND_FID, FSCTL_GET_REPARSE_POINT, NULL, 0,
3152 MAX_SMB2_CREATE_RESPONSE_SIZE -
3153 MAX_SMB2_CLOSE_RESPONSE_SIZE);
3157 smb2_set_next_command(tcon, &rqst[1]);
3158 smb2_set_related(&rqst[1]);
3162 memset(&close_iov, 0, sizeof(close_iov));
3163 rqst[2].rq_iov = close_iov;
3164 rqst[2].rq_nvec = 1;
3166 rc = SMB2_close_init(tcon, server,
3167 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3171 smb2_set_related(&rqst[2]);
3173 rc = compound_send_recv(xid, tcon->ses, server,
3175 resp_buftype, rsp_iov);
3177 ioctl_rsp = rsp_iov[1].iov_base;
3180 * Open was successful and we got an ioctl response.
3183 /* See MS-FSCC 2.3.23 */
3184 off = le32_to_cpu(ioctl_rsp->OutputOffset);
3185 count = le32_to_cpu(ioctl_rsp->OutputCount);
3186 if (check_add_overflow(off, count, &len) ||
3187 len > rsp_iov[1].iov_len) {
3188 cifs_tcon_dbg(VFS, "%s: invalid ioctl: off=%d count=%d\n",
3189 __func__, off, count);
3194 reparse_buf = (void *)((u8 *)ioctl_rsp + off);
3195 len = sizeof(*reparse_buf);
3197 count < le16_to_cpu(reparse_buf->ReparseDataLength) + len) {
3198 cifs_tcon_dbg(VFS, "%s: invalid ioctl: off=%d count=%d\n",
3199 __func__, off, count);
3203 *tag = le32_to_cpu(reparse_buf->ReparseTag);
3208 SMB2_open_free(&rqst[0]);
3209 SMB2_ioctl_free(&rqst[1]);
3210 SMB2_close_free(&rqst[2]);
3211 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3212 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3213 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3217 static struct cifs_ntsd *
3218 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
3219 const struct cifs_fid *cifsfid, u32 *pacllen)
3221 struct cifs_ntsd *pntsd = NULL;
3223 int rc = -EOPNOTSUPP;
3224 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3227 return ERR_CAST(tlink);
3230 cifs_dbg(FYI, "trying to get acl\n");
3232 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
3233 cifsfid->volatile_fid, (void **)&pntsd, pacllen);
3236 cifs_put_tlink(tlink);
3238 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3245 static struct cifs_ntsd *
3246 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
3247 const char *path, u32 *pacllen)
3249 struct cifs_ntsd *pntsd = NULL;
3250 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3253 struct cifs_tcon *tcon;
3254 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3255 struct cifs_fid fid;
3256 struct cifs_open_parms oparms;
3259 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
3261 return ERR_CAST(tlink);
3263 tcon = tlink_tcon(tlink);
3266 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3274 oparms.desired_access = READ_CONTROL;
3275 oparms.disposition = FILE_OPEN;
3277 * When querying an ACL, even if the file is a symlink we want to open
3278 * the source not the target, and so the protocol requires that the
3279 * client specify this flag when opening a reparse point
3281 oparms.create_options = cifs_create_options(cifs_sb, 0) | OPEN_REPARSE_POINT;
3283 oparms.reconnect = false;
3285 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
3289 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3290 fid.volatile_fid, (void **)&pntsd, pacllen);
3291 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3294 cifs_put_tlink(tlink);
3297 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3304 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
3305 struct inode *inode, const char *path, int aclflag)
3307 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3309 int rc, access_flags = 0;
3310 struct cifs_tcon *tcon;
3311 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
3312 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3313 struct cifs_fid fid;
3314 struct cifs_open_parms oparms;
3317 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
3319 return PTR_ERR(tlink);
3321 tcon = tlink_tcon(tlink);
3324 if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP)
3325 access_flags = WRITE_OWNER;
3327 access_flags = WRITE_DAC;
3329 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3337 oparms.desired_access = access_flags;
3338 oparms.create_options = cifs_create_options(cifs_sb, 0);
3339 oparms.disposition = FILE_OPEN;
3342 oparms.reconnect = false;
3344 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
3348 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3349 fid.volatile_fid, pnntsd, acllen, aclflag);
3350 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3353 cifs_put_tlink(tlink);
3358 /* Retrieve an ACL from the server */
3359 static struct cifs_ntsd *
3360 get_smb2_acl(struct cifs_sb_info *cifs_sb,
3361 struct inode *inode, const char *path,
3364 struct cifs_ntsd *pntsd = NULL;
3365 struct cifsFileInfo *open_file = NULL;
3368 open_file = find_readable_file(CIFS_I(inode), true);
3370 return get_smb2_acl_by_path(cifs_sb, path, pacllen);
3372 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen);
3373 cifsFileInfo_put(open_file);
3377 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3378 loff_t offset, loff_t len, bool keep_size)
3380 struct cifs_ses *ses = tcon->ses;
3381 struct inode *inode;
3382 struct cifsInodeInfo *cifsi;
3383 struct cifsFileInfo *cfile = file->private_data;
3384 struct file_zero_data_information fsctl_buf;
3391 inode = d_inode(cfile->dentry);
3392 cifsi = CIFS_I(inode);
3394 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3395 ses->Suid, offset, len);
3398 * We zero the range through ioctl, so we need remove the page caches
3399 * first, otherwise the data may be inconsistent with the server.
3401 truncate_pagecache_range(inode, offset, offset + len - 1);
3403 /* if file not oplocked can't be sure whether asking to extend size */
3404 if (!CIFS_CACHE_READ(cifsi))
3405 if (keep_size == false) {
3407 trace_smb3_zero_err(xid, cfile->fid.persistent_fid,
3408 tcon->tid, ses->Suid, offset, len, rc);
3413 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3415 fsctl_buf.FileOffset = cpu_to_le64(offset);
3416 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3418 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3419 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3421 sizeof(struct file_zero_data_information),
3424 goto zero_range_exit;
3427 * do we also need to change the size of the file?
3429 if (keep_size == false && i_size_read(inode) < offset + len) {
3430 eof = cpu_to_le64(offset + len);
3431 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3432 cfile->fid.volatile_fid, cfile->pid, &eof);
3438 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
3439 ses->Suid, offset, len, rc);
3441 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
3442 ses->Suid, offset, len);
3446 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
3447 loff_t offset, loff_t len)
3449 struct inode *inode = file_inode(file);
3450 struct cifsFileInfo *cfile = file->private_data;
3451 struct file_zero_data_information fsctl_buf;
3454 __u8 set_sparse = 1;
3459 /* Need to make file sparse, if not already, before freeing range. */
3460 /* Consider adding equivalent for compressed since it could also work */
3461 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
3467 * We implement the punch hole through ioctl, so we need remove the page
3468 * caches first, otherwise the data may be inconsistent with the server.
3470 truncate_pagecache_range(inode, offset, offset + len - 1);
3472 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3474 fsctl_buf.FileOffset = cpu_to_le64(offset);
3475 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3477 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3478 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3480 sizeof(struct file_zero_data_information),
3481 CIFSMaxBufSize, NULL, NULL);
3483 inode_unlock(inode);
3488 static int smb3_simple_fallocate_write_range(unsigned int xid,
3489 struct cifs_tcon *tcon,
3490 struct cifsFileInfo *cfile,
3491 loff_t off, loff_t len,
3494 struct cifs_io_parms io_parms = {0};
3499 io_parms.netfid = cfile->fid.netfid;
3500 io_parms.pid = current->tgid;
3501 io_parms.tcon = tcon;
3502 io_parms.persistent_fid = cfile->fid.persistent_fid;
3503 io_parms.volatile_fid = cfile->fid.volatile_fid;
3506 io_parms.offset = off;
3507 io_parms.length = len;
3508 if (io_parms.length > SMB2_MAX_BUFFER_SIZE)
3509 io_parms.length = SMB2_MAX_BUFFER_SIZE;
3510 /* iov[0] is reserved for smb header */
3511 iov[1].iov_base = buf;
3512 iov[1].iov_len = io_parms.length;
3513 rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
3525 static int smb3_simple_fallocate_range(unsigned int xid,
3526 struct cifs_tcon *tcon,
3527 struct cifsFileInfo *cfile,
3528 loff_t off, loff_t len)
3530 struct file_allocated_range_buffer in_data, *out_data = NULL, *tmp_data;
3536 in_data.file_offset = cpu_to_le64(off);
3537 in_data.length = cpu_to_le64(len);
3538 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3539 cfile->fid.volatile_fid,
3540 FSCTL_QUERY_ALLOCATED_RANGES,
3541 (char *)&in_data, sizeof(in_data),
3542 1024 * sizeof(struct file_allocated_range_buffer),
3543 (char **)&out_data, &out_data_len);
3547 buf = kzalloc(1024 * 1024, GFP_KERNEL);
3553 tmp_data = out_data;
3556 * The rest of the region is unmapped so write it all.
3558 if (out_data_len == 0) {
3559 rc = smb3_simple_fallocate_write_range(xid, tcon,
3560 cfile, off, len, buf);
3564 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3569 if (off < le64_to_cpu(tmp_data->file_offset)) {
3571 * We are at a hole. Write until the end of the region
3572 * or until the next allocated data,
3573 * whichever comes next.
3575 l = le64_to_cpu(tmp_data->file_offset) - off;
3578 rc = smb3_simple_fallocate_write_range(xid, tcon,
3579 cfile, off, l, buf);
3588 * We are at a section of allocated data, just skip forward
3589 * until the end of the data or the end of the region
3590 * we are supposed to fallocate, whichever comes first.
3592 l = le64_to_cpu(tmp_data->length);
3598 tmp_data = &tmp_data[1];
3599 out_data_len -= sizeof(struct file_allocated_range_buffer);
3609 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3610 loff_t off, loff_t len, bool keep_size)
3612 struct inode *inode;
3613 struct cifsInodeInfo *cifsi;
3614 struct cifsFileInfo *cfile = file->private_data;
3615 long rc = -EOPNOTSUPP;
3621 inode = d_inode(cfile->dentry);
3622 cifsi = CIFS_I(inode);
3624 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3625 tcon->ses->Suid, off, len);
3626 /* if file not oplocked can't be sure whether asking to extend size */
3627 if (!CIFS_CACHE_READ(cifsi))
3628 if (keep_size == false) {
3629 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3630 tcon->tid, tcon->ses->Suid, off, len, rc);
3636 * Extending the file
3638 if ((keep_size == false) && i_size_read(inode) < off + len) {
3639 rc = inode_newsize_ok(inode, off + len);
3643 if (cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)
3644 smb2_set_sparse(xid, tcon, cfile, inode, false);
3646 eof = cpu_to_le64(off + len);
3647 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3648 cfile->fid.volatile_fid, cfile->pid, &eof);
3650 cifsi->server_eof = off + len;
3651 cifs_setsize(inode, off + len);
3652 cifs_truncate_page(inode->i_mapping, inode->i_size);
3653 truncate_setsize(inode, off + len);
3659 * Files are non-sparse by default so falloc may be a no-op
3660 * Must check if file sparse. If not sparse, and since we are not
3661 * extending then no need to do anything since file already allocated
3663 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
3668 if (keep_size == true) {
3670 * We can not preallocate pages beyond the end of the file
3673 if (off >= i_size_read(inode)) {
3678 * For fallocates that are partially beyond the end of file,
3679 * clamp len so we only fallocate up to the end of file.
3681 if (off + len > i_size_read(inode)) {
3682 len = i_size_read(inode) - off;
3686 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3688 * At this point, we are trying to fallocate an internal
3689 * regions of a sparse file. Since smb2 does not have a
3690 * fallocate command we have two otions on how to emulate this.
3691 * We can either turn the entire file to become non-sparse
3692 * which we only do if the fallocate is for virtually
3693 * the whole file, or we can overwrite the region with zeroes
3694 * using SMB2_write, which could be prohibitevly expensive
3698 * We are only trying to fallocate a small region so
3699 * just write it with zero.
3701 if (len <= 1024 * 1024) {
3702 rc = smb3_simple_fallocate_range(xid, tcon, cfile,
3708 * Check if falloc starts within first few pages of file
3709 * and ends within a few pages of the end of file to
3710 * ensure that most of file is being forced to be
3711 * fallocated now. If so then setting whole file sparse
3712 * ie potentially making a few extra pages at the beginning
3713 * or end of the file non-sparse via set_sparse is harmless.
3715 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
3721 smb2_set_sparse(xid, tcon, cfile, inode, false);
3726 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3727 tcon->ses->Suid, off, len, rc);
3729 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3730 tcon->ses->Suid, off, len);
3736 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3738 struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3739 struct cifsInodeInfo *cifsi;
3740 struct inode *inode;
3742 struct file_allocated_range_buffer in_data, *out_data = NULL;
3746 if (whence != SEEK_HOLE && whence != SEEK_DATA)
3747 return generic_file_llseek(file, offset, whence);
3749 inode = d_inode(cfile->dentry);
3750 cifsi = CIFS_I(inode);
3752 if (offset < 0 || offset >= i_size_read(inode))
3757 * We need to be sure that all dirty pages are written as they
3758 * might fill holes on the server.
3759 * Note that we also MUST flush any written pages since at least
3760 * some servers (Windows2016) will not reflect recent writes in
3761 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3763 wrcfile = find_writable_file(cifsi, FIND_WR_ANY);
3765 filemap_write_and_wait(inode->i_mapping);
3766 smb2_flush_file(xid, tcon, &wrcfile->fid);
3767 cifsFileInfo_put(wrcfile);
3770 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3771 if (whence == SEEK_HOLE)
3772 offset = i_size_read(inode);
3776 in_data.file_offset = cpu_to_le64(offset);
3777 in_data.length = cpu_to_le64(i_size_read(inode));
3779 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3780 cfile->fid.volatile_fid,
3781 FSCTL_QUERY_ALLOCATED_RANGES,
3782 (char *)&in_data, sizeof(in_data),
3783 sizeof(struct file_allocated_range_buffer),
3784 (char **)&out_data, &out_data_len);
3790 if (whence == SEEK_HOLE && out_data_len == 0)
3793 if (whence == SEEK_DATA && out_data_len == 0) {
3798 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3802 if (whence == SEEK_DATA) {
3803 offset = le64_to_cpu(out_data->file_offset);
3806 if (offset < le64_to_cpu(out_data->file_offset))
3809 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3815 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3820 static int smb3_fiemap(struct cifs_tcon *tcon,
3821 struct cifsFileInfo *cfile,
3822 struct fiemap_extent_info *fei, u64 start, u64 len)
3825 struct file_allocated_range_buffer in_data, *out_data;
3827 int i, num, rc, flags, last_blob;
3830 rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0);
3836 in_data.file_offset = cpu_to_le64(start);
3837 in_data.length = cpu_to_le64(len);
3839 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3840 cfile->fid.volatile_fid,
3841 FSCTL_QUERY_ALLOCATED_RANGES,
3842 (char *)&in_data, sizeof(in_data),
3843 1024 * sizeof(struct file_allocated_range_buffer),
3844 (char **)&out_data, &out_data_len);
3853 if (out_data_len && out_data_len < sizeof(struct file_allocated_range_buffer)) {
3857 if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3862 num = out_data_len / sizeof(struct file_allocated_range_buffer);
3863 for (i = 0; i < num; i++) {
3865 if (i == num - 1 && last_blob)
3866 flags |= FIEMAP_EXTENT_LAST;
3868 rc = fiemap_fill_next_extent(fei,
3869 le64_to_cpu(out_data[i].file_offset),
3870 le64_to_cpu(out_data[i].file_offset),
3871 le64_to_cpu(out_data[i].length),
3882 next = le64_to_cpu(out_data[num - 1].file_offset) +
3883 le64_to_cpu(out_data[num - 1].length);
3884 len = len - (next - start);
3895 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
3896 loff_t off, loff_t len)
3898 /* KEEP_SIZE already checked for by do_fallocate */
3899 if (mode & FALLOC_FL_PUNCH_HOLE)
3900 return smb3_punch_hole(file, tcon, off, len);
3901 else if (mode & FALLOC_FL_ZERO_RANGE) {
3902 if (mode & FALLOC_FL_KEEP_SIZE)
3903 return smb3_zero_range(file, tcon, off, len, true);
3904 return smb3_zero_range(file, tcon, off, len, false);
3905 } else if (mode == FALLOC_FL_KEEP_SIZE)
3906 return smb3_simple_falloc(file, tcon, off, len, true);
3908 return smb3_simple_falloc(file, tcon, off, len, false);
3914 smb2_downgrade_oplock(struct TCP_Server_Info *server,
3915 struct cifsInodeInfo *cinode, __u32 oplock,
3916 unsigned int epoch, bool *purge_cache)
3918 server->ops->set_oplock_level(cinode, oplock, 0, NULL);
3922 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3923 unsigned int epoch, bool *purge_cache);
3926 smb3_downgrade_oplock(struct TCP_Server_Info *server,
3927 struct cifsInodeInfo *cinode, __u32 oplock,
3928 unsigned int epoch, bool *purge_cache)
3930 unsigned int old_state = cinode->oplock;
3931 unsigned int old_epoch = cinode->epoch;
3932 unsigned int new_state;
3934 if (epoch > old_epoch) {
3935 smb21_set_oplock_level(cinode, oplock, 0, NULL);
3936 cinode->epoch = epoch;
3939 new_state = cinode->oplock;
3940 *purge_cache = false;
3942 if ((old_state & CIFS_CACHE_READ_FLG) != 0 &&
3943 (new_state & CIFS_CACHE_READ_FLG) == 0)
3944 *purge_cache = true;
3945 else if (old_state == new_state && (epoch - old_epoch > 1))
3946 *purge_cache = true;
3950 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3951 unsigned int epoch, bool *purge_cache)
3954 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3956 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
3957 cinode->oplock = CIFS_CACHE_RHW_FLG;
3958 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
3959 &cinode->vfs_inode);
3960 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
3961 cinode->oplock = CIFS_CACHE_RW_FLG;
3962 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
3963 &cinode->vfs_inode);
3964 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
3965 cinode->oplock = CIFS_CACHE_READ_FLG;
3966 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
3967 &cinode->vfs_inode);
3973 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3974 unsigned int epoch, bool *purge_cache)
3976 char message[5] = {0};
3977 unsigned int new_oplock = 0;
3980 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3983 /* Check if the server granted an oplock rather than a lease */
3984 if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE)
3985 return smb2_set_oplock_level(cinode, oplock, epoch,
3988 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
3989 new_oplock |= CIFS_CACHE_READ_FLG;
3990 strcat(message, "R");
3992 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
3993 new_oplock |= CIFS_CACHE_HANDLE_FLG;
3994 strcat(message, "H");
3996 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
3997 new_oplock |= CIFS_CACHE_WRITE_FLG;
3998 strcat(message, "W");
4001 strncpy(message, "None", sizeof(message));
4003 cinode->oplock = new_oplock;
4004 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
4005 &cinode->vfs_inode);
4009 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4010 unsigned int epoch, bool *purge_cache)
4012 unsigned int old_oplock = cinode->oplock;
4014 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
4017 *purge_cache = false;
4018 if (old_oplock == CIFS_CACHE_READ_FLG) {
4019 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
4020 (epoch - cinode->epoch > 0))
4021 *purge_cache = true;
4022 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4023 (epoch - cinode->epoch > 1))
4024 *purge_cache = true;
4025 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4026 (epoch - cinode->epoch > 1))
4027 *purge_cache = true;
4028 else if (cinode->oplock == 0 &&
4029 (epoch - cinode->epoch > 0))
4030 *purge_cache = true;
4031 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
4032 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4033 (epoch - cinode->epoch > 0))
4034 *purge_cache = true;
4035 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4036 (epoch - cinode->epoch > 1))
4037 *purge_cache = true;
4039 cinode->epoch = epoch;
4043 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
4045 smb2_is_read_op(__u32 oplock)
4047 return oplock == SMB2_OPLOCK_LEVEL_II;
4049 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
4052 smb21_is_read_op(__u32 oplock)
4054 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
4055 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
4059 map_oplock_to_lease(u8 oplock)
4061 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4062 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
4063 else if (oplock == SMB2_OPLOCK_LEVEL_II)
4064 return SMB2_LEASE_READ_CACHING;
4065 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
4066 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
4067 SMB2_LEASE_WRITE_CACHING;
4072 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
4074 struct create_lease *buf;
4076 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
4080 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4081 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4083 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4084 (struct create_lease, lcontext));
4085 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
4086 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4087 (struct create_lease, Name));
4088 buf->ccontext.NameLength = cpu_to_le16(4);
4089 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4098 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
4100 struct create_lease_v2 *buf;
4102 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
4106 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4107 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4109 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4110 (struct create_lease_v2, lcontext));
4111 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
4112 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4113 (struct create_lease_v2, Name));
4114 buf->ccontext.NameLength = cpu_to_le16(4);
4115 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4124 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4126 struct create_lease *lc = (struct create_lease *)buf;
4128 *epoch = 0; /* not used */
4129 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
4130 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4131 return le32_to_cpu(lc->lcontext.LeaseState);
4135 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4137 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
4139 *epoch = le16_to_cpu(lc->lcontext.Epoch);
4140 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
4141 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4143 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
4144 return le32_to_cpu(lc->lcontext.LeaseState);
4148 smb2_wp_retry_size(struct inode *inode)
4150 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
4151 SMB2_MAX_BUFFER_SIZE);
4155 smb2_dir_needs_close(struct cifsFileInfo *cfile)
4157 return !cfile->invalidHandle;
4161 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
4162 struct smb_rqst *old_rq, __le16 cipher_type)
4164 struct smb2_sync_hdr *shdr =
4165 (struct smb2_sync_hdr *)old_rq->rq_iov[0].iov_base;
4167 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
4168 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
4169 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
4170 tr_hdr->Flags = cpu_to_le16(0x01);
4171 if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4172 (cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4173 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4175 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4176 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
4179 static void *smb2_aead_req_alloc(struct crypto_aead *tfm, const struct smb_rqst *rqst,
4180 int num_rqst, const u8 *sig, u8 **iv,
4181 struct aead_request **req, struct scatterlist **sgl,
4182 unsigned int *num_sgs)
4184 unsigned int req_size = sizeof(**req) + crypto_aead_reqsize(tfm);
4185 unsigned int iv_size = crypto_aead_ivsize(tfm);
4189 *num_sgs = cifs_get_num_sgs(rqst, num_rqst, sig);
4192 len += crypto_aead_alignmask(tfm) & ~(crypto_tfm_ctx_alignment() - 1);
4193 len = ALIGN(len, crypto_tfm_ctx_alignment());
4195 len = ALIGN(len, __alignof__(struct scatterlist));
4196 len += *num_sgs * sizeof(**sgl);
4198 p = kmalloc(len, GFP_ATOMIC);
4202 *iv = (u8 *)PTR_ALIGN(p, crypto_aead_alignmask(tfm) + 1);
4203 *req = (struct aead_request *)PTR_ALIGN(*iv + iv_size,
4204 crypto_tfm_ctx_alignment());
4205 *sgl = (struct scatterlist *)PTR_ALIGN((u8 *)*req + req_size,
4206 __alignof__(struct scatterlist));
4210 static void *smb2_get_aead_req(struct crypto_aead *tfm, const struct smb_rqst *rqst,
4211 int num_rqst, const u8 *sig, u8 **iv,
4212 struct aead_request **req, struct scatterlist **sgl)
4214 unsigned int off, len, skip;
4215 struct scatterlist *sg;
4216 unsigned int num_sgs;
4221 p = smb2_aead_req_alloc(tfm, rqst, num_rqst, sig, iv, req, sgl, &num_sgs);
4225 sg_init_table(*sgl, num_sgs);
4228 /* Assumes the first rqst has a transform header as the first iov.
4230 * rqst[0].rq_iov[0] is transform header
4231 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
4232 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
4234 for (i = 0; i < num_rqst; i++) {
4236 * The first rqst has a transform header where the
4237 * first 20 bytes are not part of the encrypted blob.
4239 for (j = 0; j < rqst[i].rq_nvec; j++) {
4240 struct kvec *iov = &rqst[i].rq_iov[j];
4242 skip = (i == 0) && (j == 0) ? 20 : 0;
4243 addr = (unsigned long)iov->iov_base + skip;
4244 len = iov->iov_len - skip;
4245 sg = cifs_sg_set_buf(sg, (void *)addr, len);
4247 for (j = 0; j < rqst[i].rq_npages; j++) {
4248 rqst_page_get_length(&rqst[i], j, &len, &off);
4249 sg_set_page(sg++, rqst[i].rq_pages[j], len, off);
4252 cifs_sg_set_buf(sg, sig, SMB2_SIGNATURE_SIZE);
4258 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
4260 struct cifs_ses *ses;
4263 spin_lock(&cifs_tcp_ses_lock);
4264 list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
4265 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
4266 if (ses->Suid == ses_id) {
4267 ses_enc_key = enc ? ses->smb3encryptionkey :
4268 ses->smb3decryptionkey;
4269 memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE);
4270 spin_unlock(&cifs_tcp_ses_lock);
4275 spin_unlock(&cifs_tcp_ses_lock);
4280 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
4281 * iov[0] - transform header (associate data),
4282 * iov[1-N] - SMB2 header and pages - data to encrypt.
4283 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4287 crypt_message(struct TCP_Server_Info *server, int num_rqst,
4288 struct smb_rqst *rqst, int enc)
4290 struct smb2_transform_hdr *tr_hdr =
4291 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
4292 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
4294 struct scatterlist *sg;
4295 u8 sign[SMB2_SIGNATURE_SIZE] = {};
4296 u8 key[SMB3_ENC_DEC_KEY_SIZE];
4297 struct aead_request *req;
4299 DECLARE_CRYPTO_WAIT(wait);
4300 struct crypto_aead *tfm;
4301 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4304 rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key);
4306 cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
4311 rc = smb3_crypto_aead_allocate(server);
4313 cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
4317 tfm = enc ? server->secmech.ccmaesencrypt :
4318 server->secmech.ccmaesdecrypt;
4320 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
4321 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4322 rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
4324 rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE);
4327 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
4331 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
4333 cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
4337 creq = smb2_get_aead_req(tfm, rqst, num_rqst, sign, &iv, &req, &sg);
4338 if (unlikely(!creq))
4342 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
4343 crypt_len += SMB2_SIGNATURE_SIZE;
4346 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4347 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4348 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4351 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4354 aead_request_set_tfm(req, tfm);
4355 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
4356 aead_request_set_ad(req, assoc_data_len);
4358 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
4359 crypto_req_done, &wait);
4361 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
4362 : crypto_aead_decrypt(req), &wait);
4365 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
4367 kfree_sensitive(creq);
4372 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
4376 for (i = 0; i < num_rqst; i++) {
4377 if (rqst[i].rq_pages) {
4378 for (j = rqst[i].rq_npages - 1; j >= 0; j--)
4379 put_page(rqst[i].rq_pages[j]);
4380 kfree(rqst[i].rq_pages);
4386 * This function will initialize new_rq and encrypt the content.
4387 * The first entry, new_rq[0], only contains a single iov which contains
4388 * a smb2_transform_hdr and is pre-allocated by the caller.
4389 * This function then populates new_rq[1+] with the content from olq_rq[0+].
4391 * The end result is an array of smb_rqst structures where the first structure
4392 * only contains a single iov for the transform header which we then can pass
4393 * to crypt_message().
4395 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4396 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
4399 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
4400 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
4402 struct page **pages;
4403 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
4404 unsigned int npages;
4405 unsigned int orig_len = 0;
4409 for (i = 1; i < num_rqst; i++) {
4410 npages = old_rq[i - 1].rq_npages;
4411 pages = kmalloc_array(npages, sizeof(struct page *),
4416 new_rq[i].rq_pages = pages;
4417 new_rq[i].rq_npages = npages;
4418 new_rq[i].rq_offset = old_rq[i - 1].rq_offset;
4419 new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz;
4420 new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz;
4421 new_rq[i].rq_iov = old_rq[i - 1].rq_iov;
4422 new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec;
4424 orig_len += smb_rqst_len(server, &old_rq[i - 1]);
4426 for (j = 0; j < npages; j++) {
4427 pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4432 /* copy pages form the old */
4433 for (j = 0; j < npages; j++) {
4435 unsigned int offset, len;
4437 rqst_page_get_length(&new_rq[i], j, &len, &offset);
4439 dst = (char *) kmap(new_rq[i].rq_pages[j]) + offset;
4440 src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset;
4442 memcpy(dst, src, len);
4443 kunmap(new_rq[i].rq_pages[j]);
4444 kunmap(old_rq[i - 1].rq_pages[j]);
4448 /* fill the 1st iov with a transform header */
4449 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
4451 rc = crypt_message(server, num_rqst, new_rq, 1);
4452 cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
4459 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
4464 smb3_is_transform_hdr(void *buf)
4466 struct smb2_transform_hdr *trhdr = buf;
4468 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
4472 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
4473 unsigned int buf_data_size, struct page **pages,
4474 unsigned int npages, unsigned int page_data_size,
4478 struct smb_rqst rqst = {NULL};
4481 iov[0].iov_base = buf;
4482 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
4483 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
4484 iov[1].iov_len = buf_data_size;
4488 rqst.rq_pages = pages;
4489 rqst.rq_npages = npages;
4490 rqst.rq_pagesz = PAGE_SIZE;
4491 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
4493 rc = crypt_message(server, 1, &rqst, 0);
4494 cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
4499 memmove(buf, iov[1].iov_base, buf_data_size);
4502 server->total_read = buf_data_size + page_data_size;
4508 read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
4509 unsigned int npages, unsigned int len)
4514 for (i = 0; i < npages; i++) {
4515 struct page *page = pages[i];
4519 if (len >= PAGE_SIZE) {
4520 /* enough data to fill the page */
4524 zero_user(page, len, PAGE_SIZE - len);
4527 length = cifs_read_page_from_socket(server, page, 0, n);
4530 server->total_read += length;
4537 init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
4538 unsigned int cur_off, struct bio_vec **page_vec)
4540 struct bio_vec *bvec;
4543 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
4547 for (i = 0; i < npages; i++) {
4548 bvec[i].bv_page = pages[i];
4549 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
4550 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
4551 data_size -= bvec[i].bv_len;
4554 if (data_size != 0) {
4555 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
4565 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
4566 char *buf, unsigned int buf_len, struct page **pages,
4567 unsigned int npages, unsigned int page_data_size,
4570 unsigned int data_offset;
4571 unsigned int data_len;
4572 unsigned int cur_off;
4573 unsigned int cur_page_idx;
4574 unsigned int pad_len;
4575 struct cifs_readdata *rdata = mid->callback_data;
4576 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
4577 struct bio_vec *bvec = NULL;
4578 struct iov_iter iter;
4581 bool use_rdma_mr = false;
4583 if (shdr->Command != SMB2_READ) {
4584 cifs_server_dbg(VFS, "only big read responses are supported\n");
4588 if (server->ops->is_session_expired &&
4589 server->ops->is_session_expired(buf)) {
4591 cifs_reconnect(server);
4595 if (server->ops->is_status_pending &&
4596 server->ops->is_status_pending(buf, server))
4599 /* set up first two iov to get credits */
4600 rdata->iov[0].iov_base = buf;
4601 rdata->iov[0].iov_len = 0;
4602 rdata->iov[1].iov_base = buf;
4603 rdata->iov[1].iov_len =
4604 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
4605 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
4606 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
4607 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
4608 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
4610 rdata->result = server->ops->map_error(buf, true);
4611 if (rdata->result != 0) {
4612 cifs_dbg(FYI, "%s: server returned error %d\n",
4613 __func__, rdata->result);
4614 /* normal error on read response */
4616 mid->mid_state = MID_RESPONSE_RECEIVED;
4618 dequeue_mid(mid, false);
4622 data_offset = server->ops->read_data_offset(buf);
4623 #ifdef CONFIG_CIFS_SMB_DIRECT
4624 use_rdma_mr = rdata->mr;
4626 data_len = server->ops->read_data_length(buf, use_rdma_mr);
4628 if (data_offset < server->vals->read_rsp_size) {
4630 * win2k8 sometimes sends an offset of 0 when the read
4631 * is beyond the EOF. Treat it as if the data starts just after
4634 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
4635 __func__, data_offset);
4636 data_offset = server->vals->read_rsp_size;
4637 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
4638 /* data_offset is beyond the end of smallbuf */
4639 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
4640 __func__, data_offset);
4641 rdata->result = -EIO;
4643 mid->mid_state = MID_RESPONSE_MALFORMED;
4645 dequeue_mid(mid, rdata->result);
4649 pad_len = data_offset - server->vals->read_rsp_size;
4651 if (buf_len <= data_offset) {
4652 /* read response payload is in pages */
4653 cur_page_idx = pad_len / PAGE_SIZE;
4654 cur_off = pad_len % PAGE_SIZE;
4656 if (cur_page_idx != 0) {
4657 /* data offset is beyond the 1st page of response */
4658 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
4659 __func__, data_offset);
4660 rdata->result = -EIO;
4662 mid->mid_state = MID_RESPONSE_MALFORMED;
4664 dequeue_mid(mid, rdata->result);
4668 if (data_len > page_data_size - pad_len) {
4669 /* data_len is corrupt -- discard frame */
4670 rdata->result = -EIO;
4672 mid->mid_state = MID_RESPONSE_MALFORMED;
4674 dequeue_mid(mid, rdata->result);
4678 rdata->result = init_read_bvec(pages, npages, page_data_size,
4680 if (rdata->result != 0) {
4682 mid->mid_state = MID_RESPONSE_MALFORMED;
4684 dequeue_mid(mid, rdata->result);
4688 iov_iter_bvec(&iter, WRITE, bvec, npages, data_len);
4689 } else if (buf_len >= data_offset + data_len) {
4690 /* read response payload is in buf */
4691 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
4692 iov.iov_base = buf + data_offset;
4693 iov.iov_len = data_len;
4694 iov_iter_kvec(&iter, WRITE, &iov, 1, data_len);
4696 /* read response payload cannot be in both buf and pages */
4697 WARN_ONCE(1, "buf can not contain only a part of read data");
4698 rdata->result = -EIO;
4700 mid->mid_state = MID_RESPONSE_MALFORMED;
4702 dequeue_mid(mid, rdata->result);
4706 length = rdata->copy_into_pages(server, rdata, &iter);
4714 mid->mid_state = MID_RESPONSE_RECEIVED;
4716 dequeue_mid(mid, false);
4720 struct smb2_decrypt_work {
4721 struct work_struct decrypt;
4722 struct TCP_Server_Info *server;
4723 struct page **ppages;
4725 unsigned int npages;
4730 static void smb2_decrypt_offload(struct work_struct *work)
4732 struct smb2_decrypt_work *dw = container_of(work,
4733 struct smb2_decrypt_work, decrypt);
4735 struct mid_q_entry *mid;
4737 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
4738 dw->ppages, dw->npages, dw->len, true);
4740 cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
4744 dw->server->lstrp = jiffies;
4745 mid = smb2_find_dequeue_mid(dw->server, dw->buf);
4747 cifs_dbg(FYI, "mid not found\n");
4749 mid->decrypted = true;
4750 rc = handle_read_data(dw->server, mid, dw->buf,
4751 dw->server->vals->read_rsp_size,
4752 dw->ppages, dw->npages, dw->len,
4755 #ifdef CONFIG_CIFS_STATS2
4756 mid->when_received = jiffies;
4760 spin_lock(&GlobalMid_Lock);
4761 if (dw->server->tcpStatus == CifsNeedReconnect) {
4762 mid->mid_state = MID_RETRY_NEEDED;
4763 spin_unlock(&GlobalMid_Lock);
4766 mid->mid_state = MID_REQUEST_SUBMITTED;
4767 mid->mid_flags &= ~(MID_DELETED);
4768 list_add_tail(&mid->qhead,
4769 &dw->server->pending_mid_q);
4770 spin_unlock(&GlobalMid_Lock);
4773 cifs_mid_q_entry_release(mid);
4777 for (i = dw->npages-1; i >= 0; i--)
4778 put_page(dw->ppages[i]);
4781 cifs_small_buf_release(dw->buf);
4787 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
4790 char *buf = server->smallbuf;
4791 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4792 unsigned int npages;
4793 struct page **pages;
4795 unsigned int buflen = server->pdu_size;
4798 struct smb2_decrypt_work *dw;
4801 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
4802 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
4804 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
4807 server->total_read += rc;
4809 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
4810 server->vals->read_rsp_size;
4811 npages = DIV_ROUND_UP(len, PAGE_SIZE);
4813 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
4819 for (; i < npages; i++) {
4820 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4827 /* read read data into pages */
4828 rc = read_data_into_pages(server, pages, npages, len);
4832 rc = cifs_discard_remaining_data(server);
4837 * For large reads, offload to different thread for better performance,
4838 * use more cores decrypting which can be expensive
4841 if ((server->min_offload) && (server->in_flight > 1) &&
4842 (server->pdu_size >= server->min_offload)) {
4843 dw = kmalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL);
4845 goto non_offloaded_decrypt;
4847 dw->buf = server->smallbuf;
4848 server->smallbuf = (char *)cifs_small_buf_get();
4850 INIT_WORK(&dw->decrypt, smb2_decrypt_offload);
4852 dw->npages = npages;
4853 dw->server = server;
4856 queue_work(decrypt_wq, &dw->decrypt);
4857 *num_mids = 0; /* worker thread takes care of finding mid */
4861 non_offloaded_decrypt:
4862 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
4863 pages, npages, len, false);
4867 *mid = smb2_find_mid(server, buf);
4869 cifs_dbg(FYI, "mid not found\n");
4871 cifs_dbg(FYI, "mid found\n");
4872 (*mid)->decrypted = true;
4873 rc = handle_read_data(server, *mid, buf,
4874 server->vals->read_rsp_size,
4875 pages, npages, len, false);
4879 for (i = i - 1; i >= 0; i--)
4884 cifs_discard_remaining_data(server);
4889 receive_encrypted_standard(struct TCP_Server_Info *server,
4890 struct mid_q_entry **mids, char **bufs,
4894 char *buf = server->smallbuf;
4895 struct smb2_sync_hdr *shdr;
4896 unsigned int pdu_length = server->pdu_size;
4897 unsigned int buf_size;
4898 unsigned int next_cmd;
4899 struct mid_q_entry *mid_entry;
4901 char *next_buffer = NULL;
4905 /* switch to large buffer if too big for a small one */
4906 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
4907 server->large_buf = true;
4908 memcpy(server->bigbuf, buf, server->total_read);
4909 buf = server->bigbuf;
4912 /* now read the rest */
4913 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
4914 pdu_length - HEADER_SIZE(server) + 1);
4917 server->total_read += length;
4919 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
4920 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0, false);
4924 next_is_large = server->large_buf;
4926 shdr = (struct smb2_sync_hdr *)buf;
4927 next_cmd = le32_to_cpu(shdr->NextCommand);
4929 if (WARN_ON_ONCE(next_cmd > pdu_length))
4932 next_buffer = (char *)cifs_buf_get();
4934 next_buffer = (char *)cifs_small_buf_get();
4935 memcpy(next_buffer, buf + next_cmd, pdu_length - next_cmd);
4938 mid_entry = smb2_find_mid(server, buf);
4939 if (mid_entry == NULL)
4940 cifs_dbg(FYI, "mid not found\n");
4942 cifs_dbg(FYI, "mid found\n");
4943 mid_entry->decrypted = true;
4944 mid_entry->resp_buf_size = server->pdu_size;
4947 if (*num_mids >= MAX_COMPOUND) {
4948 cifs_server_dbg(VFS, "too many PDUs in compound\n");
4951 bufs[*num_mids] = buf;
4952 mids[(*num_mids)++] = mid_entry;
4954 if (mid_entry && mid_entry->handle)
4955 ret = mid_entry->handle(server, mid_entry);
4957 ret = cifs_handle_standard(server, mid_entry);
4959 if (ret == 0 && next_cmd) {
4960 pdu_length -= next_cmd;
4961 server->large_buf = next_is_large;
4963 server->bigbuf = buf = next_buffer;
4965 server->smallbuf = buf = next_buffer;
4967 } else if (ret != 0) {
4969 * ret != 0 here means that we didn't get to handle_mid() thus
4970 * server->smallbuf and server->bigbuf are still valid. We need
4971 * to free next_buffer because it is not going to be used
4975 free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer);
4977 free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer);
4984 smb3_receive_transform(struct TCP_Server_Info *server,
4985 struct mid_q_entry **mids, char **bufs, int *num_mids)
4987 char *buf = server->smallbuf;
4988 unsigned int pdu_length = server->pdu_size;
4989 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4990 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4992 if (pdu_length < sizeof(struct smb2_transform_hdr) +
4993 sizeof(struct smb2_sync_hdr)) {
4994 cifs_server_dbg(VFS, "Transform message is too small (%u)\n",
4996 cifs_reconnect(server);
4997 return -ECONNABORTED;
5000 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
5001 cifs_server_dbg(VFS, "Transform message is broken\n");
5002 cifs_reconnect(server);
5003 return -ECONNABORTED;
5006 /* TODO: add support for compounds containing READ. */
5007 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
5008 return receive_encrypted_read(server, &mids[0], num_mids);
5011 return receive_encrypted_standard(server, mids, bufs, num_mids);
5015 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
5017 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
5019 return handle_read_data(server, mid, buf, server->pdu_size,
5024 smb2_next_header(char *buf)
5026 struct smb2_sync_hdr *hdr = (struct smb2_sync_hdr *)buf;
5027 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
5029 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
5030 return sizeof(struct smb2_transform_hdr) +
5031 le32_to_cpu(t_hdr->OriginalMessageSize);
5033 return le32_to_cpu(hdr->NextCommand);
5037 smb2_make_node(unsigned int xid, struct inode *inode,
5038 struct dentry *dentry, struct cifs_tcon *tcon,
5039 char *full_path, umode_t mode, dev_t dev)
5041 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
5043 FILE_ALL_INFO *buf = NULL;
5044 struct cifs_io_parms io_parms = {0};
5046 struct cifs_fid fid;
5047 struct cifs_open_parms oparms;
5048 unsigned int bytes_written;
5049 struct win_dev *pdev;
5053 * Check if mounted with mount parm 'sfu' mount parm.
5054 * SFU emulation should work with all servers, but only
5055 * supports block and char device (no socket & fifo),
5056 * and was used by default in earlier versions of Windows
5058 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
5062 * TODO: Add ability to create instead via reparse point. Windows (e.g.
5063 * their current NFS server) uses this approach to expose special files
5064 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
5067 if (!S_ISCHR(mode) && !S_ISBLK(mode))
5070 cifs_dbg(FYI, "sfu compat create special file\n");
5072 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
5079 oparms.cifs_sb = cifs_sb;
5080 oparms.desired_access = GENERIC_WRITE;
5081 oparms.create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR |
5082 CREATE_OPTION_SPECIAL);
5083 oparms.disposition = FILE_CREATE;
5084 oparms.path = full_path;
5086 oparms.reconnect = false;
5088 if (tcon->ses->server->oplocks)
5089 oplock = REQ_OPLOCK;
5092 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf);
5097 * BB Do not bother to decode buf since no local inode yet to put
5098 * timestamps in, but we can reuse it safely.
5101 pdev = (struct win_dev *)buf;
5102 io_parms.pid = current->tgid;
5103 io_parms.tcon = tcon;
5104 io_parms.offset = 0;
5105 io_parms.length = sizeof(struct win_dev);
5106 iov[1].iov_base = buf;
5107 iov[1].iov_len = sizeof(struct win_dev);
5108 if (S_ISCHR(mode)) {
5109 memcpy(pdev->type, "IntxCHR", 8);
5110 pdev->major = cpu_to_le64(MAJOR(dev));
5111 pdev->minor = cpu_to_le64(MINOR(dev));
5112 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5113 &bytes_written, iov, 1);
5114 } else if (S_ISBLK(mode)) {
5115 memcpy(pdev->type, "IntxBLK", 8);
5116 pdev->major = cpu_to_le64(MAJOR(dev));
5117 pdev->minor = cpu_to_le64(MINOR(dev));
5118 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5119 &bytes_written, iov, 1);
5121 tcon->ses->server->ops->close(xid, tcon, &fid);
5124 /* FIXME: add code here to set EAs */
5130 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5131 struct smb_version_operations smb20_operations = {
5132 .compare_fids = smb2_compare_fids,
5133 .setup_request = smb2_setup_request,
5134 .setup_async_request = smb2_setup_async_request,
5135 .check_receive = smb2_check_receive,
5136 .add_credits = smb2_add_credits,
5137 .set_credits = smb2_set_credits,
5138 .get_credits_field = smb2_get_credits_field,
5139 .get_credits = smb2_get_credits,
5140 .wait_mtu_credits = cifs_wait_mtu_credits,
5141 .get_next_mid = smb2_get_next_mid,
5142 .revert_current_mid = smb2_revert_current_mid,
5143 .read_data_offset = smb2_read_data_offset,
5144 .read_data_length = smb2_read_data_length,
5145 .map_error = map_smb2_to_linux_error,
5146 .find_mid = smb2_find_mid,
5147 .check_message = smb2_check_message,
5148 .dump_detail = smb2_dump_detail,
5149 .clear_stats = smb2_clear_stats,
5150 .print_stats = smb2_print_stats,
5151 .is_oplock_break = smb2_is_valid_oplock_break,
5152 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5153 .downgrade_oplock = smb2_downgrade_oplock,
5154 .need_neg = smb2_need_neg,
5155 .negotiate = smb2_negotiate,
5156 .negotiate_wsize = smb2_negotiate_wsize,
5157 .negotiate_rsize = smb2_negotiate_rsize,
5158 .sess_setup = SMB2_sess_setup,
5159 .logoff = SMB2_logoff,
5160 .tree_connect = SMB2_tcon,
5161 .tree_disconnect = SMB2_tdis,
5162 .qfs_tcon = smb2_qfs_tcon,
5163 .is_path_accessible = smb2_is_path_accessible,
5164 .can_echo = smb2_can_echo,
5166 .query_path_info = smb2_query_path_info,
5167 .get_srv_inum = smb2_get_srv_inum,
5168 .query_file_info = smb2_query_file_info,
5169 .set_path_size = smb2_set_path_size,
5170 .set_file_size = smb2_set_file_size,
5171 .set_file_info = smb2_set_file_info,
5172 .set_compression = smb2_set_compression,
5173 .mkdir = smb2_mkdir,
5174 .mkdir_setinfo = smb2_mkdir_setinfo,
5175 .rmdir = smb2_rmdir,
5176 .unlink = smb2_unlink,
5177 .rename = smb2_rename_path,
5178 .create_hardlink = smb2_create_hardlink,
5179 .query_symlink = smb2_query_symlink,
5180 .query_mf_symlink = smb3_query_mf_symlink,
5181 .create_mf_symlink = smb3_create_mf_symlink,
5182 .open = smb2_open_file,
5183 .set_fid = smb2_set_fid,
5184 .close = smb2_close_file,
5185 .flush = smb2_flush_file,
5186 .async_readv = smb2_async_readv,
5187 .async_writev = smb2_async_writev,
5188 .sync_read = smb2_sync_read,
5189 .sync_write = smb2_sync_write,
5190 .query_dir_first = smb2_query_dir_first,
5191 .query_dir_next = smb2_query_dir_next,
5192 .close_dir = smb2_close_dir,
5193 .calc_smb_size = smb2_calc_size,
5194 .is_status_pending = smb2_is_status_pending,
5195 .is_session_expired = smb2_is_session_expired,
5196 .oplock_response = smb2_oplock_response,
5197 .queryfs = smb2_queryfs,
5198 .mand_lock = smb2_mand_lock,
5199 .mand_unlock_range = smb2_unlock_range,
5200 .push_mand_locks = smb2_push_mandatory_locks,
5201 .get_lease_key = smb2_get_lease_key,
5202 .set_lease_key = smb2_set_lease_key,
5203 .new_lease_key = smb2_new_lease_key,
5204 .calc_signature = smb2_calc_signature,
5205 .is_read_op = smb2_is_read_op,
5206 .set_oplock_level = smb2_set_oplock_level,
5207 .create_lease_buf = smb2_create_lease_buf,
5208 .parse_lease_buf = smb2_parse_lease_buf,
5209 .copychunk_range = smb2_copychunk_range,
5210 .wp_retry_size = smb2_wp_retry_size,
5211 .dir_needs_close = smb2_dir_needs_close,
5212 .get_dfs_refer = smb2_get_dfs_refer,
5213 .select_sectype = smb2_select_sectype,
5214 #ifdef CONFIG_CIFS_XATTR
5215 .query_all_EAs = smb2_query_eas,
5216 .set_EA = smb2_set_ea,
5217 #endif /* CIFS_XATTR */
5218 .get_acl = get_smb2_acl,
5219 .get_acl_by_fid = get_smb2_acl_by_fid,
5220 .set_acl = set_smb2_acl,
5221 .next_header = smb2_next_header,
5222 .ioctl_query_info = smb2_ioctl_query_info,
5223 .make_node = smb2_make_node,
5224 .fiemap = smb3_fiemap,
5225 .llseek = smb3_llseek,
5226 .is_status_io_timeout = smb2_is_status_io_timeout,
5228 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
5230 struct smb_version_operations smb21_operations = {
5231 .compare_fids = smb2_compare_fids,
5232 .setup_request = smb2_setup_request,
5233 .setup_async_request = smb2_setup_async_request,
5234 .check_receive = smb2_check_receive,
5235 .add_credits = smb2_add_credits,
5236 .set_credits = smb2_set_credits,
5237 .get_credits_field = smb2_get_credits_field,
5238 .get_credits = smb2_get_credits,
5239 .wait_mtu_credits = smb2_wait_mtu_credits,
5240 .adjust_credits = smb2_adjust_credits,
5241 .get_next_mid = smb2_get_next_mid,
5242 .revert_current_mid = smb2_revert_current_mid,
5243 .read_data_offset = smb2_read_data_offset,
5244 .read_data_length = smb2_read_data_length,
5245 .map_error = map_smb2_to_linux_error,
5246 .find_mid = smb2_find_mid,
5247 .check_message = smb2_check_message,
5248 .dump_detail = smb2_dump_detail,
5249 .clear_stats = smb2_clear_stats,
5250 .print_stats = smb2_print_stats,
5251 .is_oplock_break = smb2_is_valid_oplock_break,
5252 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5253 .downgrade_oplock = smb2_downgrade_oplock,
5254 .need_neg = smb2_need_neg,
5255 .negotiate = smb2_negotiate,
5256 .negotiate_wsize = smb2_negotiate_wsize,
5257 .negotiate_rsize = smb2_negotiate_rsize,
5258 .sess_setup = SMB2_sess_setup,
5259 .logoff = SMB2_logoff,
5260 .tree_connect = SMB2_tcon,
5261 .tree_disconnect = SMB2_tdis,
5262 .qfs_tcon = smb2_qfs_tcon,
5263 .is_path_accessible = smb2_is_path_accessible,
5264 .can_echo = smb2_can_echo,
5266 .query_path_info = smb2_query_path_info,
5267 .get_srv_inum = smb2_get_srv_inum,
5268 .query_file_info = smb2_query_file_info,
5269 .set_path_size = smb2_set_path_size,
5270 .set_file_size = smb2_set_file_size,
5271 .set_file_info = smb2_set_file_info,
5272 .set_compression = smb2_set_compression,
5273 .mkdir = smb2_mkdir,
5274 .mkdir_setinfo = smb2_mkdir_setinfo,
5275 .rmdir = smb2_rmdir,
5276 .unlink = smb2_unlink,
5277 .rename = smb2_rename_path,
5278 .create_hardlink = smb2_create_hardlink,
5279 .query_symlink = smb2_query_symlink,
5280 .query_mf_symlink = smb3_query_mf_symlink,
5281 .create_mf_symlink = smb3_create_mf_symlink,
5282 .open = smb2_open_file,
5283 .set_fid = smb2_set_fid,
5284 .close = smb2_close_file,
5285 .flush = smb2_flush_file,
5286 .async_readv = smb2_async_readv,
5287 .async_writev = smb2_async_writev,
5288 .sync_read = smb2_sync_read,
5289 .sync_write = smb2_sync_write,
5290 .query_dir_first = smb2_query_dir_first,
5291 .query_dir_next = smb2_query_dir_next,
5292 .close_dir = smb2_close_dir,
5293 .calc_smb_size = smb2_calc_size,
5294 .is_status_pending = smb2_is_status_pending,
5295 .is_session_expired = smb2_is_session_expired,
5296 .oplock_response = smb2_oplock_response,
5297 .queryfs = smb2_queryfs,
5298 .mand_lock = smb2_mand_lock,
5299 .mand_unlock_range = smb2_unlock_range,
5300 .push_mand_locks = smb2_push_mandatory_locks,
5301 .get_lease_key = smb2_get_lease_key,
5302 .set_lease_key = smb2_set_lease_key,
5303 .new_lease_key = smb2_new_lease_key,
5304 .calc_signature = smb2_calc_signature,
5305 .is_read_op = smb21_is_read_op,
5306 .set_oplock_level = smb21_set_oplock_level,
5307 .create_lease_buf = smb2_create_lease_buf,
5308 .parse_lease_buf = smb2_parse_lease_buf,
5309 .copychunk_range = smb2_copychunk_range,
5310 .wp_retry_size = smb2_wp_retry_size,
5311 .dir_needs_close = smb2_dir_needs_close,
5312 .enum_snapshots = smb3_enum_snapshots,
5313 .notify = smb3_notify,
5314 .get_dfs_refer = smb2_get_dfs_refer,
5315 .select_sectype = smb2_select_sectype,
5316 #ifdef CONFIG_CIFS_XATTR
5317 .query_all_EAs = smb2_query_eas,
5318 .set_EA = smb2_set_ea,
5319 #endif /* CIFS_XATTR */
5320 .get_acl = get_smb2_acl,
5321 .get_acl_by_fid = get_smb2_acl_by_fid,
5322 .set_acl = set_smb2_acl,
5323 .next_header = smb2_next_header,
5324 .ioctl_query_info = smb2_ioctl_query_info,
5325 .make_node = smb2_make_node,
5326 .fiemap = smb3_fiemap,
5327 .llseek = smb3_llseek,
5328 .is_status_io_timeout = smb2_is_status_io_timeout,
5331 struct smb_version_operations smb30_operations = {
5332 .compare_fids = smb2_compare_fids,
5333 .setup_request = smb2_setup_request,
5334 .setup_async_request = smb2_setup_async_request,
5335 .check_receive = smb2_check_receive,
5336 .add_credits = smb2_add_credits,
5337 .set_credits = smb2_set_credits,
5338 .get_credits_field = smb2_get_credits_field,
5339 .get_credits = smb2_get_credits,
5340 .wait_mtu_credits = smb2_wait_mtu_credits,
5341 .adjust_credits = smb2_adjust_credits,
5342 .get_next_mid = smb2_get_next_mid,
5343 .revert_current_mid = smb2_revert_current_mid,
5344 .read_data_offset = smb2_read_data_offset,
5345 .read_data_length = smb2_read_data_length,
5346 .map_error = map_smb2_to_linux_error,
5347 .find_mid = smb2_find_mid,
5348 .check_message = smb2_check_message,
5349 .dump_detail = smb2_dump_detail,
5350 .clear_stats = smb2_clear_stats,
5351 .print_stats = smb2_print_stats,
5352 .dump_share_caps = smb2_dump_share_caps,
5353 .is_oplock_break = smb2_is_valid_oplock_break,
5354 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5355 .downgrade_oplock = smb3_downgrade_oplock,
5356 .need_neg = smb2_need_neg,
5357 .negotiate = smb2_negotiate,
5358 .negotiate_wsize = smb3_negotiate_wsize,
5359 .negotiate_rsize = smb3_negotiate_rsize,
5360 .sess_setup = SMB2_sess_setup,
5361 .logoff = SMB2_logoff,
5362 .tree_connect = SMB2_tcon,
5363 .tree_disconnect = SMB2_tdis,
5364 .qfs_tcon = smb3_qfs_tcon,
5365 .is_path_accessible = smb2_is_path_accessible,
5366 .can_echo = smb2_can_echo,
5368 .query_path_info = smb2_query_path_info,
5369 /* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */
5370 .query_reparse_tag = smb2_query_reparse_tag,
5371 .get_srv_inum = smb2_get_srv_inum,
5372 .query_file_info = smb2_query_file_info,
5373 .set_path_size = smb2_set_path_size,
5374 .set_file_size = smb2_set_file_size,
5375 .set_file_info = smb2_set_file_info,
5376 .set_compression = smb2_set_compression,
5377 .mkdir = smb2_mkdir,
5378 .mkdir_setinfo = smb2_mkdir_setinfo,
5379 .rmdir = smb2_rmdir,
5380 .unlink = smb2_unlink,
5381 .rename = smb2_rename_path,
5382 .create_hardlink = smb2_create_hardlink,
5383 .query_symlink = smb2_query_symlink,
5384 .query_mf_symlink = smb3_query_mf_symlink,
5385 .create_mf_symlink = smb3_create_mf_symlink,
5386 .open = smb2_open_file,
5387 .set_fid = smb2_set_fid,
5388 .close = smb2_close_file,
5389 .close_getattr = smb2_close_getattr,
5390 .flush = smb2_flush_file,
5391 .async_readv = smb2_async_readv,
5392 .async_writev = smb2_async_writev,
5393 .sync_read = smb2_sync_read,
5394 .sync_write = smb2_sync_write,
5395 .query_dir_first = smb2_query_dir_first,
5396 .query_dir_next = smb2_query_dir_next,
5397 .close_dir = smb2_close_dir,
5398 .calc_smb_size = smb2_calc_size,
5399 .is_status_pending = smb2_is_status_pending,
5400 .is_session_expired = smb2_is_session_expired,
5401 .oplock_response = smb2_oplock_response,
5402 .queryfs = smb2_queryfs,
5403 .mand_lock = smb2_mand_lock,
5404 .mand_unlock_range = smb2_unlock_range,
5405 .push_mand_locks = smb2_push_mandatory_locks,
5406 .get_lease_key = smb2_get_lease_key,
5407 .set_lease_key = smb2_set_lease_key,
5408 .new_lease_key = smb2_new_lease_key,
5409 .generate_signingkey = generate_smb30signingkey,
5410 .calc_signature = smb3_calc_signature,
5411 .set_integrity = smb3_set_integrity,
5412 .is_read_op = smb21_is_read_op,
5413 .set_oplock_level = smb3_set_oplock_level,
5414 .create_lease_buf = smb3_create_lease_buf,
5415 .parse_lease_buf = smb3_parse_lease_buf,
5416 .copychunk_range = smb2_copychunk_range,
5417 .duplicate_extents = smb2_duplicate_extents,
5418 .validate_negotiate = smb3_validate_negotiate,
5419 .wp_retry_size = smb2_wp_retry_size,
5420 .dir_needs_close = smb2_dir_needs_close,
5421 .fallocate = smb3_fallocate,
5422 .enum_snapshots = smb3_enum_snapshots,
5423 .notify = smb3_notify,
5424 .init_transform_rq = smb3_init_transform_rq,
5425 .is_transform_hdr = smb3_is_transform_hdr,
5426 .receive_transform = smb3_receive_transform,
5427 .get_dfs_refer = smb2_get_dfs_refer,
5428 .select_sectype = smb2_select_sectype,
5429 #ifdef CONFIG_CIFS_XATTR
5430 .query_all_EAs = smb2_query_eas,
5431 .set_EA = smb2_set_ea,
5432 #endif /* CIFS_XATTR */
5433 .get_acl = get_smb2_acl,
5434 .get_acl_by_fid = get_smb2_acl_by_fid,
5435 .set_acl = set_smb2_acl,
5436 .next_header = smb2_next_header,
5437 .ioctl_query_info = smb2_ioctl_query_info,
5438 .make_node = smb2_make_node,
5439 .fiemap = smb3_fiemap,
5440 .llseek = smb3_llseek,
5441 .is_status_io_timeout = smb2_is_status_io_timeout,
5444 struct smb_version_operations smb311_operations = {
5445 .compare_fids = smb2_compare_fids,
5446 .setup_request = smb2_setup_request,
5447 .setup_async_request = smb2_setup_async_request,
5448 .check_receive = smb2_check_receive,
5449 .add_credits = smb2_add_credits,
5450 .set_credits = smb2_set_credits,
5451 .get_credits_field = smb2_get_credits_field,
5452 .get_credits = smb2_get_credits,
5453 .wait_mtu_credits = smb2_wait_mtu_credits,
5454 .adjust_credits = smb2_adjust_credits,
5455 .get_next_mid = smb2_get_next_mid,
5456 .revert_current_mid = smb2_revert_current_mid,
5457 .read_data_offset = smb2_read_data_offset,
5458 .read_data_length = smb2_read_data_length,
5459 .map_error = map_smb2_to_linux_error,
5460 .find_mid = smb2_find_mid,
5461 .check_message = smb2_check_message,
5462 .dump_detail = smb2_dump_detail,
5463 .clear_stats = smb2_clear_stats,
5464 .print_stats = smb2_print_stats,
5465 .dump_share_caps = smb2_dump_share_caps,
5466 .is_oplock_break = smb2_is_valid_oplock_break,
5467 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5468 .downgrade_oplock = smb3_downgrade_oplock,
5469 .need_neg = smb2_need_neg,
5470 .negotiate = smb2_negotiate,
5471 .negotiate_wsize = smb3_negotiate_wsize,
5472 .negotiate_rsize = smb3_negotiate_rsize,
5473 .sess_setup = SMB2_sess_setup,
5474 .logoff = SMB2_logoff,
5475 .tree_connect = SMB2_tcon,
5476 .tree_disconnect = SMB2_tdis,
5477 .qfs_tcon = smb3_qfs_tcon,
5478 .is_path_accessible = smb2_is_path_accessible,
5479 .can_echo = smb2_can_echo,
5481 .query_path_info = smb2_query_path_info,
5482 .query_reparse_tag = smb2_query_reparse_tag,
5483 .get_srv_inum = smb2_get_srv_inum,
5484 .query_file_info = smb2_query_file_info,
5485 .set_path_size = smb2_set_path_size,
5486 .set_file_size = smb2_set_file_size,
5487 .set_file_info = smb2_set_file_info,
5488 .set_compression = smb2_set_compression,
5489 .mkdir = smb2_mkdir,
5490 .mkdir_setinfo = smb2_mkdir_setinfo,
5491 .posix_mkdir = smb311_posix_mkdir,
5492 .rmdir = smb2_rmdir,
5493 .unlink = smb2_unlink,
5494 .rename = smb2_rename_path,
5495 .create_hardlink = smb2_create_hardlink,
5496 .query_symlink = smb2_query_symlink,
5497 .query_mf_symlink = smb3_query_mf_symlink,
5498 .create_mf_symlink = smb3_create_mf_symlink,
5499 .open = smb2_open_file,
5500 .set_fid = smb2_set_fid,
5501 .close = smb2_close_file,
5502 .close_getattr = smb2_close_getattr,
5503 .flush = smb2_flush_file,
5504 .async_readv = smb2_async_readv,
5505 .async_writev = smb2_async_writev,
5506 .sync_read = smb2_sync_read,
5507 .sync_write = smb2_sync_write,
5508 .query_dir_first = smb2_query_dir_first,
5509 .query_dir_next = smb2_query_dir_next,
5510 .close_dir = smb2_close_dir,
5511 .calc_smb_size = smb2_calc_size,
5512 .is_status_pending = smb2_is_status_pending,
5513 .is_session_expired = smb2_is_session_expired,
5514 .oplock_response = smb2_oplock_response,
5515 .queryfs = smb311_queryfs,
5516 .mand_lock = smb2_mand_lock,
5517 .mand_unlock_range = smb2_unlock_range,
5518 .push_mand_locks = smb2_push_mandatory_locks,
5519 .get_lease_key = smb2_get_lease_key,
5520 .set_lease_key = smb2_set_lease_key,
5521 .new_lease_key = smb2_new_lease_key,
5522 .generate_signingkey = generate_smb311signingkey,
5523 .calc_signature = smb3_calc_signature,
5524 .set_integrity = smb3_set_integrity,
5525 .is_read_op = smb21_is_read_op,
5526 .set_oplock_level = smb3_set_oplock_level,
5527 .create_lease_buf = smb3_create_lease_buf,
5528 .parse_lease_buf = smb3_parse_lease_buf,
5529 .copychunk_range = smb2_copychunk_range,
5530 .duplicate_extents = smb2_duplicate_extents,
5531 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
5532 .wp_retry_size = smb2_wp_retry_size,
5533 .dir_needs_close = smb2_dir_needs_close,
5534 .fallocate = smb3_fallocate,
5535 .enum_snapshots = smb3_enum_snapshots,
5536 .notify = smb3_notify,
5537 .init_transform_rq = smb3_init_transform_rq,
5538 .is_transform_hdr = smb3_is_transform_hdr,
5539 .receive_transform = smb3_receive_transform,
5540 .get_dfs_refer = smb2_get_dfs_refer,
5541 .select_sectype = smb2_select_sectype,
5542 #ifdef CONFIG_CIFS_XATTR
5543 .query_all_EAs = smb2_query_eas,
5544 .set_EA = smb2_set_ea,
5545 #endif /* CIFS_XATTR */
5546 .get_acl = get_smb2_acl,
5547 .get_acl_by_fid = get_smb2_acl_by_fid,
5548 .set_acl = set_smb2_acl,
5549 .next_header = smb2_next_header,
5550 .ioctl_query_info = smb2_ioctl_query_info,
5551 .make_node = smb2_make_node,
5552 .fiemap = smb3_fiemap,
5553 .llseek = smb3_llseek,
5554 .is_status_io_timeout = smb2_is_status_io_timeout,
5557 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5558 struct smb_version_values smb20_values = {
5559 .version_string = SMB20_VERSION_STRING,
5560 .protocol_id = SMB20_PROT_ID,
5561 .req_capabilities = 0, /* MBZ */
5562 .large_lock_type = 0,
5563 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5564 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5565 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5566 .header_size = sizeof(struct smb2_sync_hdr),
5567 .header_preamble_size = 0,
5568 .max_header_size = MAX_SMB2_HDR_SIZE,
5569 .read_rsp_size = sizeof(struct smb2_read_rsp),
5570 .lock_cmd = SMB2_LOCK,
5572 .cap_nt_find = SMB2_NT_FIND,
5573 .cap_large_files = SMB2_LARGE_FILES,
5574 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5575 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5576 .create_lease_size = sizeof(struct create_lease),
5578 #endif /* ALLOW_INSECURE_LEGACY */
5580 struct smb_version_values smb21_values = {
5581 .version_string = SMB21_VERSION_STRING,
5582 .protocol_id = SMB21_PROT_ID,
5583 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
5584 .large_lock_type = 0,
5585 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5586 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5587 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5588 .header_size = sizeof(struct smb2_sync_hdr),
5589 .header_preamble_size = 0,
5590 .max_header_size = MAX_SMB2_HDR_SIZE,
5591 .read_rsp_size = sizeof(struct smb2_read_rsp),
5592 .lock_cmd = SMB2_LOCK,
5594 .cap_nt_find = SMB2_NT_FIND,
5595 .cap_large_files = SMB2_LARGE_FILES,
5596 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5597 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5598 .create_lease_size = sizeof(struct create_lease),
5601 struct smb_version_values smb3any_values = {
5602 .version_string = SMB3ANY_VERSION_STRING,
5603 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5604 .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,
5605 .large_lock_type = 0,
5606 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5607 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5608 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5609 .header_size = sizeof(struct smb2_sync_hdr),
5610 .header_preamble_size = 0,
5611 .max_header_size = MAX_SMB2_HDR_SIZE,
5612 .read_rsp_size = sizeof(struct smb2_read_rsp),
5613 .lock_cmd = SMB2_LOCK,
5615 .cap_nt_find = SMB2_NT_FIND,
5616 .cap_large_files = SMB2_LARGE_FILES,
5617 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5618 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5619 .create_lease_size = sizeof(struct create_lease_v2),
5622 struct smb_version_values smbdefault_values = {
5623 .version_string = SMBDEFAULT_VERSION_STRING,
5624 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5625 .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,
5626 .large_lock_type = 0,
5627 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5628 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5629 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5630 .header_size = sizeof(struct smb2_sync_hdr),
5631 .header_preamble_size = 0,
5632 .max_header_size = MAX_SMB2_HDR_SIZE,
5633 .read_rsp_size = sizeof(struct smb2_read_rsp),
5634 .lock_cmd = SMB2_LOCK,
5636 .cap_nt_find = SMB2_NT_FIND,
5637 .cap_large_files = SMB2_LARGE_FILES,
5638 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5639 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5640 .create_lease_size = sizeof(struct create_lease_v2),
5643 struct smb_version_values smb30_values = {
5644 .version_string = SMB30_VERSION_STRING,
5645 .protocol_id = SMB30_PROT_ID,
5646 .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,
5647 .large_lock_type = 0,
5648 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5649 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5650 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5651 .header_size = sizeof(struct smb2_sync_hdr),
5652 .header_preamble_size = 0,
5653 .max_header_size = MAX_SMB2_HDR_SIZE,
5654 .read_rsp_size = sizeof(struct smb2_read_rsp),
5655 .lock_cmd = SMB2_LOCK,
5657 .cap_nt_find = SMB2_NT_FIND,
5658 .cap_large_files = SMB2_LARGE_FILES,
5659 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5660 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5661 .create_lease_size = sizeof(struct create_lease_v2),
5664 struct smb_version_values smb302_values = {
5665 .version_string = SMB302_VERSION_STRING,
5666 .protocol_id = SMB302_PROT_ID,
5667 .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,
5668 .large_lock_type = 0,
5669 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5670 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5671 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5672 .header_size = sizeof(struct smb2_sync_hdr),
5673 .header_preamble_size = 0,
5674 .max_header_size = MAX_SMB2_HDR_SIZE,
5675 .read_rsp_size = sizeof(struct smb2_read_rsp),
5676 .lock_cmd = SMB2_LOCK,
5678 .cap_nt_find = SMB2_NT_FIND,
5679 .cap_large_files = SMB2_LARGE_FILES,
5680 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5681 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5682 .create_lease_size = sizeof(struct create_lease_v2),
5685 struct smb_version_values smb311_values = {
5686 .version_string = SMB311_VERSION_STRING,
5687 .protocol_id = SMB311_PROT_ID,
5688 .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,
5689 .large_lock_type = 0,
5690 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5691 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5692 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5693 .header_size = sizeof(struct smb2_sync_hdr),
5694 .header_preamble_size = 0,
5695 .max_header_size = MAX_SMB2_HDR_SIZE,
5696 .read_rsp_size = sizeof(struct smb2_read_rsp),
5697 .lock_cmd = SMB2_LOCK,
5699 .cap_nt_find = SMB2_NT_FIND,
5700 .cap_large_files = SMB2_LARGE_FILES,
5701 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5702 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5703 .create_lease_size = sizeof(struct create_lease_v2),