1 // SPDX-License-Identifier: GPL-2.0
3 * SMB2 version specific operations
5 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
8 #include <linux/pagemap.h>
10 #include <linux/falloc.h>
11 #include <linux/scatterlist.h>
12 #include <linux/uuid.h>
13 #include <linux/sort.h>
14 #include <crypto/aead.h>
15 #include <linux/fiemap.h>
16 #include <uapi/linux/magic.h>
20 #include "smb2proto.h"
21 #include "cifsproto.h"
22 #include "cifs_debug.h"
23 #include "cifs_unicode.h"
24 #include "smb2status.h"
26 #include "cifs_ioctl.h"
27 #include "smbdirect.h"
29 #include "fs_context.h"
30 #include "cached_dir.h"
32 /* Change credits for different ops and return the total number of credits */
34 change_conf(struct TCP_Server_Info *server)
36 server->credits += server->echo_credits + server->oplock_credits;
37 if (server->credits > server->max_credits)
38 server->credits = server->max_credits;
39 server->oplock_credits = server->echo_credits = 0;
40 switch (server->credits) {
44 server->echoes = false;
45 server->oplocks = false;
48 server->echoes = true;
49 server->oplocks = false;
50 server->echo_credits = 1;
53 server->echoes = true;
55 server->oplocks = true;
56 server->oplock_credits = 1;
58 server->oplocks = false;
60 server->echo_credits = 1;
62 server->credits -= server->echo_credits + server->oplock_credits;
63 return server->credits + server->echo_credits + server->oplock_credits;
67 smb2_add_credits(struct TCP_Server_Info *server,
68 const struct cifs_credits *credits, const int optype)
71 int scredits, in_flight;
72 unsigned int add = credits->value;
73 unsigned int instance = credits->instance;
74 bool reconnect_detected = false;
75 bool reconnect_with_invalid_credits = false;
77 spin_lock(&server->req_lock);
78 val = server->ops->get_credits_field(server, optype);
80 /* eg found case where write overlapping reconnect messed up credits */
81 if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0))
82 reconnect_with_invalid_credits = true;
84 if ((instance == 0) || (instance == server->reconnect_instance))
87 reconnect_detected = true;
90 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
91 pr_warn_once("server overflowed SMB3 credits\n");
92 trace_smb3_overflow_credits(server->CurrentMid,
93 server->conn_id, server->hostname, *val,
94 add, server->in_flight);
96 WARN_ON_ONCE(server->in_flight == 0);
98 if (server->in_flight == 0 &&
99 ((optype & CIFS_OP_MASK) != CIFS_NEG_OP) &&
100 ((optype & CIFS_OP_MASK) != CIFS_SESS_OP))
101 rc = change_conf(server);
103 * Sometimes server returns 0 credits on oplock break ack - we need to
104 * rebalance credits in this case.
106 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
108 if (server->credits > 1) {
110 server->oplock_credits++;
112 } else if ((server->in_flight > 0) && (server->oplock_credits > 3) &&
113 ((optype & CIFS_OP_MASK) == CIFS_OBREAK_OP))
114 /* if now have too many oplock credits, rebalance so don't starve normal ops */
118 in_flight = server->in_flight;
119 spin_unlock(&server->req_lock);
120 wake_up(&server->request_q);
122 if (reconnect_detected) {
123 trace_smb3_reconnect_detected(server->CurrentMid,
124 server->conn_id, server->hostname, scredits, add, in_flight);
126 cifs_dbg(FYI, "trying to put %d credits from the old server instance %d\n",
130 if (reconnect_with_invalid_credits) {
131 trace_smb3_reconnect_with_invalid_credits(server->CurrentMid,
132 server->conn_id, server->hostname, scredits, add, in_flight);
133 cifs_dbg(FYI, "Negotiate operation when server credits is non-zero. Optype: %d, server credits: %d, credits added: %d\n",
134 optype, scredits, add);
137 spin_lock(&server->srv_lock);
138 if (server->tcpStatus == CifsNeedReconnect
139 || server->tcpStatus == CifsExiting) {
140 spin_unlock(&server->srv_lock);
143 spin_unlock(&server->srv_lock);
147 /* change_conf hasn't been executed */
150 cifs_server_dbg(VFS, "Possible client or server bug - zero credits\n");
153 cifs_server_dbg(VFS, "disabling echoes and oplocks\n");
156 cifs_dbg(FYI, "disabling oplocks\n");
159 /* change_conf rebalanced credits for different types */
163 trace_smb3_add_credits(server->CurrentMid,
164 server->conn_id, server->hostname, scredits, add, in_flight);
165 cifs_dbg(FYI, "%s: added %u credits total=%d\n", __func__, add, scredits);
169 smb2_set_credits(struct TCP_Server_Info *server, const int val)
171 int scredits, in_flight;
173 spin_lock(&server->req_lock);
174 server->credits = val;
176 server->reconnect_instance++;
178 * ChannelSequence updated for all channels in primary channel so that consistent
179 * across SMB3 requests sent on any channel. See MS-SMB2 3.2.4.1 and 3.2.7.1
181 if (SERVER_IS_CHAN(server))
182 server->primary_server->channel_sequence_num++;
184 server->channel_sequence_num++;
186 scredits = server->credits;
187 in_flight = server->in_flight;
188 spin_unlock(&server->req_lock);
190 trace_smb3_set_credits(server->CurrentMid,
191 server->conn_id, server->hostname, scredits, val, in_flight);
192 cifs_dbg(FYI, "%s: set %u credits\n", __func__, val);
194 /* don't log while holding the lock */
196 cifs_dbg(FYI, "set credits to 1 due to smb2 reconnect\n");
200 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
204 return &server->echo_credits;
206 return &server->oplock_credits;
208 return &server->credits;
213 smb2_get_credits(struct mid_q_entry *mid)
215 return mid->credits_received;
219 smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
220 unsigned int *num, struct cifs_credits *credits)
223 unsigned int scredits, in_flight;
225 spin_lock(&server->req_lock);
227 spin_unlock(&server->req_lock);
229 spin_lock(&server->srv_lock);
230 if (server->tcpStatus == CifsExiting) {
231 spin_unlock(&server->srv_lock);
234 spin_unlock(&server->srv_lock);
236 spin_lock(&server->req_lock);
237 if (server->credits <= 0) {
238 spin_unlock(&server->req_lock);
239 cifs_num_waiters_inc(server);
240 rc = wait_event_killable(server->request_q,
241 has_credits(server, &server->credits, 1));
242 cifs_num_waiters_dec(server);
245 spin_lock(&server->req_lock);
247 scredits = server->credits;
248 /* can deadlock with reopen */
250 *num = SMB2_MAX_BUFFER_SIZE;
252 credits->instance = 0;
256 /* leave some credits for reopen and other ops */
258 *num = min_t(unsigned int, size,
259 scredits * SMB2_MAX_BUFFER_SIZE);
262 DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
263 credits->instance = server->reconnect_instance;
264 server->credits -= credits->value;
266 if (server->in_flight > server->max_in_flight)
267 server->max_in_flight = server->in_flight;
271 scredits = server->credits;
272 in_flight = server->in_flight;
273 spin_unlock(&server->req_lock);
275 trace_smb3_wait_credits(server->CurrentMid,
276 server->conn_id, server->hostname, scredits, -(credits->value), in_flight);
277 cifs_dbg(FYI, "%s: removed %u credits total=%d\n",
278 __func__, credits->value, scredits);
284 smb2_adjust_credits(struct TCP_Server_Info *server,
285 struct cifs_credits *credits,
286 const unsigned int payload_size)
288 int new_val = DIV_ROUND_UP(payload_size, SMB2_MAX_BUFFER_SIZE);
289 int scredits, in_flight;
291 if (!credits->value || credits->value == new_val)
294 if (credits->value < new_val) {
295 trace_smb3_too_many_credits(server->CurrentMid,
296 server->conn_id, server->hostname, 0, credits->value - new_val, 0);
297 cifs_server_dbg(VFS, "request has less credits (%d) than required (%d)",
298 credits->value, new_val);
303 spin_lock(&server->req_lock);
305 if (server->reconnect_instance != credits->instance) {
306 scredits = server->credits;
307 in_flight = server->in_flight;
308 spin_unlock(&server->req_lock);
310 trace_smb3_reconnect_detected(server->CurrentMid,
311 server->conn_id, server->hostname, scredits,
312 credits->value - new_val, in_flight);
313 cifs_server_dbg(VFS, "trying to return %d credits to old session\n",
314 credits->value - new_val);
318 server->credits += credits->value - new_val;
319 scredits = server->credits;
320 in_flight = server->in_flight;
321 spin_unlock(&server->req_lock);
322 wake_up(&server->request_q);
324 trace_smb3_adj_credits(server->CurrentMid,
325 server->conn_id, server->hostname, scredits,
326 credits->value - new_val, in_flight);
327 cifs_dbg(FYI, "%s: adjust added %u credits total=%d\n",
328 __func__, credits->value - new_val, scredits);
330 credits->value = new_val;
336 smb2_get_next_mid(struct TCP_Server_Info *server)
339 /* for SMB2 we need the current value */
340 spin_lock(&server->mid_lock);
341 mid = server->CurrentMid++;
342 spin_unlock(&server->mid_lock);
347 smb2_revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
349 spin_lock(&server->mid_lock);
350 if (server->CurrentMid >= val)
351 server->CurrentMid -= val;
352 spin_unlock(&server->mid_lock);
355 static struct mid_q_entry *
356 __smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue)
358 struct mid_q_entry *mid;
359 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
360 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
362 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
363 cifs_server_dbg(VFS, "Encrypted frame parsing not supported yet\n");
367 spin_lock(&server->mid_lock);
368 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
369 if ((mid->mid == wire_mid) &&
370 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
371 (mid->command == shdr->Command)) {
372 kref_get(&mid->refcount);
374 list_del_init(&mid->qhead);
375 mid->mid_flags |= MID_DELETED;
377 spin_unlock(&server->mid_lock);
381 spin_unlock(&server->mid_lock);
385 static struct mid_q_entry *
386 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
388 return __smb2_find_mid(server, buf, false);
391 static struct mid_q_entry *
392 smb2_find_dequeue_mid(struct TCP_Server_Info *server, char *buf)
394 return __smb2_find_mid(server, buf, true);
398 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
400 #ifdef CONFIG_CIFS_DEBUG2
401 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
403 cifs_server_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
404 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
405 shdr->Id.SyncId.ProcessId);
406 cifs_server_dbg(VFS, "smb buf %p len %u\n", buf,
407 server->ops->calc_smb_size(buf));
412 smb2_need_neg(struct TCP_Server_Info *server)
414 return server->max_read == 0;
418 smb2_negotiate(const unsigned int xid,
419 struct cifs_ses *ses,
420 struct TCP_Server_Info *server)
424 spin_lock(&server->mid_lock);
425 server->CurrentMid = 0;
426 spin_unlock(&server->mid_lock);
427 rc = SMB2_negotiate(xid, ses, server);
428 /* BB we probably don't need to retry with modern servers */
435 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
437 struct TCP_Server_Info *server = tcon->ses->server;
440 /* start with specified wsize, or default */
441 wsize = ctx->wsize ? ctx->wsize : CIFS_DEFAULT_IOSIZE;
442 wsize = min_t(unsigned int, wsize, server->max_write);
443 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
444 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
450 smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
452 struct TCP_Server_Info *server = tcon->ses->server;
455 /* start with specified wsize, or default */
456 wsize = ctx->wsize ? ctx->wsize : SMB3_DEFAULT_IOSIZE;
457 wsize = min_t(unsigned int, wsize, server->max_write);
458 #ifdef CONFIG_CIFS_SMB_DIRECT
462 * Account for SMB2 data transfer packet header and
463 * possible encryption header
465 wsize = min_t(unsigned int,
467 server->smbd_conn->max_fragmented_send_size -
468 SMB2_READWRITE_PDU_HEADER_SIZE -
469 sizeof(struct smb2_transform_hdr));
471 wsize = min_t(unsigned int,
472 wsize, server->smbd_conn->max_readwrite_size);
475 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
476 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
482 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
484 struct TCP_Server_Info *server = tcon->ses->server;
487 /* start with specified rsize, or default */
488 rsize = ctx->rsize ? ctx->rsize : CIFS_DEFAULT_IOSIZE;
489 rsize = min_t(unsigned int, rsize, server->max_read);
491 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
492 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
498 smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
500 struct TCP_Server_Info *server = tcon->ses->server;
503 /* start with specified rsize, or default */
504 rsize = ctx->rsize ? ctx->rsize : SMB3_DEFAULT_IOSIZE;
505 rsize = min_t(unsigned int, rsize, server->max_read);
506 #ifdef CONFIG_CIFS_SMB_DIRECT
510 * Account for SMB2 data transfer packet header and
511 * possible encryption header
513 rsize = min_t(unsigned int,
515 server->smbd_conn->max_fragmented_recv_size -
516 SMB2_READWRITE_PDU_HEADER_SIZE -
517 sizeof(struct smb2_transform_hdr));
519 rsize = min_t(unsigned int,
520 rsize, server->smbd_conn->max_readwrite_size);
524 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
525 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
531 * compare two interfaces a and b
532 * return 0 if everything matches.
533 * return 1 if a is rdma capable, or rss capable, or has higher link speed
534 * return -1 otherwise.
537 iface_cmp(struct cifs_server_iface *a, struct cifs_server_iface *b)
542 if (a->rdma_capable == b->rdma_capable) {
543 if (a->rss_capable == b->rss_capable) {
544 if (a->speed == b->speed) {
545 cmp_ret = cifs_ipaddr_cmp((struct sockaddr *) &a->sockaddr,
546 (struct sockaddr *) &b->sockaddr);
549 else if (cmp_ret > 0)
553 } else if (a->speed > b->speed)
557 } else if (a->rss_capable > b->rss_capable)
561 } else if (a->rdma_capable > b->rdma_capable)
568 parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
569 size_t buf_len, struct cifs_ses *ses, bool in_mount)
571 struct network_interface_info_ioctl_rsp *p;
572 struct sockaddr_in *addr4;
573 struct sockaddr_in6 *addr6;
574 struct iface_info_ipv4 *p4;
575 struct iface_info_ipv6 *p6;
576 struct cifs_server_iface *info = NULL, *iface = NULL, *niface = NULL;
577 struct cifs_server_iface tmp_iface;
583 bytes_left = buf_len;
586 spin_lock(&ses->iface_lock);
587 /* do not query too frequently, this time with lock held */
588 if (ses->iface_last_update &&
589 time_before(jiffies, ses->iface_last_update +
590 (SMB_INTERFACE_POLL_INTERVAL * HZ))) {
591 spin_unlock(&ses->iface_lock);
596 * Go through iface_list and do kref_put to remove
597 * any unused ifaces. ifaces in use will be removed
598 * when the last user calls a kref_put on it
600 list_for_each_entry_safe(iface, niface, &ses->iface_list,
602 iface->is_active = 0;
603 kref_put(&iface->refcount, release_iface);
606 spin_unlock(&ses->iface_lock);
609 * Samba server e.g. can return an empty interface list in some cases,
610 * which would only be a problem if we were requesting multichannel
612 if (bytes_left == 0) {
613 /* avoid spamming logs every 10 minutes, so log only in mount */
614 if ((ses->chan_max > 1) && in_mount)
616 "multichannel not available\n"
617 "Empty network interface list returned by server %s\n",
618 ses->server->hostname);
623 while (bytes_left >= sizeof(*p)) {
624 memset(&tmp_iface, 0, sizeof(tmp_iface));
625 tmp_iface.speed = le64_to_cpu(p->LinkSpeed);
626 tmp_iface.rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE) ? 1 : 0;
627 tmp_iface.rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE) ? 1 : 0;
631 * The kernel and wire socket structures have the same
632 * layout and use network byte order but make the
633 * conversion explicit in case either one changes.
636 addr4 = (struct sockaddr_in *)&tmp_iface.sockaddr;
637 p4 = (struct iface_info_ipv4 *)p->Buffer;
638 addr4->sin_family = AF_INET;
639 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
641 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
642 addr4->sin_port = cpu_to_be16(CIFS_PORT);
644 cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
648 addr6 = (struct sockaddr_in6 *)&tmp_iface.sockaddr;
649 p6 = (struct iface_info_ipv6 *)p->Buffer;
650 addr6->sin6_family = AF_INET6;
651 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
653 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
654 addr6->sin6_flowinfo = 0;
655 addr6->sin6_scope_id = 0;
656 addr6->sin6_port = cpu_to_be16(CIFS_PORT);
658 cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
663 "%s: skipping unsupported socket family\n",
669 * The iface_list is assumed to be sorted by speed.
670 * Check if the new interface exists in that list.
671 * NEVER change iface. it could be in use.
672 * Add a new one instead
674 spin_lock(&ses->iface_lock);
675 list_for_each_entry_safe(iface, niface, &ses->iface_list,
677 ret = iface_cmp(iface, &tmp_iface);
679 /* just get a ref so that it doesn't get picked/freed */
680 iface->is_active = 1;
681 kref_get(&iface->refcount);
683 spin_unlock(&ses->iface_lock);
685 } else if (ret < 0) {
686 /* all remaining ifaces are slower */
687 kref_get(&iface->refcount);
691 spin_unlock(&ses->iface_lock);
693 /* no match. insert the entry in the list */
694 info = kmalloc(sizeof(struct cifs_server_iface),
700 memcpy(info, &tmp_iface, sizeof(tmp_iface));
702 /* add this new entry to the list */
703 kref_init(&info->refcount);
706 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, ses->iface_count);
707 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
708 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
709 le32_to_cpu(p->Capability));
711 spin_lock(&ses->iface_lock);
712 if (!list_entry_is_head(iface, &ses->iface_list, iface_head)) {
713 list_add_tail(&info->iface_head, &iface->iface_head);
714 kref_put(&iface->refcount, release_iface);
716 list_add_tail(&info->iface_head, &ses->iface_list);
719 spin_unlock(&ses->iface_lock);
720 ses->iface_last_update = jiffies;
723 next = le32_to_cpu(p->Next);
725 bytes_left -= sizeof(*p);
728 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
733 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
738 /* Azure rounds the buffer size up 8, to a 16 byte boundary */
739 if ((bytes_left > 8) || p->Next)
740 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
743 if (!ses->iface_count) {
753 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon, bool in_mount)
756 unsigned int ret_data_len = 0;
757 struct network_interface_info_ioctl_rsp *out_buf = NULL;
758 struct cifs_ses *ses = tcon->ses;
760 /* do not query too frequently */
761 if (ses->iface_last_update &&
762 time_before(jiffies, ses->iface_last_update +
763 (SMB_INTERFACE_POLL_INTERVAL * HZ)))
766 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
767 FSCTL_QUERY_NETWORK_INTERFACE_INFO,
768 NULL /* no data input */, 0 /* no data input */,
769 CIFSMaxBufSize, (char **)&out_buf, &ret_data_len);
770 if (rc == -EOPNOTSUPP) {
772 "server does not support query network interfaces\n");
774 } else if (rc != 0) {
775 cifs_tcon_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
779 rc = parse_server_interfaces(out_buf, ret_data_len, ses, in_mount);
789 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
790 struct cifs_sb_info *cifs_sb)
793 __le16 srch_path = 0; /* Null - open root of share */
794 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
795 struct cifs_open_parms oparms;
797 struct cached_fid *cfid = NULL;
799 oparms = (struct cifs_open_parms) {
802 .desired_access = FILE_READ_ATTRIBUTES,
803 .disposition = FILE_OPEN,
804 .create_options = cifs_create_options(cifs_sb, 0),
808 rc = open_cached_dir(xid, tcon, "", cifs_sb, false, &cfid);
810 memcpy(&fid, &cfid->fid, sizeof(struct cifs_fid));
812 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
817 SMB3_request_interfaces(xid, tcon, true /* called during mount */);
819 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
820 FS_ATTRIBUTE_INFORMATION);
821 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
822 FS_DEVICE_INFORMATION);
823 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
824 FS_VOLUME_INFORMATION);
825 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
826 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
828 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
830 close_cached_dir(cfid);
834 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
835 struct cifs_sb_info *cifs_sb)
838 __le16 srch_path = 0; /* Null - open root of share */
839 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
840 struct cifs_open_parms oparms;
843 oparms = (struct cifs_open_parms) {
846 .desired_access = FILE_READ_ATTRIBUTES,
847 .disposition = FILE_OPEN,
848 .create_options = cifs_create_options(cifs_sb, 0),
852 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
857 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
858 FS_ATTRIBUTE_INFORMATION);
859 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
860 FS_DEVICE_INFORMATION);
861 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
865 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
866 struct cifs_sb_info *cifs_sb, const char *full_path)
869 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
870 int err_buftype = CIFS_NO_BUFFER;
871 struct cifs_open_parms oparms;
872 struct kvec err_iov = {};
874 struct cached_fid *cfid;
878 rc = open_cached_dir(xid, tcon, full_path, cifs_sb, true, &cfid);
880 if (cfid->has_lease) {
881 close_cached_dir(cfid);
884 close_cached_dir(cfid);
887 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
891 oparms = (struct cifs_open_parms) {
894 .desired_access = FILE_READ_ATTRIBUTES,
895 .disposition = FILE_OPEN,
896 .create_options = cifs_create_options(cifs_sb, 0),
900 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
901 &err_iov, &err_buftype);
903 struct smb2_hdr *hdr = err_iov.iov_base;
905 if (unlikely(!hdr || err_buftype == CIFS_NO_BUFFER))
908 if (rc != -EREMOTE && hdr->Status == STATUS_OBJECT_NAME_INVALID) {
909 rc2 = cifs_inval_name_dfs_link_error(xid, tcon, cifs_sb,
918 if (rc == -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) && cifs_sb &&
919 (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS))
924 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
927 free_rsp_buf(err_buftype, err_iov.iov_base);
932 static int smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
933 struct cifs_sb_info *cifs_sb, const char *full_path,
934 u64 *uniqueid, struct cifs_open_info_data *data)
936 *uniqueid = le64_to_cpu(data->fi.IndexNumber);
940 static int smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
941 struct cifsFileInfo *cfile, struct cifs_open_info_data *data)
943 struct cifs_fid *fid = &cfile->fid;
945 if (cfile->symlink_target) {
946 data->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
947 if (!data->symlink_target)
950 return SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, &data->fi);
953 #ifdef CONFIG_CIFS_XATTR
955 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
956 struct smb2_file_full_ea_info *src, size_t src_size,
957 const unsigned char *ea_name)
960 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
962 size_t buf_size = dst_size;
963 size_t name_len, value_len, user_name_len;
965 while (src_size > 0) {
966 name_len = (size_t)src->ea_name_length;
967 value_len = (size_t)le16_to_cpu(src->ea_value_length);
972 if (src_size < 8 + name_len + 1 + value_len) {
973 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
978 name = &src->ea_data[0];
979 value = &src->ea_data[src->ea_name_length + 1];
982 if (ea_name_len == name_len &&
983 memcmp(ea_name, name, name_len) == 0) {
987 if (dst_size < value_len) {
991 memcpy(dst, value, value_len);
995 /* 'user.' plus a terminating null */
996 user_name_len = 5 + 1 + name_len;
999 /* skip copy - calc size only */
1000 rc += user_name_len;
1001 } else if (dst_size >= user_name_len) {
1002 dst_size -= user_name_len;
1003 memcpy(dst, "user.", 5);
1005 memcpy(dst, src->ea_data, name_len);
1009 rc += user_name_len;
1011 /* stop before overrun buffer */
1017 if (!src->next_entry_offset)
1020 if (src_size < le32_to_cpu(src->next_entry_offset)) {
1021 /* stop before overrun buffer */
1025 src_size -= le32_to_cpu(src->next_entry_offset);
1026 src = (void *)((char *)src +
1027 le32_to_cpu(src->next_entry_offset));
1030 /* didn't find the named attribute */
1039 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
1040 const unsigned char *path, const unsigned char *ea_name,
1041 char *ea_data, size_t buf_size,
1042 struct cifs_sb_info *cifs_sb)
1045 struct kvec rsp_iov = {NULL, 0};
1046 int buftype = CIFS_NO_BUFFER;
1047 struct smb2_query_info_rsp *rsp;
1048 struct smb2_file_full_ea_info *info = NULL;
1050 rc = smb2_query_info_compound(xid, tcon, path,
1052 FILE_FULL_EA_INFORMATION,
1055 MAX_SMB2_CREATE_RESPONSE_SIZE -
1056 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1057 &rsp_iov, &buftype, cifs_sb);
1060 * If ea_name is NULL (listxattr) and there are no EAs,
1061 * return 0 as it's not an error. Otherwise, the specified
1062 * ea_name was not found.
1064 if (!ea_name && rc == -ENODATA)
1069 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
1070 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1071 le32_to_cpu(rsp->OutputBufferLength),
1073 sizeof(struct smb2_file_full_ea_info));
1077 info = (struct smb2_file_full_ea_info *)(
1078 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1079 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
1080 le32_to_cpu(rsp->OutputBufferLength), ea_name);
1083 free_rsp_buf(buftype, rsp_iov.iov_base);
1088 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
1089 const char *path, const char *ea_name, const void *ea_value,
1090 const __u16 ea_value_len, const struct nls_table *nls_codepage,
1091 struct cifs_sb_info *cifs_sb)
1093 struct smb2_compound_vars *vars;
1094 struct cifs_ses *ses = tcon->ses;
1095 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1096 struct smb_rqst *rqst;
1097 struct kvec *rsp_iov;
1098 __le16 *utf16_path = NULL;
1099 int ea_name_len = strlen(ea_name);
1100 int flags = CIFS_CP_CREATE_CLOSE_OP;
1102 int resp_buftype[3];
1103 struct cifs_open_parms oparms;
1104 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1105 struct cifs_fid fid;
1106 unsigned int size[1];
1108 struct smb2_file_full_ea_info *ea = NULL;
1109 struct smb2_query_info_rsp *rsp;
1110 int rc, used_len = 0;
1112 if (smb3_encryption_required(tcon))
1113 flags |= CIFS_TRANSFORM_REQ;
1115 if (ea_name_len > 255)
1118 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1122 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1123 vars = kzalloc(sizeof(*vars), GFP_KERNEL);
1129 rsp_iov = vars->rsp_iov;
1131 if (ses->server->ops->query_all_EAs) {
1133 rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1139 /* If we are adding a attribute we should first check
1140 * if there will be enough space available to store
1141 * the new EA. If not we should not add it since we
1142 * would not be able to even read the EAs back.
1144 rc = smb2_query_info_compound(xid, tcon, path,
1146 FILE_FULL_EA_INFORMATION,
1149 MAX_SMB2_CREATE_RESPONSE_SIZE -
1150 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1151 &rsp_iov[1], &resp_buftype[1], cifs_sb);
1153 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1154 used_len = le32_to_cpu(rsp->OutputBufferLength);
1156 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1157 resp_buftype[1] = CIFS_NO_BUFFER;
1158 memset(&rsp_iov[1], 0, sizeof(rsp_iov[1]));
1161 /* Use a fudge factor of 256 bytes in case we collide
1162 * with a different set_EAs command.
1164 if (CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1165 MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 <
1166 used_len + ea_name_len + ea_value_len + 1) {
1174 rqst[0].rq_iov = vars->open_iov;
1175 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1177 oparms = (struct cifs_open_parms) {
1180 .desired_access = FILE_WRITE_EA,
1181 .disposition = FILE_OPEN,
1182 .create_options = cifs_create_options(cifs_sb, 0),
1186 rc = SMB2_open_init(tcon, server,
1187 &rqst[0], &oplock, &oparms, utf16_path);
1190 smb2_set_next_command(tcon, &rqst[0]);
1194 rqst[1].rq_iov = vars->si_iov;
1195 rqst[1].rq_nvec = 1;
1197 len = sizeof(*ea) + ea_name_len + ea_value_len + 1;
1198 ea = kzalloc(len, GFP_KERNEL);
1204 ea->ea_name_length = ea_name_len;
1205 ea->ea_value_length = cpu_to_le16(ea_value_len);
1206 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
1207 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
1212 rc = SMB2_set_info_init(tcon, server,
1213 &rqst[1], COMPOUND_FID,
1214 COMPOUND_FID, current->tgid,
1215 FILE_FULL_EA_INFORMATION,
1216 SMB2_O_INFO_FILE, 0, data, size);
1219 smb2_set_next_command(tcon, &rqst[1]);
1220 smb2_set_related(&rqst[1]);
1223 rqst[2].rq_iov = &vars->close_iov;
1224 rqst[2].rq_nvec = 1;
1225 rc = SMB2_close_init(tcon, server,
1226 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1229 smb2_set_related(&rqst[2]);
1231 rc = compound_send_recv(xid, ses, server,
1233 resp_buftype, rsp_iov);
1234 /* no need to bump num_remote_opens because handle immediately closed */
1238 SMB2_open_free(&rqst[0]);
1239 SMB2_set_info_free(&rqst[1]);
1240 SMB2_close_free(&rqst[2]);
1241 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1242 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1243 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1252 smb2_can_echo(struct TCP_Server_Info *server)
1254 return server->echoes;
1258 smb2_clear_stats(struct cifs_tcon *tcon)
1262 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1263 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1264 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1269 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1271 seq_puts(m, "\n\tShare Capabilities:");
1272 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1273 seq_puts(m, " DFS,");
1274 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1275 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1276 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1277 seq_puts(m, " SCALEOUT,");
1278 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1279 seq_puts(m, " CLUSTER,");
1280 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1281 seq_puts(m, " ASYMMETRIC,");
1282 if (tcon->capabilities == 0)
1283 seq_puts(m, " None");
1284 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1285 seq_puts(m, " Aligned,");
1286 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1287 seq_puts(m, " Partition Aligned,");
1288 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1289 seq_puts(m, " SSD,");
1290 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1291 seq_puts(m, " TRIM-support,");
1293 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1294 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1295 if (tcon->perf_sector_size)
1296 seq_printf(m, "\tOptimal sector size: 0x%x",
1297 tcon->perf_sector_size);
1298 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1302 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1304 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1305 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1308 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1309 * totals (requests sent) since those SMBs are per-session not per tcon
1311 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1312 (long long)(tcon->bytes_read),
1313 (long long)(tcon->bytes_written));
1314 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1315 atomic_read(&tcon->num_local_opens),
1316 atomic_read(&tcon->num_remote_opens));
1317 seq_printf(m, "\nTreeConnects: %d total %d failed",
1318 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1319 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1320 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1321 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1322 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1323 seq_printf(m, "\nCreates: %d total %d failed",
1324 atomic_read(&sent[SMB2_CREATE_HE]),
1325 atomic_read(&failed[SMB2_CREATE_HE]));
1326 seq_printf(m, "\nCloses: %d total %d failed",
1327 atomic_read(&sent[SMB2_CLOSE_HE]),
1328 atomic_read(&failed[SMB2_CLOSE_HE]));
1329 seq_printf(m, "\nFlushes: %d total %d failed",
1330 atomic_read(&sent[SMB2_FLUSH_HE]),
1331 atomic_read(&failed[SMB2_FLUSH_HE]));
1332 seq_printf(m, "\nReads: %d total %d failed",
1333 atomic_read(&sent[SMB2_READ_HE]),
1334 atomic_read(&failed[SMB2_READ_HE]));
1335 seq_printf(m, "\nWrites: %d total %d failed",
1336 atomic_read(&sent[SMB2_WRITE_HE]),
1337 atomic_read(&failed[SMB2_WRITE_HE]));
1338 seq_printf(m, "\nLocks: %d total %d failed",
1339 atomic_read(&sent[SMB2_LOCK_HE]),
1340 atomic_read(&failed[SMB2_LOCK_HE]));
1341 seq_printf(m, "\nIOCTLs: %d total %d failed",
1342 atomic_read(&sent[SMB2_IOCTL_HE]),
1343 atomic_read(&failed[SMB2_IOCTL_HE]));
1344 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1345 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1346 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1347 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1348 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1349 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1350 seq_printf(m, "\nQueryInfos: %d total %d failed",
1351 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1352 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1353 seq_printf(m, "\nSetInfos: %d total %d failed",
1354 atomic_read(&sent[SMB2_SET_INFO_HE]),
1355 atomic_read(&failed[SMB2_SET_INFO_HE]));
1356 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1357 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1358 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1362 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1364 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1365 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1367 cfile->fid.persistent_fid = fid->persistent_fid;
1368 cfile->fid.volatile_fid = fid->volatile_fid;
1369 cfile->fid.access = fid->access;
1370 #ifdef CONFIG_CIFS_DEBUG2
1371 cfile->fid.mid = fid->mid;
1372 #endif /* CIFS_DEBUG2 */
1373 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1375 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1376 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1380 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1381 struct cifs_fid *fid)
1383 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1387 smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon,
1388 struct cifsFileInfo *cfile)
1390 struct smb2_file_network_open_info file_inf;
1391 struct inode *inode;
1394 rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid,
1395 cfile->fid.volatile_fid, &file_inf);
1399 inode = d_inode(cfile->dentry);
1401 spin_lock(&inode->i_lock);
1402 CIFS_I(inode)->time = jiffies;
1404 /* Creation time should not need to be updated on close */
1405 if (file_inf.LastWriteTime)
1406 inode_set_mtime_to_ts(inode,
1407 cifs_NTtimeToUnix(file_inf.LastWriteTime));
1408 if (file_inf.ChangeTime)
1409 inode_set_ctime_to_ts(inode,
1410 cifs_NTtimeToUnix(file_inf.ChangeTime));
1411 if (file_inf.LastAccessTime)
1412 inode_set_atime_to_ts(inode,
1413 cifs_NTtimeToUnix(file_inf.LastAccessTime));
1416 * i_blocks is not related to (i_size / i_blksize),
1417 * but instead 512 byte (2**9) size is required for
1418 * calculating num blocks.
1420 if (le64_to_cpu(file_inf.AllocationSize) > 4096)
1422 (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9;
1424 /* End of file and Attributes should not have to be updated on close */
1425 spin_unlock(&inode->i_lock);
1429 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1430 u64 persistent_fid, u64 volatile_fid,
1431 struct copychunk_ioctl *pcchunk)
1434 unsigned int ret_data_len;
1435 struct resume_key_req *res_key;
1437 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1438 FSCTL_SRV_REQUEST_RESUME_KEY, NULL, 0 /* no input */,
1439 CIFSMaxBufSize, (char **)&res_key, &ret_data_len);
1441 if (rc == -EOPNOTSUPP) {
1442 pr_warn_once("Server share %s does not support copy range\n", tcon->tree_name);
1443 goto req_res_key_exit;
1445 cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1446 goto req_res_key_exit;
1448 if (ret_data_len < sizeof(struct resume_key_req)) {
1449 cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n");
1451 goto req_res_key_exit;
1453 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1461 smb2_ioctl_query_info(const unsigned int xid,
1462 struct cifs_tcon *tcon,
1463 struct cifs_sb_info *cifs_sb,
1464 __le16 *path, int is_dir,
1467 struct smb2_compound_vars *vars;
1468 struct smb_rqst *rqst;
1469 struct kvec *rsp_iov;
1470 struct cifs_ses *ses = tcon->ses;
1471 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1472 char __user *arg = (char __user *)p;
1473 struct smb_query_info qi;
1474 struct smb_query_info __user *pqi;
1476 int flags = CIFS_CP_CREATE_CLOSE_OP;
1477 struct smb2_query_info_rsp *qi_rsp = NULL;
1478 struct smb2_ioctl_rsp *io_rsp = NULL;
1479 void *buffer = NULL;
1480 int resp_buftype[3];
1481 struct cifs_open_parms oparms;
1482 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1483 struct cifs_fid fid;
1484 unsigned int size[2];
1486 int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR;
1487 void (*free_req1_func)(struct smb_rqst *r);
1489 vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
1492 rqst = &vars->rqst[0];
1493 rsp_iov = &vars->rsp_iov[0];
1495 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1497 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info))) {
1501 if (qi.output_buffer_length > 1024) {
1506 if (!ses || !server) {
1511 if (smb3_encryption_required(tcon))
1512 flags |= CIFS_TRANSFORM_REQ;
1514 if (qi.output_buffer_length) {
1515 buffer = memdup_user(arg + sizeof(struct smb_query_info), qi.output_buffer_length);
1516 if (IS_ERR(buffer)) {
1517 rc = PTR_ERR(buffer);
1523 rqst[0].rq_iov = &vars->open_iov[0];
1524 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1526 oparms = (struct cifs_open_parms) {
1528 .disposition = FILE_OPEN,
1529 .create_options = cifs_create_options(cifs_sb, create_options),
1533 if (qi.flags & PASSTHRU_FSCTL) {
1534 switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1535 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1536 oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1538 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1539 oparms.desired_access = GENERIC_ALL;
1541 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1542 oparms.desired_access = GENERIC_READ;
1544 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1545 oparms.desired_access = GENERIC_WRITE;
1548 } else if (qi.flags & PASSTHRU_SET_INFO) {
1549 oparms.desired_access = GENERIC_WRITE;
1551 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1554 rc = SMB2_open_init(tcon, server,
1555 &rqst[0], &oplock, &oparms, path);
1557 goto free_output_buffer;
1558 smb2_set_next_command(tcon, &rqst[0]);
1561 if (qi.flags & PASSTHRU_FSCTL) {
1562 /* Can eventually relax perm check since server enforces too */
1563 if (!capable(CAP_SYS_ADMIN)) {
1567 rqst[1].rq_iov = &vars->io_iov[0];
1568 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1570 rc = SMB2_ioctl_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1571 qi.info_type, buffer, qi.output_buffer_length,
1572 CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1573 MAX_SMB2_CLOSE_RESPONSE_SIZE);
1574 free_req1_func = SMB2_ioctl_free;
1575 } else if (qi.flags == PASSTHRU_SET_INFO) {
1576 /* Can eventually relax perm check since server enforces too */
1577 if (!capable(CAP_SYS_ADMIN)) {
1581 if (qi.output_buffer_length < 8) {
1585 rqst[1].rq_iov = vars->si_iov;
1586 rqst[1].rq_nvec = 1;
1588 /* MS-FSCC 2.4.13 FileEndOfFileInformation */
1592 rc = SMB2_set_info_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1593 current->tgid, FILE_END_OF_FILE_INFORMATION,
1594 SMB2_O_INFO_FILE, 0, data, size);
1595 free_req1_func = SMB2_set_info_free;
1596 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1597 rqst[1].rq_iov = &vars->qi_iov;
1598 rqst[1].rq_nvec = 1;
1600 rc = SMB2_query_info_init(tcon, server,
1601 &rqst[1], COMPOUND_FID,
1602 COMPOUND_FID, qi.file_info_class,
1603 qi.info_type, qi.additional_information,
1604 qi.input_buffer_length,
1605 qi.output_buffer_length, buffer);
1606 free_req1_func = SMB2_query_info_free;
1607 } else { /* unknown flags */
1608 cifs_tcon_dbg(VFS, "Invalid passthru query flags: 0x%x\n",
1615 smb2_set_next_command(tcon, &rqst[1]);
1616 smb2_set_related(&rqst[1]);
1619 rqst[2].rq_iov = &vars->close_iov;
1620 rqst[2].rq_nvec = 1;
1622 rc = SMB2_close_init(tcon, server,
1623 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1626 smb2_set_related(&rqst[2]);
1628 rc = compound_send_recv(xid, ses, server,
1630 resp_buftype, rsp_iov);
1634 /* No need to bump num_remote_opens since handle immediately closed */
1635 if (qi.flags & PASSTHRU_FSCTL) {
1636 pqi = (struct smb_query_info __user *)arg;
1637 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1638 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1639 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1640 if (qi.input_buffer_length > 0 &&
1641 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length
1642 > rsp_iov[1].iov_len) {
1647 if (copy_to_user(&pqi->input_buffer_length,
1648 &qi.input_buffer_length,
1649 sizeof(qi.input_buffer_length))) {
1654 if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1655 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1656 qi.input_buffer_length))
1659 pqi = (struct smb_query_info __user *)arg;
1660 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1661 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1662 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1663 if (copy_to_user(&pqi->input_buffer_length,
1664 &qi.input_buffer_length,
1665 sizeof(qi.input_buffer_length))) {
1670 if (copy_to_user(pqi + 1, qi_rsp->Buffer,
1671 qi.input_buffer_length))
1676 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1677 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1678 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1679 SMB2_close_free(&rqst[2]);
1681 free_req1_func(&rqst[1]);
1683 SMB2_open_free(&rqst[0]);
1692 smb2_copychunk_range(const unsigned int xid,
1693 struct cifsFileInfo *srcfile,
1694 struct cifsFileInfo *trgtfile, u64 src_off,
1695 u64 len, u64 dest_off)
1698 unsigned int ret_data_len;
1699 struct copychunk_ioctl *pcchunk;
1700 struct copychunk_ioctl_rsp *retbuf = NULL;
1701 struct cifs_tcon *tcon;
1702 int chunks_copied = 0;
1703 bool chunk_sizes_updated = false;
1704 ssize_t bytes_written, total_bytes_written = 0;
1706 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1707 if (pcchunk == NULL)
1710 cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
1711 /* Request a key from the server to identify the source of the copy */
1712 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1713 srcfile->fid.persistent_fid,
1714 srcfile->fid.volatile_fid, pcchunk);
1716 /* Note: request_res_key sets res_key null only if rc !=0 */
1720 /* For now array only one chunk long, will make more flexible later */
1721 pcchunk->ChunkCount = cpu_to_le32(1);
1722 pcchunk->Reserved = 0;
1723 pcchunk->Reserved2 = 0;
1725 tcon = tlink_tcon(trgtfile->tlink);
1728 pcchunk->SourceOffset = cpu_to_le64(src_off);
1729 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1731 cpu_to_le32(min_t(u64, len, tcon->max_bytes_chunk));
1733 /* Request server copy to target from src identified by key */
1736 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1737 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1738 (char *)pcchunk, sizeof(struct copychunk_ioctl),
1739 CIFSMaxBufSize, (char **)&retbuf, &ret_data_len);
1742 sizeof(struct copychunk_ioctl_rsp)) {
1743 cifs_tcon_dbg(VFS, "Invalid cchunk response size\n");
1747 if (retbuf->TotalBytesWritten == 0) {
1748 cifs_dbg(FYI, "no bytes copied\n");
1753 * Check if server claimed to write more than we asked
1755 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1756 le32_to_cpu(pcchunk->Length)) {
1757 cifs_tcon_dbg(VFS, "Invalid copy chunk response\n");
1761 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1762 cifs_tcon_dbg(VFS, "Invalid num chunks written\n");
1768 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1769 src_off += bytes_written;
1770 dest_off += bytes_written;
1771 len -= bytes_written;
1772 total_bytes_written += bytes_written;
1774 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1775 le32_to_cpu(retbuf->ChunksWritten),
1776 le32_to_cpu(retbuf->ChunkBytesWritten),
1778 } else if (rc == -EINVAL) {
1779 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1782 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1783 le32_to_cpu(retbuf->ChunksWritten),
1784 le32_to_cpu(retbuf->ChunkBytesWritten),
1785 le32_to_cpu(retbuf->TotalBytesWritten));
1788 * Check if this is the first request using these sizes,
1789 * (ie check if copy succeed once with original sizes
1790 * and check if the server gave us different sizes after
1791 * we already updated max sizes on previous request).
1792 * if not then why is the server returning an error now
1794 if ((chunks_copied != 0) || chunk_sizes_updated)
1797 /* Check that server is not asking us to grow size */
1798 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1799 tcon->max_bytes_chunk)
1800 tcon->max_bytes_chunk =
1801 le32_to_cpu(retbuf->ChunkBytesWritten);
1803 goto cchunk_out; /* server gave us bogus size */
1805 /* No need to change MaxChunks since already set to 1 */
1806 chunk_sizes_updated = true;
1817 return total_bytes_written;
1821 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1822 struct cifs_fid *fid)
1824 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1828 smb2_read_data_offset(char *buf)
1830 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1832 return rsp->DataOffset;
1836 smb2_read_data_length(char *buf, bool in_remaining)
1838 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1841 return le32_to_cpu(rsp->DataRemaining);
1843 return le32_to_cpu(rsp->DataLength);
1848 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1849 struct cifs_io_parms *parms, unsigned int *bytes_read,
1850 char **buf, int *buf_type)
1852 parms->persistent_fid = pfid->persistent_fid;
1853 parms->volatile_fid = pfid->volatile_fid;
1854 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1858 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1859 struct cifs_io_parms *parms, unsigned int *written,
1860 struct kvec *iov, unsigned long nr_segs)
1863 parms->persistent_fid = pfid->persistent_fid;
1864 parms->volatile_fid = pfid->volatile_fid;
1865 return SMB2_write(xid, parms, written, iov, nr_segs);
1868 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1869 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1870 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1872 struct cifsInodeInfo *cifsi;
1875 cifsi = CIFS_I(inode);
1877 /* if file already sparse don't bother setting sparse again */
1878 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1879 return true; /* already sparse */
1881 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1882 return true; /* already not sparse */
1885 * Can't check for sparse support on share the usual way via the
1886 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1887 * since Samba server doesn't set the flag on the share, yet
1888 * supports the set sparse FSCTL and returns sparse correctly
1889 * in the file attributes. If we fail setting sparse though we
1890 * mark that server does not support sparse files for this share
1891 * to avoid repeatedly sending the unsupported fsctl to server
1892 * if the file is repeatedly extended.
1894 if (tcon->broken_sparse_sup)
1897 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1898 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1899 &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
1901 tcon->broken_sparse_sup = true;
1902 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1907 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1909 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1915 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1916 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1918 __le64 eof = cpu_to_le64(size);
1919 struct inode *inode;
1922 * If extending file more than one page make sparse. Many Linux fs
1923 * make files sparse by default when extending via ftruncate
1925 inode = d_inode(cfile->dentry);
1927 if (!set_alloc && (size > inode->i_size + 8192)) {
1928 __u8 set_sparse = 1;
1930 /* whether set sparse succeeds or not, extend the file */
1931 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1934 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1935 cfile->fid.volatile_fid, cfile->pid, &eof);
1939 smb2_duplicate_extents(const unsigned int xid,
1940 struct cifsFileInfo *srcfile,
1941 struct cifsFileInfo *trgtfile, u64 src_off,
1942 u64 len, u64 dest_off)
1945 unsigned int ret_data_len;
1946 struct inode *inode;
1947 struct duplicate_extents_to_file dup_ext_buf;
1948 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1950 /* server fileays advertise duplicate extent support with this flag */
1951 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1952 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1955 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1956 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1957 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1958 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1959 dup_ext_buf.ByteCount = cpu_to_le64(len);
1960 cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
1961 src_off, dest_off, len);
1963 inode = d_inode(trgtfile->dentry);
1964 if (inode->i_size < dest_off + len) {
1965 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1967 goto duplicate_extents_out;
1970 * Although also could set plausible allocation size (i_blocks)
1971 * here in addition to setting the file size, in reflink
1972 * it is likely that the target file is sparse. Its allocation
1973 * size will be queried on next revalidate, but it is important
1974 * to make sure that file's cached size is updated immediately
1976 cifs_setsize(inode, dest_off + len);
1978 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1979 trgtfile->fid.volatile_fid,
1980 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1981 (char *)&dup_ext_buf,
1982 sizeof(struct duplicate_extents_to_file),
1983 CIFSMaxBufSize, NULL,
1986 if (ret_data_len > 0)
1987 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
1989 duplicate_extents_out:
1994 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1995 struct cifsFileInfo *cfile)
1997 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1998 cfile->fid.volatile_fid);
2002 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
2003 struct cifsFileInfo *cfile)
2005 struct fsctl_set_integrity_information_req integr_info;
2006 unsigned int ret_data_len;
2008 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
2009 integr_info.Flags = 0;
2010 integr_info.Reserved = 0;
2012 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2013 cfile->fid.volatile_fid,
2014 FSCTL_SET_INTEGRITY_INFORMATION,
2015 (char *)&integr_info,
2016 sizeof(struct fsctl_set_integrity_information_req),
2017 CIFSMaxBufSize, NULL,
2022 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
2023 #define GMT_TOKEN_SIZE 50
2025 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
2028 * Input buffer contains (empty) struct smb_snapshot array with size filled in
2029 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
2032 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
2033 struct cifsFileInfo *cfile, void __user *ioc_buf)
2035 char *retbuf = NULL;
2036 unsigned int ret_data_len = 0;
2038 u32 max_response_size;
2039 struct smb_snapshot_array snapshot_in;
2042 * On the first query to enumerate the list of snapshots available
2043 * for this volume the buffer begins with 0 (number of snapshots
2044 * which can be returned is zero since at that point we do not know
2045 * how big the buffer needs to be). On the second query,
2046 * it (ret_data_len) is set to number of snapshots so we can
2047 * know to set the maximum response size larger (see below).
2049 if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
2053 * Note that for snapshot queries that servers like Azure expect that
2054 * the first query be minimal size (and just used to get the number/size
2055 * of previous versions) so response size must be specified as EXACTLY
2056 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
2059 if (ret_data_len == 0)
2060 max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
2062 max_response_size = CIFSMaxBufSize;
2064 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2065 cfile->fid.volatile_fid,
2066 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
2067 NULL, 0 /* no input data */, max_response_size,
2070 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
2075 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
2077 if (copy_from_user(&snapshot_in, ioc_buf,
2078 sizeof(struct smb_snapshot_array))) {
2085 * Check for min size, ie not large enough to fit even one GMT
2086 * token (snapshot). On the first ioctl some users may pass in
2087 * smaller size (or zero) to simply get the size of the array
2088 * so the user space caller can allocate sufficient memory
2089 * and retry the ioctl again with larger array size sufficient
2090 * to hold all of the snapshot GMT tokens on the second try.
2092 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
2093 ret_data_len = sizeof(struct smb_snapshot_array);
2096 * We return struct SRV_SNAPSHOT_ARRAY, followed by
2097 * the snapshot array (of 50 byte GMT tokens) each
2098 * representing an available previous version of the data
2100 if (ret_data_len > (snapshot_in.snapshot_array_size +
2101 sizeof(struct smb_snapshot_array)))
2102 ret_data_len = snapshot_in.snapshot_array_size +
2103 sizeof(struct smb_snapshot_array);
2105 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
2116 smb3_notify(const unsigned int xid, struct file *pfile,
2117 void __user *ioc_buf, bool return_changes)
2119 struct smb3_notify_info notify;
2120 struct smb3_notify_info __user *pnotify_buf;
2121 struct dentry *dentry = pfile->f_path.dentry;
2122 struct inode *inode = file_inode(pfile);
2123 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2124 struct cifs_open_parms oparms;
2125 struct cifs_fid fid;
2126 struct cifs_tcon *tcon;
2127 const unsigned char *path;
2128 char *returned_ioctl_info = NULL;
2129 void *page = alloc_dentry_path();
2130 __le16 *utf16_path = NULL;
2131 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2135 path = build_path_from_dentry(dentry, page);
2141 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2142 if (utf16_path == NULL) {
2147 if (return_changes) {
2148 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify_info))) {
2153 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify))) {
2157 notify.data_len = 0;
2160 tcon = cifs_sb_master_tcon(cifs_sb);
2161 oparms = (struct cifs_open_parms) {
2164 .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
2165 .disposition = FILE_OPEN,
2166 .create_options = cifs_create_options(cifs_sb, 0),
2170 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
2175 rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid,
2176 notify.watch_tree, notify.completion_filter,
2177 notify.data_len, &returned_ioctl_info, &ret_len);
2179 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2181 cifs_dbg(FYI, "change notify for path %s rc %d\n", path, rc);
2182 if (return_changes && (ret_len > 0) && (notify.data_len > 0)) {
2183 if (ret_len > notify.data_len)
2184 ret_len = notify.data_len;
2185 pnotify_buf = (struct smb3_notify_info __user *)ioc_buf;
2186 if (copy_to_user(pnotify_buf->notify_data, returned_ioctl_info, ret_len))
2188 else if (copy_to_user(&pnotify_buf->data_len, &ret_len, sizeof(ret_len)))
2191 kfree(returned_ioctl_info);
2193 free_dentry_path(page);
2199 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
2200 const char *path, struct cifs_sb_info *cifs_sb,
2201 struct cifs_fid *fid, __u16 search_flags,
2202 struct cifs_search_info *srch_inf)
2205 struct smb_rqst rqst[2];
2206 struct kvec rsp_iov[2];
2207 int resp_buftype[2];
2208 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2209 struct kvec qd_iov[SMB2_QUERY_DIRECTORY_IOV_SIZE];
2211 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2212 struct cifs_open_parms oparms;
2213 struct smb2_query_directory_rsp *qd_rsp = NULL;
2214 struct smb2_create_rsp *op_rsp = NULL;
2215 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2216 int retry_count = 0;
2218 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2222 if (smb3_encryption_required(tcon))
2223 flags |= CIFS_TRANSFORM_REQ;
2225 memset(rqst, 0, sizeof(rqst));
2226 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
2227 memset(rsp_iov, 0, sizeof(rsp_iov));
2230 memset(&open_iov, 0, sizeof(open_iov));
2231 rqst[0].rq_iov = open_iov;
2232 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2234 oparms = (struct cifs_open_parms) {
2237 .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
2238 .disposition = FILE_OPEN,
2239 .create_options = cifs_create_options(cifs_sb, 0),
2243 rc = SMB2_open_init(tcon, server,
2244 &rqst[0], &oplock, &oparms, utf16_path);
2247 smb2_set_next_command(tcon, &rqst[0]);
2249 /* Query directory */
2250 srch_inf->entries_in_buffer = 0;
2251 srch_inf->index_of_last_entry = 2;
2253 memset(&qd_iov, 0, sizeof(qd_iov));
2254 rqst[1].rq_iov = qd_iov;
2255 rqst[1].rq_nvec = SMB2_QUERY_DIRECTORY_IOV_SIZE;
2257 rc = SMB2_query_directory_init(xid, tcon, server,
2259 COMPOUND_FID, COMPOUND_FID,
2260 0, srch_inf->info_level);
2264 smb2_set_related(&rqst[1]);
2267 rc = compound_send_recv(xid, tcon->ses, server,
2269 resp_buftype, rsp_iov);
2271 if (rc == -EAGAIN && retry_count++ < 10)
2274 /* If the open failed there is nothing to do */
2275 op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
2276 if (op_rsp == NULL || op_rsp->hdr.Status != STATUS_SUCCESS) {
2277 cifs_dbg(FYI, "query_dir_first: open failed rc=%d\n", rc);
2280 fid->persistent_fid = op_rsp->PersistentFileId;
2281 fid->volatile_fid = op_rsp->VolatileFileId;
2283 /* Anything else than ENODATA means a genuine error */
2284 if (rc && rc != -ENODATA) {
2285 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2286 cifs_dbg(FYI, "query_dir_first: query directory failed rc=%d\n", rc);
2287 trace_smb3_query_dir_err(xid, fid->persistent_fid,
2288 tcon->tid, tcon->ses->Suid, 0, 0, rc);
2292 atomic_inc(&tcon->num_remote_opens);
2294 qd_rsp = (struct smb2_query_directory_rsp *)rsp_iov[1].iov_base;
2295 if (qd_rsp->hdr.Status == STATUS_NO_MORE_FILES) {
2296 trace_smb3_query_dir_done(xid, fid->persistent_fid,
2297 tcon->tid, tcon->ses->Suid, 0, 0);
2298 srch_inf->endOfSearch = true;
2303 rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1],
2306 trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid,
2307 tcon->ses->Suid, 0, 0, rc);
2310 resp_buftype[1] = CIFS_NO_BUFFER;
2312 trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid,
2313 tcon->ses->Suid, 0, srch_inf->entries_in_buffer);
2317 SMB2_open_free(&rqst[0]);
2318 SMB2_query_directory_free(&rqst[1]);
2319 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2320 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2325 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
2326 struct cifs_fid *fid, __u16 search_flags,
2327 struct cifs_search_info *srch_inf)
2329 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
2330 fid->volatile_fid, 0, srch_inf);
2334 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
2335 struct cifs_fid *fid)
2337 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2341 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2342 * the number of credits and return true. Otherwise - return false.
2345 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
2347 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2348 int scredits, in_flight;
2350 if (shdr->Status != STATUS_PENDING)
2353 if (shdr->CreditRequest) {
2354 spin_lock(&server->req_lock);
2355 server->credits += le16_to_cpu(shdr->CreditRequest);
2356 scredits = server->credits;
2357 in_flight = server->in_flight;
2358 spin_unlock(&server->req_lock);
2359 wake_up(&server->request_q);
2361 trace_smb3_pend_credits(server->CurrentMid,
2362 server->conn_id, server->hostname, scredits,
2363 le16_to_cpu(shdr->CreditRequest), in_flight);
2364 cifs_dbg(FYI, "%s: status pending add %u credits total=%d\n",
2365 __func__, le16_to_cpu(shdr->CreditRequest), scredits);
2372 smb2_is_session_expired(char *buf)
2374 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2376 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
2377 shdr->Status != STATUS_USER_SESSION_DELETED)
2380 trace_smb3_ses_expired(le32_to_cpu(shdr->Id.SyncId.TreeId),
2381 le64_to_cpu(shdr->SessionId),
2382 le16_to_cpu(shdr->Command),
2383 le64_to_cpu(shdr->MessageId));
2384 cifs_dbg(FYI, "Session expired or deleted\n");
2390 smb2_is_status_io_timeout(char *buf)
2392 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2394 if (shdr->Status == STATUS_IO_TIMEOUT)
2401 smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server)
2403 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2404 struct TCP_Server_Info *pserver;
2405 struct cifs_ses *ses;
2406 struct cifs_tcon *tcon;
2408 if (shdr->Status != STATUS_NETWORK_NAME_DELETED)
2411 /* If server is a channel, select the primary channel */
2412 pserver = SERVER_IS_CHAN(server) ? server->primary_server : server;
2414 spin_lock(&cifs_tcp_ses_lock);
2415 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
2416 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
2417 if (tcon->tid == le32_to_cpu(shdr->Id.SyncId.TreeId)) {
2418 spin_lock(&tcon->tc_lock);
2419 tcon->need_reconnect = true;
2420 spin_unlock(&tcon->tc_lock);
2421 spin_unlock(&cifs_tcp_ses_lock);
2422 pr_warn_once("Server share %s deleted.\n",
2428 spin_unlock(&cifs_tcp_ses_lock);
2434 smb2_oplock_response(struct cifs_tcon *tcon, __u64 persistent_fid,
2435 __u64 volatile_fid, __u16 net_fid, struct cifsInodeInfo *cinode)
2437 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
2438 return SMB2_lease_break(0, tcon, cinode->lease_key,
2439 smb2_get_lease_state(cinode));
2441 return SMB2_oplock_break(0, tcon, persistent_fid, volatile_fid,
2442 CIFS_CACHE_READ(cinode) ? 1 : 0);
2446 smb2_set_related(struct smb_rqst *rqst)
2448 struct smb2_hdr *shdr;
2450 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2452 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2455 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2458 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
2461 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
2463 struct smb2_hdr *shdr;
2464 struct cifs_ses *ses = tcon->ses;
2465 struct TCP_Server_Info *server = ses->server;
2466 unsigned long len = smb_rqst_len(server, rqst);
2469 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2471 cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2475 /* SMB headers in a compound are 8 byte aligned. */
2477 /* No padding needed */
2481 num_padding = 8 - (len & 7);
2482 if (!smb3_encryption_required(tcon)) {
2484 * If we do not have encryption then we can just add an extra
2485 * iov for the padding.
2487 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2488 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2493 * We can not add a small padding iov for the encryption case
2494 * because the encryption framework can not handle the padding
2496 * We have to flatten this into a single buffer and add
2497 * the padding to it.
2499 for (i = 1; i < rqst->rq_nvec; i++) {
2500 memcpy(rqst->rq_iov[0].iov_base +
2501 rqst->rq_iov[0].iov_len,
2502 rqst->rq_iov[i].iov_base,
2503 rqst->rq_iov[i].iov_len);
2504 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2506 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2508 rqst->rq_iov[0].iov_len += num_padding;
2514 shdr->NextCommand = cpu_to_le32(len);
2518 * Passes the query info response back to the caller on success.
2519 * Caller need to free this with free_rsp_buf().
2522 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2523 const char *path, u32 desired_access,
2524 u32 class, u32 type, u32 output_len,
2525 struct kvec *rsp, int *buftype,
2526 struct cifs_sb_info *cifs_sb)
2528 struct smb2_compound_vars *vars;
2529 struct cifs_ses *ses = tcon->ses;
2530 struct TCP_Server_Info *server = cifs_pick_channel(ses);
2531 int flags = CIFS_CP_CREATE_CLOSE_OP;
2532 struct smb_rqst *rqst;
2533 int resp_buftype[3];
2534 struct kvec *rsp_iov;
2535 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2536 struct cifs_open_parms oparms;
2537 struct cifs_fid fid;
2540 struct cached_fid *cfid = NULL;
2544 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2548 if (smb3_encryption_required(tcon))
2549 flags |= CIFS_TRANSFORM_REQ;
2551 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2552 vars = kzalloc(sizeof(*vars), GFP_KERNEL);
2558 rsp_iov = vars->rsp_iov;
2561 * We can only call this for things we know are directories.
2563 if (!strcmp(path, ""))
2564 open_cached_dir(xid, tcon, path, cifs_sb, false,
2565 &cfid); /* cfid null if open dir failed */
2567 rqst[0].rq_iov = vars->open_iov;
2568 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2570 oparms = (struct cifs_open_parms) {
2573 .desired_access = desired_access,
2574 .disposition = FILE_OPEN,
2575 .create_options = cifs_create_options(cifs_sb, 0),
2579 rc = SMB2_open_init(tcon, server,
2580 &rqst[0], &oplock, &oparms, utf16_path);
2583 smb2_set_next_command(tcon, &rqst[0]);
2585 rqst[1].rq_iov = &vars->qi_iov;
2586 rqst[1].rq_nvec = 1;
2589 rc = SMB2_query_info_init(tcon, server,
2591 cfid->fid.persistent_fid,
2592 cfid->fid.volatile_fid,
2597 rc = SMB2_query_info_init(tcon, server,
2608 smb2_set_next_command(tcon, &rqst[1]);
2609 smb2_set_related(&rqst[1]);
2612 rqst[2].rq_iov = &vars->close_iov;
2613 rqst[2].rq_nvec = 1;
2615 rc = SMB2_close_init(tcon, server,
2616 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2619 smb2_set_related(&rqst[2]);
2622 rc = compound_send_recv(xid, ses, server,
2624 &resp_buftype[1], &rsp_iov[1]);
2626 rc = compound_send_recv(xid, ses, server,
2628 resp_buftype, rsp_iov);
2631 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2632 if (rc == -EREMCHG) {
2633 tcon->need_reconnect = true;
2634 pr_warn_once("server share %s deleted\n",
2640 *buftype = resp_buftype[1];
2643 SMB2_open_free(&rqst[0]);
2644 SMB2_query_info_free(&rqst[1]);
2645 SMB2_close_free(&rqst[2]);
2646 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2647 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2649 close_cached_dir(cfid);
2657 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2658 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2660 struct smb2_query_info_rsp *rsp;
2661 struct smb2_fs_full_size_info *info = NULL;
2662 struct kvec rsp_iov = {NULL, 0};
2663 int buftype = CIFS_NO_BUFFER;
2667 rc = smb2_query_info_compound(xid, tcon, "",
2668 FILE_READ_ATTRIBUTES,
2669 FS_FULL_SIZE_INFORMATION,
2670 SMB2_O_INFO_FILESYSTEM,
2671 sizeof(struct smb2_fs_full_size_info),
2672 &rsp_iov, &buftype, cifs_sb);
2676 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2677 buf->f_type = SMB2_SUPER_MAGIC;
2678 info = (struct smb2_fs_full_size_info *)(
2679 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2680 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2681 le32_to_cpu(rsp->OutputBufferLength),
2683 sizeof(struct smb2_fs_full_size_info));
2685 smb2_copy_fs_info_to_kstatfs(info, buf);
2688 trace_smb3_qfs_done(xid, tcon->tid, tcon->ses->Suid, tcon->tree_name, rc);
2689 free_rsp_buf(buftype, rsp_iov.iov_base);
2694 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2695 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2698 __le16 srch_path = 0; /* Null - open root of share */
2699 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2700 struct cifs_open_parms oparms;
2701 struct cifs_fid fid;
2703 if (!tcon->posix_extensions)
2704 return smb2_queryfs(xid, tcon, cifs_sb, buf);
2706 oparms = (struct cifs_open_parms) {
2709 .desired_access = FILE_READ_ATTRIBUTES,
2710 .disposition = FILE_OPEN,
2711 .create_options = cifs_create_options(cifs_sb, 0),
2715 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
2720 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2721 fid.volatile_fid, buf);
2722 buf->f_type = SMB2_SUPER_MAGIC;
2723 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2728 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2730 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2731 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2735 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2736 __u64 length, __u32 type, int lock, int unlock, bool wait)
2738 if (unlock && !lock)
2739 type = SMB2_LOCKFLAG_UNLOCK;
2740 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2741 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2742 current->tgid, length, offset, type, wait);
2746 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2748 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2752 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2754 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2758 smb2_new_lease_key(struct cifs_fid *fid)
2760 generate_random_uuid(fid->lease_key);
2764 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2765 const char *search_name,
2766 struct dfs_info3_param **target_nodes,
2767 unsigned int *num_of_nodes,
2768 const struct nls_table *nls_codepage, int remap)
2771 __le16 *utf16_path = NULL;
2772 int utf16_path_len = 0;
2773 struct cifs_tcon *tcon;
2774 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2775 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2776 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2777 int retry_count = 0;
2779 cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name);
2782 * Try to use the IPC tcon, otherwise just use any
2784 tcon = ses->tcon_ipc;
2786 spin_lock(&cifs_tcp_ses_lock);
2787 tcon = list_first_entry_or_null(&ses->tcon_list,
2792 spin_unlock(&cifs_tcp_ses_lock);
2796 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2802 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2804 nls_codepage, remap);
2810 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2811 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2817 /* Highest DFS referral version understood */
2818 dfs_req->MaxReferralLevel = DFS_VERSION;
2820 /* Path to resolve in an UTF-16 null-terminated string */
2821 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2824 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2825 FSCTL_DFS_GET_REFERRALS,
2826 (char *)dfs_req, dfs_req_size, CIFSMaxBufSize,
2827 (char **)&dfs_rsp, &dfs_rsp_size);
2828 if (!is_retryable_error(rc))
2830 usleep_range(512, 2048);
2831 } while (++retry_count < 5);
2834 if (!is_retryable_error(rc) && rc != -ENOENT && rc != -EOPNOTSUPP)
2835 cifs_tcon_dbg(VFS, "%s: ioctl error: rc=%d\n", __func__, rc);
2839 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
2840 num_of_nodes, target_nodes,
2841 nls_codepage, remap, search_name,
2842 true /* is_unicode */);
2844 cifs_tcon_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc);
2849 if (tcon && !tcon->ipc) {
2850 /* ipc tcons are not refcounted */
2851 spin_lock(&cifs_tcp_ses_lock);
2853 /* tc_count can never go negative */
2854 WARN_ON(tcon->tc_count < 0);
2855 spin_unlock(&cifs_tcp_ses_lock);
2864 parse_reparse_posix(struct reparse_posix_data *symlink_buf,
2865 u32 plen, char **target_path,
2866 struct cifs_sb_info *cifs_sb)
2870 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
2871 len = le16_to_cpu(symlink_buf->ReparseDataLength);
2873 if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
2874 cifs_dbg(VFS, "%lld not a supported symlink type\n",
2875 le64_to_cpu(symlink_buf->InodeType));
2879 *target_path = cifs_strndup_from_utf16(
2880 symlink_buf->PathBuffer,
2881 len, true, cifs_sb->local_nls);
2882 if (!(*target_path))
2885 convert_delimiter(*target_path, '/');
2886 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2892 parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
2893 u32 plen, char **target_path,
2894 struct cifs_sb_info *cifs_sb)
2896 unsigned int sub_len;
2897 unsigned int sub_offset;
2899 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */
2901 sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset);
2902 sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength);
2903 if (sub_offset + 20 > plen ||
2904 sub_offset + sub_len + 20 > plen) {
2905 cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
2909 *target_path = cifs_strndup_from_utf16(
2910 symlink_buf->PathBuffer + sub_offset,
2911 sub_len, true, cifs_sb->local_nls);
2912 if (!(*target_path))
2915 convert_delimiter(*target_path, '/');
2916 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2922 parse_reparse_point(struct reparse_data_buffer *buf,
2923 u32 plen, char **target_path,
2924 struct cifs_sb_info *cifs_sb)
2926 if (plen < sizeof(struct reparse_data_buffer)) {
2927 cifs_dbg(VFS, "reparse buffer is too small. Must be at least 8 bytes but was %d\n",
2932 if (plen < le16_to_cpu(buf->ReparseDataLength) +
2933 sizeof(struct reparse_data_buffer)) {
2934 cifs_dbg(VFS, "srv returned invalid reparse buf length: %d\n",
2939 /* See MS-FSCC 2.1.2 */
2940 switch (le32_to_cpu(buf->ReparseTag)) {
2941 case IO_REPARSE_TAG_NFS:
2942 return parse_reparse_posix(
2943 (struct reparse_posix_data *)buf,
2944 plen, target_path, cifs_sb);
2945 case IO_REPARSE_TAG_SYMLINK:
2946 return parse_reparse_symlink(
2947 (struct reparse_symlink_data_buffer *)buf,
2948 plen, target_path, cifs_sb);
2950 cifs_dbg(VFS, "srv returned unknown symlink buffer tag:0x%08x\n",
2951 le32_to_cpu(buf->ReparseTag));
2956 static int smb2_query_symlink(const unsigned int xid,
2957 struct cifs_tcon *tcon,
2958 struct cifs_sb_info *cifs_sb,
2959 const char *full_path,
2961 struct kvec *rsp_iov)
2963 struct reparse_data_buffer *buf;
2964 struct smb2_ioctl_rsp *io = rsp_iov->iov_base;
2965 u32 plen = le32_to_cpu(io->OutputCount);
2967 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2969 buf = (struct reparse_data_buffer *)((u8 *)io +
2970 le32_to_cpu(io->OutputOffset));
2971 return parse_reparse_point(buf, plen, target_path, cifs_sb);
2974 static int smb2_query_reparse_point(const unsigned int xid,
2975 struct cifs_tcon *tcon,
2976 struct cifs_sb_info *cifs_sb,
2977 const char *full_path,
2978 u32 *tag, struct kvec *rsp,
2981 struct smb2_compound_vars *vars;
2983 __le16 *utf16_path = NULL;
2984 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2985 struct cifs_open_parms oparms;
2986 struct cifs_fid fid;
2987 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2988 int flags = CIFS_CP_CREATE_CLOSE_OP;
2989 struct smb_rqst *rqst;
2990 int resp_buftype[3];
2991 struct kvec *rsp_iov;
2992 struct smb2_ioctl_rsp *ioctl_rsp;
2993 struct reparse_data_buffer *reparse_buf;
2996 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2998 if (smb3_encryption_required(tcon))
2999 flags |= CIFS_TRANSFORM_REQ;
3001 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
3005 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
3006 vars = kzalloc(sizeof(*vars), GFP_KERNEL);
3012 rsp_iov = vars->rsp_iov;
3015 * setup smb2open - TODO add optimization to call cifs_get_readable_path
3016 * to see if there is a handle already open that we can use
3018 rqst[0].rq_iov = vars->open_iov;
3019 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
3021 oparms = (struct cifs_open_parms) {
3024 .desired_access = FILE_READ_ATTRIBUTES,
3025 .disposition = FILE_OPEN,
3026 .create_options = cifs_create_options(cifs_sb, OPEN_REPARSE_POINT),
3030 rc = SMB2_open_init(tcon, server,
3031 &rqst[0], &oplock, &oparms, utf16_path);
3034 smb2_set_next_command(tcon, &rqst[0]);
3038 rqst[1].rq_iov = vars->io_iov;
3039 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3041 rc = SMB2_ioctl_init(tcon, server,
3042 &rqst[1], COMPOUND_FID,
3043 COMPOUND_FID, FSCTL_GET_REPARSE_POINT, NULL, 0,
3045 MAX_SMB2_CREATE_RESPONSE_SIZE -
3046 MAX_SMB2_CLOSE_RESPONSE_SIZE);
3050 smb2_set_next_command(tcon, &rqst[1]);
3051 smb2_set_related(&rqst[1]);
3054 rqst[2].rq_iov = &vars->close_iov;
3055 rqst[2].rq_nvec = 1;
3057 rc = SMB2_close_init(tcon, server,
3058 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3062 smb2_set_related(&rqst[2]);
3064 rc = compound_send_recv(xid, tcon->ses, server,
3066 resp_buftype, rsp_iov);
3068 ioctl_rsp = rsp_iov[1].iov_base;
3071 * Open was successful and we got an ioctl response.
3074 /* See MS-FSCC 2.3.23 */
3076 reparse_buf = (struct reparse_data_buffer *)
3077 ((char *)ioctl_rsp +
3078 le32_to_cpu(ioctl_rsp->OutputOffset));
3079 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3081 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3082 rsp_iov[1].iov_len) {
3083 cifs_tcon_dbg(FYI, "srv returned invalid ioctl len: %d\n",
3088 *tag = le32_to_cpu(reparse_buf->ReparseTag);
3090 *rsp_buftype = resp_buftype[1];
3091 resp_buftype[1] = CIFS_NO_BUFFER;
3095 SMB2_open_free(&rqst[0]);
3096 SMB2_ioctl_free(&rqst[1]);
3097 SMB2_close_free(&rqst[2]);
3098 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3099 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3100 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3107 static struct cifs_ntsd *
3108 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
3109 const struct cifs_fid *cifsfid, u32 *pacllen, u32 info)
3111 struct cifs_ntsd *pntsd = NULL;
3113 int rc = -EOPNOTSUPP;
3114 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3117 return ERR_CAST(tlink);
3120 cifs_dbg(FYI, "trying to get acl\n");
3122 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
3123 cifsfid->volatile_fid, (void **)&pntsd, pacllen,
3127 cifs_put_tlink(tlink);
3129 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3136 static struct cifs_ntsd *
3137 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
3138 const char *path, u32 *pacllen, u32 info)
3140 struct cifs_ntsd *pntsd = NULL;
3141 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3144 struct cifs_tcon *tcon;
3145 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3146 struct cifs_fid fid;
3147 struct cifs_open_parms oparms;
3150 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
3152 return ERR_CAST(tlink);
3154 tcon = tlink_tcon(tlink);
3157 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3164 oparms = (struct cifs_open_parms) {
3167 .desired_access = READ_CONTROL,
3168 .disposition = FILE_OPEN,
3170 * When querying an ACL, even if the file is a symlink
3171 * we want to open the source not the target, and so
3172 * the protocol requires that the client specify this
3173 * flag when opening a reparse point
3175 .create_options = cifs_create_options(cifs_sb, 0) |
3180 if (info & SACL_SECINFO)
3181 oparms.desired_access |= SYSTEM_SECURITY;
3183 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
3187 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3188 fid.volatile_fid, (void **)&pntsd, pacllen,
3190 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3193 cifs_put_tlink(tlink);
3196 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3203 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
3204 struct inode *inode, const char *path, int aclflag)
3206 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3208 int rc, access_flags = 0;
3209 struct cifs_tcon *tcon;
3210 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
3211 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3212 struct cifs_fid fid;
3213 struct cifs_open_parms oparms;
3216 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
3218 return PTR_ERR(tlink);
3220 tcon = tlink_tcon(tlink);
3223 if (aclflag & CIFS_ACL_OWNER || aclflag & CIFS_ACL_GROUP)
3224 access_flags |= WRITE_OWNER;
3225 if (aclflag & CIFS_ACL_SACL)
3226 access_flags |= SYSTEM_SECURITY;
3227 if (aclflag & CIFS_ACL_DACL)
3228 access_flags |= WRITE_DAC;
3230 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3237 oparms = (struct cifs_open_parms) {
3239 .desired_access = access_flags,
3240 .create_options = cifs_create_options(cifs_sb, 0),
3241 .disposition = FILE_OPEN,
3246 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
3250 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3251 fid.volatile_fid, pnntsd, acllen, aclflag);
3252 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3255 cifs_put_tlink(tlink);
3260 /* Retrieve an ACL from the server */
3261 static struct cifs_ntsd *
3262 get_smb2_acl(struct cifs_sb_info *cifs_sb,
3263 struct inode *inode, const char *path,
3264 u32 *pacllen, u32 info)
3266 struct cifs_ntsd *pntsd = NULL;
3267 struct cifsFileInfo *open_file = NULL;
3269 if (inode && !(info & SACL_SECINFO))
3270 open_file = find_readable_file(CIFS_I(inode), true);
3271 if (!open_file || (info & SACL_SECINFO))
3272 return get_smb2_acl_by_path(cifs_sb, path, pacllen, info);
3274 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen, info);
3275 cifsFileInfo_put(open_file);
3279 static long smb3_zero_data(struct file *file, struct cifs_tcon *tcon,
3280 loff_t offset, loff_t len, unsigned int xid)
3282 struct cifsFileInfo *cfile = file->private_data;
3283 struct file_zero_data_information fsctl_buf;
3285 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3287 fsctl_buf.FileOffset = cpu_to_le64(offset);
3288 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3290 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3291 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3293 sizeof(struct file_zero_data_information),
3297 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3298 loff_t offset, loff_t len, bool keep_size)
3300 struct cifs_ses *ses = tcon->ses;
3301 struct inode *inode = file_inode(file);
3302 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3303 struct cifsFileInfo *cfile = file->private_data;
3310 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3311 ses->Suid, offset, len);
3314 filemap_invalidate_lock(inode->i_mapping);
3317 * We zero the range through ioctl, so we need remove the page caches
3318 * first, otherwise the data may be inconsistent with the server.
3320 truncate_pagecache_range(inode, offset, offset + len - 1);
3322 /* if file not oplocked can't be sure whether asking to extend size */
3324 if (keep_size == false && !CIFS_CACHE_READ(cifsi))
3325 goto zero_range_exit;
3327 rc = smb3_zero_data(file, tcon, offset, len, xid);
3329 goto zero_range_exit;
3332 * do we also need to change the size of the file?
3334 if (keep_size == false && i_size_read(inode) < offset + len) {
3335 eof = cpu_to_le64(offset + len);
3336 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3337 cfile->fid.volatile_fid, cfile->pid, &eof);
3341 filemap_invalidate_unlock(inode->i_mapping);
3342 inode_unlock(inode);
3345 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
3346 ses->Suid, offset, len, rc);
3348 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
3349 ses->Suid, offset, len);
3353 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
3354 loff_t offset, loff_t len)
3356 struct inode *inode = file_inode(file);
3357 struct cifsFileInfo *cfile = file->private_data;
3358 struct file_zero_data_information fsctl_buf;
3361 __u8 set_sparse = 1;
3366 /* Need to make file sparse, if not already, before freeing range. */
3367 /* Consider adding equivalent for compressed since it could also work */
3368 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
3373 filemap_invalidate_lock(inode->i_mapping);
3375 * We implement the punch hole through ioctl, so we need remove the page
3376 * caches first, otherwise the data may be inconsistent with the server.
3378 truncate_pagecache_range(inode, offset, offset + len - 1);
3380 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3382 fsctl_buf.FileOffset = cpu_to_le64(offset);
3383 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3385 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3386 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3388 sizeof(struct file_zero_data_information),
3389 CIFSMaxBufSize, NULL, NULL);
3390 filemap_invalidate_unlock(inode->i_mapping);
3392 inode_unlock(inode);
3397 static int smb3_simple_fallocate_write_range(unsigned int xid,
3398 struct cifs_tcon *tcon,
3399 struct cifsFileInfo *cfile,
3400 loff_t off, loff_t len,
3403 struct cifs_io_parms io_parms = {0};
3408 io_parms.netfid = cfile->fid.netfid;
3409 io_parms.pid = current->tgid;
3410 io_parms.tcon = tcon;
3411 io_parms.persistent_fid = cfile->fid.persistent_fid;
3412 io_parms.volatile_fid = cfile->fid.volatile_fid;
3415 io_parms.offset = off;
3416 io_parms.length = len;
3417 if (io_parms.length > SMB2_MAX_BUFFER_SIZE)
3418 io_parms.length = SMB2_MAX_BUFFER_SIZE;
3419 /* iov[0] is reserved for smb header */
3420 iov[1].iov_base = buf;
3421 iov[1].iov_len = io_parms.length;
3422 rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
3434 static int smb3_simple_fallocate_range(unsigned int xid,
3435 struct cifs_tcon *tcon,
3436 struct cifsFileInfo *cfile,
3437 loff_t off, loff_t len)
3439 struct file_allocated_range_buffer in_data, *out_data = NULL, *tmp_data;
3445 in_data.file_offset = cpu_to_le64(off);
3446 in_data.length = cpu_to_le64(len);
3447 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3448 cfile->fid.volatile_fid,
3449 FSCTL_QUERY_ALLOCATED_RANGES,
3450 (char *)&in_data, sizeof(in_data),
3451 1024 * sizeof(struct file_allocated_range_buffer),
3452 (char **)&out_data, &out_data_len);
3456 buf = kzalloc(1024 * 1024, GFP_KERNEL);
3462 tmp_data = out_data;
3465 * The rest of the region is unmapped so write it all.
3467 if (out_data_len == 0) {
3468 rc = smb3_simple_fallocate_write_range(xid, tcon,
3469 cfile, off, len, buf);
3473 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3478 if (off < le64_to_cpu(tmp_data->file_offset)) {
3480 * We are at a hole. Write until the end of the region
3481 * or until the next allocated data,
3482 * whichever comes next.
3484 l = le64_to_cpu(tmp_data->file_offset) - off;
3487 rc = smb3_simple_fallocate_write_range(xid, tcon,
3488 cfile, off, l, buf);
3497 * We are at a section of allocated data, just skip forward
3498 * until the end of the data or the end of the region
3499 * we are supposed to fallocate, whichever comes first.
3501 l = le64_to_cpu(tmp_data->length);
3507 tmp_data = &tmp_data[1];
3508 out_data_len -= sizeof(struct file_allocated_range_buffer);
3518 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3519 loff_t off, loff_t len, bool keep_size)
3521 struct inode *inode;
3522 struct cifsInodeInfo *cifsi;
3523 struct cifsFileInfo *cfile = file->private_data;
3524 long rc = -EOPNOTSUPP;
3530 inode = d_inode(cfile->dentry);
3531 cifsi = CIFS_I(inode);
3533 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3534 tcon->ses->Suid, off, len);
3535 /* if file not oplocked can't be sure whether asking to extend size */
3536 if (!CIFS_CACHE_READ(cifsi))
3537 if (keep_size == false) {
3538 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3539 tcon->tid, tcon->ses->Suid, off, len, rc);
3545 * Extending the file
3547 if ((keep_size == false) && i_size_read(inode) < off + len) {
3548 rc = inode_newsize_ok(inode, off + len);
3552 if (cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)
3553 smb2_set_sparse(xid, tcon, cfile, inode, false);
3555 eof = cpu_to_le64(off + len);
3556 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3557 cfile->fid.volatile_fid, cfile->pid, &eof);
3559 cifsi->server_eof = off + len;
3560 cifs_setsize(inode, off + len);
3561 cifs_truncate_page(inode->i_mapping, inode->i_size);
3562 truncate_setsize(inode, off + len);
3568 * Files are non-sparse by default so falloc may be a no-op
3569 * Must check if file sparse. If not sparse, and since we are not
3570 * extending then no need to do anything since file already allocated
3572 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
3577 if (keep_size == true) {
3579 * We can not preallocate pages beyond the end of the file
3582 if (off >= i_size_read(inode)) {
3587 * For fallocates that are partially beyond the end of file,
3588 * clamp len so we only fallocate up to the end of file.
3590 if (off + len > i_size_read(inode)) {
3591 len = i_size_read(inode) - off;
3595 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3597 * At this point, we are trying to fallocate an internal
3598 * regions of a sparse file. Since smb2 does not have a
3599 * fallocate command we have two otions on how to emulate this.
3600 * We can either turn the entire file to become non-sparse
3601 * which we only do if the fallocate is for virtually
3602 * the whole file, or we can overwrite the region with zeroes
3603 * using SMB2_write, which could be prohibitevly expensive
3607 * We are only trying to fallocate a small region so
3608 * just write it with zero.
3610 if (len <= 1024 * 1024) {
3611 rc = smb3_simple_fallocate_range(xid, tcon, cfile,
3617 * Check if falloc starts within first few pages of file
3618 * and ends within a few pages of the end of file to
3619 * ensure that most of file is being forced to be
3620 * fallocated now. If so then setting whole file sparse
3621 * ie potentially making a few extra pages at the beginning
3622 * or end of the file non-sparse via set_sparse is harmless.
3624 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
3630 smb2_set_sparse(xid, tcon, cfile, inode, false);
3635 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3636 tcon->ses->Suid, off, len, rc);
3638 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3639 tcon->ses->Suid, off, len);
3645 static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
3646 loff_t off, loff_t len)
3650 struct inode *inode = file_inode(file);
3651 struct cifsFileInfo *cfile = file->private_data;
3652 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3660 old_eof = i_size_read(inode);
3661 if ((off >= old_eof) ||
3662 off + len >= old_eof) {
3667 filemap_invalidate_lock(inode->i_mapping);
3668 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof - 1);
3672 truncate_pagecache_range(inode, off, old_eof);
3674 rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
3675 old_eof - off - len, off);
3679 eof = cpu_to_le64(old_eof - len);
3680 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3681 cfile->fid.volatile_fid, cfile->pid, &eof);
3687 cifsi->server_eof = i_size_read(inode) - len;
3688 truncate_setsize(inode, cifsi->server_eof);
3689 fscache_resize_cookie(cifs_inode_cookie(inode), cifsi->server_eof);
3691 filemap_invalidate_unlock(inode->i_mapping);
3693 inode_unlock(inode);
3698 static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
3699 loff_t off, loff_t len)
3703 struct cifsFileInfo *cfile = file->private_data;
3704 struct inode *inode = file_inode(file);
3706 __u64 count, old_eof;
3712 old_eof = i_size_read(inode);
3713 if (off >= old_eof) {
3718 count = old_eof - off;
3719 eof = cpu_to_le64(old_eof + len);
3721 filemap_invalidate_lock(inode->i_mapping);
3722 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof + len - 1);
3725 truncate_pagecache_range(inode, off, old_eof);
3727 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3728 cfile->fid.volatile_fid, cfile->pid, &eof);
3732 rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len);
3736 rc = smb3_zero_data(file, tcon, off, len, xid);
3742 filemap_invalidate_unlock(inode->i_mapping);
3744 inode_unlock(inode);
3749 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3751 struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3752 struct cifsInodeInfo *cifsi;
3753 struct inode *inode;
3755 struct file_allocated_range_buffer in_data, *out_data = NULL;
3759 if (whence != SEEK_HOLE && whence != SEEK_DATA)
3760 return generic_file_llseek(file, offset, whence);
3762 inode = d_inode(cfile->dentry);
3763 cifsi = CIFS_I(inode);
3765 if (offset < 0 || offset >= i_size_read(inode))
3770 * We need to be sure that all dirty pages are written as they
3771 * might fill holes on the server.
3772 * Note that we also MUST flush any written pages since at least
3773 * some servers (Windows2016) will not reflect recent writes in
3774 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3776 wrcfile = find_writable_file(cifsi, FIND_WR_ANY);
3778 filemap_write_and_wait(inode->i_mapping);
3779 smb2_flush_file(xid, tcon, &wrcfile->fid);
3780 cifsFileInfo_put(wrcfile);
3783 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3784 if (whence == SEEK_HOLE)
3785 offset = i_size_read(inode);
3789 in_data.file_offset = cpu_to_le64(offset);
3790 in_data.length = cpu_to_le64(i_size_read(inode));
3792 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3793 cfile->fid.volatile_fid,
3794 FSCTL_QUERY_ALLOCATED_RANGES,
3795 (char *)&in_data, sizeof(in_data),
3796 sizeof(struct file_allocated_range_buffer),
3797 (char **)&out_data, &out_data_len);
3803 if (whence == SEEK_HOLE && out_data_len == 0)
3806 if (whence == SEEK_DATA && out_data_len == 0) {
3811 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3815 if (whence == SEEK_DATA) {
3816 offset = le64_to_cpu(out_data->file_offset);
3819 if (offset < le64_to_cpu(out_data->file_offset))
3822 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3828 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3833 static int smb3_fiemap(struct cifs_tcon *tcon,
3834 struct cifsFileInfo *cfile,
3835 struct fiemap_extent_info *fei, u64 start, u64 len)
3838 struct file_allocated_range_buffer in_data, *out_data;
3840 int i, num, rc, flags, last_blob;
3843 rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0);
3849 in_data.file_offset = cpu_to_le64(start);
3850 in_data.length = cpu_to_le64(len);
3852 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3853 cfile->fid.volatile_fid,
3854 FSCTL_QUERY_ALLOCATED_RANGES,
3855 (char *)&in_data, sizeof(in_data),
3856 1024 * sizeof(struct file_allocated_range_buffer),
3857 (char **)&out_data, &out_data_len);
3866 if (out_data_len && out_data_len < sizeof(struct file_allocated_range_buffer)) {
3870 if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3875 num = out_data_len / sizeof(struct file_allocated_range_buffer);
3876 for (i = 0; i < num; i++) {
3878 if (i == num - 1 && last_blob)
3879 flags |= FIEMAP_EXTENT_LAST;
3881 rc = fiemap_fill_next_extent(fei,
3882 le64_to_cpu(out_data[i].file_offset),
3883 le64_to_cpu(out_data[i].file_offset),
3884 le64_to_cpu(out_data[i].length),
3895 next = le64_to_cpu(out_data[num - 1].file_offset) +
3896 le64_to_cpu(out_data[num - 1].length);
3897 len = len - (next - start);
3908 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
3909 loff_t off, loff_t len)
3911 /* KEEP_SIZE already checked for by do_fallocate */
3912 if (mode & FALLOC_FL_PUNCH_HOLE)
3913 return smb3_punch_hole(file, tcon, off, len);
3914 else if (mode & FALLOC_FL_ZERO_RANGE) {
3915 if (mode & FALLOC_FL_KEEP_SIZE)
3916 return smb3_zero_range(file, tcon, off, len, true);
3917 return smb3_zero_range(file, tcon, off, len, false);
3918 } else if (mode == FALLOC_FL_KEEP_SIZE)
3919 return smb3_simple_falloc(file, tcon, off, len, true);
3920 else if (mode == FALLOC_FL_COLLAPSE_RANGE)
3921 return smb3_collapse_range(file, tcon, off, len);
3922 else if (mode == FALLOC_FL_INSERT_RANGE)
3923 return smb3_insert_range(file, tcon, off, len);
3925 return smb3_simple_falloc(file, tcon, off, len, false);
3931 smb2_downgrade_oplock(struct TCP_Server_Info *server,
3932 struct cifsInodeInfo *cinode, __u32 oplock,
3933 unsigned int epoch, bool *purge_cache)
3935 server->ops->set_oplock_level(cinode, oplock, 0, NULL);
3939 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3940 unsigned int epoch, bool *purge_cache);
3943 smb3_downgrade_oplock(struct TCP_Server_Info *server,
3944 struct cifsInodeInfo *cinode, __u32 oplock,
3945 unsigned int epoch, bool *purge_cache)
3947 unsigned int old_state = cinode->oplock;
3948 unsigned int old_epoch = cinode->epoch;
3949 unsigned int new_state;
3951 if (epoch > old_epoch) {
3952 smb21_set_oplock_level(cinode, oplock, 0, NULL);
3953 cinode->epoch = epoch;
3956 new_state = cinode->oplock;
3957 *purge_cache = false;
3959 if ((old_state & CIFS_CACHE_READ_FLG) != 0 &&
3960 (new_state & CIFS_CACHE_READ_FLG) == 0)
3961 *purge_cache = true;
3962 else if (old_state == new_state && (epoch - old_epoch > 1))
3963 *purge_cache = true;
3967 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3968 unsigned int epoch, bool *purge_cache)
3971 cinode->lease_granted = false;
3972 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3974 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
3975 cinode->oplock = CIFS_CACHE_RHW_FLG;
3976 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
3977 &cinode->netfs.inode);
3978 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
3979 cinode->oplock = CIFS_CACHE_RW_FLG;
3980 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
3981 &cinode->netfs.inode);
3982 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
3983 cinode->oplock = CIFS_CACHE_READ_FLG;
3984 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
3985 &cinode->netfs.inode);
3991 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3992 unsigned int epoch, bool *purge_cache)
3994 char message[5] = {0};
3995 unsigned int new_oplock = 0;
3998 cinode->lease_granted = true;
3999 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
4002 /* Check if the server granted an oplock rather than a lease */
4003 if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4004 return smb2_set_oplock_level(cinode, oplock, epoch,
4007 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
4008 new_oplock |= CIFS_CACHE_READ_FLG;
4009 strcat(message, "R");
4011 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
4012 new_oplock |= CIFS_CACHE_HANDLE_FLG;
4013 strcat(message, "H");
4015 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
4016 new_oplock |= CIFS_CACHE_WRITE_FLG;
4017 strcat(message, "W");
4020 strncpy(message, "None", sizeof(message));
4022 cinode->oplock = new_oplock;
4023 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
4024 &cinode->netfs.inode);
4028 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4029 unsigned int epoch, bool *purge_cache)
4031 unsigned int old_oplock = cinode->oplock;
4033 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
4036 *purge_cache = false;
4037 if (old_oplock == CIFS_CACHE_READ_FLG) {
4038 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
4039 (epoch - cinode->epoch > 0))
4040 *purge_cache = true;
4041 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4042 (epoch - cinode->epoch > 1))
4043 *purge_cache = true;
4044 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4045 (epoch - cinode->epoch > 1))
4046 *purge_cache = true;
4047 else if (cinode->oplock == 0 &&
4048 (epoch - cinode->epoch > 0))
4049 *purge_cache = true;
4050 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
4051 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4052 (epoch - cinode->epoch > 0))
4053 *purge_cache = true;
4054 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4055 (epoch - cinode->epoch > 1))
4056 *purge_cache = true;
4058 cinode->epoch = epoch;
4062 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
4064 smb2_is_read_op(__u32 oplock)
4066 return oplock == SMB2_OPLOCK_LEVEL_II;
4068 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
4071 smb21_is_read_op(__u32 oplock)
4073 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
4074 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
4078 map_oplock_to_lease(u8 oplock)
4080 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4081 return SMB2_LEASE_WRITE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE;
4082 else if (oplock == SMB2_OPLOCK_LEVEL_II)
4083 return SMB2_LEASE_READ_CACHING_LE;
4084 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
4085 return SMB2_LEASE_HANDLE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE |
4086 SMB2_LEASE_WRITE_CACHING_LE;
4091 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
4093 struct create_lease *buf;
4095 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
4099 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4100 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4102 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4103 (struct create_lease, lcontext));
4104 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
4105 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4106 (struct create_lease, Name));
4107 buf->ccontext.NameLength = cpu_to_le16(4);
4108 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4117 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
4119 struct create_lease_v2 *buf;
4121 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
4125 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4126 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4128 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4129 (struct create_lease_v2, lcontext));
4130 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
4131 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4132 (struct create_lease_v2, Name));
4133 buf->ccontext.NameLength = cpu_to_le16(4);
4134 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4143 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4145 struct create_lease *lc = (struct create_lease *)buf;
4147 *epoch = 0; /* not used */
4148 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4149 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4150 return le32_to_cpu(lc->lcontext.LeaseState);
4154 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4156 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
4158 *epoch = le16_to_cpu(lc->lcontext.Epoch);
4159 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4160 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4162 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
4163 return le32_to_cpu(lc->lcontext.LeaseState);
4167 smb2_wp_retry_size(struct inode *inode)
4169 return min_t(unsigned int, CIFS_SB(inode->i_sb)->ctx->wsize,
4170 SMB2_MAX_BUFFER_SIZE);
4174 smb2_dir_needs_close(struct cifsFileInfo *cfile)
4176 return !cfile->invalidHandle;
4180 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
4181 struct smb_rqst *old_rq, __le16 cipher_type)
4183 struct smb2_hdr *shdr =
4184 (struct smb2_hdr *)old_rq->rq_iov[0].iov_base;
4186 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
4187 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
4188 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
4189 tr_hdr->Flags = cpu_to_le16(0x01);
4190 if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4191 (cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4192 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4194 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4195 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
4198 static void *smb2_aead_req_alloc(struct crypto_aead *tfm, const struct smb_rqst *rqst,
4199 int num_rqst, const u8 *sig, u8 **iv,
4200 struct aead_request **req, struct sg_table *sgt,
4201 unsigned int *num_sgs, size_t *sensitive_size)
4203 unsigned int req_size = sizeof(**req) + crypto_aead_reqsize(tfm);
4204 unsigned int iv_size = crypto_aead_ivsize(tfm);
4208 *num_sgs = cifs_get_num_sgs(rqst, num_rqst, sig);
4209 if (IS_ERR_VALUE((long)(int)*num_sgs))
4210 return ERR_PTR(*num_sgs);
4213 len += crypto_aead_alignmask(tfm) & ~(crypto_tfm_ctx_alignment() - 1);
4214 len = ALIGN(len, crypto_tfm_ctx_alignment());
4216 len = ALIGN(len, __alignof__(struct scatterlist));
4217 len += array_size(*num_sgs, sizeof(struct scatterlist));
4218 *sensitive_size = len;
4220 p = kvzalloc(len, GFP_NOFS);
4222 return ERR_PTR(-ENOMEM);
4224 *iv = (u8 *)PTR_ALIGN(p, crypto_aead_alignmask(tfm) + 1);
4225 *req = (struct aead_request *)PTR_ALIGN(*iv + iv_size,
4226 crypto_tfm_ctx_alignment());
4227 sgt->sgl = (struct scatterlist *)PTR_ALIGN((u8 *)*req + req_size,
4228 __alignof__(struct scatterlist));
4232 static void *smb2_get_aead_req(struct crypto_aead *tfm, struct smb_rqst *rqst,
4233 int num_rqst, const u8 *sig, u8 **iv,
4234 struct aead_request **req, struct scatterlist **sgl,
4235 size_t *sensitive_size)
4237 struct sg_table sgtable = {};
4238 unsigned int skip, num_sgs, i, j;
4242 p = smb2_aead_req_alloc(tfm, rqst, num_rqst, sig, iv, req, &sgtable,
4243 &num_sgs, sensitive_size);
4247 sg_init_marker(sgtable.sgl, num_sgs);
4250 * The first rqst has a transform header where the
4251 * first 20 bytes are not part of the encrypted blob.
4255 for (i = 0; i < num_rqst; i++) {
4256 struct iov_iter *iter = &rqst[i].rq_iter;
4257 size_t count = iov_iter_count(iter);
4259 for (j = 0; j < rqst[i].rq_nvec; j++) {
4260 cifs_sg_set_buf(&sgtable,
4261 rqst[i].rq_iov[j].iov_base + skip,
4262 rqst[i].rq_iov[j].iov_len - skip);
4264 /* See the above comment on the 'skip' assignment */
4267 sgtable.orig_nents = sgtable.nents;
4269 rc = extract_iter_to_sg(iter, count, &sgtable,
4270 num_sgs - sgtable.nents, 0);
4271 iov_iter_revert(iter, rc);
4272 sgtable.orig_nents = sgtable.nents;
4275 cifs_sg_set_buf(&sgtable, sig, SMB2_SIGNATURE_SIZE);
4276 sg_mark_end(&sgtable.sgl[sgtable.nents - 1]);
4282 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
4284 struct TCP_Server_Info *pserver;
4285 struct cifs_ses *ses;
4288 /* If server is a channel, select the primary channel */
4289 pserver = SERVER_IS_CHAN(server) ? server->primary_server : server;
4291 spin_lock(&cifs_tcp_ses_lock);
4292 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
4293 if (ses->Suid == ses_id) {
4294 spin_lock(&ses->ses_lock);
4295 ses_enc_key = enc ? ses->smb3encryptionkey :
4296 ses->smb3decryptionkey;
4297 memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE);
4298 spin_unlock(&ses->ses_lock);
4299 spin_unlock(&cifs_tcp_ses_lock);
4303 spin_unlock(&cifs_tcp_ses_lock);
4305 trace_smb3_ses_not_found(ses_id);
4310 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
4311 * iov[0] - transform header (associate data),
4312 * iov[1-N] - SMB2 header and pages - data to encrypt.
4313 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4317 crypt_message(struct TCP_Server_Info *server, int num_rqst,
4318 struct smb_rqst *rqst, int enc)
4320 struct smb2_transform_hdr *tr_hdr =
4321 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
4322 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
4324 struct scatterlist *sg;
4325 u8 sign[SMB2_SIGNATURE_SIZE] = {};
4326 u8 key[SMB3_ENC_DEC_KEY_SIZE];
4327 struct aead_request *req;
4329 DECLARE_CRYPTO_WAIT(wait);
4330 struct crypto_aead *tfm;
4331 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4333 size_t sensitive_size;
4335 rc = smb2_get_enc_key(server, le64_to_cpu(tr_hdr->SessionId), enc, key);
4337 cifs_server_dbg(FYI, "%s: Could not get %scryption key. sid: 0x%llx\n", __func__,
4338 enc ? "en" : "de", le64_to_cpu(tr_hdr->SessionId));
4342 rc = smb3_crypto_aead_allocate(server);
4344 cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
4348 tfm = enc ? server->secmech.enc : server->secmech.dec;
4350 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
4351 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4352 rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
4354 rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE);
4357 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
4361 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
4363 cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
4367 creq = smb2_get_aead_req(tfm, rqst, num_rqst, sign, &iv, &req, &sg,
4370 return PTR_ERR(creq);
4373 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
4374 crypt_len += SMB2_SIGNATURE_SIZE;
4377 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4378 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4379 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4382 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4385 aead_request_set_tfm(req, tfm);
4386 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
4387 aead_request_set_ad(req, assoc_data_len);
4389 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
4390 crypto_req_done, &wait);
4392 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
4393 : crypto_aead_decrypt(req), &wait);
4396 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
4398 kvfree_sensitive(creq, sensitive_size);
4403 * Clear a read buffer, discarding the folios which have XA_MARK_0 set.
4405 static void cifs_clear_xarray_buffer(struct xarray *buffer)
4407 struct folio *folio;
4409 XA_STATE(xas, buffer, 0);
4412 xas_for_each_marked(&xas, folio, ULONG_MAX, XA_MARK_0) {
4420 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
4424 for (i = 0; i < num_rqst; i++)
4425 if (!xa_empty(&rqst[i].rq_buffer))
4426 cifs_clear_xarray_buffer(&rqst[i].rq_buffer);
4430 * This function will initialize new_rq and encrypt the content.
4431 * The first entry, new_rq[0], only contains a single iov which contains
4432 * a smb2_transform_hdr and is pre-allocated by the caller.
4433 * This function then populates new_rq[1+] with the content from olq_rq[0+].
4435 * The end result is an array of smb_rqst structures where the first structure
4436 * only contains a single iov for the transform header which we then can pass
4437 * to crypt_message().
4439 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4440 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
4443 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
4444 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
4446 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
4448 unsigned int orig_len = 0;
4452 for (i = 1; i < num_rqst; i++) {
4453 struct smb_rqst *old = &old_rq[i - 1];
4454 struct smb_rqst *new = &new_rq[i];
4455 struct xarray *buffer = &new->rq_buffer;
4456 size_t size = iov_iter_count(&old->rq_iter), seg, copied = 0;
4458 orig_len += smb_rqst_len(server, old);
4459 new->rq_iov = old->rq_iov;
4460 new->rq_nvec = old->rq_nvec;
4465 unsigned int npages = DIV_ROUND_UP(size, PAGE_SIZE);
4467 for (j = 0; j < npages; j++) {
4471 page = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4475 o = xa_store(buffer, j, page, GFP_KERNEL);
4482 xa_set_mark(buffer, j, XA_MARK_0);
4484 seg = min_t(size_t, size - copied, PAGE_SIZE);
4485 if (copy_page_from_iter(page, 0, seg, &old->rq_iter) != seg) {
4491 iov_iter_xarray(&new->rq_iter, ITER_SOURCE,
4493 new->rq_iter_size = size;
4497 /* fill the 1st iov with a transform header */
4498 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
4500 rc = crypt_message(server, num_rqst, new_rq, 1);
4501 cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
4508 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
4513 smb3_is_transform_hdr(void *buf)
4515 struct smb2_transform_hdr *trhdr = buf;
4517 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
4521 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
4522 unsigned int buf_data_size, struct iov_iter *iter,
4526 struct smb_rqst rqst = {NULL};
4527 size_t iter_size = 0;
4530 iov[0].iov_base = buf;
4531 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
4532 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
4533 iov[1].iov_len = buf_data_size;
4538 rqst.rq_iter = *iter;
4539 rqst.rq_iter_size = iov_iter_count(iter);
4540 iter_size = iov_iter_count(iter);
4543 rc = crypt_message(server, 1, &rqst, 0);
4544 cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
4549 memmove(buf, iov[1].iov_base, buf_data_size);
4552 server->total_read = buf_data_size + iter_size;
4558 cifs_copy_pages_to_iter(struct xarray *pages, unsigned int data_size,
4559 unsigned int skip, struct iov_iter *iter)
4562 unsigned long index;
4564 xa_for_each(pages, index, page) {
4565 size_t n, len = min_t(unsigned int, PAGE_SIZE - skip, data_size);
4567 n = copy_page_to_iter(page, skip, len, iter);
4569 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
4580 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
4581 char *buf, unsigned int buf_len, struct xarray *pages,
4582 unsigned int pages_len, bool is_offloaded)
4584 unsigned int data_offset;
4585 unsigned int data_len;
4586 unsigned int cur_off;
4587 unsigned int cur_page_idx;
4588 unsigned int pad_len;
4589 struct cifs_readdata *rdata = mid->callback_data;
4590 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
4592 bool use_rdma_mr = false;
4594 if (shdr->Command != SMB2_READ) {
4595 cifs_server_dbg(VFS, "only big read responses are supported\n");
4599 if (server->ops->is_session_expired &&
4600 server->ops->is_session_expired(buf)) {
4602 cifs_reconnect(server, true);
4606 if (server->ops->is_status_pending &&
4607 server->ops->is_status_pending(buf, server))
4610 /* set up first two iov to get credits */
4611 rdata->iov[0].iov_base = buf;
4612 rdata->iov[0].iov_len = 0;
4613 rdata->iov[1].iov_base = buf;
4614 rdata->iov[1].iov_len =
4615 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
4616 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
4617 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
4618 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
4619 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
4621 rdata->result = server->ops->map_error(buf, true);
4622 if (rdata->result != 0) {
4623 cifs_dbg(FYI, "%s: server returned error %d\n",
4624 __func__, rdata->result);
4625 /* normal error on read response */
4627 mid->mid_state = MID_RESPONSE_RECEIVED;
4629 dequeue_mid(mid, false);
4633 data_offset = server->ops->read_data_offset(buf);
4634 #ifdef CONFIG_CIFS_SMB_DIRECT
4635 use_rdma_mr = rdata->mr;
4637 data_len = server->ops->read_data_length(buf, use_rdma_mr);
4639 if (data_offset < server->vals->read_rsp_size) {
4641 * win2k8 sometimes sends an offset of 0 when the read
4642 * is beyond the EOF. Treat it as if the data starts just after
4645 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
4646 __func__, data_offset);
4647 data_offset = server->vals->read_rsp_size;
4648 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
4649 /* data_offset is beyond the end of smallbuf */
4650 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
4651 __func__, data_offset);
4652 rdata->result = -EIO;
4654 mid->mid_state = MID_RESPONSE_MALFORMED;
4656 dequeue_mid(mid, rdata->result);
4660 pad_len = data_offset - server->vals->read_rsp_size;
4662 if (buf_len <= data_offset) {
4663 /* read response payload is in pages */
4664 cur_page_idx = pad_len / PAGE_SIZE;
4665 cur_off = pad_len % PAGE_SIZE;
4667 if (cur_page_idx != 0) {
4668 /* data offset is beyond the 1st page of response */
4669 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
4670 __func__, data_offset);
4671 rdata->result = -EIO;
4673 mid->mid_state = MID_RESPONSE_MALFORMED;
4675 dequeue_mid(mid, rdata->result);
4679 if (data_len > pages_len - pad_len) {
4680 /* data_len is corrupt -- discard frame */
4681 rdata->result = -EIO;
4683 mid->mid_state = MID_RESPONSE_MALFORMED;
4685 dequeue_mid(mid, rdata->result);
4689 /* Copy the data to the output I/O iterator. */
4690 rdata->result = cifs_copy_pages_to_iter(pages, pages_len,
4691 cur_off, &rdata->iter);
4692 if (rdata->result != 0) {
4694 mid->mid_state = MID_RESPONSE_MALFORMED;
4696 dequeue_mid(mid, rdata->result);
4699 rdata->got_bytes = pages_len;
4701 } else if (buf_len >= data_offset + data_len) {
4702 /* read response payload is in buf */
4703 WARN_ONCE(pages && !xa_empty(pages),
4704 "read data can be either in buf or in pages");
4705 length = copy_to_iter(buf + data_offset, data_len, &rdata->iter);
4708 rdata->got_bytes = data_len;
4710 /* read response payload cannot be in both buf and pages */
4711 WARN_ONCE(1, "buf can not contain only a part of read data");
4712 rdata->result = -EIO;
4714 mid->mid_state = MID_RESPONSE_MALFORMED;
4716 dequeue_mid(mid, rdata->result);
4721 mid->mid_state = MID_RESPONSE_RECEIVED;
4723 dequeue_mid(mid, false);
4727 struct smb2_decrypt_work {
4728 struct work_struct decrypt;
4729 struct TCP_Server_Info *server;
4730 struct xarray buffer;
4736 static void smb2_decrypt_offload(struct work_struct *work)
4738 struct smb2_decrypt_work *dw = container_of(work,
4739 struct smb2_decrypt_work, decrypt);
4741 struct mid_q_entry *mid;
4742 struct iov_iter iter;
4744 iov_iter_xarray(&iter, ITER_DEST, &dw->buffer, 0, dw->len);
4745 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
4748 cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
4752 dw->server->lstrp = jiffies;
4753 mid = smb2_find_dequeue_mid(dw->server, dw->buf);
4755 cifs_dbg(FYI, "mid not found\n");
4757 mid->decrypted = true;
4758 rc = handle_read_data(dw->server, mid, dw->buf,
4759 dw->server->vals->read_rsp_size,
4760 &dw->buffer, dw->len,
4763 #ifdef CONFIG_CIFS_STATS2
4764 mid->when_received = jiffies;
4766 if (dw->server->ops->is_network_name_deleted)
4767 dw->server->ops->is_network_name_deleted(dw->buf,
4772 spin_lock(&dw->server->srv_lock);
4773 if (dw->server->tcpStatus == CifsNeedReconnect) {
4774 spin_lock(&dw->server->mid_lock);
4775 mid->mid_state = MID_RETRY_NEEDED;
4776 spin_unlock(&dw->server->mid_lock);
4777 spin_unlock(&dw->server->srv_lock);
4780 spin_lock(&dw->server->mid_lock);
4781 mid->mid_state = MID_REQUEST_SUBMITTED;
4782 mid->mid_flags &= ~(MID_DELETED);
4783 list_add_tail(&mid->qhead,
4784 &dw->server->pending_mid_q);
4785 spin_unlock(&dw->server->mid_lock);
4786 spin_unlock(&dw->server->srv_lock);
4793 cifs_clear_xarray_buffer(&dw->buffer);
4794 cifs_small_buf_release(dw->buf);
4800 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
4804 char *buf = server->smallbuf;
4805 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4806 struct iov_iter iter;
4807 unsigned int len, npages;
4808 unsigned int buflen = server->pdu_size;
4811 struct smb2_decrypt_work *dw;
4813 dw = kzalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL);
4816 xa_init(&dw->buffer);
4817 INIT_WORK(&dw->decrypt, smb2_decrypt_offload);
4818 dw->server = server;
4821 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
4822 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
4824 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
4827 server->total_read += rc;
4829 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
4830 server->vals->read_rsp_size;
4832 npages = DIV_ROUND_UP(len, PAGE_SIZE);
4835 for (; i < npages; i++) {
4838 page = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4842 old = xa_store(&dw->buffer, i, page, GFP_KERNEL);
4843 if (xa_is_err(old)) {
4848 xa_set_mark(&dw->buffer, i, XA_MARK_0);
4851 iov_iter_xarray(&iter, ITER_DEST, &dw->buffer, 0, npages * PAGE_SIZE);
4853 /* Read the data into the buffer and clear excess bufferage. */
4854 rc = cifs_read_iter_from_socket(server, &iter, dw->len);
4858 server->total_read += rc;
4859 if (rc < npages * PAGE_SIZE)
4860 iov_iter_zero(npages * PAGE_SIZE - rc, &iter);
4861 iov_iter_revert(&iter, npages * PAGE_SIZE);
4862 iov_iter_truncate(&iter, dw->len);
4864 rc = cifs_discard_remaining_data(server);
4869 * For large reads, offload to different thread for better performance,
4870 * use more cores decrypting which can be expensive
4873 if ((server->min_offload) && (server->in_flight > 1) &&
4874 (server->pdu_size >= server->min_offload)) {
4875 dw->buf = server->smallbuf;
4876 server->smallbuf = (char *)cifs_small_buf_get();
4878 queue_work(decrypt_wq, &dw->decrypt);
4879 *num_mids = 0; /* worker thread takes care of finding mid */
4883 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
4888 *mid = smb2_find_mid(server, buf);
4890 cifs_dbg(FYI, "mid not found\n");
4892 cifs_dbg(FYI, "mid found\n");
4893 (*mid)->decrypted = true;
4894 rc = handle_read_data(server, *mid, buf,
4895 server->vals->read_rsp_size,
4896 &dw->buffer, dw->len, false);
4898 if (server->ops->is_network_name_deleted) {
4899 server->ops->is_network_name_deleted(buf,
4906 cifs_clear_xarray_buffer(&dw->buffer);
4911 cifs_discard_remaining_data(server);
4916 receive_encrypted_standard(struct TCP_Server_Info *server,
4917 struct mid_q_entry **mids, char **bufs,
4921 char *buf = server->smallbuf;
4922 struct smb2_hdr *shdr;
4923 unsigned int pdu_length = server->pdu_size;
4924 unsigned int buf_size;
4925 struct mid_q_entry *mid_entry;
4927 char *next_buffer = NULL;
4931 /* switch to large buffer if too big for a small one */
4932 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
4933 server->large_buf = true;
4934 memcpy(server->bigbuf, buf, server->total_read);
4935 buf = server->bigbuf;
4938 /* now read the rest */
4939 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
4940 pdu_length - HEADER_SIZE(server) + 1);
4943 server->total_read += length;
4945 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
4946 length = decrypt_raw_data(server, buf, buf_size, NULL, false);
4950 next_is_large = server->large_buf;
4952 shdr = (struct smb2_hdr *)buf;
4953 if (shdr->NextCommand) {
4955 next_buffer = (char *)cifs_buf_get();
4957 next_buffer = (char *)cifs_small_buf_get();
4959 buf + le32_to_cpu(shdr->NextCommand),
4960 pdu_length - le32_to_cpu(shdr->NextCommand));
4963 mid_entry = smb2_find_mid(server, buf);
4964 if (mid_entry == NULL)
4965 cifs_dbg(FYI, "mid not found\n");
4967 cifs_dbg(FYI, "mid found\n");
4968 mid_entry->decrypted = true;
4969 mid_entry->resp_buf_size = server->pdu_size;
4972 if (*num_mids >= MAX_COMPOUND) {
4973 cifs_server_dbg(VFS, "too many PDUs in compound\n");
4976 bufs[*num_mids] = buf;
4977 mids[(*num_mids)++] = mid_entry;
4979 if (mid_entry && mid_entry->handle)
4980 ret = mid_entry->handle(server, mid_entry);
4982 ret = cifs_handle_standard(server, mid_entry);
4984 if (ret == 0 && shdr->NextCommand) {
4985 pdu_length -= le32_to_cpu(shdr->NextCommand);
4986 server->large_buf = next_is_large;
4988 server->bigbuf = buf = next_buffer;
4990 server->smallbuf = buf = next_buffer;
4992 } else if (ret != 0) {
4994 * ret != 0 here means that we didn't get to handle_mid() thus
4995 * server->smallbuf and server->bigbuf are still valid. We need
4996 * to free next_buffer because it is not going to be used
5000 free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer);
5002 free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer);
5009 smb3_receive_transform(struct TCP_Server_Info *server,
5010 struct mid_q_entry **mids, char **bufs, int *num_mids)
5012 char *buf = server->smallbuf;
5013 unsigned int pdu_length = server->pdu_size;
5014 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
5015 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
5017 if (pdu_length < sizeof(struct smb2_transform_hdr) +
5018 sizeof(struct smb2_hdr)) {
5019 cifs_server_dbg(VFS, "Transform message is too small (%u)\n",
5021 cifs_reconnect(server, true);
5022 return -ECONNABORTED;
5025 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
5026 cifs_server_dbg(VFS, "Transform message is broken\n");
5027 cifs_reconnect(server, true);
5028 return -ECONNABORTED;
5031 /* TODO: add support for compounds containing READ. */
5032 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
5033 return receive_encrypted_read(server, &mids[0], num_mids);
5036 return receive_encrypted_standard(server, mids, bufs, num_mids);
5040 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
5042 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
5044 return handle_read_data(server, mid, buf, server->pdu_size,
5049 smb2_next_header(char *buf)
5051 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
5052 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
5054 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
5055 return sizeof(struct smb2_transform_hdr) +
5056 le32_to_cpu(t_hdr->OriginalMessageSize);
5058 return le32_to_cpu(hdr->NextCommand);
5062 smb2_make_node(unsigned int xid, struct inode *inode,
5063 struct dentry *dentry, struct cifs_tcon *tcon,
5064 const char *full_path, umode_t mode, dev_t dev)
5066 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
5068 struct cifs_open_info_data buf = {};
5069 struct cifs_io_parms io_parms = {0};
5071 struct cifs_fid fid;
5072 struct cifs_open_parms oparms;
5073 unsigned int bytes_written;
5074 struct win_dev *pdev;
5078 * Check if mounted with mount parm 'sfu' mount parm.
5079 * SFU emulation should work with all servers, but only
5080 * supports block and char device (no socket & fifo),
5081 * and was used by default in earlier versions of Windows
5083 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
5087 * TODO: Add ability to create instead via reparse point. Windows (e.g.
5088 * their current NFS server) uses this approach to expose special files
5089 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
5092 if (!S_ISCHR(mode) && !S_ISBLK(mode) && !S_ISFIFO(mode))
5095 cifs_dbg(FYI, "sfu compat create special file\n");
5097 oparms = (struct cifs_open_parms) {
5100 .desired_access = GENERIC_WRITE,
5101 .create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR |
5102 CREATE_OPTION_SPECIAL),
5103 .disposition = FILE_CREATE,
5108 if (tcon->ses->server->oplocks)
5109 oplock = REQ_OPLOCK;
5112 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, &buf);
5117 * BB Do not bother to decode buf since no local inode yet to put
5118 * timestamps in, but we can reuse it safely.
5121 pdev = (struct win_dev *)&buf.fi;
5122 io_parms.pid = current->tgid;
5123 io_parms.tcon = tcon;
5124 io_parms.offset = 0;
5125 io_parms.length = sizeof(struct win_dev);
5126 iov[1].iov_base = &buf.fi;
5127 iov[1].iov_len = sizeof(struct win_dev);
5128 if (S_ISCHR(mode)) {
5129 memcpy(pdev->type, "IntxCHR", 8);
5130 pdev->major = cpu_to_le64(MAJOR(dev));
5131 pdev->minor = cpu_to_le64(MINOR(dev));
5132 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5133 &bytes_written, iov, 1);
5134 } else if (S_ISBLK(mode)) {
5135 memcpy(pdev->type, "IntxBLK", 8);
5136 pdev->major = cpu_to_le64(MAJOR(dev));
5137 pdev->minor = cpu_to_le64(MINOR(dev));
5138 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5139 &bytes_written, iov, 1);
5140 } else if (S_ISFIFO(mode)) {
5141 memcpy(pdev->type, "LnxFIFO", 8);
5144 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5145 &bytes_written, iov, 1);
5147 tcon->ses->server->ops->close(xid, tcon, &fid);
5150 /* FIXME: add code here to set EAs */
5152 cifs_free_open_info(&buf);
5156 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5157 struct smb_version_operations smb20_operations = {
5158 .compare_fids = smb2_compare_fids,
5159 .setup_request = smb2_setup_request,
5160 .setup_async_request = smb2_setup_async_request,
5161 .check_receive = smb2_check_receive,
5162 .add_credits = smb2_add_credits,
5163 .set_credits = smb2_set_credits,
5164 .get_credits_field = smb2_get_credits_field,
5165 .get_credits = smb2_get_credits,
5166 .wait_mtu_credits = cifs_wait_mtu_credits,
5167 .get_next_mid = smb2_get_next_mid,
5168 .revert_current_mid = smb2_revert_current_mid,
5169 .read_data_offset = smb2_read_data_offset,
5170 .read_data_length = smb2_read_data_length,
5171 .map_error = map_smb2_to_linux_error,
5172 .find_mid = smb2_find_mid,
5173 .check_message = smb2_check_message,
5174 .dump_detail = smb2_dump_detail,
5175 .clear_stats = smb2_clear_stats,
5176 .print_stats = smb2_print_stats,
5177 .is_oplock_break = smb2_is_valid_oplock_break,
5178 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5179 .downgrade_oplock = smb2_downgrade_oplock,
5180 .need_neg = smb2_need_neg,
5181 .negotiate = smb2_negotiate,
5182 .negotiate_wsize = smb2_negotiate_wsize,
5183 .negotiate_rsize = smb2_negotiate_rsize,
5184 .sess_setup = SMB2_sess_setup,
5185 .logoff = SMB2_logoff,
5186 .tree_connect = SMB2_tcon,
5187 .tree_disconnect = SMB2_tdis,
5188 .qfs_tcon = smb2_qfs_tcon,
5189 .is_path_accessible = smb2_is_path_accessible,
5190 .can_echo = smb2_can_echo,
5192 .query_path_info = smb2_query_path_info,
5193 .query_reparse_point = smb2_query_reparse_point,
5194 .get_srv_inum = smb2_get_srv_inum,
5195 .query_file_info = smb2_query_file_info,
5196 .set_path_size = smb2_set_path_size,
5197 .set_file_size = smb2_set_file_size,
5198 .set_file_info = smb2_set_file_info,
5199 .set_compression = smb2_set_compression,
5200 .mkdir = smb2_mkdir,
5201 .mkdir_setinfo = smb2_mkdir_setinfo,
5202 .rmdir = smb2_rmdir,
5203 .unlink = smb2_unlink,
5204 .rename = smb2_rename_path,
5205 .create_hardlink = smb2_create_hardlink,
5206 .query_symlink = smb2_query_symlink,
5207 .query_mf_symlink = smb3_query_mf_symlink,
5208 .create_mf_symlink = smb3_create_mf_symlink,
5209 .open = smb2_open_file,
5210 .set_fid = smb2_set_fid,
5211 .close = smb2_close_file,
5212 .flush = smb2_flush_file,
5213 .async_readv = smb2_async_readv,
5214 .async_writev = smb2_async_writev,
5215 .sync_read = smb2_sync_read,
5216 .sync_write = smb2_sync_write,
5217 .query_dir_first = smb2_query_dir_first,
5218 .query_dir_next = smb2_query_dir_next,
5219 .close_dir = smb2_close_dir,
5220 .calc_smb_size = smb2_calc_size,
5221 .is_status_pending = smb2_is_status_pending,
5222 .is_session_expired = smb2_is_session_expired,
5223 .oplock_response = smb2_oplock_response,
5224 .queryfs = smb2_queryfs,
5225 .mand_lock = smb2_mand_lock,
5226 .mand_unlock_range = smb2_unlock_range,
5227 .push_mand_locks = smb2_push_mandatory_locks,
5228 .get_lease_key = smb2_get_lease_key,
5229 .set_lease_key = smb2_set_lease_key,
5230 .new_lease_key = smb2_new_lease_key,
5231 .calc_signature = smb2_calc_signature,
5232 .is_read_op = smb2_is_read_op,
5233 .set_oplock_level = smb2_set_oplock_level,
5234 .create_lease_buf = smb2_create_lease_buf,
5235 .parse_lease_buf = smb2_parse_lease_buf,
5236 .copychunk_range = smb2_copychunk_range,
5237 .wp_retry_size = smb2_wp_retry_size,
5238 .dir_needs_close = smb2_dir_needs_close,
5239 .get_dfs_refer = smb2_get_dfs_refer,
5240 .select_sectype = smb2_select_sectype,
5241 #ifdef CONFIG_CIFS_XATTR
5242 .query_all_EAs = smb2_query_eas,
5243 .set_EA = smb2_set_ea,
5244 #endif /* CIFS_XATTR */
5245 .get_acl = get_smb2_acl,
5246 .get_acl_by_fid = get_smb2_acl_by_fid,
5247 .set_acl = set_smb2_acl,
5248 .next_header = smb2_next_header,
5249 .ioctl_query_info = smb2_ioctl_query_info,
5250 .make_node = smb2_make_node,
5251 .fiemap = smb3_fiemap,
5252 .llseek = smb3_llseek,
5253 .is_status_io_timeout = smb2_is_status_io_timeout,
5254 .is_network_name_deleted = smb2_is_network_name_deleted,
5256 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
5258 struct smb_version_operations smb21_operations = {
5259 .compare_fids = smb2_compare_fids,
5260 .setup_request = smb2_setup_request,
5261 .setup_async_request = smb2_setup_async_request,
5262 .check_receive = smb2_check_receive,
5263 .add_credits = smb2_add_credits,
5264 .set_credits = smb2_set_credits,
5265 .get_credits_field = smb2_get_credits_field,
5266 .get_credits = smb2_get_credits,
5267 .wait_mtu_credits = smb2_wait_mtu_credits,
5268 .adjust_credits = smb2_adjust_credits,
5269 .get_next_mid = smb2_get_next_mid,
5270 .revert_current_mid = smb2_revert_current_mid,
5271 .read_data_offset = smb2_read_data_offset,
5272 .read_data_length = smb2_read_data_length,
5273 .map_error = map_smb2_to_linux_error,
5274 .find_mid = smb2_find_mid,
5275 .check_message = smb2_check_message,
5276 .dump_detail = smb2_dump_detail,
5277 .clear_stats = smb2_clear_stats,
5278 .print_stats = smb2_print_stats,
5279 .is_oplock_break = smb2_is_valid_oplock_break,
5280 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5281 .downgrade_oplock = smb2_downgrade_oplock,
5282 .need_neg = smb2_need_neg,
5283 .negotiate = smb2_negotiate,
5284 .negotiate_wsize = smb2_negotiate_wsize,
5285 .negotiate_rsize = smb2_negotiate_rsize,
5286 .sess_setup = SMB2_sess_setup,
5287 .logoff = SMB2_logoff,
5288 .tree_connect = SMB2_tcon,
5289 .tree_disconnect = SMB2_tdis,
5290 .qfs_tcon = smb2_qfs_tcon,
5291 .is_path_accessible = smb2_is_path_accessible,
5292 .can_echo = smb2_can_echo,
5294 .query_path_info = smb2_query_path_info,
5295 .query_reparse_point = smb2_query_reparse_point,
5296 .get_srv_inum = smb2_get_srv_inum,
5297 .query_file_info = smb2_query_file_info,
5298 .set_path_size = smb2_set_path_size,
5299 .set_file_size = smb2_set_file_size,
5300 .set_file_info = smb2_set_file_info,
5301 .set_compression = smb2_set_compression,
5302 .mkdir = smb2_mkdir,
5303 .mkdir_setinfo = smb2_mkdir_setinfo,
5304 .rmdir = smb2_rmdir,
5305 .unlink = smb2_unlink,
5306 .rename = smb2_rename_path,
5307 .create_hardlink = smb2_create_hardlink,
5308 .query_symlink = smb2_query_symlink,
5309 .query_mf_symlink = smb3_query_mf_symlink,
5310 .create_mf_symlink = smb3_create_mf_symlink,
5311 .open = smb2_open_file,
5312 .set_fid = smb2_set_fid,
5313 .close = smb2_close_file,
5314 .flush = smb2_flush_file,
5315 .async_readv = smb2_async_readv,
5316 .async_writev = smb2_async_writev,
5317 .sync_read = smb2_sync_read,
5318 .sync_write = smb2_sync_write,
5319 .query_dir_first = smb2_query_dir_first,
5320 .query_dir_next = smb2_query_dir_next,
5321 .close_dir = smb2_close_dir,
5322 .calc_smb_size = smb2_calc_size,
5323 .is_status_pending = smb2_is_status_pending,
5324 .is_session_expired = smb2_is_session_expired,
5325 .oplock_response = smb2_oplock_response,
5326 .queryfs = smb2_queryfs,
5327 .mand_lock = smb2_mand_lock,
5328 .mand_unlock_range = smb2_unlock_range,
5329 .push_mand_locks = smb2_push_mandatory_locks,
5330 .get_lease_key = smb2_get_lease_key,
5331 .set_lease_key = smb2_set_lease_key,
5332 .new_lease_key = smb2_new_lease_key,
5333 .calc_signature = smb2_calc_signature,
5334 .is_read_op = smb21_is_read_op,
5335 .set_oplock_level = smb21_set_oplock_level,
5336 .create_lease_buf = smb2_create_lease_buf,
5337 .parse_lease_buf = smb2_parse_lease_buf,
5338 .copychunk_range = smb2_copychunk_range,
5339 .wp_retry_size = smb2_wp_retry_size,
5340 .dir_needs_close = smb2_dir_needs_close,
5341 .enum_snapshots = smb3_enum_snapshots,
5342 .notify = smb3_notify,
5343 .get_dfs_refer = smb2_get_dfs_refer,
5344 .select_sectype = smb2_select_sectype,
5345 #ifdef CONFIG_CIFS_XATTR
5346 .query_all_EAs = smb2_query_eas,
5347 .set_EA = smb2_set_ea,
5348 #endif /* CIFS_XATTR */
5349 .get_acl = get_smb2_acl,
5350 .get_acl_by_fid = get_smb2_acl_by_fid,
5351 .set_acl = set_smb2_acl,
5352 .next_header = smb2_next_header,
5353 .ioctl_query_info = smb2_ioctl_query_info,
5354 .make_node = smb2_make_node,
5355 .fiemap = smb3_fiemap,
5356 .llseek = smb3_llseek,
5357 .is_status_io_timeout = smb2_is_status_io_timeout,
5358 .is_network_name_deleted = smb2_is_network_name_deleted,
5361 struct smb_version_operations smb30_operations = {
5362 .compare_fids = smb2_compare_fids,
5363 .setup_request = smb2_setup_request,
5364 .setup_async_request = smb2_setup_async_request,
5365 .check_receive = smb2_check_receive,
5366 .add_credits = smb2_add_credits,
5367 .set_credits = smb2_set_credits,
5368 .get_credits_field = smb2_get_credits_field,
5369 .get_credits = smb2_get_credits,
5370 .wait_mtu_credits = smb2_wait_mtu_credits,
5371 .adjust_credits = smb2_adjust_credits,
5372 .get_next_mid = smb2_get_next_mid,
5373 .revert_current_mid = smb2_revert_current_mid,
5374 .read_data_offset = smb2_read_data_offset,
5375 .read_data_length = smb2_read_data_length,
5376 .map_error = map_smb2_to_linux_error,
5377 .find_mid = smb2_find_mid,
5378 .check_message = smb2_check_message,
5379 .dump_detail = smb2_dump_detail,
5380 .clear_stats = smb2_clear_stats,
5381 .print_stats = smb2_print_stats,
5382 .dump_share_caps = smb2_dump_share_caps,
5383 .is_oplock_break = smb2_is_valid_oplock_break,
5384 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5385 .downgrade_oplock = smb3_downgrade_oplock,
5386 .need_neg = smb2_need_neg,
5387 .negotiate = smb2_negotiate,
5388 .negotiate_wsize = smb3_negotiate_wsize,
5389 .negotiate_rsize = smb3_negotiate_rsize,
5390 .sess_setup = SMB2_sess_setup,
5391 .logoff = SMB2_logoff,
5392 .tree_connect = SMB2_tcon,
5393 .tree_disconnect = SMB2_tdis,
5394 .qfs_tcon = smb3_qfs_tcon,
5395 .is_path_accessible = smb2_is_path_accessible,
5396 .can_echo = smb2_can_echo,
5398 .query_path_info = smb2_query_path_info,
5399 /* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */
5400 .query_reparse_point = smb2_query_reparse_point,
5401 .get_srv_inum = smb2_get_srv_inum,
5402 .query_file_info = smb2_query_file_info,
5403 .set_path_size = smb2_set_path_size,
5404 .set_file_size = smb2_set_file_size,
5405 .set_file_info = smb2_set_file_info,
5406 .set_compression = smb2_set_compression,
5407 .mkdir = smb2_mkdir,
5408 .mkdir_setinfo = smb2_mkdir_setinfo,
5409 .rmdir = smb2_rmdir,
5410 .unlink = smb2_unlink,
5411 .rename = smb2_rename_path,
5412 .create_hardlink = smb2_create_hardlink,
5413 .query_symlink = smb2_query_symlink,
5414 .query_mf_symlink = smb3_query_mf_symlink,
5415 .create_mf_symlink = smb3_create_mf_symlink,
5416 .open = smb2_open_file,
5417 .set_fid = smb2_set_fid,
5418 .close = smb2_close_file,
5419 .close_getattr = smb2_close_getattr,
5420 .flush = smb2_flush_file,
5421 .async_readv = smb2_async_readv,
5422 .async_writev = smb2_async_writev,
5423 .sync_read = smb2_sync_read,
5424 .sync_write = smb2_sync_write,
5425 .query_dir_first = smb2_query_dir_first,
5426 .query_dir_next = smb2_query_dir_next,
5427 .close_dir = smb2_close_dir,
5428 .calc_smb_size = smb2_calc_size,
5429 .is_status_pending = smb2_is_status_pending,
5430 .is_session_expired = smb2_is_session_expired,
5431 .oplock_response = smb2_oplock_response,
5432 .queryfs = smb2_queryfs,
5433 .mand_lock = smb2_mand_lock,
5434 .mand_unlock_range = smb2_unlock_range,
5435 .push_mand_locks = smb2_push_mandatory_locks,
5436 .get_lease_key = smb2_get_lease_key,
5437 .set_lease_key = smb2_set_lease_key,
5438 .new_lease_key = smb2_new_lease_key,
5439 .generate_signingkey = generate_smb30signingkey,
5440 .calc_signature = smb3_calc_signature,
5441 .set_integrity = smb3_set_integrity,
5442 .is_read_op = smb21_is_read_op,
5443 .set_oplock_level = smb3_set_oplock_level,
5444 .create_lease_buf = smb3_create_lease_buf,
5445 .parse_lease_buf = smb3_parse_lease_buf,
5446 .copychunk_range = smb2_copychunk_range,
5447 .duplicate_extents = smb2_duplicate_extents,
5448 .validate_negotiate = smb3_validate_negotiate,
5449 .wp_retry_size = smb2_wp_retry_size,
5450 .dir_needs_close = smb2_dir_needs_close,
5451 .fallocate = smb3_fallocate,
5452 .enum_snapshots = smb3_enum_snapshots,
5453 .notify = smb3_notify,
5454 .init_transform_rq = smb3_init_transform_rq,
5455 .is_transform_hdr = smb3_is_transform_hdr,
5456 .receive_transform = smb3_receive_transform,
5457 .get_dfs_refer = smb2_get_dfs_refer,
5458 .select_sectype = smb2_select_sectype,
5459 #ifdef CONFIG_CIFS_XATTR
5460 .query_all_EAs = smb2_query_eas,
5461 .set_EA = smb2_set_ea,
5462 #endif /* CIFS_XATTR */
5463 .get_acl = get_smb2_acl,
5464 .get_acl_by_fid = get_smb2_acl_by_fid,
5465 .set_acl = set_smb2_acl,
5466 .next_header = smb2_next_header,
5467 .ioctl_query_info = smb2_ioctl_query_info,
5468 .make_node = smb2_make_node,
5469 .fiemap = smb3_fiemap,
5470 .llseek = smb3_llseek,
5471 .is_status_io_timeout = smb2_is_status_io_timeout,
5472 .is_network_name_deleted = smb2_is_network_name_deleted,
5475 struct smb_version_operations smb311_operations = {
5476 .compare_fids = smb2_compare_fids,
5477 .setup_request = smb2_setup_request,
5478 .setup_async_request = smb2_setup_async_request,
5479 .check_receive = smb2_check_receive,
5480 .add_credits = smb2_add_credits,
5481 .set_credits = smb2_set_credits,
5482 .get_credits_field = smb2_get_credits_field,
5483 .get_credits = smb2_get_credits,
5484 .wait_mtu_credits = smb2_wait_mtu_credits,
5485 .adjust_credits = smb2_adjust_credits,
5486 .get_next_mid = smb2_get_next_mid,
5487 .revert_current_mid = smb2_revert_current_mid,
5488 .read_data_offset = smb2_read_data_offset,
5489 .read_data_length = smb2_read_data_length,
5490 .map_error = map_smb2_to_linux_error,
5491 .find_mid = smb2_find_mid,
5492 .check_message = smb2_check_message,
5493 .dump_detail = smb2_dump_detail,
5494 .clear_stats = smb2_clear_stats,
5495 .print_stats = smb2_print_stats,
5496 .dump_share_caps = smb2_dump_share_caps,
5497 .is_oplock_break = smb2_is_valid_oplock_break,
5498 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5499 .downgrade_oplock = smb3_downgrade_oplock,
5500 .need_neg = smb2_need_neg,
5501 .negotiate = smb2_negotiate,
5502 .negotiate_wsize = smb3_negotiate_wsize,
5503 .negotiate_rsize = smb3_negotiate_rsize,
5504 .sess_setup = SMB2_sess_setup,
5505 .logoff = SMB2_logoff,
5506 .tree_connect = SMB2_tcon,
5507 .tree_disconnect = SMB2_tdis,
5508 .qfs_tcon = smb3_qfs_tcon,
5509 .is_path_accessible = smb2_is_path_accessible,
5510 .can_echo = smb2_can_echo,
5512 .query_path_info = smb2_query_path_info,
5513 .query_reparse_point = smb2_query_reparse_point,
5514 .get_srv_inum = smb2_get_srv_inum,
5515 .query_file_info = smb2_query_file_info,
5516 .set_path_size = smb2_set_path_size,
5517 .set_file_size = smb2_set_file_size,
5518 .set_file_info = smb2_set_file_info,
5519 .set_compression = smb2_set_compression,
5520 .mkdir = smb2_mkdir,
5521 .mkdir_setinfo = smb2_mkdir_setinfo,
5522 .posix_mkdir = smb311_posix_mkdir,
5523 .rmdir = smb2_rmdir,
5524 .unlink = smb2_unlink,
5525 .rename = smb2_rename_path,
5526 .create_hardlink = smb2_create_hardlink,
5527 .query_symlink = smb2_query_symlink,
5528 .query_mf_symlink = smb3_query_mf_symlink,
5529 .create_mf_symlink = smb3_create_mf_symlink,
5530 .open = smb2_open_file,
5531 .set_fid = smb2_set_fid,
5532 .close = smb2_close_file,
5533 .close_getattr = smb2_close_getattr,
5534 .flush = smb2_flush_file,
5535 .async_readv = smb2_async_readv,
5536 .async_writev = smb2_async_writev,
5537 .sync_read = smb2_sync_read,
5538 .sync_write = smb2_sync_write,
5539 .query_dir_first = smb2_query_dir_first,
5540 .query_dir_next = smb2_query_dir_next,
5541 .close_dir = smb2_close_dir,
5542 .calc_smb_size = smb2_calc_size,
5543 .is_status_pending = smb2_is_status_pending,
5544 .is_session_expired = smb2_is_session_expired,
5545 .oplock_response = smb2_oplock_response,
5546 .queryfs = smb311_queryfs,
5547 .mand_lock = smb2_mand_lock,
5548 .mand_unlock_range = smb2_unlock_range,
5549 .push_mand_locks = smb2_push_mandatory_locks,
5550 .get_lease_key = smb2_get_lease_key,
5551 .set_lease_key = smb2_set_lease_key,
5552 .new_lease_key = smb2_new_lease_key,
5553 .generate_signingkey = generate_smb311signingkey,
5554 .calc_signature = smb3_calc_signature,
5555 .set_integrity = smb3_set_integrity,
5556 .is_read_op = smb21_is_read_op,
5557 .set_oplock_level = smb3_set_oplock_level,
5558 .create_lease_buf = smb3_create_lease_buf,
5559 .parse_lease_buf = smb3_parse_lease_buf,
5560 .copychunk_range = smb2_copychunk_range,
5561 .duplicate_extents = smb2_duplicate_extents,
5562 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
5563 .wp_retry_size = smb2_wp_retry_size,
5564 .dir_needs_close = smb2_dir_needs_close,
5565 .fallocate = smb3_fallocate,
5566 .enum_snapshots = smb3_enum_snapshots,
5567 .notify = smb3_notify,
5568 .init_transform_rq = smb3_init_transform_rq,
5569 .is_transform_hdr = smb3_is_transform_hdr,
5570 .receive_transform = smb3_receive_transform,
5571 .get_dfs_refer = smb2_get_dfs_refer,
5572 .select_sectype = smb2_select_sectype,
5573 #ifdef CONFIG_CIFS_XATTR
5574 .query_all_EAs = smb2_query_eas,
5575 .set_EA = smb2_set_ea,
5576 #endif /* CIFS_XATTR */
5577 .get_acl = get_smb2_acl,
5578 .get_acl_by_fid = get_smb2_acl_by_fid,
5579 .set_acl = set_smb2_acl,
5580 .next_header = smb2_next_header,
5581 .ioctl_query_info = smb2_ioctl_query_info,
5582 .make_node = smb2_make_node,
5583 .fiemap = smb3_fiemap,
5584 .llseek = smb3_llseek,
5585 .is_status_io_timeout = smb2_is_status_io_timeout,
5586 .is_network_name_deleted = smb2_is_network_name_deleted,
5589 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5590 struct smb_version_values smb20_values = {
5591 .version_string = SMB20_VERSION_STRING,
5592 .protocol_id = SMB20_PROT_ID,
5593 .req_capabilities = 0, /* MBZ */
5594 .large_lock_type = 0,
5595 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5596 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5597 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5598 .header_size = sizeof(struct smb2_hdr),
5599 .header_preamble_size = 0,
5600 .max_header_size = MAX_SMB2_HDR_SIZE,
5601 .read_rsp_size = sizeof(struct smb2_read_rsp),
5602 .lock_cmd = SMB2_LOCK,
5604 .cap_nt_find = SMB2_NT_FIND,
5605 .cap_large_files = SMB2_LARGE_FILES,
5606 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5607 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5608 .create_lease_size = sizeof(struct create_lease),
5610 #endif /* ALLOW_INSECURE_LEGACY */
5612 struct smb_version_values smb21_values = {
5613 .version_string = SMB21_VERSION_STRING,
5614 .protocol_id = SMB21_PROT_ID,
5615 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
5616 .large_lock_type = 0,
5617 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5618 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5619 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5620 .header_size = sizeof(struct smb2_hdr),
5621 .header_preamble_size = 0,
5622 .max_header_size = MAX_SMB2_HDR_SIZE,
5623 .read_rsp_size = sizeof(struct smb2_read_rsp),
5624 .lock_cmd = SMB2_LOCK,
5626 .cap_nt_find = SMB2_NT_FIND,
5627 .cap_large_files = SMB2_LARGE_FILES,
5628 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5629 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5630 .create_lease_size = sizeof(struct create_lease),
5633 struct smb_version_values smb3any_values = {
5634 .version_string = SMB3ANY_VERSION_STRING,
5635 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5636 .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,
5637 .large_lock_type = 0,
5638 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5639 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5640 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5641 .header_size = sizeof(struct smb2_hdr),
5642 .header_preamble_size = 0,
5643 .max_header_size = MAX_SMB2_HDR_SIZE,
5644 .read_rsp_size = sizeof(struct smb2_read_rsp),
5645 .lock_cmd = SMB2_LOCK,
5647 .cap_nt_find = SMB2_NT_FIND,
5648 .cap_large_files = SMB2_LARGE_FILES,
5649 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5650 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5651 .create_lease_size = sizeof(struct create_lease_v2),
5654 struct smb_version_values smbdefault_values = {
5655 .version_string = SMBDEFAULT_VERSION_STRING,
5656 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5657 .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,
5658 .large_lock_type = 0,
5659 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5660 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5661 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5662 .header_size = sizeof(struct smb2_hdr),
5663 .header_preamble_size = 0,
5664 .max_header_size = MAX_SMB2_HDR_SIZE,
5665 .read_rsp_size = sizeof(struct smb2_read_rsp),
5666 .lock_cmd = SMB2_LOCK,
5668 .cap_nt_find = SMB2_NT_FIND,
5669 .cap_large_files = SMB2_LARGE_FILES,
5670 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5671 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5672 .create_lease_size = sizeof(struct create_lease_v2),
5675 struct smb_version_values smb30_values = {
5676 .version_string = SMB30_VERSION_STRING,
5677 .protocol_id = SMB30_PROT_ID,
5678 .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,
5679 .large_lock_type = 0,
5680 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5681 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5682 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5683 .header_size = sizeof(struct smb2_hdr),
5684 .header_preamble_size = 0,
5685 .max_header_size = MAX_SMB2_HDR_SIZE,
5686 .read_rsp_size = sizeof(struct smb2_read_rsp),
5687 .lock_cmd = SMB2_LOCK,
5689 .cap_nt_find = SMB2_NT_FIND,
5690 .cap_large_files = SMB2_LARGE_FILES,
5691 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5692 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5693 .create_lease_size = sizeof(struct create_lease_v2),
5696 struct smb_version_values smb302_values = {
5697 .version_string = SMB302_VERSION_STRING,
5698 .protocol_id = SMB302_PROT_ID,
5699 .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,
5700 .large_lock_type = 0,
5701 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5702 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5703 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5704 .header_size = sizeof(struct smb2_hdr),
5705 .header_preamble_size = 0,
5706 .max_header_size = MAX_SMB2_HDR_SIZE,
5707 .read_rsp_size = sizeof(struct smb2_read_rsp),
5708 .lock_cmd = SMB2_LOCK,
5710 .cap_nt_find = SMB2_NT_FIND,
5711 .cap_large_files = SMB2_LARGE_FILES,
5712 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5713 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5714 .create_lease_size = sizeof(struct create_lease_v2),
5717 struct smb_version_values smb311_values = {
5718 .version_string = SMB311_VERSION_STRING,
5719 .protocol_id = SMB311_PROT_ID,
5720 .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,
5721 .large_lock_type = 0,
5722 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5723 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5724 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5725 .header_size = sizeof(struct smb2_hdr),
5726 .header_preamble_size = 0,
5727 .max_header_size = MAX_SMB2_HDR_SIZE,
5728 .read_rsp_size = sizeof(struct smb2_read_rsp),
5729 .lock_cmd = SMB2_LOCK,
5731 .cap_nt_find = SMB2_NT_FIND,
5732 .cap_large_files = SMB2_LARGE_FILES,
5733 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5734 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5735 .create_lease_size = sizeof(struct create_lease_v2),