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);
97 if (server->in_flight == 0 &&
98 ((optype & CIFS_OP_MASK) != CIFS_NEG_OP) &&
99 ((optype & CIFS_OP_MASK) != CIFS_SESS_OP))
100 rc = change_conf(server);
102 * Sometimes server returns 0 credits on oplock break ack - we need to
103 * rebalance credits in this case.
105 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
107 if (server->credits > 1) {
109 server->oplock_credits++;
113 in_flight = server->in_flight;
114 spin_unlock(&server->req_lock);
115 wake_up(&server->request_q);
117 if (reconnect_detected) {
118 trace_smb3_reconnect_detected(server->CurrentMid,
119 server->conn_id, server->hostname, scredits, add, in_flight);
121 cifs_dbg(FYI, "trying to put %d credits from the old server instance %d\n",
125 if (reconnect_with_invalid_credits) {
126 trace_smb3_reconnect_with_invalid_credits(server->CurrentMid,
127 server->conn_id, server->hostname, scredits, add, in_flight);
128 cifs_dbg(FYI, "Negotiate operation when server credits is non-zero. Optype: %d, server credits: %d, credits added: %d\n",
129 optype, scredits, add);
132 spin_lock(&server->srv_lock);
133 if (server->tcpStatus == CifsNeedReconnect
134 || server->tcpStatus == CifsExiting) {
135 spin_unlock(&server->srv_lock);
138 spin_unlock(&server->srv_lock);
142 /* change_conf hasn't been executed */
145 cifs_server_dbg(VFS, "Possible client or server bug - zero credits\n");
148 cifs_server_dbg(VFS, "disabling echoes and oplocks\n");
151 cifs_dbg(FYI, "disabling oplocks\n");
154 /* change_conf rebalanced credits for different types */
158 trace_smb3_add_credits(server->CurrentMid,
159 server->conn_id, server->hostname, scredits, add, in_flight);
160 cifs_dbg(FYI, "%s: added %u credits total=%d\n", __func__, add, scredits);
164 smb2_set_credits(struct TCP_Server_Info *server, const int val)
166 int scredits, in_flight;
168 spin_lock(&server->req_lock);
169 server->credits = val;
171 server->reconnect_instance++;
173 * ChannelSequence updated for all channels in primary channel so that consistent
174 * across SMB3 requests sent on any channel. See MS-SMB2 3.2.4.1 and 3.2.7.1
176 if (CIFS_SERVER_IS_CHAN(server))
177 server->primary_server->channel_sequence_num++;
179 server->channel_sequence_num++;
181 scredits = server->credits;
182 in_flight = server->in_flight;
183 spin_unlock(&server->req_lock);
185 trace_smb3_set_credits(server->CurrentMid,
186 server->conn_id, server->hostname, scredits, val, in_flight);
187 cifs_dbg(FYI, "%s: set %u credits\n", __func__, val);
189 /* don't log while holding the lock */
191 cifs_dbg(FYI, "set credits to 1 due to smb2 reconnect\n");
195 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
199 return &server->echo_credits;
201 return &server->oplock_credits;
203 return &server->credits;
208 smb2_get_credits(struct mid_q_entry *mid)
210 return mid->credits_received;
214 smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
215 unsigned int *num, struct cifs_credits *credits)
218 unsigned int scredits, in_flight;
220 spin_lock(&server->req_lock);
222 spin_unlock(&server->req_lock);
224 spin_lock(&server->srv_lock);
225 if (server->tcpStatus == CifsExiting) {
226 spin_unlock(&server->srv_lock);
229 spin_unlock(&server->srv_lock);
231 spin_lock(&server->req_lock);
232 if (server->credits <= 0) {
233 spin_unlock(&server->req_lock);
234 cifs_num_waiters_inc(server);
235 rc = wait_event_killable(server->request_q,
236 has_credits(server, &server->credits, 1));
237 cifs_num_waiters_dec(server);
240 spin_lock(&server->req_lock);
242 scredits = server->credits;
243 /* can deadlock with reopen */
245 *num = SMB2_MAX_BUFFER_SIZE;
247 credits->instance = 0;
251 /* leave some credits for reopen and other ops */
253 *num = min_t(unsigned int, size,
254 scredits * SMB2_MAX_BUFFER_SIZE);
257 DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
258 credits->instance = server->reconnect_instance;
259 server->credits -= credits->value;
261 if (server->in_flight > server->max_in_flight)
262 server->max_in_flight = server->in_flight;
266 scredits = server->credits;
267 in_flight = server->in_flight;
268 spin_unlock(&server->req_lock);
270 trace_smb3_wait_credits(server->CurrentMid,
271 server->conn_id, server->hostname, scredits, -(credits->value), in_flight);
272 cifs_dbg(FYI, "%s: removed %u credits total=%d\n",
273 __func__, credits->value, scredits);
279 smb2_adjust_credits(struct TCP_Server_Info *server,
280 struct cifs_credits *credits,
281 const unsigned int payload_size)
283 int new_val = DIV_ROUND_UP(payload_size, SMB2_MAX_BUFFER_SIZE);
284 int scredits, in_flight;
286 if (!credits->value || credits->value == new_val)
289 if (credits->value < new_val) {
290 trace_smb3_too_many_credits(server->CurrentMid,
291 server->conn_id, server->hostname, 0, credits->value - new_val, 0);
292 cifs_server_dbg(VFS, "request has less credits (%d) than required (%d)",
293 credits->value, new_val);
298 spin_lock(&server->req_lock);
300 if (server->reconnect_instance != credits->instance) {
301 scredits = server->credits;
302 in_flight = server->in_flight;
303 spin_unlock(&server->req_lock);
305 trace_smb3_reconnect_detected(server->CurrentMid,
306 server->conn_id, server->hostname, scredits,
307 credits->value - new_val, in_flight);
308 cifs_server_dbg(VFS, "trying to return %d credits to old session\n",
309 credits->value - new_val);
313 server->credits += credits->value - new_val;
314 scredits = server->credits;
315 in_flight = server->in_flight;
316 spin_unlock(&server->req_lock);
317 wake_up(&server->request_q);
319 trace_smb3_adj_credits(server->CurrentMid,
320 server->conn_id, server->hostname, scredits,
321 credits->value - new_val, in_flight);
322 cifs_dbg(FYI, "%s: adjust added %u credits total=%d\n",
323 __func__, credits->value - new_val, scredits);
325 credits->value = new_val;
331 smb2_get_next_mid(struct TCP_Server_Info *server)
334 /* for SMB2 we need the current value */
335 spin_lock(&server->mid_lock);
336 mid = server->CurrentMid++;
337 spin_unlock(&server->mid_lock);
342 smb2_revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
344 spin_lock(&server->mid_lock);
345 if (server->CurrentMid >= val)
346 server->CurrentMid -= val;
347 spin_unlock(&server->mid_lock);
350 static struct mid_q_entry *
351 __smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue)
353 struct mid_q_entry *mid;
354 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
355 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
357 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
358 cifs_server_dbg(VFS, "Encrypted frame parsing not supported yet\n");
362 spin_lock(&server->mid_lock);
363 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
364 if ((mid->mid == wire_mid) &&
365 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
366 (mid->command == shdr->Command)) {
367 kref_get(&mid->refcount);
369 list_del_init(&mid->qhead);
370 mid->mid_flags |= MID_DELETED;
372 spin_unlock(&server->mid_lock);
376 spin_unlock(&server->mid_lock);
380 static struct mid_q_entry *
381 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
383 return __smb2_find_mid(server, buf, false);
386 static struct mid_q_entry *
387 smb2_find_dequeue_mid(struct TCP_Server_Info *server, char *buf)
389 return __smb2_find_mid(server, buf, true);
393 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
395 #ifdef CONFIG_CIFS_DEBUG2
396 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
398 cifs_server_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
399 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
400 shdr->Id.SyncId.ProcessId);
401 cifs_server_dbg(VFS, "smb buf %p len %u\n", buf,
402 server->ops->calc_smb_size(buf));
407 smb2_need_neg(struct TCP_Server_Info *server)
409 return server->max_read == 0;
413 smb2_negotiate(const unsigned int xid,
414 struct cifs_ses *ses,
415 struct TCP_Server_Info *server)
419 spin_lock(&server->mid_lock);
420 server->CurrentMid = 0;
421 spin_unlock(&server->mid_lock);
422 rc = SMB2_negotiate(xid, ses, server);
423 /* BB we probably don't need to retry with modern servers */
430 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
432 struct TCP_Server_Info *server = tcon->ses->server;
435 /* start with specified wsize, or default */
436 wsize = ctx->wsize ? ctx->wsize : CIFS_DEFAULT_IOSIZE;
437 wsize = min_t(unsigned int, wsize, server->max_write);
438 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
439 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
445 smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
447 struct TCP_Server_Info *server = tcon->ses->server;
450 /* start with specified wsize, or default */
451 wsize = ctx->wsize ? ctx->wsize : SMB3_DEFAULT_IOSIZE;
452 wsize = min_t(unsigned int, wsize, server->max_write);
453 #ifdef CONFIG_CIFS_SMB_DIRECT
457 * Account for SMB2 data transfer packet header and
458 * possible encryption header
460 wsize = min_t(unsigned int,
462 server->smbd_conn->max_fragmented_send_size -
463 SMB2_READWRITE_PDU_HEADER_SIZE -
464 sizeof(struct smb2_transform_hdr));
466 wsize = min_t(unsigned int,
467 wsize, server->smbd_conn->max_readwrite_size);
470 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
471 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
477 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
479 struct TCP_Server_Info *server = tcon->ses->server;
482 /* start with specified rsize, or default */
483 rsize = ctx->rsize ? ctx->rsize : CIFS_DEFAULT_IOSIZE;
484 rsize = min_t(unsigned int, rsize, server->max_read);
486 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
487 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
493 smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
495 struct TCP_Server_Info *server = tcon->ses->server;
498 /* start with specified rsize, or default */
499 rsize = ctx->rsize ? ctx->rsize : SMB3_DEFAULT_IOSIZE;
500 rsize = min_t(unsigned int, rsize, server->max_read);
501 #ifdef CONFIG_CIFS_SMB_DIRECT
505 * Account for SMB2 data transfer packet header and
506 * possible encryption header
508 rsize = min_t(unsigned int,
510 server->smbd_conn->max_fragmented_recv_size -
511 SMB2_READWRITE_PDU_HEADER_SIZE -
512 sizeof(struct smb2_transform_hdr));
514 rsize = min_t(unsigned int,
515 rsize, server->smbd_conn->max_readwrite_size);
519 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
520 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
526 * compare two interfaces a and b
527 * return 0 if everything matches.
528 * return 1 if a is rdma capable, or rss capable, or has higher link speed
529 * return -1 otherwise.
532 iface_cmp(struct cifs_server_iface *a, struct cifs_server_iface *b)
537 if (a->rdma_capable == b->rdma_capable) {
538 if (a->rss_capable == b->rss_capable) {
539 if (a->speed == b->speed) {
540 cmp_ret = cifs_ipaddr_cmp((struct sockaddr *) &a->sockaddr,
541 (struct sockaddr *) &b->sockaddr);
544 else if (cmp_ret > 0)
548 } else if (a->speed > b->speed)
552 } else if (a->rss_capable > b->rss_capable)
556 } else if (a->rdma_capable > b->rdma_capable)
563 parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
564 size_t buf_len, struct cifs_ses *ses, bool in_mount)
566 struct network_interface_info_ioctl_rsp *p;
567 struct sockaddr_in *addr4;
568 struct sockaddr_in6 *addr6;
569 struct iface_info_ipv4 *p4;
570 struct iface_info_ipv6 *p6;
571 struct cifs_server_iface *info = NULL, *iface = NULL, *niface = NULL;
572 struct cifs_server_iface tmp_iface;
578 bytes_left = buf_len;
581 spin_lock(&ses->iface_lock);
582 /* do not query too frequently, this time with lock held */
583 if (ses->iface_last_update &&
584 time_before(jiffies, ses->iface_last_update +
585 (SMB_INTERFACE_POLL_INTERVAL * HZ))) {
586 spin_unlock(&ses->iface_lock);
591 * Go through iface_list and do kref_put to remove
592 * any unused ifaces. ifaces in use will be removed
593 * when the last user calls a kref_put on it
595 list_for_each_entry_safe(iface, niface, &ses->iface_list,
597 iface->is_active = 0;
598 kref_put(&iface->refcount, release_iface);
601 spin_unlock(&ses->iface_lock);
604 * Samba server e.g. can return an empty interface list in some cases,
605 * which would only be a problem if we were requesting multichannel
607 if (bytes_left == 0) {
608 /* avoid spamming logs every 10 minutes, so log only in mount */
609 if ((ses->chan_max > 1) && in_mount)
611 "multichannel not available\n"
612 "Empty network interface list returned by server %s\n",
613 ses->server->hostname);
618 while (bytes_left >= sizeof(*p)) {
619 memset(&tmp_iface, 0, sizeof(tmp_iface));
620 tmp_iface.speed = le64_to_cpu(p->LinkSpeed);
621 tmp_iface.rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE) ? 1 : 0;
622 tmp_iface.rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE) ? 1 : 0;
626 * The kernel and wire socket structures have the same
627 * layout and use network byte order but make the
628 * conversion explicit in case either one changes.
631 addr4 = (struct sockaddr_in *)&tmp_iface.sockaddr;
632 p4 = (struct iface_info_ipv4 *)p->Buffer;
633 addr4->sin_family = AF_INET;
634 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
636 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
637 addr4->sin_port = cpu_to_be16(CIFS_PORT);
639 cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
643 addr6 = (struct sockaddr_in6 *)&tmp_iface.sockaddr;
644 p6 = (struct iface_info_ipv6 *)p->Buffer;
645 addr6->sin6_family = AF_INET6;
646 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
648 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
649 addr6->sin6_flowinfo = 0;
650 addr6->sin6_scope_id = 0;
651 addr6->sin6_port = cpu_to_be16(CIFS_PORT);
653 cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
658 "%s: skipping unsupported socket family\n",
664 * The iface_list is assumed to be sorted by speed.
665 * Check if the new interface exists in that list.
666 * NEVER change iface. it could be in use.
667 * Add a new one instead
669 spin_lock(&ses->iface_lock);
670 iface = niface = NULL;
671 list_for_each_entry_safe(iface, niface, &ses->iface_list,
673 ret = iface_cmp(iface, &tmp_iface);
675 /* just get a ref so that it doesn't get picked/freed */
676 iface->is_active = 1;
677 kref_get(&iface->refcount);
679 spin_unlock(&ses->iface_lock);
681 } else if (ret < 0) {
682 /* all remaining ifaces are slower */
683 kref_get(&iface->refcount);
687 spin_unlock(&ses->iface_lock);
689 /* no match. insert the entry in the list */
690 info = kmalloc(sizeof(struct cifs_server_iface),
696 memcpy(info, &tmp_iface, sizeof(tmp_iface));
698 /* add this new entry to the list */
699 kref_init(&info->refcount);
702 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, ses->iface_count);
703 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
704 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
705 le32_to_cpu(p->Capability));
707 spin_lock(&ses->iface_lock);
708 if (!list_entry_is_head(iface, &ses->iface_list, iface_head)) {
709 list_add_tail(&info->iface_head, &iface->iface_head);
710 kref_put(&iface->refcount, release_iface);
712 list_add_tail(&info->iface_head, &ses->iface_list);
715 spin_unlock(&ses->iface_lock);
716 ses->iface_last_update = jiffies;
719 next = le32_to_cpu(p->Next);
721 bytes_left -= sizeof(*p);
724 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
729 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
734 /* Azure rounds the buffer size up 8, to a 16 byte boundary */
735 if ((bytes_left > 8) || p->Next)
736 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
739 if (!ses->iface_count) {
749 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon, bool in_mount)
752 unsigned int ret_data_len = 0;
753 struct network_interface_info_ioctl_rsp *out_buf = NULL;
754 struct cifs_ses *ses = tcon->ses;
756 /* do not query too frequently */
757 if (ses->iface_last_update &&
758 time_before(jiffies, ses->iface_last_update +
759 (SMB_INTERFACE_POLL_INTERVAL * HZ)))
762 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
763 FSCTL_QUERY_NETWORK_INTERFACE_INFO,
764 NULL /* no data input */, 0 /* no data input */,
765 CIFSMaxBufSize, (char **)&out_buf, &ret_data_len);
766 if (rc == -EOPNOTSUPP) {
768 "server does not support query network interfaces\n");
770 } else if (rc != 0) {
771 cifs_tcon_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
775 rc = parse_server_interfaces(out_buf, ret_data_len, ses, in_mount);
785 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
786 struct cifs_sb_info *cifs_sb)
789 __le16 srch_path = 0; /* Null - open root of share */
790 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
791 struct cifs_open_parms oparms;
793 struct cached_fid *cfid = NULL;
795 oparms = (struct cifs_open_parms) {
798 .desired_access = FILE_READ_ATTRIBUTES,
799 .disposition = FILE_OPEN,
800 .create_options = cifs_create_options(cifs_sb, 0),
804 rc = open_cached_dir(xid, tcon, "", cifs_sb, false, &cfid);
806 memcpy(&fid, &cfid->fid, sizeof(struct cifs_fid));
808 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
813 SMB3_request_interfaces(xid, tcon, true /* called during mount */);
815 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
816 FS_ATTRIBUTE_INFORMATION);
817 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
818 FS_DEVICE_INFORMATION);
819 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
820 FS_VOLUME_INFORMATION);
821 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
822 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
824 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
826 close_cached_dir(cfid);
830 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
831 struct cifs_sb_info *cifs_sb)
834 __le16 srch_path = 0; /* Null - open root of share */
835 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
836 struct cifs_open_parms oparms;
839 oparms = (struct cifs_open_parms) {
842 .desired_access = FILE_READ_ATTRIBUTES,
843 .disposition = FILE_OPEN,
844 .create_options = cifs_create_options(cifs_sb, 0),
848 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
853 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
854 FS_ATTRIBUTE_INFORMATION);
855 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
856 FS_DEVICE_INFORMATION);
857 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
861 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
862 struct cifs_sb_info *cifs_sb, const char *full_path)
865 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
866 int err_buftype = CIFS_NO_BUFFER;
867 struct cifs_open_parms oparms;
868 struct kvec err_iov = {};
870 struct cached_fid *cfid;
874 rc = open_cached_dir(xid, tcon, full_path, cifs_sb, true, &cfid);
876 if (cfid->has_lease) {
877 close_cached_dir(cfid);
880 close_cached_dir(cfid);
883 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
887 oparms = (struct cifs_open_parms) {
890 .desired_access = FILE_READ_ATTRIBUTES,
891 .disposition = FILE_OPEN,
892 .create_options = cifs_create_options(cifs_sb, 0),
896 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
897 &err_iov, &err_buftype);
899 struct smb2_hdr *hdr = err_iov.iov_base;
901 if (unlikely(!hdr || err_buftype == CIFS_NO_BUFFER))
904 if (rc != -EREMOTE && hdr->Status == STATUS_OBJECT_NAME_INVALID) {
905 rc2 = cifs_inval_name_dfs_link_error(xid, tcon, cifs_sb,
914 if (rc == -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) && cifs_sb &&
915 (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS))
920 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
923 free_rsp_buf(err_buftype, err_iov.iov_base);
928 static int smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
929 struct cifs_sb_info *cifs_sb, const char *full_path,
930 u64 *uniqueid, struct cifs_open_info_data *data)
932 *uniqueid = le64_to_cpu(data->fi.IndexNumber);
936 static int smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
937 struct cifsFileInfo *cfile, struct cifs_open_info_data *data)
939 struct cifs_fid *fid = &cfile->fid;
941 if (cfile->symlink_target) {
942 data->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
943 if (!data->symlink_target)
946 return SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, &data->fi);
949 #ifdef CONFIG_CIFS_XATTR
951 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
952 struct smb2_file_full_ea_info *src, size_t src_size,
953 const unsigned char *ea_name)
956 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
958 size_t buf_size = dst_size;
959 size_t name_len, value_len, user_name_len;
961 while (src_size > 0) {
962 name_len = (size_t)src->ea_name_length;
963 value_len = (size_t)le16_to_cpu(src->ea_value_length);
968 if (src_size < 8 + name_len + 1 + value_len) {
969 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
974 name = &src->ea_data[0];
975 value = &src->ea_data[src->ea_name_length + 1];
978 if (ea_name_len == name_len &&
979 memcmp(ea_name, name, name_len) == 0) {
983 if (dst_size < value_len) {
987 memcpy(dst, value, value_len);
991 /* 'user.' plus a terminating null */
992 user_name_len = 5 + 1 + name_len;
995 /* skip copy - calc size only */
997 } else if (dst_size >= user_name_len) {
998 dst_size -= user_name_len;
999 memcpy(dst, "user.", 5);
1001 memcpy(dst, src->ea_data, name_len);
1005 rc += user_name_len;
1007 /* stop before overrun buffer */
1013 if (!src->next_entry_offset)
1016 if (src_size < le32_to_cpu(src->next_entry_offset)) {
1017 /* stop before overrun buffer */
1021 src_size -= le32_to_cpu(src->next_entry_offset);
1022 src = (void *)((char *)src +
1023 le32_to_cpu(src->next_entry_offset));
1026 /* didn't find the named attribute */
1035 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
1036 const unsigned char *path, const unsigned char *ea_name,
1037 char *ea_data, size_t buf_size,
1038 struct cifs_sb_info *cifs_sb)
1041 struct kvec rsp_iov = {NULL, 0};
1042 int buftype = CIFS_NO_BUFFER;
1043 struct smb2_query_info_rsp *rsp;
1044 struct smb2_file_full_ea_info *info = NULL;
1046 rc = smb2_query_info_compound(xid, tcon, path,
1048 FILE_FULL_EA_INFORMATION,
1051 MAX_SMB2_CREATE_RESPONSE_SIZE -
1052 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1053 &rsp_iov, &buftype, cifs_sb);
1056 * If ea_name is NULL (listxattr) and there are no EAs,
1057 * return 0 as it's not an error. Otherwise, the specified
1058 * ea_name was not found.
1060 if (!ea_name && rc == -ENODATA)
1065 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
1066 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1067 le32_to_cpu(rsp->OutputBufferLength),
1069 sizeof(struct smb2_file_full_ea_info));
1073 info = (struct smb2_file_full_ea_info *)(
1074 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1075 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
1076 le32_to_cpu(rsp->OutputBufferLength), ea_name);
1079 free_rsp_buf(buftype, rsp_iov.iov_base);
1085 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
1086 const char *path, const char *ea_name, const void *ea_value,
1087 const __u16 ea_value_len, const struct nls_table *nls_codepage,
1088 struct cifs_sb_info *cifs_sb)
1090 struct cifs_ses *ses = tcon->ses;
1091 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1092 __le16 *utf16_path = NULL;
1093 int ea_name_len = strlen(ea_name);
1094 int flags = CIFS_CP_CREATE_CLOSE_OP;
1096 struct smb_rqst rqst[3];
1097 int resp_buftype[3];
1098 struct kvec rsp_iov[3];
1099 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1100 struct cifs_open_parms oparms;
1101 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1102 struct cifs_fid fid;
1103 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1104 unsigned int size[1];
1106 struct smb2_file_full_ea_info *ea = NULL;
1107 struct kvec close_iov[1];
1108 struct smb2_query_info_rsp *rsp;
1109 int rc, used_len = 0;
1111 if (smb3_encryption_required(tcon))
1112 flags |= CIFS_TRANSFORM_REQ;
1114 if (ea_name_len > 255)
1117 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1121 memset(rqst, 0, sizeof(rqst));
1122 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1123 memset(rsp_iov, 0, sizeof(rsp_iov));
1125 if (ses->server->ops->query_all_EAs) {
1127 rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1133 /* If we are adding a attribute we should first check
1134 * if there will be enough space available to store
1135 * the new EA. If not we should not add it since we
1136 * would not be able to even read the EAs back.
1138 rc = smb2_query_info_compound(xid, tcon, path,
1140 FILE_FULL_EA_INFORMATION,
1143 MAX_SMB2_CREATE_RESPONSE_SIZE -
1144 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1145 &rsp_iov[1], &resp_buftype[1], cifs_sb);
1147 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1148 used_len = le32_to_cpu(rsp->OutputBufferLength);
1150 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1151 resp_buftype[1] = CIFS_NO_BUFFER;
1152 memset(&rsp_iov[1], 0, sizeof(rsp_iov[1]));
1155 /* Use a fudge factor of 256 bytes in case we collide
1156 * with a different set_EAs command.
1158 if (CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1159 MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 <
1160 used_len + ea_name_len + ea_value_len + 1) {
1168 memset(&open_iov, 0, sizeof(open_iov));
1169 rqst[0].rq_iov = open_iov;
1170 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1172 oparms = (struct cifs_open_parms) {
1175 .desired_access = FILE_WRITE_EA,
1176 .disposition = FILE_OPEN,
1177 .create_options = cifs_create_options(cifs_sb, 0),
1181 rc = SMB2_open_init(tcon, server,
1182 &rqst[0], &oplock, &oparms, utf16_path);
1185 smb2_set_next_command(tcon, &rqst[0]);
1189 memset(&si_iov, 0, sizeof(si_iov));
1190 rqst[1].rq_iov = si_iov;
1191 rqst[1].rq_nvec = 1;
1193 len = sizeof(*ea) + ea_name_len + ea_value_len + 1;
1194 ea = kzalloc(len, GFP_KERNEL);
1200 ea->ea_name_length = ea_name_len;
1201 ea->ea_value_length = cpu_to_le16(ea_value_len);
1202 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
1203 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
1208 rc = SMB2_set_info_init(tcon, server,
1209 &rqst[1], COMPOUND_FID,
1210 COMPOUND_FID, current->tgid,
1211 FILE_FULL_EA_INFORMATION,
1212 SMB2_O_INFO_FILE, 0, data, size);
1215 smb2_set_next_command(tcon, &rqst[1]);
1216 smb2_set_related(&rqst[1]);
1220 memset(&close_iov, 0, sizeof(close_iov));
1221 rqst[2].rq_iov = close_iov;
1222 rqst[2].rq_nvec = 1;
1223 rc = SMB2_close_init(tcon, server,
1224 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1227 smb2_set_related(&rqst[2]);
1229 rc = compound_send_recv(xid, ses, server,
1231 resp_buftype, rsp_iov);
1232 /* no need to bump num_remote_opens because handle immediately closed */
1237 SMB2_open_free(&rqst[0]);
1238 SMB2_set_info_free(&rqst[1]);
1239 SMB2_close_free(&rqst[2]);
1240 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1241 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1242 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1248 smb2_can_echo(struct TCP_Server_Info *server)
1250 return server->echoes;
1254 smb2_clear_stats(struct cifs_tcon *tcon)
1258 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1259 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1260 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1265 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1267 seq_puts(m, "\n\tShare Capabilities:");
1268 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1269 seq_puts(m, " DFS,");
1270 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1271 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1272 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1273 seq_puts(m, " SCALEOUT,");
1274 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1275 seq_puts(m, " CLUSTER,");
1276 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1277 seq_puts(m, " ASYMMETRIC,");
1278 if (tcon->capabilities == 0)
1279 seq_puts(m, " None");
1280 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1281 seq_puts(m, " Aligned,");
1282 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1283 seq_puts(m, " Partition Aligned,");
1284 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1285 seq_puts(m, " SSD,");
1286 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1287 seq_puts(m, " TRIM-support,");
1289 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1290 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1291 if (tcon->perf_sector_size)
1292 seq_printf(m, "\tOptimal sector size: 0x%x",
1293 tcon->perf_sector_size);
1294 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1298 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1300 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1301 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1304 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1305 * totals (requests sent) since those SMBs are per-session not per tcon
1307 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1308 (long long)(tcon->bytes_read),
1309 (long long)(tcon->bytes_written));
1310 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1311 atomic_read(&tcon->num_local_opens),
1312 atomic_read(&tcon->num_remote_opens));
1313 seq_printf(m, "\nTreeConnects: %d total %d failed",
1314 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1315 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1316 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1317 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1318 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1319 seq_printf(m, "\nCreates: %d total %d failed",
1320 atomic_read(&sent[SMB2_CREATE_HE]),
1321 atomic_read(&failed[SMB2_CREATE_HE]));
1322 seq_printf(m, "\nCloses: %d total %d failed",
1323 atomic_read(&sent[SMB2_CLOSE_HE]),
1324 atomic_read(&failed[SMB2_CLOSE_HE]));
1325 seq_printf(m, "\nFlushes: %d total %d failed",
1326 atomic_read(&sent[SMB2_FLUSH_HE]),
1327 atomic_read(&failed[SMB2_FLUSH_HE]));
1328 seq_printf(m, "\nReads: %d total %d failed",
1329 atomic_read(&sent[SMB2_READ_HE]),
1330 atomic_read(&failed[SMB2_READ_HE]));
1331 seq_printf(m, "\nWrites: %d total %d failed",
1332 atomic_read(&sent[SMB2_WRITE_HE]),
1333 atomic_read(&failed[SMB2_WRITE_HE]));
1334 seq_printf(m, "\nLocks: %d total %d failed",
1335 atomic_read(&sent[SMB2_LOCK_HE]),
1336 atomic_read(&failed[SMB2_LOCK_HE]));
1337 seq_printf(m, "\nIOCTLs: %d total %d failed",
1338 atomic_read(&sent[SMB2_IOCTL_HE]),
1339 atomic_read(&failed[SMB2_IOCTL_HE]));
1340 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1341 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1342 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1343 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1344 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1345 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1346 seq_printf(m, "\nQueryInfos: %d total %d failed",
1347 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1348 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1349 seq_printf(m, "\nSetInfos: %d total %d failed",
1350 atomic_read(&sent[SMB2_SET_INFO_HE]),
1351 atomic_read(&failed[SMB2_SET_INFO_HE]));
1352 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1353 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1354 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1358 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1360 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1361 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1363 cfile->fid.persistent_fid = fid->persistent_fid;
1364 cfile->fid.volatile_fid = fid->volatile_fid;
1365 cfile->fid.access = fid->access;
1366 #ifdef CONFIG_CIFS_DEBUG2
1367 cfile->fid.mid = fid->mid;
1368 #endif /* CIFS_DEBUG2 */
1369 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1371 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1372 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1376 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1377 struct cifs_fid *fid)
1379 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1383 smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon,
1384 struct cifsFileInfo *cfile)
1386 struct smb2_file_network_open_info file_inf;
1387 struct inode *inode;
1390 rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid,
1391 cfile->fid.volatile_fid, &file_inf);
1395 inode = d_inode(cfile->dentry);
1397 spin_lock(&inode->i_lock);
1398 CIFS_I(inode)->time = jiffies;
1400 /* Creation time should not need to be updated on close */
1401 if (file_inf.LastWriteTime)
1402 inode->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime);
1403 if (file_inf.ChangeTime)
1404 inode->i_ctime = cifs_NTtimeToUnix(file_inf.ChangeTime);
1405 if (file_inf.LastAccessTime)
1406 inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime);
1409 * i_blocks is not related to (i_size / i_blksize),
1410 * but instead 512 byte (2**9) size is required for
1411 * calculating num blocks.
1413 if (le64_to_cpu(file_inf.AllocationSize) > 4096)
1415 (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9;
1417 /* End of file and Attributes should not have to be updated on close */
1418 spin_unlock(&inode->i_lock);
1422 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1423 u64 persistent_fid, u64 volatile_fid,
1424 struct copychunk_ioctl *pcchunk)
1427 unsigned int ret_data_len;
1428 struct resume_key_req *res_key;
1430 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1431 FSCTL_SRV_REQUEST_RESUME_KEY, NULL, 0 /* no input */,
1432 CIFSMaxBufSize, (char **)&res_key, &ret_data_len);
1434 if (rc == -EOPNOTSUPP) {
1435 pr_warn_once("Server share %s does not support copy range\n", tcon->tree_name);
1436 goto req_res_key_exit;
1438 cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1439 goto req_res_key_exit;
1441 if (ret_data_len < sizeof(struct resume_key_req)) {
1442 cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n");
1444 goto req_res_key_exit;
1446 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1454 struct smb_rqst rqst[3];
1455 struct kvec rsp_iov[3];
1456 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1457 struct kvec qi_iov[1];
1458 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
1459 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1460 struct kvec close_iov[1];
1464 smb2_ioctl_query_info(const unsigned int xid,
1465 struct cifs_tcon *tcon,
1466 struct cifs_sb_info *cifs_sb,
1467 __le16 *path, int is_dir,
1470 struct iqi_vars *vars;
1471 struct smb_rqst *rqst;
1472 struct kvec *rsp_iov;
1473 struct cifs_ses *ses = tcon->ses;
1474 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1475 char __user *arg = (char __user *)p;
1476 struct smb_query_info qi;
1477 struct smb_query_info __user *pqi;
1479 int flags = CIFS_CP_CREATE_CLOSE_OP;
1480 struct smb2_query_info_rsp *qi_rsp = NULL;
1481 struct smb2_ioctl_rsp *io_rsp = NULL;
1482 void *buffer = NULL;
1483 int resp_buftype[3];
1484 struct cifs_open_parms oparms;
1485 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1486 struct cifs_fid fid;
1487 unsigned int size[2];
1489 int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR;
1490 void (*free_req1_func)(struct smb_rqst *r);
1492 vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
1495 rqst = &vars->rqst[0];
1496 rsp_iov = &vars->rsp_iov[0];
1498 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1500 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info))) {
1504 if (qi.output_buffer_length > 1024) {
1509 if (!ses || !server) {
1514 if (smb3_encryption_required(tcon))
1515 flags |= CIFS_TRANSFORM_REQ;
1517 if (qi.output_buffer_length) {
1518 buffer = memdup_user(arg + sizeof(struct smb_query_info), qi.output_buffer_length);
1519 if (IS_ERR(buffer)) {
1520 rc = PTR_ERR(buffer);
1526 rqst[0].rq_iov = &vars->open_iov[0];
1527 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1529 oparms = (struct cifs_open_parms) {
1531 .disposition = FILE_OPEN,
1532 .create_options = cifs_create_options(cifs_sb, create_options),
1536 if (qi.flags & PASSTHRU_FSCTL) {
1537 switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1538 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1539 oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1541 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1542 oparms.desired_access = GENERIC_ALL;
1544 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1545 oparms.desired_access = GENERIC_READ;
1547 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1548 oparms.desired_access = GENERIC_WRITE;
1551 } else if (qi.flags & PASSTHRU_SET_INFO) {
1552 oparms.desired_access = GENERIC_WRITE;
1554 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1557 rc = SMB2_open_init(tcon, server,
1558 &rqst[0], &oplock, &oparms, path);
1560 goto free_output_buffer;
1561 smb2_set_next_command(tcon, &rqst[0]);
1564 if (qi.flags & PASSTHRU_FSCTL) {
1565 /* Can eventually relax perm check since server enforces too */
1566 if (!capable(CAP_SYS_ADMIN)) {
1570 rqst[1].rq_iov = &vars->io_iov[0];
1571 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1573 rc = SMB2_ioctl_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1574 qi.info_type, buffer, qi.output_buffer_length,
1575 CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1576 MAX_SMB2_CLOSE_RESPONSE_SIZE);
1577 free_req1_func = SMB2_ioctl_free;
1578 } else if (qi.flags == PASSTHRU_SET_INFO) {
1579 /* Can eventually relax perm check since server enforces too */
1580 if (!capable(CAP_SYS_ADMIN)) {
1584 if (qi.output_buffer_length < 8) {
1588 rqst[1].rq_iov = &vars->si_iov[0];
1589 rqst[1].rq_nvec = 1;
1591 /* MS-FSCC 2.4.13 FileEndOfFileInformation */
1595 rc = SMB2_set_info_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1596 current->tgid, FILE_END_OF_FILE_INFORMATION,
1597 SMB2_O_INFO_FILE, 0, data, size);
1598 free_req1_func = SMB2_set_info_free;
1599 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1600 rqst[1].rq_iov = &vars->qi_iov[0];
1601 rqst[1].rq_nvec = 1;
1603 rc = SMB2_query_info_init(tcon, server,
1604 &rqst[1], COMPOUND_FID,
1605 COMPOUND_FID, qi.file_info_class,
1606 qi.info_type, qi.additional_information,
1607 qi.input_buffer_length,
1608 qi.output_buffer_length, buffer);
1609 free_req1_func = SMB2_query_info_free;
1610 } else { /* unknown flags */
1611 cifs_tcon_dbg(VFS, "Invalid passthru query flags: 0x%x\n",
1618 smb2_set_next_command(tcon, &rqst[1]);
1619 smb2_set_related(&rqst[1]);
1622 rqst[2].rq_iov = &vars->close_iov[0];
1623 rqst[2].rq_nvec = 1;
1625 rc = SMB2_close_init(tcon, server,
1626 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1629 smb2_set_related(&rqst[2]);
1631 rc = compound_send_recv(xid, ses, server,
1633 resp_buftype, rsp_iov);
1637 /* No need to bump num_remote_opens since handle immediately closed */
1638 if (qi.flags & PASSTHRU_FSCTL) {
1639 pqi = (struct smb_query_info __user *)arg;
1640 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1641 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1642 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1643 if (qi.input_buffer_length > 0 &&
1644 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length
1645 > rsp_iov[1].iov_len) {
1650 if (copy_to_user(&pqi->input_buffer_length,
1651 &qi.input_buffer_length,
1652 sizeof(qi.input_buffer_length))) {
1657 if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1658 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1659 qi.input_buffer_length))
1662 pqi = (struct smb_query_info __user *)arg;
1663 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1664 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1665 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1666 if (copy_to_user(&pqi->input_buffer_length,
1667 &qi.input_buffer_length,
1668 sizeof(qi.input_buffer_length))) {
1673 if (copy_to_user(pqi + 1, qi_rsp->Buffer,
1674 qi.input_buffer_length))
1679 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1680 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1681 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1682 SMB2_close_free(&rqst[2]);
1684 free_req1_func(&rqst[1]);
1686 SMB2_open_free(&rqst[0]);
1695 smb2_copychunk_range(const unsigned int xid,
1696 struct cifsFileInfo *srcfile,
1697 struct cifsFileInfo *trgtfile, u64 src_off,
1698 u64 len, u64 dest_off)
1701 unsigned int ret_data_len;
1702 struct copychunk_ioctl *pcchunk;
1703 struct copychunk_ioctl_rsp *retbuf = NULL;
1704 struct cifs_tcon *tcon;
1705 int chunks_copied = 0;
1706 bool chunk_sizes_updated = false;
1707 ssize_t bytes_written, total_bytes_written = 0;
1709 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1710 if (pcchunk == NULL)
1713 cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
1714 /* Request a key from the server to identify the source of the copy */
1715 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1716 srcfile->fid.persistent_fid,
1717 srcfile->fid.volatile_fid, pcchunk);
1719 /* Note: request_res_key sets res_key null only if rc !=0 */
1723 /* For now array only one chunk long, will make more flexible later */
1724 pcchunk->ChunkCount = cpu_to_le32(1);
1725 pcchunk->Reserved = 0;
1726 pcchunk->Reserved2 = 0;
1728 tcon = tlink_tcon(trgtfile->tlink);
1731 pcchunk->SourceOffset = cpu_to_le64(src_off);
1732 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1734 cpu_to_le32(min_t(u64, len, tcon->max_bytes_chunk));
1736 /* Request server copy to target from src identified by key */
1739 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1740 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1741 (char *)pcchunk, sizeof(struct copychunk_ioctl),
1742 CIFSMaxBufSize, (char **)&retbuf, &ret_data_len);
1745 sizeof(struct copychunk_ioctl_rsp)) {
1746 cifs_tcon_dbg(VFS, "Invalid cchunk response size\n");
1750 if (retbuf->TotalBytesWritten == 0) {
1751 cifs_dbg(FYI, "no bytes copied\n");
1756 * Check if server claimed to write more than we asked
1758 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1759 le32_to_cpu(pcchunk->Length)) {
1760 cifs_tcon_dbg(VFS, "Invalid copy chunk response\n");
1764 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1765 cifs_tcon_dbg(VFS, "Invalid num chunks written\n");
1771 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1772 src_off += bytes_written;
1773 dest_off += bytes_written;
1774 len -= bytes_written;
1775 total_bytes_written += bytes_written;
1777 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1778 le32_to_cpu(retbuf->ChunksWritten),
1779 le32_to_cpu(retbuf->ChunkBytesWritten),
1781 } else if (rc == -EINVAL) {
1782 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1785 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1786 le32_to_cpu(retbuf->ChunksWritten),
1787 le32_to_cpu(retbuf->ChunkBytesWritten),
1788 le32_to_cpu(retbuf->TotalBytesWritten));
1791 * Check if this is the first request using these sizes,
1792 * (ie check if copy succeed once with original sizes
1793 * and check if the server gave us different sizes after
1794 * we already updated max sizes on previous request).
1795 * if not then why is the server returning an error now
1797 if ((chunks_copied != 0) || chunk_sizes_updated)
1800 /* Check that server is not asking us to grow size */
1801 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1802 tcon->max_bytes_chunk)
1803 tcon->max_bytes_chunk =
1804 le32_to_cpu(retbuf->ChunkBytesWritten);
1806 goto cchunk_out; /* server gave us bogus size */
1808 /* No need to change MaxChunks since already set to 1 */
1809 chunk_sizes_updated = true;
1820 return total_bytes_written;
1824 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1825 struct cifs_fid *fid)
1827 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1831 smb2_read_data_offset(char *buf)
1833 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1835 return rsp->DataOffset;
1839 smb2_read_data_length(char *buf, bool in_remaining)
1841 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1844 return le32_to_cpu(rsp->DataRemaining);
1846 return le32_to_cpu(rsp->DataLength);
1851 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1852 struct cifs_io_parms *parms, unsigned int *bytes_read,
1853 char **buf, int *buf_type)
1855 parms->persistent_fid = pfid->persistent_fid;
1856 parms->volatile_fid = pfid->volatile_fid;
1857 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1861 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1862 struct cifs_io_parms *parms, unsigned int *written,
1863 struct kvec *iov, unsigned long nr_segs)
1866 parms->persistent_fid = pfid->persistent_fid;
1867 parms->volatile_fid = pfid->volatile_fid;
1868 return SMB2_write(xid, parms, written, iov, nr_segs);
1871 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1872 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1873 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1875 struct cifsInodeInfo *cifsi;
1878 cifsi = CIFS_I(inode);
1880 /* if file already sparse don't bother setting sparse again */
1881 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1882 return true; /* already sparse */
1884 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1885 return true; /* already not sparse */
1888 * Can't check for sparse support on share the usual way via the
1889 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1890 * since Samba server doesn't set the flag on the share, yet
1891 * supports the set sparse FSCTL and returns sparse correctly
1892 * in the file attributes. If we fail setting sparse though we
1893 * mark that server does not support sparse files for this share
1894 * to avoid repeatedly sending the unsupported fsctl to server
1895 * if the file is repeatedly extended.
1897 if (tcon->broken_sparse_sup)
1900 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1901 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1902 &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
1904 tcon->broken_sparse_sup = true;
1905 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1910 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1912 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1918 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1919 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1921 __le64 eof = cpu_to_le64(size);
1922 struct inode *inode;
1925 * If extending file more than one page make sparse. Many Linux fs
1926 * make files sparse by default when extending via ftruncate
1928 inode = d_inode(cfile->dentry);
1930 if (!set_alloc && (size > inode->i_size + 8192)) {
1931 __u8 set_sparse = 1;
1933 /* whether set sparse succeeds or not, extend the file */
1934 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1937 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1938 cfile->fid.volatile_fid, cfile->pid, &eof);
1942 smb2_duplicate_extents(const unsigned int xid,
1943 struct cifsFileInfo *srcfile,
1944 struct cifsFileInfo *trgtfile, u64 src_off,
1945 u64 len, u64 dest_off)
1948 unsigned int ret_data_len;
1949 struct inode *inode;
1950 struct duplicate_extents_to_file dup_ext_buf;
1951 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1953 /* server fileays advertise duplicate extent support with this flag */
1954 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1955 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1958 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1959 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1960 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1961 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1962 dup_ext_buf.ByteCount = cpu_to_le64(len);
1963 cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
1964 src_off, dest_off, len);
1966 inode = d_inode(trgtfile->dentry);
1967 if (inode->i_size < dest_off + len) {
1968 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1970 goto duplicate_extents_out;
1973 * Although also could set plausible allocation size (i_blocks)
1974 * here in addition to setting the file size, in reflink
1975 * it is likely that the target file is sparse. Its allocation
1976 * size will be queried on next revalidate, but it is important
1977 * to make sure that file's cached size is updated immediately
1979 cifs_setsize(inode, dest_off + len);
1981 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1982 trgtfile->fid.volatile_fid,
1983 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1984 (char *)&dup_ext_buf,
1985 sizeof(struct duplicate_extents_to_file),
1986 CIFSMaxBufSize, NULL,
1989 if (ret_data_len > 0)
1990 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
1992 duplicate_extents_out:
1997 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1998 struct cifsFileInfo *cfile)
2000 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
2001 cfile->fid.volatile_fid);
2005 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
2006 struct cifsFileInfo *cfile)
2008 struct fsctl_set_integrity_information_req integr_info;
2009 unsigned int ret_data_len;
2011 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
2012 integr_info.Flags = 0;
2013 integr_info.Reserved = 0;
2015 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2016 cfile->fid.volatile_fid,
2017 FSCTL_SET_INTEGRITY_INFORMATION,
2018 (char *)&integr_info,
2019 sizeof(struct fsctl_set_integrity_information_req),
2020 CIFSMaxBufSize, NULL,
2025 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
2026 #define GMT_TOKEN_SIZE 50
2028 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
2031 * Input buffer contains (empty) struct smb_snapshot array with size filled in
2032 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
2035 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
2036 struct cifsFileInfo *cfile, void __user *ioc_buf)
2038 char *retbuf = NULL;
2039 unsigned int ret_data_len = 0;
2041 u32 max_response_size;
2042 struct smb_snapshot_array snapshot_in;
2045 * On the first query to enumerate the list of snapshots available
2046 * for this volume the buffer begins with 0 (number of snapshots
2047 * which can be returned is zero since at that point we do not know
2048 * how big the buffer needs to be). On the second query,
2049 * it (ret_data_len) is set to number of snapshots so we can
2050 * know to set the maximum response size larger (see below).
2052 if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
2056 * Note that for snapshot queries that servers like Azure expect that
2057 * the first query be minimal size (and just used to get the number/size
2058 * of previous versions) so response size must be specified as EXACTLY
2059 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
2062 if (ret_data_len == 0)
2063 max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
2065 max_response_size = CIFSMaxBufSize;
2067 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2068 cfile->fid.volatile_fid,
2069 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
2070 NULL, 0 /* no input data */, max_response_size,
2073 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
2078 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
2080 if (copy_from_user(&snapshot_in, ioc_buf,
2081 sizeof(struct smb_snapshot_array))) {
2088 * Check for min size, ie not large enough to fit even one GMT
2089 * token (snapshot). On the first ioctl some users may pass in
2090 * smaller size (or zero) to simply get the size of the array
2091 * so the user space caller can allocate sufficient memory
2092 * and retry the ioctl again with larger array size sufficient
2093 * to hold all of the snapshot GMT tokens on the second try.
2095 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
2096 ret_data_len = sizeof(struct smb_snapshot_array);
2099 * We return struct SRV_SNAPSHOT_ARRAY, followed by
2100 * the snapshot array (of 50 byte GMT tokens) each
2101 * representing an available previous version of the data
2103 if (ret_data_len > (snapshot_in.snapshot_array_size +
2104 sizeof(struct smb_snapshot_array)))
2105 ret_data_len = snapshot_in.snapshot_array_size +
2106 sizeof(struct smb_snapshot_array);
2108 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
2119 smb3_notify(const unsigned int xid, struct file *pfile,
2120 void __user *ioc_buf, bool return_changes)
2122 struct smb3_notify_info notify;
2123 struct smb3_notify_info __user *pnotify_buf;
2124 struct dentry *dentry = pfile->f_path.dentry;
2125 struct inode *inode = file_inode(pfile);
2126 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2127 struct cifs_open_parms oparms;
2128 struct cifs_fid fid;
2129 struct cifs_tcon *tcon;
2130 const unsigned char *path;
2131 char *returned_ioctl_info = NULL;
2132 void *page = alloc_dentry_path();
2133 __le16 *utf16_path = NULL;
2134 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2138 path = build_path_from_dentry(dentry, page);
2144 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2145 if (utf16_path == NULL) {
2150 if (return_changes) {
2151 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify_info))) {
2156 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify))) {
2160 notify.data_len = 0;
2163 tcon = cifs_sb_master_tcon(cifs_sb);
2164 oparms = (struct cifs_open_parms) {
2167 .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
2168 .disposition = FILE_OPEN,
2169 .create_options = cifs_create_options(cifs_sb, 0),
2173 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
2178 rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid,
2179 notify.watch_tree, notify.completion_filter,
2180 notify.data_len, &returned_ioctl_info, &ret_len);
2182 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2184 cifs_dbg(FYI, "change notify for path %s rc %d\n", path, rc);
2185 if (return_changes && (ret_len > 0) && (notify.data_len > 0)) {
2186 if (ret_len > notify.data_len)
2187 ret_len = notify.data_len;
2188 pnotify_buf = (struct smb3_notify_info __user *)ioc_buf;
2189 if (copy_to_user(pnotify_buf->notify_data, returned_ioctl_info, ret_len))
2191 else if (copy_to_user(&pnotify_buf->data_len, &ret_len, sizeof(ret_len)))
2194 kfree(returned_ioctl_info);
2196 free_dentry_path(page);
2202 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
2203 const char *path, struct cifs_sb_info *cifs_sb,
2204 struct cifs_fid *fid, __u16 search_flags,
2205 struct cifs_search_info *srch_inf)
2208 struct smb_rqst rqst[2];
2209 struct kvec rsp_iov[2];
2210 int resp_buftype[2];
2211 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2212 struct kvec qd_iov[SMB2_QUERY_DIRECTORY_IOV_SIZE];
2214 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2215 struct cifs_open_parms oparms;
2216 struct smb2_query_directory_rsp *qd_rsp = NULL;
2217 struct smb2_create_rsp *op_rsp = NULL;
2218 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2219 int retry_count = 0;
2221 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2225 if (smb3_encryption_required(tcon))
2226 flags |= CIFS_TRANSFORM_REQ;
2228 memset(rqst, 0, sizeof(rqst));
2229 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
2230 memset(rsp_iov, 0, sizeof(rsp_iov));
2233 memset(&open_iov, 0, sizeof(open_iov));
2234 rqst[0].rq_iov = open_iov;
2235 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2237 oparms = (struct cifs_open_parms) {
2240 .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
2241 .disposition = FILE_OPEN,
2242 .create_options = cifs_create_options(cifs_sb, 0),
2246 rc = SMB2_open_init(tcon, server,
2247 &rqst[0], &oplock, &oparms, utf16_path);
2250 smb2_set_next_command(tcon, &rqst[0]);
2252 /* Query directory */
2253 srch_inf->entries_in_buffer = 0;
2254 srch_inf->index_of_last_entry = 2;
2256 memset(&qd_iov, 0, sizeof(qd_iov));
2257 rqst[1].rq_iov = qd_iov;
2258 rqst[1].rq_nvec = SMB2_QUERY_DIRECTORY_IOV_SIZE;
2260 rc = SMB2_query_directory_init(xid, tcon, server,
2262 COMPOUND_FID, COMPOUND_FID,
2263 0, srch_inf->info_level);
2267 smb2_set_related(&rqst[1]);
2270 rc = compound_send_recv(xid, tcon->ses, server,
2272 resp_buftype, rsp_iov);
2274 if (rc == -EAGAIN && retry_count++ < 10)
2277 /* If the open failed there is nothing to do */
2278 op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
2279 if (op_rsp == NULL || op_rsp->hdr.Status != STATUS_SUCCESS) {
2280 cifs_dbg(FYI, "query_dir_first: open failed rc=%d\n", rc);
2283 fid->persistent_fid = op_rsp->PersistentFileId;
2284 fid->volatile_fid = op_rsp->VolatileFileId;
2286 /* Anything else than ENODATA means a genuine error */
2287 if (rc && rc != -ENODATA) {
2288 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2289 cifs_dbg(FYI, "query_dir_first: query directory failed rc=%d\n", rc);
2290 trace_smb3_query_dir_err(xid, fid->persistent_fid,
2291 tcon->tid, tcon->ses->Suid, 0, 0, rc);
2295 atomic_inc(&tcon->num_remote_opens);
2297 qd_rsp = (struct smb2_query_directory_rsp *)rsp_iov[1].iov_base;
2298 if (qd_rsp->hdr.Status == STATUS_NO_MORE_FILES) {
2299 trace_smb3_query_dir_done(xid, fid->persistent_fid,
2300 tcon->tid, tcon->ses->Suid, 0, 0);
2301 srch_inf->endOfSearch = true;
2306 rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1],
2309 trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid,
2310 tcon->ses->Suid, 0, 0, rc);
2313 resp_buftype[1] = CIFS_NO_BUFFER;
2315 trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid,
2316 tcon->ses->Suid, 0, srch_inf->entries_in_buffer);
2320 SMB2_open_free(&rqst[0]);
2321 SMB2_query_directory_free(&rqst[1]);
2322 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2323 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2328 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
2329 struct cifs_fid *fid, __u16 search_flags,
2330 struct cifs_search_info *srch_inf)
2332 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
2333 fid->volatile_fid, 0, srch_inf);
2337 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
2338 struct cifs_fid *fid)
2340 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2344 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2345 * the number of credits and return true. Otherwise - return false.
2348 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
2350 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2351 int scredits, in_flight;
2353 if (shdr->Status != STATUS_PENDING)
2356 if (shdr->CreditRequest) {
2357 spin_lock(&server->req_lock);
2358 server->credits += le16_to_cpu(shdr->CreditRequest);
2359 scredits = server->credits;
2360 in_flight = server->in_flight;
2361 spin_unlock(&server->req_lock);
2362 wake_up(&server->request_q);
2364 trace_smb3_pend_credits(server->CurrentMid,
2365 server->conn_id, server->hostname, scredits,
2366 le16_to_cpu(shdr->CreditRequest), in_flight);
2367 cifs_dbg(FYI, "%s: status pending add %u credits total=%d\n",
2368 __func__, le16_to_cpu(shdr->CreditRequest), scredits);
2375 smb2_is_session_expired(char *buf)
2377 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2379 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
2380 shdr->Status != STATUS_USER_SESSION_DELETED)
2383 trace_smb3_ses_expired(le32_to_cpu(shdr->Id.SyncId.TreeId),
2384 le64_to_cpu(shdr->SessionId),
2385 le16_to_cpu(shdr->Command),
2386 le64_to_cpu(shdr->MessageId));
2387 cifs_dbg(FYI, "Session expired or deleted\n");
2393 smb2_is_status_io_timeout(char *buf)
2395 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2397 if (shdr->Status == STATUS_IO_TIMEOUT)
2404 smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server)
2406 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2407 struct TCP_Server_Info *pserver;
2408 struct cifs_ses *ses;
2409 struct cifs_tcon *tcon;
2411 if (shdr->Status != STATUS_NETWORK_NAME_DELETED)
2414 /* If server is a channel, select the primary channel */
2415 pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
2417 spin_lock(&cifs_tcp_ses_lock);
2418 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
2419 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
2420 if (tcon->tid == le32_to_cpu(shdr->Id.SyncId.TreeId)) {
2421 spin_lock(&tcon->tc_lock);
2422 tcon->need_reconnect = true;
2423 spin_unlock(&tcon->tc_lock);
2424 spin_unlock(&cifs_tcp_ses_lock);
2425 pr_warn_once("Server share %s deleted.\n",
2431 spin_unlock(&cifs_tcp_ses_lock);
2435 smb2_oplock_response(struct cifs_tcon *tcon, __u64 persistent_fid,
2436 __u64 volatile_fid, __u16 net_fid, struct cifsInodeInfo *cinode)
2438 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
2439 return SMB2_lease_break(0, tcon, cinode->lease_key,
2440 smb2_get_lease_state(cinode));
2442 return SMB2_oplock_break(0, tcon, persistent_fid, volatile_fid,
2443 CIFS_CACHE_READ(cinode) ? 1 : 0);
2447 smb2_set_related(struct smb_rqst *rqst)
2449 struct smb2_hdr *shdr;
2451 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2453 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2456 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2459 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
2462 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
2464 struct smb2_hdr *shdr;
2465 struct cifs_ses *ses = tcon->ses;
2466 struct TCP_Server_Info *server = ses->server;
2467 unsigned long len = smb_rqst_len(server, rqst);
2470 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2472 cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2476 /* SMB headers in a compound are 8 byte aligned. */
2478 /* No padding needed */
2482 num_padding = 8 - (len & 7);
2483 if (!smb3_encryption_required(tcon)) {
2485 * If we do not have encryption then we can just add an extra
2486 * iov for the padding.
2488 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2489 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2494 * We can not add a small padding iov for the encryption case
2495 * because the encryption framework can not handle the padding
2497 * We have to flatten this into a single buffer and add
2498 * the padding to it.
2500 for (i = 1; i < rqst->rq_nvec; i++) {
2501 memcpy(rqst->rq_iov[0].iov_base +
2502 rqst->rq_iov[0].iov_len,
2503 rqst->rq_iov[i].iov_base,
2504 rqst->rq_iov[i].iov_len);
2505 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2507 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2509 rqst->rq_iov[0].iov_len += num_padding;
2515 shdr->NextCommand = cpu_to_le32(len);
2519 * Passes the query info response back to the caller on success.
2520 * Caller need to free this with free_rsp_buf().
2523 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2524 const char *path, u32 desired_access,
2525 u32 class, u32 type, u32 output_len,
2526 struct kvec *rsp, int *buftype,
2527 struct cifs_sb_info *cifs_sb)
2529 struct cifs_ses *ses = tcon->ses;
2530 struct TCP_Server_Info *server = cifs_pick_channel(ses);
2531 int flags = CIFS_CP_CREATE_CLOSE_OP;
2532 struct smb_rqst rqst[3];
2533 int resp_buftype[3];
2534 struct kvec rsp_iov[3];
2535 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2536 struct kvec qi_iov[1];
2537 struct kvec close_iov[1];
2538 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2539 struct cifs_open_parms oparms;
2540 struct cifs_fid fid;
2543 struct cached_fid *cfid = NULL;
2547 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2551 if (smb3_encryption_required(tcon))
2552 flags |= CIFS_TRANSFORM_REQ;
2554 memset(rqst, 0, sizeof(rqst));
2555 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2556 memset(rsp_iov, 0, sizeof(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 memset(&open_iov, 0, sizeof(open_iov));
2566 rqst[0].rq_iov = open_iov;
2567 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2569 oparms = (struct cifs_open_parms) {
2572 .desired_access = desired_access,
2573 .disposition = FILE_OPEN,
2574 .create_options = cifs_create_options(cifs_sb, 0),
2578 rc = SMB2_open_init(tcon, server,
2579 &rqst[0], &oplock, &oparms, utf16_path);
2582 smb2_set_next_command(tcon, &rqst[0]);
2584 memset(&qi_iov, 0, sizeof(qi_iov));
2585 rqst[1].rq_iov = qi_iov;
2586 rqst[1].rq_nvec = 1;
2589 rc = SMB2_query_info_init(tcon, server,
2591 cfid->fid.persistent_fid,
2592 cfid->fid.volatile_fid,
2597 rc = SMB2_query_info_init(tcon, server,
2608 smb2_set_next_command(tcon, &rqst[1]);
2609 smb2_set_related(&rqst[1]);
2612 memset(&close_iov, 0, sizeof(close_iov));
2613 rqst[2].rq_iov = close_iov;
2614 rqst[2].rq_nvec = 1;
2616 rc = SMB2_close_init(tcon, server,
2617 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2620 smb2_set_related(&rqst[2]);
2623 rc = compound_send_recv(xid, ses, server,
2625 &resp_buftype[1], &rsp_iov[1]);
2627 rc = compound_send_recv(xid, ses, server,
2629 resp_buftype, rsp_iov);
2632 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2633 if (rc == -EREMCHG) {
2634 tcon->need_reconnect = true;
2635 pr_warn_once("server share %s deleted\n",
2641 *buftype = resp_buftype[1];
2645 SMB2_open_free(&rqst[0]);
2646 SMB2_query_info_free(&rqst[1]);
2647 SMB2_close_free(&rqst[2]);
2648 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2649 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2651 close_cached_dir(cfid);
2656 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2657 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2659 struct smb2_query_info_rsp *rsp;
2660 struct smb2_fs_full_size_info *info = NULL;
2661 struct kvec rsp_iov = {NULL, 0};
2662 int buftype = CIFS_NO_BUFFER;
2666 rc = smb2_query_info_compound(xid, tcon, "",
2667 FILE_READ_ATTRIBUTES,
2668 FS_FULL_SIZE_INFORMATION,
2669 SMB2_O_INFO_FILESYSTEM,
2670 sizeof(struct smb2_fs_full_size_info),
2671 &rsp_iov, &buftype, cifs_sb);
2675 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2676 buf->f_type = SMB2_SUPER_MAGIC;
2677 info = (struct smb2_fs_full_size_info *)(
2678 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2679 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2680 le32_to_cpu(rsp->OutputBufferLength),
2682 sizeof(struct smb2_fs_full_size_info));
2684 smb2_copy_fs_info_to_kstatfs(info, buf);
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));
2955 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
2956 struct cifs_sb_info *cifs_sb, const char *full_path,
2957 char **target_path, bool is_reparse_point)
2960 __le16 *utf16_path = NULL;
2961 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2962 struct cifs_open_parms oparms;
2963 struct cifs_fid fid;
2964 struct kvec err_iov = {NULL, 0};
2965 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2966 int flags = CIFS_CP_CREATE_CLOSE_OP;
2967 struct smb_rqst rqst[3];
2968 int resp_buftype[3];
2969 struct kvec rsp_iov[3];
2970 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2971 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2972 struct kvec close_iov[1];
2973 struct smb2_create_rsp *create_rsp;
2974 struct smb2_ioctl_rsp *ioctl_rsp;
2975 struct reparse_data_buffer *reparse_buf;
2976 int create_options = is_reparse_point ? OPEN_REPARSE_POINT : 0;
2979 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2981 *target_path = NULL;
2983 if (smb3_encryption_required(tcon))
2984 flags |= CIFS_TRANSFORM_REQ;
2986 memset(rqst, 0, sizeof(rqst));
2987 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2988 memset(rsp_iov, 0, sizeof(rsp_iov));
2990 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
2995 memset(&open_iov, 0, sizeof(open_iov));
2996 rqst[0].rq_iov = open_iov;
2997 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2999 oparms = (struct cifs_open_parms) {
3002 .desired_access = FILE_READ_ATTRIBUTES,
3003 .disposition = FILE_OPEN,
3004 .create_options = cifs_create_options(cifs_sb, create_options),
3008 rc = SMB2_open_init(tcon, server,
3009 &rqst[0], &oplock, &oparms, utf16_path);
3012 smb2_set_next_command(tcon, &rqst[0]);
3016 memset(&io_iov, 0, sizeof(io_iov));
3017 rqst[1].rq_iov = io_iov;
3018 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3020 rc = SMB2_ioctl_init(tcon, server,
3021 &rqst[1], fid.persistent_fid,
3022 fid.volatile_fid, FSCTL_GET_REPARSE_POINT, NULL, 0,
3024 MAX_SMB2_CREATE_RESPONSE_SIZE -
3025 MAX_SMB2_CLOSE_RESPONSE_SIZE);
3029 smb2_set_next_command(tcon, &rqst[1]);
3030 smb2_set_related(&rqst[1]);
3034 memset(&close_iov, 0, sizeof(close_iov));
3035 rqst[2].rq_iov = close_iov;
3036 rqst[2].rq_nvec = 1;
3038 rc = SMB2_close_init(tcon, server,
3039 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3043 smb2_set_related(&rqst[2]);
3045 rc = compound_send_recv(xid, tcon->ses, server,
3047 resp_buftype, rsp_iov);
3049 create_rsp = rsp_iov[0].iov_base;
3050 if (create_rsp && create_rsp->hdr.Status)
3051 err_iov = rsp_iov[0];
3052 ioctl_rsp = rsp_iov[1].iov_base;
3055 * Open was successful and we got an ioctl response.
3057 if ((rc == 0) && (is_reparse_point)) {
3058 /* See MS-FSCC 2.3.23 */
3060 reparse_buf = (struct reparse_data_buffer *)
3061 ((char *)ioctl_rsp +
3062 le32_to_cpu(ioctl_rsp->OutputOffset));
3063 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3065 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3066 rsp_iov[1].iov_len) {
3067 cifs_tcon_dbg(VFS, "srv returned invalid ioctl len: %d\n",
3073 rc = parse_reparse_point(reparse_buf, plen, target_path,
3078 if (!rc || !err_iov.iov_base) {
3083 rc = smb2_parse_symlink_response(cifs_sb, &err_iov, target_path);
3086 cifs_dbg(FYI, "query symlink rc %d\n", rc);
3088 SMB2_open_free(&rqst[0]);
3089 SMB2_ioctl_free(&rqst[1]);
3090 SMB2_close_free(&rqst[2]);
3091 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3092 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3093 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3098 smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
3099 struct cifs_sb_info *cifs_sb, const char *full_path,
3103 __le16 *utf16_path = NULL;
3104 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3105 struct cifs_open_parms oparms;
3106 struct cifs_fid fid;
3107 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
3108 int flags = CIFS_CP_CREATE_CLOSE_OP;
3109 struct smb_rqst rqst[3];
3110 int resp_buftype[3];
3111 struct kvec rsp_iov[3];
3112 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
3113 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
3114 struct kvec close_iov[1];
3115 struct smb2_ioctl_rsp *ioctl_rsp;
3116 struct reparse_data_buffer *reparse_buf;
3119 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
3121 if (smb3_encryption_required(tcon))
3122 flags |= CIFS_TRANSFORM_REQ;
3124 memset(rqst, 0, sizeof(rqst));
3125 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
3126 memset(rsp_iov, 0, sizeof(rsp_iov));
3128 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
3133 * setup smb2open - TODO add optimization to call cifs_get_readable_path
3134 * to see if there is a handle already open that we can use
3136 memset(&open_iov, 0, sizeof(open_iov));
3137 rqst[0].rq_iov = open_iov;
3138 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
3140 oparms = (struct cifs_open_parms) {
3143 .desired_access = FILE_READ_ATTRIBUTES,
3144 .disposition = FILE_OPEN,
3145 .create_options = cifs_create_options(cifs_sb, OPEN_REPARSE_POINT),
3149 rc = SMB2_open_init(tcon, server,
3150 &rqst[0], &oplock, &oparms, utf16_path);
3153 smb2_set_next_command(tcon, &rqst[0]);
3157 memset(&io_iov, 0, sizeof(io_iov));
3158 rqst[1].rq_iov = io_iov;
3159 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3161 rc = SMB2_ioctl_init(tcon, server,
3162 &rqst[1], COMPOUND_FID,
3163 COMPOUND_FID, FSCTL_GET_REPARSE_POINT, NULL, 0,
3165 MAX_SMB2_CREATE_RESPONSE_SIZE -
3166 MAX_SMB2_CLOSE_RESPONSE_SIZE);
3170 smb2_set_next_command(tcon, &rqst[1]);
3171 smb2_set_related(&rqst[1]);
3175 memset(&close_iov, 0, sizeof(close_iov));
3176 rqst[2].rq_iov = close_iov;
3177 rqst[2].rq_nvec = 1;
3179 rc = SMB2_close_init(tcon, server,
3180 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3184 smb2_set_related(&rqst[2]);
3186 rc = compound_send_recv(xid, tcon->ses, server,
3188 resp_buftype, rsp_iov);
3190 ioctl_rsp = rsp_iov[1].iov_base;
3193 * Open was successful and we got an ioctl response.
3196 /* See MS-FSCC 2.3.23 */
3198 reparse_buf = (struct reparse_data_buffer *)
3199 ((char *)ioctl_rsp +
3200 le32_to_cpu(ioctl_rsp->OutputOffset));
3201 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3203 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3204 rsp_iov[1].iov_len) {
3205 cifs_tcon_dbg(FYI, "srv returned invalid ioctl len: %d\n",
3210 *tag = le32_to_cpu(reparse_buf->ReparseTag);
3215 SMB2_open_free(&rqst[0]);
3216 SMB2_ioctl_free(&rqst[1]);
3217 SMB2_close_free(&rqst[2]);
3218 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3219 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3220 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3224 static struct cifs_ntsd *
3225 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
3226 const struct cifs_fid *cifsfid, u32 *pacllen, u32 info)
3228 struct cifs_ntsd *pntsd = NULL;
3230 int rc = -EOPNOTSUPP;
3231 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3234 return ERR_CAST(tlink);
3237 cifs_dbg(FYI, "trying to get acl\n");
3239 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
3240 cifsfid->volatile_fid, (void **)&pntsd, pacllen,
3244 cifs_put_tlink(tlink);
3246 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3253 static struct cifs_ntsd *
3254 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
3255 const char *path, u32 *pacllen, u32 info)
3257 struct cifs_ntsd *pntsd = NULL;
3258 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3261 struct cifs_tcon *tcon;
3262 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3263 struct cifs_fid fid;
3264 struct cifs_open_parms oparms;
3267 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
3269 return ERR_CAST(tlink);
3271 tcon = tlink_tcon(tlink);
3274 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3281 oparms = (struct cifs_open_parms) {
3284 .desired_access = READ_CONTROL,
3285 .disposition = FILE_OPEN,
3287 * When querying an ACL, even if the file is a symlink
3288 * we want to open the source not the target, and so
3289 * the protocol requires that the client specify this
3290 * flag when opening a reparse point
3292 .create_options = cifs_create_options(cifs_sb, 0) |
3297 if (info & SACL_SECINFO)
3298 oparms.desired_access |= SYSTEM_SECURITY;
3300 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
3304 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3305 fid.volatile_fid, (void **)&pntsd, pacllen,
3307 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3310 cifs_put_tlink(tlink);
3313 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3320 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
3321 struct inode *inode, const char *path, int aclflag)
3323 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3325 int rc, access_flags = 0;
3326 struct cifs_tcon *tcon;
3327 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
3328 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3329 struct cifs_fid fid;
3330 struct cifs_open_parms oparms;
3333 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
3335 return PTR_ERR(tlink);
3337 tcon = tlink_tcon(tlink);
3340 if (aclflag & CIFS_ACL_OWNER || aclflag & CIFS_ACL_GROUP)
3341 access_flags |= WRITE_OWNER;
3342 if (aclflag & CIFS_ACL_SACL)
3343 access_flags |= SYSTEM_SECURITY;
3344 if (aclflag & CIFS_ACL_DACL)
3345 access_flags |= WRITE_DAC;
3347 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3354 oparms = (struct cifs_open_parms) {
3356 .desired_access = access_flags,
3357 .create_options = cifs_create_options(cifs_sb, 0),
3358 .disposition = FILE_OPEN,
3363 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
3367 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3368 fid.volatile_fid, pnntsd, acllen, aclflag);
3369 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3372 cifs_put_tlink(tlink);
3377 /* Retrieve an ACL from the server */
3378 static struct cifs_ntsd *
3379 get_smb2_acl(struct cifs_sb_info *cifs_sb,
3380 struct inode *inode, const char *path,
3381 u32 *pacllen, u32 info)
3383 struct cifs_ntsd *pntsd = NULL;
3384 struct cifsFileInfo *open_file = NULL;
3386 if (inode && !(info & SACL_SECINFO))
3387 open_file = find_readable_file(CIFS_I(inode), true);
3388 if (!open_file || (info & SACL_SECINFO))
3389 return get_smb2_acl_by_path(cifs_sb, path, pacllen, info);
3391 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen, info);
3392 cifsFileInfo_put(open_file);
3396 static long smb3_zero_data(struct file *file, struct cifs_tcon *tcon,
3397 loff_t offset, loff_t len, unsigned int xid)
3399 struct cifsFileInfo *cfile = file->private_data;
3400 struct file_zero_data_information fsctl_buf;
3402 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3404 fsctl_buf.FileOffset = cpu_to_le64(offset);
3405 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3407 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3408 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3410 sizeof(struct file_zero_data_information),
3414 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3415 loff_t offset, loff_t len, bool keep_size)
3417 struct cifs_ses *ses = tcon->ses;
3418 struct inode *inode = file_inode(file);
3419 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3420 struct cifsFileInfo *cfile = file->private_data;
3427 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3428 ses->Suid, offset, len);
3431 filemap_invalidate_lock(inode->i_mapping);
3434 * We zero the range through ioctl, so we need remove the page caches
3435 * first, otherwise the data may be inconsistent with the server.
3437 truncate_pagecache_range(inode, offset, offset + len - 1);
3439 /* if file not oplocked can't be sure whether asking to extend size */
3441 if (keep_size == false && !CIFS_CACHE_READ(cifsi))
3442 goto zero_range_exit;
3444 rc = smb3_zero_data(file, tcon, offset, len, xid);
3446 goto zero_range_exit;
3449 * do we also need to change the size of the file?
3451 if (keep_size == false && i_size_read(inode) < offset + len) {
3452 eof = cpu_to_le64(offset + len);
3453 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3454 cfile->fid.volatile_fid, cfile->pid, &eof);
3458 filemap_invalidate_unlock(inode->i_mapping);
3459 inode_unlock(inode);
3462 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
3463 ses->Suid, offset, len, rc);
3465 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
3466 ses->Suid, offset, len);
3470 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
3471 loff_t offset, loff_t len)
3473 struct inode *inode = file_inode(file);
3474 struct cifsFileInfo *cfile = file->private_data;
3475 struct file_zero_data_information fsctl_buf;
3478 __u8 set_sparse = 1;
3483 /* Need to make file sparse, if not already, before freeing range. */
3484 /* Consider adding equivalent for compressed since it could also work */
3485 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
3490 filemap_invalidate_lock(inode->i_mapping);
3492 * We implement the punch hole through ioctl, so we need remove the page
3493 * caches first, otherwise the data may be inconsistent with the server.
3495 truncate_pagecache_range(inode, offset, offset + len - 1);
3497 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3499 fsctl_buf.FileOffset = cpu_to_le64(offset);
3500 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3502 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3503 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3505 sizeof(struct file_zero_data_information),
3506 CIFSMaxBufSize, NULL, NULL);
3507 filemap_invalidate_unlock(inode->i_mapping);
3509 inode_unlock(inode);
3514 static int smb3_simple_fallocate_write_range(unsigned int xid,
3515 struct cifs_tcon *tcon,
3516 struct cifsFileInfo *cfile,
3517 loff_t off, loff_t len,
3520 struct cifs_io_parms io_parms = {0};
3525 io_parms.netfid = cfile->fid.netfid;
3526 io_parms.pid = current->tgid;
3527 io_parms.tcon = tcon;
3528 io_parms.persistent_fid = cfile->fid.persistent_fid;
3529 io_parms.volatile_fid = cfile->fid.volatile_fid;
3532 io_parms.offset = off;
3533 io_parms.length = len;
3534 if (io_parms.length > SMB2_MAX_BUFFER_SIZE)
3535 io_parms.length = SMB2_MAX_BUFFER_SIZE;
3536 /* iov[0] is reserved for smb header */
3537 iov[1].iov_base = buf;
3538 iov[1].iov_len = io_parms.length;
3539 rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
3551 static int smb3_simple_fallocate_range(unsigned int xid,
3552 struct cifs_tcon *tcon,
3553 struct cifsFileInfo *cfile,
3554 loff_t off, loff_t len)
3556 struct file_allocated_range_buffer in_data, *out_data = NULL, *tmp_data;
3562 in_data.file_offset = cpu_to_le64(off);
3563 in_data.length = cpu_to_le64(len);
3564 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3565 cfile->fid.volatile_fid,
3566 FSCTL_QUERY_ALLOCATED_RANGES,
3567 (char *)&in_data, sizeof(in_data),
3568 1024 * sizeof(struct file_allocated_range_buffer),
3569 (char **)&out_data, &out_data_len);
3573 buf = kzalloc(1024 * 1024, GFP_KERNEL);
3579 tmp_data = out_data;
3582 * The rest of the region is unmapped so write it all.
3584 if (out_data_len == 0) {
3585 rc = smb3_simple_fallocate_write_range(xid, tcon,
3586 cfile, off, len, buf);
3590 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3595 if (off < le64_to_cpu(tmp_data->file_offset)) {
3597 * We are at a hole. Write until the end of the region
3598 * or until the next allocated data,
3599 * whichever comes next.
3601 l = le64_to_cpu(tmp_data->file_offset) - off;
3604 rc = smb3_simple_fallocate_write_range(xid, tcon,
3605 cfile, off, l, buf);
3614 * We are at a section of allocated data, just skip forward
3615 * until the end of the data or the end of the region
3616 * we are supposed to fallocate, whichever comes first.
3618 l = le64_to_cpu(tmp_data->length);
3624 tmp_data = &tmp_data[1];
3625 out_data_len -= sizeof(struct file_allocated_range_buffer);
3635 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3636 loff_t off, loff_t len, bool keep_size)
3638 struct inode *inode;
3639 struct cifsInodeInfo *cifsi;
3640 struct cifsFileInfo *cfile = file->private_data;
3641 long rc = -EOPNOTSUPP;
3647 inode = d_inode(cfile->dentry);
3648 cifsi = CIFS_I(inode);
3650 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3651 tcon->ses->Suid, off, len);
3652 /* if file not oplocked can't be sure whether asking to extend size */
3653 if (!CIFS_CACHE_READ(cifsi))
3654 if (keep_size == false) {
3655 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3656 tcon->tid, tcon->ses->Suid, off, len, rc);
3662 * Extending the file
3664 if ((keep_size == false) && i_size_read(inode) < off + len) {
3665 rc = inode_newsize_ok(inode, off + len);
3669 if (cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)
3670 smb2_set_sparse(xid, tcon, cfile, inode, false);
3672 eof = cpu_to_le64(off + len);
3673 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3674 cfile->fid.volatile_fid, cfile->pid, &eof);
3676 cifsi->server_eof = off + len;
3677 cifs_setsize(inode, off + len);
3678 cifs_truncate_page(inode->i_mapping, inode->i_size);
3679 truncate_setsize(inode, off + len);
3685 * Files are non-sparse by default so falloc may be a no-op
3686 * Must check if file sparse. If not sparse, and since we are not
3687 * extending then no need to do anything since file already allocated
3689 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
3694 if (keep_size == true) {
3696 * We can not preallocate pages beyond the end of the file
3699 if (off >= i_size_read(inode)) {
3704 * For fallocates that are partially beyond the end of file,
3705 * clamp len so we only fallocate up to the end of file.
3707 if (off + len > i_size_read(inode)) {
3708 len = i_size_read(inode) - off;
3712 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3714 * At this point, we are trying to fallocate an internal
3715 * regions of a sparse file. Since smb2 does not have a
3716 * fallocate command we have two otions on how to emulate this.
3717 * We can either turn the entire file to become non-sparse
3718 * which we only do if the fallocate is for virtually
3719 * the whole file, or we can overwrite the region with zeroes
3720 * using SMB2_write, which could be prohibitevly expensive
3724 * We are only trying to fallocate a small region so
3725 * just write it with zero.
3727 if (len <= 1024 * 1024) {
3728 rc = smb3_simple_fallocate_range(xid, tcon, cfile,
3734 * Check if falloc starts within first few pages of file
3735 * and ends within a few pages of the end of file to
3736 * ensure that most of file is being forced to be
3737 * fallocated now. If so then setting whole file sparse
3738 * ie potentially making a few extra pages at the beginning
3739 * or end of the file non-sparse via set_sparse is harmless.
3741 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
3747 smb2_set_sparse(xid, tcon, cfile, inode, false);
3752 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3753 tcon->ses->Suid, off, len, rc);
3755 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3756 tcon->ses->Suid, off, len);
3762 static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
3763 loff_t off, loff_t len)
3767 struct inode *inode = file_inode(file);
3768 struct cifsFileInfo *cfile = file->private_data;
3769 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3777 old_eof = i_size_read(inode);
3778 if ((off >= old_eof) ||
3779 off + len >= old_eof) {
3784 filemap_invalidate_lock(inode->i_mapping);
3785 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof - 1);
3789 truncate_pagecache_range(inode, off, old_eof);
3791 rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
3792 old_eof - off - len, off);
3796 eof = cpu_to_le64(old_eof - len);
3797 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3798 cfile->fid.volatile_fid, cfile->pid, &eof);
3804 cifsi->server_eof = i_size_read(inode) - len;
3805 truncate_setsize(inode, cifsi->server_eof);
3806 fscache_resize_cookie(cifs_inode_cookie(inode), cifsi->server_eof);
3808 filemap_invalidate_unlock(inode->i_mapping);
3810 inode_unlock(inode);
3815 static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
3816 loff_t off, loff_t len)
3820 struct cifsFileInfo *cfile = file->private_data;
3821 struct inode *inode = file_inode(file);
3823 __u64 count, old_eof;
3829 old_eof = i_size_read(inode);
3830 if (off >= old_eof) {
3835 count = old_eof - off;
3836 eof = cpu_to_le64(old_eof + len);
3838 filemap_invalidate_lock(inode->i_mapping);
3839 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof + len - 1);
3842 truncate_pagecache_range(inode, off, old_eof);
3844 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3845 cfile->fid.volatile_fid, cfile->pid, &eof);
3849 rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len);
3853 rc = smb3_zero_data(file, tcon, off, len, xid);
3859 filemap_invalidate_unlock(inode->i_mapping);
3861 inode_unlock(inode);
3866 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3868 struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3869 struct cifsInodeInfo *cifsi;
3870 struct inode *inode;
3872 struct file_allocated_range_buffer in_data, *out_data = NULL;
3876 if (whence != SEEK_HOLE && whence != SEEK_DATA)
3877 return generic_file_llseek(file, offset, whence);
3879 inode = d_inode(cfile->dentry);
3880 cifsi = CIFS_I(inode);
3882 if (offset < 0 || offset >= i_size_read(inode))
3887 * We need to be sure that all dirty pages are written as they
3888 * might fill holes on the server.
3889 * Note that we also MUST flush any written pages since at least
3890 * some servers (Windows2016) will not reflect recent writes in
3891 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3893 wrcfile = find_writable_file(cifsi, FIND_WR_ANY);
3895 filemap_write_and_wait(inode->i_mapping);
3896 smb2_flush_file(xid, tcon, &wrcfile->fid);
3897 cifsFileInfo_put(wrcfile);
3900 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3901 if (whence == SEEK_HOLE)
3902 offset = i_size_read(inode);
3906 in_data.file_offset = cpu_to_le64(offset);
3907 in_data.length = cpu_to_le64(i_size_read(inode));
3909 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3910 cfile->fid.volatile_fid,
3911 FSCTL_QUERY_ALLOCATED_RANGES,
3912 (char *)&in_data, sizeof(in_data),
3913 sizeof(struct file_allocated_range_buffer),
3914 (char **)&out_data, &out_data_len);
3920 if (whence == SEEK_HOLE && out_data_len == 0)
3923 if (whence == SEEK_DATA && out_data_len == 0) {
3928 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3932 if (whence == SEEK_DATA) {
3933 offset = le64_to_cpu(out_data->file_offset);
3936 if (offset < le64_to_cpu(out_data->file_offset))
3939 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3945 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3950 static int smb3_fiemap(struct cifs_tcon *tcon,
3951 struct cifsFileInfo *cfile,
3952 struct fiemap_extent_info *fei, u64 start, u64 len)
3955 struct file_allocated_range_buffer in_data, *out_data;
3957 int i, num, rc, flags, last_blob;
3960 rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0);
3966 in_data.file_offset = cpu_to_le64(start);
3967 in_data.length = cpu_to_le64(len);
3969 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3970 cfile->fid.volatile_fid,
3971 FSCTL_QUERY_ALLOCATED_RANGES,
3972 (char *)&in_data, sizeof(in_data),
3973 1024 * sizeof(struct file_allocated_range_buffer),
3974 (char **)&out_data, &out_data_len);
3983 if (out_data_len && out_data_len < sizeof(struct file_allocated_range_buffer)) {
3987 if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3992 num = out_data_len / sizeof(struct file_allocated_range_buffer);
3993 for (i = 0; i < num; i++) {
3995 if (i == num - 1 && last_blob)
3996 flags |= FIEMAP_EXTENT_LAST;
3998 rc = fiemap_fill_next_extent(fei,
3999 le64_to_cpu(out_data[i].file_offset),
4000 le64_to_cpu(out_data[i].file_offset),
4001 le64_to_cpu(out_data[i].length),
4012 next = le64_to_cpu(out_data[num - 1].file_offset) +
4013 le64_to_cpu(out_data[num - 1].length);
4014 len = len - (next - start);
4025 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
4026 loff_t off, loff_t len)
4028 /* KEEP_SIZE already checked for by do_fallocate */
4029 if (mode & FALLOC_FL_PUNCH_HOLE)
4030 return smb3_punch_hole(file, tcon, off, len);
4031 else if (mode & FALLOC_FL_ZERO_RANGE) {
4032 if (mode & FALLOC_FL_KEEP_SIZE)
4033 return smb3_zero_range(file, tcon, off, len, true);
4034 return smb3_zero_range(file, tcon, off, len, false);
4035 } else if (mode == FALLOC_FL_KEEP_SIZE)
4036 return smb3_simple_falloc(file, tcon, off, len, true);
4037 else if (mode == FALLOC_FL_COLLAPSE_RANGE)
4038 return smb3_collapse_range(file, tcon, off, len);
4039 else if (mode == FALLOC_FL_INSERT_RANGE)
4040 return smb3_insert_range(file, tcon, off, len);
4042 return smb3_simple_falloc(file, tcon, off, len, false);
4048 smb2_downgrade_oplock(struct TCP_Server_Info *server,
4049 struct cifsInodeInfo *cinode, __u32 oplock,
4050 unsigned int epoch, bool *purge_cache)
4052 server->ops->set_oplock_level(cinode, oplock, 0, NULL);
4056 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4057 unsigned int epoch, bool *purge_cache);
4060 smb3_downgrade_oplock(struct TCP_Server_Info *server,
4061 struct cifsInodeInfo *cinode, __u32 oplock,
4062 unsigned int epoch, bool *purge_cache)
4064 unsigned int old_state = cinode->oplock;
4065 unsigned int old_epoch = cinode->epoch;
4066 unsigned int new_state;
4068 if (epoch > old_epoch) {
4069 smb21_set_oplock_level(cinode, oplock, 0, NULL);
4070 cinode->epoch = epoch;
4073 new_state = cinode->oplock;
4074 *purge_cache = false;
4076 if ((old_state & CIFS_CACHE_READ_FLG) != 0 &&
4077 (new_state & CIFS_CACHE_READ_FLG) == 0)
4078 *purge_cache = true;
4079 else if (old_state == new_state && (epoch - old_epoch > 1))
4080 *purge_cache = true;
4084 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4085 unsigned int epoch, bool *purge_cache)
4088 cinode->lease_granted = false;
4089 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
4091 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
4092 cinode->oplock = CIFS_CACHE_RHW_FLG;
4093 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
4094 &cinode->netfs.inode);
4095 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
4096 cinode->oplock = CIFS_CACHE_RW_FLG;
4097 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
4098 &cinode->netfs.inode);
4099 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
4100 cinode->oplock = CIFS_CACHE_READ_FLG;
4101 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
4102 &cinode->netfs.inode);
4108 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4109 unsigned int epoch, bool *purge_cache)
4111 char message[5] = {0};
4112 unsigned int new_oplock = 0;
4115 cinode->lease_granted = true;
4116 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
4119 /* Check if the server granted an oplock rather than a lease */
4120 if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4121 return smb2_set_oplock_level(cinode, oplock, epoch,
4124 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
4125 new_oplock |= CIFS_CACHE_READ_FLG;
4126 strcat(message, "R");
4128 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
4129 new_oplock |= CIFS_CACHE_HANDLE_FLG;
4130 strcat(message, "H");
4132 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
4133 new_oplock |= CIFS_CACHE_WRITE_FLG;
4134 strcat(message, "W");
4137 strncpy(message, "None", sizeof(message));
4139 cinode->oplock = new_oplock;
4140 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
4141 &cinode->netfs.inode);
4145 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4146 unsigned int epoch, bool *purge_cache)
4148 unsigned int old_oplock = cinode->oplock;
4150 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
4153 *purge_cache = false;
4154 if (old_oplock == CIFS_CACHE_READ_FLG) {
4155 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
4156 (epoch - cinode->epoch > 0))
4157 *purge_cache = true;
4158 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4159 (epoch - cinode->epoch > 1))
4160 *purge_cache = true;
4161 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4162 (epoch - cinode->epoch > 1))
4163 *purge_cache = true;
4164 else if (cinode->oplock == 0 &&
4165 (epoch - cinode->epoch > 0))
4166 *purge_cache = true;
4167 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
4168 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4169 (epoch - cinode->epoch > 0))
4170 *purge_cache = true;
4171 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4172 (epoch - cinode->epoch > 1))
4173 *purge_cache = true;
4175 cinode->epoch = epoch;
4179 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
4181 smb2_is_read_op(__u32 oplock)
4183 return oplock == SMB2_OPLOCK_LEVEL_II;
4185 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
4188 smb21_is_read_op(__u32 oplock)
4190 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
4191 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
4195 map_oplock_to_lease(u8 oplock)
4197 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4198 return SMB2_LEASE_WRITE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE;
4199 else if (oplock == SMB2_OPLOCK_LEVEL_II)
4200 return SMB2_LEASE_READ_CACHING_LE;
4201 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
4202 return SMB2_LEASE_HANDLE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE |
4203 SMB2_LEASE_WRITE_CACHING_LE;
4208 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
4210 struct create_lease *buf;
4212 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
4216 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4217 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4219 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4220 (struct create_lease, lcontext));
4221 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
4222 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4223 (struct create_lease, Name));
4224 buf->ccontext.NameLength = cpu_to_le16(4);
4225 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4234 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
4236 struct create_lease_v2 *buf;
4238 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
4242 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4243 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4245 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4246 (struct create_lease_v2, lcontext));
4247 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
4248 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4249 (struct create_lease_v2, Name));
4250 buf->ccontext.NameLength = cpu_to_le16(4);
4251 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4260 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4262 struct create_lease *lc = (struct create_lease *)buf;
4264 *epoch = 0; /* not used */
4265 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4266 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4267 return le32_to_cpu(lc->lcontext.LeaseState);
4271 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4273 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
4275 *epoch = le16_to_cpu(lc->lcontext.Epoch);
4276 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4277 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4279 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
4280 return le32_to_cpu(lc->lcontext.LeaseState);
4284 smb2_wp_retry_size(struct inode *inode)
4286 return min_t(unsigned int, CIFS_SB(inode->i_sb)->ctx->wsize,
4287 SMB2_MAX_BUFFER_SIZE);
4291 smb2_dir_needs_close(struct cifsFileInfo *cfile)
4293 return !cfile->invalidHandle;
4297 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
4298 struct smb_rqst *old_rq, __le16 cipher_type)
4300 struct smb2_hdr *shdr =
4301 (struct smb2_hdr *)old_rq->rq_iov[0].iov_base;
4303 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
4304 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
4305 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
4306 tr_hdr->Flags = cpu_to_le16(0x01);
4307 if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4308 (cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4309 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4311 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4312 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
4315 static void *smb2_aead_req_alloc(struct crypto_aead *tfm, const struct smb_rqst *rqst,
4316 int num_rqst, const u8 *sig, u8 **iv,
4317 struct aead_request **req, struct scatterlist **sgl,
4318 unsigned int *num_sgs)
4320 unsigned int req_size = sizeof(**req) + crypto_aead_reqsize(tfm);
4321 unsigned int iv_size = crypto_aead_ivsize(tfm);
4325 *num_sgs = cifs_get_num_sgs(rqst, num_rqst, sig);
4328 len += crypto_aead_alignmask(tfm) & ~(crypto_tfm_ctx_alignment() - 1);
4329 len = ALIGN(len, crypto_tfm_ctx_alignment());
4331 len = ALIGN(len, __alignof__(struct scatterlist));
4332 len += *num_sgs * sizeof(**sgl);
4334 p = kmalloc(len, GFP_ATOMIC);
4338 *iv = (u8 *)PTR_ALIGN(p, crypto_aead_alignmask(tfm) + 1);
4339 *req = (struct aead_request *)PTR_ALIGN(*iv + iv_size,
4340 crypto_tfm_ctx_alignment());
4341 *sgl = (struct scatterlist *)PTR_ALIGN((u8 *)*req + req_size,
4342 __alignof__(struct scatterlist));
4346 static void *smb2_get_aead_req(struct crypto_aead *tfm, const struct smb_rqst *rqst,
4347 int num_rqst, const u8 *sig, u8 **iv,
4348 struct aead_request **req, struct scatterlist **sgl)
4350 unsigned int off, len, skip;
4351 struct scatterlist *sg;
4352 unsigned int num_sgs;
4357 p = smb2_aead_req_alloc(tfm, rqst, num_rqst, sig, iv, req, sgl, &num_sgs);
4361 sg_init_table(*sgl, num_sgs);
4364 /* Assumes the first rqst has a transform header as the first iov.
4366 * rqst[0].rq_iov[0] is transform header
4367 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
4368 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
4370 for (i = 0; i < num_rqst; i++) {
4372 * The first rqst has a transform header where the
4373 * first 20 bytes are not part of the encrypted blob.
4375 for (j = 0; j < rqst[i].rq_nvec; j++) {
4376 struct kvec *iov = &rqst[i].rq_iov[j];
4378 skip = (i == 0) && (j == 0) ? 20 : 0;
4379 addr = (unsigned long)iov->iov_base + skip;
4380 len = iov->iov_len - skip;
4381 sg = cifs_sg_set_buf(sg, (void *)addr, len);
4383 for (j = 0; j < rqst[i].rq_npages; j++) {
4384 rqst_page_get_length(&rqst[i], j, &len, &off);
4385 sg_set_page(sg++, rqst[i].rq_pages[j], len, off);
4388 cifs_sg_set_buf(sg, sig, SMB2_SIGNATURE_SIZE);
4394 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
4396 struct TCP_Server_Info *pserver;
4397 struct cifs_ses *ses;
4400 /* If server is a channel, select the primary channel */
4401 pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
4403 spin_lock(&cifs_tcp_ses_lock);
4404 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
4405 if (ses->Suid == ses_id) {
4406 spin_lock(&ses->ses_lock);
4407 ses_enc_key = enc ? ses->smb3encryptionkey :
4408 ses->smb3decryptionkey;
4409 memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE);
4410 spin_unlock(&ses->ses_lock);
4411 spin_unlock(&cifs_tcp_ses_lock);
4415 spin_unlock(&cifs_tcp_ses_lock);
4420 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
4421 * iov[0] - transform header (associate data),
4422 * iov[1-N] - SMB2 header and pages - data to encrypt.
4423 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4427 crypt_message(struct TCP_Server_Info *server, int num_rqst,
4428 struct smb_rqst *rqst, int enc)
4430 struct smb2_transform_hdr *tr_hdr =
4431 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
4432 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
4434 struct scatterlist *sg;
4435 u8 sign[SMB2_SIGNATURE_SIZE] = {};
4436 u8 key[SMB3_ENC_DEC_KEY_SIZE];
4437 struct aead_request *req;
4439 DECLARE_CRYPTO_WAIT(wait);
4440 struct crypto_aead *tfm;
4441 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4444 rc = smb2_get_enc_key(server, le64_to_cpu(tr_hdr->SessionId), enc, key);
4446 cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
4451 rc = smb3_crypto_aead_allocate(server);
4453 cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
4457 tfm = enc ? server->secmech.enc : server->secmech.dec;
4459 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
4460 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4461 rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
4463 rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE);
4466 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
4470 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
4472 cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
4476 creq = smb2_get_aead_req(tfm, rqst, num_rqst, sign, &iv, &req, &sg);
4477 if (unlikely(!creq))
4481 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
4482 crypt_len += SMB2_SIGNATURE_SIZE;
4485 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4486 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4487 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4490 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4493 aead_request_set_tfm(req, tfm);
4494 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
4495 aead_request_set_ad(req, assoc_data_len);
4497 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
4498 crypto_req_done, &wait);
4500 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
4501 : crypto_aead_decrypt(req), &wait);
4504 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
4506 kfree_sensitive(creq);
4511 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
4515 for (i = 0; i < num_rqst; i++) {
4516 if (rqst[i].rq_pages) {
4517 for (j = rqst[i].rq_npages - 1; j >= 0; j--)
4518 put_page(rqst[i].rq_pages[j]);
4519 kfree(rqst[i].rq_pages);
4525 * This function will initialize new_rq and encrypt the content.
4526 * The first entry, new_rq[0], only contains a single iov which contains
4527 * a smb2_transform_hdr and is pre-allocated by the caller.
4528 * This function then populates new_rq[1+] with the content from olq_rq[0+].
4530 * The end result is an array of smb_rqst structures where the first structure
4531 * only contains a single iov for the transform header which we then can pass
4532 * to crypt_message().
4534 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4535 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
4538 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
4539 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
4541 struct page **pages;
4542 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
4543 unsigned int npages;
4544 unsigned int orig_len = 0;
4548 for (i = 1; i < num_rqst; i++) {
4549 npages = old_rq[i - 1].rq_npages;
4550 pages = kmalloc_array(npages, sizeof(struct page *),
4555 new_rq[i].rq_pages = pages;
4556 new_rq[i].rq_npages = npages;
4557 new_rq[i].rq_offset = old_rq[i - 1].rq_offset;
4558 new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz;
4559 new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz;
4560 new_rq[i].rq_iov = old_rq[i - 1].rq_iov;
4561 new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec;
4563 orig_len += smb_rqst_len(server, &old_rq[i - 1]);
4565 for (j = 0; j < npages; j++) {
4566 pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4571 /* copy pages form the old */
4572 for (j = 0; j < npages; j++) {
4574 unsigned int offset, len;
4576 rqst_page_get_length(&new_rq[i], j, &len, &offset);
4578 dst = (char *) kmap(new_rq[i].rq_pages[j]) + offset;
4579 src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset;
4581 memcpy(dst, src, len);
4582 kunmap(new_rq[i].rq_pages[j]);
4583 kunmap(old_rq[i - 1].rq_pages[j]);
4587 /* fill the 1st iov with a transform header */
4588 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
4590 rc = crypt_message(server, num_rqst, new_rq, 1);
4591 cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
4598 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
4603 smb3_is_transform_hdr(void *buf)
4605 struct smb2_transform_hdr *trhdr = buf;
4607 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
4611 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
4612 unsigned int buf_data_size, struct page **pages,
4613 unsigned int npages, unsigned int page_data_size,
4617 struct smb_rqst rqst = {NULL};
4620 iov[0].iov_base = buf;
4621 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
4622 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
4623 iov[1].iov_len = buf_data_size;
4627 rqst.rq_pages = pages;
4628 rqst.rq_npages = npages;
4629 rqst.rq_pagesz = PAGE_SIZE;
4630 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
4632 rc = crypt_message(server, 1, &rqst, 0);
4633 cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
4638 memmove(buf, iov[1].iov_base, buf_data_size);
4641 server->total_read = buf_data_size + page_data_size;
4647 read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
4648 unsigned int npages, unsigned int len)
4653 for (i = 0; i < npages; i++) {
4654 struct page *page = pages[i];
4658 if (len >= PAGE_SIZE) {
4659 /* enough data to fill the page */
4663 zero_user(page, len, PAGE_SIZE - len);
4666 length = cifs_read_page_from_socket(server, page, 0, n);
4669 server->total_read += length;
4676 init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
4677 unsigned int cur_off, struct bio_vec **page_vec)
4679 struct bio_vec *bvec;
4682 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
4686 for (i = 0; i < npages; i++) {
4687 bvec[i].bv_page = pages[i];
4688 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
4689 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
4690 data_size -= bvec[i].bv_len;
4693 if (data_size != 0) {
4694 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
4704 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
4705 char *buf, unsigned int buf_len, struct page **pages,
4706 unsigned int npages, unsigned int page_data_size,
4709 unsigned int data_offset;
4710 unsigned int data_len;
4711 unsigned int cur_off;
4712 unsigned int cur_page_idx;
4713 unsigned int pad_len;
4714 struct cifs_readdata *rdata = mid->callback_data;
4715 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
4716 struct bio_vec *bvec = NULL;
4717 struct iov_iter iter;
4720 bool use_rdma_mr = false;
4722 if (shdr->Command != SMB2_READ) {
4723 cifs_server_dbg(VFS, "only big read responses are supported\n");
4727 if (server->ops->is_session_expired &&
4728 server->ops->is_session_expired(buf)) {
4730 cifs_reconnect(server, true);
4734 if (server->ops->is_status_pending &&
4735 server->ops->is_status_pending(buf, server))
4738 /* set up first two iov to get credits */
4739 rdata->iov[0].iov_base = buf;
4740 rdata->iov[0].iov_len = 0;
4741 rdata->iov[1].iov_base = buf;
4742 rdata->iov[1].iov_len =
4743 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
4744 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
4745 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
4746 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
4747 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
4749 rdata->result = server->ops->map_error(buf, true);
4750 if (rdata->result != 0) {
4751 cifs_dbg(FYI, "%s: server returned error %d\n",
4752 __func__, rdata->result);
4753 /* normal error on read response */
4755 mid->mid_state = MID_RESPONSE_RECEIVED;
4757 dequeue_mid(mid, false);
4761 data_offset = server->ops->read_data_offset(buf);
4762 #ifdef CONFIG_CIFS_SMB_DIRECT
4763 use_rdma_mr = rdata->mr;
4765 data_len = server->ops->read_data_length(buf, use_rdma_mr);
4767 if (data_offset < server->vals->read_rsp_size) {
4769 * win2k8 sometimes sends an offset of 0 when the read
4770 * is beyond the EOF. Treat it as if the data starts just after
4773 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
4774 __func__, data_offset);
4775 data_offset = server->vals->read_rsp_size;
4776 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
4777 /* data_offset is beyond the end of smallbuf */
4778 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
4779 __func__, data_offset);
4780 rdata->result = -EIO;
4782 mid->mid_state = MID_RESPONSE_MALFORMED;
4784 dequeue_mid(mid, rdata->result);
4788 pad_len = data_offset - server->vals->read_rsp_size;
4790 if (buf_len <= data_offset) {
4791 /* read response payload is in pages */
4792 cur_page_idx = pad_len / PAGE_SIZE;
4793 cur_off = pad_len % PAGE_SIZE;
4795 if (cur_page_idx != 0) {
4796 /* data offset is beyond the 1st page of response */
4797 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
4798 __func__, data_offset);
4799 rdata->result = -EIO;
4801 mid->mid_state = MID_RESPONSE_MALFORMED;
4803 dequeue_mid(mid, rdata->result);
4807 if (data_len > page_data_size - pad_len) {
4808 /* data_len is corrupt -- discard frame */
4809 rdata->result = -EIO;
4811 mid->mid_state = MID_RESPONSE_MALFORMED;
4813 dequeue_mid(mid, rdata->result);
4817 rdata->result = init_read_bvec(pages, npages, page_data_size,
4819 if (rdata->result != 0) {
4821 mid->mid_state = MID_RESPONSE_MALFORMED;
4823 dequeue_mid(mid, rdata->result);
4827 iov_iter_bvec(&iter, ITER_SOURCE, bvec, npages, data_len);
4828 } else if (buf_len >= data_offset + data_len) {
4829 /* read response payload is in buf */
4830 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
4831 iov.iov_base = buf + data_offset;
4832 iov.iov_len = data_len;
4833 iov_iter_kvec(&iter, ITER_SOURCE, &iov, 1, data_len);
4835 /* read response payload cannot be in both buf and pages */
4836 WARN_ONCE(1, "buf can not contain only a part of read data");
4837 rdata->result = -EIO;
4839 mid->mid_state = MID_RESPONSE_MALFORMED;
4841 dequeue_mid(mid, rdata->result);
4845 length = rdata->copy_into_pages(server, rdata, &iter);
4853 mid->mid_state = MID_RESPONSE_RECEIVED;
4855 dequeue_mid(mid, false);
4859 struct smb2_decrypt_work {
4860 struct work_struct decrypt;
4861 struct TCP_Server_Info *server;
4862 struct page **ppages;
4864 unsigned int npages;
4869 static void smb2_decrypt_offload(struct work_struct *work)
4871 struct smb2_decrypt_work *dw = container_of(work,
4872 struct smb2_decrypt_work, decrypt);
4874 struct mid_q_entry *mid;
4876 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
4877 dw->ppages, dw->npages, dw->len, true);
4879 cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
4883 dw->server->lstrp = jiffies;
4884 mid = smb2_find_dequeue_mid(dw->server, dw->buf);
4886 cifs_dbg(FYI, "mid not found\n");
4888 mid->decrypted = true;
4889 rc = handle_read_data(dw->server, mid, dw->buf,
4890 dw->server->vals->read_rsp_size,
4891 dw->ppages, dw->npages, dw->len,
4894 #ifdef CONFIG_CIFS_STATS2
4895 mid->when_received = jiffies;
4897 if (dw->server->ops->is_network_name_deleted)
4898 dw->server->ops->is_network_name_deleted(dw->buf,
4903 spin_lock(&dw->server->srv_lock);
4904 if (dw->server->tcpStatus == CifsNeedReconnect) {
4905 spin_lock(&dw->server->mid_lock);
4906 mid->mid_state = MID_RETRY_NEEDED;
4907 spin_unlock(&dw->server->mid_lock);
4908 spin_unlock(&dw->server->srv_lock);
4911 spin_lock(&dw->server->mid_lock);
4912 mid->mid_state = MID_REQUEST_SUBMITTED;
4913 mid->mid_flags &= ~(MID_DELETED);
4914 list_add_tail(&mid->qhead,
4915 &dw->server->pending_mid_q);
4916 spin_unlock(&dw->server->mid_lock);
4917 spin_unlock(&dw->server->srv_lock);
4924 for (i = dw->npages-1; i >= 0; i--)
4925 put_page(dw->ppages[i]);
4928 cifs_small_buf_release(dw->buf);
4934 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
4937 char *buf = server->smallbuf;
4938 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4939 unsigned int npages;
4940 struct page **pages;
4942 unsigned int buflen = server->pdu_size;
4945 struct smb2_decrypt_work *dw;
4948 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
4949 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
4951 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
4954 server->total_read += rc;
4956 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
4957 server->vals->read_rsp_size;
4958 npages = DIV_ROUND_UP(len, PAGE_SIZE);
4960 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
4966 for (; i < npages; i++) {
4967 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4974 /* read read data into pages */
4975 rc = read_data_into_pages(server, pages, npages, len);
4979 rc = cifs_discard_remaining_data(server);
4984 * For large reads, offload to different thread for better performance,
4985 * use more cores decrypting which can be expensive
4988 if ((server->min_offload) && (server->in_flight > 1) &&
4989 (server->pdu_size >= server->min_offload)) {
4990 dw = kmalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL);
4992 goto non_offloaded_decrypt;
4994 dw->buf = server->smallbuf;
4995 server->smallbuf = (char *)cifs_small_buf_get();
4997 INIT_WORK(&dw->decrypt, smb2_decrypt_offload);
4999 dw->npages = npages;
5000 dw->server = server;
5003 queue_work(decrypt_wq, &dw->decrypt);
5004 *num_mids = 0; /* worker thread takes care of finding mid */
5008 non_offloaded_decrypt:
5009 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
5010 pages, npages, len, false);
5014 *mid = smb2_find_mid(server, buf);
5016 cifs_dbg(FYI, "mid not found\n");
5018 cifs_dbg(FYI, "mid found\n");
5019 (*mid)->decrypted = true;
5020 rc = handle_read_data(server, *mid, buf,
5021 server->vals->read_rsp_size,
5022 pages, npages, len, false);
5024 if (server->ops->is_network_name_deleted) {
5025 server->ops->is_network_name_deleted(buf,
5032 for (i = i - 1; i >= 0; i--)
5037 cifs_discard_remaining_data(server);
5042 receive_encrypted_standard(struct TCP_Server_Info *server,
5043 struct mid_q_entry **mids, char **bufs,
5047 char *buf = server->smallbuf;
5048 struct smb2_hdr *shdr;
5049 unsigned int pdu_length = server->pdu_size;
5050 unsigned int buf_size;
5051 struct mid_q_entry *mid_entry;
5053 char *next_buffer = NULL;
5057 /* switch to large buffer if too big for a small one */
5058 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
5059 server->large_buf = true;
5060 memcpy(server->bigbuf, buf, server->total_read);
5061 buf = server->bigbuf;
5064 /* now read the rest */
5065 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
5066 pdu_length - HEADER_SIZE(server) + 1);
5069 server->total_read += length;
5071 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
5072 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0, false);
5076 next_is_large = server->large_buf;
5078 shdr = (struct smb2_hdr *)buf;
5079 if (shdr->NextCommand) {
5081 next_buffer = (char *)cifs_buf_get();
5083 next_buffer = (char *)cifs_small_buf_get();
5085 buf + le32_to_cpu(shdr->NextCommand),
5086 pdu_length - le32_to_cpu(shdr->NextCommand));
5089 mid_entry = smb2_find_mid(server, buf);
5090 if (mid_entry == NULL)
5091 cifs_dbg(FYI, "mid not found\n");
5093 cifs_dbg(FYI, "mid found\n");
5094 mid_entry->decrypted = true;
5095 mid_entry->resp_buf_size = server->pdu_size;
5098 if (*num_mids >= MAX_COMPOUND) {
5099 cifs_server_dbg(VFS, "too many PDUs in compound\n");
5102 bufs[*num_mids] = buf;
5103 mids[(*num_mids)++] = mid_entry;
5105 if (mid_entry && mid_entry->handle)
5106 ret = mid_entry->handle(server, mid_entry);
5108 ret = cifs_handle_standard(server, mid_entry);
5110 if (ret == 0 && shdr->NextCommand) {
5111 pdu_length -= le32_to_cpu(shdr->NextCommand);
5112 server->large_buf = next_is_large;
5114 server->bigbuf = buf = next_buffer;
5116 server->smallbuf = buf = next_buffer;
5118 } else if (ret != 0) {
5120 * ret != 0 here means that we didn't get to handle_mid() thus
5121 * server->smallbuf and server->bigbuf are still valid. We need
5122 * to free next_buffer because it is not going to be used
5126 free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer);
5128 free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer);
5135 smb3_receive_transform(struct TCP_Server_Info *server,
5136 struct mid_q_entry **mids, char **bufs, int *num_mids)
5138 char *buf = server->smallbuf;
5139 unsigned int pdu_length = server->pdu_size;
5140 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
5141 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
5143 if (pdu_length < sizeof(struct smb2_transform_hdr) +
5144 sizeof(struct smb2_hdr)) {
5145 cifs_server_dbg(VFS, "Transform message is too small (%u)\n",
5147 cifs_reconnect(server, true);
5148 return -ECONNABORTED;
5151 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
5152 cifs_server_dbg(VFS, "Transform message is broken\n");
5153 cifs_reconnect(server, true);
5154 return -ECONNABORTED;
5157 /* TODO: add support for compounds containing READ. */
5158 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
5159 return receive_encrypted_read(server, &mids[0], num_mids);
5162 return receive_encrypted_standard(server, mids, bufs, num_mids);
5166 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
5168 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
5170 return handle_read_data(server, mid, buf, server->pdu_size,
5175 smb2_next_header(char *buf)
5177 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
5178 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
5180 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
5181 return sizeof(struct smb2_transform_hdr) +
5182 le32_to_cpu(t_hdr->OriginalMessageSize);
5184 return le32_to_cpu(hdr->NextCommand);
5188 smb2_make_node(unsigned int xid, struct inode *inode,
5189 struct dentry *dentry, struct cifs_tcon *tcon,
5190 const char *full_path, umode_t mode, dev_t dev)
5192 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
5194 struct cifs_open_info_data buf = {};
5195 struct cifs_io_parms io_parms = {0};
5197 struct cifs_fid fid;
5198 struct cifs_open_parms oparms;
5199 unsigned int bytes_written;
5200 struct win_dev *pdev;
5204 * Check if mounted with mount parm 'sfu' mount parm.
5205 * SFU emulation should work with all servers, but only
5206 * supports block and char device (no socket & fifo),
5207 * and was used by default in earlier versions of Windows
5209 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
5213 * TODO: Add ability to create instead via reparse point. Windows (e.g.
5214 * their current NFS server) uses this approach to expose special files
5215 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
5218 if (!S_ISCHR(mode) && !S_ISBLK(mode) && !S_ISFIFO(mode))
5221 cifs_dbg(FYI, "sfu compat create special file\n");
5223 oparms = (struct cifs_open_parms) {
5226 .desired_access = GENERIC_WRITE,
5227 .create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR |
5228 CREATE_OPTION_SPECIAL),
5229 .disposition = FILE_CREATE,
5234 if (tcon->ses->server->oplocks)
5235 oplock = REQ_OPLOCK;
5238 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, &buf);
5243 * BB Do not bother to decode buf since no local inode yet to put
5244 * timestamps in, but we can reuse it safely.
5247 pdev = (struct win_dev *)&buf.fi;
5248 io_parms.pid = current->tgid;
5249 io_parms.tcon = tcon;
5250 io_parms.offset = 0;
5251 io_parms.length = sizeof(struct win_dev);
5252 iov[1].iov_base = &buf.fi;
5253 iov[1].iov_len = sizeof(struct win_dev);
5254 if (S_ISCHR(mode)) {
5255 memcpy(pdev->type, "IntxCHR", 8);
5256 pdev->major = cpu_to_le64(MAJOR(dev));
5257 pdev->minor = cpu_to_le64(MINOR(dev));
5258 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5259 &bytes_written, iov, 1);
5260 } else if (S_ISBLK(mode)) {
5261 memcpy(pdev->type, "IntxBLK", 8);
5262 pdev->major = cpu_to_le64(MAJOR(dev));
5263 pdev->minor = cpu_to_le64(MINOR(dev));
5264 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5265 &bytes_written, iov, 1);
5266 } else if (S_ISFIFO(mode)) {
5267 memcpy(pdev->type, "LnxFIFO", 8);
5270 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5271 &bytes_written, iov, 1);
5273 tcon->ses->server->ops->close(xid, tcon, &fid);
5276 /* FIXME: add code here to set EAs */
5278 cifs_free_open_info(&buf);
5282 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5283 struct smb_version_operations smb20_operations = {
5284 .compare_fids = smb2_compare_fids,
5285 .setup_request = smb2_setup_request,
5286 .setup_async_request = smb2_setup_async_request,
5287 .check_receive = smb2_check_receive,
5288 .add_credits = smb2_add_credits,
5289 .set_credits = smb2_set_credits,
5290 .get_credits_field = smb2_get_credits_field,
5291 .get_credits = smb2_get_credits,
5292 .wait_mtu_credits = cifs_wait_mtu_credits,
5293 .get_next_mid = smb2_get_next_mid,
5294 .revert_current_mid = smb2_revert_current_mid,
5295 .read_data_offset = smb2_read_data_offset,
5296 .read_data_length = smb2_read_data_length,
5297 .map_error = map_smb2_to_linux_error,
5298 .find_mid = smb2_find_mid,
5299 .check_message = smb2_check_message,
5300 .dump_detail = smb2_dump_detail,
5301 .clear_stats = smb2_clear_stats,
5302 .print_stats = smb2_print_stats,
5303 .is_oplock_break = smb2_is_valid_oplock_break,
5304 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5305 .downgrade_oplock = smb2_downgrade_oplock,
5306 .need_neg = smb2_need_neg,
5307 .negotiate = smb2_negotiate,
5308 .negotiate_wsize = smb2_negotiate_wsize,
5309 .negotiate_rsize = smb2_negotiate_rsize,
5310 .sess_setup = SMB2_sess_setup,
5311 .logoff = SMB2_logoff,
5312 .tree_connect = SMB2_tcon,
5313 .tree_disconnect = SMB2_tdis,
5314 .qfs_tcon = smb2_qfs_tcon,
5315 .is_path_accessible = smb2_is_path_accessible,
5316 .can_echo = smb2_can_echo,
5318 .query_path_info = smb2_query_path_info,
5319 .get_srv_inum = smb2_get_srv_inum,
5320 .query_file_info = smb2_query_file_info,
5321 .set_path_size = smb2_set_path_size,
5322 .set_file_size = smb2_set_file_size,
5323 .set_file_info = smb2_set_file_info,
5324 .set_compression = smb2_set_compression,
5325 .mkdir = smb2_mkdir,
5326 .mkdir_setinfo = smb2_mkdir_setinfo,
5327 .rmdir = smb2_rmdir,
5328 .unlink = smb2_unlink,
5329 .rename = smb2_rename_path,
5330 .create_hardlink = smb2_create_hardlink,
5331 .query_symlink = smb2_query_symlink,
5332 .query_mf_symlink = smb3_query_mf_symlink,
5333 .create_mf_symlink = smb3_create_mf_symlink,
5334 .open = smb2_open_file,
5335 .set_fid = smb2_set_fid,
5336 .close = smb2_close_file,
5337 .flush = smb2_flush_file,
5338 .async_readv = smb2_async_readv,
5339 .async_writev = smb2_async_writev,
5340 .sync_read = smb2_sync_read,
5341 .sync_write = smb2_sync_write,
5342 .query_dir_first = smb2_query_dir_first,
5343 .query_dir_next = smb2_query_dir_next,
5344 .close_dir = smb2_close_dir,
5345 .calc_smb_size = smb2_calc_size,
5346 .is_status_pending = smb2_is_status_pending,
5347 .is_session_expired = smb2_is_session_expired,
5348 .oplock_response = smb2_oplock_response,
5349 .queryfs = smb2_queryfs,
5350 .mand_lock = smb2_mand_lock,
5351 .mand_unlock_range = smb2_unlock_range,
5352 .push_mand_locks = smb2_push_mandatory_locks,
5353 .get_lease_key = smb2_get_lease_key,
5354 .set_lease_key = smb2_set_lease_key,
5355 .new_lease_key = smb2_new_lease_key,
5356 .calc_signature = smb2_calc_signature,
5357 .is_read_op = smb2_is_read_op,
5358 .set_oplock_level = smb2_set_oplock_level,
5359 .create_lease_buf = smb2_create_lease_buf,
5360 .parse_lease_buf = smb2_parse_lease_buf,
5361 .copychunk_range = smb2_copychunk_range,
5362 .wp_retry_size = smb2_wp_retry_size,
5363 .dir_needs_close = smb2_dir_needs_close,
5364 .get_dfs_refer = smb2_get_dfs_refer,
5365 .select_sectype = smb2_select_sectype,
5366 #ifdef CONFIG_CIFS_XATTR
5367 .query_all_EAs = smb2_query_eas,
5368 .set_EA = smb2_set_ea,
5369 #endif /* CIFS_XATTR */
5370 .get_acl = get_smb2_acl,
5371 .get_acl_by_fid = get_smb2_acl_by_fid,
5372 .set_acl = set_smb2_acl,
5373 .next_header = smb2_next_header,
5374 .ioctl_query_info = smb2_ioctl_query_info,
5375 .make_node = smb2_make_node,
5376 .fiemap = smb3_fiemap,
5377 .llseek = smb3_llseek,
5378 .is_status_io_timeout = smb2_is_status_io_timeout,
5379 .is_network_name_deleted = smb2_is_network_name_deleted,
5381 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
5383 struct smb_version_operations smb21_operations = {
5384 .compare_fids = smb2_compare_fids,
5385 .setup_request = smb2_setup_request,
5386 .setup_async_request = smb2_setup_async_request,
5387 .check_receive = smb2_check_receive,
5388 .add_credits = smb2_add_credits,
5389 .set_credits = smb2_set_credits,
5390 .get_credits_field = smb2_get_credits_field,
5391 .get_credits = smb2_get_credits,
5392 .wait_mtu_credits = smb2_wait_mtu_credits,
5393 .adjust_credits = smb2_adjust_credits,
5394 .get_next_mid = smb2_get_next_mid,
5395 .revert_current_mid = smb2_revert_current_mid,
5396 .read_data_offset = smb2_read_data_offset,
5397 .read_data_length = smb2_read_data_length,
5398 .map_error = map_smb2_to_linux_error,
5399 .find_mid = smb2_find_mid,
5400 .check_message = smb2_check_message,
5401 .dump_detail = smb2_dump_detail,
5402 .clear_stats = smb2_clear_stats,
5403 .print_stats = smb2_print_stats,
5404 .is_oplock_break = smb2_is_valid_oplock_break,
5405 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5406 .downgrade_oplock = smb2_downgrade_oplock,
5407 .need_neg = smb2_need_neg,
5408 .negotiate = smb2_negotiate,
5409 .negotiate_wsize = smb2_negotiate_wsize,
5410 .negotiate_rsize = smb2_negotiate_rsize,
5411 .sess_setup = SMB2_sess_setup,
5412 .logoff = SMB2_logoff,
5413 .tree_connect = SMB2_tcon,
5414 .tree_disconnect = SMB2_tdis,
5415 .qfs_tcon = smb2_qfs_tcon,
5416 .is_path_accessible = smb2_is_path_accessible,
5417 .can_echo = smb2_can_echo,
5419 .query_path_info = smb2_query_path_info,
5420 .get_srv_inum = smb2_get_srv_inum,
5421 .query_file_info = smb2_query_file_info,
5422 .set_path_size = smb2_set_path_size,
5423 .set_file_size = smb2_set_file_size,
5424 .set_file_info = smb2_set_file_info,
5425 .set_compression = smb2_set_compression,
5426 .mkdir = smb2_mkdir,
5427 .mkdir_setinfo = smb2_mkdir_setinfo,
5428 .rmdir = smb2_rmdir,
5429 .unlink = smb2_unlink,
5430 .rename = smb2_rename_path,
5431 .create_hardlink = smb2_create_hardlink,
5432 .query_symlink = smb2_query_symlink,
5433 .query_mf_symlink = smb3_query_mf_symlink,
5434 .create_mf_symlink = smb3_create_mf_symlink,
5435 .open = smb2_open_file,
5436 .set_fid = smb2_set_fid,
5437 .close = smb2_close_file,
5438 .flush = smb2_flush_file,
5439 .async_readv = smb2_async_readv,
5440 .async_writev = smb2_async_writev,
5441 .sync_read = smb2_sync_read,
5442 .sync_write = smb2_sync_write,
5443 .query_dir_first = smb2_query_dir_first,
5444 .query_dir_next = smb2_query_dir_next,
5445 .close_dir = smb2_close_dir,
5446 .calc_smb_size = smb2_calc_size,
5447 .is_status_pending = smb2_is_status_pending,
5448 .is_session_expired = smb2_is_session_expired,
5449 .oplock_response = smb2_oplock_response,
5450 .queryfs = smb2_queryfs,
5451 .mand_lock = smb2_mand_lock,
5452 .mand_unlock_range = smb2_unlock_range,
5453 .push_mand_locks = smb2_push_mandatory_locks,
5454 .get_lease_key = smb2_get_lease_key,
5455 .set_lease_key = smb2_set_lease_key,
5456 .new_lease_key = smb2_new_lease_key,
5457 .calc_signature = smb2_calc_signature,
5458 .is_read_op = smb21_is_read_op,
5459 .set_oplock_level = smb21_set_oplock_level,
5460 .create_lease_buf = smb2_create_lease_buf,
5461 .parse_lease_buf = smb2_parse_lease_buf,
5462 .copychunk_range = smb2_copychunk_range,
5463 .wp_retry_size = smb2_wp_retry_size,
5464 .dir_needs_close = smb2_dir_needs_close,
5465 .enum_snapshots = smb3_enum_snapshots,
5466 .notify = smb3_notify,
5467 .get_dfs_refer = smb2_get_dfs_refer,
5468 .select_sectype = smb2_select_sectype,
5469 #ifdef CONFIG_CIFS_XATTR
5470 .query_all_EAs = smb2_query_eas,
5471 .set_EA = smb2_set_ea,
5472 #endif /* CIFS_XATTR */
5473 .get_acl = get_smb2_acl,
5474 .get_acl_by_fid = get_smb2_acl_by_fid,
5475 .set_acl = set_smb2_acl,
5476 .next_header = smb2_next_header,
5477 .ioctl_query_info = smb2_ioctl_query_info,
5478 .make_node = smb2_make_node,
5479 .fiemap = smb3_fiemap,
5480 .llseek = smb3_llseek,
5481 .is_status_io_timeout = smb2_is_status_io_timeout,
5482 .is_network_name_deleted = smb2_is_network_name_deleted,
5485 struct smb_version_operations smb30_operations = {
5486 .compare_fids = smb2_compare_fids,
5487 .setup_request = smb2_setup_request,
5488 .setup_async_request = smb2_setup_async_request,
5489 .check_receive = smb2_check_receive,
5490 .add_credits = smb2_add_credits,
5491 .set_credits = smb2_set_credits,
5492 .get_credits_field = smb2_get_credits_field,
5493 .get_credits = smb2_get_credits,
5494 .wait_mtu_credits = smb2_wait_mtu_credits,
5495 .adjust_credits = smb2_adjust_credits,
5496 .get_next_mid = smb2_get_next_mid,
5497 .revert_current_mid = smb2_revert_current_mid,
5498 .read_data_offset = smb2_read_data_offset,
5499 .read_data_length = smb2_read_data_length,
5500 .map_error = map_smb2_to_linux_error,
5501 .find_mid = smb2_find_mid,
5502 .check_message = smb2_check_message,
5503 .dump_detail = smb2_dump_detail,
5504 .clear_stats = smb2_clear_stats,
5505 .print_stats = smb2_print_stats,
5506 .dump_share_caps = smb2_dump_share_caps,
5507 .is_oplock_break = smb2_is_valid_oplock_break,
5508 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5509 .downgrade_oplock = smb3_downgrade_oplock,
5510 .need_neg = smb2_need_neg,
5511 .negotiate = smb2_negotiate,
5512 .negotiate_wsize = smb3_negotiate_wsize,
5513 .negotiate_rsize = smb3_negotiate_rsize,
5514 .sess_setup = SMB2_sess_setup,
5515 .logoff = SMB2_logoff,
5516 .tree_connect = SMB2_tcon,
5517 .tree_disconnect = SMB2_tdis,
5518 .qfs_tcon = smb3_qfs_tcon,
5519 .is_path_accessible = smb2_is_path_accessible,
5520 .can_echo = smb2_can_echo,
5522 .query_path_info = smb2_query_path_info,
5523 /* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */
5524 .query_reparse_tag = smb2_query_reparse_tag,
5525 .get_srv_inum = smb2_get_srv_inum,
5526 .query_file_info = smb2_query_file_info,
5527 .set_path_size = smb2_set_path_size,
5528 .set_file_size = smb2_set_file_size,
5529 .set_file_info = smb2_set_file_info,
5530 .set_compression = smb2_set_compression,
5531 .mkdir = smb2_mkdir,
5532 .mkdir_setinfo = smb2_mkdir_setinfo,
5533 .rmdir = smb2_rmdir,
5534 .unlink = smb2_unlink,
5535 .rename = smb2_rename_path,
5536 .create_hardlink = smb2_create_hardlink,
5537 .query_symlink = smb2_query_symlink,
5538 .query_mf_symlink = smb3_query_mf_symlink,
5539 .create_mf_symlink = smb3_create_mf_symlink,
5540 .open = smb2_open_file,
5541 .set_fid = smb2_set_fid,
5542 .close = smb2_close_file,
5543 .close_getattr = smb2_close_getattr,
5544 .flush = smb2_flush_file,
5545 .async_readv = smb2_async_readv,
5546 .async_writev = smb2_async_writev,
5547 .sync_read = smb2_sync_read,
5548 .sync_write = smb2_sync_write,
5549 .query_dir_first = smb2_query_dir_first,
5550 .query_dir_next = smb2_query_dir_next,
5551 .close_dir = smb2_close_dir,
5552 .calc_smb_size = smb2_calc_size,
5553 .is_status_pending = smb2_is_status_pending,
5554 .is_session_expired = smb2_is_session_expired,
5555 .oplock_response = smb2_oplock_response,
5556 .queryfs = smb2_queryfs,
5557 .mand_lock = smb2_mand_lock,
5558 .mand_unlock_range = smb2_unlock_range,
5559 .push_mand_locks = smb2_push_mandatory_locks,
5560 .get_lease_key = smb2_get_lease_key,
5561 .set_lease_key = smb2_set_lease_key,
5562 .new_lease_key = smb2_new_lease_key,
5563 .generate_signingkey = generate_smb30signingkey,
5564 .calc_signature = smb3_calc_signature,
5565 .set_integrity = smb3_set_integrity,
5566 .is_read_op = smb21_is_read_op,
5567 .set_oplock_level = smb3_set_oplock_level,
5568 .create_lease_buf = smb3_create_lease_buf,
5569 .parse_lease_buf = smb3_parse_lease_buf,
5570 .copychunk_range = smb2_copychunk_range,
5571 .duplicate_extents = smb2_duplicate_extents,
5572 .validate_negotiate = smb3_validate_negotiate,
5573 .wp_retry_size = smb2_wp_retry_size,
5574 .dir_needs_close = smb2_dir_needs_close,
5575 .fallocate = smb3_fallocate,
5576 .enum_snapshots = smb3_enum_snapshots,
5577 .notify = smb3_notify,
5578 .init_transform_rq = smb3_init_transform_rq,
5579 .is_transform_hdr = smb3_is_transform_hdr,
5580 .receive_transform = smb3_receive_transform,
5581 .get_dfs_refer = smb2_get_dfs_refer,
5582 .select_sectype = smb2_select_sectype,
5583 #ifdef CONFIG_CIFS_XATTR
5584 .query_all_EAs = smb2_query_eas,
5585 .set_EA = smb2_set_ea,
5586 #endif /* CIFS_XATTR */
5587 .get_acl = get_smb2_acl,
5588 .get_acl_by_fid = get_smb2_acl_by_fid,
5589 .set_acl = set_smb2_acl,
5590 .next_header = smb2_next_header,
5591 .ioctl_query_info = smb2_ioctl_query_info,
5592 .make_node = smb2_make_node,
5593 .fiemap = smb3_fiemap,
5594 .llseek = smb3_llseek,
5595 .is_status_io_timeout = smb2_is_status_io_timeout,
5596 .is_network_name_deleted = smb2_is_network_name_deleted,
5599 struct smb_version_operations smb311_operations = {
5600 .compare_fids = smb2_compare_fids,
5601 .setup_request = smb2_setup_request,
5602 .setup_async_request = smb2_setup_async_request,
5603 .check_receive = smb2_check_receive,
5604 .add_credits = smb2_add_credits,
5605 .set_credits = smb2_set_credits,
5606 .get_credits_field = smb2_get_credits_field,
5607 .get_credits = smb2_get_credits,
5608 .wait_mtu_credits = smb2_wait_mtu_credits,
5609 .adjust_credits = smb2_adjust_credits,
5610 .get_next_mid = smb2_get_next_mid,
5611 .revert_current_mid = smb2_revert_current_mid,
5612 .read_data_offset = smb2_read_data_offset,
5613 .read_data_length = smb2_read_data_length,
5614 .map_error = map_smb2_to_linux_error,
5615 .find_mid = smb2_find_mid,
5616 .check_message = smb2_check_message,
5617 .dump_detail = smb2_dump_detail,
5618 .clear_stats = smb2_clear_stats,
5619 .print_stats = smb2_print_stats,
5620 .dump_share_caps = smb2_dump_share_caps,
5621 .is_oplock_break = smb2_is_valid_oplock_break,
5622 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5623 .downgrade_oplock = smb3_downgrade_oplock,
5624 .need_neg = smb2_need_neg,
5625 .negotiate = smb2_negotiate,
5626 .negotiate_wsize = smb3_negotiate_wsize,
5627 .negotiate_rsize = smb3_negotiate_rsize,
5628 .sess_setup = SMB2_sess_setup,
5629 .logoff = SMB2_logoff,
5630 .tree_connect = SMB2_tcon,
5631 .tree_disconnect = SMB2_tdis,
5632 .qfs_tcon = smb3_qfs_tcon,
5633 .is_path_accessible = smb2_is_path_accessible,
5634 .can_echo = smb2_can_echo,
5636 .query_path_info = smb2_query_path_info,
5637 .query_reparse_tag = smb2_query_reparse_tag,
5638 .get_srv_inum = smb2_get_srv_inum,
5639 .query_file_info = smb2_query_file_info,
5640 .set_path_size = smb2_set_path_size,
5641 .set_file_size = smb2_set_file_size,
5642 .set_file_info = smb2_set_file_info,
5643 .set_compression = smb2_set_compression,
5644 .mkdir = smb2_mkdir,
5645 .mkdir_setinfo = smb2_mkdir_setinfo,
5646 .posix_mkdir = smb311_posix_mkdir,
5647 .rmdir = smb2_rmdir,
5648 .unlink = smb2_unlink,
5649 .rename = smb2_rename_path,
5650 .create_hardlink = smb2_create_hardlink,
5651 .query_symlink = smb2_query_symlink,
5652 .query_mf_symlink = smb3_query_mf_symlink,
5653 .create_mf_symlink = smb3_create_mf_symlink,
5654 .open = smb2_open_file,
5655 .set_fid = smb2_set_fid,
5656 .close = smb2_close_file,
5657 .close_getattr = smb2_close_getattr,
5658 .flush = smb2_flush_file,
5659 .async_readv = smb2_async_readv,
5660 .async_writev = smb2_async_writev,
5661 .sync_read = smb2_sync_read,
5662 .sync_write = smb2_sync_write,
5663 .query_dir_first = smb2_query_dir_first,
5664 .query_dir_next = smb2_query_dir_next,
5665 .close_dir = smb2_close_dir,
5666 .calc_smb_size = smb2_calc_size,
5667 .is_status_pending = smb2_is_status_pending,
5668 .is_session_expired = smb2_is_session_expired,
5669 .oplock_response = smb2_oplock_response,
5670 .queryfs = smb311_queryfs,
5671 .mand_lock = smb2_mand_lock,
5672 .mand_unlock_range = smb2_unlock_range,
5673 .push_mand_locks = smb2_push_mandatory_locks,
5674 .get_lease_key = smb2_get_lease_key,
5675 .set_lease_key = smb2_set_lease_key,
5676 .new_lease_key = smb2_new_lease_key,
5677 .generate_signingkey = generate_smb311signingkey,
5678 .calc_signature = smb3_calc_signature,
5679 .set_integrity = smb3_set_integrity,
5680 .is_read_op = smb21_is_read_op,
5681 .set_oplock_level = smb3_set_oplock_level,
5682 .create_lease_buf = smb3_create_lease_buf,
5683 .parse_lease_buf = smb3_parse_lease_buf,
5684 .copychunk_range = smb2_copychunk_range,
5685 .duplicate_extents = smb2_duplicate_extents,
5686 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
5687 .wp_retry_size = smb2_wp_retry_size,
5688 .dir_needs_close = smb2_dir_needs_close,
5689 .fallocate = smb3_fallocate,
5690 .enum_snapshots = smb3_enum_snapshots,
5691 .notify = smb3_notify,
5692 .init_transform_rq = smb3_init_transform_rq,
5693 .is_transform_hdr = smb3_is_transform_hdr,
5694 .receive_transform = smb3_receive_transform,
5695 .get_dfs_refer = smb2_get_dfs_refer,
5696 .select_sectype = smb2_select_sectype,
5697 #ifdef CONFIG_CIFS_XATTR
5698 .query_all_EAs = smb2_query_eas,
5699 .set_EA = smb2_set_ea,
5700 #endif /* CIFS_XATTR */
5701 .get_acl = get_smb2_acl,
5702 .get_acl_by_fid = get_smb2_acl_by_fid,
5703 .set_acl = set_smb2_acl,
5704 .next_header = smb2_next_header,
5705 .ioctl_query_info = smb2_ioctl_query_info,
5706 .make_node = smb2_make_node,
5707 .fiemap = smb3_fiemap,
5708 .llseek = smb3_llseek,
5709 .is_status_io_timeout = smb2_is_status_io_timeout,
5710 .is_network_name_deleted = smb2_is_network_name_deleted,
5713 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5714 struct smb_version_values smb20_values = {
5715 .version_string = SMB20_VERSION_STRING,
5716 .protocol_id = SMB20_PROT_ID,
5717 .req_capabilities = 0, /* MBZ */
5718 .large_lock_type = 0,
5719 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5720 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5721 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5722 .header_size = sizeof(struct smb2_hdr),
5723 .header_preamble_size = 0,
5724 .max_header_size = MAX_SMB2_HDR_SIZE,
5725 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5726 .lock_cmd = SMB2_LOCK,
5728 .cap_nt_find = SMB2_NT_FIND,
5729 .cap_large_files = SMB2_LARGE_FILES,
5730 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5731 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5732 .create_lease_size = sizeof(struct create_lease),
5734 #endif /* ALLOW_INSECURE_LEGACY */
5736 struct smb_version_values smb21_values = {
5737 .version_string = SMB21_VERSION_STRING,
5738 .protocol_id = SMB21_PROT_ID,
5739 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
5740 .large_lock_type = 0,
5741 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5742 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5743 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5744 .header_size = sizeof(struct smb2_hdr),
5745 .header_preamble_size = 0,
5746 .max_header_size = MAX_SMB2_HDR_SIZE,
5747 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5748 .lock_cmd = SMB2_LOCK,
5750 .cap_nt_find = SMB2_NT_FIND,
5751 .cap_large_files = SMB2_LARGE_FILES,
5752 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5753 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5754 .create_lease_size = sizeof(struct create_lease),
5757 struct smb_version_values smb3any_values = {
5758 .version_string = SMB3ANY_VERSION_STRING,
5759 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5760 .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,
5761 .large_lock_type = 0,
5762 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5763 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5764 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5765 .header_size = sizeof(struct smb2_hdr),
5766 .header_preamble_size = 0,
5767 .max_header_size = MAX_SMB2_HDR_SIZE,
5768 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5769 .lock_cmd = SMB2_LOCK,
5771 .cap_nt_find = SMB2_NT_FIND,
5772 .cap_large_files = SMB2_LARGE_FILES,
5773 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5774 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5775 .create_lease_size = sizeof(struct create_lease_v2),
5778 struct smb_version_values smbdefault_values = {
5779 .version_string = SMBDEFAULT_VERSION_STRING,
5780 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5781 .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,
5782 .large_lock_type = 0,
5783 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5784 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5785 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5786 .header_size = sizeof(struct smb2_hdr),
5787 .header_preamble_size = 0,
5788 .max_header_size = MAX_SMB2_HDR_SIZE,
5789 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5790 .lock_cmd = SMB2_LOCK,
5792 .cap_nt_find = SMB2_NT_FIND,
5793 .cap_large_files = SMB2_LARGE_FILES,
5794 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5795 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5796 .create_lease_size = sizeof(struct create_lease_v2),
5799 struct smb_version_values smb30_values = {
5800 .version_string = SMB30_VERSION_STRING,
5801 .protocol_id = SMB30_PROT_ID,
5802 .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,
5803 .large_lock_type = 0,
5804 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5805 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5806 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5807 .header_size = sizeof(struct smb2_hdr),
5808 .header_preamble_size = 0,
5809 .max_header_size = MAX_SMB2_HDR_SIZE,
5810 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5811 .lock_cmd = SMB2_LOCK,
5813 .cap_nt_find = SMB2_NT_FIND,
5814 .cap_large_files = SMB2_LARGE_FILES,
5815 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5816 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5817 .create_lease_size = sizeof(struct create_lease_v2),
5820 struct smb_version_values smb302_values = {
5821 .version_string = SMB302_VERSION_STRING,
5822 .protocol_id = SMB302_PROT_ID,
5823 .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,
5824 .large_lock_type = 0,
5825 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5826 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5827 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5828 .header_size = sizeof(struct smb2_hdr),
5829 .header_preamble_size = 0,
5830 .max_header_size = MAX_SMB2_HDR_SIZE,
5831 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5832 .lock_cmd = SMB2_LOCK,
5834 .cap_nt_find = SMB2_NT_FIND,
5835 .cap_large_files = SMB2_LARGE_FILES,
5836 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5837 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5838 .create_lease_size = sizeof(struct create_lease_v2),
5841 struct smb_version_values smb311_values = {
5842 .version_string = SMB311_VERSION_STRING,
5843 .protocol_id = SMB311_PROT_ID,
5844 .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,
5845 .large_lock_type = 0,
5846 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5847 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5848 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5849 .header_size = sizeof(struct smb2_hdr),
5850 .header_preamble_size = 0,
5851 .max_header_size = MAX_SMB2_HDR_SIZE,
5852 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5853 .lock_cmd = SMB2_LOCK,
5855 .cap_nt_find = SMB2_NT_FIND,
5856 .cap_large_files = SMB2_LARGE_FILES,
5857 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5858 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5859 .create_lease_size = sizeof(struct create_lease_v2),