1 // SPDX-License-Identifier: GPL-2.0
3 * SMB2 version specific operations
8 #include <linux/pagemap.h>
10 #include <linux/falloc.h>
11 #include <linux/scatterlist.h>
12 #include <linux/uuid.h>
13 #include <linux/sort.h>
14 #include <crypto/aead.h>
15 #include <linux/fiemap.h>
16 #include <linux/folio_queue.h>
17 #include <uapi/linux/magic.h>
21 #include "smb2proto.h"
22 #include "cifsproto.h"
23 #include "cifs_debug.h"
24 #include "cifs_unicode.h"
25 #include "../common/smb2status.h"
27 #include "cifs_ioctl.h"
28 #include "smbdirect.h"
30 #include "fs_context.h"
31 #include "cached_dir.h"
34 /* Change credits for different ops and return the total number of credits */
36 change_conf(struct TCP_Server_Info *server)
38 server->credits += server->echo_credits + server->oplock_credits;
39 if (server->credits > server->max_credits)
40 server->credits = server->max_credits;
41 server->oplock_credits = server->echo_credits = 0;
42 switch (server->credits) {
46 server->echoes = false;
47 server->oplocks = false;
50 server->echoes = true;
51 server->oplocks = false;
52 server->echo_credits = 1;
55 server->echoes = true;
57 server->oplocks = true;
58 server->oplock_credits = 1;
60 server->oplocks = false;
62 server->echo_credits = 1;
64 server->credits -= server->echo_credits + server->oplock_credits;
65 return server->credits + server->echo_credits + server->oplock_credits;
69 smb2_add_credits(struct TCP_Server_Info *server,
70 struct cifs_credits *credits, const int optype)
73 int scredits, in_flight;
74 unsigned int add = credits->value;
75 unsigned int instance = credits->instance;
76 bool reconnect_detected = false;
77 bool reconnect_with_invalid_credits = false;
79 spin_lock(&server->req_lock);
80 val = server->ops->get_credits_field(server, optype);
82 /* eg found case where write overlapping reconnect messed up credits */
83 if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0))
84 reconnect_with_invalid_credits = true;
86 if ((instance == 0) || (instance == server->reconnect_instance))
89 reconnect_detected = true;
92 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
93 pr_warn_once("server overflowed SMB3 credits\n");
94 trace_smb3_overflow_credits(server->CurrentMid,
95 server->conn_id, server->hostname, *val,
96 add, server->in_flight);
98 if (credits->in_flight_check > 1) {
99 pr_warn_once("rreq R=%08x[%x] Credits not in flight\n",
100 credits->rreq_debug_id, credits->rreq_debug_index);
102 credits->in_flight_check = 2;
104 if (WARN_ON_ONCE(server->in_flight == 0)) {
105 pr_warn_once("rreq R=%08x[%x] Zero in_flight\n",
106 credits->rreq_debug_id, credits->rreq_debug_index);
107 trace_smb3_rw_credits(credits->rreq_debug_id,
108 credits->rreq_debug_index,
110 server->credits, server->in_flight, 0,
111 cifs_trace_rw_credits_zero_in_flight);
114 if (server->in_flight == 0 &&
115 ((optype & CIFS_OP_MASK) != CIFS_NEG_OP) &&
116 ((optype & CIFS_OP_MASK) != CIFS_SESS_OP))
117 rc = change_conf(server);
119 * Sometimes server returns 0 credits on oplock break ack - we need to
120 * rebalance credits in this case.
122 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
124 if (server->credits > 1) {
126 server->oplock_credits++;
128 } else if ((server->in_flight > 0) && (server->oplock_credits > 3) &&
129 ((optype & CIFS_OP_MASK) == CIFS_OBREAK_OP))
130 /* if now have too many oplock credits, rebalance so don't starve normal ops */
134 in_flight = server->in_flight;
135 spin_unlock(&server->req_lock);
136 wake_up(&server->request_q);
138 if (reconnect_detected) {
139 trace_smb3_reconnect_detected(server->CurrentMid,
140 server->conn_id, server->hostname, scredits, add, in_flight);
142 cifs_dbg(FYI, "trying to put %d credits from the old server instance %d\n",
146 if (reconnect_with_invalid_credits) {
147 trace_smb3_reconnect_with_invalid_credits(server->CurrentMid,
148 server->conn_id, server->hostname, scredits, add, in_flight);
149 cifs_dbg(FYI, "Negotiate operation when server credits is non-zero. Optype: %d, server credits: %d, credits added: %d\n",
150 optype, scredits, add);
153 spin_lock(&server->srv_lock);
154 if (server->tcpStatus == CifsNeedReconnect
155 || server->tcpStatus == CifsExiting) {
156 spin_unlock(&server->srv_lock);
159 spin_unlock(&server->srv_lock);
163 /* change_conf hasn't been executed */
166 cifs_server_dbg(VFS, "Possible client or server bug - zero credits\n");
169 cifs_server_dbg(VFS, "disabling echoes and oplocks\n");
172 cifs_dbg(FYI, "disabling oplocks\n");
175 /* change_conf rebalanced credits for different types */
179 trace_smb3_add_credits(server->CurrentMid,
180 server->conn_id, server->hostname, scredits, add, in_flight);
181 cifs_dbg(FYI, "%s: added %u credits total=%d\n", __func__, add, scredits);
185 smb2_set_credits(struct TCP_Server_Info *server, const int val)
187 int scredits, in_flight;
189 spin_lock(&server->req_lock);
190 server->credits = val;
192 server->reconnect_instance++;
194 * ChannelSequence updated for all channels in primary channel so that consistent
195 * across SMB3 requests sent on any channel. See MS-SMB2 3.2.4.1 and 3.2.7.1
197 if (SERVER_IS_CHAN(server))
198 server->primary_server->channel_sequence_num++;
200 server->channel_sequence_num++;
202 scredits = server->credits;
203 in_flight = server->in_flight;
204 spin_unlock(&server->req_lock);
206 trace_smb3_set_credits(server->CurrentMid,
207 server->conn_id, server->hostname, scredits, val, in_flight);
208 cifs_dbg(FYI, "%s: set %u credits\n", __func__, val);
210 /* don't log while holding the lock */
212 cifs_dbg(FYI, "set credits to 1 due to smb2 reconnect\n");
216 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
220 return &server->echo_credits;
222 return &server->oplock_credits;
224 return &server->credits;
229 smb2_get_credits(struct mid_q_entry *mid)
231 return mid->credits_received;
235 smb2_wait_mtu_credits(struct TCP_Server_Info *server, size_t size,
236 size_t *num, struct cifs_credits *credits)
239 unsigned int scredits, in_flight;
241 spin_lock(&server->req_lock);
243 spin_unlock(&server->req_lock);
245 spin_lock(&server->srv_lock);
246 if (server->tcpStatus == CifsExiting) {
247 spin_unlock(&server->srv_lock);
250 spin_unlock(&server->srv_lock);
252 spin_lock(&server->req_lock);
253 if (server->credits <= 0) {
254 spin_unlock(&server->req_lock);
255 cifs_num_waiters_inc(server);
256 rc = wait_event_killable(server->request_q,
257 has_credits(server, &server->credits, 1));
258 cifs_num_waiters_dec(server);
261 spin_lock(&server->req_lock);
263 scredits = server->credits;
264 /* can deadlock with reopen */
266 *num = SMB2_MAX_BUFFER_SIZE;
268 credits->instance = 0;
272 /* leave some credits for reopen and other ops */
274 *num = min_t(unsigned int, size,
275 scredits * SMB2_MAX_BUFFER_SIZE);
278 DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
279 credits->instance = server->reconnect_instance;
280 server->credits -= credits->value;
282 if (server->in_flight > server->max_in_flight)
283 server->max_in_flight = server->in_flight;
287 scredits = server->credits;
288 in_flight = server->in_flight;
289 spin_unlock(&server->req_lock);
291 trace_smb3_wait_credits(server->CurrentMid,
292 server->conn_id, server->hostname, scredits, -(credits->value), in_flight);
293 cifs_dbg(FYI, "%s: removed %u credits total=%d\n",
294 __func__, credits->value, scredits);
300 smb2_adjust_credits(struct TCP_Server_Info *server,
301 struct cifs_io_subrequest *subreq,
302 unsigned int /*enum smb3_rw_credits_trace*/ trace)
304 struct cifs_credits *credits = &subreq->credits;
305 int new_val = DIV_ROUND_UP(subreq->subreq.len - subreq->subreq.transferred,
306 SMB2_MAX_BUFFER_SIZE);
307 int scredits, in_flight;
309 if (!credits->value || credits->value == new_val)
312 if (credits->value < new_val) {
313 trace_smb3_rw_credits(subreq->rreq->debug_id,
314 subreq->subreq.debug_index,
316 server->credits, server->in_flight,
317 new_val - credits->value,
318 cifs_trace_rw_credits_no_adjust_up);
319 trace_smb3_too_many_credits(server->CurrentMid,
320 server->conn_id, server->hostname, 0, credits->value - new_val, 0);
321 cifs_server_dbg(VFS, "R=%x[%x] request has less credits (%d) than required (%d)",
322 subreq->rreq->debug_id, subreq->subreq.debug_index,
323 credits->value, new_val);
328 spin_lock(&server->req_lock);
330 if (server->reconnect_instance != credits->instance) {
331 scredits = server->credits;
332 in_flight = server->in_flight;
333 spin_unlock(&server->req_lock);
335 trace_smb3_rw_credits(subreq->rreq->debug_id,
336 subreq->subreq.debug_index,
338 server->credits, server->in_flight,
339 new_val - credits->value,
340 cifs_trace_rw_credits_old_session);
341 trace_smb3_reconnect_detected(server->CurrentMid,
342 server->conn_id, server->hostname, scredits,
343 credits->value - new_val, in_flight);
344 cifs_server_dbg(VFS, "R=%x[%x] trying to return %d credits to old session\n",
345 subreq->rreq->debug_id, subreq->subreq.debug_index,
346 credits->value - new_val);
350 trace_smb3_rw_credits(subreq->rreq->debug_id,
351 subreq->subreq.debug_index,
353 server->credits, server->in_flight,
354 new_val - credits->value, trace);
355 server->credits += credits->value - new_val;
356 scredits = server->credits;
357 in_flight = server->in_flight;
358 spin_unlock(&server->req_lock);
359 wake_up(&server->request_q);
361 trace_smb3_adj_credits(server->CurrentMid,
362 server->conn_id, server->hostname, scredits,
363 credits->value - new_val, in_flight);
364 cifs_dbg(FYI, "%s: adjust added %u credits total=%d\n",
365 __func__, credits->value - new_val, scredits);
367 credits->value = new_val;
373 smb2_get_next_mid(struct TCP_Server_Info *server)
376 /* for SMB2 we need the current value */
377 spin_lock(&server->mid_lock);
378 mid = server->CurrentMid++;
379 spin_unlock(&server->mid_lock);
384 smb2_revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
386 spin_lock(&server->mid_lock);
387 if (server->CurrentMid >= val)
388 server->CurrentMid -= val;
389 spin_unlock(&server->mid_lock);
392 static struct mid_q_entry *
393 __smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue)
395 struct mid_q_entry *mid;
396 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
397 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
399 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
400 cifs_server_dbg(VFS, "Encrypted frame parsing not supported yet\n");
404 spin_lock(&server->mid_lock);
405 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
406 if ((mid->mid == wire_mid) &&
407 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
408 (mid->command == shdr->Command)) {
409 kref_get(&mid->refcount);
411 list_del_init(&mid->qhead);
412 mid->mid_flags |= MID_DELETED;
414 spin_unlock(&server->mid_lock);
418 spin_unlock(&server->mid_lock);
422 static struct mid_q_entry *
423 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
425 return __smb2_find_mid(server, buf, false);
428 static struct mid_q_entry *
429 smb2_find_dequeue_mid(struct TCP_Server_Info *server, char *buf)
431 return __smb2_find_mid(server, buf, true);
435 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
437 #ifdef CONFIG_CIFS_DEBUG2
438 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
440 cifs_server_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
441 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
442 shdr->Id.SyncId.ProcessId);
443 if (!server->ops->check_message(buf, server->total_read, server)) {
444 cifs_server_dbg(VFS, "smb buf %p len %u\n", buf,
445 server->ops->calc_smb_size(buf));
451 smb2_need_neg(struct TCP_Server_Info *server)
453 return server->max_read == 0;
457 smb2_negotiate(const unsigned int xid,
458 struct cifs_ses *ses,
459 struct TCP_Server_Info *server)
463 spin_lock(&server->mid_lock);
464 server->CurrentMid = 0;
465 spin_unlock(&server->mid_lock);
466 rc = SMB2_negotiate(xid, ses, server);
467 /* BB we probably don't need to retry with modern servers */
474 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
476 struct TCP_Server_Info *server = tcon->ses->server;
479 /* start with specified wsize, or default */
480 wsize = ctx->wsize ? ctx->wsize : CIFS_DEFAULT_IOSIZE;
481 wsize = min_t(unsigned int, wsize, server->max_write);
482 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
483 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
489 smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
491 struct TCP_Server_Info *server = tcon->ses->server;
494 /* start with specified wsize, or default */
495 wsize = ctx->wsize ? ctx->wsize : SMB3_DEFAULT_IOSIZE;
496 wsize = min_t(unsigned int, wsize, server->max_write);
497 #ifdef CONFIG_CIFS_SMB_DIRECT
501 * Account for SMB2 data transfer packet header and
502 * possible encryption header
504 wsize = min_t(unsigned int,
506 server->smbd_conn->max_fragmented_send_size -
507 SMB2_READWRITE_PDU_HEADER_SIZE -
508 sizeof(struct smb2_transform_hdr));
510 wsize = min_t(unsigned int,
511 wsize, server->smbd_conn->max_readwrite_size);
514 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
515 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
521 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
523 struct TCP_Server_Info *server = tcon->ses->server;
526 /* start with specified rsize, or default */
527 rsize = ctx->rsize ? ctx->rsize : CIFS_DEFAULT_IOSIZE;
528 rsize = min_t(unsigned int, rsize, server->max_read);
530 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
531 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
537 smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
539 struct TCP_Server_Info *server = tcon->ses->server;
542 /* start with specified rsize, or default */
543 rsize = ctx->rsize ? ctx->rsize : SMB3_DEFAULT_IOSIZE;
544 rsize = min_t(unsigned int, rsize, server->max_read);
545 #ifdef CONFIG_CIFS_SMB_DIRECT
549 * Account for SMB2 data transfer packet header and
550 * possible encryption header
552 rsize = min_t(unsigned int,
554 server->smbd_conn->max_fragmented_recv_size -
555 SMB2_READWRITE_PDU_HEADER_SIZE -
556 sizeof(struct smb2_transform_hdr));
558 rsize = min_t(unsigned int,
559 rsize, server->smbd_conn->max_readwrite_size);
563 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
564 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
570 * compare two interfaces a and b
571 * return 0 if everything matches.
572 * return 1 if a is rdma capable, or rss capable, or has higher link speed
573 * return -1 otherwise.
576 iface_cmp(struct cifs_server_iface *a, struct cifs_server_iface *b)
581 if (a->rdma_capable == b->rdma_capable) {
582 if (a->rss_capable == b->rss_capable) {
583 if (a->speed == b->speed) {
584 cmp_ret = cifs_ipaddr_cmp((struct sockaddr *) &a->sockaddr,
585 (struct sockaddr *) &b->sockaddr);
588 else if (cmp_ret > 0)
592 } else if (a->speed > b->speed)
596 } else if (a->rss_capable > b->rss_capable)
600 } else if (a->rdma_capable > b->rdma_capable)
607 parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
608 size_t buf_len, struct cifs_ses *ses, bool in_mount)
610 struct network_interface_info_ioctl_rsp *p;
611 struct sockaddr_in *addr4;
612 struct sockaddr_in6 *addr6;
613 struct iface_info_ipv4 *p4;
614 struct iface_info_ipv6 *p6;
615 struct cifs_server_iface *info = NULL, *iface = NULL, *niface = NULL;
616 struct cifs_server_iface tmp_iface;
622 bytes_left = buf_len;
625 spin_lock(&ses->iface_lock);
626 /* do not query too frequently, this time with lock held */
627 if (ses->iface_last_update &&
628 time_before(jiffies, ses->iface_last_update +
629 (SMB_INTERFACE_POLL_INTERVAL * HZ))) {
630 spin_unlock(&ses->iface_lock);
635 * Go through iface_list and mark them as inactive
637 list_for_each_entry_safe(iface, niface, &ses->iface_list,
639 iface->is_active = 0;
641 spin_unlock(&ses->iface_lock);
644 * Samba server e.g. can return an empty interface list in some cases,
645 * which would only be a problem if we were requesting multichannel
647 if (bytes_left == 0) {
648 /* avoid spamming logs every 10 minutes, so log only in mount */
649 if ((ses->chan_max > 1) && in_mount)
651 "multichannel not available\n"
652 "Empty network interface list returned by server %s\n",
653 ses->server->hostname);
655 ses->iface_last_update = jiffies;
659 while (bytes_left >= (ssize_t)sizeof(*p)) {
660 memset(&tmp_iface, 0, sizeof(tmp_iface));
661 tmp_iface.speed = le64_to_cpu(p->LinkSpeed);
662 tmp_iface.rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE) ? 1 : 0;
663 tmp_iface.rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE) ? 1 : 0;
667 * The kernel and wire socket structures have the same
668 * layout and use network byte order but make the
669 * conversion explicit in case either one changes.
672 addr4 = (struct sockaddr_in *)&tmp_iface.sockaddr;
673 p4 = (struct iface_info_ipv4 *)p->Buffer;
674 addr4->sin_family = AF_INET;
675 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
677 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
678 addr4->sin_port = cpu_to_be16(CIFS_PORT);
680 cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
684 addr6 = (struct sockaddr_in6 *)&tmp_iface.sockaddr;
685 p6 = (struct iface_info_ipv6 *)p->Buffer;
686 addr6->sin6_family = AF_INET6;
687 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
689 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
690 addr6->sin6_flowinfo = 0;
691 addr6->sin6_scope_id = 0;
692 addr6->sin6_port = cpu_to_be16(CIFS_PORT);
694 cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
699 "%s: skipping unsupported socket family\n",
705 * The iface_list is assumed to be sorted by speed.
706 * Check if the new interface exists in that list.
707 * NEVER change iface. it could be in use.
708 * Add a new one instead
710 spin_lock(&ses->iface_lock);
711 list_for_each_entry_safe(iface, niface, &ses->iface_list,
713 ret = iface_cmp(iface, &tmp_iface);
715 iface->is_active = 1;
716 spin_unlock(&ses->iface_lock);
718 } else if (ret < 0) {
719 /* all remaining ifaces are slower */
720 kref_get(&iface->refcount);
724 spin_unlock(&ses->iface_lock);
726 /* no match. insert the entry in the list */
727 info = kmalloc(sizeof(struct cifs_server_iface),
733 memcpy(info, &tmp_iface, sizeof(tmp_iface));
735 /* add this new entry to the list */
736 kref_init(&info->refcount);
739 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, ses->iface_count);
740 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
741 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
742 le32_to_cpu(p->Capability));
744 spin_lock(&ses->iface_lock);
745 if (!list_entry_is_head(iface, &ses->iface_list, iface_head)) {
746 list_add_tail(&info->iface_head, &iface->iface_head);
747 kref_put(&iface->refcount, release_iface);
749 list_add_tail(&info->iface_head, &ses->iface_list);
752 spin_unlock(&ses->iface_lock);
755 next = le32_to_cpu(p->Next);
757 bytes_left -= sizeof(*p);
760 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
765 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
770 /* Azure rounds the buffer size up 8, to a 16 byte boundary */
771 if ((bytes_left > 8) || p->Next)
772 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
774 ses->iface_last_update = jiffies;
778 * Go through the list again and put the inactive entries
780 spin_lock(&ses->iface_lock);
781 list_for_each_entry_safe(iface, niface, &ses->iface_list,
783 if (!iface->is_active) {
784 list_del(&iface->iface_head);
785 kref_put(&iface->refcount, release_iface);
789 spin_unlock(&ses->iface_lock);
795 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon, bool in_mount)
798 unsigned int ret_data_len = 0;
799 struct network_interface_info_ioctl_rsp *out_buf = NULL;
800 struct cifs_ses *ses = tcon->ses;
801 struct TCP_Server_Info *pserver;
803 /* do not query too frequently */
804 if (ses->iface_last_update &&
805 time_before(jiffies, ses->iface_last_update +
806 (SMB_INTERFACE_POLL_INTERVAL * HZ)))
809 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
810 FSCTL_QUERY_NETWORK_INTERFACE_INFO,
811 NULL /* no data input */, 0 /* no data input */,
812 CIFSMaxBufSize, (char **)&out_buf, &ret_data_len);
813 if (rc == -EOPNOTSUPP) {
815 "server does not support query network interfaces\n");
817 } else if (rc != 0) {
818 cifs_tcon_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
822 rc = parse_server_interfaces(out_buf, ret_data_len, ses, in_mount);
826 /* check if iface is still active */
827 spin_lock(&ses->chan_lock);
828 pserver = ses->chans[0].server;
829 if (pserver && !cifs_chan_is_iface_active(ses, pserver)) {
830 spin_unlock(&ses->chan_lock);
831 cifs_chan_update_iface(ses, pserver);
832 spin_lock(&ses->chan_lock);
834 spin_unlock(&ses->chan_lock);
842 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
843 struct cifs_sb_info *cifs_sb)
846 __le16 srch_path = 0; /* Null - open root of share */
847 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
848 struct cifs_open_parms oparms;
850 struct cached_fid *cfid = NULL;
852 oparms = (struct cifs_open_parms) {
855 .desired_access = FILE_READ_ATTRIBUTES,
856 .disposition = FILE_OPEN,
857 .create_options = cifs_create_options(cifs_sb, 0),
861 rc = open_cached_dir(xid, tcon, "", cifs_sb, false, &cfid);
863 memcpy(&fid, &cfid->fid, sizeof(struct cifs_fid));
865 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
870 SMB3_request_interfaces(xid, tcon, true /* called during mount */);
872 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
873 FS_ATTRIBUTE_INFORMATION);
874 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
875 FS_DEVICE_INFORMATION);
876 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
877 FS_VOLUME_INFORMATION);
878 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
879 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
881 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
883 close_cached_dir(cfid);
887 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
888 struct cifs_sb_info *cifs_sb)
891 __le16 srch_path = 0; /* Null - open root of share */
892 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
893 struct cifs_open_parms oparms;
896 oparms = (struct cifs_open_parms) {
899 .desired_access = FILE_READ_ATTRIBUTES,
900 .disposition = FILE_OPEN,
901 .create_options = cifs_create_options(cifs_sb, 0),
905 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
910 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
911 FS_ATTRIBUTE_INFORMATION);
912 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
913 FS_DEVICE_INFORMATION);
914 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
918 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
919 struct cifs_sb_info *cifs_sb, const char *full_path)
922 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
923 int err_buftype = CIFS_NO_BUFFER;
924 struct cifs_open_parms oparms;
925 struct kvec err_iov = {};
927 struct cached_fid *cfid;
931 rc = open_cached_dir(xid, tcon, full_path, cifs_sb, true, &cfid);
933 if (cfid->has_lease) {
934 close_cached_dir(cfid);
937 close_cached_dir(cfid);
940 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
944 oparms = (struct cifs_open_parms) {
947 .desired_access = FILE_READ_ATTRIBUTES,
948 .disposition = FILE_OPEN,
949 .create_options = cifs_create_options(cifs_sb, 0),
953 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
954 &err_iov, &err_buftype);
956 struct smb2_hdr *hdr = err_iov.iov_base;
958 if (unlikely(!hdr || err_buftype == CIFS_NO_BUFFER))
961 if (rc != -EREMOTE && hdr->Status == STATUS_OBJECT_NAME_INVALID) {
962 rc2 = cifs_inval_name_dfs_link_error(xid, tcon, cifs_sb,
971 if (rc == -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) && cifs_sb &&
972 (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS))
977 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
980 free_rsp_buf(err_buftype, err_iov.iov_base);
985 static int smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
986 struct cifs_sb_info *cifs_sb, const char *full_path,
987 u64 *uniqueid, struct cifs_open_info_data *data)
989 *uniqueid = le64_to_cpu(data->fi.IndexNumber);
993 static int smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
994 struct cifsFileInfo *cfile, struct cifs_open_info_data *data)
996 struct cifs_fid *fid = &cfile->fid;
998 if (cfile->symlink_target) {
999 data->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
1000 if (!data->symlink_target)
1003 return SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, &data->fi);
1006 #ifdef CONFIG_CIFS_XATTR
1008 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
1009 struct smb2_file_full_ea_info *src, size_t src_size,
1010 const unsigned char *ea_name)
1013 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
1015 size_t buf_size = dst_size;
1016 size_t name_len, value_len, user_name_len;
1018 while (src_size > 0) {
1019 name_len = (size_t)src->ea_name_length;
1020 value_len = (size_t)le16_to_cpu(src->ea_value_length);
1025 if (src_size < 8 + name_len + 1 + value_len) {
1026 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
1031 name = &src->ea_data[0];
1032 value = &src->ea_data[src->ea_name_length + 1];
1035 if (ea_name_len == name_len &&
1036 memcmp(ea_name, name, name_len) == 0) {
1040 if (dst_size < value_len) {
1044 memcpy(dst, value, value_len);
1048 /* 'user.' plus a terminating null */
1049 user_name_len = 5 + 1 + name_len;
1051 if (buf_size == 0) {
1052 /* skip copy - calc size only */
1053 rc += user_name_len;
1054 } else if (dst_size >= user_name_len) {
1055 dst_size -= user_name_len;
1056 memcpy(dst, "user.", 5);
1058 memcpy(dst, src->ea_data, name_len);
1062 rc += user_name_len;
1064 /* stop before overrun buffer */
1070 if (!src->next_entry_offset)
1073 if (src_size < le32_to_cpu(src->next_entry_offset)) {
1074 /* stop before overrun buffer */
1078 src_size -= le32_to_cpu(src->next_entry_offset);
1079 src = (void *)((char *)src +
1080 le32_to_cpu(src->next_entry_offset));
1083 /* didn't find the named attribute */
1092 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
1093 const unsigned char *path, const unsigned char *ea_name,
1094 char *ea_data, size_t buf_size,
1095 struct cifs_sb_info *cifs_sb)
1098 struct kvec rsp_iov = {NULL, 0};
1099 int buftype = CIFS_NO_BUFFER;
1100 struct smb2_query_info_rsp *rsp;
1101 struct smb2_file_full_ea_info *info = NULL;
1103 rc = smb2_query_info_compound(xid, tcon, path,
1105 FILE_FULL_EA_INFORMATION,
1108 MAX_SMB2_CREATE_RESPONSE_SIZE -
1109 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1110 &rsp_iov, &buftype, cifs_sb);
1113 * If ea_name is NULL (listxattr) and there are no EAs,
1114 * return 0 as it's not an error. Otherwise, the specified
1115 * ea_name was not found.
1117 if (!ea_name && rc == -ENODATA)
1122 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
1123 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1124 le32_to_cpu(rsp->OutputBufferLength),
1126 sizeof(struct smb2_file_full_ea_info));
1130 info = (struct smb2_file_full_ea_info *)(
1131 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1132 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
1133 le32_to_cpu(rsp->OutputBufferLength), ea_name);
1136 free_rsp_buf(buftype, rsp_iov.iov_base);
1141 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
1142 const char *path, const char *ea_name, const void *ea_value,
1143 const __u16 ea_value_len, const struct nls_table *nls_codepage,
1144 struct cifs_sb_info *cifs_sb)
1146 struct smb2_compound_vars *vars;
1147 struct cifs_ses *ses = tcon->ses;
1148 struct TCP_Server_Info *server;
1149 struct smb_rqst *rqst;
1150 struct kvec *rsp_iov;
1151 __le16 *utf16_path = NULL;
1152 int ea_name_len = strlen(ea_name);
1153 int flags = CIFS_CP_CREATE_CLOSE_OP;
1155 int resp_buftype[3];
1156 struct cifs_open_parms oparms;
1157 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1158 struct cifs_fid fid;
1159 unsigned int size[1];
1161 struct smb2_file_full_ea_info *ea;
1162 struct smb2_query_info_rsp *rsp;
1163 int rc, used_len = 0;
1164 int retries = 0, cur_sleep = 1;
1167 /* reinitialize for possible replay */
1168 flags = CIFS_CP_CREATE_CLOSE_OP;
1169 oplock = SMB2_OPLOCK_LEVEL_NONE;
1170 server = cifs_pick_channel(ses);
1172 if (smb3_encryption_required(tcon))
1173 flags |= CIFS_TRANSFORM_REQ;
1175 if (ea_name_len > 255)
1178 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1183 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1184 vars = kzalloc(sizeof(*vars), GFP_KERNEL);
1190 rsp_iov = vars->rsp_iov;
1192 if (ses->server->ops->query_all_EAs) {
1194 rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1200 /* If we are adding a attribute we should first check
1201 * if there will be enough space available to store
1202 * the new EA. If not we should not add it since we
1203 * would not be able to even read the EAs back.
1205 rc = smb2_query_info_compound(xid, tcon, path,
1207 FILE_FULL_EA_INFORMATION,
1210 MAX_SMB2_CREATE_RESPONSE_SIZE -
1211 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1212 &rsp_iov[1], &resp_buftype[1], cifs_sb);
1214 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1215 used_len = le32_to_cpu(rsp->OutputBufferLength);
1217 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1218 resp_buftype[1] = CIFS_NO_BUFFER;
1219 memset(&rsp_iov[1], 0, sizeof(rsp_iov[1]));
1222 /* Use a fudge factor of 256 bytes in case we collide
1223 * with a different set_EAs command.
1225 if (CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1226 MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 <
1227 used_len + ea_name_len + ea_value_len + 1) {
1235 rqst[0].rq_iov = vars->open_iov;
1236 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1238 oparms = (struct cifs_open_parms) {
1241 .desired_access = FILE_WRITE_EA,
1242 .disposition = FILE_OPEN,
1243 .create_options = cifs_create_options(cifs_sb, 0),
1245 .replay = !!(retries),
1248 rc = SMB2_open_init(tcon, server,
1249 &rqst[0], &oplock, &oparms, utf16_path);
1252 smb2_set_next_command(tcon, &rqst[0]);
1256 rqst[1].rq_iov = vars->si_iov;
1257 rqst[1].rq_nvec = 1;
1259 len = sizeof(*ea) + ea_name_len + ea_value_len + 1;
1260 ea = kzalloc(len, GFP_KERNEL);
1266 ea->ea_name_length = ea_name_len;
1267 ea->ea_value_length = cpu_to_le16(ea_value_len);
1268 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
1269 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
1274 rc = SMB2_set_info_init(tcon, server,
1275 &rqst[1], COMPOUND_FID,
1276 COMPOUND_FID, current->tgid,
1277 FILE_FULL_EA_INFORMATION,
1278 SMB2_O_INFO_FILE, 0, data, size);
1281 smb2_set_next_command(tcon, &rqst[1]);
1282 smb2_set_related(&rqst[1]);
1285 rqst[2].rq_iov = &vars->close_iov;
1286 rqst[2].rq_nvec = 1;
1287 rc = SMB2_close_init(tcon, server,
1288 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1291 smb2_set_related(&rqst[2]);
1294 smb2_set_replay(server, &rqst[0]);
1295 smb2_set_replay(server, &rqst[1]);
1296 smb2_set_replay(server, &rqst[2]);
1299 rc = compound_send_recv(xid, ses, server,
1301 resp_buftype, rsp_iov);
1302 /* no need to bump num_remote_opens because handle immediately closed */
1306 SMB2_open_free(&rqst[0]);
1307 SMB2_set_info_free(&rqst[1]);
1308 SMB2_close_free(&rqst[2]);
1309 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1310 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1311 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1316 if (is_replayable_error(rc) &&
1317 smb2_should_replay(tcon, &retries, &cur_sleep))
1325 smb2_can_echo(struct TCP_Server_Info *server)
1327 return server->echoes;
1331 smb2_clear_stats(struct cifs_tcon *tcon)
1335 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1336 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1337 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1342 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1344 seq_puts(m, "\n\tShare Capabilities:");
1345 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1346 seq_puts(m, " DFS,");
1347 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1348 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1349 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1350 seq_puts(m, " SCALEOUT,");
1351 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1352 seq_puts(m, " CLUSTER,");
1353 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1354 seq_puts(m, " ASYMMETRIC,");
1355 if (tcon->capabilities == 0)
1356 seq_puts(m, " None");
1357 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1358 seq_puts(m, " Aligned,");
1359 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1360 seq_puts(m, " Partition Aligned,");
1361 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1362 seq_puts(m, " SSD,");
1363 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1364 seq_puts(m, " TRIM-support,");
1366 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1367 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1368 if (tcon->perf_sector_size)
1369 seq_printf(m, "\tOptimal sector size: 0x%x",
1370 tcon->perf_sector_size);
1371 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1375 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1377 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1378 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1381 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1382 * totals (requests sent) since those SMBs are per-session not per tcon
1384 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1385 (long long)(tcon->bytes_read),
1386 (long long)(tcon->bytes_written));
1387 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1388 atomic_read(&tcon->num_local_opens),
1389 atomic_read(&tcon->num_remote_opens));
1390 seq_printf(m, "\nTreeConnects: %d total %d failed",
1391 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1392 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1393 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1394 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1395 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1396 seq_printf(m, "\nCreates: %d total %d failed",
1397 atomic_read(&sent[SMB2_CREATE_HE]),
1398 atomic_read(&failed[SMB2_CREATE_HE]));
1399 seq_printf(m, "\nCloses: %d total %d failed",
1400 atomic_read(&sent[SMB2_CLOSE_HE]),
1401 atomic_read(&failed[SMB2_CLOSE_HE]));
1402 seq_printf(m, "\nFlushes: %d total %d failed",
1403 atomic_read(&sent[SMB2_FLUSH_HE]),
1404 atomic_read(&failed[SMB2_FLUSH_HE]));
1405 seq_printf(m, "\nReads: %d total %d failed",
1406 atomic_read(&sent[SMB2_READ_HE]),
1407 atomic_read(&failed[SMB2_READ_HE]));
1408 seq_printf(m, "\nWrites: %d total %d failed",
1409 atomic_read(&sent[SMB2_WRITE_HE]),
1410 atomic_read(&failed[SMB2_WRITE_HE]));
1411 seq_printf(m, "\nLocks: %d total %d failed",
1412 atomic_read(&sent[SMB2_LOCK_HE]),
1413 atomic_read(&failed[SMB2_LOCK_HE]));
1414 seq_printf(m, "\nIOCTLs: %d total %d failed",
1415 atomic_read(&sent[SMB2_IOCTL_HE]),
1416 atomic_read(&failed[SMB2_IOCTL_HE]));
1417 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1418 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1419 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1420 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1421 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1422 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1423 seq_printf(m, "\nQueryInfos: %d total %d failed",
1424 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1425 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1426 seq_printf(m, "\nSetInfos: %d total %d failed",
1427 atomic_read(&sent[SMB2_SET_INFO_HE]),
1428 atomic_read(&failed[SMB2_SET_INFO_HE]));
1429 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1430 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1431 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1435 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1437 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1438 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1440 cfile->fid.persistent_fid = fid->persistent_fid;
1441 cfile->fid.volatile_fid = fid->volatile_fid;
1442 cfile->fid.access = fid->access;
1443 #ifdef CONFIG_CIFS_DEBUG2
1444 cfile->fid.mid = fid->mid;
1445 #endif /* CIFS_DEBUG2 */
1446 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1448 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1449 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1453 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1454 struct cifs_fid *fid)
1456 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1460 smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon,
1461 struct cifsFileInfo *cfile)
1463 struct smb2_file_network_open_info file_inf;
1464 struct inode *inode;
1467 rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid,
1468 cfile->fid.volatile_fid, &file_inf);
1472 inode = d_inode(cfile->dentry);
1474 spin_lock(&inode->i_lock);
1475 CIFS_I(inode)->time = jiffies;
1477 /* Creation time should not need to be updated on close */
1478 if (file_inf.LastWriteTime)
1479 inode_set_mtime_to_ts(inode,
1480 cifs_NTtimeToUnix(file_inf.LastWriteTime));
1481 if (file_inf.ChangeTime)
1482 inode_set_ctime_to_ts(inode,
1483 cifs_NTtimeToUnix(file_inf.ChangeTime));
1484 if (file_inf.LastAccessTime)
1485 inode_set_atime_to_ts(inode,
1486 cifs_NTtimeToUnix(file_inf.LastAccessTime));
1489 * i_blocks is not related to (i_size / i_blksize),
1490 * but instead 512 byte (2**9) size is required for
1491 * calculating num blocks.
1493 if (le64_to_cpu(file_inf.AllocationSize) > 4096)
1495 (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9;
1497 /* End of file and Attributes should not have to be updated on close */
1498 spin_unlock(&inode->i_lock);
1503 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1504 u64 persistent_fid, u64 volatile_fid,
1505 struct copychunk_ioctl *pcchunk)
1508 unsigned int ret_data_len;
1509 struct resume_key_req *res_key;
1511 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1512 FSCTL_SRV_REQUEST_RESUME_KEY, NULL, 0 /* no input */,
1513 CIFSMaxBufSize, (char **)&res_key, &ret_data_len);
1515 if (rc == -EOPNOTSUPP) {
1516 pr_warn_once("Server share %s does not support copy range\n", tcon->tree_name);
1517 goto req_res_key_exit;
1519 cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1520 goto req_res_key_exit;
1522 if (ret_data_len < sizeof(struct resume_key_req)) {
1523 cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n");
1525 goto req_res_key_exit;
1527 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1535 smb2_ioctl_query_info(const unsigned int xid,
1536 struct cifs_tcon *tcon,
1537 struct cifs_sb_info *cifs_sb,
1538 __le16 *path, int is_dir,
1541 struct smb2_compound_vars *vars;
1542 struct smb_rqst *rqst;
1543 struct kvec *rsp_iov;
1544 struct cifs_ses *ses = tcon->ses;
1545 struct TCP_Server_Info *server;
1546 char __user *arg = (char __user *)p;
1547 struct smb_query_info qi;
1548 struct smb_query_info __user *pqi;
1550 int flags = CIFS_CP_CREATE_CLOSE_OP;
1551 struct smb2_query_info_rsp *qi_rsp = NULL;
1552 struct smb2_ioctl_rsp *io_rsp = NULL;
1553 void *buffer = NULL;
1554 int resp_buftype[3];
1555 struct cifs_open_parms oparms;
1556 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1557 struct cifs_fid fid;
1558 unsigned int size[2];
1560 int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR;
1561 void (*free_req1_func)(struct smb_rqst *r);
1562 int retries = 0, cur_sleep = 1;
1565 /* reinitialize for possible replay */
1566 flags = CIFS_CP_CREATE_CLOSE_OP;
1567 oplock = SMB2_OPLOCK_LEVEL_NONE;
1568 server = cifs_pick_channel(ses);
1570 vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
1573 rqst = &vars->rqst[0];
1574 rsp_iov = &vars->rsp_iov[0];
1576 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1578 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info))) {
1582 if (qi.output_buffer_length > 1024) {
1587 if (!ses || !server) {
1592 if (smb3_encryption_required(tcon))
1593 flags |= CIFS_TRANSFORM_REQ;
1595 if (qi.output_buffer_length) {
1596 buffer = memdup_user(arg + sizeof(struct smb_query_info), qi.output_buffer_length);
1597 if (IS_ERR(buffer)) {
1598 rc = PTR_ERR(buffer);
1604 rqst[0].rq_iov = &vars->open_iov[0];
1605 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1607 oparms = (struct cifs_open_parms) {
1609 .disposition = FILE_OPEN,
1610 .create_options = cifs_create_options(cifs_sb, create_options),
1612 .replay = !!(retries),
1615 if (qi.flags & PASSTHRU_FSCTL) {
1616 switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1617 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1618 oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1620 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1621 oparms.desired_access = GENERIC_ALL;
1623 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1624 oparms.desired_access = GENERIC_READ;
1626 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1627 oparms.desired_access = GENERIC_WRITE;
1630 } else if (qi.flags & PASSTHRU_SET_INFO) {
1631 oparms.desired_access = GENERIC_WRITE;
1633 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1636 rc = SMB2_open_init(tcon, server,
1637 &rqst[0], &oplock, &oparms, path);
1639 goto free_output_buffer;
1640 smb2_set_next_command(tcon, &rqst[0]);
1643 if (qi.flags & PASSTHRU_FSCTL) {
1644 /* Can eventually relax perm check since server enforces too */
1645 if (!capable(CAP_SYS_ADMIN)) {
1649 rqst[1].rq_iov = &vars->io_iov[0];
1650 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1652 rc = SMB2_ioctl_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1653 qi.info_type, buffer, qi.output_buffer_length,
1654 CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1655 MAX_SMB2_CLOSE_RESPONSE_SIZE);
1656 free_req1_func = SMB2_ioctl_free;
1657 } else if (qi.flags == PASSTHRU_SET_INFO) {
1658 /* Can eventually relax perm check since server enforces too */
1659 if (!capable(CAP_SYS_ADMIN)) {
1663 if (qi.output_buffer_length < 8) {
1667 rqst[1].rq_iov = vars->si_iov;
1668 rqst[1].rq_nvec = 1;
1670 /* MS-FSCC 2.4.13 FileEndOfFileInformation */
1674 rc = SMB2_set_info_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1675 current->tgid, FILE_END_OF_FILE_INFORMATION,
1676 SMB2_O_INFO_FILE, 0, data, size);
1677 free_req1_func = SMB2_set_info_free;
1678 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1679 rqst[1].rq_iov = &vars->qi_iov;
1680 rqst[1].rq_nvec = 1;
1682 rc = SMB2_query_info_init(tcon, server,
1683 &rqst[1], COMPOUND_FID,
1684 COMPOUND_FID, qi.file_info_class,
1685 qi.info_type, qi.additional_information,
1686 qi.input_buffer_length,
1687 qi.output_buffer_length, buffer);
1688 free_req1_func = SMB2_query_info_free;
1689 } else { /* unknown flags */
1690 cifs_tcon_dbg(VFS, "Invalid passthru query flags: 0x%x\n",
1697 smb2_set_next_command(tcon, &rqst[1]);
1698 smb2_set_related(&rqst[1]);
1701 rqst[2].rq_iov = &vars->close_iov;
1702 rqst[2].rq_nvec = 1;
1704 rc = SMB2_close_init(tcon, server,
1705 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1708 smb2_set_related(&rqst[2]);
1711 smb2_set_replay(server, &rqst[0]);
1712 smb2_set_replay(server, &rqst[1]);
1713 smb2_set_replay(server, &rqst[2]);
1716 rc = compound_send_recv(xid, ses, server,
1718 resp_buftype, rsp_iov);
1722 /* No need to bump num_remote_opens since handle immediately closed */
1723 if (qi.flags & PASSTHRU_FSCTL) {
1724 pqi = (struct smb_query_info __user *)arg;
1725 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1726 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1727 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1728 if (qi.input_buffer_length > 0 &&
1729 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length
1730 > rsp_iov[1].iov_len) {
1735 if (copy_to_user(&pqi->input_buffer_length,
1736 &qi.input_buffer_length,
1737 sizeof(qi.input_buffer_length))) {
1742 if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1743 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1744 qi.input_buffer_length))
1747 pqi = (struct smb_query_info __user *)arg;
1748 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1749 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1750 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1751 if (copy_to_user(&pqi->input_buffer_length,
1752 &qi.input_buffer_length,
1753 sizeof(qi.input_buffer_length))) {
1758 if (copy_to_user(pqi + 1, qi_rsp->Buffer,
1759 qi.input_buffer_length))
1764 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1765 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1766 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1767 SMB2_close_free(&rqst[2]);
1769 free_req1_func(&rqst[1]);
1771 SMB2_open_free(&rqst[0]);
1777 if (is_replayable_error(rc) &&
1778 smb2_should_replay(tcon, &retries, &cur_sleep))
1785 smb2_copychunk_range(const unsigned int xid,
1786 struct cifsFileInfo *srcfile,
1787 struct cifsFileInfo *trgtfile, u64 src_off,
1788 u64 len, u64 dest_off)
1791 unsigned int ret_data_len;
1792 struct copychunk_ioctl *pcchunk;
1793 struct copychunk_ioctl_rsp *retbuf = NULL;
1794 struct cifs_tcon *tcon;
1795 int chunks_copied = 0;
1796 bool chunk_sizes_updated = false;
1797 ssize_t bytes_written, total_bytes_written = 0;
1799 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1800 if (pcchunk == NULL)
1803 cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
1804 /* Request a key from the server to identify the source of the copy */
1805 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1806 srcfile->fid.persistent_fid,
1807 srcfile->fid.volatile_fid, pcchunk);
1809 /* Note: request_res_key sets res_key null only if rc !=0 */
1813 /* For now array only one chunk long, will make more flexible later */
1814 pcchunk->ChunkCount = cpu_to_le32(1);
1815 pcchunk->Reserved = 0;
1816 pcchunk->Reserved2 = 0;
1818 tcon = tlink_tcon(trgtfile->tlink);
1820 trace_smb3_copychunk_enter(xid, srcfile->fid.volatile_fid,
1821 trgtfile->fid.volatile_fid, tcon->tid,
1822 tcon->ses->Suid, src_off, dest_off, len);
1825 pcchunk->SourceOffset = cpu_to_le64(src_off);
1826 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1828 cpu_to_le32(min_t(u64, len, tcon->max_bytes_chunk));
1830 /* Request server copy to target from src identified by key */
1833 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1834 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1835 (char *)pcchunk, sizeof(struct copychunk_ioctl),
1836 CIFSMaxBufSize, (char **)&retbuf, &ret_data_len);
1839 sizeof(struct copychunk_ioctl_rsp)) {
1840 cifs_tcon_dbg(VFS, "Invalid cchunk response size\n");
1844 if (retbuf->TotalBytesWritten == 0) {
1845 cifs_dbg(FYI, "no bytes copied\n");
1850 * Check if server claimed to write more than we asked
1852 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1853 le32_to_cpu(pcchunk->Length)) {
1854 cifs_tcon_dbg(VFS, "Invalid copy chunk response\n");
1858 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1859 cifs_tcon_dbg(VFS, "Invalid num chunks written\n");
1865 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1866 src_off += bytes_written;
1867 dest_off += bytes_written;
1868 len -= bytes_written;
1869 total_bytes_written += bytes_written;
1871 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1872 le32_to_cpu(retbuf->ChunksWritten),
1873 le32_to_cpu(retbuf->ChunkBytesWritten),
1875 trace_smb3_copychunk_done(xid, srcfile->fid.volatile_fid,
1876 trgtfile->fid.volatile_fid, tcon->tid,
1877 tcon->ses->Suid, src_off, dest_off, len);
1878 } else if (rc == -EINVAL) {
1879 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1882 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1883 le32_to_cpu(retbuf->ChunksWritten),
1884 le32_to_cpu(retbuf->ChunkBytesWritten),
1885 le32_to_cpu(retbuf->TotalBytesWritten));
1888 * Check if this is the first request using these sizes,
1889 * (ie check if copy succeed once with original sizes
1890 * and check if the server gave us different sizes after
1891 * we already updated max sizes on previous request).
1892 * if not then why is the server returning an error now
1894 if ((chunks_copied != 0) || chunk_sizes_updated)
1897 /* Check that server is not asking us to grow size */
1898 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1899 tcon->max_bytes_chunk)
1900 tcon->max_bytes_chunk =
1901 le32_to_cpu(retbuf->ChunkBytesWritten);
1903 goto cchunk_out; /* server gave us bogus size */
1905 /* No need to change MaxChunks since already set to 1 */
1906 chunk_sizes_updated = true;
1917 return total_bytes_written;
1921 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1922 struct cifs_fid *fid)
1924 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1928 smb2_read_data_offset(char *buf)
1930 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1932 return rsp->DataOffset;
1936 smb2_read_data_length(char *buf, bool in_remaining)
1938 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1941 return le32_to_cpu(rsp->DataRemaining);
1943 return le32_to_cpu(rsp->DataLength);
1948 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1949 struct cifs_io_parms *parms, unsigned int *bytes_read,
1950 char **buf, int *buf_type)
1952 parms->persistent_fid = pfid->persistent_fid;
1953 parms->volatile_fid = pfid->volatile_fid;
1954 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1958 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1959 struct cifs_io_parms *parms, unsigned int *written,
1960 struct kvec *iov, unsigned long nr_segs)
1963 parms->persistent_fid = pfid->persistent_fid;
1964 parms->volatile_fid = pfid->volatile_fid;
1965 return SMB2_write(xid, parms, written, iov, nr_segs);
1968 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1969 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1970 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1972 struct cifsInodeInfo *cifsi;
1975 cifsi = CIFS_I(inode);
1977 /* if file already sparse don't bother setting sparse again */
1978 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1979 return true; /* already sparse */
1981 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1982 return true; /* already not sparse */
1985 * Can't check for sparse support on share the usual way via the
1986 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1987 * since Samba server doesn't set the flag on the share, yet
1988 * supports the set sparse FSCTL and returns sparse correctly
1989 * in the file attributes. If we fail setting sparse though we
1990 * mark that server does not support sparse files for this share
1991 * to avoid repeatedly sending the unsupported fsctl to server
1992 * if the file is repeatedly extended.
1994 if (tcon->broken_sparse_sup)
1997 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1998 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1999 &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
2001 tcon->broken_sparse_sup = true;
2002 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
2007 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
2009 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
2015 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
2016 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
2018 struct inode *inode;
2021 * If extending file more than one page make sparse. Many Linux fs
2022 * make files sparse by default when extending via ftruncate
2024 inode = d_inode(cfile->dentry);
2026 if (!set_alloc && (size > inode->i_size + 8192)) {
2027 __u8 set_sparse = 1;
2029 /* whether set sparse succeeds or not, extend the file */
2030 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
2033 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
2034 cfile->fid.volatile_fid, cfile->pid, size);
2038 smb2_duplicate_extents(const unsigned int xid,
2039 struct cifsFileInfo *srcfile,
2040 struct cifsFileInfo *trgtfile, u64 src_off,
2041 u64 len, u64 dest_off)
2044 unsigned int ret_data_len;
2045 struct inode *inode;
2046 struct duplicate_extents_to_file dup_ext_buf;
2047 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
2049 /* server fileays advertise duplicate extent support with this flag */
2050 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
2051 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
2054 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
2055 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
2056 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
2057 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
2058 dup_ext_buf.ByteCount = cpu_to_le64(len);
2059 cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
2060 src_off, dest_off, len);
2061 trace_smb3_clone_enter(xid, srcfile->fid.volatile_fid,
2062 trgtfile->fid.volatile_fid, tcon->tid,
2063 tcon->ses->Suid, src_off, dest_off, len);
2064 inode = d_inode(trgtfile->dentry);
2065 if (inode->i_size < dest_off + len) {
2066 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
2068 goto duplicate_extents_out;
2071 * Although also could set plausible allocation size (i_blocks)
2072 * here in addition to setting the file size, in reflink
2073 * it is likely that the target file is sparse. Its allocation
2074 * size will be queried on next revalidate, but it is important
2075 * to make sure that file's cached size is updated immediately
2077 netfs_resize_file(netfs_inode(inode), dest_off + len, true);
2078 cifs_setsize(inode, dest_off + len);
2080 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
2081 trgtfile->fid.volatile_fid,
2082 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
2083 (char *)&dup_ext_buf,
2084 sizeof(struct duplicate_extents_to_file),
2085 CIFSMaxBufSize, NULL,
2088 if (ret_data_len > 0)
2089 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
2091 duplicate_extents_out:
2093 trace_smb3_clone_err(xid, srcfile->fid.volatile_fid,
2094 trgtfile->fid.volatile_fid,
2095 tcon->tid, tcon->ses->Suid, src_off,
2098 trace_smb3_clone_done(xid, srcfile->fid.volatile_fid,
2099 trgtfile->fid.volatile_fid, tcon->tid,
2100 tcon->ses->Suid, src_off, dest_off, len);
2105 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
2106 struct cifsFileInfo *cfile)
2108 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
2109 cfile->fid.volatile_fid);
2113 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
2114 struct cifsFileInfo *cfile)
2116 struct fsctl_set_integrity_information_req integr_info;
2117 unsigned int ret_data_len;
2119 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
2120 integr_info.Flags = 0;
2121 integr_info.Reserved = 0;
2123 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2124 cfile->fid.volatile_fid,
2125 FSCTL_SET_INTEGRITY_INFORMATION,
2126 (char *)&integr_info,
2127 sizeof(struct fsctl_set_integrity_information_req),
2128 CIFSMaxBufSize, NULL,
2133 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
2134 #define GMT_TOKEN_SIZE 50
2136 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
2139 * Input buffer contains (empty) struct smb_snapshot array with size filled in
2140 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
2143 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
2144 struct cifsFileInfo *cfile, void __user *ioc_buf)
2146 char *retbuf = NULL;
2147 unsigned int ret_data_len = 0;
2149 u32 max_response_size;
2150 struct smb_snapshot_array snapshot_in;
2153 * On the first query to enumerate the list of snapshots available
2154 * for this volume the buffer begins with 0 (number of snapshots
2155 * which can be returned is zero since at that point we do not know
2156 * how big the buffer needs to be). On the second query,
2157 * it (ret_data_len) is set to number of snapshots so we can
2158 * know to set the maximum response size larger (see below).
2160 if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
2164 * Note that for snapshot queries that servers like Azure expect that
2165 * the first query be minimal size (and just used to get the number/size
2166 * of previous versions) so response size must be specified as EXACTLY
2167 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
2170 if (ret_data_len == 0)
2171 max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
2173 max_response_size = CIFSMaxBufSize;
2175 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2176 cfile->fid.volatile_fid,
2177 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
2178 NULL, 0 /* no input data */, max_response_size,
2181 cifs_dbg(FYI, "enum snapshots ioctl returned %d and ret buflen is %d\n",
2186 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
2188 if (copy_from_user(&snapshot_in, ioc_buf,
2189 sizeof(struct smb_snapshot_array))) {
2196 * Check for min size, ie not large enough to fit even one GMT
2197 * token (snapshot). On the first ioctl some users may pass in
2198 * smaller size (or zero) to simply get the size of the array
2199 * so the user space caller can allocate sufficient memory
2200 * and retry the ioctl again with larger array size sufficient
2201 * to hold all of the snapshot GMT tokens on the second try.
2203 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
2204 ret_data_len = sizeof(struct smb_snapshot_array);
2207 * We return struct SRV_SNAPSHOT_ARRAY, followed by
2208 * the snapshot array (of 50 byte GMT tokens) each
2209 * representing an available previous version of the data
2211 if (ret_data_len > (snapshot_in.snapshot_array_size +
2212 sizeof(struct smb_snapshot_array)))
2213 ret_data_len = snapshot_in.snapshot_array_size +
2214 sizeof(struct smb_snapshot_array);
2216 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
2227 smb3_notify(const unsigned int xid, struct file *pfile,
2228 void __user *ioc_buf, bool return_changes)
2230 struct smb3_notify_info notify;
2231 struct smb3_notify_info __user *pnotify_buf;
2232 struct dentry *dentry = pfile->f_path.dentry;
2233 struct inode *inode = file_inode(pfile);
2234 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2235 struct cifs_open_parms oparms;
2236 struct cifs_fid fid;
2237 struct cifs_tcon *tcon;
2238 const unsigned char *path;
2239 char *returned_ioctl_info = NULL;
2240 void *page = alloc_dentry_path();
2241 __le16 *utf16_path = NULL;
2242 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2246 path = build_path_from_dentry(dentry, page);
2252 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2253 if (utf16_path == NULL) {
2258 if (return_changes) {
2259 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify_info))) {
2264 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify))) {
2268 notify.data_len = 0;
2271 tcon = cifs_sb_master_tcon(cifs_sb);
2272 oparms = (struct cifs_open_parms) {
2275 .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
2276 .disposition = FILE_OPEN,
2277 .create_options = cifs_create_options(cifs_sb, 0),
2281 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
2286 rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid,
2287 notify.watch_tree, notify.completion_filter,
2288 notify.data_len, &returned_ioctl_info, &ret_len);
2290 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2292 cifs_dbg(FYI, "change notify for path %s rc %d\n", path, rc);
2293 if (return_changes && (ret_len > 0) && (notify.data_len > 0)) {
2294 if (ret_len > notify.data_len)
2295 ret_len = notify.data_len;
2296 pnotify_buf = (struct smb3_notify_info __user *)ioc_buf;
2297 if (copy_to_user(pnotify_buf->notify_data, returned_ioctl_info, ret_len))
2299 else if (copy_to_user(&pnotify_buf->data_len, &ret_len, sizeof(ret_len)))
2302 kfree(returned_ioctl_info);
2304 free_dentry_path(page);
2310 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
2311 const char *path, struct cifs_sb_info *cifs_sb,
2312 struct cifs_fid *fid, __u16 search_flags,
2313 struct cifs_search_info *srch_inf)
2316 struct smb_rqst rqst[2];
2317 struct kvec rsp_iov[2];
2318 int resp_buftype[2];
2319 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2320 struct kvec qd_iov[SMB2_QUERY_DIRECTORY_IOV_SIZE];
2322 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2323 struct cifs_open_parms oparms;
2324 struct smb2_query_directory_rsp *qd_rsp = NULL;
2325 struct smb2_create_rsp *op_rsp = NULL;
2326 struct TCP_Server_Info *server;
2327 int retries = 0, cur_sleep = 1;
2330 /* reinitialize for possible replay */
2332 oplock = SMB2_OPLOCK_LEVEL_NONE;
2333 server = cifs_pick_channel(tcon->ses);
2335 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2339 if (smb3_encryption_required(tcon))
2340 flags |= CIFS_TRANSFORM_REQ;
2342 memset(rqst, 0, sizeof(rqst));
2343 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
2344 memset(rsp_iov, 0, sizeof(rsp_iov));
2347 memset(&open_iov, 0, sizeof(open_iov));
2348 rqst[0].rq_iov = open_iov;
2349 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2351 oparms = (struct cifs_open_parms) {
2354 .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
2355 .disposition = FILE_OPEN,
2356 .create_options = cifs_create_options(cifs_sb, 0),
2358 .replay = !!(retries),
2361 rc = SMB2_open_init(tcon, server,
2362 &rqst[0], &oplock, &oparms, utf16_path);
2365 smb2_set_next_command(tcon, &rqst[0]);
2367 /* Query directory */
2368 srch_inf->entries_in_buffer = 0;
2369 srch_inf->index_of_last_entry = 2;
2371 memset(&qd_iov, 0, sizeof(qd_iov));
2372 rqst[1].rq_iov = qd_iov;
2373 rqst[1].rq_nvec = SMB2_QUERY_DIRECTORY_IOV_SIZE;
2375 rc = SMB2_query_directory_init(xid, tcon, server,
2377 COMPOUND_FID, COMPOUND_FID,
2378 0, srch_inf->info_level);
2382 smb2_set_related(&rqst[1]);
2385 smb2_set_replay(server, &rqst[0]);
2386 smb2_set_replay(server, &rqst[1]);
2389 rc = compound_send_recv(xid, tcon->ses, server,
2391 resp_buftype, rsp_iov);
2393 /* If the open failed there is nothing to do */
2394 op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
2395 if (op_rsp == NULL || op_rsp->hdr.Status != STATUS_SUCCESS) {
2396 cifs_dbg(FYI, "query_dir_first: open failed rc=%d\n", rc);
2399 fid->persistent_fid = op_rsp->PersistentFileId;
2400 fid->volatile_fid = op_rsp->VolatileFileId;
2402 /* Anything else than ENODATA means a genuine error */
2403 if (rc && rc != -ENODATA) {
2404 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2405 cifs_dbg(FYI, "query_dir_first: query directory failed rc=%d\n", rc);
2406 trace_smb3_query_dir_err(xid, fid->persistent_fid,
2407 tcon->tid, tcon->ses->Suid, 0, 0, rc);
2411 atomic_inc(&tcon->num_remote_opens);
2413 qd_rsp = (struct smb2_query_directory_rsp *)rsp_iov[1].iov_base;
2414 if (qd_rsp->hdr.Status == STATUS_NO_MORE_FILES) {
2415 trace_smb3_query_dir_done(xid, fid->persistent_fid,
2416 tcon->tid, tcon->ses->Suid, 0, 0);
2417 srch_inf->endOfSearch = true;
2422 rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1],
2425 trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid,
2426 tcon->ses->Suid, 0, 0, rc);
2429 resp_buftype[1] = CIFS_NO_BUFFER;
2431 trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid,
2432 tcon->ses->Suid, 0, srch_inf->entries_in_buffer);
2436 SMB2_open_free(&rqst[0]);
2437 SMB2_query_directory_free(&rqst[1]);
2438 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2439 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2441 if (is_replayable_error(rc) &&
2442 smb2_should_replay(tcon, &retries, &cur_sleep))
2449 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
2450 struct cifs_fid *fid, __u16 search_flags,
2451 struct cifs_search_info *srch_inf)
2453 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
2454 fid->volatile_fid, 0, srch_inf);
2458 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
2459 struct cifs_fid *fid)
2461 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2465 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2466 * the number of credits and return true. Otherwise - return false.
2469 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
2471 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2472 int scredits, in_flight;
2474 if (shdr->Status != STATUS_PENDING)
2477 if (shdr->CreditRequest) {
2478 spin_lock(&server->req_lock);
2479 server->credits += le16_to_cpu(shdr->CreditRequest);
2480 scredits = server->credits;
2481 in_flight = server->in_flight;
2482 spin_unlock(&server->req_lock);
2483 wake_up(&server->request_q);
2485 trace_smb3_pend_credits(server->CurrentMid,
2486 server->conn_id, server->hostname, scredits,
2487 le16_to_cpu(shdr->CreditRequest), in_flight);
2488 cifs_dbg(FYI, "%s: status pending add %u credits total=%d\n",
2489 __func__, le16_to_cpu(shdr->CreditRequest), scredits);
2496 smb2_is_session_expired(char *buf)
2498 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2500 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
2501 shdr->Status != STATUS_USER_SESSION_DELETED)
2504 trace_smb3_ses_expired(le32_to_cpu(shdr->Id.SyncId.TreeId),
2505 le64_to_cpu(shdr->SessionId),
2506 le16_to_cpu(shdr->Command),
2507 le64_to_cpu(shdr->MessageId));
2508 cifs_dbg(FYI, "Session expired or deleted\n");
2514 smb2_is_status_io_timeout(char *buf)
2516 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2518 if (shdr->Status == STATUS_IO_TIMEOUT)
2525 smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server)
2527 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2528 struct TCP_Server_Info *pserver;
2529 struct cifs_ses *ses;
2530 struct cifs_tcon *tcon;
2532 if (shdr->Status != STATUS_NETWORK_NAME_DELETED)
2535 /* If server is a channel, select the primary channel */
2536 pserver = SERVER_IS_CHAN(server) ? server->primary_server : server;
2538 spin_lock(&cifs_tcp_ses_lock);
2539 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
2540 if (cifs_ses_exiting(ses))
2542 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
2543 if (tcon->tid == le32_to_cpu(shdr->Id.SyncId.TreeId)) {
2544 spin_lock(&tcon->tc_lock);
2545 tcon->need_reconnect = true;
2546 spin_unlock(&tcon->tc_lock);
2547 spin_unlock(&cifs_tcp_ses_lock);
2548 pr_warn_once("Server share %s deleted.\n",
2554 spin_unlock(&cifs_tcp_ses_lock);
2560 smb2_oplock_response(struct cifs_tcon *tcon, __u64 persistent_fid,
2561 __u64 volatile_fid, __u16 net_fid, struct cifsInodeInfo *cinode)
2563 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
2564 return SMB2_lease_break(0, tcon, cinode->lease_key,
2565 smb2_get_lease_state(cinode));
2567 return SMB2_oplock_break(0, tcon, persistent_fid, volatile_fid,
2568 CIFS_CACHE_READ(cinode) ? 1 : 0);
2572 smb2_set_replay(struct TCP_Server_Info *server, struct smb_rqst *rqst)
2574 struct smb2_hdr *shdr;
2576 if (server->dialect < SMB30_PROT_ID)
2579 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2581 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2584 shdr->Flags |= SMB2_FLAGS_REPLAY_OPERATION;
2588 smb2_set_related(struct smb_rqst *rqst)
2590 struct smb2_hdr *shdr;
2592 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2594 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2597 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2600 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
2603 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
2605 struct smb2_hdr *shdr;
2606 struct cifs_ses *ses = tcon->ses;
2607 struct TCP_Server_Info *server = ses->server;
2608 unsigned long len = smb_rqst_len(server, rqst);
2611 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2613 cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2617 /* SMB headers in a compound are 8 byte aligned. */
2618 if (!IS_ALIGNED(len, 8)) {
2619 num_padding = 8 - (len & 7);
2620 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2621 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2625 shdr->NextCommand = cpu_to_le32(len);
2629 * helper function for exponential backoff and check if replayable
2631 bool smb2_should_replay(struct cifs_tcon *tcon,
2635 if (!pretries || !pcur_sleep)
2638 if (tcon->retry || (*pretries)++ < tcon->ses->server->retrans) {
2639 msleep(*pcur_sleep);
2640 (*pcur_sleep) = ((*pcur_sleep) << 1);
2641 if ((*pcur_sleep) > CIFS_MAX_SLEEP)
2642 (*pcur_sleep) = CIFS_MAX_SLEEP;
2650 * Passes the query info response back to the caller on success.
2651 * Caller need to free this with free_rsp_buf().
2654 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2655 const char *path, u32 desired_access,
2656 u32 class, u32 type, u32 output_len,
2657 struct kvec *rsp, int *buftype,
2658 struct cifs_sb_info *cifs_sb)
2660 struct smb2_compound_vars *vars;
2661 struct cifs_ses *ses = tcon->ses;
2662 struct TCP_Server_Info *server;
2663 int flags = CIFS_CP_CREATE_CLOSE_OP;
2664 struct smb_rqst *rqst;
2665 int resp_buftype[3];
2666 struct kvec *rsp_iov;
2667 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2668 struct cifs_open_parms oparms;
2669 struct cifs_fid fid;
2672 struct cached_fid *cfid = NULL;
2673 int retries = 0, cur_sleep = 1;
2676 /* reinitialize for possible replay */
2677 flags = CIFS_CP_CREATE_CLOSE_OP;
2678 oplock = SMB2_OPLOCK_LEVEL_NONE;
2679 server = cifs_pick_channel(ses);
2683 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2687 if (smb3_encryption_required(tcon))
2688 flags |= CIFS_TRANSFORM_REQ;
2690 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2691 vars = kzalloc(sizeof(*vars), GFP_KERNEL);
2697 rsp_iov = vars->rsp_iov;
2700 * We can only call this for things we know are directories.
2702 if (!strcmp(path, ""))
2703 open_cached_dir(xid, tcon, path, cifs_sb, false,
2704 &cfid); /* cfid null if open dir failed */
2706 rqst[0].rq_iov = vars->open_iov;
2707 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2709 oparms = (struct cifs_open_parms) {
2712 .desired_access = desired_access,
2713 .disposition = FILE_OPEN,
2714 .create_options = cifs_create_options(cifs_sb, 0),
2716 .replay = !!(retries),
2719 rc = SMB2_open_init(tcon, server,
2720 &rqst[0], &oplock, &oparms, utf16_path);
2723 smb2_set_next_command(tcon, &rqst[0]);
2725 rqst[1].rq_iov = &vars->qi_iov;
2726 rqst[1].rq_nvec = 1;
2729 rc = SMB2_query_info_init(tcon, server,
2731 cfid->fid.persistent_fid,
2732 cfid->fid.volatile_fid,
2737 rc = SMB2_query_info_init(tcon, server,
2748 smb2_set_next_command(tcon, &rqst[1]);
2749 smb2_set_related(&rqst[1]);
2752 rqst[2].rq_iov = &vars->close_iov;
2753 rqst[2].rq_nvec = 1;
2755 rc = SMB2_close_init(tcon, server,
2756 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2759 smb2_set_related(&rqst[2]);
2763 smb2_set_replay(server, &rqst[0]);
2764 smb2_set_replay(server, &rqst[2]);
2766 smb2_set_replay(server, &rqst[1]);
2770 rc = compound_send_recv(xid, ses, server,
2772 &resp_buftype[1], &rsp_iov[1]);
2774 rc = compound_send_recv(xid, ses, server,
2776 resp_buftype, rsp_iov);
2779 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2780 if (rc == -EREMCHG) {
2781 tcon->need_reconnect = true;
2782 pr_warn_once("server share %s deleted\n",
2788 *buftype = resp_buftype[1];
2791 SMB2_open_free(&rqst[0]);
2792 SMB2_query_info_free(&rqst[1]);
2793 SMB2_close_free(&rqst[2]);
2794 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2795 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2797 close_cached_dir(cfid);
2802 if (is_replayable_error(rc) &&
2803 smb2_should_replay(tcon, &retries, &cur_sleep))
2810 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2811 const char *path, struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2813 struct smb2_query_info_rsp *rsp;
2814 struct smb2_fs_full_size_info *info = NULL;
2815 struct kvec rsp_iov = {NULL, 0};
2816 int buftype = CIFS_NO_BUFFER;
2820 rc = smb2_query_info_compound(xid, tcon, path,
2821 FILE_READ_ATTRIBUTES,
2822 FS_FULL_SIZE_INFORMATION,
2823 SMB2_O_INFO_FILESYSTEM,
2824 sizeof(struct smb2_fs_full_size_info),
2825 &rsp_iov, &buftype, cifs_sb);
2829 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2830 buf->f_type = SMB2_SUPER_MAGIC;
2831 info = (struct smb2_fs_full_size_info *)(
2832 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2833 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2834 le32_to_cpu(rsp->OutputBufferLength),
2836 sizeof(struct smb2_fs_full_size_info));
2838 smb2_copy_fs_info_to_kstatfs(info, buf);
2841 trace_smb3_qfs_done(xid, tcon->tid, tcon->ses->Suid, tcon->tree_name, rc);
2842 free_rsp_buf(buftype, rsp_iov.iov_base);
2847 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2848 const char *path, struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2851 __le16 *utf16_path = NULL;
2852 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2853 struct cifs_open_parms oparms;
2854 struct cifs_fid fid;
2856 if (!tcon->posix_extensions)
2857 return smb2_queryfs(xid, tcon, path, cifs_sb, buf);
2859 oparms = (struct cifs_open_parms) {
2862 .desired_access = FILE_READ_ATTRIBUTES,
2863 .disposition = FILE_OPEN,
2864 .create_options = cifs_create_options(cifs_sb, 0),
2868 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2869 if (utf16_path == NULL)
2872 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
2878 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2879 fid.volatile_fid, buf);
2880 buf->f_type = SMB2_SUPER_MAGIC;
2881 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2886 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2888 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2889 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2893 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2894 __u64 length, __u32 type, int lock, int unlock, bool wait)
2896 if (unlock && !lock)
2897 type = SMB2_LOCKFLAG_UNLOCK;
2898 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2899 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2900 current->tgid, length, offset, type, wait);
2904 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2906 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2910 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2912 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2916 smb2_new_lease_key(struct cifs_fid *fid)
2918 generate_random_uuid(fid->lease_key);
2922 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2923 const char *search_name,
2924 struct dfs_info3_param **target_nodes,
2925 unsigned int *num_of_nodes,
2926 const struct nls_table *nls_codepage, int remap)
2929 __le16 *utf16_path = NULL;
2930 int utf16_path_len = 0;
2931 struct cifs_tcon *tcon;
2932 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2933 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2934 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2937 cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name);
2940 * Try to use the IPC tcon, otherwise just use any
2942 tcon = ses->tcon_ipc;
2944 spin_lock(&cifs_tcp_ses_lock);
2945 tcon = list_first_entry_or_null(&ses->tcon_list,
2950 trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count,
2951 netfs_trace_tcon_ref_get_dfs_refer);
2953 spin_unlock(&cifs_tcp_ses_lock);
2957 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2963 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2965 nls_codepage, remap);
2971 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2972 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2978 /* Highest DFS referral version understood */
2979 dfs_req->MaxReferralLevel = DFS_VERSION;
2981 /* Path to resolve in an UTF-16 null-terminated string */
2982 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2985 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2986 FSCTL_DFS_GET_REFERRALS,
2987 (char *)dfs_req, dfs_req_size, CIFSMaxBufSize,
2988 (char **)&dfs_rsp, &dfs_rsp_size);
2989 if (fatal_signal_pending(current)) {
2993 if (!is_retryable_error(rc) || retry_once++)
2995 usleep_range(512, 2048);
2998 if (!rc && !dfs_rsp)
3001 if (!is_retryable_error(rc) && rc != -ENOENT && rc != -EOPNOTSUPP)
3002 cifs_tcon_dbg(FYI, "%s: ioctl error: rc=%d\n", __func__, rc);
3006 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
3007 num_of_nodes, target_nodes,
3008 nls_codepage, remap, search_name,
3009 true /* is_unicode */);
3011 cifs_tcon_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc);
3016 if (tcon && !tcon->ipc) {
3017 /* ipc tcons are not refcounted */
3018 spin_lock(&cifs_tcp_ses_lock);
3020 trace_smb3_tcon_ref(tcon->debug_id, tcon->tc_count,
3021 netfs_trace_tcon_ref_dec_dfs_refer);
3022 /* tc_count can never go negative */
3023 WARN_ON(tcon->tc_count < 0);
3024 spin_unlock(&cifs_tcp_ses_lock);
3032 static struct smb_ntsd *
3033 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
3034 const struct cifs_fid *cifsfid, u32 *pacllen, u32 info)
3036 struct smb_ntsd *pntsd = NULL;
3038 int rc = -EOPNOTSUPP;
3039 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3042 return ERR_CAST(tlink);
3045 cifs_dbg(FYI, "trying to get acl\n");
3047 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
3048 cifsfid->volatile_fid, (void **)&pntsd, pacllen,
3052 cifs_put_tlink(tlink);
3054 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3061 static struct smb_ntsd *
3062 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
3063 const char *path, u32 *pacllen, u32 info)
3065 struct smb_ntsd *pntsd = NULL;
3066 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3069 struct cifs_tcon *tcon;
3070 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3071 struct cifs_fid fid;
3072 struct cifs_open_parms oparms;
3075 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
3077 return ERR_CAST(tlink);
3079 tcon = tlink_tcon(tlink);
3082 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3089 oparms = (struct cifs_open_parms) {
3092 .desired_access = READ_CONTROL,
3093 .disposition = FILE_OPEN,
3095 * When querying an ACL, even if the file is a symlink
3096 * we want to open the source not the target, and so
3097 * the protocol requires that the client specify this
3098 * flag when opening a reparse point
3100 .create_options = cifs_create_options(cifs_sb, 0) |
3105 if (info & SACL_SECINFO)
3106 oparms.desired_access |= SYSTEM_SECURITY;
3108 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
3112 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3113 fid.volatile_fid, (void **)&pntsd, pacllen,
3115 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3118 cifs_put_tlink(tlink);
3121 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3128 set_smb2_acl(struct smb_ntsd *pnntsd, __u32 acllen,
3129 struct inode *inode, const char *path, int aclflag)
3131 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3133 int rc, access_flags = 0;
3134 struct cifs_tcon *tcon;
3135 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
3136 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3137 struct cifs_fid fid;
3138 struct cifs_open_parms oparms;
3141 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
3143 return PTR_ERR(tlink);
3145 tcon = tlink_tcon(tlink);
3148 if (aclflag & CIFS_ACL_OWNER || aclflag & CIFS_ACL_GROUP)
3149 access_flags |= WRITE_OWNER;
3150 if (aclflag & CIFS_ACL_SACL)
3151 access_flags |= SYSTEM_SECURITY;
3152 if (aclflag & CIFS_ACL_DACL)
3153 access_flags |= WRITE_DAC;
3155 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3162 oparms = (struct cifs_open_parms) {
3164 .desired_access = access_flags,
3165 .create_options = cifs_create_options(cifs_sb, 0),
3166 .disposition = FILE_OPEN,
3171 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
3175 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3176 fid.volatile_fid, pnntsd, acllen, aclflag);
3177 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3180 cifs_put_tlink(tlink);
3185 /* Retrieve an ACL from the server */
3186 static struct smb_ntsd *
3187 get_smb2_acl(struct cifs_sb_info *cifs_sb,
3188 struct inode *inode, const char *path,
3189 u32 *pacllen, u32 info)
3191 struct smb_ntsd *pntsd = NULL;
3192 struct cifsFileInfo *open_file = NULL;
3194 if (inode && !(info & SACL_SECINFO))
3195 open_file = find_readable_file(CIFS_I(inode), true);
3196 if (!open_file || (info & SACL_SECINFO))
3197 return get_smb2_acl_by_path(cifs_sb, path, pacllen, info);
3199 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen, info);
3200 cifsFileInfo_put(open_file);
3204 static long smb3_zero_data(struct file *file, struct cifs_tcon *tcon,
3205 loff_t offset, loff_t len, unsigned int xid)
3207 struct cifsFileInfo *cfile = file->private_data;
3208 struct file_zero_data_information fsctl_buf;
3210 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3212 fsctl_buf.FileOffset = cpu_to_le64(offset);
3213 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3215 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3216 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3218 sizeof(struct file_zero_data_information),
3222 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3223 unsigned long long offset, unsigned long long len,
3226 struct cifs_ses *ses = tcon->ses;
3227 struct inode *inode = file_inode(file);
3228 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3229 struct cifsFileInfo *cfile = file->private_data;
3230 struct netfs_inode *ictx = netfs_inode(inode);
3231 unsigned long long i_size, new_size, remote_size;
3237 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3238 ses->Suid, offset, len);
3241 filemap_invalidate_lock(inode->i_mapping);
3243 i_size = i_size_read(inode);
3244 remote_size = ictx->remote_i_size;
3245 if (offset + len >= remote_size && offset < i_size) {
3246 unsigned long long top = umin(offset + len, i_size);
3248 rc = filemap_write_and_wait_range(inode->i_mapping, offset, top - 1);
3250 goto zero_range_exit;
3254 * We zero the range through ioctl, so we need remove the page caches
3255 * first, otherwise the data may be inconsistent with the server.
3257 truncate_pagecache_range(inode, offset, offset + len - 1);
3259 /* if file not oplocked can't be sure whether asking to extend size */
3261 if (keep_size == false && !CIFS_CACHE_READ(cifsi))
3262 goto zero_range_exit;
3264 rc = smb3_zero_data(file, tcon, offset, len, xid);
3266 goto zero_range_exit;
3269 * do we also need to change the size of the file?
3271 new_size = offset + len;
3272 if (keep_size == false && (unsigned long long)i_size_read(inode) < new_size) {
3273 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3274 cfile->fid.volatile_fid, cfile->pid, new_size);
3276 truncate_setsize(inode, new_size);
3277 netfs_resize_file(&cifsi->netfs, new_size, true);
3278 if (offset < cifsi->netfs.zero_point)
3279 cifsi->netfs.zero_point = offset;
3280 fscache_resize_cookie(cifs_inode_cookie(inode), new_size);
3285 filemap_invalidate_unlock(inode->i_mapping);
3286 inode_unlock(inode);
3289 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
3290 ses->Suid, offset, len, rc);
3292 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
3293 ses->Suid, offset, len);
3297 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
3298 loff_t offset, loff_t len)
3300 struct inode *inode = file_inode(file);
3301 struct cifsFileInfo *cfile = file->private_data;
3302 struct file_zero_data_information fsctl_buf;
3303 unsigned long long end = offset + len, i_size, remote_i_size;
3306 __u8 set_sparse = 1;
3311 /* Need to make file sparse, if not already, before freeing range. */
3312 /* Consider adding equivalent for compressed since it could also work */
3313 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
3318 filemap_invalidate_lock(inode->i_mapping);
3320 * We implement the punch hole through ioctl, so we need remove the page
3321 * caches first, otherwise the data may be inconsistent with the server.
3323 truncate_pagecache_range(inode, offset, offset + len - 1);
3325 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3327 fsctl_buf.FileOffset = cpu_to_le64(offset);
3328 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3330 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3331 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3333 sizeof(struct file_zero_data_information),
3334 CIFSMaxBufSize, NULL, NULL);
3339 /* If there's dirty data in the buffer that would extend the EOF if it
3340 * were written, then we need to move the EOF marker over to the lower
3341 * of the high end of the hole and the proposed EOF. The problem is
3342 * that we locally hole-punch the tail of the dirty data, the proposed
3343 * EOF update will end up in the wrong place.
3345 i_size = i_size_read(inode);
3346 remote_i_size = netfs_inode(inode)->remote_i_size;
3347 if (end > remote_i_size && i_size > remote_i_size) {
3348 unsigned long long extend_to = umin(end, i_size);
3349 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3350 cfile->fid.volatile_fid, cfile->pid, extend_to);
3352 netfs_inode(inode)->remote_i_size = extend_to;
3356 filemap_invalidate_unlock(inode->i_mapping);
3358 inode_unlock(inode);
3363 static int smb3_simple_fallocate_write_range(unsigned int xid,
3364 struct cifs_tcon *tcon,
3365 struct cifsFileInfo *cfile,
3366 loff_t off, loff_t len,
3369 struct cifs_io_parms io_parms = {0};
3374 io_parms.netfid = cfile->fid.netfid;
3375 io_parms.pid = current->tgid;
3376 io_parms.tcon = tcon;
3377 io_parms.persistent_fid = cfile->fid.persistent_fid;
3378 io_parms.volatile_fid = cfile->fid.volatile_fid;
3381 io_parms.offset = off;
3382 io_parms.length = len;
3383 if (io_parms.length > SMB2_MAX_BUFFER_SIZE)
3384 io_parms.length = SMB2_MAX_BUFFER_SIZE;
3385 /* iov[0] is reserved for smb header */
3386 iov[1].iov_base = buf;
3387 iov[1].iov_len = io_parms.length;
3388 rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
3400 static int smb3_simple_fallocate_range(unsigned int xid,
3401 struct cifs_tcon *tcon,
3402 struct cifsFileInfo *cfile,
3403 loff_t off, loff_t len)
3405 struct file_allocated_range_buffer in_data, *out_data = NULL, *tmp_data;
3411 in_data.file_offset = cpu_to_le64(off);
3412 in_data.length = cpu_to_le64(len);
3413 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3414 cfile->fid.volatile_fid,
3415 FSCTL_QUERY_ALLOCATED_RANGES,
3416 (char *)&in_data, sizeof(in_data),
3417 1024 * sizeof(struct file_allocated_range_buffer),
3418 (char **)&out_data, &out_data_len);
3422 buf = kzalloc(1024 * 1024, GFP_KERNEL);
3428 tmp_data = out_data;
3431 * The rest of the region is unmapped so write it all.
3433 if (out_data_len == 0) {
3434 rc = smb3_simple_fallocate_write_range(xid, tcon,
3435 cfile, off, len, buf);
3439 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3444 if (off < le64_to_cpu(tmp_data->file_offset)) {
3446 * We are at a hole. Write until the end of the region
3447 * or until the next allocated data,
3448 * whichever comes next.
3450 l = le64_to_cpu(tmp_data->file_offset) - off;
3453 rc = smb3_simple_fallocate_write_range(xid, tcon,
3454 cfile, off, l, buf);
3463 * We are at a section of allocated data, just skip forward
3464 * until the end of the data or the end of the region
3465 * we are supposed to fallocate, whichever comes first.
3467 l = le64_to_cpu(tmp_data->length);
3473 tmp_data = &tmp_data[1];
3474 out_data_len -= sizeof(struct file_allocated_range_buffer);
3484 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3485 loff_t off, loff_t len, bool keep_size)
3487 struct inode *inode;
3488 struct cifsInodeInfo *cifsi;
3489 struct cifsFileInfo *cfile = file->private_data;
3490 long rc = -EOPNOTSUPP;
3496 inode = d_inode(cfile->dentry);
3497 cifsi = CIFS_I(inode);
3499 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3500 tcon->ses->Suid, off, len);
3501 /* if file not oplocked can't be sure whether asking to extend size */
3502 if (!CIFS_CACHE_READ(cifsi))
3503 if (keep_size == false) {
3504 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3505 tcon->tid, tcon->ses->Suid, off, len, rc);
3511 * Extending the file
3513 if ((keep_size == false) && i_size_read(inode) < off + len) {
3514 rc = inode_newsize_ok(inode, off + len);
3518 if (cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)
3519 smb2_set_sparse(xid, tcon, cfile, inode, false);
3521 new_eof = off + len;
3522 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3523 cfile->fid.volatile_fid, cfile->pid, new_eof);
3525 netfs_resize_file(&cifsi->netfs, new_eof, true);
3526 cifs_setsize(inode, new_eof);
3527 cifs_truncate_page(inode->i_mapping, inode->i_size);
3528 truncate_setsize(inode, new_eof);
3534 * Files are non-sparse by default so falloc may be a no-op
3535 * Must check if file sparse. If not sparse, and since we are not
3536 * extending then no need to do anything since file already allocated
3538 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
3543 if (keep_size == true) {
3545 * We can not preallocate pages beyond the end of the file
3548 if (off >= i_size_read(inode)) {
3553 * For fallocates that are partially beyond the end of file,
3554 * clamp len so we only fallocate up to the end of file.
3556 if (off + len > i_size_read(inode)) {
3557 len = i_size_read(inode) - off;
3561 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3563 * At this point, we are trying to fallocate an internal
3564 * regions of a sparse file. Since smb2 does not have a
3565 * fallocate command we have two options on how to emulate this.
3566 * We can either turn the entire file to become non-sparse
3567 * which we only do if the fallocate is for virtually
3568 * the whole file, or we can overwrite the region with zeroes
3569 * using SMB2_write, which could be prohibitevly expensive
3573 * We are only trying to fallocate a small region so
3574 * just write it with zero.
3576 if (len <= 1024 * 1024) {
3577 rc = smb3_simple_fallocate_range(xid, tcon, cfile,
3583 * Check if falloc starts within first few pages of file
3584 * and ends within a few pages of the end of file to
3585 * ensure that most of file is being forced to be
3586 * fallocated now. If so then setting whole file sparse
3587 * ie potentially making a few extra pages at the beginning
3588 * or end of the file non-sparse via set_sparse is harmless.
3590 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
3596 smb2_set_sparse(xid, tcon, cfile, inode, false);
3601 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3602 tcon->ses->Suid, off, len, rc);
3604 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3605 tcon->ses->Suid, off, len);
3611 static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
3612 loff_t off, loff_t len)
3616 struct inode *inode = file_inode(file);
3617 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3618 struct cifsFileInfo *cfile = file->private_data;
3619 struct netfs_inode *ictx = &cifsi->netfs;
3620 loff_t old_eof, new_eof;
3626 old_eof = i_size_read(inode);
3627 if ((off >= old_eof) ||
3628 off + len >= old_eof) {
3633 filemap_invalidate_lock(inode->i_mapping);
3634 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof - 1);
3638 truncate_pagecache_range(inode, off, old_eof);
3639 ictx->zero_point = old_eof;
3641 rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
3642 old_eof - off - len, off);
3646 new_eof = old_eof - len;
3647 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3648 cfile->fid.volatile_fid, cfile->pid, new_eof);
3654 truncate_setsize(inode, new_eof);
3655 netfs_resize_file(&cifsi->netfs, new_eof, true);
3656 ictx->zero_point = new_eof;
3657 fscache_resize_cookie(cifs_inode_cookie(inode), new_eof);
3659 filemap_invalidate_unlock(inode->i_mapping);
3661 inode_unlock(inode);
3666 static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
3667 loff_t off, loff_t len)
3671 struct cifsFileInfo *cfile = file->private_data;
3672 struct inode *inode = file_inode(file);
3673 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3674 __u64 count, old_eof, new_eof;
3680 old_eof = i_size_read(inode);
3681 if (off >= old_eof) {
3686 count = old_eof - off;
3687 new_eof = old_eof + len;
3689 filemap_invalidate_lock(inode->i_mapping);
3690 rc = filemap_write_and_wait_range(inode->i_mapping, off, new_eof - 1);
3693 truncate_pagecache_range(inode, off, old_eof);
3695 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3696 cfile->fid.volatile_fid, cfile->pid, new_eof);
3700 truncate_setsize(inode, new_eof);
3701 netfs_resize_file(&cifsi->netfs, i_size_read(inode), true);
3702 fscache_resize_cookie(cifs_inode_cookie(inode), i_size_read(inode));
3704 rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len);
3707 cifsi->netfs.zero_point = new_eof;
3709 rc = smb3_zero_data(file, tcon, off, len, xid);
3715 filemap_invalidate_unlock(inode->i_mapping);
3717 inode_unlock(inode);
3722 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3724 struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3725 struct cifsInodeInfo *cifsi;
3726 struct inode *inode;
3728 struct file_allocated_range_buffer in_data, *out_data = NULL;
3732 if (whence != SEEK_HOLE && whence != SEEK_DATA)
3733 return generic_file_llseek(file, offset, whence);
3735 inode = d_inode(cfile->dentry);
3736 cifsi = CIFS_I(inode);
3738 if (offset < 0 || offset >= i_size_read(inode))
3743 * We need to be sure that all dirty pages are written as they
3744 * might fill holes on the server.
3745 * Note that we also MUST flush any written pages since at least
3746 * some servers (Windows2016) will not reflect recent writes in
3747 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3749 wrcfile = find_writable_file(cifsi, FIND_WR_ANY);
3751 filemap_write_and_wait(inode->i_mapping);
3752 smb2_flush_file(xid, tcon, &wrcfile->fid);
3753 cifsFileInfo_put(wrcfile);
3756 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3757 if (whence == SEEK_HOLE)
3758 offset = i_size_read(inode);
3762 in_data.file_offset = cpu_to_le64(offset);
3763 in_data.length = cpu_to_le64(i_size_read(inode));
3765 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3766 cfile->fid.volatile_fid,
3767 FSCTL_QUERY_ALLOCATED_RANGES,
3768 (char *)&in_data, sizeof(in_data),
3769 sizeof(struct file_allocated_range_buffer),
3770 (char **)&out_data, &out_data_len);
3776 if (whence == SEEK_HOLE && out_data_len == 0)
3779 if (whence == SEEK_DATA && out_data_len == 0) {
3784 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3788 if (whence == SEEK_DATA) {
3789 offset = le64_to_cpu(out_data->file_offset);
3792 if (offset < le64_to_cpu(out_data->file_offset))
3795 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3801 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3806 static int smb3_fiemap(struct cifs_tcon *tcon,
3807 struct cifsFileInfo *cfile,
3808 struct fiemap_extent_info *fei, u64 start, u64 len)
3811 struct file_allocated_range_buffer in_data, *out_data;
3813 int i, num, rc, flags, last_blob;
3816 rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0);
3822 in_data.file_offset = cpu_to_le64(start);
3823 in_data.length = cpu_to_le64(len);
3825 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3826 cfile->fid.volatile_fid,
3827 FSCTL_QUERY_ALLOCATED_RANGES,
3828 (char *)&in_data, sizeof(in_data),
3829 1024 * sizeof(struct file_allocated_range_buffer),
3830 (char **)&out_data, &out_data_len);
3839 if (out_data_len && out_data_len < sizeof(struct file_allocated_range_buffer)) {
3843 if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3848 num = out_data_len / sizeof(struct file_allocated_range_buffer);
3849 for (i = 0; i < num; i++) {
3851 if (i == num - 1 && last_blob)
3852 flags |= FIEMAP_EXTENT_LAST;
3854 rc = fiemap_fill_next_extent(fei,
3855 le64_to_cpu(out_data[i].file_offset),
3856 le64_to_cpu(out_data[i].file_offset),
3857 le64_to_cpu(out_data[i].length),
3868 next = le64_to_cpu(out_data[num - 1].file_offset) +
3869 le64_to_cpu(out_data[num - 1].length);
3870 len = len - (next - start);
3881 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
3882 loff_t off, loff_t len)
3884 /* KEEP_SIZE already checked for by do_fallocate */
3885 if (mode & FALLOC_FL_PUNCH_HOLE)
3886 return smb3_punch_hole(file, tcon, off, len);
3887 else if (mode & FALLOC_FL_ZERO_RANGE) {
3888 if (mode & FALLOC_FL_KEEP_SIZE)
3889 return smb3_zero_range(file, tcon, off, len, true);
3890 return smb3_zero_range(file, tcon, off, len, false);
3891 } else if (mode == FALLOC_FL_KEEP_SIZE)
3892 return smb3_simple_falloc(file, tcon, off, len, true);
3893 else if (mode == FALLOC_FL_COLLAPSE_RANGE)
3894 return smb3_collapse_range(file, tcon, off, len);
3895 else if (mode == FALLOC_FL_INSERT_RANGE)
3896 return smb3_insert_range(file, tcon, off, len);
3898 return smb3_simple_falloc(file, tcon, off, len, false);
3904 smb2_downgrade_oplock(struct TCP_Server_Info *server,
3905 struct cifsInodeInfo *cinode, __u32 oplock,
3906 unsigned int epoch, bool *purge_cache)
3908 server->ops->set_oplock_level(cinode, oplock, 0, NULL);
3912 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3913 unsigned int epoch, bool *purge_cache);
3916 smb3_downgrade_oplock(struct TCP_Server_Info *server,
3917 struct cifsInodeInfo *cinode, __u32 oplock,
3918 unsigned int epoch, bool *purge_cache)
3920 unsigned int old_state = cinode->oplock;
3921 unsigned int old_epoch = cinode->epoch;
3922 unsigned int new_state;
3924 if (epoch > old_epoch) {
3925 smb21_set_oplock_level(cinode, oplock, 0, NULL);
3926 cinode->epoch = epoch;
3929 new_state = cinode->oplock;
3930 *purge_cache = false;
3932 if ((old_state & CIFS_CACHE_READ_FLG) != 0 &&
3933 (new_state & CIFS_CACHE_READ_FLG) == 0)
3934 *purge_cache = true;
3935 else if (old_state == new_state && (epoch - old_epoch > 1))
3936 *purge_cache = true;
3940 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3941 unsigned int epoch, bool *purge_cache)
3944 cinode->lease_granted = false;
3945 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3947 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
3948 cinode->oplock = CIFS_CACHE_RHW_FLG;
3949 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
3950 &cinode->netfs.inode);
3951 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
3952 cinode->oplock = CIFS_CACHE_RW_FLG;
3953 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
3954 &cinode->netfs.inode);
3955 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
3956 cinode->oplock = CIFS_CACHE_READ_FLG;
3957 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
3958 &cinode->netfs.inode);
3964 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3965 unsigned int epoch, bool *purge_cache)
3967 char message[5] = {0};
3968 unsigned int new_oplock = 0;
3971 cinode->lease_granted = true;
3972 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3975 /* Check if the server granted an oplock rather than a lease */
3976 if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE)
3977 return smb2_set_oplock_level(cinode, oplock, epoch,
3980 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
3981 new_oplock |= CIFS_CACHE_READ_FLG;
3982 strcat(message, "R");
3984 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
3985 new_oplock |= CIFS_CACHE_HANDLE_FLG;
3986 strcat(message, "H");
3988 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
3989 new_oplock |= CIFS_CACHE_WRITE_FLG;
3990 strcat(message, "W");
3993 strscpy(message, "None");
3995 cinode->oplock = new_oplock;
3996 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
3997 &cinode->netfs.inode);
4001 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4002 unsigned int epoch, bool *purge_cache)
4004 unsigned int old_oplock = cinode->oplock;
4006 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
4009 *purge_cache = false;
4010 if (old_oplock == CIFS_CACHE_READ_FLG) {
4011 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
4012 (epoch - cinode->epoch > 0))
4013 *purge_cache = true;
4014 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4015 (epoch - cinode->epoch > 1))
4016 *purge_cache = true;
4017 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4018 (epoch - cinode->epoch > 1))
4019 *purge_cache = true;
4020 else if (cinode->oplock == 0 &&
4021 (epoch - cinode->epoch > 0))
4022 *purge_cache = true;
4023 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
4024 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4025 (epoch - cinode->epoch > 0))
4026 *purge_cache = true;
4027 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4028 (epoch - cinode->epoch > 1))
4029 *purge_cache = true;
4031 cinode->epoch = epoch;
4035 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
4037 smb2_is_read_op(__u32 oplock)
4039 return oplock == SMB2_OPLOCK_LEVEL_II;
4041 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
4044 smb21_is_read_op(__u32 oplock)
4046 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
4047 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
4051 map_oplock_to_lease(u8 oplock)
4053 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4054 return SMB2_LEASE_WRITE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE;
4055 else if (oplock == SMB2_OPLOCK_LEVEL_II)
4056 return SMB2_LEASE_READ_CACHING_LE | SMB2_LEASE_HANDLE_CACHING_LE;
4057 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
4058 return SMB2_LEASE_HANDLE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE |
4059 SMB2_LEASE_WRITE_CACHING_LE;
4064 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
4066 struct create_lease *buf;
4068 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
4072 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4073 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4075 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4076 (struct create_lease, lcontext));
4077 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
4078 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4079 (struct create_lease, Name));
4080 buf->ccontext.NameLength = cpu_to_le16(4);
4081 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4090 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
4092 struct create_lease_v2 *buf;
4094 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
4098 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4099 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4101 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4102 (struct create_lease_v2, lcontext));
4103 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
4104 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4105 (struct create_lease_v2, Name));
4106 buf->ccontext.NameLength = cpu_to_le16(4);
4107 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4116 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4118 struct create_lease *lc = (struct create_lease *)buf;
4120 *epoch = 0; /* not used */
4121 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4122 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4123 return le32_to_cpu(lc->lcontext.LeaseState);
4127 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4129 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
4131 *epoch = le16_to_cpu(lc->lcontext.Epoch);
4132 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4133 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4135 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
4136 return le32_to_cpu(lc->lcontext.LeaseState);
4140 smb2_wp_retry_size(struct inode *inode)
4142 return min_t(unsigned int, CIFS_SB(inode->i_sb)->ctx->wsize,
4143 SMB2_MAX_BUFFER_SIZE);
4147 smb2_dir_needs_close(struct cifsFileInfo *cfile)
4149 return !cfile->invalidHandle;
4153 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
4154 struct smb_rqst *old_rq, __le16 cipher_type)
4156 struct smb2_hdr *shdr =
4157 (struct smb2_hdr *)old_rq->rq_iov[0].iov_base;
4159 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
4160 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
4161 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
4162 tr_hdr->Flags = cpu_to_le16(0x01);
4163 if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4164 (cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4165 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4167 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4168 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
4171 static void *smb2_aead_req_alloc(struct crypto_aead *tfm, const struct smb_rqst *rqst,
4172 int num_rqst, const u8 *sig, u8 **iv,
4173 struct aead_request **req, struct sg_table *sgt,
4174 unsigned int *num_sgs, size_t *sensitive_size)
4176 unsigned int req_size = sizeof(**req) + crypto_aead_reqsize(tfm);
4177 unsigned int iv_size = crypto_aead_ivsize(tfm);
4181 *num_sgs = cifs_get_num_sgs(rqst, num_rqst, sig);
4182 if (IS_ERR_VALUE((long)(int)*num_sgs))
4183 return ERR_PTR(*num_sgs);
4186 len += crypto_aead_alignmask(tfm) & ~(crypto_tfm_ctx_alignment() - 1);
4187 len = ALIGN(len, crypto_tfm_ctx_alignment());
4189 len = ALIGN(len, __alignof__(struct scatterlist));
4190 len += array_size(*num_sgs, sizeof(struct scatterlist));
4191 *sensitive_size = len;
4193 p = kvzalloc(len, GFP_NOFS);
4195 return ERR_PTR(-ENOMEM);
4197 *iv = (u8 *)PTR_ALIGN(p, crypto_aead_alignmask(tfm) + 1);
4198 *req = (struct aead_request *)PTR_ALIGN(*iv + iv_size,
4199 crypto_tfm_ctx_alignment());
4200 sgt->sgl = (struct scatterlist *)PTR_ALIGN((u8 *)*req + req_size,
4201 __alignof__(struct scatterlist));
4205 static void *smb2_get_aead_req(struct crypto_aead *tfm, struct smb_rqst *rqst,
4206 int num_rqst, const u8 *sig, u8 **iv,
4207 struct aead_request **req, struct scatterlist **sgl,
4208 size_t *sensitive_size)
4210 struct sg_table sgtable = {};
4211 unsigned int skip, num_sgs, i, j;
4215 p = smb2_aead_req_alloc(tfm, rqst, num_rqst, sig, iv, req, &sgtable,
4216 &num_sgs, sensitive_size);
4220 sg_init_marker(sgtable.sgl, num_sgs);
4223 * The first rqst has a transform header where the
4224 * first 20 bytes are not part of the encrypted blob.
4228 for (i = 0; i < num_rqst; i++) {
4229 struct iov_iter *iter = &rqst[i].rq_iter;
4230 size_t count = iov_iter_count(iter);
4232 for (j = 0; j < rqst[i].rq_nvec; j++) {
4233 cifs_sg_set_buf(&sgtable,
4234 rqst[i].rq_iov[j].iov_base + skip,
4235 rqst[i].rq_iov[j].iov_len - skip);
4237 /* See the above comment on the 'skip' assignment */
4240 sgtable.orig_nents = sgtable.nents;
4242 rc = extract_iter_to_sg(iter, count, &sgtable,
4243 num_sgs - sgtable.nents, 0);
4244 iov_iter_revert(iter, rc);
4245 sgtable.orig_nents = sgtable.nents;
4248 cifs_sg_set_buf(&sgtable, sig, SMB2_SIGNATURE_SIZE);
4249 sg_mark_end(&sgtable.sgl[sgtable.nents - 1]);
4255 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
4257 struct TCP_Server_Info *pserver;
4258 struct cifs_ses *ses;
4261 /* If server is a channel, select the primary channel */
4262 pserver = SERVER_IS_CHAN(server) ? server->primary_server : server;
4264 spin_lock(&cifs_tcp_ses_lock);
4265 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
4266 if (ses->Suid == ses_id) {
4267 spin_lock(&ses->ses_lock);
4268 ses_enc_key = enc ? ses->smb3encryptionkey :
4269 ses->smb3decryptionkey;
4270 memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE);
4271 spin_unlock(&ses->ses_lock);
4272 spin_unlock(&cifs_tcp_ses_lock);
4276 spin_unlock(&cifs_tcp_ses_lock);
4278 trace_smb3_ses_not_found(ses_id);
4283 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
4284 * iov[0] - transform header (associate data),
4285 * iov[1-N] - SMB2 header and pages - data to encrypt.
4286 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4290 crypt_message(struct TCP_Server_Info *server, int num_rqst,
4291 struct smb_rqst *rqst, int enc, struct crypto_aead *tfm)
4293 struct smb2_transform_hdr *tr_hdr =
4294 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
4295 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
4297 struct scatterlist *sg;
4298 u8 sign[SMB2_SIGNATURE_SIZE] = {};
4299 u8 key[SMB3_ENC_DEC_KEY_SIZE];
4300 struct aead_request *req;
4302 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4304 size_t sensitive_size;
4306 rc = smb2_get_enc_key(server, le64_to_cpu(tr_hdr->SessionId), enc, key);
4308 cifs_server_dbg(FYI, "%s: Could not get %scryption key. sid: 0x%llx\n", __func__,
4309 enc ? "en" : "de", le64_to_cpu(tr_hdr->SessionId));
4313 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
4314 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4315 rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
4317 rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE);
4320 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
4324 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
4326 cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
4330 creq = smb2_get_aead_req(tfm, rqst, num_rqst, sign, &iv, &req, &sg,
4333 return PTR_ERR(creq);
4336 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
4337 crypt_len += SMB2_SIGNATURE_SIZE;
4340 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4341 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4342 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4345 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4348 aead_request_set_tfm(req, tfm);
4349 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
4350 aead_request_set_ad(req, assoc_data_len);
4352 rc = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
4355 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
4357 kvfree_sensitive(creq, sensitive_size);
4362 * Clear a read buffer, discarding the folios which have the 1st mark set.
4364 static void cifs_clear_folioq_buffer(struct folio_queue *buffer)
4366 struct folio_queue *folioq;
4368 while ((folioq = buffer)) {
4369 for (int s = 0; s < folioq_count(folioq); s++)
4370 if (folioq_is_marked(folioq, s))
4371 folio_put(folioq_folio(folioq, s));
4372 buffer = folioq->next;
4378 * Allocate buffer space into a folio queue.
4380 static struct folio_queue *cifs_alloc_folioq_buffer(ssize_t size)
4382 struct folio_queue *buffer = NULL, *tail = NULL, *p;
4383 struct folio *folio;
4387 if (!tail || folioq_full(tail)) {
4388 p = kmalloc(sizeof(*p), GFP_NOFS);
4401 folio = folio_alloc(GFP_KERNEL|__GFP_HIGHMEM, 0);
4405 slot = folioq_append_mark(tail, folio);
4406 size -= folioq_folio_size(tail, slot);
4412 cifs_clear_folioq_buffer(buffer);
4417 * Copy data from an iterator to the folios in a folio queue buffer.
4419 static bool cifs_copy_iter_to_folioq(struct iov_iter *iter, size_t size,
4420 struct folio_queue *buffer)
4422 for (; buffer; buffer = buffer->next) {
4423 for (int s = 0; s < folioq_count(buffer); s++) {
4424 struct folio *folio = folioq_folio(buffer, s);
4425 size_t part = folioq_folio_size(buffer, s);
4427 part = umin(part, size);
4429 if (copy_folio_from_iter(folio, 0, part, iter) != part)
4438 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
4440 for (int i = 0; i < num_rqst; i++)
4441 cifs_clear_folioq_buffer(rqst[i].rq_buffer);
4445 * This function will initialize new_rq and encrypt the content.
4446 * The first entry, new_rq[0], only contains a single iov which contains
4447 * a smb2_transform_hdr and is pre-allocated by the caller.
4448 * This function then populates new_rq[1+] with the content from olq_rq[0+].
4450 * The end result is an array of smb_rqst structures where the first structure
4451 * only contains a single iov for the transform header which we then can pass
4452 * to crypt_message().
4454 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4455 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
4458 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
4459 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
4461 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
4462 unsigned int orig_len = 0;
4465 for (int i = 1; i < num_rqst; i++) {
4466 struct smb_rqst *old = &old_rq[i - 1];
4467 struct smb_rqst *new = &new_rq[i];
4468 struct folio_queue *buffer;
4469 size_t size = iov_iter_count(&old->rq_iter);
4471 orig_len += smb_rqst_len(server, old);
4472 new->rq_iov = old->rq_iov;
4473 new->rq_nvec = old->rq_nvec;
4476 buffer = cifs_alloc_folioq_buffer(size);
4480 new->rq_buffer = buffer;
4481 iov_iter_folio_queue(&new->rq_iter, ITER_SOURCE,
4482 buffer, 0, 0, size);
4484 if (!cifs_copy_iter_to_folioq(&old->rq_iter, size, buffer)) {
4491 /* fill the 1st iov with a transform header */
4492 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
4494 rc = crypt_message(server, num_rqst, new_rq, 1, server->secmech.enc);
4495 cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
4502 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
4507 smb3_is_transform_hdr(void *buf)
4509 struct smb2_transform_hdr *trhdr = buf;
4511 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
4515 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
4516 unsigned int buf_data_size, struct iov_iter *iter,
4519 struct crypto_aead *tfm;
4520 struct smb_rqst rqst = {NULL};
4522 size_t iter_size = 0;
4525 iov[0].iov_base = buf;
4526 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
4527 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
4528 iov[1].iov_len = buf_data_size;
4533 rqst.rq_iter = *iter;
4534 iter_size = iov_iter_count(iter);
4538 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4539 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4540 tfm = crypto_alloc_aead("gcm(aes)", 0, 0);
4542 tfm = crypto_alloc_aead("ccm(aes)", 0, 0);
4545 cifs_server_dbg(VFS, "%s: Failed alloc decrypt TFM, rc=%d\n", __func__, rc);
4550 if (unlikely(!server->secmech.dec))
4553 tfm = server->secmech.dec;
4556 rc = crypt_message(server, 1, &rqst, 0, tfm);
4557 cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
4560 crypto_free_aead(tfm);
4565 memmove(buf, iov[1].iov_base, buf_data_size);
4568 server->total_read = buf_data_size + iter_size;
4574 cifs_copy_folioq_to_iter(struct folio_queue *folioq, size_t data_size,
4575 size_t skip, struct iov_iter *iter)
4577 for (; folioq; folioq = folioq->next) {
4578 for (int s = 0; s < folioq_count(folioq); s++) {
4579 struct folio *folio = folioq_folio(folioq, s);
4580 size_t fsize = folio_size(folio);
4581 size_t n, len = umin(fsize - skip, data_size);
4583 n = copy_folio_to_iter(folio, skip, len, iter);
4585 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
4597 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
4598 char *buf, unsigned int buf_len, struct folio_queue *buffer,
4599 unsigned int buffer_len, bool is_offloaded)
4601 unsigned int data_offset;
4602 unsigned int data_len;
4603 unsigned int cur_off;
4604 unsigned int cur_page_idx;
4605 unsigned int pad_len;
4606 struct cifs_io_subrequest *rdata = mid->callback_data;
4607 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
4609 bool use_rdma_mr = false;
4611 if (shdr->Command != SMB2_READ) {
4612 cifs_server_dbg(VFS, "only big read responses are supported\n");
4616 if (server->ops->is_session_expired &&
4617 server->ops->is_session_expired(buf)) {
4619 cifs_reconnect(server, true);
4623 if (server->ops->is_status_pending &&
4624 server->ops->is_status_pending(buf, server))
4627 /* set up first two iov to get credits */
4628 rdata->iov[0].iov_base = buf;
4629 rdata->iov[0].iov_len = 0;
4630 rdata->iov[1].iov_base = buf;
4631 rdata->iov[1].iov_len =
4632 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
4633 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
4634 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
4635 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
4636 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
4638 rdata->result = server->ops->map_error(buf, true);
4639 if (rdata->result != 0) {
4640 cifs_dbg(FYI, "%s: server returned error %d\n",
4641 __func__, rdata->result);
4642 /* normal error on read response */
4644 mid->mid_state = MID_RESPONSE_RECEIVED;
4646 dequeue_mid(mid, false);
4650 data_offset = server->ops->read_data_offset(buf);
4651 #ifdef CONFIG_CIFS_SMB_DIRECT
4652 use_rdma_mr = rdata->mr;
4654 data_len = server->ops->read_data_length(buf, use_rdma_mr);
4656 if (data_offset < server->vals->read_rsp_size) {
4658 * win2k8 sometimes sends an offset of 0 when the read
4659 * is beyond the EOF. Treat it as if the data starts just after
4662 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
4663 __func__, data_offset);
4664 data_offset = server->vals->read_rsp_size;
4665 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
4666 /* data_offset is beyond the end of smallbuf */
4667 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
4668 __func__, data_offset);
4669 rdata->result = -EIO;
4671 mid->mid_state = MID_RESPONSE_MALFORMED;
4673 dequeue_mid(mid, rdata->result);
4677 pad_len = data_offset - server->vals->read_rsp_size;
4679 if (buf_len <= data_offset) {
4680 /* read response payload is in pages */
4681 cur_page_idx = pad_len / PAGE_SIZE;
4682 cur_off = pad_len % PAGE_SIZE;
4684 if (cur_page_idx != 0) {
4685 /* data offset is beyond the 1st page of response */
4686 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
4687 __func__, data_offset);
4688 rdata->result = -EIO;
4690 mid->mid_state = MID_RESPONSE_MALFORMED;
4692 dequeue_mid(mid, rdata->result);
4696 if (data_len > buffer_len - pad_len) {
4697 /* data_len is corrupt -- discard frame */
4698 rdata->result = -EIO;
4700 mid->mid_state = MID_RESPONSE_MALFORMED;
4702 dequeue_mid(mid, rdata->result);
4706 /* Copy the data to the output I/O iterator. */
4707 rdata->result = cifs_copy_folioq_to_iter(buffer, buffer_len,
4708 cur_off, &rdata->subreq.io_iter);
4709 if (rdata->result != 0) {
4711 mid->mid_state = MID_RESPONSE_MALFORMED;
4713 dequeue_mid(mid, rdata->result);
4716 rdata->got_bytes = buffer_len;
4718 } else if (buf_len >= data_offset + data_len) {
4719 /* read response payload is in buf */
4720 WARN_ONCE(buffer, "read data can be either in buf or in buffer");
4721 length = copy_to_iter(buf + data_offset, data_len, &rdata->subreq.io_iter);
4724 rdata->got_bytes = data_len;
4726 /* read response payload cannot be in both buf and pages */
4727 WARN_ONCE(1, "buf can not contain only a part of read data");
4728 rdata->result = -EIO;
4730 mid->mid_state = MID_RESPONSE_MALFORMED;
4732 dequeue_mid(mid, rdata->result);
4737 mid->mid_state = MID_RESPONSE_RECEIVED;
4739 dequeue_mid(mid, false);
4743 struct smb2_decrypt_work {
4744 struct work_struct decrypt;
4745 struct TCP_Server_Info *server;
4746 struct folio_queue *buffer;
4752 static void smb2_decrypt_offload(struct work_struct *work)
4754 struct smb2_decrypt_work *dw = container_of(work,
4755 struct smb2_decrypt_work, decrypt);
4757 struct mid_q_entry *mid;
4758 struct iov_iter iter;
4760 iov_iter_folio_queue(&iter, ITER_DEST, dw->buffer, 0, 0, dw->len);
4761 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
4764 cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
4768 dw->server->lstrp = jiffies;
4769 mid = smb2_find_dequeue_mid(dw->server, dw->buf);
4771 cifs_dbg(FYI, "mid not found\n");
4773 mid->decrypted = true;
4774 rc = handle_read_data(dw->server, mid, dw->buf,
4775 dw->server->vals->read_rsp_size,
4776 dw->buffer, dw->len,
4779 #ifdef CONFIG_CIFS_STATS2
4780 mid->when_received = jiffies;
4782 if (dw->server->ops->is_network_name_deleted)
4783 dw->server->ops->is_network_name_deleted(dw->buf,
4788 spin_lock(&dw->server->srv_lock);
4789 if (dw->server->tcpStatus == CifsNeedReconnect) {
4790 spin_lock(&dw->server->mid_lock);
4791 mid->mid_state = MID_RETRY_NEEDED;
4792 spin_unlock(&dw->server->mid_lock);
4793 spin_unlock(&dw->server->srv_lock);
4796 spin_lock(&dw->server->mid_lock);
4797 mid->mid_state = MID_REQUEST_SUBMITTED;
4798 mid->mid_flags &= ~(MID_DELETED);
4799 list_add_tail(&mid->qhead,
4800 &dw->server->pending_mid_q);
4801 spin_unlock(&dw->server->mid_lock);
4802 spin_unlock(&dw->server->srv_lock);
4809 cifs_clear_folioq_buffer(dw->buffer);
4810 cifs_small_buf_release(dw->buf);
4816 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
4819 char *buf = server->smallbuf;
4820 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4821 struct iov_iter iter;
4823 unsigned int buflen = server->pdu_size;
4825 struct smb2_decrypt_work *dw;
4827 dw = kzalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL);
4830 INIT_WORK(&dw->decrypt, smb2_decrypt_offload);
4831 dw->server = server;
4834 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
4835 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
4837 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
4840 server->total_read += rc;
4842 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
4843 server->vals->read_rsp_size;
4845 len = round_up(dw->len, PAGE_SIZE);
4848 dw->buffer = cifs_alloc_folioq_buffer(len);
4852 iov_iter_folio_queue(&iter, ITER_DEST, dw->buffer, 0, 0, len);
4854 /* Read the data into the buffer and clear excess bufferage. */
4855 rc = cifs_read_iter_from_socket(server, &iter, dw->len);
4859 server->total_read += rc;
4861 struct iov_iter tmp = iter;
4863 iov_iter_advance(&tmp, rc);
4864 iov_iter_zero(len - rc, &tmp);
4866 iov_iter_truncate(&iter, dw->len);
4868 rc = cifs_discard_remaining_data(server);
4873 * For large reads, offload to different thread for better performance,
4874 * use more cores decrypting which can be expensive
4877 if ((server->min_offload) && (server->in_flight > 1) &&
4878 (server->pdu_size >= server->min_offload)) {
4879 dw->buf = server->smallbuf;
4880 server->smallbuf = (char *)cifs_small_buf_get();
4882 queue_work(decrypt_wq, &dw->decrypt);
4883 *num_mids = 0; /* worker thread takes care of finding mid */
4887 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
4892 *mid = smb2_find_mid(server, buf);
4894 cifs_dbg(FYI, "mid not found\n");
4896 cifs_dbg(FYI, "mid found\n");
4897 (*mid)->decrypted = true;
4898 rc = handle_read_data(server, *mid, buf,
4899 server->vals->read_rsp_size,
4900 dw->buffer, dw->len, false);
4902 if (server->ops->is_network_name_deleted) {
4903 server->ops->is_network_name_deleted(buf,
4910 cifs_clear_folioq_buffer(dw->buffer);
4915 cifs_discard_remaining_data(server);
4920 receive_encrypted_standard(struct TCP_Server_Info *server,
4921 struct mid_q_entry **mids, char **bufs,
4925 char *buf = server->smallbuf;
4926 struct smb2_hdr *shdr;
4927 unsigned int pdu_length = server->pdu_size;
4928 unsigned int buf_size;
4929 unsigned int next_cmd;
4930 struct mid_q_entry *mid_entry;
4932 char *next_buffer = NULL;
4936 /* switch to large buffer if too big for a small one */
4937 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
4938 server->large_buf = true;
4939 memcpy(server->bigbuf, buf, server->total_read);
4940 buf = server->bigbuf;
4943 /* now read the rest */
4944 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
4945 pdu_length - HEADER_SIZE(server) + 1);
4948 server->total_read += length;
4950 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
4951 length = decrypt_raw_data(server, buf, buf_size, NULL, false);
4955 next_is_large = server->large_buf;
4957 shdr = (struct smb2_hdr *)buf;
4958 next_cmd = le32_to_cpu(shdr->NextCommand);
4960 if (WARN_ON_ONCE(next_cmd > pdu_length))
4963 next_buffer = (char *)cifs_buf_get();
4965 next_buffer = (char *)cifs_small_buf_get();
4966 memcpy(next_buffer, buf + next_cmd, pdu_length - next_cmd);
4969 mid_entry = smb2_find_mid(server, buf);
4970 if (mid_entry == NULL)
4971 cifs_dbg(FYI, "mid not found\n");
4973 cifs_dbg(FYI, "mid found\n");
4974 mid_entry->decrypted = true;
4975 mid_entry->resp_buf_size = server->pdu_size;
4978 if (*num_mids >= MAX_COMPOUND) {
4979 cifs_server_dbg(VFS, "too many PDUs in compound\n");
4982 bufs[*num_mids] = buf;
4983 mids[(*num_mids)++] = mid_entry;
4985 if (mid_entry && mid_entry->handle)
4986 ret = mid_entry->handle(server, mid_entry);
4988 ret = cifs_handle_standard(server, mid_entry);
4990 if (ret == 0 && next_cmd) {
4991 pdu_length -= next_cmd;
4992 server->large_buf = next_is_large;
4994 server->bigbuf = buf = next_buffer;
4996 server->smallbuf = buf = next_buffer;
4998 } else if (ret != 0) {
5000 * ret != 0 here means that we didn't get to handle_mid() thus
5001 * server->smallbuf and server->bigbuf are still valid. We need
5002 * to free next_buffer because it is not going to be used
5006 free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer);
5008 free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer);
5015 smb3_receive_transform(struct TCP_Server_Info *server,
5016 struct mid_q_entry **mids, char **bufs, int *num_mids)
5018 char *buf = server->smallbuf;
5019 unsigned int pdu_length = server->pdu_size;
5020 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
5021 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
5023 if (pdu_length < sizeof(struct smb2_transform_hdr) +
5024 sizeof(struct smb2_hdr)) {
5025 cifs_server_dbg(VFS, "Transform message is too small (%u)\n",
5027 cifs_reconnect(server, true);
5028 return -ECONNABORTED;
5031 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
5032 cifs_server_dbg(VFS, "Transform message is broken\n");
5033 cifs_reconnect(server, true);
5034 return -ECONNABORTED;
5037 /* TODO: add support for compounds containing READ. */
5038 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
5039 return receive_encrypted_read(server, &mids[0], num_mids);
5042 return receive_encrypted_standard(server, mids, bufs, num_mids);
5046 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
5048 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
5050 return handle_read_data(server, mid, buf, server->pdu_size,
5054 static int smb2_next_header(struct TCP_Server_Info *server, char *buf,
5057 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
5058 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
5060 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
5061 *noff = le32_to_cpu(t_hdr->OriginalMessageSize);
5062 if (unlikely(check_add_overflow(*noff, sizeof(*t_hdr), noff)))
5065 *noff = le32_to_cpu(hdr->NextCommand);
5067 if (unlikely(*noff && *noff < MID_HEADER_SIZE(server)))
5072 int __cifs_sfu_make_node(unsigned int xid, struct inode *inode,
5073 struct dentry *dentry, struct cifs_tcon *tcon,
5074 const char *full_path, umode_t mode, dev_t dev,
5075 const char *symname)
5077 struct TCP_Server_Info *server = tcon->ses->server;
5078 struct cifs_open_parms oparms;
5079 struct cifs_io_parms io_parms = {};
5080 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
5081 struct cifs_fid fid;
5082 unsigned int bytes_written;
5088 } __packed pdev = {};
5089 __le16 *symname_utf16 = NULL;
5093 __u32 oplock = server->oplocks ? REQ_OPLOCK : 0;
5096 switch (mode & S_IFMT) {
5099 memcpy(type, "IntxCHR\0", type_len);
5100 pdev.major = cpu_to_le64(MAJOR(dev));
5101 pdev.minor = cpu_to_le64(MINOR(dev));
5103 data_len = sizeof(pdev);
5107 memcpy(type, "IntxBLK\0", type_len);
5108 pdev.major = cpu_to_le64(MAJOR(dev));
5109 pdev.minor = cpu_to_le64(MINOR(dev));
5111 data_len = sizeof(pdev);
5115 memcpy(type, "IntxLNK\1", type_len);
5116 symname_utf16 = cifs_strndup_to_utf16(symname, strlen(symname),
5117 &data_len, cifs_sb->local_nls,
5119 if (!symname_utf16) {
5123 data_len -= 2; /* symlink is without trailing wide-nul */
5124 data = (u8 *)symname_utf16;
5128 strscpy(type, "LnxSOCK");
5130 data_len = sizeof(pdev);
5134 strscpy(type, "LnxFIFO");
5136 data_len = sizeof(pdev);
5143 oparms = CIFS_OPARMS(cifs_sb, tcon, full_path, GENERIC_WRITE,
5144 FILE_CREATE, CREATE_NOT_DIR |
5145 CREATE_OPTION_SPECIAL, ACL_NO_MODE);
5148 rc = server->ops->open(xid, &oparms, &oplock, NULL);
5152 if (type_len + data_len > 0) {
5153 io_parms.pid = current->tgid;
5154 io_parms.tcon = tcon;
5155 io_parms.length = type_len + data_len;
5156 iov[1].iov_base = type;
5157 iov[1].iov_len = type_len;
5158 iov[2].iov_base = data;
5159 iov[2].iov_len = data_len;
5161 rc = server->ops->sync_write(xid, &fid, &io_parms,
5163 iov, ARRAY_SIZE(iov)-1);
5166 server->ops->close(xid, tcon, &fid);
5169 kfree(symname_utf16);
5173 int cifs_sfu_make_node(unsigned int xid, struct inode *inode,
5174 struct dentry *dentry, struct cifs_tcon *tcon,
5175 const char *full_path, umode_t mode, dev_t dev)
5177 struct inode *new = NULL;
5180 rc = __cifs_sfu_make_node(xid, inode, dentry, tcon,
5181 full_path, mode, dev, NULL);
5185 if (tcon->posix_extensions) {
5186 rc = smb311_posix_get_inode_info(&new, full_path, NULL,
5188 } else if (tcon->unix_ext) {
5189 rc = cifs_get_inode_info_unix(&new, full_path,
5192 rc = cifs_get_inode_info(&new, full_path, NULL,
5193 inode->i_sb, xid, NULL);
5196 d_instantiate(dentry, new);
5200 static int smb2_make_node(unsigned int xid, struct inode *inode,
5201 struct dentry *dentry, struct cifs_tcon *tcon,
5202 const char *full_path, umode_t mode, dev_t dev)
5204 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
5208 * Check if mounted with mount parm 'sfu' mount parm.
5209 * SFU emulation should work with all servers, but only
5210 * supports block and char device, socket & fifo,
5211 * and was used by default in earlier versions of Windows
5213 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
5214 rc = cifs_sfu_make_node(xid, inode, dentry, tcon,
5215 full_path, mode, dev);
5217 rc = smb2_mknod_reparse(xid, inode, dentry, tcon,
5218 full_path, mode, dev);
5223 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5224 struct smb_version_operations smb20_operations = {
5225 .compare_fids = smb2_compare_fids,
5226 .setup_request = smb2_setup_request,
5227 .setup_async_request = smb2_setup_async_request,
5228 .check_receive = smb2_check_receive,
5229 .add_credits = smb2_add_credits,
5230 .set_credits = smb2_set_credits,
5231 .get_credits_field = smb2_get_credits_field,
5232 .get_credits = smb2_get_credits,
5233 .wait_mtu_credits = cifs_wait_mtu_credits,
5234 .get_next_mid = smb2_get_next_mid,
5235 .revert_current_mid = smb2_revert_current_mid,
5236 .read_data_offset = smb2_read_data_offset,
5237 .read_data_length = smb2_read_data_length,
5238 .map_error = map_smb2_to_linux_error,
5239 .find_mid = smb2_find_mid,
5240 .check_message = smb2_check_message,
5241 .dump_detail = smb2_dump_detail,
5242 .clear_stats = smb2_clear_stats,
5243 .print_stats = smb2_print_stats,
5244 .is_oplock_break = smb2_is_valid_oplock_break,
5245 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5246 .downgrade_oplock = smb2_downgrade_oplock,
5247 .need_neg = smb2_need_neg,
5248 .negotiate = smb2_negotiate,
5249 .negotiate_wsize = smb2_negotiate_wsize,
5250 .negotiate_rsize = smb2_negotiate_rsize,
5251 .sess_setup = SMB2_sess_setup,
5252 .logoff = SMB2_logoff,
5253 .tree_connect = SMB2_tcon,
5254 .tree_disconnect = SMB2_tdis,
5255 .qfs_tcon = smb2_qfs_tcon,
5256 .is_path_accessible = smb2_is_path_accessible,
5257 .can_echo = smb2_can_echo,
5259 .query_path_info = smb2_query_path_info,
5260 .query_reparse_point = smb2_query_reparse_point,
5261 .get_srv_inum = smb2_get_srv_inum,
5262 .query_file_info = smb2_query_file_info,
5263 .set_path_size = smb2_set_path_size,
5264 .set_file_size = smb2_set_file_size,
5265 .set_file_info = smb2_set_file_info,
5266 .set_compression = smb2_set_compression,
5267 .mkdir = smb2_mkdir,
5268 .mkdir_setinfo = smb2_mkdir_setinfo,
5269 .rmdir = smb2_rmdir,
5270 .unlink = smb2_unlink,
5271 .rename = smb2_rename_path,
5272 .create_hardlink = smb2_create_hardlink,
5273 .parse_reparse_point = smb2_parse_reparse_point,
5274 .query_mf_symlink = smb3_query_mf_symlink,
5275 .create_mf_symlink = smb3_create_mf_symlink,
5276 .create_reparse_symlink = smb2_create_reparse_symlink,
5277 .open = smb2_open_file,
5278 .set_fid = smb2_set_fid,
5279 .close = smb2_close_file,
5280 .flush = smb2_flush_file,
5281 .async_readv = smb2_async_readv,
5282 .async_writev = smb2_async_writev,
5283 .sync_read = smb2_sync_read,
5284 .sync_write = smb2_sync_write,
5285 .query_dir_first = smb2_query_dir_first,
5286 .query_dir_next = smb2_query_dir_next,
5287 .close_dir = smb2_close_dir,
5288 .calc_smb_size = smb2_calc_size,
5289 .is_status_pending = smb2_is_status_pending,
5290 .is_session_expired = smb2_is_session_expired,
5291 .oplock_response = smb2_oplock_response,
5292 .queryfs = smb2_queryfs,
5293 .mand_lock = smb2_mand_lock,
5294 .mand_unlock_range = smb2_unlock_range,
5295 .push_mand_locks = smb2_push_mandatory_locks,
5296 .get_lease_key = smb2_get_lease_key,
5297 .set_lease_key = smb2_set_lease_key,
5298 .new_lease_key = smb2_new_lease_key,
5299 .calc_signature = smb2_calc_signature,
5300 .is_read_op = smb2_is_read_op,
5301 .set_oplock_level = smb2_set_oplock_level,
5302 .create_lease_buf = smb2_create_lease_buf,
5303 .parse_lease_buf = smb2_parse_lease_buf,
5304 .copychunk_range = smb2_copychunk_range,
5305 .wp_retry_size = smb2_wp_retry_size,
5306 .dir_needs_close = smb2_dir_needs_close,
5307 .get_dfs_refer = smb2_get_dfs_refer,
5308 .select_sectype = smb2_select_sectype,
5309 #ifdef CONFIG_CIFS_XATTR
5310 .query_all_EAs = smb2_query_eas,
5311 .set_EA = smb2_set_ea,
5312 #endif /* CIFS_XATTR */
5313 .get_acl = get_smb2_acl,
5314 .get_acl_by_fid = get_smb2_acl_by_fid,
5315 .set_acl = set_smb2_acl,
5316 .next_header = smb2_next_header,
5317 .ioctl_query_info = smb2_ioctl_query_info,
5318 .make_node = smb2_make_node,
5319 .fiemap = smb3_fiemap,
5320 .llseek = smb3_llseek,
5321 .is_status_io_timeout = smb2_is_status_io_timeout,
5322 .is_network_name_deleted = smb2_is_network_name_deleted,
5324 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
5326 struct smb_version_operations smb21_operations = {
5327 .compare_fids = smb2_compare_fids,
5328 .setup_request = smb2_setup_request,
5329 .setup_async_request = smb2_setup_async_request,
5330 .check_receive = smb2_check_receive,
5331 .add_credits = smb2_add_credits,
5332 .set_credits = smb2_set_credits,
5333 .get_credits_field = smb2_get_credits_field,
5334 .get_credits = smb2_get_credits,
5335 .wait_mtu_credits = smb2_wait_mtu_credits,
5336 .adjust_credits = smb2_adjust_credits,
5337 .get_next_mid = smb2_get_next_mid,
5338 .revert_current_mid = smb2_revert_current_mid,
5339 .read_data_offset = smb2_read_data_offset,
5340 .read_data_length = smb2_read_data_length,
5341 .map_error = map_smb2_to_linux_error,
5342 .find_mid = smb2_find_mid,
5343 .check_message = smb2_check_message,
5344 .dump_detail = smb2_dump_detail,
5345 .clear_stats = smb2_clear_stats,
5346 .print_stats = smb2_print_stats,
5347 .is_oplock_break = smb2_is_valid_oplock_break,
5348 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5349 .downgrade_oplock = smb2_downgrade_oplock,
5350 .need_neg = smb2_need_neg,
5351 .negotiate = smb2_negotiate,
5352 .negotiate_wsize = smb2_negotiate_wsize,
5353 .negotiate_rsize = smb2_negotiate_rsize,
5354 .sess_setup = SMB2_sess_setup,
5355 .logoff = SMB2_logoff,
5356 .tree_connect = SMB2_tcon,
5357 .tree_disconnect = SMB2_tdis,
5358 .qfs_tcon = smb2_qfs_tcon,
5359 .is_path_accessible = smb2_is_path_accessible,
5360 .can_echo = smb2_can_echo,
5362 .query_path_info = smb2_query_path_info,
5363 .query_reparse_point = smb2_query_reparse_point,
5364 .get_srv_inum = smb2_get_srv_inum,
5365 .query_file_info = smb2_query_file_info,
5366 .set_path_size = smb2_set_path_size,
5367 .set_file_size = smb2_set_file_size,
5368 .set_file_info = smb2_set_file_info,
5369 .set_compression = smb2_set_compression,
5370 .mkdir = smb2_mkdir,
5371 .mkdir_setinfo = smb2_mkdir_setinfo,
5372 .rmdir = smb2_rmdir,
5373 .unlink = smb2_unlink,
5374 .rename = smb2_rename_path,
5375 .create_hardlink = smb2_create_hardlink,
5376 .parse_reparse_point = smb2_parse_reparse_point,
5377 .query_mf_symlink = smb3_query_mf_symlink,
5378 .create_mf_symlink = smb3_create_mf_symlink,
5379 .create_reparse_symlink = smb2_create_reparse_symlink,
5380 .open = smb2_open_file,
5381 .set_fid = smb2_set_fid,
5382 .close = smb2_close_file,
5383 .flush = smb2_flush_file,
5384 .async_readv = smb2_async_readv,
5385 .async_writev = smb2_async_writev,
5386 .sync_read = smb2_sync_read,
5387 .sync_write = smb2_sync_write,
5388 .query_dir_first = smb2_query_dir_first,
5389 .query_dir_next = smb2_query_dir_next,
5390 .close_dir = smb2_close_dir,
5391 .calc_smb_size = smb2_calc_size,
5392 .is_status_pending = smb2_is_status_pending,
5393 .is_session_expired = smb2_is_session_expired,
5394 .oplock_response = smb2_oplock_response,
5395 .queryfs = smb2_queryfs,
5396 .mand_lock = smb2_mand_lock,
5397 .mand_unlock_range = smb2_unlock_range,
5398 .push_mand_locks = smb2_push_mandatory_locks,
5399 .get_lease_key = smb2_get_lease_key,
5400 .set_lease_key = smb2_set_lease_key,
5401 .new_lease_key = smb2_new_lease_key,
5402 .calc_signature = smb2_calc_signature,
5403 .is_read_op = smb21_is_read_op,
5404 .set_oplock_level = smb21_set_oplock_level,
5405 .create_lease_buf = smb2_create_lease_buf,
5406 .parse_lease_buf = smb2_parse_lease_buf,
5407 .copychunk_range = smb2_copychunk_range,
5408 .wp_retry_size = smb2_wp_retry_size,
5409 .dir_needs_close = smb2_dir_needs_close,
5410 .enum_snapshots = smb3_enum_snapshots,
5411 .notify = smb3_notify,
5412 .get_dfs_refer = smb2_get_dfs_refer,
5413 .select_sectype = smb2_select_sectype,
5414 #ifdef CONFIG_CIFS_XATTR
5415 .query_all_EAs = smb2_query_eas,
5416 .set_EA = smb2_set_ea,
5417 #endif /* CIFS_XATTR */
5418 .get_acl = get_smb2_acl,
5419 .get_acl_by_fid = get_smb2_acl_by_fid,
5420 .set_acl = set_smb2_acl,
5421 .next_header = smb2_next_header,
5422 .ioctl_query_info = smb2_ioctl_query_info,
5423 .make_node = smb2_make_node,
5424 .fiemap = smb3_fiemap,
5425 .llseek = smb3_llseek,
5426 .is_status_io_timeout = smb2_is_status_io_timeout,
5427 .is_network_name_deleted = smb2_is_network_name_deleted,
5430 struct smb_version_operations smb30_operations = {
5431 .compare_fids = smb2_compare_fids,
5432 .setup_request = smb2_setup_request,
5433 .setup_async_request = smb2_setup_async_request,
5434 .check_receive = smb2_check_receive,
5435 .add_credits = smb2_add_credits,
5436 .set_credits = smb2_set_credits,
5437 .get_credits_field = smb2_get_credits_field,
5438 .get_credits = smb2_get_credits,
5439 .wait_mtu_credits = smb2_wait_mtu_credits,
5440 .adjust_credits = smb2_adjust_credits,
5441 .get_next_mid = smb2_get_next_mid,
5442 .revert_current_mid = smb2_revert_current_mid,
5443 .read_data_offset = smb2_read_data_offset,
5444 .read_data_length = smb2_read_data_length,
5445 .map_error = map_smb2_to_linux_error,
5446 .find_mid = smb2_find_mid,
5447 .check_message = smb2_check_message,
5448 .dump_detail = smb2_dump_detail,
5449 .clear_stats = smb2_clear_stats,
5450 .print_stats = smb2_print_stats,
5451 .dump_share_caps = smb2_dump_share_caps,
5452 .is_oplock_break = smb2_is_valid_oplock_break,
5453 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5454 .downgrade_oplock = smb3_downgrade_oplock,
5455 .need_neg = smb2_need_neg,
5456 .negotiate = smb2_negotiate,
5457 .negotiate_wsize = smb3_negotiate_wsize,
5458 .negotiate_rsize = smb3_negotiate_rsize,
5459 .sess_setup = SMB2_sess_setup,
5460 .logoff = SMB2_logoff,
5461 .tree_connect = SMB2_tcon,
5462 .tree_disconnect = SMB2_tdis,
5463 .qfs_tcon = smb3_qfs_tcon,
5464 .query_server_interfaces = SMB3_request_interfaces,
5465 .is_path_accessible = smb2_is_path_accessible,
5466 .can_echo = smb2_can_echo,
5468 .query_path_info = smb2_query_path_info,
5469 /* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */
5470 .query_reparse_point = smb2_query_reparse_point,
5471 .get_srv_inum = smb2_get_srv_inum,
5472 .query_file_info = smb2_query_file_info,
5473 .set_path_size = smb2_set_path_size,
5474 .set_file_size = smb2_set_file_size,
5475 .set_file_info = smb2_set_file_info,
5476 .set_compression = smb2_set_compression,
5477 .mkdir = smb2_mkdir,
5478 .mkdir_setinfo = smb2_mkdir_setinfo,
5479 .rmdir = smb2_rmdir,
5480 .unlink = smb2_unlink,
5481 .rename = smb2_rename_path,
5482 .create_hardlink = smb2_create_hardlink,
5483 .parse_reparse_point = smb2_parse_reparse_point,
5484 .query_mf_symlink = smb3_query_mf_symlink,
5485 .create_mf_symlink = smb3_create_mf_symlink,
5486 .create_reparse_symlink = smb2_create_reparse_symlink,
5487 .open = smb2_open_file,
5488 .set_fid = smb2_set_fid,
5489 .close = smb2_close_file,
5490 .close_getattr = smb2_close_getattr,
5491 .flush = smb2_flush_file,
5492 .async_readv = smb2_async_readv,
5493 .async_writev = smb2_async_writev,
5494 .sync_read = smb2_sync_read,
5495 .sync_write = smb2_sync_write,
5496 .query_dir_first = smb2_query_dir_first,
5497 .query_dir_next = smb2_query_dir_next,
5498 .close_dir = smb2_close_dir,
5499 .calc_smb_size = smb2_calc_size,
5500 .is_status_pending = smb2_is_status_pending,
5501 .is_session_expired = smb2_is_session_expired,
5502 .oplock_response = smb2_oplock_response,
5503 .queryfs = smb2_queryfs,
5504 .mand_lock = smb2_mand_lock,
5505 .mand_unlock_range = smb2_unlock_range,
5506 .push_mand_locks = smb2_push_mandatory_locks,
5507 .get_lease_key = smb2_get_lease_key,
5508 .set_lease_key = smb2_set_lease_key,
5509 .new_lease_key = smb2_new_lease_key,
5510 .generate_signingkey = generate_smb30signingkey,
5511 .calc_signature = smb3_calc_signature,
5512 .set_integrity = smb3_set_integrity,
5513 .is_read_op = smb21_is_read_op,
5514 .set_oplock_level = smb3_set_oplock_level,
5515 .create_lease_buf = smb3_create_lease_buf,
5516 .parse_lease_buf = smb3_parse_lease_buf,
5517 .copychunk_range = smb2_copychunk_range,
5518 .duplicate_extents = smb2_duplicate_extents,
5519 .validate_negotiate = smb3_validate_negotiate,
5520 .wp_retry_size = smb2_wp_retry_size,
5521 .dir_needs_close = smb2_dir_needs_close,
5522 .fallocate = smb3_fallocate,
5523 .enum_snapshots = smb3_enum_snapshots,
5524 .notify = smb3_notify,
5525 .init_transform_rq = smb3_init_transform_rq,
5526 .is_transform_hdr = smb3_is_transform_hdr,
5527 .receive_transform = smb3_receive_transform,
5528 .get_dfs_refer = smb2_get_dfs_refer,
5529 .select_sectype = smb2_select_sectype,
5530 #ifdef CONFIG_CIFS_XATTR
5531 .query_all_EAs = smb2_query_eas,
5532 .set_EA = smb2_set_ea,
5533 #endif /* CIFS_XATTR */
5534 .get_acl = get_smb2_acl,
5535 .get_acl_by_fid = get_smb2_acl_by_fid,
5536 .set_acl = set_smb2_acl,
5537 .next_header = smb2_next_header,
5538 .ioctl_query_info = smb2_ioctl_query_info,
5539 .make_node = smb2_make_node,
5540 .fiemap = smb3_fiemap,
5541 .llseek = smb3_llseek,
5542 .is_status_io_timeout = smb2_is_status_io_timeout,
5543 .is_network_name_deleted = smb2_is_network_name_deleted,
5546 struct smb_version_operations smb311_operations = {
5547 .compare_fids = smb2_compare_fids,
5548 .setup_request = smb2_setup_request,
5549 .setup_async_request = smb2_setup_async_request,
5550 .check_receive = smb2_check_receive,
5551 .add_credits = smb2_add_credits,
5552 .set_credits = smb2_set_credits,
5553 .get_credits_field = smb2_get_credits_field,
5554 .get_credits = smb2_get_credits,
5555 .wait_mtu_credits = smb2_wait_mtu_credits,
5556 .adjust_credits = smb2_adjust_credits,
5557 .get_next_mid = smb2_get_next_mid,
5558 .revert_current_mid = smb2_revert_current_mid,
5559 .read_data_offset = smb2_read_data_offset,
5560 .read_data_length = smb2_read_data_length,
5561 .map_error = map_smb2_to_linux_error,
5562 .find_mid = smb2_find_mid,
5563 .check_message = smb2_check_message,
5564 .dump_detail = smb2_dump_detail,
5565 .clear_stats = smb2_clear_stats,
5566 .print_stats = smb2_print_stats,
5567 .dump_share_caps = smb2_dump_share_caps,
5568 .is_oplock_break = smb2_is_valid_oplock_break,
5569 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5570 .downgrade_oplock = smb3_downgrade_oplock,
5571 .need_neg = smb2_need_neg,
5572 .negotiate = smb2_negotiate,
5573 .negotiate_wsize = smb3_negotiate_wsize,
5574 .negotiate_rsize = smb3_negotiate_rsize,
5575 .sess_setup = SMB2_sess_setup,
5576 .logoff = SMB2_logoff,
5577 .tree_connect = SMB2_tcon,
5578 .tree_disconnect = SMB2_tdis,
5579 .qfs_tcon = smb3_qfs_tcon,
5580 .query_server_interfaces = SMB3_request_interfaces,
5581 .is_path_accessible = smb2_is_path_accessible,
5582 .can_echo = smb2_can_echo,
5584 .query_path_info = smb2_query_path_info,
5585 .query_reparse_point = smb2_query_reparse_point,
5586 .get_srv_inum = smb2_get_srv_inum,
5587 .query_file_info = smb2_query_file_info,
5588 .set_path_size = smb2_set_path_size,
5589 .set_file_size = smb2_set_file_size,
5590 .set_file_info = smb2_set_file_info,
5591 .set_compression = smb2_set_compression,
5592 .mkdir = smb2_mkdir,
5593 .mkdir_setinfo = smb2_mkdir_setinfo,
5594 .posix_mkdir = smb311_posix_mkdir,
5595 .rmdir = smb2_rmdir,
5596 .unlink = smb2_unlink,
5597 .rename = smb2_rename_path,
5598 .create_hardlink = smb2_create_hardlink,
5599 .parse_reparse_point = smb2_parse_reparse_point,
5600 .query_mf_symlink = smb3_query_mf_symlink,
5601 .create_mf_symlink = smb3_create_mf_symlink,
5602 .create_reparse_symlink = smb2_create_reparse_symlink,
5603 .open = smb2_open_file,
5604 .set_fid = smb2_set_fid,
5605 .close = smb2_close_file,
5606 .close_getattr = smb2_close_getattr,
5607 .flush = smb2_flush_file,
5608 .async_readv = smb2_async_readv,
5609 .async_writev = smb2_async_writev,
5610 .sync_read = smb2_sync_read,
5611 .sync_write = smb2_sync_write,
5612 .query_dir_first = smb2_query_dir_first,
5613 .query_dir_next = smb2_query_dir_next,
5614 .close_dir = smb2_close_dir,
5615 .calc_smb_size = smb2_calc_size,
5616 .is_status_pending = smb2_is_status_pending,
5617 .is_session_expired = smb2_is_session_expired,
5618 .oplock_response = smb2_oplock_response,
5619 .queryfs = smb311_queryfs,
5620 .mand_lock = smb2_mand_lock,
5621 .mand_unlock_range = smb2_unlock_range,
5622 .push_mand_locks = smb2_push_mandatory_locks,
5623 .get_lease_key = smb2_get_lease_key,
5624 .set_lease_key = smb2_set_lease_key,
5625 .new_lease_key = smb2_new_lease_key,
5626 .generate_signingkey = generate_smb311signingkey,
5627 .calc_signature = smb3_calc_signature,
5628 .set_integrity = smb3_set_integrity,
5629 .is_read_op = smb21_is_read_op,
5630 .set_oplock_level = smb3_set_oplock_level,
5631 .create_lease_buf = smb3_create_lease_buf,
5632 .parse_lease_buf = smb3_parse_lease_buf,
5633 .copychunk_range = smb2_copychunk_range,
5634 .duplicate_extents = smb2_duplicate_extents,
5635 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
5636 .wp_retry_size = smb2_wp_retry_size,
5637 .dir_needs_close = smb2_dir_needs_close,
5638 .fallocate = smb3_fallocate,
5639 .enum_snapshots = smb3_enum_snapshots,
5640 .notify = smb3_notify,
5641 .init_transform_rq = smb3_init_transform_rq,
5642 .is_transform_hdr = smb3_is_transform_hdr,
5643 .receive_transform = smb3_receive_transform,
5644 .get_dfs_refer = smb2_get_dfs_refer,
5645 .select_sectype = smb2_select_sectype,
5646 #ifdef CONFIG_CIFS_XATTR
5647 .query_all_EAs = smb2_query_eas,
5648 .set_EA = smb2_set_ea,
5649 #endif /* CIFS_XATTR */
5650 .get_acl = get_smb2_acl,
5651 .get_acl_by_fid = get_smb2_acl_by_fid,
5652 .set_acl = set_smb2_acl,
5653 .next_header = smb2_next_header,
5654 .ioctl_query_info = smb2_ioctl_query_info,
5655 .make_node = smb2_make_node,
5656 .fiemap = smb3_fiemap,
5657 .llseek = smb3_llseek,
5658 .is_status_io_timeout = smb2_is_status_io_timeout,
5659 .is_network_name_deleted = smb2_is_network_name_deleted,
5662 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5663 struct smb_version_values smb20_values = {
5664 .version_string = SMB20_VERSION_STRING,
5665 .protocol_id = SMB20_PROT_ID,
5666 .req_capabilities = 0, /* MBZ */
5667 .large_lock_type = 0,
5668 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5669 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5670 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5671 .header_size = sizeof(struct smb2_hdr),
5672 .header_preamble_size = 0,
5673 .max_header_size = MAX_SMB2_HDR_SIZE,
5674 .read_rsp_size = sizeof(struct smb2_read_rsp),
5675 .lock_cmd = SMB2_LOCK,
5677 .cap_nt_find = SMB2_NT_FIND,
5678 .cap_large_files = SMB2_LARGE_FILES,
5679 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5680 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5681 .create_lease_size = sizeof(struct create_lease),
5683 #endif /* ALLOW_INSECURE_LEGACY */
5685 struct smb_version_values smb21_values = {
5686 .version_string = SMB21_VERSION_STRING,
5687 .protocol_id = SMB21_PROT_ID,
5688 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
5689 .large_lock_type = 0,
5690 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5691 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5692 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5693 .header_size = sizeof(struct smb2_hdr),
5694 .header_preamble_size = 0,
5695 .max_header_size = MAX_SMB2_HDR_SIZE,
5696 .read_rsp_size = sizeof(struct smb2_read_rsp),
5697 .lock_cmd = SMB2_LOCK,
5699 .cap_nt_find = SMB2_NT_FIND,
5700 .cap_large_files = SMB2_LARGE_FILES,
5701 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5702 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5703 .create_lease_size = sizeof(struct create_lease),
5706 struct smb_version_values smb3any_values = {
5707 .version_string = SMB3ANY_VERSION_STRING,
5708 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5709 .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,
5710 .large_lock_type = 0,
5711 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5712 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5713 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5714 .header_size = sizeof(struct smb2_hdr),
5715 .header_preamble_size = 0,
5716 .max_header_size = MAX_SMB2_HDR_SIZE,
5717 .read_rsp_size = sizeof(struct smb2_read_rsp),
5718 .lock_cmd = SMB2_LOCK,
5720 .cap_nt_find = SMB2_NT_FIND,
5721 .cap_large_files = SMB2_LARGE_FILES,
5722 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5723 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5724 .create_lease_size = sizeof(struct create_lease_v2),
5727 struct smb_version_values smbdefault_values = {
5728 .version_string = SMBDEFAULT_VERSION_STRING,
5729 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5730 .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,
5731 .large_lock_type = 0,
5732 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5733 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5734 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5735 .header_size = sizeof(struct smb2_hdr),
5736 .header_preamble_size = 0,
5737 .max_header_size = MAX_SMB2_HDR_SIZE,
5738 .read_rsp_size = sizeof(struct smb2_read_rsp),
5739 .lock_cmd = SMB2_LOCK,
5741 .cap_nt_find = SMB2_NT_FIND,
5742 .cap_large_files = SMB2_LARGE_FILES,
5743 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5744 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5745 .create_lease_size = sizeof(struct create_lease_v2),
5748 struct smb_version_values smb30_values = {
5749 .version_string = SMB30_VERSION_STRING,
5750 .protocol_id = SMB30_PROT_ID,
5751 .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,
5752 .large_lock_type = 0,
5753 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5754 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5755 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5756 .header_size = sizeof(struct smb2_hdr),
5757 .header_preamble_size = 0,
5758 .max_header_size = MAX_SMB2_HDR_SIZE,
5759 .read_rsp_size = sizeof(struct smb2_read_rsp),
5760 .lock_cmd = SMB2_LOCK,
5762 .cap_nt_find = SMB2_NT_FIND,
5763 .cap_large_files = SMB2_LARGE_FILES,
5764 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5765 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5766 .create_lease_size = sizeof(struct create_lease_v2),
5769 struct smb_version_values smb302_values = {
5770 .version_string = SMB302_VERSION_STRING,
5771 .protocol_id = SMB302_PROT_ID,
5772 .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,
5773 .large_lock_type = 0,
5774 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5775 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5776 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5777 .header_size = sizeof(struct smb2_hdr),
5778 .header_preamble_size = 0,
5779 .max_header_size = MAX_SMB2_HDR_SIZE,
5780 .read_rsp_size = sizeof(struct smb2_read_rsp),
5781 .lock_cmd = SMB2_LOCK,
5783 .cap_nt_find = SMB2_NT_FIND,
5784 .cap_large_files = SMB2_LARGE_FILES,
5785 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5786 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5787 .create_lease_size = sizeof(struct create_lease_v2),
5790 struct smb_version_values smb311_values = {
5791 .version_string = SMB311_VERSION_STRING,
5792 .protocol_id = SMB311_PROT_ID,
5793 .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,
5794 .large_lock_type = 0,
5795 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5796 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5797 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5798 .header_size = sizeof(struct smb2_hdr),
5799 .header_preamble_size = 0,
5800 .max_header_size = MAX_SMB2_HDR_SIZE,
5801 .read_rsp_size = sizeof(struct smb2_read_rsp),
5802 .lock_cmd = SMB2_LOCK,
5804 .cap_nt_find = SMB2_NT_FIND,
5805 .cap_large_files = SMB2_LARGE_FILES,
5806 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5807 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5808 .create_lease_size = sizeof(struct create_lease_v2),