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->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime);
1407 if (file_inf.ChangeTime)
1408 inode_set_ctime_to_ts(inode,
1409 cifs_NTtimeToUnix(file_inf.ChangeTime));
1410 if (file_inf.LastAccessTime)
1411 inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime);
1414 * i_blocks is not related to (i_size / i_blksize),
1415 * but instead 512 byte (2**9) size is required for
1416 * calculating num blocks.
1418 if (le64_to_cpu(file_inf.AllocationSize) > 4096)
1420 (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9;
1422 /* End of file and Attributes should not have to be updated on close */
1423 spin_unlock(&inode->i_lock);
1427 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1428 u64 persistent_fid, u64 volatile_fid,
1429 struct copychunk_ioctl *pcchunk)
1432 unsigned int ret_data_len;
1433 struct resume_key_req *res_key;
1435 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1436 FSCTL_SRV_REQUEST_RESUME_KEY, NULL, 0 /* no input */,
1437 CIFSMaxBufSize, (char **)&res_key, &ret_data_len);
1439 if (rc == -EOPNOTSUPP) {
1440 pr_warn_once("Server share %s does not support copy range\n", tcon->tree_name);
1441 goto req_res_key_exit;
1443 cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1444 goto req_res_key_exit;
1446 if (ret_data_len < sizeof(struct resume_key_req)) {
1447 cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n");
1449 goto req_res_key_exit;
1451 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1459 smb2_ioctl_query_info(const unsigned int xid,
1460 struct cifs_tcon *tcon,
1461 struct cifs_sb_info *cifs_sb,
1462 __le16 *path, int is_dir,
1465 struct smb2_compound_vars *vars;
1466 struct smb_rqst *rqst;
1467 struct kvec *rsp_iov;
1468 struct cifs_ses *ses = tcon->ses;
1469 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1470 char __user *arg = (char __user *)p;
1471 struct smb_query_info qi;
1472 struct smb_query_info __user *pqi;
1474 int flags = CIFS_CP_CREATE_CLOSE_OP;
1475 struct smb2_query_info_rsp *qi_rsp = NULL;
1476 struct smb2_ioctl_rsp *io_rsp = NULL;
1477 void *buffer = NULL;
1478 int resp_buftype[3];
1479 struct cifs_open_parms oparms;
1480 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1481 struct cifs_fid fid;
1482 unsigned int size[2];
1484 int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR;
1485 void (*free_req1_func)(struct smb_rqst *r);
1487 vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
1490 rqst = &vars->rqst[0];
1491 rsp_iov = &vars->rsp_iov[0];
1493 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1495 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info))) {
1499 if (qi.output_buffer_length > 1024) {
1504 if (!ses || !server) {
1509 if (smb3_encryption_required(tcon))
1510 flags |= CIFS_TRANSFORM_REQ;
1512 if (qi.output_buffer_length) {
1513 buffer = memdup_user(arg + sizeof(struct smb_query_info), qi.output_buffer_length);
1514 if (IS_ERR(buffer)) {
1515 rc = PTR_ERR(buffer);
1521 rqst[0].rq_iov = &vars->open_iov[0];
1522 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1524 oparms = (struct cifs_open_parms) {
1526 .disposition = FILE_OPEN,
1527 .create_options = cifs_create_options(cifs_sb, create_options),
1531 if (qi.flags & PASSTHRU_FSCTL) {
1532 switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1533 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1534 oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1536 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1537 oparms.desired_access = GENERIC_ALL;
1539 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1540 oparms.desired_access = GENERIC_READ;
1542 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1543 oparms.desired_access = GENERIC_WRITE;
1546 } else if (qi.flags & PASSTHRU_SET_INFO) {
1547 oparms.desired_access = GENERIC_WRITE;
1549 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1552 rc = SMB2_open_init(tcon, server,
1553 &rqst[0], &oplock, &oparms, path);
1555 goto free_output_buffer;
1556 smb2_set_next_command(tcon, &rqst[0]);
1559 if (qi.flags & PASSTHRU_FSCTL) {
1560 /* Can eventually relax perm check since server enforces too */
1561 if (!capable(CAP_SYS_ADMIN)) {
1565 rqst[1].rq_iov = &vars->io_iov[0];
1566 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1568 rc = SMB2_ioctl_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1569 qi.info_type, buffer, qi.output_buffer_length,
1570 CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1571 MAX_SMB2_CLOSE_RESPONSE_SIZE);
1572 free_req1_func = SMB2_ioctl_free;
1573 } else if (qi.flags == PASSTHRU_SET_INFO) {
1574 /* Can eventually relax perm check since server enforces too */
1575 if (!capable(CAP_SYS_ADMIN)) {
1579 if (qi.output_buffer_length < 8) {
1583 rqst[1].rq_iov = vars->si_iov;
1584 rqst[1].rq_nvec = 1;
1586 /* MS-FSCC 2.4.13 FileEndOfFileInformation */
1590 rc = SMB2_set_info_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1591 current->tgid, FILE_END_OF_FILE_INFORMATION,
1592 SMB2_O_INFO_FILE, 0, data, size);
1593 free_req1_func = SMB2_set_info_free;
1594 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1595 rqst[1].rq_iov = &vars->qi_iov;
1596 rqst[1].rq_nvec = 1;
1598 rc = SMB2_query_info_init(tcon, server,
1599 &rqst[1], COMPOUND_FID,
1600 COMPOUND_FID, qi.file_info_class,
1601 qi.info_type, qi.additional_information,
1602 qi.input_buffer_length,
1603 qi.output_buffer_length, buffer);
1604 free_req1_func = SMB2_query_info_free;
1605 } else { /* unknown flags */
1606 cifs_tcon_dbg(VFS, "Invalid passthru query flags: 0x%x\n",
1613 smb2_set_next_command(tcon, &rqst[1]);
1614 smb2_set_related(&rqst[1]);
1617 rqst[2].rq_iov = &vars->close_iov;
1618 rqst[2].rq_nvec = 1;
1620 rc = SMB2_close_init(tcon, server,
1621 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1624 smb2_set_related(&rqst[2]);
1626 rc = compound_send_recv(xid, ses, server,
1628 resp_buftype, rsp_iov);
1632 /* No need to bump num_remote_opens since handle immediately closed */
1633 if (qi.flags & PASSTHRU_FSCTL) {
1634 pqi = (struct smb_query_info __user *)arg;
1635 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1636 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1637 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1638 if (qi.input_buffer_length > 0 &&
1639 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length
1640 > rsp_iov[1].iov_len) {
1645 if (copy_to_user(&pqi->input_buffer_length,
1646 &qi.input_buffer_length,
1647 sizeof(qi.input_buffer_length))) {
1652 if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1653 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1654 qi.input_buffer_length))
1657 pqi = (struct smb_query_info __user *)arg;
1658 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1659 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1660 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1661 if (copy_to_user(&pqi->input_buffer_length,
1662 &qi.input_buffer_length,
1663 sizeof(qi.input_buffer_length))) {
1668 if (copy_to_user(pqi + 1, qi_rsp->Buffer,
1669 qi.input_buffer_length))
1674 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1675 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1676 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1677 SMB2_close_free(&rqst[2]);
1679 free_req1_func(&rqst[1]);
1681 SMB2_open_free(&rqst[0]);
1690 smb2_copychunk_range(const unsigned int xid,
1691 struct cifsFileInfo *srcfile,
1692 struct cifsFileInfo *trgtfile, u64 src_off,
1693 u64 len, u64 dest_off)
1696 unsigned int ret_data_len;
1697 struct copychunk_ioctl *pcchunk;
1698 struct copychunk_ioctl_rsp *retbuf = NULL;
1699 struct cifs_tcon *tcon;
1700 int chunks_copied = 0;
1701 bool chunk_sizes_updated = false;
1702 ssize_t bytes_written, total_bytes_written = 0;
1704 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1705 if (pcchunk == NULL)
1708 cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
1709 /* Request a key from the server to identify the source of the copy */
1710 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1711 srcfile->fid.persistent_fid,
1712 srcfile->fid.volatile_fid, pcchunk);
1714 /* Note: request_res_key sets res_key null only if rc !=0 */
1718 /* For now array only one chunk long, will make more flexible later */
1719 pcchunk->ChunkCount = cpu_to_le32(1);
1720 pcchunk->Reserved = 0;
1721 pcchunk->Reserved2 = 0;
1723 tcon = tlink_tcon(trgtfile->tlink);
1726 pcchunk->SourceOffset = cpu_to_le64(src_off);
1727 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1729 cpu_to_le32(min_t(u64, len, tcon->max_bytes_chunk));
1731 /* Request server copy to target from src identified by key */
1734 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1735 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1736 (char *)pcchunk, sizeof(struct copychunk_ioctl),
1737 CIFSMaxBufSize, (char **)&retbuf, &ret_data_len);
1740 sizeof(struct copychunk_ioctl_rsp)) {
1741 cifs_tcon_dbg(VFS, "Invalid cchunk response size\n");
1745 if (retbuf->TotalBytesWritten == 0) {
1746 cifs_dbg(FYI, "no bytes copied\n");
1751 * Check if server claimed to write more than we asked
1753 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1754 le32_to_cpu(pcchunk->Length)) {
1755 cifs_tcon_dbg(VFS, "Invalid copy chunk response\n");
1759 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1760 cifs_tcon_dbg(VFS, "Invalid num chunks written\n");
1766 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1767 src_off += bytes_written;
1768 dest_off += bytes_written;
1769 len -= bytes_written;
1770 total_bytes_written += bytes_written;
1772 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1773 le32_to_cpu(retbuf->ChunksWritten),
1774 le32_to_cpu(retbuf->ChunkBytesWritten),
1776 } else if (rc == -EINVAL) {
1777 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1780 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1781 le32_to_cpu(retbuf->ChunksWritten),
1782 le32_to_cpu(retbuf->ChunkBytesWritten),
1783 le32_to_cpu(retbuf->TotalBytesWritten));
1786 * Check if this is the first request using these sizes,
1787 * (ie check if copy succeed once with original sizes
1788 * and check if the server gave us different sizes after
1789 * we already updated max sizes on previous request).
1790 * if not then why is the server returning an error now
1792 if ((chunks_copied != 0) || chunk_sizes_updated)
1795 /* Check that server is not asking us to grow size */
1796 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1797 tcon->max_bytes_chunk)
1798 tcon->max_bytes_chunk =
1799 le32_to_cpu(retbuf->ChunkBytesWritten);
1801 goto cchunk_out; /* server gave us bogus size */
1803 /* No need to change MaxChunks since already set to 1 */
1804 chunk_sizes_updated = true;
1815 return total_bytes_written;
1819 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1820 struct cifs_fid *fid)
1822 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1826 smb2_read_data_offset(char *buf)
1828 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1830 return rsp->DataOffset;
1834 smb2_read_data_length(char *buf, bool in_remaining)
1836 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1839 return le32_to_cpu(rsp->DataRemaining);
1841 return le32_to_cpu(rsp->DataLength);
1846 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1847 struct cifs_io_parms *parms, unsigned int *bytes_read,
1848 char **buf, int *buf_type)
1850 parms->persistent_fid = pfid->persistent_fid;
1851 parms->volatile_fid = pfid->volatile_fid;
1852 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1856 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1857 struct cifs_io_parms *parms, unsigned int *written,
1858 struct kvec *iov, unsigned long nr_segs)
1861 parms->persistent_fid = pfid->persistent_fid;
1862 parms->volatile_fid = pfid->volatile_fid;
1863 return SMB2_write(xid, parms, written, iov, nr_segs);
1866 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1867 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1868 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1870 struct cifsInodeInfo *cifsi;
1873 cifsi = CIFS_I(inode);
1875 /* if file already sparse don't bother setting sparse again */
1876 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1877 return true; /* already sparse */
1879 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1880 return true; /* already not sparse */
1883 * Can't check for sparse support on share the usual way via the
1884 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1885 * since Samba server doesn't set the flag on the share, yet
1886 * supports the set sparse FSCTL and returns sparse correctly
1887 * in the file attributes. If we fail setting sparse though we
1888 * mark that server does not support sparse files for this share
1889 * to avoid repeatedly sending the unsupported fsctl to server
1890 * if the file is repeatedly extended.
1892 if (tcon->broken_sparse_sup)
1895 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1896 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1897 &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
1899 tcon->broken_sparse_sup = true;
1900 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1905 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1907 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1913 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1914 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1916 __le64 eof = cpu_to_le64(size);
1917 struct inode *inode;
1920 * If extending file more than one page make sparse. Many Linux fs
1921 * make files sparse by default when extending via ftruncate
1923 inode = d_inode(cfile->dentry);
1925 if (!set_alloc && (size > inode->i_size + 8192)) {
1926 __u8 set_sparse = 1;
1928 /* whether set sparse succeeds or not, extend the file */
1929 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1932 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1933 cfile->fid.volatile_fid, cfile->pid, &eof);
1937 smb2_duplicate_extents(const unsigned int xid,
1938 struct cifsFileInfo *srcfile,
1939 struct cifsFileInfo *trgtfile, u64 src_off,
1940 u64 len, u64 dest_off)
1943 unsigned int ret_data_len;
1944 struct inode *inode;
1945 struct duplicate_extents_to_file dup_ext_buf;
1946 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1948 /* server fileays advertise duplicate extent support with this flag */
1949 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1950 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1953 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1954 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1955 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1956 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1957 dup_ext_buf.ByteCount = cpu_to_le64(len);
1958 cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
1959 src_off, dest_off, len);
1961 inode = d_inode(trgtfile->dentry);
1962 if (inode->i_size < dest_off + len) {
1963 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1965 goto duplicate_extents_out;
1968 * Although also could set plausible allocation size (i_blocks)
1969 * here in addition to setting the file size, in reflink
1970 * it is likely that the target file is sparse. Its allocation
1971 * size will be queried on next revalidate, but it is important
1972 * to make sure that file's cached size is updated immediately
1974 cifs_setsize(inode, dest_off + len);
1976 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1977 trgtfile->fid.volatile_fid,
1978 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1979 (char *)&dup_ext_buf,
1980 sizeof(struct duplicate_extents_to_file),
1981 CIFSMaxBufSize, NULL,
1984 if (ret_data_len > 0)
1985 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
1987 duplicate_extents_out:
1992 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1993 struct cifsFileInfo *cfile)
1995 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1996 cfile->fid.volatile_fid);
2000 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
2001 struct cifsFileInfo *cfile)
2003 struct fsctl_set_integrity_information_req integr_info;
2004 unsigned int ret_data_len;
2006 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
2007 integr_info.Flags = 0;
2008 integr_info.Reserved = 0;
2010 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2011 cfile->fid.volatile_fid,
2012 FSCTL_SET_INTEGRITY_INFORMATION,
2013 (char *)&integr_info,
2014 sizeof(struct fsctl_set_integrity_information_req),
2015 CIFSMaxBufSize, NULL,
2020 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
2021 #define GMT_TOKEN_SIZE 50
2023 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
2026 * Input buffer contains (empty) struct smb_snapshot array with size filled in
2027 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
2030 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
2031 struct cifsFileInfo *cfile, void __user *ioc_buf)
2033 char *retbuf = NULL;
2034 unsigned int ret_data_len = 0;
2036 u32 max_response_size;
2037 struct smb_snapshot_array snapshot_in;
2040 * On the first query to enumerate the list of snapshots available
2041 * for this volume the buffer begins with 0 (number of snapshots
2042 * which can be returned is zero since at that point we do not know
2043 * how big the buffer needs to be). On the second query,
2044 * it (ret_data_len) is set to number of snapshots so we can
2045 * know to set the maximum response size larger (see below).
2047 if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
2051 * Note that for snapshot queries that servers like Azure expect that
2052 * the first query be minimal size (and just used to get the number/size
2053 * of previous versions) so response size must be specified as EXACTLY
2054 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
2057 if (ret_data_len == 0)
2058 max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
2060 max_response_size = CIFSMaxBufSize;
2062 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2063 cfile->fid.volatile_fid,
2064 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
2065 NULL, 0 /* no input data */, max_response_size,
2068 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
2073 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
2075 if (copy_from_user(&snapshot_in, ioc_buf,
2076 sizeof(struct smb_snapshot_array))) {
2083 * Check for min size, ie not large enough to fit even one GMT
2084 * token (snapshot). On the first ioctl some users may pass in
2085 * smaller size (or zero) to simply get the size of the array
2086 * so the user space caller can allocate sufficient memory
2087 * and retry the ioctl again with larger array size sufficient
2088 * to hold all of the snapshot GMT tokens on the second try.
2090 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
2091 ret_data_len = sizeof(struct smb_snapshot_array);
2094 * We return struct SRV_SNAPSHOT_ARRAY, followed by
2095 * the snapshot array (of 50 byte GMT tokens) each
2096 * representing an available previous version of the data
2098 if (ret_data_len > (snapshot_in.snapshot_array_size +
2099 sizeof(struct smb_snapshot_array)))
2100 ret_data_len = snapshot_in.snapshot_array_size +
2101 sizeof(struct smb_snapshot_array);
2103 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
2114 smb3_notify(const unsigned int xid, struct file *pfile,
2115 void __user *ioc_buf, bool return_changes)
2117 struct smb3_notify_info notify;
2118 struct smb3_notify_info __user *pnotify_buf;
2119 struct dentry *dentry = pfile->f_path.dentry;
2120 struct inode *inode = file_inode(pfile);
2121 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2122 struct cifs_open_parms oparms;
2123 struct cifs_fid fid;
2124 struct cifs_tcon *tcon;
2125 const unsigned char *path;
2126 char *returned_ioctl_info = NULL;
2127 void *page = alloc_dentry_path();
2128 __le16 *utf16_path = NULL;
2129 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2133 path = build_path_from_dentry(dentry, page);
2139 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2140 if (utf16_path == NULL) {
2145 if (return_changes) {
2146 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify_info))) {
2151 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify))) {
2155 notify.data_len = 0;
2158 tcon = cifs_sb_master_tcon(cifs_sb);
2159 oparms = (struct cifs_open_parms) {
2162 .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
2163 .disposition = FILE_OPEN,
2164 .create_options = cifs_create_options(cifs_sb, 0),
2168 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
2173 rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid,
2174 notify.watch_tree, notify.completion_filter,
2175 notify.data_len, &returned_ioctl_info, &ret_len);
2177 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2179 cifs_dbg(FYI, "change notify for path %s rc %d\n", path, rc);
2180 if (return_changes && (ret_len > 0) && (notify.data_len > 0)) {
2181 if (ret_len > notify.data_len)
2182 ret_len = notify.data_len;
2183 pnotify_buf = (struct smb3_notify_info __user *)ioc_buf;
2184 if (copy_to_user(pnotify_buf->notify_data, returned_ioctl_info, ret_len))
2186 else if (copy_to_user(&pnotify_buf->data_len, &ret_len, sizeof(ret_len)))
2189 kfree(returned_ioctl_info);
2191 free_dentry_path(page);
2197 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
2198 const char *path, struct cifs_sb_info *cifs_sb,
2199 struct cifs_fid *fid, __u16 search_flags,
2200 struct cifs_search_info *srch_inf)
2203 struct smb_rqst rqst[2];
2204 struct kvec rsp_iov[2];
2205 int resp_buftype[2];
2206 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2207 struct kvec qd_iov[SMB2_QUERY_DIRECTORY_IOV_SIZE];
2209 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2210 struct cifs_open_parms oparms;
2211 struct smb2_query_directory_rsp *qd_rsp = NULL;
2212 struct smb2_create_rsp *op_rsp = NULL;
2213 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2214 int retry_count = 0;
2216 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2220 if (smb3_encryption_required(tcon))
2221 flags |= CIFS_TRANSFORM_REQ;
2223 memset(rqst, 0, sizeof(rqst));
2224 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
2225 memset(rsp_iov, 0, sizeof(rsp_iov));
2228 memset(&open_iov, 0, sizeof(open_iov));
2229 rqst[0].rq_iov = open_iov;
2230 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2232 oparms = (struct cifs_open_parms) {
2235 .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
2236 .disposition = FILE_OPEN,
2237 .create_options = cifs_create_options(cifs_sb, 0),
2241 rc = SMB2_open_init(tcon, server,
2242 &rqst[0], &oplock, &oparms, utf16_path);
2245 smb2_set_next_command(tcon, &rqst[0]);
2247 /* Query directory */
2248 srch_inf->entries_in_buffer = 0;
2249 srch_inf->index_of_last_entry = 2;
2251 memset(&qd_iov, 0, sizeof(qd_iov));
2252 rqst[1].rq_iov = qd_iov;
2253 rqst[1].rq_nvec = SMB2_QUERY_DIRECTORY_IOV_SIZE;
2255 rc = SMB2_query_directory_init(xid, tcon, server,
2257 COMPOUND_FID, COMPOUND_FID,
2258 0, srch_inf->info_level);
2262 smb2_set_related(&rqst[1]);
2265 rc = compound_send_recv(xid, tcon->ses, server,
2267 resp_buftype, rsp_iov);
2269 if (rc == -EAGAIN && retry_count++ < 10)
2272 /* If the open failed there is nothing to do */
2273 op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
2274 if (op_rsp == NULL || op_rsp->hdr.Status != STATUS_SUCCESS) {
2275 cifs_dbg(FYI, "query_dir_first: open failed rc=%d\n", rc);
2278 fid->persistent_fid = op_rsp->PersistentFileId;
2279 fid->volatile_fid = op_rsp->VolatileFileId;
2281 /* Anything else than ENODATA means a genuine error */
2282 if (rc && rc != -ENODATA) {
2283 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2284 cifs_dbg(FYI, "query_dir_first: query directory failed rc=%d\n", rc);
2285 trace_smb3_query_dir_err(xid, fid->persistent_fid,
2286 tcon->tid, tcon->ses->Suid, 0, 0, rc);
2290 atomic_inc(&tcon->num_remote_opens);
2292 qd_rsp = (struct smb2_query_directory_rsp *)rsp_iov[1].iov_base;
2293 if (qd_rsp->hdr.Status == STATUS_NO_MORE_FILES) {
2294 trace_smb3_query_dir_done(xid, fid->persistent_fid,
2295 tcon->tid, tcon->ses->Suid, 0, 0);
2296 srch_inf->endOfSearch = true;
2301 rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1],
2304 trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid,
2305 tcon->ses->Suid, 0, 0, rc);
2308 resp_buftype[1] = CIFS_NO_BUFFER;
2310 trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid,
2311 tcon->ses->Suid, 0, srch_inf->entries_in_buffer);
2315 SMB2_open_free(&rqst[0]);
2316 SMB2_query_directory_free(&rqst[1]);
2317 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2318 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2323 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
2324 struct cifs_fid *fid, __u16 search_flags,
2325 struct cifs_search_info *srch_inf)
2327 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
2328 fid->volatile_fid, 0, srch_inf);
2332 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
2333 struct cifs_fid *fid)
2335 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2339 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2340 * the number of credits and return true. Otherwise - return false.
2343 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
2345 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2346 int scredits, in_flight;
2348 if (shdr->Status != STATUS_PENDING)
2351 if (shdr->CreditRequest) {
2352 spin_lock(&server->req_lock);
2353 server->credits += le16_to_cpu(shdr->CreditRequest);
2354 scredits = server->credits;
2355 in_flight = server->in_flight;
2356 spin_unlock(&server->req_lock);
2357 wake_up(&server->request_q);
2359 trace_smb3_pend_credits(server->CurrentMid,
2360 server->conn_id, server->hostname, scredits,
2361 le16_to_cpu(shdr->CreditRequest), in_flight);
2362 cifs_dbg(FYI, "%s: status pending add %u credits total=%d\n",
2363 __func__, le16_to_cpu(shdr->CreditRequest), scredits);
2370 smb2_is_session_expired(char *buf)
2372 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2374 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
2375 shdr->Status != STATUS_USER_SESSION_DELETED)
2378 trace_smb3_ses_expired(le32_to_cpu(shdr->Id.SyncId.TreeId),
2379 le64_to_cpu(shdr->SessionId),
2380 le16_to_cpu(shdr->Command),
2381 le64_to_cpu(shdr->MessageId));
2382 cifs_dbg(FYI, "Session expired or deleted\n");
2388 smb2_is_status_io_timeout(char *buf)
2390 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2392 if (shdr->Status == STATUS_IO_TIMEOUT)
2399 smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server)
2401 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2402 struct TCP_Server_Info *pserver;
2403 struct cifs_ses *ses;
2404 struct cifs_tcon *tcon;
2406 if (shdr->Status != STATUS_NETWORK_NAME_DELETED)
2409 /* If server is a channel, select the primary channel */
2410 pserver = SERVER_IS_CHAN(server) ? server->primary_server : server;
2412 spin_lock(&cifs_tcp_ses_lock);
2413 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
2414 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
2415 if (tcon->tid == le32_to_cpu(shdr->Id.SyncId.TreeId)) {
2416 spin_lock(&tcon->tc_lock);
2417 tcon->need_reconnect = true;
2418 spin_unlock(&tcon->tc_lock);
2419 spin_unlock(&cifs_tcp_ses_lock);
2420 pr_warn_once("Server share %s deleted.\n",
2426 spin_unlock(&cifs_tcp_ses_lock);
2432 smb2_oplock_response(struct cifs_tcon *tcon, __u64 persistent_fid,
2433 __u64 volatile_fid, __u16 net_fid, struct cifsInodeInfo *cinode)
2435 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
2436 return SMB2_lease_break(0, tcon, cinode->lease_key,
2437 smb2_get_lease_state(cinode));
2439 return SMB2_oplock_break(0, tcon, persistent_fid, volatile_fid,
2440 CIFS_CACHE_READ(cinode) ? 1 : 0);
2444 smb2_set_related(struct smb_rqst *rqst)
2446 struct smb2_hdr *shdr;
2448 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2450 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2453 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2456 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
2459 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
2461 struct smb2_hdr *shdr;
2462 struct cifs_ses *ses = tcon->ses;
2463 struct TCP_Server_Info *server = ses->server;
2464 unsigned long len = smb_rqst_len(server, rqst);
2467 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2469 cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2473 /* SMB headers in a compound are 8 byte aligned. */
2475 /* No padding needed */
2479 num_padding = 8 - (len & 7);
2480 if (!smb3_encryption_required(tcon)) {
2482 * If we do not have encryption then we can just add an extra
2483 * iov for the padding.
2485 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2486 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2491 * We can not add a small padding iov for the encryption case
2492 * because the encryption framework can not handle the padding
2494 * We have to flatten this into a single buffer and add
2495 * the padding to it.
2497 for (i = 1; i < rqst->rq_nvec; i++) {
2498 memcpy(rqst->rq_iov[0].iov_base +
2499 rqst->rq_iov[0].iov_len,
2500 rqst->rq_iov[i].iov_base,
2501 rqst->rq_iov[i].iov_len);
2502 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2504 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2506 rqst->rq_iov[0].iov_len += num_padding;
2512 shdr->NextCommand = cpu_to_le32(len);
2516 * Passes the query info response back to the caller on success.
2517 * Caller need to free this with free_rsp_buf().
2520 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2521 const char *path, u32 desired_access,
2522 u32 class, u32 type, u32 output_len,
2523 struct kvec *rsp, int *buftype,
2524 struct cifs_sb_info *cifs_sb)
2526 struct smb2_compound_vars *vars;
2527 struct cifs_ses *ses = tcon->ses;
2528 struct TCP_Server_Info *server = cifs_pick_channel(ses);
2529 int flags = CIFS_CP_CREATE_CLOSE_OP;
2530 struct smb_rqst *rqst;
2531 int resp_buftype[3];
2532 struct kvec *rsp_iov;
2533 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2534 struct cifs_open_parms oparms;
2535 struct cifs_fid fid;
2538 struct cached_fid *cfid = NULL;
2542 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2546 if (smb3_encryption_required(tcon))
2547 flags |= CIFS_TRANSFORM_REQ;
2549 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2550 vars = kzalloc(sizeof(*vars), GFP_KERNEL);
2556 rsp_iov = vars->rsp_iov;
2559 * We can only call this for things we know are directories.
2561 if (!strcmp(path, ""))
2562 open_cached_dir(xid, tcon, path, cifs_sb, false,
2563 &cfid); /* cfid null if open dir failed */
2565 rqst[0].rq_iov = vars->open_iov;
2566 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2568 oparms = (struct cifs_open_parms) {
2571 .desired_access = desired_access,
2572 .disposition = FILE_OPEN,
2573 .create_options = cifs_create_options(cifs_sb, 0),
2577 rc = SMB2_open_init(tcon, server,
2578 &rqst[0], &oplock, &oparms, utf16_path);
2581 smb2_set_next_command(tcon, &rqst[0]);
2583 rqst[1].rq_iov = &vars->qi_iov;
2584 rqst[1].rq_nvec = 1;
2587 rc = SMB2_query_info_init(tcon, server,
2589 cfid->fid.persistent_fid,
2590 cfid->fid.volatile_fid,
2595 rc = SMB2_query_info_init(tcon, server,
2606 smb2_set_next_command(tcon, &rqst[1]);
2607 smb2_set_related(&rqst[1]);
2610 rqst[2].rq_iov = &vars->close_iov;
2611 rqst[2].rq_nvec = 1;
2613 rc = SMB2_close_init(tcon, server,
2614 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2617 smb2_set_related(&rqst[2]);
2620 rc = compound_send_recv(xid, ses, server,
2622 &resp_buftype[1], &rsp_iov[1]);
2624 rc = compound_send_recv(xid, ses, server,
2626 resp_buftype, rsp_iov);
2629 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2630 if (rc == -EREMCHG) {
2631 tcon->need_reconnect = true;
2632 pr_warn_once("server share %s deleted\n",
2638 *buftype = resp_buftype[1];
2641 SMB2_open_free(&rqst[0]);
2642 SMB2_query_info_free(&rqst[1]);
2643 SMB2_close_free(&rqst[2]);
2644 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2645 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2647 close_cached_dir(cfid);
2655 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2656 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2658 struct smb2_query_info_rsp *rsp;
2659 struct smb2_fs_full_size_info *info = NULL;
2660 struct kvec rsp_iov = {NULL, 0};
2661 int buftype = CIFS_NO_BUFFER;
2665 rc = smb2_query_info_compound(xid, tcon, "",
2666 FILE_READ_ATTRIBUTES,
2667 FS_FULL_SIZE_INFORMATION,
2668 SMB2_O_INFO_FILESYSTEM,
2669 sizeof(struct smb2_fs_full_size_info),
2670 &rsp_iov, &buftype, cifs_sb);
2674 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2675 buf->f_type = SMB2_SUPER_MAGIC;
2676 info = (struct smb2_fs_full_size_info *)(
2677 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2678 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2679 le32_to_cpu(rsp->OutputBufferLength),
2681 sizeof(struct smb2_fs_full_size_info));
2683 smb2_copy_fs_info_to_kstatfs(info, buf);
2686 trace_smb3_qfs_done(xid, tcon->tid, tcon->ses->Suid, tcon->tree_name, rc);
2687 free_rsp_buf(buftype, rsp_iov.iov_base);
2692 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2693 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2696 __le16 srch_path = 0; /* Null - open root of share */
2697 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2698 struct cifs_open_parms oparms;
2699 struct cifs_fid fid;
2701 if (!tcon->posix_extensions)
2702 return smb2_queryfs(xid, tcon, cifs_sb, buf);
2704 oparms = (struct cifs_open_parms) {
2707 .desired_access = FILE_READ_ATTRIBUTES,
2708 .disposition = FILE_OPEN,
2709 .create_options = cifs_create_options(cifs_sb, 0),
2713 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
2718 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2719 fid.volatile_fid, buf);
2720 buf->f_type = SMB2_SUPER_MAGIC;
2721 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2726 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2728 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2729 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2733 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2734 __u64 length, __u32 type, int lock, int unlock, bool wait)
2736 if (unlock && !lock)
2737 type = SMB2_LOCKFLAG_UNLOCK;
2738 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2739 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2740 current->tgid, length, offset, type, wait);
2744 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2746 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2750 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2752 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2756 smb2_new_lease_key(struct cifs_fid *fid)
2758 generate_random_uuid(fid->lease_key);
2762 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2763 const char *search_name,
2764 struct dfs_info3_param **target_nodes,
2765 unsigned int *num_of_nodes,
2766 const struct nls_table *nls_codepage, int remap)
2769 __le16 *utf16_path = NULL;
2770 int utf16_path_len = 0;
2771 struct cifs_tcon *tcon;
2772 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2773 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2774 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2775 int retry_count = 0;
2777 cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name);
2780 * Try to use the IPC tcon, otherwise just use any
2782 tcon = ses->tcon_ipc;
2784 spin_lock(&cifs_tcp_ses_lock);
2785 tcon = list_first_entry_or_null(&ses->tcon_list,
2790 spin_unlock(&cifs_tcp_ses_lock);
2794 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2800 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2802 nls_codepage, remap);
2808 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2809 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2815 /* Highest DFS referral version understood */
2816 dfs_req->MaxReferralLevel = DFS_VERSION;
2818 /* Path to resolve in an UTF-16 null-terminated string */
2819 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2822 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2823 FSCTL_DFS_GET_REFERRALS,
2824 (char *)dfs_req, dfs_req_size, CIFSMaxBufSize,
2825 (char **)&dfs_rsp, &dfs_rsp_size);
2826 if (!is_retryable_error(rc))
2828 usleep_range(512, 2048);
2829 } while (++retry_count < 5);
2832 if (!is_retryable_error(rc) && rc != -ENOENT && rc != -EOPNOTSUPP)
2833 cifs_tcon_dbg(VFS, "%s: ioctl error: rc=%d\n", __func__, rc);
2837 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
2838 num_of_nodes, target_nodes,
2839 nls_codepage, remap, search_name,
2840 true /* is_unicode */);
2842 cifs_tcon_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc);
2847 if (tcon && !tcon->ipc) {
2848 /* ipc tcons are not refcounted */
2849 spin_lock(&cifs_tcp_ses_lock);
2851 /* tc_count can never go negative */
2852 WARN_ON(tcon->tc_count < 0);
2853 spin_unlock(&cifs_tcp_ses_lock);
2862 parse_reparse_posix(struct reparse_posix_data *symlink_buf,
2863 u32 plen, char **target_path,
2864 struct cifs_sb_info *cifs_sb)
2868 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
2869 len = le16_to_cpu(symlink_buf->ReparseDataLength);
2871 if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
2872 cifs_dbg(VFS, "%lld not a supported symlink type\n",
2873 le64_to_cpu(symlink_buf->InodeType));
2877 *target_path = cifs_strndup_from_utf16(
2878 symlink_buf->PathBuffer,
2879 len, true, cifs_sb->local_nls);
2880 if (!(*target_path))
2883 convert_delimiter(*target_path, '/');
2884 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2890 parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
2891 u32 plen, char **target_path,
2892 struct cifs_sb_info *cifs_sb)
2894 unsigned int sub_len;
2895 unsigned int sub_offset;
2897 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */
2899 sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset);
2900 sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength);
2901 if (sub_offset + 20 > plen ||
2902 sub_offset + sub_len + 20 > plen) {
2903 cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
2907 *target_path = cifs_strndup_from_utf16(
2908 symlink_buf->PathBuffer + sub_offset,
2909 sub_len, true, cifs_sb->local_nls);
2910 if (!(*target_path))
2913 convert_delimiter(*target_path, '/');
2914 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2920 parse_reparse_point(struct reparse_data_buffer *buf,
2921 u32 plen, char **target_path,
2922 struct cifs_sb_info *cifs_sb)
2924 if (plen < sizeof(struct reparse_data_buffer)) {
2925 cifs_dbg(VFS, "reparse buffer is too small. Must be at least 8 bytes but was %d\n",
2930 if (plen < le16_to_cpu(buf->ReparseDataLength) +
2931 sizeof(struct reparse_data_buffer)) {
2932 cifs_dbg(VFS, "srv returned invalid reparse buf length: %d\n",
2937 /* See MS-FSCC 2.1.2 */
2938 switch (le32_to_cpu(buf->ReparseTag)) {
2939 case IO_REPARSE_TAG_NFS:
2940 return parse_reparse_posix(
2941 (struct reparse_posix_data *)buf,
2942 plen, target_path, cifs_sb);
2943 case IO_REPARSE_TAG_SYMLINK:
2944 return parse_reparse_symlink(
2945 (struct reparse_symlink_data_buffer *)buf,
2946 plen, target_path, cifs_sb);
2948 cifs_dbg(VFS, "srv returned unknown symlink buffer tag:0x%08x\n",
2949 le32_to_cpu(buf->ReparseTag));
2954 static int smb2_query_symlink(const unsigned int xid,
2955 struct cifs_tcon *tcon,
2956 struct cifs_sb_info *cifs_sb,
2957 const char *full_path,
2959 struct kvec *rsp_iov)
2961 struct reparse_data_buffer *buf;
2962 struct smb2_ioctl_rsp *io = rsp_iov->iov_base;
2963 u32 plen = le32_to_cpu(io->OutputCount);
2965 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2967 buf = (struct reparse_data_buffer *)((u8 *)io +
2968 le32_to_cpu(io->OutputOffset));
2969 return parse_reparse_point(buf, plen, target_path, cifs_sb);
2972 static int smb2_query_reparse_point(const unsigned int xid,
2973 struct cifs_tcon *tcon,
2974 struct cifs_sb_info *cifs_sb,
2975 const char *full_path,
2976 u32 *tag, struct kvec *rsp,
2979 struct smb2_compound_vars *vars;
2981 __le16 *utf16_path = NULL;
2982 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2983 struct cifs_open_parms oparms;
2984 struct cifs_fid fid;
2985 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2986 int flags = CIFS_CP_CREATE_CLOSE_OP;
2987 struct smb_rqst *rqst;
2988 int resp_buftype[3];
2989 struct kvec *rsp_iov;
2990 struct smb2_ioctl_rsp *ioctl_rsp;
2991 struct reparse_data_buffer *reparse_buf;
2994 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2996 if (smb3_encryption_required(tcon))
2997 flags |= CIFS_TRANSFORM_REQ;
2999 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
3003 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
3004 vars = kzalloc(sizeof(*vars), GFP_KERNEL);
3010 rsp_iov = vars->rsp_iov;
3013 * setup smb2open - TODO add optimization to call cifs_get_readable_path
3014 * to see if there is a handle already open that we can use
3016 rqst[0].rq_iov = vars->open_iov;
3017 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
3019 oparms = (struct cifs_open_parms) {
3022 .desired_access = FILE_READ_ATTRIBUTES,
3023 .disposition = FILE_OPEN,
3024 .create_options = cifs_create_options(cifs_sb, OPEN_REPARSE_POINT),
3028 rc = SMB2_open_init(tcon, server,
3029 &rqst[0], &oplock, &oparms, utf16_path);
3032 smb2_set_next_command(tcon, &rqst[0]);
3036 rqst[1].rq_iov = vars->io_iov;
3037 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3039 rc = SMB2_ioctl_init(tcon, server,
3040 &rqst[1], COMPOUND_FID,
3041 COMPOUND_FID, FSCTL_GET_REPARSE_POINT, NULL, 0,
3043 MAX_SMB2_CREATE_RESPONSE_SIZE -
3044 MAX_SMB2_CLOSE_RESPONSE_SIZE);
3048 smb2_set_next_command(tcon, &rqst[1]);
3049 smb2_set_related(&rqst[1]);
3052 rqst[2].rq_iov = &vars->close_iov;
3053 rqst[2].rq_nvec = 1;
3055 rc = SMB2_close_init(tcon, server,
3056 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3060 smb2_set_related(&rqst[2]);
3062 rc = compound_send_recv(xid, tcon->ses, server,
3064 resp_buftype, rsp_iov);
3066 ioctl_rsp = rsp_iov[1].iov_base;
3069 * Open was successful and we got an ioctl response.
3072 /* See MS-FSCC 2.3.23 */
3074 reparse_buf = (struct reparse_data_buffer *)
3075 ((char *)ioctl_rsp +
3076 le32_to_cpu(ioctl_rsp->OutputOffset));
3077 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3079 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3080 rsp_iov[1].iov_len) {
3081 cifs_tcon_dbg(FYI, "srv returned invalid ioctl len: %d\n",
3086 *tag = le32_to_cpu(reparse_buf->ReparseTag);
3088 *rsp_buftype = resp_buftype[1];
3089 resp_buftype[1] = CIFS_NO_BUFFER;
3093 SMB2_open_free(&rqst[0]);
3094 SMB2_ioctl_free(&rqst[1]);
3095 SMB2_close_free(&rqst[2]);
3096 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3097 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3098 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3105 static struct cifs_ntsd *
3106 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
3107 const struct cifs_fid *cifsfid, u32 *pacllen, u32 info)
3109 struct cifs_ntsd *pntsd = NULL;
3111 int rc = -EOPNOTSUPP;
3112 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3115 return ERR_CAST(tlink);
3118 cifs_dbg(FYI, "trying to get acl\n");
3120 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
3121 cifsfid->volatile_fid, (void **)&pntsd, pacllen,
3125 cifs_put_tlink(tlink);
3127 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3134 static struct cifs_ntsd *
3135 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
3136 const char *path, u32 *pacllen, u32 info)
3138 struct cifs_ntsd *pntsd = NULL;
3139 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3142 struct cifs_tcon *tcon;
3143 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3144 struct cifs_fid fid;
3145 struct cifs_open_parms oparms;
3148 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
3150 return ERR_CAST(tlink);
3152 tcon = tlink_tcon(tlink);
3155 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3162 oparms = (struct cifs_open_parms) {
3165 .desired_access = READ_CONTROL,
3166 .disposition = FILE_OPEN,
3168 * When querying an ACL, even if the file is a symlink
3169 * we want to open the source not the target, and so
3170 * the protocol requires that the client specify this
3171 * flag when opening a reparse point
3173 .create_options = cifs_create_options(cifs_sb, 0) |
3178 if (info & SACL_SECINFO)
3179 oparms.desired_access |= SYSTEM_SECURITY;
3181 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
3185 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3186 fid.volatile_fid, (void **)&pntsd, pacllen,
3188 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3191 cifs_put_tlink(tlink);
3194 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3201 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
3202 struct inode *inode, const char *path, int aclflag)
3204 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3206 int rc, access_flags = 0;
3207 struct cifs_tcon *tcon;
3208 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
3209 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3210 struct cifs_fid fid;
3211 struct cifs_open_parms oparms;
3214 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
3216 return PTR_ERR(tlink);
3218 tcon = tlink_tcon(tlink);
3221 if (aclflag & CIFS_ACL_OWNER || aclflag & CIFS_ACL_GROUP)
3222 access_flags |= WRITE_OWNER;
3223 if (aclflag & CIFS_ACL_SACL)
3224 access_flags |= SYSTEM_SECURITY;
3225 if (aclflag & CIFS_ACL_DACL)
3226 access_flags |= WRITE_DAC;
3228 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3235 oparms = (struct cifs_open_parms) {
3237 .desired_access = access_flags,
3238 .create_options = cifs_create_options(cifs_sb, 0),
3239 .disposition = FILE_OPEN,
3244 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
3248 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3249 fid.volatile_fid, pnntsd, acllen, aclflag);
3250 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3253 cifs_put_tlink(tlink);
3258 /* Retrieve an ACL from the server */
3259 static struct cifs_ntsd *
3260 get_smb2_acl(struct cifs_sb_info *cifs_sb,
3261 struct inode *inode, const char *path,
3262 u32 *pacllen, u32 info)
3264 struct cifs_ntsd *pntsd = NULL;
3265 struct cifsFileInfo *open_file = NULL;
3267 if (inode && !(info & SACL_SECINFO))
3268 open_file = find_readable_file(CIFS_I(inode), true);
3269 if (!open_file || (info & SACL_SECINFO))
3270 return get_smb2_acl_by_path(cifs_sb, path, pacllen, info);
3272 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen, info);
3273 cifsFileInfo_put(open_file);
3277 static long smb3_zero_data(struct file *file, struct cifs_tcon *tcon,
3278 loff_t offset, loff_t len, unsigned int xid)
3280 struct cifsFileInfo *cfile = file->private_data;
3281 struct file_zero_data_information fsctl_buf;
3283 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3285 fsctl_buf.FileOffset = cpu_to_le64(offset);
3286 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3288 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3289 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3291 sizeof(struct file_zero_data_information),
3295 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3296 loff_t offset, loff_t len, bool keep_size)
3298 struct cifs_ses *ses = tcon->ses;
3299 struct inode *inode = file_inode(file);
3300 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3301 struct cifsFileInfo *cfile = file->private_data;
3308 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3309 ses->Suid, offset, len);
3312 filemap_invalidate_lock(inode->i_mapping);
3315 * We zero the range through ioctl, so we need remove the page caches
3316 * first, otherwise the data may be inconsistent with the server.
3318 truncate_pagecache_range(inode, offset, offset + len - 1);
3320 /* if file not oplocked can't be sure whether asking to extend size */
3322 if (keep_size == false && !CIFS_CACHE_READ(cifsi))
3323 goto zero_range_exit;
3325 rc = smb3_zero_data(file, tcon, offset, len, xid);
3327 goto zero_range_exit;
3330 * do we also need to change the size of the file?
3332 if (keep_size == false && i_size_read(inode) < offset + len) {
3333 eof = cpu_to_le64(offset + len);
3334 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3335 cfile->fid.volatile_fid, cfile->pid, &eof);
3339 filemap_invalidate_unlock(inode->i_mapping);
3340 inode_unlock(inode);
3343 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
3344 ses->Suid, offset, len, rc);
3346 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
3347 ses->Suid, offset, len);
3351 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
3352 loff_t offset, loff_t len)
3354 struct inode *inode = file_inode(file);
3355 struct cifsFileInfo *cfile = file->private_data;
3356 struct file_zero_data_information fsctl_buf;
3359 __u8 set_sparse = 1;
3364 /* Need to make file sparse, if not already, before freeing range. */
3365 /* Consider adding equivalent for compressed since it could also work */
3366 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
3371 filemap_invalidate_lock(inode->i_mapping);
3373 * We implement the punch hole through ioctl, so we need remove the page
3374 * caches first, otherwise the data may be inconsistent with the server.
3376 truncate_pagecache_range(inode, offset, offset + len - 1);
3378 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3380 fsctl_buf.FileOffset = cpu_to_le64(offset);
3381 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3383 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3384 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3386 sizeof(struct file_zero_data_information),
3387 CIFSMaxBufSize, NULL, NULL);
3388 filemap_invalidate_unlock(inode->i_mapping);
3390 inode_unlock(inode);
3395 static int smb3_simple_fallocate_write_range(unsigned int xid,
3396 struct cifs_tcon *tcon,
3397 struct cifsFileInfo *cfile,
3398 loff_t off, loff_t len,
3401 struct cifs_io_parms io_parms = {0};
3406 io_parms.netfid = cfile->fid.netfid;
3407 io_parms.pid = current->tgid;
3408 io_parms.tcon = tcon;
3409 io_parms.persistent_fid = cfile->fid.persistent_fid;
3410 io_parms.volatile_fid = cfile->fid.volatile_fid;
3413 io_parms.offset = off;
3414 io_parms.length = len;
3415 if (io_parms.length > SMB2_MAX_BUFFER_SIZE)
3416 io_parms.length = SMB2_MAX_BUFFER_SIZE;
3417 /* iov[0] is reserved for smb header */
3418 iov[1].iov_base = buf;
3419 iov[1].iov_len = io_parms.length;
3420 rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
3432 static int smb3_simple_fallocate_range(unsigned int xid,
3433 struct cifs_tcon *tcon,
3434 struct cifsFileInfo *cfile,
3435 loff_t off, loff_t len)
3437 struct file_allocated_range_buffer in_data, *out_data = NULL, *tmp_data;
3443 in_data.file_offset = cpu_to_le64(off);
3444 in_data.length = cpu_to_le64(len);
3445 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3446 cfile->fid.volatile_fid,
3447 FSCTL_QUERY_ALLOCATED_RANGES,
3448 (char *)&in_data, sizeof(in_data),
3449 1024 * sizeof(struct file_allocated_range_buffer),
3450 (char **)&out_data, &out_data_len);
3454 buf = kzalloc(1024 * 1024, GFP_KERNEL);
3460 tmp_data = out_data;
3463 * The rest of the region is unmapped so write it all.
3465 if (out_data_len == 0) {
3466 rc = smb3_simple_fallocate_write_range(xid, tcon,
3467 cfile, off, len, buf);
3471 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3476 if (off < le64_to_cpu(tmp_data->file_offset)) {
3478 * We are at a hole. Write until the end of the region
3479 * or until the next allocated data,
3480 * whichever comes next.
3482 l = le64_to_cpu(tmp_data->file_offset) - off;
3485 rc = smb3_simple_fallocate_write_range(xid, tcon,
3486 cfile, off, l, buf);
3495 * We are at a section of allocated data, just skip forward
3496 * until the end of the data or the end of the region
3497 * we are supposed to fallocate, whichever comes first.
3499 l = le64_to_cpu(tmp_data->length);
3505 tmp_data = &tmp_data[1];
3506 out_data_len -= sizeof(struct file_allocated_range_buffer);
3516 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3517 loff_t off, loff_t len, bool keep_size)
3519 struct inode *inode;
3520 struct cifsInodeInfo *cifsi;
3521 struct cifsFileInfo *cfile = file->private_data;
3522 long rc = -EOPNOTSUPP;
3528 inode = d_inode(cfile->dentry);
3529 cifsi = CIFS_I(inode);
3531 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3532 tcon->ses->Suid, off, len);
3533 /* if file not oplocked can't be sure whether asking to extend size */
3534 if (!CIFS_CACHE_READ(cifsi))
3535 if (keep_size == false) {
3536 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3537 tcon->tid, tcon->ses->Suid, off, len, rc);
3543 * Extending the file
3545 if ((keep_size == false) && i_size_read(inode) < off + len) {
3546 rc = inode_newsize_ok(inode, off + len);
3550 if (cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)
3551 smb2_set_sparse(xid, tcon, cfile, inode, false);
3553 eof = cpu_to_le64(off + len);
3554 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3555 cfile->fid.volatile_fid, cfile->pid, &eof);
3557 cifsi->server_eof = off + len;
3558 cifs_setsize(inode, off + len);
3559 cifs_truncate_page(inode->i_mapping, inode->i_size);
3560 truncate_setsize(inode, off + len);
3566 * Files are non-sparse by default so falloc may be a no-op
3567 * Must check if file sparse. If not sparse, and since we are not
3568 * extending then no need to do anything since file already allocated
3570 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
3575 if (keep_size == true) {
3577 * We can not preallocate pages beyond the end of the file
3580 if (off >= i_size_read(inode)) {
3585 * For fallocates that are partially beyond the end of file,
3586 * clamp len so we only fallocate up to the end of file.
3588 if (off + len > i_size_read(inode)) {
3589 len = i_size_read(inode) - off;
3593 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3595 * At this point, we are trying to fallocate an internal
3596 * regions of a sparse file. Since smb2 does not have a
3597 * fallocate command we have two otions on how to emulate this.
3598 * We can either turn the entire file to become non-sparse
3599 * which we only do if the fallocate is for virtually
3600 * the whole file, or we can overwrite the region with zeroes
3601 * using SMB2_write, which could be prohibitevly expensive
3605 * We are only trying to fallocate a small region so
3606 * just write it with zero.
3608 if (len <= 1024 * 1024) {
3609 rc = smb3_simple_fallocate_range(xid, tcon, cfile,
3615 * Check if falloc starts within first few pages of file
3616 * and ends within a few pages of the end of file to
3617 * ensure that most of file is being forced to be
3618 * fallocated now. If so then setting whole file sparse
3619 * ie potentially making a few extra pages at the beginning
3620 * or end of the file non-sparse via set_sparse is harmless.
3622 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
3628 smb2_set_sparse(xid, tcon, cfile, inode, false);
3633 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3634 tcon->ses->Suid, off, len, rc);
3636 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3637 tcon->ses->Suid, off, len);
3643 static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
3644 loff_t off, loff_t len)
3648 struct inode *inode = file_inode(file);
3649 struct cifsFileInfo *cfile = file->private_data;
3650 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3658 old_eof = i_size_read(inode);
3659 if ((off >= old_eof) ||
3660 off + len >= old_eof) {
3665 filemap_invalidate_lock(inode->i_mapping);
3666 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof - 1);
3670 truncate_pagecache_range(inode, off, old_eof);
3672 rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
3673 old_eof - off - len, off);
3677 eof = cpu_to_le64(old_eof - len);
3678 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3679 cfile->fid.volatile_fid, cfile->pid, &eof);
3685 cifsi->server_eof = i_size_read(inode) - len;
3686 truncate_setsize(inode, cifsi->server_eof);
3687 fscache_resize_cookie(cifs_inode_cookie(inode), cifsi->server_eof);
3689 filemap_invalidate_unlock(inode->i_mapping);
3691 inode_unlock(inode);
3696 static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
3697 loff_t off, loff_t len)
3701 struct cifsFileInfo *cfile = file->private_data;
3702 struct inode *inode = file_inode(file);
3704 __u64 count, old_eof;
3710 old_eof = i_size_read(inode);
3711 if (off >= old_eof) {
3716 count = old_eof - off;
3717 eof = cpu_to_le64(old_eof + len);
3719 filemap_invalidate_lock(inode->i_mapping);
3720 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof + len - 1);
3723 truncate_pagecache_range(inode, off, old_eof);
3725 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3726 cfile->fid.volatile_fid, cfile->pid, &eof);
3730 rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len);
3734 rc = smb3_zero_data(file, tcon, off, len, xid);
3740 filemap_invalidate_unlock(inode->i_mapping);
3742 inode_unlock(inode);
3747 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3749 struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3750 struct cifsInodeInfo *cifsi;
3751 struct inode *inode;
3753 struct file_allocated_range_buffer in_data, *out_data = NULL;
3757 if (whence != SEEK_HOLE && whence != SEEK_DATA)
3758 return generic_file_llseek(file, offset, whence);
3760 inode = d_inode(cfile->dentry);
3761 cifsi = CIFS_I(inode);
3763 if (offset < 0 || offset >= i_size_read(inode))
3768 * We need to be sure that all dirty pages are written as they
3769 * might fill holes on the server.
3770 * Note that we also MUST flush any written pages since at least
3771 * some servers (Windows2016) will not reflect recent writes in
3772 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3774 wrcfile = find_writable_file(cifsi, FIND_WR_ANY);
3776 filemap_write_and_wait(inode->i_mapping);
3777 smb2_flush_file(xid, tcon, &wrcfile->fid);
3778 cifsFileInfo_put(wrcfile);
3781 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3782 if (whence == SEEK_HOLE)
3783 offset = i_size_read(inode);
3787 in_data.file_offset = cpu_to_le64(offset);
3788 in_data.length = cpu_to_le64(i_size_read(inode));
3790 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3791 cfile->fid.volatile_fid,
3792 FSCTL_QUERY_ALLOCATED_RANGES,
3793 (char *)&in_data, sizeof(in_data),
3794 sizeof(struct file_allocated_range_buffer),
3795 (char **)&out_data, &out_data_len);
3801 if (whence == SEEK_HOLE && out_data_len == 0)
3804 if (whence == SEEK_DATA && out_data_len == 0) {
3809 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3813 if (whence == SEEK_DATA) {
3814 offset = le64_to_cpu(out_data->file_offset);
3817 if (offset < le64_to_cpu(out_data->file_offset))
3820 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3826 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3831 static int smb3_fiemap(struct cifs_tcon *tcon,
3832 struct cifsFileInfo *cfile,
3833 struct fiemap_extent_info *fei, u64 start, u64 len)
3836 struct file_allocated_range_buffer in_data, *out_data;
3838 int i, num, rc, flags, last_blob;
3841 rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0);
3847 in_data.file_offset = cpu_to_le64(start);
3848 in_data.length = cpu_to_le64(len);
3850 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3851 cfile->fid.volatile_fid,
3852 FSCTL_QUERY_ALLOCATED_RANGES,
3853 (char *)&in_data, sizeof(in_data),
3854 1024 * sizeof(struct file_allocated_range_buffer),
3855 (char **)&out_data, &out_data_len);
3864 if (out_data_len && out_data_len < sizeof(struct file_allocated_range_buffer)) {
3868 if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3873 num = out_data_len / sizeof(struct file_allocated_range_buffer);
3874 for (i = 0; i < num; i++) {
3876 if (i == num - 1 && last_blob)
3877 flags |= FIEMAP_EXTENT_LAST;
3879 rc = fiemap_fill_next_extent(fei,
3880 le64_to_cpu(out_data[i].file_offset),
3881 le64_to_cpu(out_data[i].file_offset),
3882 le64_to_cpu(out_data[i].length),
3893 next = le64_to_cpu(out_data[num - 1].file_offset) +
3894 le64_to_cpu(out_data[num - 1].length);
3895 len = len - (next - start);
3906 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
3907 loff_t off, loff_t len)
3909 /* KEEP_SIZE already checked for by do_fallocate */
3910 if (mode & FALLOC_FL_PUNCH_HOLE)
3911 return smb3_punch_hole(file, tcon, off, len);
3912 else if (mode & FALLOC_FL_ZERO_RANGE) {
3913 if (mode & FALLOC_FL_KEEP_SIZE)
3914 return smb3_zero_range(file, tcon, off, len, true);
3915 return smb3_zero_range(file, tcon, off, len, false);
3916 } else if (mode == FALLOC_FL_KEEP_SIZE)
3917 return smb3_simple_falloc(file, tcon, off, len, true);
3918 else if (mode == FALLOC_FL_COLLAPSE_RANGE)
3919 return smb3_collapse_range(file, tcon, off, len);
3920 else if (mode == FALLOC_FL_INSERT_RANGE)
3921 return smb3_insert_range(file, tcon, off, len);
3923 return smb3_simple_falloc(file, tcon, off, len, false);
3929 smb2_downgrade_oplock(struct TCP_Server_Info *server,
3930 struct cifsInodeInfo *cinode, __u32 oplock,
3931 unsigned int epoch, bool *purge_cache)
3933 server->ops->set_oplock_level(cinode, oplock, 0, NULL);
3937 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3938 unsigned int epoch, bool *purge_cache);
3941 smb3_downgrade_oplock(struct TCP_Server_Info *server,
3942 struct cifsInodeInfo *cinode, __u32 oplock,
3943 unsigned int epoch, bool *purge_cache)
3945 unsigned int old_state = cinode->oplock;
3946 unsigned int old_epoch = cinode->epoch;
3947 unsigned int new_state;
3949 if (epoch > old_epoch) {
3950 smb21_set_oplock_level(cinode, oplock, 0, NULL);
3951 cinode->epoch = epoch;
3954 new_state = cinode->oplock;
3955 *purge_cache = false;
3957 if ((old_state & CIFS_CACHE_READ_FLG) != 0 &&
3958 (new_state & CIFS_CACHE_READ_FLG) == 0)
3959 *purge_cache = true;
3960 else if (old_state == new_state && (epoch - old_epoch > 1))
3961 *purge_cache = true;
3965 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3966 unsigned int epoch, bool *purge_cache)
3969 cinode->lease_granted = false;
3970 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3972 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
3973 cinode->oplock = CIFS_CACHE_RHW_FLG;
3974 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
3975 &cinode->netfs.inode);
3976 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
3977 cinode->oplock = CIFS_CACHE_RW_FLG;
3978 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
3979 &cinode->netfs.inode);
3980 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
3981 cinode->oplock = CIFS_CACHE_READ_FLG;
3982 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
3983 &cinode->netfs.inode);
3989 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3990 unsigned int epoch, bool *purge_cache)
3992 char message[5] = {0};
3993 unsigned int new_oplock = 0;
3996 cinode->lease_granted = true;
3997 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
4000 /* Check if the server granted an oplock rather than a lease */
4001 if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4002 return smb2_set_oplock_level(cinode, oplock, epoch,
4005 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
4006 new_oplock |= CIFS_CACHE_READ_FLG;
4007 strcat(message, "R");
4009 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
4010 new_oplock |= CIFS_CACHE_HANDLE_FLG;
4011 strcat(message, "H");
4013 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
4014 new_oplock |= CIFS_CACHE_WRITE_FLG;
4015 strcat(message, "W");
4018 strncpy(message, "None", sizeof(message));
4020 cinode->oplock = new_oplock;
4021 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
4022 &cinode->netfs.inode);
4026 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4027 unsigned int epoch, bool *purge_cache)
4029 unsigned int old_oplock = cinode->oplock;
4031 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
4034 *purge_cache = false;
4035 if (old_oplock == CIFS_CACHE_READ_FLG) {
4036 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
4037 (epoch - cinode->epoch > 0))
4038 *purge_cache = true;
4039 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4040 (epoch - cinode->epoch > 1))
4041 *purge_cache = true;
4042 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4043 (epoch - cinode->epoch > 1))
4044 *purge_cache = true;
4045 else if (cinode->oplock == 0 &&
4046 (epoch - cinode->epoch > 0))
4047 *purge_cache = true;
4048 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
4049 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4050 (epoch - cinode->epoch > 0))
4051 *purge_cache = true;
4052 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4053 (epoch - cinode->epoch > 1))
4054 *purge_cache = true;
4056 cinode->epoch = epoch;
4060 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
4062 smb2_is_read_op(__u32 oplock)
4064 return oplock == SMB2_OPLOCK_LEVEL_II;
4066 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
4069 smb21_is_read_op(__u32 oplock)
4071 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
4072 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
4076 map_oplock_to_lease(u8 oplock)
4078 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4079 return SMB2_LEASE_WRITE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE;
4080 else if (oplock == SMB2_OPLOCK_LEVEL_II)
4081 return SMB2_LEASE_READ_CACHING_LE;
4082 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
4083 return SMB2_LEASE_HANDLE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE |
4084 SMB2_LEASE_WRITE_CACHING_LE;
4089 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
4091 struct create_lease *buf;
4093 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
4097 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4098 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4100 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4101 (struct create_lease, lcontext));
4102 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
4103 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4104 (struct create_lease, Name));
4105 buf->ccontext.NameLength = cpu_to_le16(4);
4106 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4115 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
4117 struct create_lease_v2 *buf;
4119 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
4123 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4124 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4126 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4127 (struct create_lease_v2, lcontext));
4128 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
4129 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4130 (struct create_lease_v2, Name));
4131 buf->ccontext.NameLength = cpu_to_le16(4);
4132 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4141 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4143 struct create_lease *lc = (struct create_lease *)buf;
4145 *epoch = 0; /* not used */
4146 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4147 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4148 return le32_to_cpu(lc->lcontext.LeaseState);
4152 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4154 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
4156 *epoch = le16_to_cpu(lc->lcontext.Epoch);
4157 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4158 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4160 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
4161 return le32_to_cpu(lc->lcontext.LeaseState);
4165 smb2_wp_retry_size(struct inode *inode)
4167 return min_t(unsigned int, CIFS_SB(inode->i_sb)->ctx->wsize,
4168 SMB2_MAX_BUFFER_SIZE);
4172 smb2_dir_needs_close(struct cifsFileInfo *cfile)
4174 return !cfile->invalidHandle;
4178 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
4179 struct smb_rqst *old_rq, __le16 cipher_type)
4181 struct smb2_hdr *shdr =
4182 (struct smb2_hdr *)old_rq->rq_iov[0].iov_base;
4184 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
4185 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
4186 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
4187 tr_hdr->Flags = cpu_to_le16(0x01);
4188 if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4189 (cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4190 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4192 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4193 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
4196 static void *smb2_aead_req_alloc(struct crypto_aead *tfm, const struct smb_rqst *rqst,
4197 int num_rqst, const u8 *sig, u8 **iv,
4198 struct aead_request **req, struct sg_table *sgt,
4199 unsigned int *num_sgs, size_t *sensitive_size)
4201 unsigned int req_size = sizeof(**req) + crypto_aead_reqsize(tfm);
4202 unsigned int iv_size = crypto_aead_ivsize(tfm);
4206 *num_sgs = cifs_get_num_sgs(rqst, num_rqst, sig);
4207 if (IS_ERR_VALUE((long)(int)*num_sgs))
4208 return ERR_PTR(*num_sgs);
4211 len += crypto_aead_alignmask(tfm) & ~(crypto_tfm_ctx_alignment() - 1);
4212 len = ALIGN(len, crypto_tfm_ctx_alignment());
4214 len = ALIGN(len, __alignof__(struct scatterlist));
4215 len += array_size(*num_sgs, sizeof(struct scatterlist));
4216 *sensitive_size = len;
4218 p = kvzalloc(len, GFP_NOFS);
4220 return ERR_PTR(-ENOMEM);
4222 *iv = (u8 *)PTR_ALIGN(p, crypto_aead_alignmask(tfm) + 1);
4223 *req = (struct aead_request *)PTR_ALIGN(*iv + iv_size,
4224 crypto_tfm_ctx_alignment());
4225 sgt->sgl = (struct scatterlist *)PTR_ALIGN((u8 *)*req + req_size,
4226 __alignof__(struct scatterlist));
4230 static void *smb2_get_aead_req(struct crypto_aead *tfm, struct smb_rqst *rqst,
4231 int num_rqst, const u8 *sig, u8 **iv,
4232 struct aead_request **req, struct scatterlist **sgl,
4233 size_t *sensitive_size)
4235 struct sg_table sgtable = {};
4236 unsigned int skip, num_sgs, i, j;
4240 p = smb2_aead_req_alloc(tfm, rqst, num_rqst, sig, iv, req, &sgtable,
4241 &num_sgs, sensitive_size);
4245 sg_init_marker(sgtable.sgl, num_sgs);
4248 * The first rqst has a transform header where the
4249 * first 20 bytes are not part of the encrypted blob.
4253 for (i = 0; i < num_rqst; i++) {
4254 struct iov_iter *iter = &rqst[i].rq_iter;
4255 size_t count = iov_iter_count(iter);
4257 for (j = 0; j < rqst[i].rq_nvec; j++) {
4258 cifs_sg_set_buf(&sgtable,
4259 rqst[i].rq_iov[j].iov_base + skip,
4260 rqst[i].rq_iov[j].iov_len - skip);
4262 /* See the above comment on the 'skip' assignment */
4265 sgtable.orig_nents = sgtable.nents;
4267 rc = extract_iter_to_sg(iter, count, &sgtable,
4268 num_sgs - sgtable.nents, 0);
4269 iov_iter_revert(iter, rc);
4270 sgtable.orig_nents = sgtable.nents;
4273 cifs_sg_set_buf(&sgtable, sig, SMB2_SIGNATURE_SIZE);
4274 sg_mark_end(&sgtable.sgl[sgtable.nents - 1]);
4280 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
4282 struct TCP_Server_Info *pserver;
4283 struct cifs_ses *ses;
4286 /* If server is a channel, select the primary channel */
4287 pserver = SERVER_IS_CHAN(server) ? server->primary_server : server;
4289 spin_lock(&cifs_tcp_ses_lock);
4290 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
4291 if (ses->Suid == ses_id) {
4292 spin_lock(&ses->ses_lock);
4293 ses_enc_key = enc ? ses->smb3encryptionkey :
4294 ses->smb3decryptionkey;
4295 memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE);
4296 spin_unlock(&ses->ses_lock);
4297 spin_unlock(&cifs_tcp_ses_lock);
4301 spin_unlock(&cifs_tcp_ses_lock);
4303 trace_smb3_ses_not_found(ses_id);
4308 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
4309 * iov[0] - transform header (associate data),
4310 * iov[1-N] - SMB2 header and pages - data to encrypt.
4311 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4315 crypt_message(struct TCP_Server_Info *server, int num_rqst,
4316 struct smb_rqst *rqst, int enc)
4318 struct smb2_transform_hdr *tr_hdr =
4319 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
4320 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
4322 struct scatterlist *sg;
4323 u8 sign[SMB2_SIGNATURE_SIZE] = {};
4324 u8 key[SMB3_ENC_DEC_KEY_SIZE];
4325 struct aead_request *req;
4327 DECLARE_CRYPTO_WAIT(wait);
4328 struct crypto_aead *tfm;
4329 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4331 size_t sensitive_size;
4333 rc = smb2_get_enc_key(server, le64_to_cpu(tr_hdr->SessionId), enc, key);
4335 cifs_server_dbg(FYI, "%s: Could not get %scryption key. sid: 0x%llx\n", __func__,
4336 enc ? "en" : "de", le64_to_cpu(tr_hdr->SessionId));
4340 rc = smb3_crypto_aead_allocate(server);
4342 cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
4346 tfm = enc ? server->secmech.enc : server->secmech.dec;
4348 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
4349 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4350 rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
4352 rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE);
4355 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
4359 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
4361 cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
4365 creq = smb2_get_aead_req(tfm, rqst, num_rqst, sign, &iv, &req, &sg,
4368 return PTR_ERR(creq);
4371 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
4372 crypt_len += SMB2_SIGNATURE_SIZE;
4375 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4376 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4377 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4380 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4383 aead_request_set_tfm(req, tfm);
4384 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
4385 aead_request_set_ad(req, assoc_data_len);
4387 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
4388 crypto_req_done, &wait);
4390 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
4391 : crypto_aead_decrypt(req), &wait);
4394 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
4396 kvfree_sensitive(creq, sensitive_size);
4401 * Clear a read buffer, discarding the folios which have XA_MARK_0 set.
4403 static void cifs_clear_xarray_buffer(struct xarray *buffer)
4405 struct folio *folio;
4407 XA_STATE(xas, buffer, 0);
4410 xas_for_each_marked(&xas, folio, ULONG_MAX, XA_MARK_0) {
4418 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
4422 for (i = 0; i < num_rqst; i++)
4423 if (!xa_empty(&rqst[i].rq_buffer))
4424 cifs_clear_xarray_buffer(&rqst[i].rq_buffer);
4428 * This function will initialize new_rq and encrypt the content.
4429 * The first entry, new_rq[0], only contains a single iov which contains
4430 * a smb2_transform_hdr and is pre-allocated by the caller.
4431 * This function then populates new_rq[1+] with the content from olq_rq[0+].
4433 * The end result is an array of smb_rqst structures where the first structure
4434 * only contains a single iov for the transform header which we then can pass
4435 * to crypt_message().
4437 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4438 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
4441 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
4442 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
4444 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
4446 unsigned int orig_len = 0;
4450 for (i = 1; i < num_rqst; i++) {
4451 struct smb_rqst *old = &old_rq[i - 1];
4452 struct smb_rqst *new = &new_rq[i];
4453 struct xarray *buffer = &new->rq_buffer;
4454 size_t size = iov_iter_count(&old->rq_iter), seg, copied = 0;
4456 orig_len += smb_rqst_len(server, old);
4457 new->rq_iov = old->rq_iov;
4458 new->rq_nvec = old->rq_nvec;
4463 unsigned int npages = DIV_ROUND_UP(size, PAGE_SIZE);
4465 for (j = 0; j < npages; j++) {
4469 page = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4473 o = xa_store(buffer, j, page, GFP_KERNEL);
4480 xa_set_mark(buffer, j, XA_MARK_0);
4482 seg = min_t(size_t, size - copied, PAGE_SIZE);
4483 if (copy_page_from_iter(page, 0, seg, &old->rq_iter) != seg) {
4489 iov_iter_xarray(&new->rq_iter, ITER_SOURCE,
4491 new->rq_iter_size = size;
4495 /* fill the 1st iov with a transform header */
4496 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
4498 rc = crypt_message(server, num_rqst, new_rq, 1);
4499 cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
4506 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
4511 smb3_is_transform_hdr(void *buf)
4513 struct smb2_transform_hdr *trhdr = buf;
4515 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
4519 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
4520 unsigned int buf_data_size, struct iov_iter *iter,
4524 struct smb_rqst rqst = {NULL};
4525 size_t iter_size = 0;
4528 iov[0].iov_base = buf;
4529 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
4530 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
4531 iov[1].iov_len = buf_data_size;
4536 rqst.rq_iter = *iter;
4537 rqst.rq_iter_size = iov_iter_count(iter);
4538 iter_size = iov_iter_count(iter);
4541 rc = crypt_message(server, 1, &rqst, 0);
4542 cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
4547 memmove(buf, iov[1].iov_base, buf_data_size);
4550 server->total_read = buf_data_size + iter_size;
4556 cifs_copy_pages_to_iter(struct xarray *pages, unsigned int data_size,
4557 unsigned int skip, struct iov_iter *iter)
4560 unsigned long index;
4562 xa_for_each(pages, index, page) {
4563 size_t n, len = min_t(unsigned int, PAGE_SIZE - skip, data_size);
4565 n = copy_page_to_iter(page, skip, len, iter);
4567 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
4578 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
4579 char *buf, unsigned int buf_len, struct xarray *pages,
4580 unsigned int pages_len, bool is_offloaded)
4582 unsigned int data_offset;
4583 unsigned int data_len;
4584 unsigned int cur_off;
4585 unsigned int cur_page_idx;
4586 unsigned int pad_len;
4587 struct cifs_readdata *rdata = mid->callback_data;
4588 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
4590 bool use_rdma_mr = false;
4592 if (shdr->Command != SMB2_READ) {
4593 cifs_server_dbg(VFS, "only big read responses are supported\n");
4597 if (server->ops->is_session_expired &&
4598 server->ops->is_session_expired(buf)) {
4600 cifs_reconnect(server, true);
4604 if (server->ops->is_status_pending &&
4605 server->ops->is_status_pending(buf, server))
4608 /* set up first two iov to get credits */
4609 rdata->iov[0].iov_base = buf;
4610 rdata->iov[0].iov_len = 0;
4611 rdata->iov[1].iov_base = buf;
4612 rdata->iov[1].iov_len =
4613 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
4614 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
4615 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
4616 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
4617 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
4619 rdata->result = server->ops->map_error(buf, true);
4620 if (rdata->result != 0) {
4621 cifs_dbg(FYI, "%s: server returned error %d\n",
4622 __func__, rdata->result);
4623 /* normal error on read response */
4625 mid->mid_state = MID_RESPONSE_RECEIVED;
4627 dequeue_mid(mid, false);
4631 data_offset = server->ops->read_data_offset(buf);
4632 #ifdef CONFIG_CIFS_SMB_DIRECT
4633 use_rdma_mr = rdata->mr;
4635 data_len = server->ops->read_data_length(buf, use_rdma_mr);
4637 if (data_offset < server->vals->read_rsp_size) {
4639 * win2k8 sometimes sends an offset of 0 when the read
4640 * is beyond the EOF. Treat it as if the data starts just after
4643 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
4644 __func__, data_offset);
4645 data_offset = server->vals->read_rsp_size;
4646 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
4647 /* data_offset is beyond the end of smallbuf */
4648 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
4649 __func__, data_offset);
4650 rdata->result = -EIO;
4652 mid->mid_state = MID_RESPONSE_MALFORMED;
4654 dequeue_mid(mid, rdata->result);
4658 pad_len = data_offset - server->vals->read_rsp_size;
4660 if (buf_len <= data_offset) {
4661 /* read response payload is in pages */
4662 cur_page_idx = pad_len / PAGE_SIZE;
4663 cur_off = pad_len % PAGE_SIZE;
4665 if (cur_page_idx != 0) {
4666 /* data offset is beyond the 1st page of response */
4667 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
4668 __func__, data_offset);
4669 rdata->result = -EIO;
4671 mid->mid_state = MID_RESPONSE_MALFORMED;
4673 dequeue_mid(mid, rdata->result);
4677 if (data_len > pages_len - pad_len) {
4678 /* data_len is corrupt -- discard frame */
4679 rdata->result = -EIO;
4681 mid->mid_state = MID_RESPONSE_MALFORMED;
4683 dequeue_mid(mid, rdata->result);
4687 /* Copy the data to the output I/O iterator. */
4688 rdata->result = cifs_copy_pages_to_iter(pages, pages_len,
4689 cur_off, &rdata->iter);
4690 if (rdata->result != 0) {
4692 mid->mid_state = MID_RESPONSE_MALFORMED;
4694 dequeue_mid(mid, rdata->result);
4697 rdata->got_bytes = pages_len;
4699 } else if (buf_len >= data_offset + data_len) {
4700 /* read response payload is in buf */
4701 WARN_ONCE(pages && !xa_empty(pages),
4702 "read data can be either in buf or in pages");
4703 length = copy_to_iter(buf + data_offset, data_len, &rdata->iter);
4706 rdata->got_bytes = data_len;
4708 /* read response payload cannot be in both buf and pages */
4709 WARN_ONCE(1, "buf can not contain only a part of read data");
4710 rdata->result = -EIO;
4712 mid->mid_state = MID_RESPONSE_MALFORMED;
4714 dequeue_mid(mid, rdata->result);
4719 mid->mid_state = MID_RESPONSE_RECEIVED;
4721 dequeue_mid(mid, false);
4725 struct smb2_decrypt_work {
4726 struct work_struct decrypt;
4727 struct TCP_Server_Info *server;
4728 struct xarray buffer;
4734 static void smb2_decrypt_offload(struct work_struct *work)
4736 struct smb2_decrypt_work *dw = container_of(work,
4737 struct smb2_decrypt_work, decrypt);
4739 struct mid_q_entry *mid;
4740 struct iov_iter iter;
4742 iov_iter_xarray(&iter, ITER_DEST, &dw->buffer, 0, dw->len);
4743 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
4746 cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
4750 dw->server->lstrp = jiffies;
4751 mid = smb2_find_dequeue_mid(dw->server, dw->buf);
4753 cifs_dbg(FYI, "mid not found\n");
4755 mid->decrypted = true;
4756 rc = handle_read_data(dw->server, mid, dw->buf,
4757 dw->server->vals->read_rsp_size,
4758 &dw->buffer, dw->len,
4761 #ifdef CONFIG_CIFS_STATS2
4762 mid->when_received = jiffies;
4764 if (dw->server->ops->is_network_name_deleted)
4765 dw->server->ops->is_network_name_deleted(dw->buf,
4770 spin_lock(&dw->server->srv_lock);
4771 if (dw->server->tcpStatus == CifsNeedReconnect) {
4772 spin_lock(&dw->server->mid_lock);
4773 mid->mid_state = MID_RETRY_NEEDED;
4774 spin_unlock(&dw->server->mid_lock);
4775 spin_unlock(&dw->server->srv_lock);
4778 spin_lock(&dw->server->mid_lock);
4779 mid->mid_state = MID_REQUEST_SUBMITTED;
4780 mid->mid_flags &= ~(MID_DELETED);
4781 list_add_tail(&mid->qhead,
4782 &dw->server->pending_mid_q);
4783 spin_unlock(&dw->server->mid_lock);
4784 spin_unlock(&dw->server->srv_lock);
4791 cifs_clear_xarray_buffer(&dw->buffer);
4792 cifs_small_buf_release(dw->buf);
4798 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
4802 char *buf = server->smallbuf;
4803 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4804 struct iov_iter iter;
4805 unsigned int len, npages;
4806 unsigned int buflen = server->pdu_size;
4809 struct smb2_decrypt_work *dw;
4811 dw = kzalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL);
4814 xa_init(&dw->buffer);
4815 INIT_WORK(&dw->decrypt, smb2_decrypt_offload);
4816 dw->server = server;
4819 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
4820 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
4822 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
4825 server->total_read += rc;
4827 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
4828 server->vals->read_rsp_size;
4830 npages = DIV_ROUND_UP(len, PAGE_SIZE);
4833 for (; i < npages; i++) {
4836 page = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4840 old = xa_store(&dw->buffer, i, page, GFP_KERNEL);
4841 if (xa_is_err(old)) {
4846 xa_set_mark(&dw->buffer, i, XA_MARK_0);
4849 iov_iter_xarray(&iter, ITER_DEST, &dw->buffer, 0, npages * PAGE_SIZE);
4851 /* Read the data into the buffer and clear excess bufferage. */
4852 rc = cifs_read_iter_from_socket(server, &iter, dw->len);
4856 server->total_read += rc;
4857 if (rc < npages * PAGE_SIZE)
4858 iov_iter_zero(npages * PAGE_SIZE - rc, &iter);
4859 iov_iter_revert(&iter, npages * PAGE_SIZE);
4860 iov_iter_truncate(&iter, dw->len);
4862 rc = cifs_discard_remaining_data(server);
4867 * For large reads, offload to different thread for better performance,
4868 * use more cores decrypting which can be expensive
4871 if ((server->min_offload) && (server->in_flight > 1) &&
4872 (server->pdu_size >= server->min_offload)) {
4873 dw->buf = server->smallbuf;
4874 server->smallbuf = (char *)cifs_small_buf_get();
4876 queue_work(decrypt_wq, &dw->decrypt);
4877 *num_mids = 0; /* worker thread takes care of finding mid */
4881 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
4886 *mid = smb2_find_mid(server, buf);
4888 cifs_dbg(FYI, "mid not found\n");
4890 cifs_dbg(FYI, "mid found\n");
4891 (*mid)->decrypted = true;
4892 rc = handle_read_data(server, *mid, buf,
4893 server->vals->read_rsp_size,
4894 &dw->buffer, dw->len, false);
4896 if (server->ops->is_network_name_deleted) {
4897 server->ops->is_network_name_deleted(buf,
4904 cifs_clear_xarray_buffer(&dw->buffer);
4909 cifs_discard_remaining_data(server);
4914 receive_encrypted_standard(struct TCP_Server_Info *server,
4915 struct mid_q_entry **mids, char **bufs,
4919 char *buf = server->smallbuf;
4920 struct smb2_hdr *shdr;
4921 unsigned int pdu_length = server->pdu_size;
4922 unsigned int buf_size;
4923 struct mid_q_entry *mid_entry;
4925 char *next_buffer = NULL;
4929 /* switch to large buffer if too big for a small one */
4930 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
4931 server->large_buf = true;
4932 memcpy(server->bigbuf, buf, server->total_read);
4933 buf = server->bigbuf;
4936 /* now read the rest */
4937 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
4938 pdu_length - HEADER_SIZE(server) + 1);
4941 server->total_read += length;
4943 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
4944 length = decrypt_raw_data(server, buf, buf_size, NULL, false);
4948 next_is_large = server->large_buf;
4950 shdr = (struct smb2_hdr *)buf;
4951 if (shdr->NextCommand) {
4953 next_buffer = (char *)cifs_buf_get();
4955 next_buffer = (char *)cifs_small_buf_get();
4957 buf + le32_to_cpu(shdr->NextCommand),
4958 pdu_length - le32_to_cpu(shdr->NextCommand));
4961 mid_entry = smb2_find_mid(server, buf);
4962 if (mid_entry == NULL)
4963 cifs_dbg(FYI, "mid not found\n");
4965 cifs_dbg(FYI, "mid found\n");
4966 mid_entry->decrypted = true;
4967 mid_entry->resp_buf_size = server->pdu_size;
4970 if (*num_mids >= MAX_COMPOUND) {
4971 cifs_server_dbg(VFS, "too many PDUs in compound\n");
4974 bufs[*num_mids] = buf;
4975 mids[(*num_mids)++] = mid_entry;
4977 if (mid_entry && mid_entry->handle)
4978 ret = mid_entry->handle(server, mid_entry);
4980 ret = cifs_handle_standard(server, mid_entry);
4982 if (ret == 0 && shdr->NextCommand) {
4983 pdu_length -= le32_to_cpu(shdr->NextCommand);
4984 server->large_buf = next_is_large;
4986 server->bigbuf = buf = next_buffer;
4988 server->smallbuf = buf = next_buffer;
4990 } else if (ret != 0) {
4992 * ret != 0 here means that we didn't get to handle_mid() thus
4993 * server->smallbuf and server->bigbuf are still valid. We need
4994 * to free next_buffer because it is not going to be used
4998 free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer);
5000 free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer);
5007 smb3_receive_transform(struct TCP_Server_Info *server,
5008 struct mid_q_entry **mids, char **bufs, int *num_mids)
5010 char *buf = server->smallbuf;
5011 unsigned int pdu_length = server->pdu_size;
5012 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
5013 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
5015 if (pdu_length < sizeof(struct smb2_transform_hdr) +
5016 sizeof(struct smb2_hdr)) {
5017 cifs_server_dbg(VFS, "Transform message is too small (%u)\n",
5019 cifs_reconnect(server, true);
5020 return -ECONNABORTED;
5023 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
5024 cifs_server_dbg(VFS, "Transform message is broken\n");
5025 cifs_reconnect(server, true);
5026 return -ECONNABORTED;
5029 /* TODO: add support for compounds containing READ. */
5030 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
5031 return receive_encrypted_read(server, &mids[0], num_mids);
5034 return receive_encrypted_standard(server, mids, bufs, num_mids);
5038 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
5040 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
5042 return handle_read_data(server, mid, buf, server->pdu_size,
5047 smb2_next_header(char *buf)
5049 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
5050 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
5052 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
5053 return sizeof(struct smb2_transform_hdr) +
5054 le32_to_cpu(t_hdr->OriginalMessageSize);
5056 return le32_to_cpu(hdr->NextCommand);
5060 smb2_make_node(unsigned int xid, struct inode *inode,
5061 struct dentry *dentry, struct cifs_tcon *tcon,
5062 const char *full_path, umode_t mode, dev_t dev)
5064 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
5066 struct cifs_open_info_data buf = {};
5067 struct cifs_io_parms io_parms = {0};
5069 struct cifs_fid fid;
5070 struct cifs_open_parms oparms;
5071 unsigned int bytes_written;
5072 struct win_dev *pdev;
5076 * Check if mounted with mount parm 'sfu' mount parm.
5077 * SFU emulation should work with all servers, but only
5078 * supports block and char device (no socket & fifo),
5079 * and was used by default in earlier versions of Windows
5081 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
5085 * TODO: Add ability to create instead via reparse point. Windows (e.g.
5086 * their current NFS server) uses this approach to expose special files
5087 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
5090 if (!S_ISCHR(mode) && !S_ISBLK(mode))
5093 cifs_dbg(FYI, "sfu compat create special file\n");
5095 oparms = (struct cifs_open_parms) {
5098 .desired_access = GENERIC_WRITE,
5099 .create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR |
5100 CREATE_OPTION_SPECIAL),
5101 .disposition = FILE_CREATE,
5106 if (tcon->ses->server->oplocks)
5107 oplock = REQ_OPLOCK;
5110 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, &buf);
5115 * BB Do not bother to decode buf since no local inode yet to put
5116 * timestamps in, but we can reuse it safely.
5119 pdev = (struct win_dev *)&buf.fi;
5120 io_parms.pid = current->tgid;
5121 io_parms.tcon = tcon;
5122 io_parms.offset = 0;
5123 io_parms.length = sizeof(struct win_dev);
5124 iov[1].iov_base = &buf.fi;
5125 iov[1].iov_len = sizeof(struct win_dev);
5126 if (S_ISCHR(mode)) {
5127 memcpy(pdev->type, "IntxCHR", 8);
5128 pdev->major = cpu_to_le64(MAJOR(dev));
5129 pdev->minor = cpu_to_le64(MINOR(dev));
5130 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5131 &bytes_written, iov, 1);
5132 } else if (S_ISBLK(mode)) {
5133 memcpy(pdev->type, "IntxBLK", 8);
5134 pdev->major = cpu_to_le64(MAJOR(dev));
5135 pdev->minor = cpu_to_le64(MINOR(dev));
5136 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5137 &bytes_written, iov, 1);
5139 tcon->ses->server->ops->close(xid, tcon, &fid);
5142 /* FIXME: add code here to set EAs */
5144 cifs_free_open_info(&buf);
5148 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5149 struct smb_version_operations smb20_operations = {
5150 .compare_fids = smb2_compare_fids,
5151 .setup_request = smb2_setup_request,
5152 .setup_async_request = smb2_setup_async_request,
5153 .check_receive = smb2_check_receive,
5154 .add_credits = smb2_add_credits,
5155 .set_credits = smb2_set_credits,
5156 .get_credits_field = smb2_get_credits_field,
5157 .get_credits = smb2_get_credits,
5158 .wait_mtu_credits = cifs_wait_mtu_credits,
5159 .get_next_mid = smb2_get_next_mid,
5160 .revert_current_mid = smb2_revert_current_mid,
5161 .read_data_offset = smb2_read_data_offset,
5162 .read_data_length = smb2_read_data_length,
5163 .map_error = map_smb2_to_linux_error,
5164 .find_mid = smb2_find_mid,
5165 .check_message = smb2_check_message,
5166 .dump_detail = smb2_dump_detail,
5167 .clear_stats = smb2_clear_stats,
5168 .print_stats = smb2_print_stats,
5169 .is_oplock_break = smb2_is_valid_oplock_break,
5170 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5171 .downgrade_oplock = smb2_downgrade_oplock,
5172 .need_neg = smb2_need_neg,
5173 .negotiate = smb2_negotiate,
5174 .negotiate_wsize = smb2_negotiate_wsize,
5175 .negotiate_rsize = smb2_negotiate_rsize,
5176 .sess_setup = SMB2_sess_setup,
5177 .logoff = SMB2_logoff,
5178 .tree_connect = SMB2_tcon,
5179 .tree_disconnect = SMB2_tdis,
5180 .qfs_tcon = smb2_qfs_tcon,
5181 .is_path_accessible = smb2_is_path_accessible,
5182 .can_echo = smb2_can_echo,
5184 .query_path_info = smb2_query_path_info,
5185 .query_reparse_point = smb2_query_reparse_point,
5186 .get_srv_inum = smb2_get_srv_inum,
5187 .query_file_info = smb2_query_file_info,
5188 .set_path_size = smb2_set_path_size,
5189 .set_file_size = smb2_set_file_size,
5190 .set_file_info = smb2_set_file_info,
5191 .set_compression = smb2_set_compression,
5192 .mkdir = smb2_mkdir,
5193 .mkdir_setinfo = smb2_mkdir_setinfo,
5194 .rmdir = smb2_rmdir,
5195 .unlink = smb2_unlink,
5196 .rename = smb2_rename_path,
5197 .create_hardlink = smb2_create_hardlink,
5198 .query_symlink = smb2_query_symlink,
5199 .query_mf_symlink = smb3_query_mf_symlink,
5200 .create_mf_symlink = smb3_create_mf_symlink,
5201 .open = smb2_open_file,
5202 .set_fid = smb2_set_fid,
5203 .close = smb2_close_file,
5204 .flush = smb2_flush_file,
5205 .async_readv = smb2_async_readv,
5206 .async_writev = smb2_async_writev,
5207 .sync_read = smb2_sync_read,
5208 .sync_write = smb2_sync_write,
5209 .query_dir_first = smb2_query_dir_first,
5210 .query_dir_next = smb2_query_dir_next,
5211 .close_dir = smb2_close_dir,
5212 .calc_smb_size = smb2_calc_size,
5213 .is_status_pending = smb2_is_status_pending,
5214 .is_session_expired = smb2_is_session_expired,
5215 .oplock_response = smb2_oplock_response,
5216 .queryfs = smb2_queryfs,
5217 .mand_lock = smb2_mand_lock,
5218 .mand_unlock_range = smb2_unlock_range,
5219 .push_mand_locks = smb2_push_mandatory_locks,
5220 .get_lease_key = smb2_get_lease_key,
5221 .set_lease_key = smb2_set_lease_key,
5222 .new_lease_key = smb2_new_lease_key,
5223 .calc_signature = smb2_calc_signature,
5224 .is_read_op = smb2_is_read_op,
5225 .set_oplock_level = smb2_set_oplock_level,
5226 .create_lease_buf = smb2_create_lease_buf,
5227 .parse_lease_buf = smb2_parse_lease_buf,
5228 .copychunk_range = smb2_copychunk_range,
5229 .wp_retry_size = smb2_wp_retry_size,
5230 .dir_needs_close = smb2_dir_needs_close,
5231 .get_dfs_refer = smb2_get_dfs_refer,
5232 .select_sectype = smb2_select_sectype,
5233 #ifdef CONFIG_CIFS_XATTR
5234 .query_all_EAs = smb2_query_eas,
5235 .set_EA = smb2_set_ea,
5236 #endif /* CIFS_XATTR */
5237 .get_acl = get_smb2_acl,
5238 .get_acl_by_fid = get_smb2_acl_by_fid,
5239 .set_acl = set_smb2_acl,
5240 .next_header = smb2_next_header,
5241 .ioctl_query_info = smb2_ioctl_query_info,
5242 .make_node = smb2_make_node,
5243 .fiemap = smb3_fiemap,
5244 .llseek = smb3_llseek,
5245 .is_status_io_timeout = smb2_is_status_io_timeout,
5246 .is_network_name_deleted = smb2_is_network_name_deleted,
5248 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
5250 struct smb_version_operations smb21_operations = {
5251 .compare_fids = smb2_compare_fids,
5252 .setup_request = smb2_setup_request,
5253 .setup_async_request = smb2_setup_async_request,
5254 .check_receive = smb2_check_receive,
5255 .add_credits = smb2_add_credits,
5256 .set_credits = smb2_set_credits,
5257 .get_credits_field = smb2_get_credits_field,
5258 .get_credits = smb2_get_credits,
5259 .wait_mtu_credits = smb2_wait_mtu_credits,
5260 .adjust_credits = smb2_adjust_credits,
5261 .get_next_mid = smb2_get_next_mid,
5262 .revert_current_mid = smb2_revert_current_mid,
5263 .read_data_offset = smb2_read_data_offset,
5264 .read_data_length = smb2_read_data_length,
5265 .map_error = map_smb2_to_linux_error,
5266 .find_mid = smb2_find_mid,
5267 .check_message = smb2_check_message,
5268 .dump_detail = smb2_dump_detail,
5269 .clear_stats = smb2_clear_stats,
5270 .print_stats = smb2_print_stats,
5271 .is_oplock_break = smb2_is_valid_oplock_break,
5272 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5273 .downgrade_oplock = smb2_downgrade_oplock,
5274 .need_neg = smb2_need_neg,
5275 .negotiate = smb2_negotiate,
5276 .negotiate_wsize = smb2_negotiate_wsize,
5277 .negotiate_rsize = smb2_negotiate_rsize,
5278 .sess_setup = SMB2_sess_setup,
5279 .logoff = SMB2_logoff,
5280 .tree_connect = SMB2_tcon,
5281 .tree_disconnect = SMB2_tdis,
5282 .qfs_tcon = smb2_qfs_tcon,
5283 .is_path_accessible = smb2_is_path_accessible,
5284 .can_echo = smb2_can_echo,
5286 .query_path_info = smb2_query_path_info,
5287 .query_reparse_point = smb2_query_reparse_point,
5288 .get_srv_inum = smb2_get_srv_inum,
5289 .query_file_info = smb2_query_file_info,
5290 .set_path_size = smb2_set_path_size,
5291 .set_file_size = smb2_set_file_size,
5292 .set_file_info = smb2_set_file_info,
5293 .set_compression = smb2_set_compression,
5294 .mkdir = smb2_mkdir,
5295 .mkdir_setinfo = smb2_mkdir_setinfo,
5296 .rmdir = smb2_rmdir,
5297 .unlink = smb2_unlink,
5298 .rename = smb2_rename_path,
5299 .create_hardlink = smb2_create_hardlink,
5300 .query_symlink = smb2_query_symlink,
5301 .query_mf_symlink = smb3_query_mf_symlink,
5302 .create_mf_symlink = smb3_create_mf_symlink,
5303 .open = smb2_open_file,
5304 .set_fid = smb2_set_fid,
5305 .close = smb2_close_file,
5306 .flush = smb2_flush_file,
5307 .async_readv = smb2_async_readv,
5308 .async_writev = smb2_async_writev,
5309 .sync_read = smb2_sync_read,
5310 .sync_write = smb2_sync_write,
5311 .query_dir_first = smb2_query_dir_first,
5312 .query_dir_next = smb2_query_dir_next,
5313 .close_dir = smb2_close_dir,
5314 .calc_smb_size = smb2_calc_size,
5315 .is_status_pending = smb2_is_status_pending,
5316 .is_session_expired = smb2_is_session_expired,
5317 .oplock_response = smb2_oplock_response,
5318 .queryfs = smb2_queryfs,
5319 .mand_lock = smb2_mand_lock,
5320 .mand_unlock_range = smb2_unlock_range,
5321 .push_mand_locks = smb2_push_mandatory_locks,
5322 .get_lease_key = smb2_get_lease_key,
5323 .set_lease_key = smb2_set_lease_key,
5324 .new_lease_key = smb2_new_lease_key,
5325 .calc_signature = smb2_calc_signature,
5326 .is_read_op = smb21_is_read_op,
5327 .set_oplock_level = smb21_set_oplock_level,
5328 .create_lease_buf = smb2_create_lease_buf,
5329 .parse_lease_buf = smb2_parse_lease_buf,
5330 .copychunk_range = smb2_copychunk_range,
5331 .wp_retry_size = smb2_wp_retry_size,
5332 .dir_needs_close = smb2_dir_needs_close,
5333 .enum_snapshots = smb3_enum_snapshots,
5334 .notify = smb3_notify,
5335 .get_dfs_refer = smb2_get_dfs_refer,
5336 .select_sectype = smb2_select_sectype,
5337 #ifdef CONFIG_CIFS_XATTR
5338 .query_all_EAs = smb2_query_eas,
5339 .set_EA = smb2_set_ea,
5340 #endif /* CIFS_XATTR */
5341 .get_acl = get_smb2_acl,
5342 .get_acl_by_fid = get_smb2_acl_by_fid,
5343 .set_acl = set_smb2_acl,
5344 .next_header = smb2_next_header,
5345 .ioctl_query_info = smb2_ioctl_query_info,
5346 .make_node = smb2_make_node,
5347 .fiemap = smb3_fiemap,
5348 .llseek = smb3_llseek,
5349 .is_status_io_timeout = smb2_is_status_io_timeout,
5350 .is_network_name_deleted = smb2_is_network_name_deleted,
5353 struct smb_version_operations smb30_operations = {
5354 .compare_fids = smb2_compare_fids,
5355 .setup_request = smb2_setup_request,
5356 .setup_async_request = smb2_setup_async_request,
5357 .check_receive = smb2_check_receive,
5358 .add_credits = smb2_add_credits,
5359 .set_credits = smb2_set_credits,
5360 .get_credits_field = smb2_get_credits_field,
5361 .get_credits = smb2_get_credits,
5362 .wait_mtu_credits = smb2_wait_mtu_credits,
5363 .adjust_credits = smb2_adjust_credits,
5364 .get_next_mid = smb2_get_next_mid,
5365 .revert_current_mid = smb2_revert_current_mid,
5366 .read_data_offset = smb2_read_data_offset,
5367 .read_data_length = smb2_read_data_length,
5368 .map_error = map_smb2_to_linux_error,
5369 .find_mid = smb2_find_mid,
5370 .check_message = smb2_check_message,
5371 .dump_detail = smb2_dump_detail,
5372 .clear_stats = smb2_clear_stats,
5373 .print_stats = smb2_print_stats,
5374 .dump_share_caps = smb2_dump_share_caps,
5375 .is_oplock_break = smb2_is_valid_oplock_break,
5376 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5377 .downgrade_oplock = smb3_downgrade_oplock,
5378 .need_neg = smb2_need_neg,
5379 .negotiate = smb2_negotiate,
5380 .negotiate_wsize = smb3_negotiate_wsize,
5381 .negotiate_rsize = smb3_negotiate_rsize,
5382 .sess_setup = SMB2_sess_setup,
5383 .logoff = SMB2_logoff,
5384 .tree_connect = SMB2_tcon,
5385 .tree_disconnect = SMB2_tdis,
5386 .qfs_tcon = smb3_qfs_tcon,
5387 .is_path_accessible = smb2_is_path_accessible,
5388 .can_echo = smb2_can_echo,
5390 .query_path_info = smb2_query_path_info,
5391 /* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */
5392 .query_reparse_point = smb2_query_reparse_point,
5393 .get_srv_inum = smb2_get_srv_inum,
5394 .query_file_info = smb2_query_file_info,
5395 .set_path_size = smb2_set_path_size,
5396 .set_file_size = smb2_set_file_size,
5397 .set_file_info = smb2_set_file_info,
5398 .set_compression = smb2_set_compression,
5399 .mkdir = smb2_mkdir,
5400 .mkdir_setinfo = smb2_mkdir_setinfo,
5401 .rmdir = smb2_rmdir,
5402 .unlink = smb2_unlink,
5403 .rename = smb2_rename_path,
5404 .create_hardlink = smb2_create_hardlink,
5405 .query_symlink = smb2_query_symlink,
5406 .query_mf_symlink = smb3_query_mf_symlink,
5407 .create_mf_symlink = smb3_create_mf_symlink,
5408 .open = smb2_open_file,
5409 .set_fid = smb2_set_fid,
5410 .close = smb2_close_file,
5411 .close_getattr = smb2_close_getattr,
5412 .flush = smb2_flush_file,
5413 .async_readv = smb2_async_readv,
5414 .async_writev = smb2_async_writev,
5415 .sync_read = smb2_sync_read,
5416 .sync_write = smb2_sync_write,
5417 .query_dir_first = smb2_query_dir_first,
5418 .query_dir_next = smb2_query_dir_next,
5419 .close_dir = smb2_close_dir,
5420 .calc_smb_size = smb2_calc_size,
5421 .is_status_pending = smb2_is_status_pending,
5422 .is_session_expired = smb2_is_session_expired,
5423 .oplock_response = smb2_oplock_response,
5424 .queryfs = smb2_queryfs,
5425 .mand_lock = smb2_mand_lock,
5426 .mand_unlock_range = smb2_unlock_range,
5427 .push_mand_locks = smb2_push_mandatory_locks,
5428 .get_lease_key = smb2_get_lease_key,
5429 .set_lease_key = smb2_set_lease_key,
5430 .new_lease_key = smb2_new_lease_key,
5431 .generate_signingkey = generate_smb30signingkey,
5432 .calc_signature = smb3_calc_signature,
5433 .set_integrity = smb3_set_integrity,
5434 .is_read_op = smb21_is_read_op,
5435 .set_oplock_level = smb3_set_oplock_level,
5436 .create_lease_buf = smb3_create_lease_buf,
5437 .parse_lease_buf = smb3_parse_lease_buf,
5438 .copychunk_range = smb2_copychunk_range,
5439 .duplicate_extents = smb2_duplicate_extents,
5440 .validate_negotiate = smb3_validate_negotiate,
5441 .wp_retry_size = smb2_wp_retry_size,
5442 .dir_needs_close = smb2_dir_needs_close,
5443 .fallocate = smb3_fallocate,
5444 .enum_snapshots = smb3_enum_snapshots,
5445 .notify = smb3_notify,
5446 .init_transform_rq = smb3_init_transform_rq,
5447 .is_transform_hdr = smb3_is_transform_hdr,
5448 .receive_transform = smb3_receive_transform,
5449 .get_dfs_refer = smb2_get_dfs_refer,
5450 .select_sectype = smb2_select_sectype,
5451 #ifdef CONFIG_CIFS_XATTR
5452 .query_all_EAs = smb2_query_eas,
5453 .set_EA = smb2_set_ea,
5454 #endif /* CIFS_XATTR */
5455 .get_acl = get_smb2_acl,
5456 .get_acl_by_fid = get_smb2_acl_by_fid,
5457 .set_acl = set_smb2_acl,
5458 .next_header = smb2_next_header,
5459 .ioctl_query_info = smb2_ioctl_query_info,
5460 .make_node = smb2_make_node,
5461 .fiemap = smb3_fiemap,
5462 .llseek = smb3_llseek,
5463 .is_status_io_timeout = smb2_is_status_io_timeout,
5464 .is_network_name_deleted = smb2_is_network_name_deleted,
5467 struct smb_version_operations smb311_operations = {
5468 .compare_fids = smb2_compare_fids,
5469 .setup_request = smb2_setup_request,
5470 .setup_async_request = smb2_setup_async_request,
5471 .check_receive = smb2_check_receive,
5472 .add_credits = smb2_add_credits,
5473 .set_credits = smb2_set_credits,
5474 .get_credits_field = smb2_get_credits_field,
5475 .get_credits = smb2_get_credits,
5476 .wait_mtu_credits = smb2_wait_mtu_credits,
5477 .adjust_credits = smb2_adjust_credits,
5478 .get_next_mid = smb2_get_next_mid,
5479 .revert_current_mid = smb2_revert_current_mid,
5480 .read_data_offset = smb2_read_data_offset,
5481 .read_data_length = smb2_read_data_length,
5482 .map_error = map_smb2_to_linux_error,
5483 .find_mid = smb2_find_mid,
5484 .check_message = smb2_check_message,
5485 .dump_detail = smb2_dump_detail,
5486 .clear_stats = smb2_clear_stats,
5487 .print_stats = smb2_print_stats,
5488 .dump_share_caps = smb2_dump_share_caps,
5489 .is_oplock_break = smb2_is_valid_oplock_break,
5490 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5491 .downgrade_oplock = smb3_downgrade_oplock,
5492 .need_neg = smb2_need_neg,
5493 .negotiate = smb2_negotiate,
5494 .negotiate_wsize = smb3_negotiate_wsize,
5495 .negotiate_rsize = smb3_negotiate_rsize,
5496 .sess_setup = SMB2_sess_setup,
5497 .logoff = SMB2_logoff,
5498 .tree_connect = SMB2_tcon,
5499 .tree_disconnect = SMB2_tdis,
5500 .qfs_tcon = smb3_qfs_tcon,
5501 .is_path_accessible = smb2_is_path_accessible,
5502 .can_echo = smb2_can_echo,
5504 .query_path_info = smb2_query_path_info,
5505 .query_reparse_point = smb2_query_reparse_point,
5506 .get_srv_inum = smb2_get_srv_inum,
5507 .query_file_info = smb2_query_file_info,
5508 .set_path_size = smb2_set_path_size,
5509 .set_file_size = smb2_set_file_size,
5510 .set_file_info = smb2_set_file_info,
5511 .set_compression = smb2_set_compression,
5512 .mkdir = smb2_mkdir,
5513 .mkdir_setinfo = smb2_mkdir_setinfo,
5514 .posix_mkdir = smb311_posix_mkdir,
5515 .rmdir = smb2_rmdir,
5516 .unlink = smb2_unlink,
5517 .rename = smb2_rename_path,
5518 .create_hardlink = smb2_create_hardlink,
5519 .query_symlink = smb2_query_symlink,
5520 .query_mf_symlink = smb3_query_mf_symlink,
5521 .create_mf_symlink = smb3_create_mf_symlink,
5522 .open = smb2_open_file,
5523 .set_fid = smb2_set_fid,
5524 .close = smb2_close_file,
5525 .close_getattr = smb2_close_getattr,
5526 .flush = smb2_flush_file,
5527 .async_readv = smb2_async_readv,
5528 .async_writev = smb2_async_writev,
5529 .sync_read = smb2_sync_read,
5530 .sync_write = smb2_sync_write,
5531 .query_dir_first = smb2_query_dir_first,
5532 .query_dir_next = smb2_query_dir_next,
5533 .close_dir = smb2_close_dir,
5534 .calc_smb_size = smb2_calc_size,
5535 .is_status_pending = smb2_is_status_pending,
5536 .is_session_expired = smb2_is_session_expired,
5537 .oplock_response = smb2_oplock_response,
5538 .queryfs = smb311_queryfs,
5539 .mand_lock = smb2_mand_lock,
5540 .mand_unlock_range = smb2_unlock_range,
5541 .push_mand_locks = smb2_push_mandatory_locks,
5542 .get_lease_key = smb2_get_lease_key,
5543 .set_lease_key = smb2_set_lease_key,
5544 .new_lease_key = smb2_new_lease_key,
5545 .generate_signingkey = generate_smb311signingkey,
5546 .calc_signature = smb3_calc_signature,
5547 .set_integrity = smb3_set_integrity,
5548 .is_read_op = smb21_is_read_op,
5549 .set_oplock_level = smb3_set_oplock_level,
5550 .create_lease_buf = smb3_create_lease_buf,
5551 .parse_lease_buf = smb3_parse_lease_buf,
5552 .copychunk_range = smb2_copychunk_range,
5553 .duplicate_extents = smb2_duplicate_extents,
5554 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
5555 .wp_retry_size = smb2_wp_retry_size,
5556 .dir_needs_close = smb2_dir_needs_close,
5557 .fallocate = smb3_fallocate,
5558 .enum_snapshots = smb3_enum_snapshots,
5559 .notify = smb3_notify,
5560 .init_transform_rq = smb3_init_transform_rq,
5561 .is_transform_hdr = smb3_is_transform_hdr,
5562 .receive_transform = smb3_receive_transform,
5563 .get_dfs_refer = smb2_get_dfs_refer,
5564 .select_sectype = smb2_select_sectype,
5565 #ifdef CONFIG_CIFS_XATTR
5566 .query_all_EAs = smb2_query_eas,
5567 .set_EA = smb2_set_ea,
5568 #endif /* CIFS_XATTR */
5569 .get_acl = get_smb2_acl,
5570 .get_acl_by_fid = get_smb2_acl_by_fid,
5571 .set_acl = set_smb2_acl,
5572 .next_header = smb2_next_header,
5573 .ioctl_query_info = smb2_ioctl_query_info,
5574 .make_node = smb2_make_node,
5575 .fiemap = smb3_fiemap,
5576 .llseek = smb3_llseek,
5577 .is_status_io_timeout = smb2_is_status_io_timeout,
5578 .is_network_name_deleted = smb2_is_network_name_deleted,
5581 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5582 struct smb_version_values smb20_values = {
5583 .version_string = SMB20_VERSION_STRING,
5584 .protocol_id = SMB20_PROT_ID,
5585 .req_capabilities = 0, /* MBZ */
5586 .large_lock_type = 0,
5587 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5588 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5589 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5590 .header_size = sizeof(struct smb2_hdr),
5591 .header_preamble_size = 0,
5592 .max_header_size = MAX_SMB2_HDR_SIZE,
5593 .read_rsp_size = sizeof(struct smb2_read_rsp),
5594 .lock_cmd = SMB2_LOCK,
5596 .cap_nt_find = SMB2_NT_FIND,
5597 .cap_large_files = SMB2_LARGE_FILES,
5598 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5599 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5600 .create_lease_size = sizeof(struct create_lease),
5602 #endif /* ALLOW_INSECURE_LEGACY */
5604 struct smb_version_values smb21_values = {
5605 .version_string = SMB21_VERSION_STRING,
5606 .protocol_id = SMB21_PROT_ID,
5607 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
5608 .large_lock_type = 0,
5609 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5610 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5611 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5612 .header_size = sizeof(struct smb2_hdr),
5613 .header_preamble_size = 0,
5614 .max_header_size = MAX_SMB2_HDR_SIZE,
5615 .read_rsp_size = sizeof(struct smb2_read_rsp),
5616 .lock_cmd = SMB2_LOCK,
5618 .cap_nt_find = SMB2_NT_FIND,
5619 .cap_large_files = SMB2_LARGE_FILES,
5620 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5621 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5622 .create_lease_size = sizeof(struct create_lease),
5625 struct smb_version_values smb3any_values = {
5626 .version_string = SMB3ANY_VERSION_STRING,
5627 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5628 .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,
5629 .large_lock_type = 0,
5630 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5631 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5632 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5633 .header_size = sizeof(struct smb2_hdr),
5634 .header_preamble_size = 0,
5635 .max_header_size = MAX_SMB2_HDR_SIZE,
5636 .read_rsp_size = sizeof(struct smb2_read_rsp),
5637 .lock_cmd = SMB2_LOCK,
5639 .cap_nt_find = SMB2_NT_FIND,
5640 .cap_large_files = SMB2_LARGE_FILES,
5641 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5642 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5643 .create_lease_size = sizeof(struct create_lease_v2),
5646 struct smb_version_values smbdefault_values = {
5647 .version_string = SMBDEFAULT_VERSION_STRING,
5648 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5649 .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,
5650 .large_lock_type = 0,
5651 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5652 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5653 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5654 .header_size = sizeof(struct smb2_hdr),
5655 .header_preamble_size = 0,
5656 .max_header_size = MAX_SMB2_HDR_SIZE,
5657 .read_rsp_size = sizeof(struct smb2_read_rsp),
5658 .lock_cmd = SMB2_LOCK,
5660 .cap_nt_find = SMB2_NT_FIND,
5661 .cap_large_files = SMB2_LARGE_FILES,
5662 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5663 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5664 .create_lease_size = sizeof(struct create_lease_v2),
5667 struct smb_version_values smb30_values = {
5668 .version_string = SMB30_VERSION_STRING,
5669 .protocol_id = SMB30_PROT_ID,
5670 .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,
5671 .large_lock_type = 0,
5672 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5673 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5674 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5675 .header_size = sizeof(struct smb2_hdr),
5676 .header_preamble_size = 0,
5677 .max_header_size = MAX_SMB2_HDR_SIZE,
5678 .read_rsp_size = sizeof(struct smb2_read_rsp),
5679 .lock_cmd = SMB2_LOCK,
5681 .cap_nt_find = SMB2_NT_FIND,
5682 .cap_large_files = SMB2_LARGE_FILES,
5683 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5684 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5685 .create_lease_size = sizeof(struct create_lease_v2),
5688 struct smb_version_values smb302_values = {
5689 .version_string = SMB302_VERSION_STRING,
5690 .protocol_id = SMB302_PROT_ID,
5691 .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,
5692 .large_lock_type = 0,
5693 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5694 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5695 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5696 .header_size = sizeof(struct smb2_hdr),
5697 .header_preamble_size = 0,
5698 .max_header_size = MAX_SMB2_HDR_SIZE,
5699 .read_rsp_size = sizeof(struct smb2_read_rsp),
5700 .lock_cmd = SMB2_LOCK,
5702 .cap_nt_find = SMB2_NT_FIND,
5703 .cap_large_files = SMB2_LARGE_FILES,
5704 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5705 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5706 .create_lease_size = sizeof(struct create_lease_v2),
5709 struct smb_version_values smb311_values = {
5710 .version_string = SMB311_VERSION_STRING,
5711 .protocol_id = SMB311_PROT_ID,
5712 .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,
5713 .large_lock_type = 0,
5714 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5715 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5716 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5717 .header_size = sizeof(struct smb2_hdr),
5718 .header_preamble_size = 0,
5719 .max_header_size = MAX_SMB2_HDR_SIZE,
5720 .read_rsp_size = sizeof(struct smb2_read_rsp),
5721 .lock_cmd = SMB2_LOCK,
5723 .cap_nt_find = SMB2_NT_FIND,
5724 .cap_large_files = SMB2_LARGE_FILES,
5725 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5726 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5727 .create_lease_size = sizeof(struct create_lease_v2),