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");
86 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
87 rc = change_conf(server);
89 * Sometimes server returns 0 credits on oplock break ack - we need to
90 * rebalance credits in this case.
92 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
94 if (server->credits > 1) {
96 server->oplock_credits++;
99 spin_unlock(&server->req_lock);
100 wake_up(&server->request_q);
102 if (reconnect_detected)
103 cifs_dbg(FYI, "trying to put %d credits from the old server instance %d\n",
106 if (server->tcpStatus == CifsNeedReconnect
107 || server->tcpStatus == CifsExiting)
112 /* change_conf hasn't been executed */
115 cifs_server_dbg(VFS, "Possible client or server bug - zero credits\n");
118 cifs_server_dbg(VFS, "disabling echoes and oplocks\n");
121 cifs_dbg(FYI, "disabling oplocks\n");
124 trace_smb3_add_credits(server->CurrentMid,
125 server->hostname, rc, add);
126 cifs_dbg(FYI, "add %u credits total=%d\n", add, rc);
131 smb2_set_credits(struct TCP_Server_Info *server, const int val)
133 spin_lock(&server->req_lock);
134 server->credits = val;
136 server->reconnect_instance++;
137 spin_unlock(&server->req_lock);
138 /* don't log while holding the lock */
140 cifs_dbg(FYI, "set credits to 1 due to smb2 reconnect\n");
144 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
148 return &server->echo_credits;
150 return &server->oplock_credits;
152 return &server->credits;
157 smb2_get_credits(struct mid_q_entry *mid)
159 return mid->credits_received;
163 smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
164 unsigned int *num, struct cifs_credits *credits)
167 unsigned int scredits;
169 spin_lock(&server->req_lock);
171 if (server->credits <= 0) {
172 spin_unlock(&server->req_lock);
173 cifs_num_waiters_inc(server);
174 rc = wait_event_killable(server->request_q,
175 has_credits(server, &server->credits, 1));
176 cifs_num_waiters_dec(server);
179 spin_lock(&server->req_lock);
181 if (server->tcpStatus == CifsExiting) {
182 spin_unlock(&server->req_lock);
186 scredits = server->credits;
187 /* can deadlock with reopen */
189 *num = SMB2_MAX_BUFFER_SIZE;
191 credits->instance = 0;
195 /* leave some credits for reopen and other ops */
197 *num = min_t(unsigned int, size,
198 scredits * SMB2_MAX_BUFFER_SIZE);
201 DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
202 credits->instance = server->reconnect_instance;
203 server->credits -= credits->value;
205 if (server->in_flight > server->max_in_flight)
206 server->max_in_flight = server->in_flight;
210 spin_unlock(&server->req_lock);
215 smb2_adjust_credits(struct TCP_Server_Info *server,
216 struct cifs_credits *credits,
217 const unsigned int payload_size)
219 int new_val = DIV_ROUND_UP(payload_size, SMB2_MAX_BUFFER_SIZE);
221 if (!credits->value || credits->value == new_val)
224 if (credits->value < new_val) {
225 WARN_ONCE(1, "request has less credits (%d) than required (%d)",
226 credits->value, new_val);
230 spin_lock(&server->req_lock);
232 if (server->reconnect_instance != credits->instance) {
233 spin_unlock(&server->req_lock);
234 cifs_server_dbg(VFS, "trying to return %d credits to old session\n",
235 credits->value - new_val);
239 server->credits += credits->value - new_val;
240 spin_unlock(&server->req_lock);
241 wake_up(&server->request_q);
242 credits->value = new_val;
247 smb2_get_next_mid(struct TCP_Server_Info *server)
250 /* for SMB2 we need the current value */
251 spin_lock(&GlobalMid_Lock);
252 mid = server->CurrentMid++;
253 spin_unlock(&GlobalMid_Lock);
258 smb2_revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
260 spin_lock(&GlobalMid_Lock);
261 if (server->CurrentMid >= val)
262 server->CurrentMid -= val;
263 spin_unlock(&GlobalMid_Lock);
266 static struct mid_q_entry *
267 __smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue)
269 struct mid_q_entry *mid;
270 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
271 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
273 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
274 cifs_server_dbg(VFS, "Encrypted frame parsing not supported yet\n");
278 spin_lock(&GlobalMid_Lock);
279 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
280 if ((mid->mid == wire_mid) &&
281 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
282 (mid->command == shdr->Command)) {
283 kref_get(&mid->refcount);
285 list_del_init(&mid->qhead);
286 mid->mid_flags |= MID_DELETED;
288 spin_unlock(&GlobalMid_Lock);
292 spin_unlock(&GlobalMid_Lock);
296 static struct mid_q_entry *
297 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
299 return __smb2_find_mid(server, buf, false);
302 static struct mid_q_entry *
303 smb2_find_dequeue_mid(struct TCP_Server_Info *server, char *buf)
305 return __smb2_find_mid(server, buf, true);
309 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
311 #ifdef CONFIG_CIFS_DEBUG2
312 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
314 cifs_server_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
315 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
317 cifs_server_dbg(VFS, "smb buf %p len %u\n", buf,
318 server->ops->calc_smb_size(buf, server));
323 smb2_need_neg(struct TCP_Server_Info *server)
325 return server->max_read == 0;
329 smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
333 cifs_ses_server(ses)->CurrentMid = 0;
334 rc = SMB2_negotiate(xid, ses);
335 /* BB we probably don't need to retry with modern servers */
342 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
344 struct TCP_Server_Info *server = tcon->ses->server;
347 /* start with specified wsize, or default */
348 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
349 wsize = min_t(unsigned int, wsize, server->max_write);
350 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
351 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
357 smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
359 struct TCP_Server_Info *server = tcon->ses->server;
362 /* start with specified wsize, or default */
363 wsize = volume_info->wsize ? volume_info->wsize : SMB3_DEFAULT_IOSIZE;
364 wsize = min_t(unsigned int, wsize, server->max_write);
365 #ifdef CONFIG_CIFS_SMB_DIRECT
369 * Account for SMB2 data transfer packet header and
370 * possible encryption header
372 wsize = min_t(unsigned int,
374 server->smbd_conn->max_fragmented_send_size -
375 SMB2_READWRITE_PDU_HEADER_SIZE -
376 sizeof(struct smb2_transform_hdr));
378 wsize = min_t(unsigned int,
379 wsize, server->smbd_conn->max_readwrite_size);
382 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
383 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
389 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
391 struct TCP_Server_Info *server = tcon->ses->server;
394 /* start with specified rsize, or default */
395 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
396 rsize = min_t(unsigned int, rsize, server->max_read);
398 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
399 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
405 smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
407 struct TCP_Server_Info *server = tcon->ses->server;
410 /* start with specified rsize, or default */
411 rsize = volume_info->rsize ? volume_info->rsize : SMB3_DEFAULT_IOSIZE;
412 rsize = min_t(unsigned int, rsize, server->max_read);
413 #ifdef CONFIG_CIFS_SMB_DIRECT
417 * Account for SMB2 data transfer packet header and
418 * possible encryption header
420 rsize = min_t(unsigned int,
422 server->smbd_conn->max_fragmented_recv_size -
423 SMB2_READWRITE_PDU_HEADER_SIZE -
424 sizeof(struct smb2_transform_hdr));
426 rsize = min_t(unsigned int,
427 rsize, server->smbd_conn->max_readwrite_size);
431 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
432 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
438 parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
440 struct cifs_server_iface **iface_list,
443 struct network_interface_info_ioctl_rsp *p;
444 struct sockaddr_in *addr4;
445 struct sockaddr_in6 *addr6;
446 struct iface_info_ipv4 *p4;
447 struct iface_info_ipv6 *p6;
448 struct cifs_server_iface *info;
458 * Fist pass: count and sanity check
461 bytes_left = buf_len;
463 while (bytes_left >= sizeof(*p)) {
465 next = le32_to_cpu(p->Next);
467 bytes_left -= sizeof(*p);
470 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
475 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
480 /* Azure rounds the buffer size up 8, to a 16 byte boundary */
481 if ((bytes_left > 8) || p->Next)
482 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
486 * Second pass: extract info to internal structure
489 *iface_list = kcalloc(nb_iface, sizeof(**iface_list), GFP_KERNEL);
496 bytes_left = buf_len;
498 while (bytes_left >= sizeof(*p)) {
499 info->speed = le64_to_cpu(p->LinkSpeed);
500 info->rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE) ? 1 : 0;
501 info->rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE) ? 1 : 0;
503 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, *iface_count);
504 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
505 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
506 le32_to_cpu(p->Capability));
510 * The kernel and wire socket structures have the same
511 * layout and use network byte order but make the
512 * conversion explicit in case either one changes.
515 addr4 = (struct sockaddr_in *)&info->sockaddr;
516 p4 = (struct iface_info_ipv4 *)p->Buffer;
517 addr4->sin_family = AF_INET;
518 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
520 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
521 addr4->sin_port = cpu_to_be16(CIFS_PORT);
523 cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
527 addr6 = (struct sockaddr_in6 *)&info->sockaddr;
528 p6 = (struct iface_info_ipv6 *)p->Buffer;
529 addr6->sin6_family = AF_INET6;
530 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
532 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
533 addr6->sin6_flowinfo = 0;
534 addr6->sin6_scope_id = 0;
535 addr6->sin6_port = cpu_to_be16(CIFS_PORT);
537 cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
542 "%s: skipping unsupported socket family\n",
550 next = le32_to_cpu(p->Next);
553 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
571 static int compare_iface(const void *ia, const void *ib)
573 const struct cifs_server_iface *a = (struct cifs_server_iface *)ia;
574 const struct cifs_server_iface *b = (struct cifs_server_iface *)ib;
576 return a->speed == b->speed ? 0 : (a->speed > b->speed ? -1 : 1);
580 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
583 unsigned int ret_data_len = 0;
584 struct network_interface_info_ioctl_rsp *out_buf = NULL;
585 struct cifs_server_iface *iface_list;
587 struct cifs_ses *ses = tcon->ses;
589 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
590 FSCTL_QUERY_NETWORK_INTERFACE_INFO,
591 NULL /* no data input */, 0 /* no data input */,
592 CIFSMaxBufSize, (char **)&out_buf, &ret_data_len);
593 if (rc == -EOPNOTSUPP) {
595 "server does not support query network interfaces\n");
597 } else if (rc != 0) {
598 cifs_tcon_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
602 rc = parse_server_interfaces(out_buf, ret_data_len,
603 &iface_list, &iface_count);
607 /* sort interfaces from fastest to slowest */
608 sort(iface_list, iface_count, sizeof(*iface_list), compare_iface, NULL);
610 spin_lock(&ses->iface_lock);
611 kfree(ses->iface_list);
612 ses->iface_list = iface_list;
613 ses->iface_count = iface_count;
614 ses->iface_last_update = jiffies;
615 spin_unlock(&ses->iface_lock);
623 smb2_close_cached_fid(struct kref *ref)
625 struct cached_fid *cfid = container_of(ref, struct cached_fid,
628 if (cfid->is_valid) {
629 cifs_dbg(FYI, "clear cached root file handle\n");
630 SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid,
631 cfid->fid->volatile_fid);
632 cfid->is_valid = false;
633 cfid->file_all_info_is_valid = false;
634 cfid->has_lease = false;
638 void close_shroot(struct cached_fid *cfid)
640 mutex_lock(&cfid->fid_mutex);
641 kref_put(&cfid->refcount, smb2_close_cached_fid);
642 mutex_unlock(&cfid->fid_mutex);
645 void close_shroot_lease_locked(struct cached_fid *cfid)
647 if (cfid->has_lease) {
648 cfid->has_lease = false;
649 kref_put(&cfid->refcount, smb2_close_cached_fid);
653 void close_shroot_lease(struct cached_fid *cfid)
655 mutex_lock(&cfid->fid_mutex);
656 close_shroot_lease_locked(cfid);
657 mutex_unlock(&cfid->fid_mutex);
661 smb2_cached_lease_break(struct work_struct *work)
663 struct cached_fid *cfid = container_of(work,
664 struct cached_fid, lease_break);
666 close_shroot_lease(cfid);
670 * Open the directory at the root of a share
672 int open_shroot(unsigned int xid, struct cifs_tcon *tcon,
673 struct cifs_sb_info *cifs_sb,
674 struct cached_fid **cfid)
676 struct cifs_ses *ses = tcon->ses;
677 struct TCP_Server_Info *server = ses->server;
678 struct cifs_open_parms oparms;
679 struct smb2_create_rsp *o_rsp = NULL;
680 struct smb2_query_info_rsp *qi_rsp = NULL;
682 struct smb_rqst rqst[2];
683 struct kvec rsp_iov[2];
684 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
685 struct kvec qi_iov[1];
687 __le16 utf16_path = 0; /* Null - since an open of top of share */
688 u8 oplock = SMB2_OPLOCK_LEVEL_II;
689 struct cifs_fid *pfid;
691 mutex_lock(&tcon->crfid.fid_mutex);
692 if (tcon->crfid.is_valid) {
693 cifs_dbg(FYI, "found a cached root file handle\n");
694 *cfid = &tcon->crfid;
695 kref_get(&tcon->crfid.refcount);
696 mutex_unlock(&tcon->crfid.fid_mutex);
701 * We do not hold the lock for the open because in case
702 * SMB2_open needs to reconnect, it will end up calling
703 * cifs_mark_open_files_invalid() which takes the lock again
704 * thus causing a deadlock
707 mutex_unlock(&tcon->crfid.fid_mutex);
709 if (smb3_encryption_required(tcon))
710 flags |= CIFS_TRANSFORM_REQ;
712 if (!server->ops->new_lease_key)
715 pfid = tcon->crfid.fid;
716 server->ops->new_lease_key(pfid);
718 memset(rqst, 0, sizeof(rqst));
719 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
720 memset(rsp_iov, 0, sizeof(rsp_iov));
723 memset(&open_iov, 0, sizeof(open_iov));
724 rqst[0].rq_iov = open_iov;
725 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
728 oparms.create_options = cifs_create_options(cifs_sb, 0);
729 oparms.desired_access = FILE_READ_ATTRIBUTES;
730 oparms.disposition = FILE_OPEN;
732 oparms.reconnect = false;
734 rc = SMB2_open_init(tcon, server,
735 &rqst[0], &oplock, &oparms, &utf16_path);
738 smb2_set_next_command(tcon, &rqst[0]);
740 memset(&qi_iov, 0, sizeof(qi_iov));
741 rqst[1].rq_iov = qi_iov;
744 rc = SMB2_query_info_init(tcon, server,
745 &rqst[1], COMPOUND_FID,
746 COMPOUND_FID, FILE_ALL_INFORMATION,
748 sizeof(struct smb2_file_all_info) +
749 PATH_MAX * 2, 0, NULL);
753 smb2_set_related(&rqst[1]);
755 rc = compound_send_recv(xid, ses, server,
757 resp_buftype, rsp_iov);
758 mutex_lock(&tcon->crfid.fid_mutex);
761 * Now we need to check again as the cached root might have
762 * been successfully re-opened from a concurrent process
765 if (tcon->crfid.is_valid) {
766 /* work was already done */
768 /* stash fids for close() later */
769 struct cifs_fid fid = {
770 .persistent_fid = pfid->persistent_fid,
771 .volatile_fid = pfid->volatile_fid,
775 * caller expects this func to set pfid to a valid
776 * cached root, so we copy the existing one and get a
779 memcpy(pfid, tcon->crfid.fid, sizeof(*pfid));
780 kref_get(&tcon->crfid.refcount);
782 mutex_unlock(&tcon->crfid.fid_mutex);
785 /* close extra handle outside of crit sec */
786 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
792 /* Cached root is still invalid, continue normaly */
795 if (rc == -EREMCHG) {
796 tcon->need_reconnect = true;
797 pr_warn_once("server share %s deleted\n",
803 atomic_inc(&tcon->num_remote_opens);
805 o_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
806 oparms.fid->persistent_fid = o_rsp->PersistentFileId;
807 oparms.fid->volatile_fid = o_rsp->VolatileFileId;
808 #ifdef CONFIG_CIFS_DEBUG2
809 oparms.fid->mid = le64_to_cpu(o_rsp->sync_hdr.MessageId);
810 #endif /* CIFS_DEBUG2 */
812 memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid));
813 tcon->crfid.tcon = tcon;
814 tcon->crfid.is_valid = true;
815 kref_init(&tcon->crfid.refcount);
817 /* BB TBD check to see if oplock level check can be removed below */
818 if (o_rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE) {
819 kref_get(&tcon->crfid.refcount);
820 tcon->crfid.has_lease = true;
821 smb2_parse_contexts(server, o_rsp,
823 oparms.fid->lease_key, &oplock,
828 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
829 if (le32_to_cpu(qi_rsp->OutputBufferLength) < sizeof(struct smb2_file_all_info))
831 if (!smb2_validate_and_copy_iov(
832 le16_to_cpu(qi_rsp->OutputBufferOffset),
833 sizeof(struct smb2_file_all_info),
834 &rsp_iov[1], sizeof(struct smb2_file_all_info),
835 (char *)&tcon->crfid.file_all_info))
836 tcon->crfid.file_all_info_is_valid = true;
839 mutex_unlock(&tcon->crfid.fid_mutex);
841 SMB2_open_free(&rqst[0]);
842 SMB2_query_info_free(&rqst[1]);
843 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
844 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
846 *cfid = &tcon->crfid;
851 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
852 struct cifs_sb_info *cifs_sb)
855 __le16 srch_path = 0; /* Null - open root of share */
856 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
857 struct cifs_open_parms oparms;
859 bool no_cached_open = tcon->nohandlecache;
860 struct cached_fid *cfid = NULL;
863 oparms.desired_access = FILE_READ_ATTRIBUTES;
864 oparms.disposition = FILE_OPEN;
865 oparms.create_options = cifs_create_options(cifs_sb, 0);
867 oparms.reconnect = false;
869 if (no_cached_open) {
870 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
873 rc = open_shroot(xid, tcon, cifs_sb, &cfid);
875 memcpy(&fid, cfid->fid, sizeof(struct cifs_fid));
880 SMB3_request_interfaces(xid, tcon);
882 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
883 FS_ATTRIBUTE_INFORMATION);
884 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
885 FS_DEVICE_INFORMATION);
886 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
887 FS_VOLUME_INFORMATION);
888 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
889 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
891 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
897 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
898 struct cifs_sb_info *cifs_sb)
901 __le16 srch_path = 0; /* Null - open root of share */
902 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
903 struct cifs_open_parms oparms;
907 oparms.desired_access = FILE_READ_ATTRIBUTES;
908 oparms.disposition = FILE_OPEN;
909 oparms.create_options = cifs_create_options(cifs_sb, 0);
911 oparms.reconnect = false;
913 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
918 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
919 FS_ATTRIBUTE_INFORMATION);
920 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
921 FS_DEVICE_INFORMATION);
922 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
926 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
927 struct cifs_sb_info *cifs_sb, const char *full_path)
931 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
932 struct cifs_open_parms oparms;
935 if ((*full_path == 0) && tcon->crfid.is_valid)
938 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
943 oparms.desired_access = FILE_READ_ATTRIBUTES;
944 oparms.disposition = FILE_OPEN;
945 oparms.create_options = cifs_create_options(cifs_sb, 0);
947 oparms.reconnect = false;
949 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
956 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
962 smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
963 struct cifs_sb_info *cifs_sb, const char *full_path,
964 u64 *uniqueid, FILE_ALL_INFO *data)
966 *uniqueid = le64_to_cpu(data->IndexNumber);
971 smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
972 struct cifs_fid *fid, FILE_ALL_INFO *data)
975 struct smb2_file_all_info *smb2_data;
977 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
979 if (smb2_data == NULL)
982 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
985 move_smb2_info_to_cifs(data, smb2_data);
990 #ifdef CONFIG_CIFS_XATTR
992 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
993 struct smb2_file_full_ea_info *src, size_t src_size,
994 const unsigned char *ea_name)
997 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
999 size_t buf_size = dst_size;
1000 size_t name_len, value_len, user_name_len;
1002 while (src_size > 0) {
1003 name_len = (size_t)src->ea_name_length;
1004 value_len = (size_t)le16_to_cpu(src->ea_value_length);
1009 if (src_size < 8 + name_len + 1 + value_len) {
1010 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
1015 name = &src->ea_data[0];
1016 value = &src->ea_data[src->ea_name_length + 1];
1019 if (ea_name_len == name_len &&
1020 memcmp(ea_name, name, name_len) == 0) {
1024 if (dst_size < value_len) {
1028 memcpy(dst, value, value_len);
1032 /* 'user.' plus a terminating null */
1033 user_name_len = 5 + 1 + name_len;
1035 if (buf_size == 0) {
1036 /* skip copy - calc size only */
1037 rc += user_name_len;
1038 } else if (dst_size >= user_name_len) {
1039 dst_size -= user_name_len;
1040 memcpy(dst, "user.", 5);
1042 memcpy(dst, src->ea_data, name_len);
1046 rc += user_name_len;
1048 /* stop before overrun buffer */
1054 if (!src->next_entry_offset)
1057 if (src_size < le32_to_cpu(src->next_entry_offset)) {
1058 /* stop before overrun buffer */
1062 src_size -= le32_to_cpu(src->next_entry_offset);
1063 src = (void *)((char *)src +
1064 le32_to_cpu(src->next_entry_offset));
1067 /* didn't find the named attribute */
1076 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
1077 const unsigned char *path, const unsigned char *ea_name,
1078 char *ea_data, size_t buf_size,
1079 struct cifs_sb_info *cifs_sb)
1083 struct kvec rsp_iov = {NULL, 0};
1084 int buftype = CIFS_NO_BUFFER;
1085 struct smb2_query_info_rsp *rsp;
1086 struct smb2_file_full_ea_info *info = NULL;
1088 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1092 rc = smb2_query_info_compound(xid, tcon, utf16_path,
1094 FILE_FULL_EA_INFORMATION,
1097 MAX_SMB2_CREATE_RESPONSE_SIZE -
1098 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1099 &rsp_iov, &buftype, cifs_sb);
1102 * If ea_name is NULL (listxattr) and there are no EAs,
1103 * return 0 as it's not an error. Otherwise, the specified
1104 * ea_name was not found.
1106 if (!ea_name && rc == -ENODATA)
1111 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
1112 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1113 le32_to_cpu(rsp->OutputBufferLength),
1115 sizeof(struct smb2_file_full_ea_info));
1119 info = (struct smb2_file_full_ea_info *)(
1120 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1121 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
1122 le32_to_cpu(rsp->OutputBufferLength), ea_name);
1126 free_rsp_buf(buftype, rsp_iov.iov_base);
1132 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
1133 const char *path, const char *ea_name, const void *ea_value,
1134 const __u16 ea_value_len, const struct nls_table *nls_codepage,
1135 struct cifs_sb_info *cifs_sb)
1137 struct cifs_ses *ses = tcon->ses;
1138 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1139 __le16 *utf16_path = NULL;
1140 int ea_name_len = strlen(ea_name);
1141 int flags = CIFS_CP_CREATE_CLOSE_OP;
1143 struct smb_rqst rqst[3];
1144 int resp_buftype[3];
1145 struct kvec rsp_iov[3];
1146 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1147 struct cifs_open_parms oparms;
1148 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1149 struct cifs_fid fid;
1150 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1151 unsigned int size[1];
1153 struct smb2_file_full_ea_info *ea = NULL;
1154 struct kvec close_iov[1];
1155 struct smb2_query_info_rsp *rsp;
1156 int rc, used_len = 0;
1158 if (smb3_encryption_required(tcon))
1159 flags |= CIFS_TRANSFORM_REQ;
1161 if (ea_name_len > 255)
1164 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1168 memset(rqst, 0, sizeof(rqst));
1169 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1170 memset(rsp_iov, 0, sizeof(rsp_iov));
1172 if (ses->server->ops->query_all_EAs) {
1174 rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1180 /* If we are adding a attribute we should first check
1181 * if there will be enough space available to store
1182 * the new EA. If not we should not add it since we
1183 * would not be able to even read the EAs back.
1185 rc = smb2_query_info_compound(xid, tcon, utf16_path,
1187 FILE_FULL_EA_INFORMATION,
1190 MAX_SMB2_CREATE_RESPONSE_SIZE -
1191 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1192 &rsp_iov[1], &resp_buftype[1], cifs_sb);
1194 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1195 used_len = le32_to_cpu(rsp->OutputBufferLength);
1197 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1198 resp_buftype[1] = CIFS_NO_BUFFER;
1199 memset(&rsp_iov[1], 0, sizeof(rsp_iov[1]));
1202 /* Use a fudge factor of 256 bytes in case we collide
1203 * with a different set_EAs command.
1205 if(CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1206 MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 <
1207 used_len + ea_name_len + ea_value_len + 1) {
1215 memset(&open_iov, 0, sizeof(open_iov));
1216 rqst[0].rq_iov = open_iov;
1217 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1219 memset(&oparms, 0, sizeof(oparms));
1221 oparms.desired_access = FILE_WRITE_EA;
1222 oparms.disposition = FILE_OPEN;
1223 oparms.create_options = cifs_create_options(cifs_sb, 0);
1225 oparms.reconnect = false;
1227 rc = SMB2_open_init(tcon, server,
1228 &rqst[0], &oplock, &oparms, utf16_path);
1231 smb2_set_next_command(tcon, &rqst[0]);
1235 memset(&si_iov, 0, sizeof(si_iov));
1236 rqst[1].rq_iov = si_iov;
1237 rqst[1].rq_nvec = 1;
1239 len = sizeof(*ea) + ea_name_len + ea_value_len + 1;
1240 ea = kzalloc(len, GFP_KERNEL);
1246 ea->ea_name_length = ea_name_len;
1247 ea->ea_value_length = cpu_to_le16(ea_value_len);
1248 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
1249 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
1254 rc = SMB2_set_info_init(tcon, server,
1255 &rqst[1], COMPOUND_FID,
1256 COMPOUND_FID, current->tgid,
1257 FILE_FULL_EA_INFORMATION,
1258 SMB2_O_INFO_FILE, 0, data, size);
1259 smb2_set_next_command(tcon, &rqst[1]);
1260 smb2_set_related(&rqst[1]);
1264 memset(&close_iov, 0, sizeof(close_iov));
1265 rqst[2].rq_iov = close_iov;
1266 rqst[2].rq_nvec = 1;
1267 rc = SMB2_close_init(tcon, server,
1268 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1269 smb2_set_related(&rqst[2]);
1271 rc = compound_send_recv(xid, ses, server,
1273 resp_buftype, rsp_iov);
1274 /* no need to bump num_remote_opens because handle immediately closed */
1279 SMB2_open_free(&rqst[0]);
1280 SMB2_set_info_free(&rqst[1]);
1281 SMB2_close_free(&rqst[2]);
1282 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1283 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1284 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1290 smb2_can_echo(struct TCP_Server_Info *server)
1292 return server->echoes;
1296 smb2_clear_stats(struct cifs_tcon *tcon)
1300 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1301 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1302 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1307 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1309 seq_puts(m, "\n\tShare Capabilities:");
1310 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1311 seq_puts(m, " DFS,");
1312 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1313 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1314 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1315 seq_puts(m, " SCALEOUT,");
1316 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1317 seq_puts(m, " CLUSTER,");
1318 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1319 seq_puts(m, " ASYMMETRIC,");
1320 if (tcon->capabilities == 0)
1321 seq_puts(m, " None");
1322 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1323 seq_puts(m, " Aligned,");
1324 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1325 seq_puts(m, " Partition Aligned,");
1326 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1327 seq_puts(m, " SSD,");
1328 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1329 seq_puts(m, " TRIM-support,");
1331 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1332 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1333 if (tcon->perf_sector_size)
1334 seq_printf(m, "\tOptimal sector size: 0x%x",
1335 tcon->perf_sector_size);
1336 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1340 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1342 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1343 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1346 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1347 * totals (requests sent) since those SMBs are per-session not per tcon
1349 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1350 (long long)(tcon->bytes_read),
1351 (long long)(tcon->bytes_written));
1352 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1353 atomic_read(&tcon->num_local_opens),
1354 atomic_read(&tcon->num_remote_opens));
1355 seq_printf(m, "\nTreeConnects: %d total %d failed",
1356 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1357 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1358 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1359 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1360 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1361 seq_printf(m, "\nCreates: %d total %d failed",
1362 atomic_read(&sent[SMB2_CREATE_HE]),
1363 atomic_read(&failed[SMB2_CREATE_HE]));
1364 seq_printf(m, "\nCloses: %d total %d failed",
1365 atomic_read(&sent[SMB2_CLOSE_HE]),
1366 atomic_read(&failed[SMB2_CLOSE_HE]));
1367 seq_printf(m, "\nFlushes: %d total %d failed",
1368 atomic_read(&sent[SMB2_FLUSH_HE]),
1369 atomic_read(&failed[SMB2_FLUSH_HE]));
1370 seq_printf(m, "\nReads: %d total %d failed",
1371 atomic_read(&sent[SMB2_READ_HE]),
1372 atomic_read(&failed[SMB2_READ_HE]));
1373 seq_printf(m, "\nWrites: %d total %d failed",
1374 atomic_read(&sent[SMB2_WRITE_HE]),
1375 atomic_read(&failed[SMB2_WRITE_HE]));
1376 seq_printf(m, "\nLocks: %d total %d failed",
1377 atomic_read(&sent[SMB2_LOCK_HE]),
1378 atomic_read(&failed[SMB2_LOCK_HE]));
1379 seq_printf(m, "\nIOCTLs: %d total %d failed",
1380 atomic_read(&sent[SMB2_IOCTL_HE]),
1381 atomic_read(&failed[SMB2_IOCTL_HE]));
1382 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1383 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1384 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1385 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1386 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1387 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1388 seq_printf(m, "\nQueryInfos: %d total %d failed",
1389 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1390 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1391 seq_printf(m, "\nSetInfos: %d total %d failed",
1392 atomic_read(&sent[SMB2_SET_INFO_HE]),
1393 atomic_read(&failed[SMB2_SET_INFO_HE]));
1394 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1395 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1396 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1400 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1402 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1403 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1405 cfile->fid.persistent_fid = fid->persistent_fid;
1406 cfile->fid.volatile_fid = fid->volatile_fid;
1407 cfile->fid.access = fid->access;
1408 #ifdef CONFIG_CIFS_DEBUG2
1409 cfile->fid.mid = fid->mid;
1410 #endif /* CIFS_DEBUG2 */
1411 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1413 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1414 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1418 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1419 struct cifs_fid *fid)
1421 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1425 smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon,
1426 struct cifsFileInfo *cfile)
1428 struct smb2_file_network_open_info file_inf;
1429 struct inode *inode;
1432 rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid,
1433 cfile->fid.volatile_fid, &file_inf);
1437 inode = d_inode(cfile->dentry);
1439 spin_lock(&inode->i_lock);
1440 CIFS_I(inode)->time = jiffies;
1442 /* Creation time should not need to be updated on close */
1443 if (file_inf.LastWriteTime)
1444 inode->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime);
1445 if (file_inf.ChangeTime)
1446 inode->i_ctime = cifs_NTtimeToUnix(file_inf.ChangeTime);
1447 if (file_inf.LastAccessTime)
1448 inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime);
1451 * i_blocks is not related to (i_size / i_blksize),
1452 * but instead 512 byte (2**9) size is required for
1453 * calculating num blocks.
1455 if (le64_to_cpu(file_inf.AllocationSize) > 4096)
1457 (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9;
1459 /* End of file and Attributes should not have to be updated on close */
1460 spin_unlock(&inode->i_lock);
1464 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1465 u64 persistent_fid, u64 volatile_fid,
1466 struct copychunk_ioctl *pcchunk)
1469 unsigned int ret_data_len;
1470 struct resume_key_req *res_key;
1472 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1473 FSCTL_SRV_REQUEST_RESUME_KEY, NULL, 0 /* no input */,
1474 CIFSMaxBufSize, (char **)&res_key, &ret_data_len);
1477 cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1478 goto req_res_key_exit;
1480 if (ret_data_len < sizeof(struct resume_key_req)) {
1481 cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n");
1483 goto req_res_key_exit;
1485 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1493 struct smb_rqst rqst[3];
1494 struct kvec rsp_iov[3];
1495 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1496 struct kvec qi_iov[1];
1497 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
1498 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1499 struct kvec close_iov[1];
1503 smb2_ioctl_query_info(const unsigned int xid,
1504 struct cifs_tcon *tcon,
1505 struct cifs_sb_info *cifs_sb,
1506 __le16 *path, int is_dir,
1509 struct iqi_vars *vars;
1510 struct smb_rqst *rqst;
1511 struct kvec *rsp_iov;
1512 struct cifs_ses *ses = tcon->ses;
1513 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1514 char __user *arg = (char __user *)p;
1515 struct smb_query_info qi;
1516 struct smb_query_info __user *pqi;
1518 int flags = CIFS_CP_CREATE_CLOSE_OP;
1519 struct smb2_query_info_rsp *qi_rsp = NULL;
1520 struct smb2_ioctl_rsp *io_rsp = NULL;
1521 void *buffer = NULL;
1522 int resp_buftype[3];
1523 struct cifs_open_parms oparms;
1524 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1525 struct cifs_fid fid;
1526 unsigned int size[2];
1528 int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR;
1529 void (*free_req1_func)(struct smb_rqst *r);
1531 vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
1534 rqst = &vars->rqst[0];
1535 rsp_iov = &vars->rsp_iov[0];
1537 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1539 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info))) {
1543 if (qi.output_buffer_length > 1024) {
1548 if (!ses || !server) {
1553 if (smb3_encryption_required(tcon))
1554 flags |= CIFS_TRANSFORM_REQ;
1556 if (qi.output_buffer_length) {
1557 buffer = memdup_user(arg + sizeof(struct smb_query_info), qi.output_buffer_length);
1558 if (IS_ERR(buffer)) {
1559 rc = PTR_ERR(buffer);
1565 rqst[0].rq_iov = &vars->open_iov[0];
1566 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1568 memset(&oparms, 0, sizeof(oparms));
1570 oparms.disposition = FILE_OPEN;
1571 oparms.create_options = cifs_create_options(cifs_sb, create_options);
1573 oparms.reconnect = false;
1575 if (qi.flags & PASSTHRU_FSCTL) {
1576 switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1577 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1578 oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1580 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1581 oparms.desired_access = GENERIC_ALL;
1583 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1584 oparms.desired_access = GENERIC_READ;
1586 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1587 oparms.desired_access = GENERIC_WRITE;
1590 } else if (qi.flags & PASSTHRU_SET_INFO) {
1591 oparms.desired_access = GENERIC_WRITE;
1593 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1596 rc = SMB2_open_init(tcon, server,
1597 &rqst[0], &oplock, &oparms, path);
1599 goto free_output_buffer;
1600 smb2_set_next_command(tcon, &rqst[0]);
1603 if (qi.flags & PASSTHRU_FSCTL) {
1604 /* Can eventually relax perm check since server enforces too */
1605 if (!capable(CAP_SYS_ADMIN)) {
1609 rqst[1].rq_iov = &vars->io_iov[0];
1610 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1612 rc = SMB2_ioctl_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1613 qi.info_type, buffer, qi.output_buffer_length,
1614 CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1615 MAX_SMB2_CLOSE_RESPONSE_SIZE);
1616 free_req1_func = SMB2_ioctl_free;
1617 } else if (qi.flags == PASSTHRU_SET_INFO) {
1618 /* Can eventually relax perm check since server enforces too */
1619 if (!capable(CAP_SYS_ADMIN)) {
1623 if (qi.output_buffer_length < 8) {
1627 rqst[1].rq_iov = &vars->si_iov[0];
1628 rqst[1].rq_nvec = 1;
1630 /* MS-FSCC 2.4.13 FileEndOfFileInformation */
1634 rc = SMB2_set_info_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1635 current->tgid, FILE_END_OF_FILE_INFORMATION,
1636 SMB2_O_INFO_FILE, 0, data, size);
1637 free_req1_func = SMB2_set_info_free;
1638 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1639 rqst[1].rq_iov = &vars->qi_iov[0];
1640 rqst[1].rq_nvec = 1;
1642 rc = SMB2_query_info_init(tcon, server,
1643 &rqst[1], COMPOUND_FID,
1644 COMPOUND_FID, qi.file_info_class,
1645 qi.info_type, qi.additional_information,
1646 qi.input_buffer_length,
1647 qi.output_buffer_length, buffer);
1648 free_req1_func = SMB2_query_info_free;
1649 } else { /* unknown flags */
1650 cifs_tcon_dbg(VFS, "Invalid passthru query flags: 0x%x\n",
1657 smb2_set_next_command(tcon, &rqst[1]);
1658 smb2_set_related(&rqst[1]);
1661 rqst[2].rq_iov = &vars->close_iov[0];
1662 rqst[2].rq_nvec = 1;
1664 rc = SMB2_close_init(tcon, server,
1665 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1668 smb2_set_related(&rqst[2]);
1670 rc = compound_send_recv(xid, ses, server,
1672 resp_buftype, rsp_iov);
1676 /* No need to bump num_remote_opens since handle immediately closed */
1677 if (qi.flags & PASSTHRU_FSCTL) {
1678 pqi = (struct smb_query_info __user *)arg;
1679 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1680 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1681 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1682 if (qi.input_buffer_length > 0 &&
1683 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length
1684 > rsp_iov[1].iov_len) {
1689 if (copy_to_user(&pqi->input_buffer_length,
1690 &qi.input_buffer_length,
1691 sizeof(qi.input_buffer_length))) {
1696 if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1697 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1698 qi.input_buffer_length))
1701 pqi = (struct smb_query_info __user *)arg;
1702 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1703 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1704 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1705 if (copy_to_user(&pqi->input_buffer_length,
1706 &qi.input_buffer_length,
1707 sizeof(qi.input_buffer_length))) {
1712 if (copy_to_user(pqi + 1, qi_rsp->Buffer,
1713 qi.input_buffer_length))
1718 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1719 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1720 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1721 SMB2_close_free(&rqst[2]);
1723 free_req1_func(&rqst[1]);
1725 SMB2_open_free(&rqst[0]);
1734 smb2_copychunk_range(const unsigned int xid,
1735 struct cifsFileInfo *srcfile,
1736 struct cifsFileInfo *trgtfile, u64 src_off,
1737 u64 len, u64 dest_off)
1740 unsigned int ret_data_len;
1741 struct copychunk_ioctl *pcchunk;
1742 struct copychunk_ioctl_rsp *retbuf = NULL;
1743 struct cifs_tcon *tcon;
1744 int chunks_copied = 0;
1745 bool chunk_sizes_updated = false;
1746 ssize_t bytes_written, total_bytes_written = 0;
1747 struct inode *inode;
1749 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1752 * We need to flush all unwritten data before we can send the
1753 * copychunk ioctl to the server.
1755 inode = d_inode(trgtfile->dentry);
1756 filemap_write_and_wait(inode->i_mapping);
1758 if (pcchunk == NULL)
1761 cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
1762 /* Request a key from the server to identify the source of the copy */
1763 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1764 srcfile->fid.persistent_fid,
1765 srcfile->fid.volatile_fid, pcchunk);
1767 /* Note: request_res_key sets res_key null only if rc !=0 */
1771 /* For now array only one chunk long, will make more flexible later */
1772 pcchunk->ChunkCount = cpu_to_le32(1);
1773 pcchunk->Reserved = 0;
1774 pcchunk->Reserved2 = 0;
1776 tcon = tlink_tcon(trgtfile->tlink);
1779 pcchunk->SourceOffset = cpu_to_le64(src_off);
1780 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1782 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
1784 /* Request server copy to target from src identified by key */
1787 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1788 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1789 (char *)pcchunk, sizeof(struct copychunk_ioctl),
1790 CIFSMaxBufSize, (char **)&retbuf, &ret_data_len);
1793 sizeof(struct copychunk_ioctl_rsp)) {
1794 cifs_tcon_dbg(VFS, "Invalid cchunk response size\n");
1798 if (retbuf->TotalBytesWritten == 0) {
1799 cifs_dbg(FYI, "no bytes copied\n");
1804 * Check if server claimed to write more than we asked
1806 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1807 le32_to_cpu(pcchunk->Length)) {
1808 cifs_tcon_dbg(VFS, "Invalid copy chunk response\n");
1812 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1813 cifs_tcon_dbg(VFS, "Invalid num chunks written\n");
1819 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1820 src_off += bytes_written;
1821 dest_off += bytes_written;
1822 len -= bytes_written;
1823 total_bytes_written += bytes_written;
1825 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1826 le32_to_cpu(retbuf->ChunksWritten),
1827 le32_to_cpu(retbuf->ChunkBytesWritten),
1829 } else if (rc == -EINVAL) {
1830 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1833 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1834 le32_to_cpu(retbuf->ChunksWritten),
1835 le32_to_cpu(retbuf->ChunkBytesWritten),
1836 le32_to_cpu(retbuf->TotalBytesWritten));
1839 * Check if this is the first request using these sizes,
1840 * (ie check if copy succeed once with original sizes
1841 * and check if the server gave us different sizes after
1842 * we already updated max sizes on previous request).
1843 * if not then why is the server returning an error now
1845 if ((chunks_copied != 0) || chunk_sizes_updated)
1848 /* Check that server is not asking us to grow size */
1849 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1850 tcon->max_bytes_chunk)
1851 tcon->max_bytes_chunk =
1852 le32_to_cpu(retbuf->ChunkBytesWritten);
1854 goto cchunk_out; /* server gave us bogus size */
1856 /* No need to change MaxChunks since already set to 1 */
1857 chunk_sizes_updated = true;
1868 return total_bytes_written;
1872 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1873 struct cifs_fid *fid)
1875 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1879 smb2_read_data_offset(char *buf)
1881 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1883 return rsp->DataOffset;
1887 smb2_read_data_length(char *buf, bool in_remaining)
1889 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1892 return le32_to_cpu(rsp->DataRemaining);
1894 return le32_to_cpu(rsp->DataLength);
1899 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1900 struct cifs_io_parms *parms, unsigned int *bytes_read,
1901 char **buf, int *buf_type)
1903 parms->persistent_fid = pfid->persistent_fid;
1904 parms->volatile_fid = pfid->volatile_fid;
1905 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1909 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1910 struct cifs_io_parms *parms, unsigned int *written,
1911 struct kvec *iov, unsigned long nr_segs)
1914 parms->persistent_fid = pfid->persistent_fid;
1915 parms->volatile_fid = pfid->volatile_fid;
1916 return SMB2_write(xid, parms, written, iov, nr_segs);
1919 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1920 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1921 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1923 struct cifsInodeInfo *cifsi;
1926 cifsi = CIFS_I(inode);
1928 /* if file already sparse don't bother setting sparse again */
1929 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1930 return true; /* already sparse */
1932 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1933 return true; /* already not sparse */
1936 * Can't check for sparse support on share the usual way via the
1937 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1938 * since Samba server doesn't set the flag on the share, yet
1939 * supports the set sparse FSCTL and returns sparse correctly
1940 * in the file attributes. If we fail setting sparse though we
1941 * mark that server does not support sparse files for this share
1942 * to avoid repeatedly sending the unsupported fsctl to server
1943 * if the file is repeatedly extended.
1945 if (tcon->broken_sparse_sup)
1948 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1949 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1950 &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
1952 tcon->broken_sparse_sup = true;
1953 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1958 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1960 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1966 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1967 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1969 __le64 eof = cpu_to_le64(size);
1970 struct inode *inode;
1973 * If extending file more than one page make sparse. Many Linux fs
1974 * make files sparse by default when extending via ftruncate
1976 inode = d_inode(cfile->dentry);
1978 if (!set_alloc && (size > inode->i_size + 8192)) {
1979 __u8 set_sparse = 1;
1981 /* whether set sparse succeeds or not, extend the file */
1982 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1985 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1986 cfile->fid.volatile_fid, cfile->pid, &eof);
1990 smb2_duplicate_extents(const unsigned int xid,
1991 struct cifsFileInfo *srcfile,
1992 struct cifsFileInfo *trgtfile, u64 src_off,
1993 u64 len, u64 dest_off)
1996 unsigned int ret_data_len;
1997 struct inode *inode;
1998 struct duplicate_extents_to_file dup_ext_buf;
1999 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
2001 /* server fileays advertise duplicate extent support with this flag */
2002 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
2003 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
2006 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
2007 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
2008 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
2009 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
2010 dup_ext_buf.ByteCount = cpu_to_le64(len);
2011 cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
2012 src_off, dest_off, len);
2014 inode = d_inode(trgtfile->dentry);
2015 if (inode->i_size < dest_off + len) {
2016 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
2018 goto duplicate_extents_out;
2021 * Although also could set plausible allocation size (i_blocks)
2022 * here in addition to setting the file size, in reflink
2023 * it is likely that the target file is sparse. Its allocation
2024 * size will be queried on next revalidate, but it is important
2025 * to make sure that file's cached size is updated immediately
2027 cifs_setsize(inode, dest_off + len);
2029 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
2030 trgtfile->fid.volatile_fid,
2031 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
2032 (char *)&dup_ext_buf,
2033 sizeof(struct duplicate_extents_to_file),
2034 CIFSMaxBufSize, NULL,
2037 if (ret_data_len > 0)
2038 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
2040 duplicate_extents_out:
2045 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
2046 struct cifsFileInfo *cfile)
2048 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
2049 cfile->fid.volatile_fid);
2053 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
2054 struct cifsFileInfo *cfile)
2056 struct fsctl_set_integrity_information_req integr_info;
2057 unsigned int ret_data_len;
2059 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
2060 integr_info.Flags = 0;
2061 integr_info.Reserved = 0;
2063 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2064 cfile->fid.volatile_fid,
2065 FSCTL_SET_INTEGRITY_INFORMATION,
2066 (char *)&integr_info,
2067 sizeof(struct fsctl_set_integrity_information_req),
2068 CIFSMaxBufSize, NULL,
2073 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
2074 #define GMT_TOKEN_SIZE 50
2076 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
2079 * Input buffer contains (empty) struct smb_snapshot array with size filled in
2080 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
2083 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
2084 struct cifsFileInfo *cfile, void __user *ioc_buf)
2086 char *retbuf = NULL;
2087 unsigned int ret_data_len = 0;
2089 u32 max_response_size;
2090 struct smb_snapshot_array snapshot_in;
2093 * On the first query to enumerate the list of snapshots available
2094 * for this volume the buffer begins with 0 (number of snapshots
2095 * which can be returned is zero since at that point we do not know
2096 * how big the buffer needs to be). On the second query,
2097 * it (ret_data_len) is set to number of snapshots so we can
2098 * know to set the maximum response size larger (see below).
2100 if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
2104 * Note that for snapshot queries that servers like Azure expect that
2105 * the first query be minimal size (and just used to get the number/size
2106 * of previous versions) so response size must be specified as EXACTLY
2107 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
2110 if (ret_data_len == 0)
2111 max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
2113 max_response_size = CIFSMaxBufSize;
2115 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2116 cfile->fid.volatile_fid,
2117 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
2118 NULL, 0 /* no input data */, max_response_size,
2121 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
2126 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
2128 if (copy_from_user(&snapshot_in, ioc_buf,
2129 sizeof(struct smb_snapshot_array))) {
2136 * Check for min size, ie not large enough to fit even one GMT
2137 * token (snapshot). On the first ioctl some users may pass in
2138 * smaller size (or zero) to simply get the size of the array
2139 * so the user space caller can allocate sufficient memory
2140 * and retry the ioctl again with larger array size sufficient
2141 * to hold all of the snapshot GMT tokens on the second try.
2143 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
2144 ret_data_len = sizeof(struct smb_snapshot_array);
2147 * We return struct SRV_SNAPSHOT_ARRAY, followed by
2148 * the snapshot array (of 50 byte GMT tokens) each
2149 * representing an available previous version of the data
2151 if (ret_data_len > (snapshot_in.snapshot_array_size +
2152 sizeof(struct smb_snapshot_array)))
2153 ret_data_len = snapshot_in.snapshot_array_size +
2154 sizeof(struct smb_snapshot_array);
2156 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
2167 smb3_notify(const unsigned int xid, struct file *pfile,
2168 void __user *ioc_buf)
2170 struct smb3_notify notify;
2171 struct dentry *dentry = pfile->f_path.dentry;
2172 struct inode *inode = file_inode(pfile);
2173 struct cifs_sb_info *cifs_sb;
2174 struct cifs_open_parms oparms;
2175 struct cifs_fid fid;
2176 struct cifs_tcon *tcon;
2177 unsigned char *path = NULL;
2178 __le16 *utf16_path = NULL;
2179 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2182 path = build_path_from_dentry(dentry);
2186 cifs_sb = CIFS_SB(inode->i_sb);
2188 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2189 if (utf16_path == NULL) {
2194 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify))) {
2199 tcon = cifs_sb_master_tcon(cifs_sb);
2201 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
2202 oparms.disposition = FILE_OPEN;
2203 oparms.create_options = cifs_create_options(cifs_sb, 0);
2205 oparms.reconnect = false;
2207 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
2212 rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid,
2213 notify.watch_tree, notify.completion_filter);
2215 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2217 cifs_dbg(FYI, "change notify for path %s rc %d\n", path, rc);
2226 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
2227 const char *path, struct cifs_sb_info *cifs_sb,
2228 struct cifs_fid *fid, __u16 search_flags,
2229 struct cifs_search_info *srch_inf)
2232 struct smb_rqst rqst[2];
2233 struct kvec rsp_iov[2];
2234 int resp_buftype[2];
2235 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2236 struct kvec qd_iov[SMB2_QUERY_DIRECTORY_IOV_SIZE];
2238 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2239 struct cifs_open_parms oparms;
2240 struct smb2_query_directory_rsp *qd_rsp = NULL;
2241 struct smb2_create_rsp *op_rsp = NULL;
2242 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2244 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2248 if (smb3_encryption_required(tcon))
2249 flags |= CIFS_TRANSFORM_REQ;
2251 memset(rqst, 0, sizeof(rqst));
2252 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
2253 memset(rsp_iov, 0, sizeof(rsp_iov));
2256 memset(&open_iov, 0, sizeof(open_iov));
2257 rqst[0].rq_iov = open_iov;
2258 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2261 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
2262 oparms.disposition = FILE_OPEN;
2263 oparms.create_options = cifs_create_options(cifs_sb, 0);
2265 oparms.reconnect = false;
2267 rc = SMB2_open_init(tcon, server,
2268 &rqst[0], &oplock, &oparms, utf16_path);
2271 smb2_set_next_command(tcon, &rqst[0]);
2273 /* Query directory */
2274 srch_inf->entries_in_buffer = 0;
2275 srch_inf->index_of_last_entry = 2;
2277 memset(&qd_iov, 0, sizeof(qd_iov));
2278 rqst[1].rq_iov = qd_iov;
2279 rqst[1].rq_nvec = SMB2_QUERY_DIRECTORY_IOV_SIZE;
2281 rc = SMB2_query_directory_init(xid, tcon, server,
2283 COMPOUND_FID, COMPOUND_FID,
2284 0, srch_inf->info_level);
2288 smb2_set_related(&rqst[1]);
2290 rc = compound_send_recv(xid, tcon->ses, server,
2292 resp_buftype, rsp_iov);
2294 /* If the open failed there is nothing to do */
2295 op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
2296 if (op_rsp == NULL || op_rsp->sync_hdr.Status != STATUS_SUCCESS) {
2297 cifs_dbg(FYI, "query_dir_first: open failed rc=%d\n", rc);
2300 fid->persistent_fid = op_rsp->PersistentFileId;
2301 fid->volatile_fid = op_rsp->VolatileFileId;
2303 /* Anything else than ENODATA means a genuine error */
2304 if (rc && rc != -ENODATA) {
2305 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2306 cifs_dbg(FYI, "query_dir_first: query directory failed rc=%d\n", rc);
2307 trace_smb3_query_dir_err(xid, fid->persistent_fid,
2308 tcon->tid, tcon->ses->Suid, 0, 0, rc);
2312 atomic_inc(&tcon->num_remote_opens);
2314 qd_rsp = (struct smb2_query_directory_rsp *)rsp_iov[1].iov_base;
2315 if (qd_rsp->sync_hdr.Status == STATUS_NO_MORE_FILES) {
2316 trace_smb3_query_dir_done(xid, fid->persistent_fid,
2317 tcon->tid, tcon->ses->Suid, 0, 0);
2318 srch_inf->endOfSearch = true;
2323 rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1],
2326 trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid,
2327 tcon->ses->Suid, 0, 0, rc);
2330 resp_buftype[1] = CIFS_NO_BUFFER;
2332 trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid,
2333 tcon->ses->Suid, 0, srch_inf->entries_in_buffer);
2337 SMB2_open_free(&rqst[0]);
2338 SMB2_query_directory_free(&rqst[1]);
2339 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2340 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2345 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
2346 struct cifs_fid *fid, __u16 search_flags,
2347 struct cifs_search_info *srch_inf)
2349 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
2350 fid->volatile_fid, 0, srch_inf);
2354 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
2355 struct cifs_fid *fid)
2357 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2361 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2362 * the number of credits and return true. Otherwise - return false.
2365 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
2367 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2369 if (shdr->Status != STATUS_PENDING)
2372 if (shdr->CreditRequest) {
2373 spin_lock(&server->req_lock);
2374 server->credits += le16_to_cpu(shdr->CreditRequest);
2375 spin_unlock(&server->req_lock);
2376 wake_up(&server->request_q);
2383 smb2_is_session_expired(char *buf)
2385 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2387 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
2388 shdr->Status != STATUS_USER_SESSION_DELETED)
2391 trace_smb3_ses_expired(shdr->TreeId, shdr->SessionId,
2392 le16_to_cpu(shdr->Command),
2393 le64_to_cpu(shdr->MessageId));
2394 cifs_dbg(FYI, "Session expired or deleted\n");
2400 smb2_is_status_io_timeout(char *buf)
2402 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2404 if (shdr->Status == STATUS_IO_TIMEOUT)
2411 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
2412 struct cifsInodeInfo *cinode)
2414 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
2415 return SMB2_lease_break(0, tcon, cinode->lease_key,
2416 smb2_get_lease_state(cinode));
2418 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
2420 CIFS_CACHE_READ(cinode) ? 1 : 0);
2424 smb2_set_related(struct smb_rqst *rqst)
2426 struct smb2_sync_hdr *shdr;
2428 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
2430 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2433 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2436 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
2439 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
2441 struct smb2_sync_hdr *shdr;
2442 struct cifs_ses *ses = tcon->ses;
2443 struct TCP_Server_Info *server = ses->server;
2444 unsigned long len = smb_rqst_len(server, rqst);
2447 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
2449 cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2453 /* SMB headers in a compound are 8 byte aligned. */
2455 /* No padding needed */
2459 num_padding = 8 - (len & 7);
2460 if (!smb3_encryption_required(tcon)) {
2462 * If we do not have encryption then we can just add an extra
2463 * iov for the padding.
2465 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2466 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2471 * We can not add a small padding iov for the encryption case
2472 * because the encryption framework can not handle the padding
2474 * We have to flatten this into a single buffer and add
2475 * the padding to it.
2477 for (i = 1; i < rqst->rq_nvec; i++) {
2478 memcpy(rqst->rq_iov[0].iov_base +
2479 rqst->rq_iov[0].iov_len,
2480 rqst->rq_iov[i].iov_base,
2481 rqst->rq_iov[i].iov_len);
2482 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2484 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2486 rqst->rq_iov[0].iov_len += num_padding;
2492 shdr->NextCommand = cpu_to_le32(len);
2496 * Passes the query info response back to the caller on success.
2497 * Caller need to free this with free_rsp_buf().
2500 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2501 __le16 *utf16_path, u32 desired_access,
2502 u32 class, u32 type, u32 output_len,
2503 struct kvec *rsp, int *buftype,
2504 struct cifs_sb_info *cifs_sb)
2506 struct cifs_ses *ses = tcon->ses;
2507 struct TCP_Server_Info *server = cifs_pick_channel(ses);
2508 int flags = CIFS_CP_CREATE_CLOSE_OP;
2509 struct smb_rqst rqst[3];
2510 int resp_buftype[3];
2511 struct kvec rsp_iov[3];
2512 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2513 struct kvec qi_iov[1];
2514 struct kvec close_iov[1];
2515 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2516 struct cifs_open_parms oparms;
2517 struct cifs_fid fid;
2520 if (smb3_encryption_required(tcon))
2521 flags |= CIFS_TRANSFORM_REQ;
2523 memset(rqst, 0, sizeof(rqst));
2524 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2525 memset(rsp_iov, 0, sizeof(rsp_iov));
2527 memset(&open_iov, 0, sizeof(open_iov));
2528 rqst[0].rq_iov = open_iov;
2529 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2532 oparms.desired_access = desired_access;
2533 oparms.disposition = FILE_OPEN;
2534 oparms.create_options = cifs_create_options(cifs_sb, 0);
2536 oparms.reconnect = false;
2538 rc = SMB2_open_init(tcon, server,
2539 &rqst[0], &oplock, &oparms, utf16_path);
2542 smb2_set_next_command(tcon, &rqst[0]);
2544 memset(&qi_iov, 0, sizeof(qi_iov));
2545 rqst[1].rq_iov = qi_iov;
2546 rqst[1].rq_nvec = 1;
2548 rc = SMB2_query_info_init(tcon, server,
2549 &rqst[1], COMPOUND_FID, COMPOUND_FID,
2555 smb2_set_next_command(tcon, &rqst[1]);
2556 smb2_set_related(&rqst[1]);
2558 memset(&close_iov, 0, sizeof(close_iov));
2559 rqst[2].rq_iov = close_iov;
2560 rqst[2].rq_nvec = 1;
2562 rc = SMB2_close_init(tcon, server,
2563 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2566 smb2_set_related(&rqst[2]);
2568 rc = compound_send_recv(xid, ses, server,
2570 resp_buftype, rsp_iov);
2572 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2573 if (rc == -EREMCHG) {
2574 tcon->need_reconnect = true;
2575 pr_warn_once("server share %s deleted\n",
2581 *buftype = resp_buftype[1];
2584 SMB2_open_free(&rqst[0]);
2585 SMB2_query_info_free(&rqst[1]);
2586 SMB2_close_free(&rqst[2]);
2587 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2588 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2593 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2594 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2596 struct smb2_query_info_rsp *rsp;
2597 struct smb2_fs_full_size_info *info = NULL;
2598 __le16 utf16_path = 0; /* Null - open root of share */
2599 struct kvec rsp_iov = {NULL, 0};
2600 int buftype = CIFS_NO_BUFFER;
2604 rc = smb2_query_info_compound(xid, tcon, &utf16_path,
2605 FILE_READ_ATTRIBUTES,
2606 FS_FULL_SIZE_INFORMATION,
2607 SMB2_O_INFO_FILESYSTEM,
2608 sizeof(struct smb2_fs_full_size_info),
2609 &rsp_iov, &buftype, cifs_sb);
2613 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2614 buf->f_type = SMB2_MAGIC_NUMBER;
2615 info = (struct smb2_fs_full_size_info *)(
2616 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2617 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2618 le32_to_cpu(rsp->OutputBufferLength),
2620 sizeof(struct smb2_fs_full_size_info));
2622 smb2_copy_fs_info_to_kstatfs(info, buf);
2625 free_rsp_buf(buftype, rsp_iov.iov_base);
2630 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2631 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2634 __le16 srch_path = 0; /* Null - open root of share */
2635 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2636 struct cifs_open_parms oparms;
2637 struct cifs_fid fid;
2639 if (!tcon->posix_extensions)
2640 return smb2_queryfs(xid, tcon, cifs_sb, buf);
2643 oparms.desired_access = FILE_READ_ATTRIBUTES;
2644 oparms.disposition = FILE_OPEN;
2645 oparms.create_options = cifs_create_options(cifs_sb, 0);
2647 oparms.reconnect = false;
2649 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
2654 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2655 fid.volatile_fid, buf);
2656 buf->f_type = SMB2_MAGIC_NUMBER;
2657 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2662 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2664 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2665 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2669 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2670 __u64 length, __u32 type, int lock, int unlock, bool wait)
2672 if (unlock && !lock)
2673 type = SMB2_LOCKFLAG_UNLOCK;
2674 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2675 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2676 current->tgid, length, offset, type, wait);
2680 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2682 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2686 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2688 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2692 smb2_new_lease_key(struct cifs_fid *fid)
2694 generate_random_uuid(fid->lease_key);
2698 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2699 const char *search_name,
2700 struct dfs_info3_param **target_nodes,
2701 unsigned int *num_of_nodes,
2702 const struct nls_table *nls_codepage, int remap)
2705 __le16 *utf16_path = NULL;
2706 int utf16_path_len = 0;
2707 struct cifs_tcon *tcon;
2708 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2709 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2710 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2712 cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name);
2715 * Try to use the IPC tcon, otherwise just use any
2717 tcon = ses->tcon_ipc;
2719 spin_lock(&cifs_tcp_ses_lock);
2720 tcon = list_first_entry_or_null(&ses->tcon_list,
2725 spin_unlock(&cifs_tcp_ses_lock);
2729 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2735 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2737 nls_codepage, remap);
2743 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2744 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2750 /* Highest DFS referral version understood */
2751 dfs_req->MaxReferralLevel = DFS_VERSION;
2753 /* Path to resolve in an UTF-16 null-terminated string */
2754 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2757 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2758 FSCTL_DFS_GET_REFERRALS,
2759 (char *)dfs_req, dfs_req_size, CIFSMaxBufSize,
2760 (char **)&dfs_rsp, &dfs_rsp_size);
2761 } while (rc == -EAGAIN);
2764 if ((rc != -ENOENT) && (rc != -EOPNOTSUPP))
2765 cifs_tcon_dbg(VFS, "ioctl error in %s rc=%d\n", __func__, rc);
2769 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
2770 num_of_nodes, target_nodes,
2771 nls_codepage, remap, search_name,
2772 true /* is_unicode */);
2774 cifs_tcon_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc);
2779 if (tcon && !tcon->ipc) {
2780 /* ipc tcons are not refcounted */
2781 spin_lock(&cifs_tcp_ses_lock);
2783 spin_unlock(&cifs_tcp_ses_lock);
2792 parse_reparse_posix(struct reparse_posix_data *symlink_buf,
2793 u32 plen, char **target_path,
2794 struct cifs_sb_info *cifs_sb)
2798 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
2799 len = le16_to_cpu(symlink_buf->ReparseDataLength);
2801 if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
2802 cifs_dbg(VFS, "%lld not a supported symlink type\n",
2803 le64_to_cpu(symlink_buf->InodeType));
2807 *target_path = cifs_strndup_from_utf16(
2808 symlink_buf->PathBuffer,
2809 len, true, cifs_sb->local_nls);
2810 if (!(*target_path))
2813 convert_delimiter(*target_path, '/');
2814 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2820 parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
2821 u32 plen, char **target_path,
2822 struct cifs_sb_info *cifs_sb)
2824 unsigned int sub_len;
2825 unsigned int sub_offset;
2827 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */
2829 sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset);
2830 sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength);
2831 if (sub_offset + 20 > plen ||
2832 sub_offset + sub_len + 20 > plen) {
2833 cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
2837 *target_path = cifs_strndup_from_utf16(
2838 symlink_buf->PathBuffer + sub_offset,
2839 sub_len, true, cifs_sb->local_nls);
2840 if (!(*target_path))
2843 convert_delimiter(*target_path, '/');
2844 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2850 parse_reparse_point(struct reparse_data_buffer *buf,
2851 u32 plen, char **target_path,
2852 struct cifs_sb_info *cifs_sb)
2854 if (plen < sizeof(struct reparse_data_buffer)) {
2855 cifs_dbg(VFS, "reparse buffer is too small. Must be at least 8 bytes but was %d\n",
2860 if (plen < le16_to_cpu(buf->ReparseDataLength) +
2861 sizeof(struct reparse_data_buffer)) {
2862 cifs_dbg(VFS, "srv returned invalid reparse buf length: %d\n",
2867 /* See MS-FSCC 2.1.2 */
2868 switch (le32_to_cpu(buf->ReparseTag)) {
2869 case IO_REPARSE_TAG_NFS:
2870 return parse_reparse_posix(
2871 (struct reparse_posix_data *)buf,
2872 plen, target_path, cifs_sb);
2873 case IO_REPARSE_TAG_SYMLINK:
2874 return parse_reparse_symlink(
2875 (struct reparse_symlink_data_buffer *)buf,
2876 plen, target_path, cifs_sb);
2878 cifs_dbg(VFS, "srv returned unknown symlink buffer tag:0x%08x\n",
2879 le32_to_cpu(buf->ReparseTag));
2884 #define SMB2_SYMLINK_STRUCT_SIZE \
2885 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
2888 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
2889 struct cifs_sb_info *cifs_sb, const char *full_path,
2890 char **target_path, bool is_reparse_point)
2893 __le16 *utf16_path = NULL;
2894 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2895 struct cifs_open_parms oparms;
2896 struct cifs_fid fid;
2897 struct kvec err_iov = {NULL, 0};
2898 struct smb2_err_rsp *err_buf = NULL;
2899 struct smb2_symlink_err_rsp *symlink;
2900 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2901 unsigned int sub_len;
2902 unsigned int sub_offset;
2903 unsigned int print_len;
2904 unsigned int print_offset;
2905 int flags = CIFS_CP_CREATE_CLOSE_OP;
2906 struct smb_rqst rqst[3];
2907 int resp_buftype[3];
2908 struct kvec rsp_iov[3];
2909 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2910 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2911 struct kvec close_iov[1];
2912 struct smb2_create_rsp *create_rsp;
2913 struct smb2_ioctl_rsp *ioctl_rsp;
2914 struct reparse_data_buffer *reparse_buf;
2915 int create_options = is_reparse_point ? OPEN_REPARSE_POINT : 0;
2918 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2920 *target_path = NULL;
2922 if (smb3_encryption_required(tcon))
2923 flags |= CIFS_TRANSFORM_REQ;
2925 memset(rqst, 0, sizeof(rqst));
2926 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2927 memset(rsp_iov, 0, sizeof(rsp_iov));
2929 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
2934 memset(&open_iov, 0, sizeof(open_iov));
2935 rqst[0].rq_iov = open_iov;
2936 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2938 memset(&oparms, 0, sizeof(oparms));
2940 oparms.desired_access = FILE_READ_ATTRIBUTES;
2941 oparms.disposition = FILE_OPEN;
2942 oparms.create_options = cifs_create_options(cifs_sb, create_options);
2944 oparms.reconnect = false;
2946 rc = SMB2_open_init(tcon, server,
2947 &rqst[0], &oplock, &oparms, utf16_path);
2950 smb2_set_next_command(tcon, &rqst[0]);
2954 memset(&io_iov, 0, sizeof(io_iov));
2955 rqst[1].rq_iov = io_iov;
2956 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
2958 rc = SMB2_ioctl_init(tcon, server,
2959 &rqst[1], fid.persistent_fid,
2960 fid.volatile_fid, FSCTL_GET_REPARSE_POINT, NULL, 0,
2962 MAX_SMB2_CREATE_RESPONSE_SIZE -
2963 MAX_SMB2_CLOSE_RESPONSE_SIZE);
2967 smb2_set_next_command(tcon, &rqst[1]);
2968 smb2_set_related(&rqst[1]);
2972 memset(&close_iov, 0, sizeof(close_iov));
2973 rqst[2].rq_iov = close_iov;
2974 rqst[2].rq_nvec = 1;
2976 rc = SMB2_close_init(tcon, server,
2977 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2981 smb2_set_related(&rqst[2]);
2983 rc = compound_send_recv(xid, tcon->ses, server,
2985 resp_buftype, rsp_iov);
2987 create_rsp = rsp_iov[0].iov_base;
2988 if (create_rsp && create_rsp->sync_hdr.Status)
2989 err_iov = rsp_iov[0];
2990 ioctl_rsp = rsp_iov[1].iov_base;
2993 * Open was successful and we got an ioctl response.
2995 if ((rc == 0) && (is_reparse_point)) {
2996 /* See MS-FSCC 2.3.23 */
2998 reparse_buf = (struct reparse_data_buffer *)
2999 ((char *)ioctl_rsp +
3000 le32_to_cpu(ioctl_rsp->OutputOffset));
3001 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3003 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3004 rsp_iov[1].iov_len) {
3005 cifs_tcon_dbg(VFS, "srv returned invalid ioctl len: %d\n",
3011 rc = parse_reparse_point(reparse_buf, plen, target_path,
3016 if (!rc || !err_iov.iov_base) {
3021 err_buf = err_iov.iov_base;
3022 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
3023 err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) {
3028 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
3029 if (le32_to_cpu(symlink->SymLinkErrorTag) != SYMLINK_ERROR_TAG ||
3030 le32_to_cpu(symlink->ReparseTag) != IO_REPARSE_TAG_SYMLINK) {
3035 /* open must fail on symlink - reset rc */
3037 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
3038 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
3039 print_len = le16_to_cpu(symlink->PrintNameLength);
3040 print_offset = le16_to_cpu(symlink->PrintNameOffset);
3042 if (err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
3047 if (err_iov.iov_len <
3048 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
3053 *target_path = cifs_strndup_from_utf16(
3054 (char *)symlink->PathBuffer + sub_offset,
3055 sub_len, true, cifs_sb->local_nls);
3056 if (!(*target_path)) {
3060 convert_delimiter(*target_path, '/');
3061 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
3064 cifs_dbg(FYI, "query symlink rc %d\n", rc);
3066 SMB2_open_free(&rqst[0]);
3067 SMB2_ioctl_free(&rqst[1]);
3068 SMB2_close_free(&rqst[2]);
3069 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3070 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3071 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3076 smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
3077 struct cifs_sb_info *cifs_sb, const char *full_path,
3081 __le16 *utf16_path = NULL;
3082 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3083 struct cifs_open_parms oparms;
3084 struct cifs_fid fid;
3085 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
3086 int flags = CIFS_CP_CREATE_CLOSE_OP;
3087 struct smb_rqst rqst[3];
3088 int resp_buftype[3];
3089 struct kvec rsp_iov[3];
3090 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
3091 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
3092 struct kvec close_iov[1];
3093 struct smb2_ioctl_rsp *ioctl_rsp;
3094 struct reparse_data_buffer *reparse_buf;
3097 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
3099 if (smb3_encryption_required(tcon))
3100 flags |= CIFS_TRANSFORM_REQ;
3102 memset(rqst, 0, sizeof(rqst));
3103 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
3104 memset(rsp_iov, 0, sizeof(rsp_iov));
3106 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
3111 * setup smb2open - TODO add optimization to call cifs_get_readable_path
3112 * to see if there is a handle already open that we can use
3114 memset(&open_iov, 0, sizeof(open_iov));
3115 rqst[0].rq_iov = open_iov;
3116 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
3118 memset(&oparms, 0, sizeof(oparms));
3120 oparms.desired_access = FILE_READ_ATTRIBUTES;
3121 oparms.disposition = FILE_OPEN;
3122 oparms.create_options = cifs_create_options(cifs_sb, OPEN_REPARSE_POINT);
3124 oparms.reconnect = false;
3126 rc = SMB2_open_init(tcon, server,
3127 &rqst[0], &oplock, &oparms, utf16_path);
3130 smb2_set_next_command(tcon, &rqst[0]);
3134 memset(&io_iov, 0, sizeof(io_iov));
3135 rqst[1].rq_iov = io_iov;
3136 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3138 rc = SMB2_ioctl_init(tcon, server,
3139 &rqst[1], COMPOUND_FID,
3140 COMPOUND_FID, FSCTL_GET_REPARSE_POINT, NULL, 0,
3142 MAX_SMB2_CREATE_RESPONSE_SIZE -
3143 MAX_SMB2_CLOSE_RESPONSE_SIZE);
3147 smb2_set_next_command(tcon, &rqst[1]);
3148 smb2_set_related(&rqst[1]);
3152 memset(&close_iov, 0, sizeof(close_iov));
3153 rqst[2].rq_iov = close_iov;
3154 rqst[2].rq_nvec = 1;
3156 rc = SMB2_close_init(tcon, server,
3157 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3161 smb2_set_related(&rqst[2]);
3163 rc = compound_send_recv(xid, tcon->ses, server,
3165 resp_buftype, rsp_iov);
3167 ioctl_rsp = rsp_iov[1].iov_base;
3170 * Open was successful and we got an ioctl response.
3173 /* See MS-FSCC 2.3.23 */
3175 reparse_buf = (struct reparse_data_buffer *)
3176 ((char *)ioctl_rsp +
3177 le32_to_cpu(ioctl_rsp->OutputOffset));
3178 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3180 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3181 rsp_iov[1].iov_len) {
3182 cifs_tcon_dbg(FYI, "srv returned invalid ioctl len: %d\n",
3187 *tag = le32_to_cpu(reparse_buf->ReparseTag);
3192 SMB2_open_free(&rqst[0]);
3193 SMB2_ioctl_free(&rqst[1]);
3194 SMB2_close_free(&rqst[2]);
3195 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3196 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3197 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3201 static struct cifs_ntsd *
3202 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
3203 const struct cifs_fid *cifsfid, u32 *pacllen)
3205 struct cifs_ntsd *pntsd = NULL;
3207 int rc = -EOPNOTSUPP;
3208 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3211 return ERR_CAST(tlink);
3214 cifs_dbg(FYI, "trying to get acl\n");
3216 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
3217 cifsfid->volatile_fid, (void **)&pntsd, pacllen);
3220 cifs_put_tlink(tlink);
3222 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3229 static struct cifs_ntsd *
3230 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
3231 const char *path, u32 *pacllen)
3233 struct cifs_ntsd *pntsd = NULL;
3234 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3237 struct cifs_tcon *tcon;
3238 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3239 struct cifs_fid fid;
3240 struct cifs_open_parms oparms;
3243 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
3245 return ERR_CAST(tlink);
3247 tcon = tlink_tcon(tlink);
3250 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3258 oparms.desired_access = READ_CONTROL;
3259 oparms.disposition = FILE_OPEN;
3261 * When querying an ACL, even if the file is a symlink we want to open
3262 * the source not the target, and so the protocol requires that the
3263 * client specify this flag when opening a reparse point
3265 oparms.create_options = cifs_create_options(cifs_sb, 0) | OPEN_REPARSE_POINT;
3267 oparms.reconnect = false;
3269 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
3273 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3274 fid.volatile_fid, (void **)&pntsd, pacllen);
3275 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3278 cifs_put_tlink(tlink);
3281 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3288 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
3289 struct inode *inode, const char *path, int aclflag)
3291 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3293 int rc, access_flags = 0;
3294 struct cifs_tcon *tcon;
3295 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
3296 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3297 struct cifs_fid fid;
3298 struct cifs_open_parms oparms;
3301 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
3303 return PTR_ERR(tlink);
3305 tcon = tlink_tcon(tlink);
3308 if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP)
3309 access_flags = WRITE_OWNER;
3311 access_flags = WRITE_DAC;
3313 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3321 oparms.desired_access = access_flags;
3322 oparms.create_options = cifs_create_options(cifs_sb, 0);
3323 oparms.disposition = FILE_OPEN;
3326 oparms.reconnect = false;
3328 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
3332 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3333 fid.volatile_fid, pnntsd, acllen, aclflag);
3334 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3337 cifs_put_tlink(tlink);
3342 /* Retrieve an ACL from the server */
3343 static struct cifs_ntsd *
3344 get_smb2_acl(struct cifs_sb_info *cifs_sb,
3345 struct inode *inode, const char *path,
3348 struct cifs_ntsd *pntsd = NULL;
3349 struct cifsFileInfo *open_file = NULL;
3352 open_file = find_readable_file(CIFS_I(inode), true);
3354 return get_smb2_acl_by_path(cifs_sb, path, pacllen);
3356 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen);
3357 cifsFileInfo_put(open_file);
3361 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3362 loff_t offset, loff_t len, bool keep_size)
3364 struct cifs_ses *ses = tcon->ses;
3365 struct inode *inode;
3366 struct cifsInodeInfo *cifsi;
3367 struct cifsFileInfo *cfile = file->private_data;
3368 struct file_zero_data_information fsctl_buf;
3375 inode = d_inode(cfile->dentry);
3376 cifsi = CIFS_I(inode);
3378 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3379 ses->Suid, offset, len);
3382 * We zero the range through ioctl, so we need remove the page caches
3383 * first, otherwise the data may be inconsistent with the server.
3385 truncate_pagecache_range(inode, offset, offset + len - 1);
3387 /* if file not oplocked can't be sure whether asking to extend size */
3388 if (!CIFS_CACHE_READ(cifsi))
3389 if (keep_size == false) {
3391 trace_smb3_zero_err(xid, cfile->fid.persistent_fid,
3392 tcon->tid, ses->Suid, offset, len, rc);
3397 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3399 fsctl_buf.FileOffset = cpu_to_le64(offset);
3400 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3402 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3403 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3405 sizeof(struct file_zero_data_information),
3408 goto zero_range_exit;
3411 * do we also need to change the size of the file?
3413 if (keep_size == false && i_size_read(inode) < offset + len) {
3414 eof = cpu_to_le64(offset + len);
3415 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3416 cfile->fid.volatile_fid, cfile->pid, &eof);
3422 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
3423 ses->Suid, offset, len, rc);
3425 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
3426 ses->Suid, offset, len);
3430 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
3431 loff_t offset, loff_t len)
3433 struct inode *inode = file_inode(file);
3434 struct cifsFileInfo *cfile = file->private_data;
3435 struct file_zero_data_information fsctl_buf;
3438 __u8 set_sparse = 1;
3443 /* Need to make file sparse, if not already, before freeing range. */
3444 /* Consider adding equivalent for compressed since it could also work */
3445 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
3451 * We implement the punch hole through ioctl, so we need remove the page
3452 * caches first, otherwise the data may be inconsistent with the server.
3454 truncate_pagecache_range(inode, offset, offset + len - 1);
3456 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3458 fsctl_buf.FileOffset = cpu_to_le64(offset);
3459 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3461 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3462 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3464 sizeof(struct file_zero_data_information),
3465 CIFSMaxBufSize, NULL, NULL);
3467 inode_unlock(inode);
3472 static int smb3_simple_fallocate_write_range(unsigned int xid,
3473 struct cifs_tcon *tcon,
3474 struct cifsFileInfo *cfile,
3475 loff_t off, loff_t len,
3478 struct cifs_io_parms io_parms = {0};
3483 io_parms.netfid = cfile->fid.netfid;
3484 io_parms.pid = current->tgid;
3485 io_parms.tcon = tcon;
3486 io_parms.persistent_fid = cfile->fid.persistent_fid;
3487 io_parms.volatile_fid = cfile->fid.volatile_fid;
3490 io_parms.offset = off;
3491 io_parms.length = len;
3492 if (io_parms.length > SMB2_MAX_BUFFER_SIZE)
3493 io_parms.length = SMB2_MAX_BUFFER_SIZE;
3494 /* iov[0] is reserved for smb header */
3495 iov[1].iov_base = buf;
3496 iov[1].iov_len = io_parms.length;
3497 rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
3509 static int smb3_simple_fallocate_range(unsigned int xid,
3510 struct cifs_tcon *tcon,
3511 struct cifsFileInfo *cfile,
3512 loff_t off, loff_t len)
3514 struct file_allocated_range_buffer in_data, *out_data = NULL, *tmp_data;
3520 in_data.file_offset = cpu_to_le64(off);
3521 in_data.length = cpu_to_le64(len);
3522 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3523 cfile->fid.volatile_fid,
3524 FSCTL_QUERY_ALLOCATED_RANGES,
3525 (char *)&in_data, sizeof(in_data),
3526 1024 * sizeof(struct file_allocated_range_buffer),
3527 (char **)&out_data, &out_data_len);
3531 buf = kzalloc(1024 * 1024, GFP_KERNEL);
3537 tmp_data = out_data;
3540 * The rest of the region is unmapped so write it all.
3542 if (out_data_len == 0) {
3543 rc = smb3_simple_fallocate_write_range(xid, tcon,
3544 cfile, off, len, buf);
3548 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3553 if (off < le64_to_cpu(tmp_data->file_offset)) {
3555 * We are at a hole. Write until the end of the region
3556 * or until the next allocated data,
3557 * whichever comes next.
3559 l = le64_to_cpu(tmp_data->file_offset) - off;
3562 rc = smb3_simple_fallocate_write_range(xid, tcon,
3563 cfile, off, l, buf);
3572 * We are at a section of allocated data, just skip forward
3573 * until the end of the data or the end of the region
3574 * we are supposed to fallocate, whichever comes first.
3576 l = le64_to_cpu(tmp_data->length);
3582 tmp_data = &tmp_data[1];
3583 out_data_len -= sizeof(struct file_allocated_range_buffer);
3593 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3594 loff_t off, loff_t len, bool keep_size)
3596 struct inode *inode;
3597 struct cifsInodeInfo *cifsi;
3598 struct cifsFileInfo *cfile = file->private_data;
3599 long rc = -EOPNOTSUPP;
3605 inode = d_inode(cfile->dentry);
3606 cifsi = CIFS_I(inode);
3608 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3609 tcon->ses->Suid, off, len);
3610 /* if file not oplocked can't be sure whether asking to extend size */
3611 if (!CIFS_CACHE_READ(cifsi))
3612 if (keep_size == false) {
3613 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3614 tcon->tid, tcon->ses->Suid, off, len, rc);
3620 * Extending the file
3622 if ((keep_size == false) && i_size_read(inode) < off + len) {
3623 rc = inode_newsize_ok(inode, off + len);
3627 if (cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)
3628 smb2_set_sparse(xid, tcon, cfile, inode, false);
3630 eof = cpu_to_le64(off + len);
3631 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3632 cfile->fid.volatile_fid, cfile->pid, &eof);
3634 cifsi->server_eof = off + len;
3635 cifs_setsize(inode, off + len);
3636 cifs_truncate_page(inode->i_mapping, inode->i_size);
3637 truncate_setsize(inode, off + len);
3643 * Files are non-sparse by default so falloc may be a no-op
3644 * Must check if file sparse. If not sparse, and since we are not
3645 * extending then no need to do anything since file already allocated
3647 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
3652 if (keep_size == true) {
3654 * We can not preallocate pages beyond the end of the file
3657 if (off >= i_size_read(inode)) {
3662 * For fallocates that are partially beyond the end of file,
3663 * clamp len so we only fallocate up to the end of file.
3665 if (off + len > i_size_read(inode)) {
3666 len = i_size_read(inode) - off;
3670 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3672 * At this point, we are trying to fallocate an internal
3673 * regions of a sparse file. Since smb2 does not have a
3674 * fallocate command we have two otions on how to emulate this.
3675 * We can either turn the entire file to become non-sparse
3676 * which we only do if the fallocate is for virtually
3677 * the whole file, or we can overwrite the region with zeroes
3678 * using SMB2_write, which could be prohibitevly expensive
3682 * We are only trying to fallocate a small region so
3683 * just write it with zero.
3685 if (len <= 1024 * 1024) {
3686 rc = smb3_simple_fallocate_range(xid, tcon, cfile,
3692 * Check if falloc starts within first few pages of file
3693 * and ends within a few pages of the end of file to
3694 * ensure that most of file is being forced to be
3695 * fallocated now. If so then setting whole file sparse
3696 * ie potentially making a few extra pages at the beginning
3697 * or end of the file non-sparse via set_sparse is harmless.
3699 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
3705 smb2_set_sparse(xid, tcon, cfile, inode, false);
3710 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3711 tcon->ses->Suid, off, len, rc);
3713 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3714 tcon->ses->Suid, off, len);
3720 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3722 struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3723 struct cifsInodeInfo *cifsi;
3724 struct inode *inode;
3726 struct file_allocated_range_buffer in_data, *out_data = NULL;
3730 if (whence != SEEK_HOLE && whence != SEEK_DATA)
3731 return generic_file_llseek(file, offset, whence);
3733 inode = d_inode(cfile->dentry);
3734 cifsi = CIFS_I(inode);
3736 if (offset < 0 || offset >= i_size_read(inode))
3741 * We need to be sure that all dirty pages are written as they
3742 * might fill holes on the server.
3743 * Note that we also MUST flush any written pages since at least
3744 * some servers (Windows2016) will not reflect recent writes in
3745 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3747 wrcfile = find_writable_file(cifsi, FIND_WR_ANY);
3749 filemap_write_and_wait(inode->i_mapping);
3750 smb2_flush_file(xid, tcon, &wrcfile->fid);
3751 cifsFileInfo_put(wrcfile);
3754 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3755 if (whence == SEEK_HOLE)
3756 offset = i_size_read(inode);
3760 in_data.file_offset = cpu_to_le64(offset);
3761 in_data.length = cpu_to_le64(i_size_read(inode));
3763 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3764 cfile->fid.volatile_fid,
3765 FSCTL_QUERY_ALLOCATED_RANGES,
3766 (char *)&in_data, sizeof(in_data),
3767 sizeof(struct file_allocated_range_buffer),
3768 (char **)&out_data, &out_data_len);
3774 if (whence == SEEK_HOLE && out_data_len == 0)
3777 if (whence == SEEK_DATA && out_data_len == 0) {
3782 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3786 if (whence == SEEK_DATA) {
3787 offset = le64_to_cpu(out_data->file_offset);
3790 if (offset < le64_to_cpu(out_data->file_offset))
3793 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3799 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3804 static int smb3_fiemap(struct cifs_tcon *tcon,
3805 struct cifsFileInfo *cfile,
3806 struct fiemap_extent_info *fei, u64 start, u64 len)
3809 struct file_allocated_range_buffer in_data, *out_data;
3811 int i, num, rc, flags, last_blob;
3814 rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0);
3820 in_data.file_offset = cpu_to_le64(start);
3821 in_data.length = cpu_to_le64(len);
3823 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3824 cfile->fid.volatile_fid,
3825 FSCTL_QUERY_ALLOCATED_RANGES,
3826 (char *)&in_data, sizeof(in_data),
3827 1024 * sizeof(struct file_allocated_range_buffer),
3828 (char **)&out_data, &out_data_len);
3837 if (out_data_len && out_data_len < sizeof(struct file_allocated_range_buffer)) {
3841 if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3846 num = out_data_len / sizeof(struct file_allocated_range_buffer);
3847 for (i = 0; i < num; i++) {
3849 if (i == num - 1 && last_blob)
3850 flags |= FIEMAP_EXTENT_LAST;
3852 rc = fiemap_fill_next_extent(fei,
3853 le64_to_cpu(out_data[i].file_offset),
3854 le64_to_cpu(out_data[i].file_offset),
3855 le64_to_cpu(out_data[i].length),
3866 next = le64_to_cpu(out_data[num - 1].file_offset) +
3867 le64_to_cpu(out_data[num - 1].length);
3868 len = len - (next - start);
3879 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
3880 loff_t off, loff_t len)
3882 /* KEEP_SIZE already checked for by do_fallocate */
3883 if (mode & FALLOC_FL_PUNCH_HOLE)
3884 return smb3_punch_hole(file, tcon, off, len);
3885 else if (mode & FALLOC_FL_ZERO_RANGE) {
3886 if (mode & FALLOC_FL_KEEP_SIZE)
3887 return smb3_zero_range(file, tcon, off, len, true);
3888 return smb3_zero_range(file, tcon, off, len, false);
3889 } else if (mode == FALLOC_FL_KEEP_SIZE)
3890 return smb3_simple_falloc(file, tcon, off, len, true);
3892 return smb3_simple_falloc(file, tcon, off, len, false);
3898 smb2_downgrade_oplock(struct TCP_Server_Info *server,
3899 struct cifsInodeInfo *cinode, __u32 oplock,
3900 unsigned int epoch, bool *purge_cache)
3902 server->ops->set_oplock_level(cinode, oplock, 0, NULL);
3906 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3907 unsigned int epoch, bool *purge_cache);
3910 smb3_downgrade_oplock(struct TCP_Server_Info *server,
3911 struct cifsInodeInfo *cinode, __u32 oplock,
3912 unsigned int epoch, bool *purge_cache)
3914 unsigned int old_state = cinode->oplock;
3915 unsigned int old_epoch = cinode->epoch;
3916 unsigned int new_state;
3918 if (epoch > old_epoch) {
3919 smb21_set_oplock_level(cinode, oplock, 0, NULL);
3920 cinode->epoch = epoch;
3923 new_state = cinode->oplock;
3924 *purge_cache = false;
3926 if ((old_state & CIFS_CACHE_READ_FLG) != 0 &&
3927 (new_state & CIFS_CACHE_READ_FLG) == 0)
3928 *purge_cache = true;
3929 else if (old_state == new_state && (epoch - old_epoch > 1))
3930 *purge_cache = true;
3934 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3935 unsigned int epoch, bool *purge_cache)
3938 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3940 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
3941 cinode->oplock = CIFS_CACHE_RHW_FLG;
3942 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
3943 &cinode->vfs_inode);
3944 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
3945 cinode->oplock = CIFS_CACHE_RW_FLG;
3946 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
3947 &cinode->vfs_inode);
3948 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
3949 cinode->oplock = CIFS_CACHE_READ_FLG;
3950 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
3951 &cinode->vfs_inode);
3957 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3958 unsigned int epoch, bool *purge_cache)
3960 char message[5] = {0};
3961 unsigned int new_oplock = 0;
3964 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3967 /* Check if the server granted an oplock rather than a lease */
3968 if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE)
3969 return smb2_set_oplock_level(cinode, oplock, epoch,
3972 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
3973 new_oplock |= CIFS_CACHE_READ_FLG;
3974 strcat(message, "R");
3976 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
3977 new_oplock |= CIFS_CACHE_HANDLE_FLG;
3978 strcat(message, "H");
3980 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
3981 new_oplock |= CIFS_CACHE_WRITE_FLG;
3982 strcat(message, "W");
3985 strncpy(message, "None", sizeof(message));
3987 cinode->oplock = new_oplock;
3988 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
3989 &cinode->vfs_inode);
3993 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3994 unsigned int epoch, bool *purge_cache)
3996 unsigned int old_oplock = cinode->oplock;
3998 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
4001 *purge_cache = false;
4002 if (old_oplock == CIFS_CACHE_READ_FLG) {
4003 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
4004 (epoch - cinode->epoch > 0))
4005 *purge_cache = true;
4006 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4007 (epoch - cinode->epoch > 1))
4008 *purge_cache = true;
4009 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4010 (epoch - cinode->epoch > 1))
4011 *purge_cache = true;
4012 else if (cinode->oplock == 0 &&
4013 (epoch - cinode->epoch > 0))
4014 *purge_cache = true;
4015 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
4016 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4017 (epoch - cinode->epoch > 0))
4018 *purge_cache = true;
4019 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4020 (epoch - cinode->epoch > 1))
4021 *purge_cache = true;
4023 cinode->epoch = epoch;
4027 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
4029 smb2_is_read_op(__u32 oplock)
4031 return oplock == SMB2_OPLOCK_LEVEL_II;
4033 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
4036 smb21_is_read_op(__u32 oplock)
4038 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
4039 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
4043 map_oplock_to_lease(u8 oplock)
4045 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4046 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
4047 else if (oplock == SMB2_OPLOCK_LEVEL_II)
4048 return SMB2_LEASE_READ_CACHING;
4049 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
4050 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
4051 SMB2_LEASE_WRITE_CACHING;
4056 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
4058 struct create_lease *buf;
4060 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
4064 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4065 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4067 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4068 (struct create_lease, lcontext));
4069 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
4070 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4071 (struct create_lease, Name));
4072 buf->ccontext.NameLength = cpu_to_le16(4);
4073 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4082 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
4084 struct create_lease_v2 *buf;
4086 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
4090 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4091 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4093 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4094 (struct create_lease_v2, lcontext));
4095 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
4096 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4097 (struct create_lease_v2, Name));
4098 buf->ccontext.NameLength = cpu_to_le16(4);
4099 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4108 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4110 struct create_lease *lc = (struct create_lease *)buf;
4112 *epoch = 0; /* not used */
4113 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
4114 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4115 return le32_to_cpu(lc->lcontext.LeaseState);
4119 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4121 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
4123 *epoch = le16_to_cpu(lc->lcontext.Epoch);
4124 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
4125 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4127 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
4128 return le32_to_cpu(lc->lcontext.LeaseState);
4132 smb2_wp_retry_size(struct inode *inode)
4134 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
4135 SMB2_MAX_BUFFER_SIZE);
4139 smb2_dir_needs_close(struct cifsFileInfo *cfile)
4141 return !cfile->invalidHandle;
4145 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
4146 struct smb_rqst *old_rq, __le16 cipher_type)
4148 struct smb2_sync_hdr *shdr =
4149 (struct smb2_sync_hdr *)old_rq->rq_iov[0].iov_base;
4151 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
4152 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
4153 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
4154 tr_hdr->Flags = cpu_to_le16(0x01);
4155 if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4156 (cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4157 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4159 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4160 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
4163 /* We can not use the normal sg_set_buf() as we will sometimes pass a
4164 * stack object as buf.
4166 static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
4167 unsigned int buflen)
4171 * VMAP_STACK (at least) puts stack into the vmalloc address space
4173 if (is_vmalloc_addr(buf))
4174 addr = vmalloc_to_page(buf);
4176 addr = virt_to_page(buf);
4177 sg_set_page(sg, addr, buflen, offset_in_page(buf));
4180 /* Assumes the first rqst has a transform header as the first iov.
4182 * rqst[0].rq_iov[0] is transform header
4183 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
4184 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
4186 static struct scatterlist *
4187 init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign)
4189 unsigned int sg_len;
4190 struct scatterlist *sg;
4193 unsigned int idx = 0;
4197 for (i = 0; i < num_rqst; i++)
4198 sg_len += rqst[i].rq_nvec + rqst[i].rq_npages;
4200 sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
4204 sg_init_table(sg, sg_len);
4205 for (i = 0; i < num_rqst; i++) {
4206 for (j = 0; j < rqst[i].rq_nvec; j++) {
4208 * The first rqst has a transform header where the
4209 * first 20 bytes are not part of the encrypted blob
4211 skip = (i == 0) && (j == 0) ? 20 : 0;
4212 smb2_sg_set_buf(&sg[idx++],
4213 rqst[i].rq_iov[j].iov_base + skip,
4214 rqst[i].rq_iov[j].iov_len - skip);
4217 for (j = 0; j < rqst[i].rq_npages; j++) {
4218 unsigned int len, offset;
4220 rqst_page_get_length(&rqst[i], j, &len, &offset);
4221 sg_set_page(&sg[idx++], rqst[i].rq_pages[j], len, offset);
4224 smb2_sg_set_buf(&sg[idx], sign, SMB2_SIGNATURE_SIZE);
4229 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
4231 struct cifs_ses *ses;
4234 spin_lock(&cifs_tcp_ses_lock);
4235 list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
4236 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
4237 if (ses->Suid == ses_id) {
4238 ses_enc_key = enc ? ses->smb3encryptionkey :
4239 ses->smb3decryptionkey;
4240 memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE);
4241 spin_unlock(&cifs_tcp_ses_lock);
4246 spin_unlock(&cifs_tcp_ses_lock);
4251 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
4252 * iov[0] - transform header (associate data),
4253 * iov[1-N] - SMB2 header and pages - data to encrypt.
4254 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4258 crypt_message(struct TCP_Server_Info *server, int num_rqst,
4259 struct smb_rqst *rqst, int enc)
4261 struct smb2_transform_hdr *tr_hdr =
4262 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
4263 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
4265 struct scatterlist *sg;
4266 u8 sign[SMB2_SIGNATURE_SIZE] = {};
4267 u8 key[SMB3_ENC_DEC_KEY_SIZE];
4268 struct aead_request *req;
4270 unsigned int iv_len;
4271 DECLARE_CRYPTO_WAIT(wait);
4272 struct crypto_aead *tfm;
4273 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4275 rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key);
4277 cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
4282 rc = smb3_crypto_aead_allocate(server);
4284 cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
4288 tfm = enc ? server->secmech.ccmaesencrypt :
4289 server->secmech.ccmaesdecrypt;
4291 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
4292 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4293 rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
4295 rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE);
4298 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
4302 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
4304 cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
4308 req = aead_request_alloc(tfm, GFP_KERNEL);
4310 cifs_server_dbg(VFS, "%s: Failed to alloc aead request\n", __func__);
4315 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
4316 crypt_len += SMB2_SIGNATURE_SIZE;
4319 sg = init_sg(num_rqst, rqst, sign);
4321 cifs_server_dbg(VFS, "%s: Failed to init sg\n", __func__);
4326 iv_len = crypto_aead_ivsize(tfm);
4327 iv = kzalloc(iv_len, GFP_KERNEL);
4329 cifs_server_dbg(VFS, "%s: Failed to alloc iv\n", __func__);
4334 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4335 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4336 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4339 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4342 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
4343 aead_request_set_ad(req, assoc_data_len);
4345 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
4346 crypto_req_done, &wait);
4348 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
4349 : crypto_aead_decrypt(req), &wait);
4352 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
4363 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
4367 for (i = 0; i < num_rqst; i++) {
4368 if (rqst[i].rq_pages) {
4369 for (j = rqst[i].rq_npages - 1; j >= 0; j--)
4370 put_page(rqst[i].rq_pages[j]);
4371 kfree(rqst[i].rq_pages);
4377 * This function will initialize new_rq and encrypt the content.
4378 * The first entry, new_rq[0], only contains a single iov which contains
4379 * a smb2_transform_hdr and is pre-allocated by the caller.
4380 * This function then populates new_rq[1+] with the content from olq_rq[0+].
4382 * The end result is an array of smb_rqst structures where the first structure
4383 * only contains a single iov for the transform header which we then can pass
4384 * to crypt_message().
4386 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4387 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
4390 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
4391 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
4393 struct page **pages;
4394 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
4395 unsigned int npages;
4396 unsigned int orig_len = 0;
4400 for (i = 1; i < num_rqst; i++) {
4401 npages = old_rq[i - 1].rq_npages;
4402 pages = kmalloc_array(npages, sizeof(struct page *),
4407 new_rq[i].rq_pages = pages;
4408 new_rq[i].rq_npages = npages;
4409 new_rq[i].rq_offset = old_rq[i - 1].rq_offset;
4410 new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz;
4411 new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz;
4412 new_rq[i].rq_iov = old_rq[i - 1].rq_iov;
4413 new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec;
4415 orig_len += smb_rqst_len(server, &old_rq[i - 1]);
4417 for (j = 0; j < npages; j++) {
4418 pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4423 /* copy pages form the old */
4424 for (j = 0; j < npages; j++) {
4426 unsigned int offset, len;
4428 rqst_page_get_length(&new_rq[i], j, &len, &offset);
4430 dst = (char *) kmap(new_rq[i].rq_pages[j]) + offset;
4431 src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset;
4433 memcpy(dst, src, len);
4434 kunmap(new_rq[i].rq_pages[j]);
4435 kunmap(old_rq[i - 1].rq_pages[j]);
4439 /* fill the 1st iov with a transform header */
4440 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
4442 rc = crypt_message(server, num_rqst, new_rq, 1);
4443 cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
4450 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
4455 smb3_is_transform_hdr(void *buf)
4457 struct smb2_transform_hdr *trhdr = buf;
4459 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
4463 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
4464 unsigned int buf_data_size, struct page **pages,
4465 unsigned int npages, unsigned int page_data_size,
4469 struct smb_rqst rqst = {NULL};
4472 iov[0].iov_base = buf;
4473 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
4474 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
4475 iov[1].iov_len = buf_data_size;
4479 rqst.rq_pages = pages;
4480 rqst.rq_npages = npages;
4481 rqst.rq_pagesz = PAGE_SIZE;
4482 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
4484 rc = crypt_message(server, 1, &rqst, 0);
4485 cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
4490 memmove(buf, iov[1].iov_base, buf_data_size);
4493 server->total_read = buf_data_size + page_data_size;
4499 read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
4500 unsigned int npages, unsigned int len)
4505 for (i = 0; i < npages; i++) {
4506 struct page *page = pages[i];
4510 if (len >= PAGE_SIZE) {
4511 /* enough data to fill the page */
4515 zero_user(page, len, PAGE_SIZE - len);
4518 length = cifs_read_page_from_socket(server, page, 0, n);
4521 server->total_read += length;
4528 init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
4529 unsigned int cur_off, struct bio_vec **page_vec)
4531 struct bio_vec *bvec;
4534 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
4538 for (i = 0; i < npages; i++) {
4539 bvec[i].bv_page = pages[i];
4540 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
4541 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
4542 data_size -= bvec[i].bv_len;
4545 if (data_size != 0) {
4546 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
4556 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
4557 char *buf, unsigned int buf_len, struct page **pages,
4558 unsigned int npages, unsigned int page_data_size,
4561 unsigned int data_offset;
4562 unsigned int data_len;
4563 unsigned int cur_off;
4564 unsigned int cur_page_idx;
4565 unsigned int pad_len;
4566 struct cifs_readdata *rdata = mid->callback_data;
4567 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
4568 struct bio_vec *bvec = NULL;
4569 struct iov_iter iter;
4572 bool use_rdma_mr = false;
4574 if (shdr->Command != SMB2_READ) {
4575 cifs_server_dbg(VFS, "only big read responses are supported\n");
4579 if (server->ops->is_session_expired &&
4580 server->ops->is_session_expired(buf)) {
4582 cifs_reconnect(server);
4586 if (server->ops->is_status_pending &&
4587 server->ops->is_status_pending(buf, server))
4590 /* set up first two iov to get credits */
4591 rdata->iov[0].iov_base = buf;
4592 rdata->iov[0].iov_len = 0;
4593 rdata->iov[1].iov_base = buf;
4594 rdata->iov[1].iov_len =
4595 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
4596 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
4597 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
4598 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
4599 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
4601 rdata->result = server->ops->map_error(buf, true);
4602 if (rdata->result != 0) {
4603 cifs_dbg(FYI, "%s: server returned error %d\n",
4604 __func__, rdata->result);
4605 /* normal error on read response */
4607 mid->mid_state = MID_RESPONSE_RECEIVED;
4609 dequeue_mid(mid, false);
4613 data_offset = server->ops->read_data_offset(buf);
4614 #ifdef CONFIG_CIFS_SMB_DIRECT
4615 use_rdma_mr = rdata->mr;
4617 data_len = server->ops->read_data_length(buf, use_rdma_mr);
4619 if (data_offset < server->vals->read_rsp_size) {
4621 * win2k8 sometimes sends an offset of 0 when the read
4622 * is beyond the EOF. Treat it as if the data starts just after
4625 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
4626 __func__, data_offset);
4627 data_offset = server->vals->read_rsp_size;
4628 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
4629 /* data_offset is beyond the end of smallbuf */
4630 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
4631 __func__, data_offset);
4632 rdata->result = -EIO;
4634 mid->mid_state = MID_RESPONSE_MALFORMED;
4636 dequeue_mid(mid, rdata->result);
4640 pad_len = data_offset - server->vals->read_rsp_size;
4642 if (buf_len <= data_offset) {
4643 /* read response payload is in pages */
4644 cur_page_idx = pad_len / PAGE_SIZE;
4645 cur_off = pad_len % PAGE_SIZE;
4647 if (cur_page_idx != 0) {
4648 /* data offset is beyond the 1st page of response */
4649 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
4650 __func__, data_offset);
4651 rdata->result = -EIO;
4653 mid->mid_state = MID_RESPONSE_MALFORMED;
4655 dequeue_mid(mid, rdata->result);
4659 if (data_len > page_data_size - pad_len) {
4660 /* data_len is corrupt -- discard frame */
4661 rdata->result = -EIO;
4663 mid->mid_state = MID_RESPONSE_MALFORMED;
4665 dequeue_mid(mid, rdata->result);
4669 rdata->result = init_read_bvec(pages, npages, page_data_size,
4671 if (rdata->result != 0) {
4673 mid->mid_state = MID_RESPONSE_MALFORMED;
4675 dequeue_mid(mid, rdata->result);
4679 iov_iter_bvec(&iter, WRITE, bvec, npages, data_len);
4680 } else if (buf_len >= data_offset + data_len) {
4681 /* read response payload is in buf */
4682 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
4683 iov.iov_base = buf + data_offset;
4684 iov.iov_len = data_len;
4685 iov_iter_kvec(&iter, WRITE, &iov, 1, data_len);
4687 /* read response payload cannot be in both buf and pages */
4688 WARN_ONCE(1, "buf can not contain only a part of read data");
4689 rdata->result = -EIO;
4691 mid->mid_state = MID_RESPONSE_MALFORMED;
4693 dequeue_mid(mid, rdata->result);
4697 length = rdata->copy_into_pages(server, rdata, &iter);
4705 mid->mid_state = MID_RESPONSE_RECEIVED;
4707 dequeue_mid(mid, false);
4711 struct smb2_decrypt_work {
4712 struct work_struct decrypt;
4713 struct TCP_Server_Info *server;
4714 struct page **ppages;
4716 unsigned int npages;
4721 static void smb2_decrypt_offload(struct work_struct *work)
4723 struct smb2_decrypt_work *dw = container_of(work,
4724 struct smb2_decrypt_work, decrypt);
4726 struct mid_q_entry *mid;
4728 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
4729 dw->ppages, dw->npages, dw->len, true);
4731 cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
4735 dw->server->lstrp = jiffies;
4736 mid = smb2_find_dequeue_mid(dw->server, dw->buf);
4738 cifs_dbg(FYI, "mid not found\n");
4740 mid->decrypted = true;
4741 rc = handle_read_data(dw->server, mid, dw->buf,
4742 dw->server->vals->read_rsp_size,
4743 dw->ppages, dw->npages, dw->len,
4746 #ifdef CONFIG_CIFS_STATS2
4747 mid->when_received = jiffies;
4751 spin_lock(&GlobalMid_Lock);
4752 if (dw->server->tcpStatus == CifsNeedReconnect) {
4753 mid->mid_state = MID_RETRY_NEEDED;
4754 spin_unlock(&GlobalMid_Lock);
4757 mid->mid_state = MID_REQUEST_SUBMITTED;
4758 mid->mid_flags &= ~(MID_DELETED);
4759 list_add_tail(&mid->qhead,
4760 &dw->server->pending_mid_q);
4761 spin_unlock(&GlobalMid_Lock);
4764 cifs_mid_q_entry_release(mid);
4768 for (i = dw->npages-1; i >= 0; i--)
4769 put_page(dw->ppages[i]);
4772 cifs_small_buf_release(dw->buf);
4778 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
4781 char *buf = server->smallbuf;
4782 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4783 unsigned int npages;
4784 struct page **pages;
4786 unsigned int buflen = server->pdu_size;
4789 struct smb2_decrypt_work *dw;
4792 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
4793 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
4795 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
4798 server->total_read += rc;
4800 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
4801 server->vals->read_rsp_size;
4802 npages = DIV_ROUND_UP(len, PAGE_SIZE);
4804 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
4810 for (; i < npages; i++) {
4811 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4818 /* read read data into pages */
4819 rc = read_data_into_pages(server, pages, npages, len);
4823 rc = cifs_discard_remaining_data(server);
4828 * For large reads, offload to different thread for better performance,
4829 * use more cores decrypting which can be expensive
4832 if ((server->min_offload) && (server->in_flight > 1) &&
4833 (server->pdu_size >= server->min_offload)) {
4834 dw = kmalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL);
4836 goto non_offloaded_decrypt;
4838 dw->buf = server->smallbuf;
4839 server->smallbuf = (char *)cifs_small_buf_get();
4841 INIT_WORK(&dw->decrypt, smb2_decrypt_offload);
4843 dw->npages = npages;
4844 dw->server = server;
4847 queue_work(decrypt_wq, &dw->decrypt);
4848 *num_mids = 0; /* worker thread takes care of finding mid */
4852 non_offloaded_decrypt:
4853 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
4854 pages, npages, len, false);
4858 *mid = smb2_find_mid(server, buf);
4860 cifs_dbg(FYI, "mid not found\n");
4862 cifs_dbg(FYI, "mid found\n");
4863 (*mid)->decrypted = true;
4864 rc = handle_read_data(server, *mid, buf,
4865 server->vals->read_rsp_size,
4866 pages, npages, len, false);
4870 for (i = i - 1; i >= 0; i--)
4875 cifs_discard_remaining_data(server);
4880 receive_encrypted_standard(struct TCP_Server_Info *server,
4881 struct mid_q_entry **mids, char **bufs,
4885 char *buf = server->smallbuf;
4886 struct smb2_sync_hdr *shdr;
4887 unsigned int pdu_length = server->pdu_size;
4888 unsigned int buf_size;
4889 struct mid_q_entry *mid_entry;
4891 char *next_buffer = NULL;
4895 /* switch to large buffer if too big for a small one */
4896 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
4897 server->large_buf = true;
4898 memcpy(server->bigbuf, buf, server->total_read);
4899 buf = server->bigbuf;
4902 /* now read the rest */
4903 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
4904 pdu_length - HEADER_SIZE(server) + 1);
4907 server->total_read += length;
4909 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
4910 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0, false);
4914 next_is_large = server->large_buf;
4916 shdr = (struct smb2_sync_hdr *)buf;
4917 if (shdr->NextCommand) {
4919 next_buffer = (char *)cifs_buf_get();
4921 next_buffer = (char *)cifs_small_buf_get();
4923 buf + le32_to_cpu(shdr->NextCommand),
4924 pdu_length - le32_to_cpu(shdr->NextCommand));
4927 mid_entry = smb2_find_mid(server, buf);
4928 if (mid_entry == NULL)
4929 cifs_dbg(FYI, "mid not found\n");
4931 cifs_dbg(FYI, "mid found\n");
4932 mid_entry->decrypted = true;
4933 mid_entry->resp_buf_size = server->pdu_size;
4936 if (*num_mids >= MAX_COMPOUND) {
4937 cifs_server_dbg(VFS, "too many PDUs in compound\n");
4940 bufs[*num_mids] = buf;
4941 mids[(*num_mids)++] = mid_entry;
4943 if (mid_entry && mid_entry->handle)
4944 ret = mid_entry->handle(server, mid_entry);
4946 ret = cifs_handle_standard(server, mid_entry);
4948 if (ret == 0 && shdr->NextCommand) {
4949 pdu_length -= le32_to_cpu(shdr->NextCommand);
4950 server->large_buf = next_is_large;
4952 server->bigbuf = buf = next_buffer;
4954 server->smallbuf = buf = next_buffer;
4956 } else if (ret != 0) {
4958 * ret != 0 here means that we didn't get to handle_mid() thus
4959 * server->smallbuf and server->bigbuf are still valid. We need
4960 * to free next_buffer because it is not going to be used
4964 free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer);
4966 free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer);
4973 smb3_receive_transform(struct TCP_Server_Info *server,
4974 struct mid_q_entry **mids, char **bufs, int *num_mids)
4976 char *buf = server->smallbuf;
4977 unsigned int pdu_length = server->pdu_size;
4978 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4979 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4981 if (pdu_length < sizeof(struct smb2_transform_hdr) +
4982 sizeof(struct smb2_sync_hdr)) {
4983 cifs_server_dbg(VFS, "Transform message is too small (%u)\n",
4985 cifs_reconnect(server);
4986 return -ECONNABORTED;
4989 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
4990 cifs_server_dbg(VFS, "Transform message is broken\n");
4991 cifs_reconnect(server);
4992 return -ECONNABORTED;
4995 /* TODO: add support for compounds containing READ. */
4996 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
4997 return receive_encrypted_read(server, &mids[0], num_mids);
5000 return receive_encrypted_standard(server, mids, bufs, num_mids);
5004 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
5006 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
5008 return handle_read_data(server, mid, buf, server->pdu_size,
5013 smb2_next_header(char *buf)
5015 struct smb2_sync_hdr *hdr = (struct smb2_sync_hdr *)buf;
5016 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
5018 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
5019 return sizeof(struct smb2_transform_hdr) +
5020 le32_to_cpu(t_hdr->OriginalMessageSize);
5022 return le32_to_cpu(hdr->NextCommand);
5026 smb2_make_node(unsigned int xid, struct inode *inode,
5027 struct dentry *dentry, struct cifs_tcon *tcon,
5028 char *full_path, umode_t mode, dev_t dev)
5030 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
5032 FILE_ALL_INFO *buf = NULL;
5033 struct cifs_io_parms io_parms = {0};
5035 struct cifs_fid fid;
5036 struct cifs_open_parms oparms;
5037 unsigned int bytes_written;
5038 struct win_dev *pdev;
5042 * Check if mounted with mount parm 'sfu' mount parm.
5043 * SFU emulation should work with all servers, but only
5044 * supports block and char device (no socket & fifo),
5045 * and was used by default in earlier versions of Windows
5047 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
5051 * TODO: Add ability to create instead via reparse point. Windows (e.g.
5052 * their current NFS server) uses this approach to expose special files
5053 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
5056 if (!S_ISCHR(mode) && !S_ISBLK(mode))
5059 cifs_dbg(FYI, "sfu compat create special file\n");
5061 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
5068 oparms.cifs_sb = cifs_sb;
5069 oparms.desired_access = GENERIC_WRITE;
5070 oparms.create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR |
5071 CREATE_OPTION_SPECIAL);
5072 oparms.disposition = FILE_CREATE;
5073 oparms.path = full_path;
5075 oparms.reconnect = false;
5077 if (tcon->ses->server->oplocks)
5078 oplock = REQ_OPLOCK;
5081 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf);
5086 * BB Do not bother to decode buf since no local inode yet to put
5087 * timestamps in, but we can reuse it safely.
5090 pdev = (struct win_dev *)buf;
5091 io_parms.pid = current->tgid;
5092 io_parms.tcon = tcon;
5093 io_parms.offset = 0;
5094 io_parms.length = sizeof(struct win_dev);
5095 iov[1].iov_base = buf;
5096 iov[1].iov_len = sizeof(struct win_dev);
5097 if (S_ISCHR(mode)) {
5098 memcpy(pdev->type, "IntxCHR", 8);
5099 pdev->major = cpu_to_le64(MAJOR(dev));
5100 pdev->minor = cpu_to_le64(MINOR(dev));
5101 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5102 &bytes_written, iov, 1);
5103 } else if (S_ISBLK(mode)) {
5104 memcpy(pdev->type, "IntxBLK", 8);
5105 pdev->major = cpu_to_le64(MAJOR(dev));
5106 pdev->minor = cpu_to_le64(MINOR(dev));
5107 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5108 &bytes_written, iov, 1);
5110 tcon->ses->server->ops->close(xid, tcon, &fid);
5113 /* FIXME: add code here to set EAs */
5119 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5120 struct smb_version_operations smb20_operations = {
5121 .compare_fids = smb2_compare_fids,
5122 .setup_request = smb2_setup_request,
5123 .setup_async_request = smb2_setup_async_request,
5124 .check_receive = smb2_check_receive,
5125 .add_credits = smb2_add_credits,
5126 .set_credits = smb2_set_credits,
5127 .get_credits_field = smb2_get_credits_field,
5128 .get_credits = smb2_get_credits,
5129 .wait_mtu_credits = cifs_wait_mtu_credits,
5130 .get_next_mid = smb2_get_next_mid,
5131 .revert_current_mid = smb2_revert_current_mid,
5132 .read_data_offset = smb2_read_data_offset,
5133 .read_data_length = smb2_read_data_length,
5134 .map_error = map_smb2_to_linux_error,
5135 .find_mid = smb2_find_mid,
5136 .check_message = smb2_check_message,
5137 .dump_detail = smb2_dump_detail,
5138 .clear_stats = smb2_clear_stats,
5139 .print_stats = smb2_print_stats,
5140 .is_oplock_break = smb2_is_valid_oplock_break,
5141 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5142 .downgrade_oplock = smb2_downgrade_oplock,
5143 .need_neg = smb2_need_neg,
5144 .negotiate = smb2_negotiate,
5145 .negotiate_wsize = smb2_negotiate_wsize,
5146 .negotiate_rsize = smb2_negotiate_rsize,
5147 .sess_setup = SMB2_sess_setup,
5148 .logoff = SMB2_logoff,
5149 .tree_connect = SMB2_tcon,
5150 .tree_disconnect = SMB2_tdis,
5151 .qfs_tcon = smb2_qfs_tcon,
5152 .is_path_accessible = smb2_is_path_accessible,
5153 .can_echo = smb2_can_echo,
5155 .query_path_info = smb2_query_path_info,
5156 .get_srv_inum = smb2_get_srv_inum,
5157 .query_file_info = smb2_query_file_info,
5158 .set_path_size = smb2_set_path_size,
5159 .set_file_size = smb2_set_file_size,
5160 .set_file_info = smb2_set_file_info,
5161 .set_compression = smb2_set_compression,
5162 .mkdir = smb2_mkdir,
5163 .mkdir_setinfo = smb2_mkdir_setinfo,
5164 .rmdir = smb2_rmdir,
5165 .unlink = smb2_unlink,
5166 .rename = smb2_rename_path,
5167 .create_hardlink = smb2_create_hardlink,
5168 .query_symlink = smb2_query_symlink,
5169 .query_mf_symlink = smb3_query_mf_symlink,
5170 .create_mf_symlink = smb3_create_mf_symlink,
5171 .open = smb2_open_file,
5172 .set_fid = smb2_set_fid,
5173 .close = smb2_close_file,
5174 .flush = smb2_flush_file,
5175 .async_readv = smb2_async_readv,
5176 .async_writev = smb2_async_writev,
5177 .sync_read = smb2_sync_read,
5178 .sync_write = smb2_sync_write,
5179 .query_dir_first = smb2_query_dir_first,
5180 .query_dir_next = smb2_query_dir_next,
5181 .close_dir = smb2_close_dir,
5182 .calc_smb_size = smb2_calc_size,
5183 .is_status_pending = smb2_is_status_pending,
5184 .is_session_expired = smb2_is_session_expired,
5185 .oplock_response = smb2_oplock_response,
5186 .queryfs = smb2_queryfs,
5187 .mand_lock = smb2_mand_lock,
5188 .mand_unlock_range = smb2_unlock_range,
5189 .push_mand_locks = smb2_push_mandatory_locks,
5190 .get_lease_key = smb2_get_lease_key,
5191 .set_lease_key = smb2_set_lease_key,
5192 .new_lease_key = smb2_new_lease_key,
5193 .calc_signature = smb2_calc_signature,
5194 .is_read_op = smb2_is_read_op,
5195 .set_oplock_level = smb2_set_oplock_level,
5196 .create_lease_buf = smb2_create_lease_buf,
5197 .parse_lease_buf = smb2_parse_lease_buf,
5198 .copychunk_range = smb2_copychunk_range,
5199 .wp_retry_size = smb2_wp_retry_size,
5200 .dir_needs_close = smb2_dir_needs_close,
5201 .get_dfs_refer = smb2_get_dfs_refer,
5202 .select_sectype = smb2_select_sectype,
5203 #ifdef CONFIG_CIFS_XATTR
5204 .query_all_EAs = smb2_query_eas,
5205 .set_EA = smb2_set_ea,
5206 #endif /* CIFS_XATTR */
5207 .get_acl = get_smb2_acl,
5208 .get_acl_by_fid = get_smb2_acl_by_fid,
5209 .set_acl = set_smb2_acl,
5210 .next_header = smb2_next_header,
5211 .ioctl_query_info = smb2_ioctl_query_info,
5212 .make_node = smb2_make_node,
5213 .fiemap = smb3_fiemap,
5214 .llseek = smb3_llseek,
5215 .is_status_io_timeout = smb2_is_status_io_timeout,
5217 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
5219 struct smb_version_operations smb21_operations = {
5220 .compare_fids = smb2_compare_fids,
5221 .setup_request = smb2_setup_request,
5222 .setup_async_request = smb2_setup_async_request,
5223 .check_receive = smb2_check_receive,
5224 .add_credits = smb2_add_credits,
5225 .set_credits = smb2_set_credits,
5226 .get_credits_field = smb2_get_credits_field,
5227 .get_credits = smb2_get_credits,
5228 .wait_mtu_credits = smb2_wait_mtu_credits,
5229 .adjust_credits = smb2_adjust_credits,
5230 .get_next_mid = smb2_get_next_mid,
5231 .revert_current_mid = smb2_revert_current_mid,
5232 .read_data_offset = smb2_read_data_offset,
5233 .read_data_length = smb2_read_data_length,
5234 .map_error = map_smb2_to_linux_error,
5235 .find_mid = smb2_find_mid,
5236 .check_message = smb2_check_message,
5237 .dump_detail = smb2_dump_detail,
5238 .clear_stats = smb2_clear_stats,
5239 .print_stats = smb2_print_stats,
5240 .is_oplock_break = smb2_is_valid_oplock_break,
5241 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5242 .downgrade_oplock = smb2_downgrade_oplock,
5243 .need_neg = smb2_need_neg,
5244 .negotiate = smb2_negotiate,
5245 .negotiate_wsize = smb2_negotiate_wsize,
5246 .negotiate_rsize = smb2_negotiate_rsize,
5247 .sess_setup = SMB2_sess_setup,
5248 .logoff = SMB2_logoff,
5249 .tree_connect = SMB2_tcon,
5250 .tree_disconnect = SMB2_tdis,
5251 .qfs_tcon = smb2_qfs_tcon,
5252 .is_path_accessible = smb2_is_path_accessible,
5253 .can_echo = smb2_can_echo,
5255 .query_path_info = smb2_query_path_info,
5256 .get_srv_inum = smb2_get_srv_inum,
5257 .query_file_info = smb2_query_file_info,
5258 .set_path_size = smb2_set_path_size,
5259 .set_file_size = smb2_set_file_size,
5260 .set_file_info = smb2_set_file_info,
5261 .set_compression = smb2_set_compression,
5262 .mkdir = smb2_mkdir,
5263 .mkdir_setinfo = smb2_mkdir_setinfo,
5264 .rmdir = smb2_rmdir,
5265 .unlink = smb2_unlink,
5266 .rename = smb2_rename_path,
5267 .create_hardlink = smb2_create_hardlink,
5268 .query_symlink = smb2_query_symlink,
5269 .query_mf_symlink = smb3_query_mf_symlink,
5270 .create_mf_symlink = smb3_create_mf_symlink,
5271 .open = smb2_open_file,
5272 .set_fid = smb2_set_fid,
5273 .close = smb2_close_file,
5274 .flush = smb2_flush_file,
5275 .async_readv = smb2_async_readv,
5276 .async_writev = smb2_async_writev,
5277 .sync_read = smb2_sync_read,
5278 .sync_write = smb2_sync_write,
5279 .query_dir_first = smb2_query_dir_first,
5280 .query_dir_next = smb2_query_dir_next,
5281 .close_dir = smb2_close_dir,
5282 .calc_smb_size = smb2_calc_size,
5283 .is_status_pending = smb2_is_status_pending,
5284 .is_session_expired = smb2_is_session_expired,
5285 .oplock_response = smb2_oplock_response,
5286 .queryfs = smb2_queryfs,
5287 .mand_lock = smb2_mand_lock,
5288 .mand_unlock_range = smb2_unlock_range,
5289 .push_mand_locks = smb2_push_mandatory_locks,
5290 .get_lease_key = smb2_get_lease_key,
5291 .set_lease_key = smb2_set_lease_key,
5292 .new_lease_key = smb2_new_lease_key,
5293 .calc_signature = smb2_calc_signature,
5294 .is_read_op = smb21_is_read_op,
5295 .set_oplock_level = smb21_set_oplock_level,
5296 .create_lease_buf = smb2_create_lease_buf,
5297 .parse_lease_buf = smb2_parse_lease_buf,
5298 .copychunk_range = smb2_copychunk_range,
5299 .wp_retry_size = smb2_wp_retry_size,
5300 .dir_needs_close = smb2_dir_needs_close,
5301 .enum_snapshots = smb3_enum_snapshots,
5302 .notify = smb3_notify,
5303 .get_dfs_refer = smb2_get_dfs_refer,
5304 .select_sectype = smb2_select_sectype,
5305 #ifdef CONFIG_CIFS_XATTR
5306 .query_all_EAs = smb2_query_eas,
5307 .set_EA = smb2_set_ea,
5308 #endif /* CIFS_XATTR */
5309 .get_acl = get_smb2_acl,
5310 .get_acl_by_fid = get_smb2_acl_by_fid,
5311 .set_acl = set_smb2_acl,
5312 .next_header = smb2_next_header,
5313 .ioctl_query_info = smb2_ioctl_query_info,
5314 .make_node = smb2_make_node,
5315 .fiemap = smb3_fiemap,
5316 .llseek = smb3_llseek,
5317 .is_status_io_timeout = smb2_is_status_io_timeout,
5320 struct smb_version_operations smb30_operations = {
5321 .compare_fids = smb2_compare_fids,
5322 .setup_request = smb2_setup_request,
5323 .setup_async_request = smb2_setup_async_request,
5324 .check_receive = smb2_check_receive,
5325 .add_credits = smb2_add_credits,
5326 .set_credits = smb2_set_credits,
5327 .get_credits_field = smb2_get_credits_field,
5328 .get_credits = smb2_get_credits,
5329 .wait_mtu_credits = smb2_wait_mtu_credits,
5330 .adjust_credits = smb2_adjust_credits,
5331 .get_next_mid = smb2_get_next_mid,
5332 .revert_current_mid = smb2_revert_current_mid,
5333 .read_data_offset = smb2_read_data_offset,
5334 .read_data_length = smb2_read_data_length,
5335 .map_error = map_smb2_to_linux_error,
5336 .find_mid = smb2_find_mid,
5337 .check_message = smb2_check_message,
5338 .dump_detail = smb2_dump_detail,
5339 .clear_stats = smb2_clear_stats,
5340 .print_stats = smb2_print_stats,
5341 .dump_share_caps = smb2_dump_share_caps,
5342 .is_oplock_break = smb2_is_valid_oplock_break,
5343 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5344 .downgrade_oplock = smb3_downgrade_oplock,
5345 .need_neg = smb2_need_neg,
5346 .negotiate = smb2_negotiate,
5347 .negotiate_wsize = smb3_negotiate_wsize,
5348 .negotiate_rsize = smb3_negotiate_rsize,
5349 .sess_setup = SMB2_sess_setup,
5350 .logoff = SMB2_logoff,
5351 .tree_connect = SMB2_tcon,
5352 .tree_disconnect = SMB2_tdis,
5353 .qfs_tcon = smb3_qfs_tcon,
5354 .is_path_accessible = smb2_is_path_accessible,
5355 .can_echo = smb2_can_echo,
5357 .query_path_info = smb2_query_path_info,
5358 /* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */
5359 .query_reparse_tag = smb2_query_reparse_tag,
5360 .get_srv_inum = smb2_get_srv_inum,
5361 .query_file_info = smb2_query_file_info,
5362 .set_path_size = smb2_set_path_size,
5363 .set_file_size = smb2_set_file_size,
5364 .set_file_info = smb2_set_file_info,
5365 .set_compression = smb2_set_compression,
5366 .mkdir = smb2_mkdir,
5367 .mkdir_setinfo = smb2_mkdir_setinfo,
5368 .rmdir = smb2_rmdir,
5369 .unlink = smb2_unlink,
5370 .rename = smb2_rename_path,
5371 .create_hardlink = smb2_create_hardlink,
5372 .query_symlink = smb2_query_symlink,
5373 .query_mf_symlink = smb3_query_mf_symlink,
5374 .create_mf_symlink = smb3_create_mf_symlink,
5375 .open = smb2_open_file,
5376 .set_fid = smb2_set_fid,
5377 .close = smb2_close_file,
5378 .close_getattr = smb2_close_getattr,
5379 .flush = smb2_flush_file,
5380 .async_readv = smb2_async_readv,
5381 .async_writev = smb2_async_writev,
5382 .sync_read = smb2_sync_read,
5383 .sync_write = smb2_sync_write,
5384 .query_dir_first = smb2_query_dir_first,
5385 .query_dir_next = smb2_query_dir_next,
5386 .close_dir = smb2_close_dir,
5387 .calc_smb_size = smb2_calc_size,
5388 .is_status_pending = smb2_is_status_pending,
5389 .is_session_expired = smb2_is_session_expired,
5390 .oplock_response = smb2_oplock_response,
5391 .queryfs = smb2_queryfs,
5392 .mand_lock = smb2_mand_lock,
5393 .mand_unlock_range = smb2_unlock_range,
5394 .push_mand_locks = smb2_push_mandatory_locks,
5395 .get_lease_key = smb2_get_lease_key,
5396 .set_lease_key = smb2_set_lease_key,
5397 .new_lease_key = smb2_new_lease_key,
5398 .generate_signingkey = generate_smb30signingkey,
5399 .calc_signature = smb3_calc_signature,
5400 .set_integrity = smb3_set_integrity,
5401 .is_read_op = smb21_is_read_op,
5402 .set_oplock_level = smb3_set_oplock_level,
5403 .create_lease_buf = smb3_create_lease_buf,
5404 .parse_lease_buf = smb3_parse_lease_buf,
5405 .copychunk_range = smb2_copychunk_range,
5406 .duplicate_extents = smb2_duplicate_extents,
5407 .validate_negotiate = smb3_validate_negotiate,
5408 .wp_retry_size = smb2_wp_retry_size,
5409 .dir_needs_close = smb2_dir_needs_close,
5410 .fallocate = smb3_fallocate,
5411 .enum_snapshots = smb3_enum_snapshots,
5412 .notify = smb3_notify,
5413 .init_transform_rq = smb3_init_transform_rq,
5414 .is_transform_hdr = smb3_is_transform_hdr,
5415 .receive_transform = smb3_receive_transform,
5416 .get_dfs_refer = smb2_get_dfs_refer,
5417 .select_sectype = smb2_select_sectype,
5418 #ifdef CONFIG_CIFS_XATTR
5419 .query_all_EAs = smb2_query_eas,
5420 .set_EA = smb2_set_ea,
5421 #endif /* CIFS_XATTR */
5422 .get_acl = get_smb2_acl,
5423 .get_acl_by_fid = get_smb2_acl_by_fid,
5424 .set_acl = set_smb2_acl,
5425 .next_header = smb2_next_header,
5426 .ioctl_query_info = smb2_ioctl_query_info,
5427 .make_node = smb2_make_node,
5428 .fiemap = smb3_fiemap,
5429 .llseek = smb3_llseek,
5430 .is_status_io_timeout = smb2_is_status_io_timeout,
5433 struct smb_version_operations smb311_operations = {
5434 .compare_fids = smb2_compare_fids,
5435 .setup_request = smb2_setup_request,
5436 .setup_async_request = smb2_setup_async_request,
5437 .check_receive = smb2_check_receive,
5438 .add_credits = smb2_add_credits,
5439 .set_credits = smb2_set_credits,
5440 .get_credits_field = smb2_get_credits_field,
5441 .get_credits = smb2_get_credits,
5442 .wait_mtu_credits = smb2_wait_mtu_credits,
5443 .adjust_credits = smb2_adjust_credits,
5444 .get_next_mid = smb2_get_next_mid,
5445 .revert_current_mid = smb2_revert_current_mid,
5446 .read_data_offset = smb2_read_data_offset,
5447 .read_data_length = smb2_read_data_length,
5448 .map_error = map_smb2_to_linux_error,
5449 .find_mid = smb2_find_mid,
5450 .check_message = smb2_check_message,
5451 .dump_detail = smb2_dump_detail,
5452 .clear_stats = smb2_clear_stats,
5453 .print_stats = smb2_print_stats,
5454 .dump_share_caps = smb2_dump_share_caps,
5455 .is_oplock_break = smb2_is_valid_oplock_break,
5456 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5457 .downgrade_oplock = smb3_downgrade_oplock,
5458 .need_neg = smb2_need_neg,
5459 .negotiate = smb2_negotiate,
5460 .negotiate_wsize = smb3_negotiate_wsize,
5461 .negotiate_rsize = smb3_negotiate_rsize,
5462 .sess_setup = SMB2_sess_setup,
5463 .logoff = SMB2_logoff,
5464 .tree_connect = SMB2_tcon,
5465 .tree_disconnect = SMB2_tdis,
5466 .qfs_tcon = smb3_qfs_tcon,
5467 .is_path_accessible = smb2_is_path_accessible,
5468 .can_echo = smb2_can_echo,
5470 .query_path_info = smb2_query_path_info,
5471 .query_reparse_tag = smb2_query_reparse_tag,
5472 .get_srv_inum = smb2_get_srv_inum,
5473 .query_file_info = smb2_query_file_info,
5474 .set_path_size = smb2_set_path_size,
5475 .set_file_size = smb2_set_file_size,
5476 .set_file_info = smb2_set_file_info,
5477 .set_compression = smb2_set_compression,
5478 .mkdir = smb2_mkdir,
5479 .mkdir_setinfo = smb2_mkdir_setinfo,
5480 .posix_mkdir = smb311_posix_mkdir,
5481 .rmdir = smb2_rmdir,
5482 .unlink = smb2_unlink,
5483 .rename = smb2_rename_path,
5484 .create_hardlink = smb2_create_hardlink,
5485 .query_symlink = smb2_query_symlink,
5486 .query_mf_symlink = smb3_query_mf_symlink,
5487 .create_mf_symlink = smb3_create_mf_symlink,
5488 .open = smb2_open_file,
5489 .set_fid = smb2_set_fid,
5490 .close = smb2_close_file,
5491 .close_getattr = smb2_close_getattr,
5492 .flush = smb2_flush_file,
5493 .async_readv = smb2_async_readv,
5494 .async_writev = smb2_async_writev,
5495 .sync_read = smb2_sync_read,
5496 .sync_write = smb2_sync_write,
5497 .query_dir_first = smb2_query_dir_first,
5498 .query_dir_next = smb2_query_dir_next,
5499 .close_dir = smb2_close_dir,
5500 .calc_smb_size = smb2_calc_size,
5501 .is_status_pending = smb2_is_status_pending,
5502 .is_session_expired = smb2_is_session_expired,
5503 .oplock_response = smb2_oplock_response,
5504 .queryfs = smb311_queryfs,
5505 .mand_lock = smb2_mand_lock,
5506 .mand_unlock_range = smb2_unlock_range,
5507 .push_mand_locks = smb2_push_mandatory_locks,
5508 .get_lease_key = smb2_get_lease_key,
5509 .set_lease_key = smb2_set_lease_key,
5510 .new_lease_key = smb2_new_lease_key,
5511 .generate_signingkey = generate_smb311signingkey,
5512 .calc_signature = smb3_calc_signature,
5513 .set_integrity = smb3_set_integrity,
5514 .is_read_op = smb21_is_read_op,
5515 .set_oplock_level = smb3_set_oplock_level,
5516 .create_lease_buf = smb3_create_lease_buf,
5517 .parse_lease_buf = smb3_parse_lease_buf,
5518 .copychunk_range = smb2_copychunk_range,
5519 .duplicate_extents = smb2_duplicate_extents,
5520 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
5521 .wp_retry_size = smb2_wp_retry_size,
5522 .dir_needs_close = smb2_dir_needs_close,
5523 .fallocate = smb3_fallocate,
5524 .enum_snapshots = smb3_enum_snapshots,
5525 .notify = smb3_notify,
5526 .init_transform_rq = smb3_init_transform_rq,
5527 .is_transform_hdr = smb3_is_transform_hdr,
5528 .receive_transform = smb3_receive_transform,
5529 .get_dfs_refer = smb2_get_dfs_refer,
5530 .select_sectype = smb2_select_sectype,
5531 #ifdef CONFIG_CIFS_XATTR
5532 .query_all_EAs = smb2_query_eas,
5533 .set_EA = smb2_set_ea,
5534 #endif /* CIFS_XATTR */
5535 .get_acl = get_smb2_acl,
5536 .get_acl_by_fid = get_smb2_acl_by_fid,
5537 .set_acl = set_smb2_acl,
5538 .next_header = smb2_next_header,
5539 .ioctl_query_info = smb2_ioctl_query_info,
5540 .make_node = smb2_make_node,
5541 .fiemap = smb3_fiemap,
5542 .llseek = smb3_llseek,
5543 .is_status_io_timeout = smb2_is_status_io_timeout,
5546 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5547 struct smb_version_values smb20_values = {
5548 .version_string = SMB20_VERSION_STRING,
5549 .protocol_id = SMB20_PROT_ID,
5550 .req_capabilities = 0, /* MBZ */
5551 .large_lock_type = 0,
5552 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5553 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5554 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5555 .header_size = sizeof(struct smb2_sync_hdr),
5556 .header_preamble_size = 0,
5557 .max_header_size = MAX_SMB2_HDR_SIZE,
5558 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5559 .lock_cmd = SMB2_LOCK,
5561 .cap_nt_find = SMB2_NT_FIND,
5562 .cap_large_files = SMB2_LARGE_FILES,
5563 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5564 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5565 .create_lease_size = sizeof(struct create_lease),
5567 #endif /* ALLOW_INSECURE_LEGACY */
5569 struct smb_version_values smb21_values = {
5570 .version_string = SMB21_VERSION_STRING,
5571 .protocol_id = SMB21_PROT_ID,
5572 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
5573 .large_lock_type = 0,
5574 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5575 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5576 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5577 .header_size = sizeof(struct smb2_sync_hdr),
5578 .header_preamble_size = 0,
5579 .max_header_size = MAX_SMB2_HDR_SIZE,
5580 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5581 .lock_cmd = SMB2_LOCK,
5583 .cap_nt_find = SMB2_NT_FIND,
5584 .cap_large_files = SMB2_LARGE_FILES,
5585 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5586 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5587 .create_lease_size = sizeof(struct create_lease),
5590 struct smb_version_values smb3any_values = {
5591 .version_string = SMB3ANY_VERSION_STRING,
5592 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5593 .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,
5594 .large_lock_type = 0,
5595 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5596 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5597 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5598 .header_size = sizeof(struct smb2_sync_hdr),
5599 .header_preamble_size = 0,
5600 .max_header_size = MAX_SMB2_HDR_SIZE,
5601 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5602 .lock_cmd = SMB2_LOCK,
5604 .cap_nt_find = SMB2_NT_FIND,
5605 .cap_large_files = SMB2_LARGE_FILES,
5606 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5607 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5608 .create_lease_size = sizeof(struct create_lease_v2),
5611 struct smb_version_values smbdefault_values = {
5612 .version_string = SMBDEFAULT_VERSION_STRING,
5613 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5614 .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,
5615 .large_lock_type = 0,
5616 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5617 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5618 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5619 .header_size = sizeof(struct smb2_sync_hdr),
5620 .header_preamble_size = 0,
5621 .max_header_size = MAX_SMB2_HDR_SIZE,
5622 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5623 .lock_cmd = SMB2_LOCK,
5625 .cap_nt_find = SMB2_NT_FIND,
5626 .cap_large_files = SMB2_LARGE_FILES,
5627 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5628 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5629 .create_lease_size = sizeof(struct create_lease_v2),
5632 struct smb_version_values smb30_values = {
5633 .version_string = SMB30_VERSION_STRING,
5634 .protocol_id = SMB30_PROT_ID,
5635 .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,
5636 .large_lock_type = 0,
5637 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5638 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5639 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5640 .header_size = sizeof(struct smb2_sync_hdr),
5641 .header_preamble_size = 0,
5642 .max_header_size = MAX_SMB2_HDR_SIZE,
5643 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5644 .lock_cmd = SMB2_LOCK,
5646 .cap_nt_find = SMB2_NT_FIND,
5647 .cap_large_files = SMB2_LARGE_FILES,
5648 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5649 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5650 .create_lease_size = sizeof(struct create_lease_v2),
5653 struct smb_version_values smb302_values = {
5654 .version_string = SMB302_VERSION_STRING,
5655 .protocol_id = SMB302_PROT_ID,
5656 .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,
5657 .large_lock_type = 0,
5658 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5659 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5660 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5661 .header_size = sizeof(struct smb2_sync_hdr),
5662 .header_preamble_size = 0,
5663 .max_header_size = MAX_SMB2_HDR_SIZE,
5664 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5665 .lock_cmd = SMB2_LOCK,
5667 .cap_nt_find = SMB2_NT_FIND,
5668 .cap_large_files = SMB2_LARGE_FILES,
5669 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5670 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5671 .create_lease_size = sizeof(struct create_lease_v2),
5674 struct smb_version_values smb311_values = {
5675 .version_string = SMB311_VERSION_STRING,
5676 .protocol_id = SMB311_PROT_ID,
5677 .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,
5678 .large_lock_type = 0,
5679 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5680 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5681 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5682 .header_size = sizeof(struct smb2_sync_hdr),
5683 .header_preamble_size = 0,
5684 .max_header_size = MAX_SMB2_HDR_SIZE,
5685 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5686 .lock_cmd = SMB2_LOCK,
5688 .cap_nt_find = SMB2_NT_FIND,
5689 .cap_large_files = SMB2_LARGE_FILES,
5690 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5691 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5692 .create_lease_size = sizeof(struct create_lease_v2),