1 // SPDX-License-Identifier: GPL-2.0
3 * SMB2 version specific operations
5 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
8 #include <linux/pagemap.h>
10 #include <linux/falloc.h>
11 #include <linux/scatterlist.h>
12 #include <linux/uuid.h>
13 #include <linux/sort.h>
14 #include <crypto/aead.h>
15 #include <linux/fiemap.h>
16 #include <uapi/linux/magic.h>
20 #include "smb2proto.h"
21 #include "cifsproto.h"
22 #include "cifs_debug.h"
23 #include "cifs_unicode.h"
24 #include "smb2status.h"
26 #include "cifs_ioctl.h"
27 #include "smbdirect.h"
29 #include "fs_context.h"
30 #include "cached_dir.h"
32 /* Change credits for different ops and return the total number of credits */
34 change_conf(struct TCP_Server_Info *server)
36 server->credits += server->echo_credits + server->oplock_credits;
37 if (server->credits > server->max_credits)
38 server->credits = server->max_credits;
39 server->oplock_credits = server->echo_credits = 0;
40 switch (server->credits) {
44 server->echoes = false;
45 server->oplocks = false;
48 server->echoes = true;
49 server->oplocks = false;
50 server->echo_credits = 1;
53 server->echoes = true;
55 server->oplocks = true;
56 server->oplock_credits = 1;
58 server->oplocks = false;
60 server->echo_credits = 1;
62 server->credits -= server->echo_credits + server->oplock_credits;
63 return server->credits + server->echo_credits + server->oplock_credits;
67 smb2_add_credits(struct TCP_Server_Info *server,
68 const struct cifs_credits *credits, const int optype)
71 int scredits, in_flight;
72 unsigned int add = credits->value;
73 unsigned int instance = credits->instance;
74 bool reconnect_detected = false;
75 bool reconnect_with_invalid_credits = false;
77 spin_lock(&server->req_lock);
78 val = server->ops->get_credits_field(server, optype);
80 /* eg found case where write overlapping reconnect messed up credits */
81 if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0))
82 reconnect_with_invalid_credits = true;
84 if ((instance == 0) || (instance == server->reconnect_instance))
87 reconnect_detected = true;
90 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
91 pr_warn_once("server overflowed SMB3 credits\n");
92 trace_smb3_overflow_credits(server->CurrentMid,
93 server->conn_id, server->hostname, *val,
94 add, server->in_flight);
96 WARN_ON_ONCE(server->in_flight == 0);
98 if (server->in_flight == 0 &&
99 ((optype & CIFS_OP_MASK) != CIFS_NEG_OP) &&
100 ((optype & CIFS_OP_MASK) != CIFS_SESS_OP))
101 rc = change_conf(server);
103 * Sometimes server returns 0 credits on oplock break ack - we need to
104 * rebalance credits in this case.
106 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
108 if (server->credits > 1) {
110 server->oplock_credits++;
114 in_flight = server->in_flight;
115 spin_unlock(&server->req_lock);
116 wake_up(&server->request_q);
118 if (reconnect_detected) {
119 trace_smb3_reconnect_detected(server->CurrentMid,
120 server->conn_id, server->hostname, scredits, add, in_flight);
122 cifs_dbg(FYI, "trying to put %d credits from the old server instance %d\n",
126 if (reconnect_with_invalid_credits) {
127 trace_smb3_reconnect_with_invalid_credits(server->CurrentMid,
128 server->conn_id, server->hostname, scredits, add, in_flight);
129 cifs_dbg(FYI, "Negotiate operation when server credits is non-zero. Optype: %d, server credits: %d, credits added: %d\n",
130 optype, scredits, add);
133 spin_lock(&server->srv_lock);
134 if (server->tcpStatus == CifsNeedReconnect
135 || server->tcpStatus == CifsExiting) {
136 spin_unlock(&server->srv_lock);
139 spin_unlock(&server->srv_lock);
143 /* change_conf hasn't been executed */
146 cifs_server_dbg(VFS, "Possible client or server bug - zero credits\n");
149 cifs_server_dbg(VFS, "disabling echoes and oplocks\n");
152 cifs_dbg(FYI, "disabling oplocks\n");
155 /* change_conf rebalanced credits for different types */
159 trace_smb3_add_credits(server->CurrentMid,
160 server->conn_id, server->hostname, scredits, add, in_flight);
161 cifs_dbg(FYI, "%s: added %u credits total=%d\n", __func__, add, scredits);
165 smb2_set_credits(struct TCP_Server_Info *server, const int val)
167 int scredits, in_flight;
169 spin_lock(&server->req_lock);
170 server->credits = val;
172 server->reconnect_instance++;
173 scredits = server->credits;
174 in_flight = server->in_flight;
175 spin_unlock(&server->req_lock);
177 trace_smb3_set_credits(server->CurrentMid,
178 server->conn_id, server->hostname, scredits, val, in_flight);
179 cifs_dbg(FYI, "%s: set %u credits\n", __func__, val);
181 /* don't log while holding the lock */
183 cifs_dbg(FYI, "set credits to 1 due to smb2 reconnect\n");
187 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
191 return &server->echo_credits;
193 return &server->oplock_credits;
195 return &server->credits;
200 smb2_get_credits(struct mid_q_entry *mid)
202 return mid->credits_received;
206 smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
207 unsigned int *num, struct cifs_credits *credits)
210 unsigned int scredits, in_flight;
212 spin_lock(&server->req_lock);
214 if (server->credits <= 0) {
215 spin_unlock(&server->req_lock);
216 cifs_num_waiters_inc(server);
217 rc = wait_event_killable(server->request_q,
218 has_credits(server, &server->credits, 1));
219 cifs_num_waiters_dec(server);
222 spin_lock(&server->req_lock);
224 spin_unlock(&server->req_lock);
225 spin_lock(&server->srv_lock);
226 if (server->tcpStatus == CifsExiting) {
227 spin_unlock(&server->srv_lock);
230 spin_unlock(&server->srv_lock);
232 spin_lock(&server->req_lock);
233 scredits = server->credits;
234 /* can deadlock with reopen */
236 *num = SMB2_MAX_BUFFER_SIZE;
238 credits->instance = 0;
242 /* leave some credits for reopen and other ops */
244 *num = min_t(unsigned int, size,
245 scredits * SMB2_MAX_BUFFER_SIZE);
248 DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
249 credits->instance = server->reconnect_instance;
250 server->credits -= credits->value;
252 if (server->in_flight > server->max_in_flight)
253 server->max_in_flight = server->in_flight;
257 scredits = server->credits;
258 in_flight = server->in_flight;
259 spin_unlock(&server->req_lock);
261 trace_smb3_wait_credits(server->CurrentMid,
262 server->conn_id, server->hostname, scredits, -(credits->value), in_flight);
263 cifs_dbg(FYI, "%s: removed %u credits total=%d\n",
264 __func__, credits->value, scredits);
270 smb2_adjust_credits(struct TCP_Server_Info *server,
271 struct cifs_credits *credits,
272 const unsigned int payload_size)
274 int new_val = DIV_ROUND_UP(payload_size, SMB2_MAX_BUFFER_SIZE);
275 int scredits, in_flight;
277 if (!credits->value || credits->value == new_val)
280 if (credits->value < new_val) {
281 trace_smb3_too_many_credits(server->CurrentMid,
282 server->conn_id, server->hostname, 0, credits->value - new_val, 0);
283 cifs_server_dbg(VFS, "request has less credits (%d) than required (%d)",
284 credits->value, new_val);
289 spin_lock(&server->req_lock);
291 if (server->reconnect_instance != credits->instance) {
292 scredits = server->credits;
293 in_flight = server->in_flight;
294 spin_unlock(&server->req_lock);
296 trace_smb3_reconnect_detected(server->CurrentMid,
297 server->conn_id, server->hostname, scredits,
298 credits->value - new_val, in_flight);
299 cifs_server_dbg(VFS, "trying to return %d credits to old session\n",
300 credits->value - new_val);
304 server->credits += credits->value - new_val;
305 scredits = server->credits;
306 in_flight = server->in_flight;
307 spin_unlock(&server->req_lock);
308 wake_up(&server->request_q);
310 trace_smb3_adj_credits(server->CurrentMid,
311 server->conn_id, server->hostname, scredits,
312 credits->value - new_val, in_flight);
313 cifs_dbg(FYI, "%s: adjust added %u credits total=%d\n",
314 __func__, credits->value - new_val, scredits);
316 credits->value = new_val;
322 smb2_get_next_mid(struct TCP_Server_Info *server)
325 /* for SMB2 we need the current value */
326 spin_lock(&server->mid_lock);
327 mid = server->CurrentMid++;
328 spin_unlock(&server->mid_lock);
333 smb2_revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
335 spin_lock(&server->mid_lock);
336 if (server->CurrentMid >= val)
337 server->CurrentMid -= val;
338 spin_unlock(&server->mid_lock);
341 static struct mid_q_entry *
342 __smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue)
344 struct mid_q_entry *mid;
345 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
346 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
348 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
349 cifs_server_dbg(VFS, "Encrypted frame parsing not supported yet\n");
353 spin_lock(&server->mid_lock);
354 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
355 if ((mid->mid == wire_mid) &&
356 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
357 (mid->command == shdr->Command)) {
358 kref_get(&mid->refcount);
360 list_del_init(&mid->qhead);
361 mid->mid_flags |= MID_DELETED;
363 spin_unlock(&server->mid_lock);
367 spin_unlock(&server->mid_lock);
371 static struct mid_q_entry *
372 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
374 return __smb2_find_mid(server, buf, false);
377 static struct mid_q_entry *
378 smb2_find_dequeue_mid(struct TCP_Server_Info *server, char *buf)
380 return __smb2_find_mid(server, buf, true);
384 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
386 #ifdef CONFIG_CIFS_DEBUG2
387 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
389 cifs_server_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
390 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
391 shdr->Id.SyncId.ProcessId);
392 cifs_server_dbg(VFS, "smb buf %p len %u\n", buf,
393 server->ops->calc_smb_size(buf));
398 smb2_need_neg(struct TCP_Server_Info *server)
400 return server->max_read == 0;
404 smb2_negotiate(const unsigned int xid,
405 struct cifs_ses *ses,
406 struct TCP_Server_Info *server)
410 spin_lock(&server->mid_lock);
411 server->CurrentMid = 0;
412 spin_unlock(&server->mid_lock);
413 rc = SMB2_negotiate(xid, ses, server);
414 /* BB we probably don't need to retry with modern servers */
421 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
423 struct TCP_Server_Info *server = tcon->ses->server;
426 /* start with specified wsize, or default */
427 wsize = ctx->wsize ? ctx->wsize : CIFS_DEFAULT_IOSIZE;
428 wsize = min_t(unsigned int, wsize, server->max_write);
429 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
430 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
436 smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
438 struct TCP_Server_Info *server = tcon->ses->server;
441 /* start with specified wsize, or default */
442 wsize = ctx->wsize ? ctx->wsize : SMB3_DEFAULT_IOSIZE;
443 wsize = min_t(unsigned int, wsize, server->max_write);
444 #ifdef CONFIG_CIFS_SMB_DIRECT
448 * Account for SMB2 data transfer packet header and
449 * possible encryption header
451 wsize = min_t(unsigned int,
453 server->smbd_conn->max_fragmented_send_size -
454 SMB2_READWRITE_PDU_HEADER_SIZE -
455 sizeof(struct smb2_transform_hdr));
457 wsize = min_t(unsigned int,
458 wsize, server->smbd_conn->max_readwrite_size);
461 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
462 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
468 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
470 struct TCP_Server_Info *server = tcon->ses->server;
473 /* start with specified rsize, or default */
474 rsize = ctx->rsize ? ctx->rsize : CIFS_DEFAULT_IOSIZE;
475 rsize = min_t(unsigned int, rsize, server->max_read);
477 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
478 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
484 smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
486 struct TCP_Server_Info *server = tcon->ses->server;
489 /* start with specified rsize, or default */
490 rsize = ctx->rsize ? ctx->rsize : SMB3_DEFAULT_IOSIZE;
491 rsize = min_t(unsigned int, rsize, server->max_read);
492 #ifdef CONFIG_CIFS_SMB_DIRECT
496 * Account for SMB2 data transfer packet header and
497 * possible encryption header
499 rsize = min_t(unsigned int,
501 server->smbd_conn->max_fragmented_recv_size -
502 SMB2_READWRITE_PDU_HEADER_SIZE -
503 sizeof(struct smb2_transform_hdr));
505 rsize = min_t(unsigned int,
506 rsize, server->smbd_conn->max_readwrite_size);
510 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
511 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
517 * compare two interfaces a and b
518 * return 0 if everything matches.
519 * return 1 if a is rdma capable, or rss capable, or has higher link speed
520 * return -1 otherwise.
523 iface_cmp(struct cifs_server_iface *a, struct cifs_server_iface *b)
528 if (a->rdma_capable == b->rdma_capable) {
529 if (a->rss_capable == b->rss_capable) {
530 if (a->speed == b->speed) {
531 cmp_ret = cifs_ipaddr_cmp((struct sockaddr *) &a->sockaddr,
532 (struct sockaddr *) &b->sockaddr);
535 else if (cmp_ret > 0)
539 } else if (a->speed > b->speed)
543 } else if (a->rss_capable > b->rss_capable)
547 } else if (a->rdma_capable > b->rdma_capable)
554 parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
555 size_t buf_len, struct cifs_ses *ses, bool in_mount)
557 struct network_interface_info_ioctl_rsp *p;
558 struct sockaddr_in *addr4;
559 struct sockaddr_in6 *addr6;
560 struct iface_info_ipv4 *p4;
561 struct iface_info_ipv6 *p6;
562 struct cifs_server_iface *info = NULL, *iface = NULL, *niface = NULL;
563 struct cifs_server_iface tmp_iface;
569 bytes_left = buf_len;
572 spin_lock(&ses->iface_lock);
573 /* do not query too frequently, this time with lock held */
574 if (ses->iface_last_update &&
575 time_before(jiffies, ses->iface_last_update +
576 (SMB_INTERFACE_POLL_INTERVAL * HZ))) {
577 spin_unlock(&ses->iface_lock);
582 * Go through iface_list and do kref_put to remove
583 * any unused ifaces. ifaces in use will be removed
584 * when the last user calls a kref_put on it
586 list_for_each_entry_safe(iface, niface, &ses->iface_list,
588 iface->is_active = 0;
589 kref_put(&iface->refcount, release_iface);
592 spin_unlock(&ses->iface_lock);
595 * Samba server e.g. can return an empty interface list in some cases,
596 * which would only be a problem if we were requesting multichannel
598 if (bytes_left == 0) {
599 /* avoid spamming logs every 10 minutes, so log only in mount */
600 if ((ses->chan_max > 1) && in_mount)
602 "multichannel not available\n"
603 "Empty network interface list returned by server %s\n",
604 ses->server->hostname);
609 while (bytes_left >= sizeof(*p)) {
610 memset(&tmp_iface, 0, sizeof(tmp_iface));
611 tmp_iface.speed = le64_to_cpu(p->LinkSpeed);
612 tmp_iface.rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE) ? 1 : 0;
613 tmp_iface.rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE) ? 1 : 0;
617 * The kernel and wire socket structures have the same
618 * layout and use network byte order but make the
619 * conversion explicit in case either one changes.
622 addr4 = (struct sockaddr_in *)&tmp_iface.sockaddr;
623 p4 = (struct iface_info_ipv4 *)p->Buffer;
624 addr4->sin_family = AF_INET;
625 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
627 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
628 addr4->sin_port = cpu_to_be16(CIFS_PORT);
630 cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
634 addr6 = (struct sockaddr_in6 *)&tmp_iface.sockaddr;
635 p6 = (struct iface_info_ipv6 *)p->Buffer;
636 addr6->sin6_family = AF_INET6;
637 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
639 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
640 addr6->sin6_flowinfo = 0;
641 addr6->sin6_scope_id = 0;
642 addr6->sin6_port = cpu_to_be16(CIFS_PORT);
644 cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
649 "%s: skipping unsupported socket family\n",
655 * The iface_list is assumed to be sorted by speed.
656 * Check if the new interface exists in that list.
657 * NEVER change iface. it could be in use.
658 * Add a new one instead
660 spin_lock(&ses->iface_lock);
661 list_for_each_entry_safe(iface, niface, &ses->iface_list,
663 ret = iface_cmp(iface, &tmp_iface);
665 /* just get a ref so that it doesn't get picked/freed */
666 iface->is_active = 1;
667 kref_get(&iface->refcount);
669 spin_unlock(&ses->iface_lock);
671 } else if (ret < 0) {
672 /* all remaining ifaces are slower */
673 kref_get(&iface->refcount);
677 spin_unlock(&ses->iface_lock);
679 /* no match. insert the entry in the list */
680 info = kmalloc(sizeof(struct cifs_server_iface),
686 memcpy(info, &tmp_iface, sizeof(tmp_iface));
688 /* add this new entry to the list */
689 kref_init(&info->refcount);
692 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, ses->iface_count);
693 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
694 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
695 le32_to_cpu(p->Capability));
697 spin_lock(&ses->iface_lock);
698 if (!list_entry_is_head(iface, &ses->iface_list, iface_head)) {
699 list_add_tail(&info->iface_head, &iface->iface_head);
700 kref_put(&iface->refcount, release_iface);
702 list_add_tail(&info->iface_head, &ses->iface_list);
705 spin_unlock(&ses->iface_lock);
706 ses->iface_last_update = jiffies;
709 next = le32_to_cpu(p->Next);
711 bytes_left -= sizeof(*p);
714 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
719 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
724 /* Azure rounds the buffer size up 8, to a 16 byte boundary */
725 if ((bytes_left > 8) || p->Next)
726 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
729 if (!ses->iface_count) {
739 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon, bool in_mount)
742 unsigned int ret_data_len = 0;
743 struct network_interface_info_ioctl_rsp *out_buf = NULL;
744 struct cifs_ses *ses = tcon->ses;
746 /* do not query too frequently */
747 if (ses->iface_last_update &&
748 time_before(jiffies, ses->iface_last_update +
749 (SMB_INTERFACE_POLL_INTERVAL * HZ)))
752 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
753 FSCTL_QUERY_NETWORK_INTERFACE_INFO,
754 NULL /* no data input */, 0 /* no data input */,
755 CIFSMaxBufSize, (char **)&out_buf, &ret_data_len);
756 if (rc == -EOPNOTSUPP) {
758 "server does not support query network interfaces\n");
760 } else if (rc != 0) {
761 cifs_tcon_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
765 rc = parse_server_interfaces(out_buf, ret_data_len, ses, in_mount);
775 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
776 struct cifs_sb_info *cifs_sb)
779 __le16 srch_path = 0; /* Null - open root of share */
780 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
781 struct cifs_open_parms oparms;
783 struct cached_fid *cfid = NULL;
785 oparms = (struct cifs_open_parms) {
788 .desired_access = FILE_READ_ATTRIBUTES,
789 .disposition = FILE_OPEN,
790 .create_options = cifs_create_options(cifs_sb, 0),
794 rc = open_cached_dir(xid, tcon, "", cifs_sb, false, &cfid);
796 memcpy(&fid, &cfid->fid, sizeof(struct cifs_fid));
798 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
803 SMB3_request_interfaces(xid, tcon, true /* called during mount */);
805 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
806 FS_ATTRIBUTE_INFORMATION);
807 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
808 FS_DEVICE_INFORMATION);
809 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
810 FS_VOLUME_INFORMATION);
811 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
812 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
814 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
816 close_cached_dir(cfid);
820 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
821 struct cifs_sb_info *cifs_sb)
824 __le16 srch_path = 0; /* Null - open root of share */
825 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
826 struct cifs_open_parms oparms;
829 oparms = (struct cifs_open_parms) {
832 .desired_access = FILE_READ_ATTRIBUTES,
833 .disposition = FILE_OPEN,
834 .create_options = cifs_create_options(cifs_sb, 0),
838 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
843 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
844 FS_ATTRIBUTE_INFORMATION);
845 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
846 FS_DEVICE_INFORMATION);
847 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
851 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
852 struct cifs_sb_info *cifs_sb, const char *full_path)
855 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
856 int err_buftype = CIFS_NO_BUFFER;
857 struct cifs_open_parms oparms;
858 struct kvec err_iov = {};
860 struct cached_fid *cfid;
864 rc = open_cached_dir(xid, tcon, full_path, cifs_sb, true, &cfid);
866 if (cfid->has_lease) {
867 close_cached_dir(cfid);
870 close_cached_dir(cfid);
873 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
877 oparms = (struct cifs_open_parms) {
880 .desired_access = FILE_READ_ATTRIBUTES,
881 .disposition = FILE_OPEN,
882 .create_options = cifs_create_options(cifs_sb, 0),
886 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
887 &err_iov, &err_buftype);
889 struct smb2_hdr *hdr = err_iov.iov_base;
891 if (unlikely(!hdr || err_buftype == CIFS_NO_BUFFER))
894 if (rc != -EREMOTE && hdr->Status == STATUS_OBJECT_NAME_INVALID) {
895 rc2 = cifs_inval_name_dfs_link_error(xid, tcon, cifs_sb,
904 if (rc == -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) && cifs_sb &&
905 (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS))
910 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
913 free_rsp_buf(err_buftype, err_iov.iov_base);
918 static int smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
919 struct cifs_sb_info *cifs_sb, const char *full_path,
920 u64 *uniqueid, struct cifs_open_info_data *data)
922 *uniqueid = le64_to_cpu(data->fi.IndexNumber);
926 static int smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
927 struct cifsFileInfo *cfile, struct cifs_open_info_data *data)
929 struct cifs_fid *fid = &cfile->fid;
931 if (cfile->symlink_target) {
932 data->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
933 if (!data->symlink_target)
936 return SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, &data->fi);
939 #ifdef CONFIG_CIFS_XATTR
941 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
942 struct smb2_file_full_ea_info *src, size_t src_size,
943 const unsigned char *ea_name)
946 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
948 size_t buf_size = dst_size;
949 size_t name_len, value_len, user_name_len;
951 while (src_size > 0) {
952 name_len = (size_t)src->ea_name_length;
953 value_len = (size_t)le16_to_cpu(src->ea_value_length);
958 if (src_size < 8 + name_len + 1 + value_len) {
959 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
964 name = &src->ea_data[0];
965 value = &src->ea_data[src->ea_name_length + 1];
968 if (ea_name_len == name_len &&
969 memcmp(ea_name, name, name_len) == 0) {
973 if (dst_size < value_len) {
977 memcpy(dst, value, value_len);
981 /* 'user.' plus a terminating null */
982 user_name_len = 5 + 1 + name_len;
985 /* skip copy - calc size only */
987 } else if (dst_size >= user_name_len) {
988 dst_size -= user_name_len;
989 memcpy(dst, "user.", 5);
991 memcpy(dst, src->ea_data, name_len);
997 /* stop before overrun buffer */
1003 if (!src->next_entry_offset)
1006 if (src_size < le32_to_cpu(src->next_entry_offset)) {
1007 /* stop before overrun buffer */
1011 src_size -= le32_to_cpu(src->next_entry_offset);
1012 src = (void *)((char *)src +
1013 le32_to_cpu(src->next_entry_offset));
1016 /* didn't find the named attribute */
1025 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
1026 const unsigned char *path, const unsigned char *ea_name,
1027 char *ea_data, size_t buf_size,
1028 struct cifs_sb_info *cifs_sb)
1031 struct kvec rsp_iov = {NULL, 0};
1032 int buftype = CIFS_NO_BUFFER;
1033 struct smb2_query_info_rsp *rsp;
1034 struct smb2_file_full_ea_info *info = NULL;
1036 rc = smb2_query_info_compound(xid, tcon, path,
1038 FILE_FULL_EA_INFORMATION,
1041 MAX_SMB2_CREATE_RESPONSE_SIZE -
1042 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1043 &rsp_iov, &buftype, cifs_sb);
1046 * If ea_name is NULL (listxattr) and there are no EAs,
1047 * return 0 as it's not an error. Otherwise, the specified
1048 * ea_name was not found.
1050 if (!ea_name && rc == -ENODATA)
1055 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
1056 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1057 le32_to_cpu(rsp->OutputBufferLength),
1059 sizeof(struct smb2_file_full_ea_info));
1063 info = (struct smb2_file_full_ea_info *)(
1064 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1065 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
1066 le32_to_cpu(rsp->OutputBufferLength), ea_name);
1069 free_rsp_buf(buftype, rsp_iov.iov_base);
1075 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
1076 const char *path, const char *ea_name, const void *ea_value,
1077 const __u16 ea_value_len, const struct nls_table *nls_codepage,
1078 struct cifs_sb_info *cifs_sb)
1080 struct cifs_ses *ses = tcon->ses;
1081 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1082 __le16 *utf16_path = NULL;
1083 int ea_name_len = strlen(ea_name);
1084 int flags = CIFS_CP_CREATE_CLOSE_OP;
1086 struct smb_rqst rqst[3];
1087 int resp_buftype[3];
1088 struct kvec rsp_iov[3];
1089 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1090 struct cifs_open_parms oparms;
1091 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1092 struct cifs_fid fid;
1093 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1094 unsigned int size[1];
1096 struct smb2_file_full_ea_info *ea = NULL;
1097 struct kvec close_iov[1];
1098 struct smb2_query_info_rsp *rsp;
1099 int rc, used_len = 0;
1101 if (smb3_encryption_required(tcon))
1102 flags |= CIFS_TRANSFORM_REQ;
1104 if (ea_name_len > 255)
1107 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1111 memset(rqst, 0, sizeof(rqst));
1112 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1113 memset(rsp_iov, 0, sizeof(rsp_iov));
1115 if (ses->server->ops->query_all_EAs) {
1117 rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1123 /* If we are adding a attribute we should first check
1124 * if there will be enough space available to store
1125 * the new EA. If not we should not add it since we
1126 * would not be able to even read the EAs back.
1128 rc = smb2_query_info_compound(xid, tcon, path,
1130 FILE_FULL_EA_INFORMATION,
1133 MAX_SMB2_CREATE_RESPONSE_SIZE -
1134 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1135 &rsp_iov[1], &resp_buftype[1], cifs_sb);
1137 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1138 used_len = le32_to_cpu(rsp->OutputBufferLength);
1140 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1141 resp_buftype[1] = CIFS_NO_BUFFER;
1142 memset(&rsp_iov[1], 0, sizeof(rsp_iov[1]));
1145 /* Use a fudge factor of 256 bytes in case we collide
1146 * with a different set_EAs command.
1148 if(CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1149 MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 <
1150 used_len + ea_name_len + ea_value_len + 1) {
1158 memset(&open_iov, 0, sizeof(open_iov));
1159 rqst[0].rq_iov = open_iov;
1160 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1162 oparms = (struct cifs_open_parms) {
1165 .desired_access = FILE_WRITE_EA,
1166 .disposition = FILE_OPEN,
1167 .create_options = cifs_create_options(cifs_sb, 0),
1171 rc = SMB2_open_init(tcon, server,
1172 &rqst[0], &oplock, &oparms, utf16_path);
1175 smb2_set_next_command(tcon, &rqst[0]);
1179 memset(&si_iov, 0, sizeof(si_iov));
1180 rqst[1].rq_iov = si_iov;
1181 rqst[1].rq_nvec = 1;
1183 len = sizeof(*ea) + ea_name_len + ea_value_len + 1;
1184 ea = kzalloc(len, GFP_KERNEL);
1190 ea->ea_name_length = ea_name_len;
1191 ea->ea_value_length = cpu_to_le16(ea_value_len);
1192 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
1193 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
1198 rc = SMB2_set_info_init(tcon, server,
1199 &rqst[1], COMPOUND_FID,
1200 COMPOUND_FID, current->tgid,
1201 FILE_FULL_EA_INFORMATION,
1202 SMB2_O_INFO_FILE, 0, data, size);
1205 smb2_set_next_command(tcon, &rqst[1]);
1206 smb2_set_related(&rqst[1]);
1210 memset(&close_iov, 0, sizeof(close_iov));
1211 rqst[2].rq_iov = close_iov;
1212 rqst[2].rq_nvec = 1;
1213 rc = SMB2_close_init(tcon, server,
1214 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1217 smb2_set_related(&rqst[2]);
1219 rc = compound_send_recv(xid, ses, server,
1221 resp_buftype, rsp_iov);
1222 /* no need to bump num_remote_opens because handle immediately closed */
1227 SMB2_open_free(&rqst[0]);
1228 SMB2_set_info_free(&rqst[1]);
1229 SMB2_close_free(&rqst[2]);
1230 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1231 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1232 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1238 smb2_can_echo(struct TCP_Server_Info *server)
1240 return server->echoes;
1244 smb2_clear_stats(struct cifs_tcon *tcon)
1248 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1249 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1250 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1255 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1257 seq_puts(m, "\n\tShare Capabilities:");
1258 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1259 seq_puts(m, " DFS,");
1260 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1261 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1262 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1263 seq_puts(m, " SCALEOUT,");
1264 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1265 seq_puts(m, " CLUSTER,");
1266 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1267 seq_puts(m, " ASYMMETRIC,");
1268 if (tcon->capabilities == 0)
1269 seq_puts(m, " None");
1270 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1271 seq_puts(m, " Aligned,");
1272 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1273 seq_puts(m, " Partition Aligned,");
1274 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1275 seq_puts(m, " SSD,");
1276 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1277 seq_puts(m, " TRIM-support,");
1279 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1280 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1281 if (tcon->perf_sector_size)
1282 seq_printf(m, "\tOptimal sector size: 0x%x",
1283 tcon->perf_sector_size);
1284 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1288 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1290 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1291 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1294 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1295 * totals (requests sent) since those SMBs are per-session not per tcon
1297 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1298 (long long)(tcon->bytes_read),
1299 (long long)(tcon->bytes_written));
1300 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1301 atomic_read(&tcon->num_local_opens),
1302 atomic_read(&tcon->num_remote_opens));
1303 seq_printf(m, "\nTreeConnects: %d total %d failed",
1304 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1305 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1306 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1307 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1308 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1309 seq_printf(m, "\nCreates: %d total %d failed",
1310 atomic_read(&sent[SMB2_CREATE_HE]),
1311 atomic_read(&failed[SMB2_CREATE_HE]));
1312 seq_printf(m, "\nCloses: %d total %d failed",
1313 atomic_read(&sent[SMB2_CLOSE_HE]),
1314 atomic_read(&failed[SMB2_CLOSE_HE]));
1315 seq_printf(m, "\nFlushes: %d total %d failed",
1316 atomic_read(&sent[SMB2_FLUSH_HE]),
1317 atomic_read(&failed[SMB2_FLUSH_HE]));
1318 seq_printf(m, "\nReads: %d total %d failed",
1319 atomic_read(&sent[SMB2_READ_HE]),
1320 atomic_read(&failed[SMB2_READ_HE]));
1321 seq_printf(m, "\nWrites: %d total %d failed",
1322 atomic_read(&sent[SMB2_WRITE_HE]),
1323 atomic_read(&failed[SMB2_WRITE_HE]));
1324 seq_printf(m, "\nLocks: %d total %d failed",
1325 atomic_read(&sent[SMB2_LOCK_HE]),
1326 atomic_read(&failed[SMB2_LOCK_HE]));
1327 seq_printf(m, "\nIOCTLs: %d total %d failed",
1328 atomic_read(&sent[SMB2_IOCTL_HE]),
1329 atomic_read(&failed[SMB2_IOCTL_HE]));
1330 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1331 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1332 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1333 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1334 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1335 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1336 seq_printf(m, "\nQueryInfos: %d total %d failed",
1337 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1338 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1339 seq_printf(m, "\nSetInfos: %d total %d failed",
1340 atomic_read(&sent[SMB2_SET_INFO_HE]),
1341 atomic_read(&failed[SMB2_SET_INFO_HE]));
1342 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1343 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1344 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1348 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1350 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1351 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1353 cfile->fid.persistent_fid = fid->persistent_fid;
1354 cfile->fid.volatile_fid = fid->volatile_fid;
1355 cfile->fid.access = fid->access;
1356 #ifdef CONFIG_CIFS_DEBUG2
1357 cfile->fid.mid = fid->mid;
1358 #endif /* CIFS_DEBUG2 */
1359 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1361 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1362 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1366 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1367 struct cifs_fid *fid)
1369 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1373 smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon,
1374 struct cifsFileInfo *cfile)
1376 struct smb2_file_network_open_info file_inf;
1377 struct inode *inode;
1380 rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid,
1381 cfile->fid.volatile_fid, &file_inf);
1385 inode = d_inode(cfile->dentry);
1387 spin_lock(&inode->i_lock);
1388 CIFS_I(inode)->time = jiffies;
1390 /* Creation time should not need to be updated on close */
1391 if (file_inf.LastWriteTime)
1392 inode->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime);
1393 if (file_inf.ChangeTime)
1394 inode->i_ctime = cifs_NTtimeToUnix(file_inf.ChangeTime);
1395 if (file_inf.LastAccessTime)
1396 inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime);
1399 * i_blocks is not related to (i_size / i_blksize),
1400 * but instead 512 byte (2**9) size is required for
1401 * calculating num blocks.
1403 if (le64_to_cpu(file_inf.AllocationSize) > 4096)
1405 (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9;
1407 /* End of file and Attributes should not have to be updated on close */
1408 spin_unlock(&inode->i_lock);
1412 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1413 u64 persistent_fid, u64 volatile_fid,
1414 struct copychunk_ioctl *pcchunk)
1417 unsigned int ret_data_len;
1418 struct resume_key_req *res_key;
1420 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1421 FSCTL_SRV_REQUEST_RESUME_KEY, NULL, 0 /* no input */,
1422 CIFSMaxBufSize, (char **)&res_key, &ret_data_len);
1424 if (rc == -EOPNOTSUPP) {
1425 pr_warn_once("Server share %s does not support copy range\n", tcon->tree_name);
1426 goto req_res_key_exit;
1428 cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1429 goto req_res_key_exit;
1431 if (ret_data_len < sizeof(struct resume_key_req)) {
1432 cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n");
1434 goto req_res_key_exit;
1436 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1444 struct smb_rqst rqst[3];
1445 struct kvec rsp_iov[3];
1446 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1447 struct kvec qi_iov[1];
1448 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
1449 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1450 struct kvec close_iov[1];
1454 smb2_ioctl_query_info(const unsigned int xid,
1455 struct cifs_tcon *tcon,
1456 struct cifs_sb_info *cifs_sb,
1457 __le16 *path, int is_dir,
1460 struct iqi_vars *vars;
1461 struct smb_rqst *rqst;
1462 struct kvec *rsp_iov;
1463 struct cifs_ses *ses = tcon->ses;
1464 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1465 char __user *arg = (char __user *)p;
1466 struct smb_query_info qi;
1467 struct smb_query_info __user *pqi;
1469 int flags = CIFS_CP_CREATE_CLOSE_OP;
1470 struct smb2_query_info_rsp *qi_rsp = NULL;
1471 struct smb2_ioctl_rsp *io_rsp = NULL;
1472 void *buffer = NULL;
1473 int resp_buftype[3];
1474 struct cifs_open_parms oparms;
1475 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1476 struct cifs_fid fid;
1477 unsigned int size[2];
1479 int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR;
1480 void (*free_req1_func)(struct smb_rqst *r);
1482 vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
1485 rqst = &vars->rqst[0];
1486 rsp_iov = &vars->rsp_iov[0];
1488 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1490 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info))) {
1494 if (qi.output_buffer_length > 1024) {
1499 if (!ses || !server) {
1504 if (smb3_encryption_required(tcon))
1505 flags |= CIFS_TRANSFORM_REQ;
1507 if (qi.output_buffer_length) {
1508 buffer = memdup_user(arg + sizeof(struct smb_query_info), qi.output_buffer_length);
1509 if (IS_ERR(buffer)) {
1510 rc = PTR_ERR(buffer);
1516 rqst[0].rq_iov = &vars->open_iov[0];
1517 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1519 oparms = (struct cifs_open_parms) {
1521 .disposition = FILE_OPEN,
1522 .create_options = cifs_create_options(cifs_sb, create_options),
1526 if (qi.flags & PASSTHRU_FSCTL) {
1527 switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1528 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1529 oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1531 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1532 oparms.desired_access = GENERIC_ALL;
1534 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1535 oparms.desired_access = GENERIC_READ;
1537 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1538 oparms.desired_access = GENERIC_WRITE;
1541 } else if (qi.flags & PASSTHRU_SET_INFO) {
1542 oparms.desired_access = GENERIC_WRITE;
1544 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1547 rc = SMB2_open_init(tcon, server,
1548 &rqst[0], &oplock, &oparms, path);
1550 goto free_output_buffer;
1551 smb2_set_next_command(tcon, &rqst[0]);
1554 if (qi.flags & PASSTHRU_FSCTL) {
1555 /* Can eventually relax perm check since server enforces too */
1556 if (!capable(CAP_SYS_ADMIN)) {
1560 rqst[1].rq_iov = &vars->io_iov[0];
1561 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1563 rc = SMB2_ioctl_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1564 qi.info_type, buffer, qi.output_buffer_length,
1565 CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1566 MAX_SMB2_CLOSE_RESPONSE_SIZE);
1567 free_req1_func = SMB2_ioctl_free;
1568 } else if (qi.flags == PASSTHRU_SET_INFO) {
1569 /* Can eventually relax perm check since server enforces too */
1570 if (!capable(CAP_SYS_ADMIN)) {
1574 if (qi.output_buffer_length < 8) {
1578 rqst[1].rq_iov = &vars->si_iov[0];
1579 rqst[1].rq_nvec = 1;
1581 /* MS-FSCC 2.4.13 FileEndOfFileInformation */
1585 rc = SMB2_set_info_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1586 current->tgid, FILE_END_OF_FILE_INFORMATION,
1587 SMB2_O_INFO_FILE, 0, data, size);
1588 free_req1_func = SMB2_set_info_free;
1589 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1590 rqst[1].rq_iov = &vars->qi_iov[0];
1591 rqst[1].rq_nvec = 1;
1593 rc = SMB2_query_info_init(tcon, server,
1594 &rqst[1], COMPOUND_FID,
1595 COMPOUND_FID, qi.file_info_class,
1596 qi.info_type, qi.additional_information,
1597 qi.input_buffer_length,
1598 qi.output_buffer_length, buffer);
1599 free_req1_func = SMB2_query_info_free;
1600 } else { /* unknown flags */
1601 cifs_tcon_dbg(VFS, "Invalid passthru query flags: 0x%x\n",
1608 smb2_set_next_command(tcon, &rqst[1]);
1609 smb2_set_related(&rqst[1]);
1612 rqst[2].rq_iov = &vars->close_iov[0];
1613 rqst[2].rq_nvec = 1;
1615 rc = SMB2_close_init(tcon, server,
1616 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1619 smb2_set_related(&rqst[2]);
1621 rc = compound_send_recv(xid, ses, server,
1623 resp_buftype, rsp_iov);
1627 /* No need to bump num_remote_opens since handle immediately closed */
1628 if (qi.flags & PASSTHRU_FSCTL) {
1629 pqi = (struct smb_query_info __user *)arg;
1630 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1631 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1632 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1633 if (qi.input_buffer_length > 0 &&
1634 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length
1635 > rsp_iov[1].iov_len) {
1640 if (copy_to_user(&pqi->input_buffer_length,
1641 &qi.input_buffer_length,
1642 sizeof(qi.input_buffer_length))) {
1647 if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1648 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1649 qi.input_buffer_length))
1652 pqi = (struct smb_query_info __user *)arg;
1653 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1654 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1655 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1656 if (copy_to_user(&pqi->input_buffer_length,
1657 &qi.input_buffer_length,
1658 sizeof(qi.input_buffer_length))) {
1663 if (copy_to_user(pqi + 1, qi_rsp->Buffer,
1664 qi.input_buffer_length))
1669 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1670 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1671 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1672 SMB2_close_free(&rqst[2]);
1674 free_req1_func(&rqst[1]);
1676 SMB2_open_free(&rqst[0]);
1685 smb2_copychunk_range(const unsigned int xid,
1686 struct cifsFileInfo *srcfile,
1687 struct cifsFileInfo *trgtfile, u64 src_off,
1688 u64 len, u64 dest_off)
1691 unsigned int ret_data_len;
1692 struct copychunk_ioctl *pcchunk;
1693 struct copychunk_ioctl_rsp *retbuf = NULL;
1694 struct cifs_tcon *tcon;
1695 int chunks_copied = 0;
1696 bool chunk_sizes_updated = false;
1697 ssize_t bytes_written, total_bytes_written = 0;
1699 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1700 if (pcchunk == NULL)
1703 cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
1704 /* Request a key from the server to identify the source of the copy */
1705 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1706 srcfile->fid.persistent_fid,
1707 srcfile->fid.volatile_fid, pcchunk);
1709 /* Note: request_res_key sets res_key null only if rc !=0 */
1713 /* For now array only one chunk long, will make more flexible later */
1714 pcchunk->ChunkCount = cpu_to_le32(1);
1715 pcchunk->Reserved = 0;
1716 pcchunk->Reserved2 = 0;
1718 tcon = tlink_tcon(trgtfile->tlink);
1721 pcchunk->SourceOffset = cpu_to_le64(src_off);
1722 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1724 cpu_to_le32(min_t(u64, len, tcon->max_bytes_chunk));
1726 /* Request server copy to target from src identified by key */
1729 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1730 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1731 (char *)pcchunk, sizeof(struct copychunk_ioctl),
1732 CIFSMaxBufSize, (char **)&retbuf, &ret_data_len);
1735 sizeof(struct copychunk_ioctl_rsp)) {
1736 cifs_tcon_dbg(VFS, "Invalid cchunk response size\n");
1740 if (retbuf->TotalBytesWritten == 0) {
1741 cifs_dbg(FYI, "no bytes copied\n");
1746 * Check if server claimed to write more than we asked
1748 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1749 le32_to_cpu(pcchunk->Length)) {
1750 cifs_tcon_dbg(VFS, "Invalid copy chunk response\n");
1754 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1755 cifs_tcon_dbg(VFS, "Invalid num chunks written\n");
1761 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1762 src_off += bytes_written;
1763 dest_off += bytes_written;
1764 len -= bytes_written;
1765 total_bytes_written += bytes_written;
1767 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1768 le32_to_cpu(retbuf->ChunksWritten),
1769 le32_to_cpu(retbuf->ChunkBytesWritten),
1771 } else if (rc == -EINVAL) {
1772 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1775 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1776 le32_to_cpu(retbuf->ChunksWritten),
1777 le32_to_cpu(retbuf->ChunkBytesWritten),
1778 le32_to_cpu(retbuf->TotalBytesWritten));
1781 * Check if this is the first request using these sizes,
1782 * (ie check if copy succeed once with original sizes
1783 * and check if the server gave us different sizes after
1784 * we already updated max sizes on previous request).
1785 * if not then why is the server returning an error now
1787 if ((chunks_copied != 0) || chunk_sizes_updated)
1790 /* Check that server is not asking us to grow size */
1791 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1792 tcon->max_bytes_chunk)
1793 tcon->max_bytes_chunk =
1794 le32_to_cpu(retbuf->ChunkBytesWritten);
1796 goto cchunk_out; /* server gave us bogus size */
1798 /* No need to change MaxChunks since already set to 1 */
1799 chunk_sizes_updated = true;
1810 return total_bytes_written;
1814 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1815 struct cifs_fid *fid)
1817 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1821 smb2_read_data_offset(char *buf)
1823 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1825 return rsp->DataOffset;
1829 smb2_read_data_length(char *buf, bool in_remaining)
1831 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1834 return le32_to_cpu(rsp->DataRemaining);
1836 return le32_to_cpu(rsp->DataLength);
1841 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1842 struct cifs_io_parms *parms, unsigned int *bytes_read,
1843 char **buf, int *buf_type)
1845 parms->persistent_fid = pfid->persistent_fid;
1846 parms->volatile_fid = pfid->volatile_fid;
1847 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1851 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1852 struct cifs_io_parms *parms, unsigned int *written,
1853 struct kvec *iov, unsigned long nr_segs)
1856 parms->persistent_fid = pfid->persistent_fid;
1857 parms->volatile_fid = pfid->volatile_fid;
1858 return SMB2_write(xid, parms, written, iov, nr_segs);
1861 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1862 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1863 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1865 struct cifsInodeInfo *cifsi;
1868 cifsi = CIFS_I(inode);
1870 /* if file already sparse don't bother setting sparse again */
1871 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1872 return true; /* already sparse */
1874 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1875 return true; /* already not sparse */
1878 * Can't check for sparse support on share the usual way via the
1879 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1880 * since Samba server doesn't set the flag on the share, yet
1881 * supports the set sparse FSCTL and returns sparse correctly
1882 * in the file attributes. If we fail setting sparse though we
1883 * mark that server does not support sparse files for this share
1884 * to avoid repeatedly sending the unsupported fsctl to server
1885 * if the file is repeatedly extended.
1887 if (tcon->broken_sparse_sup)
1890 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1891 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1892 &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
1894 tcon->broken_sparse_sup = true;
1895 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1900 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1902 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1908 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1909 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1911 __le64 eof = cpu_to_le64(size);
1912 struct inode *inode;
1915 * If extending file more than one page make sparse. Many Linux fs
1916 * make files sparse by default when extending via ftruncate
1918 inode = d_inode(cfile->dentry);
1920 if (!set_alloc && (size > inode->i_size + 8192)) {
1921 __u8 set_sparse = 1;
1923 /* whether set sparse succeeds or not, extend the file */
1924 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1927 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1928 cfile->fid.volatile_fid, cfile->pid, &eof);
1932 smb2_duplicate_extents(const unsigned int xid,
1933 struct cifsFileInfo *srcfile,
1934 struct cifsFileInfo *trgtfile, u64 src_off,
1935 u64 len, u64 dest_off)
1938 unsigned int ret_data_len;
1939 struct inode *inode;
1940 struct duplicate_extents_to_file dup_ext_buf;
1941 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1943 /* server fileays advertise duplicate extent support with this flag */
1944 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1945 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1948 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1949 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1950 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1951 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1952 dup_ext_buf.ByteCount = cpu_to_le64(len);
1953 cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
1954 src_off, dest_off, len);
1956 inode = d_inode(trgtfile->dentry);
1957 if (inode->i_size < dest_off + len) {
1958 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1960 goto duplicate_extents_out;
1963 * Although also could set plausible allocation size (i_blocks)
1964 * here in addition to setting the file size, in reflink
1965 * it is likely that the target file is sparse. Its allocation
1966 * size will be queried on next revalidate, but it is important
1967 * to make sure that file's cached size is updated immediately
1969 cifs_setsize(inode, dest_off + len);
1971 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1972 trgtfile->fid.volatile_fid,
1973 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1974 (char *)&dup_ext_buf,
1975 sizeof(struct duplicate_extents_to_file),
1976 CIFSMaxBufSize, NULL,
1979 if (ret_data_len > 0)
1980 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
1982 duplicate_extents_out:
1987 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1988 struct cifsFileInfo *cfile)
1990 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1991 cfile->fid.volatile_fid);
1995 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
1996 struct cifsFileInfo *cfile)
1998 struct fsctl_set_integrity_information_req integr_info;
1999 unsigned int ret_data_len;
2001 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
2002 integr_info.Flags = 0;
2003 integr_info.Reserved = 0;
2005 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2006 cfile->fid.volatile_fid,
2007 FSCTL_SET_INTEGRITY_INFORMATION,
2008 (char *)&integr_info,
2009 sizeof(struct fsctl_set_integrity_information_req),
2010 CIFSMaxBufSize, NULL,
2015 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
2016 #define GMT_TOKEN_SIZE 50
2018 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
2021 * Input buffer contains (empty) struct smb_snapshot array with size filled in
2022 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
2025 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
2026 struct cifsFileInfo *cfile, void __user *ioc_buf)
2028 char *retbuf = NULL;
2029 unsigned int ret_data_len = 0;
2031 u32 max_response_size;
2032 struct smb_snapshot_array snapshot_in;
2035 * On the first query to enumerate the list of snapshots available
2036 * for this volume the buffer begins with 0 (number of snapshots
2037 * which can be returned is zero since at that point we do not know
2038 * how big the buffer needs to be). On the second query,
2039 * it (ret_data_len) is set to number of snapshots so we can
2040 * know to set the maximum response size larger (see below).
2042 if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
2046 * Note that for snapshot queries that servers like Azure expect that
2047 * the first query be minimal size (and just used to get the number/size
2048 * of previous versions) so response size must be specified as EXACTLY
2049 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
2052 if (ret_data_len == 0)
2053 max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
2055 max_response_size = CIFSMaxBufSize;
2057 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2058 cfile->fid.volatile_fid,
2059 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
2060 NULL, 0 /* no input data */, max_response_size,
2063 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
2068 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
2070 if (copy_from_user(&snapshot_in, ioc_buf,
2071 sizeof(struct smb_snapshot_array))) {
2078 * Check for min size, ie not large enough to fit even one GMT
2079 * token (snapshot). On the first ioctl some users may pass in
2080 * smaller size (or zero) to simply get the size of the array
2081 * so the user space caller can allocate sufficient memory
2082 * and retry the ioctl again with larger array size sufficient
2083 * to hold all of the snapshot GMT tokens on the second try.
2085 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
2086 ret_data_len = sizeof(struct smb_snapshot_array);
2089 * We return struct SRV_SNAPSHOT_ARRAY, followed by
2090 * the snapshot array (of 50 byte GMT tokens) each
2091 * representing an available previous version of the data
2093 if (ret_data_len > (snapshot_in.snapshot_array_size +
2094 sizeof(struct smb_snapshot_array)))
2095 ret_data_len = snapshot_in.snapshot_array_size +
2096 sizeof(struct smb_snapshot_array);
2098 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
2109 smb3_notify(const unsigned int xid, struct file *pfile,
2110 void __user *ioc_buf, bool return_changes)
2112 struct smb3_notify_info notify;
2113 struct smb3_notify_info __user *pnotify_buf;
2114 struct dentry *dentry = pfile->f_path.dentry;
2115 struct inode *inode = file_inode(pfile);
2116 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2117 struct cifs_open_parms oparms;
2118 struct cifs_fid fid;
2119 struct cifs_tcon *tcon;
2120 const unsigned char *path;
2121 char *returned_ioctl_info = NULL;
2122 void *page = alloc_dentry_path();
2123 __le16 *utf16_path = NULL;
2124 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2128 path = build_path_from_dentry(dentry, page);
2134 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2135 if (utf16_path == NULL) {
2140 if (return_changes) {
2141 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify_info))) {
2146 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify))) {
2150 notify.data_len = 0;
2153 tcon = cifs_sb_master_tcon(cifs_sb);
2154 oparms = (struct cifs_open_parms) {
2157 .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
2158 .disposition = FILE_OPEN,
2159 .create_options = cifs_create_options(cifs_sb, 0),
2163 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
2168 rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid,
2169 notify.watch_tree, notify.completion_filter,
2170 notify.data_len, &returned_ioctl_info, &ret_len);
2172 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2174 cifs_dbg(FYI, "change notify for path %s rc %d\n", path, rc);
2175 if (return_changes && (ret_len > 0) && (notify.data_len > 0)) {
2176 if (ret_len > notify.data_len)
2177 ret_len = notify.data_len;
2178 pnotify_buf = (struct smb3_notify_info __user *)ioc_buf;
2179 if (copy_to_user(pnotify_buf->notify_data, returned_ioctl_info, ret_len))
2181 else if (copy_to_user(&pnotify_buf->data_len, &ret_len, sizeof(ret_len)))
2184 kfree(returned_ioctl_info);
2186 free_dentry_path(page);
2192 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
2193 const char *path, struct cifs_sb_info *cifs_sb,
2194 struct cifs_fid *fid, __u16 search_flags,
2195 struct cifs_search_info *srch_inf)
2198 struct smb_rqst rqst[2];
2199 struct kvec rsp_iov[2];
2200 int resp_buftype[2];
2201 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2202 struct kvec qd_iov[SMB2_QUERY_DIRECTORY_IOV_SIZE];
2204 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2205 struct cifs_open_parms oparms;
2206 struct smb2_query_directory_rsp *qd_rsp = NULL;
2207 struct smb2_create_rsp *op_rsp = NULL;
2208 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2209 int retry_count = 0;
2211 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2215 if (smb3_encryption_required(tcon))
2216 flags |= CIFS_TRANSFORM_REQ;
2218 memset(rqst, 0, sizeof(rqst));
2219 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
2220 memset(rsp_iov, 0, sizeof(rsp_iov));
2223 memset(&open_iov, 0, sizeof(open_iov));
2224 rqst[0].rq_iov = open_iov;
2225 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2227 oparms = (struct cifs_open_parms) {
2230 .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
2231 .disposition = FILE_OPEN,
2232 .create_options = cifs_create_options(cifs_sb, 0),
2236 rc = SMB2_open_init(tcon, server,
2237 &rqst[0], &oplock, &oparms, utf16_path);
2240 smb2_set_next_command(tcon, &rqst[0]);
2242 /* Query directory */
2243 srch_inf->entries_in_buffer = 0;
2244 srch_inf->index_of_last_entry = 2;
2246 memset(&qd_iov, 0, sizeof(qd_iov));
2247 rqst[1].rq_iov = qd_iov;
2248 rqst[1].rq_nvec = SMB2_QUERY_DIRECTORY_IOV_SIZE;
2250 rc = SMB2_query_directory_init(xid, tcon, server,
2252 COMPOUND_FID, COMPOUND_FID,
2253 0, srch_inf->info_level);
2257 smb2_set_related(&rqst[1]);
2260 rc = compound_send_recv(xid, tcon->ses, server,
2262 resp_buftype, rsp_iov);
2264 if (rc == -EAGAIN && retry_count++ < 10)
2267 /* If the open failed there is nothing to do */
2268 op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
2269 if (op_rsp == NULL || op_rsp->hdr.Status != STATUS_SUCCESS) {
2270 cifs_dbg(FYI, "query_dir_first: open failed rc=%d\n", rc);
2273 fid->persistent_fid = op_rsp->PersistentFileId;
2274 fid->volatile_fid = op_rsp->VolatileFileId;
2276 /* Anything else than ENODATA means a genuine error */
2277 if (rc && rc != -ENODATA) {
2278 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2279 cifs_dbg(FYI, "query_dir_first: query directory failed rc=%d\n", rc);
2280 trace_smb3_query_dir_err(xid, fid->persistent_fid,
2281 tcon->tid, tcon->ses->Suid, 0, 0, rc);
2285 atomic_inc(&tcon->num_remote_opens);
2287 qd_rsp = (struct smb2_query_directory_rsp *)rsp_iov[1].iov_base;
2288 if (qd_rsp->hdr.Status == STATUS_NO_MORE_FILES) {
2289 trace_smb3_query_dir_done(xid, fid->persistent_fid,
2290 tcon->tid, tcon->ses->Suid, 0, 0);
2291 srch_inf->endOfSearch = true;
2296 rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1],
2299 trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid,
2300 tcon->ses->Suid, 0, 0, rc);
2303 resp_buftype[1] = CIFS_NO_BUFFER;
2305 trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid,
2306 tcon->ses->Suid, 0, srch_inf->entries_in_buffer);
2310 SMB2_open_free(&rqst[0]);
2311 SMB2_query_directory_free(&rqst[1]);
2312 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2313 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2318 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
2319 struct cifs_fid *fid, __u16 search_flags,
2320 struct cifs_search_info *srch_inf)
2322 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
2323 fid->volatile_fid, 0, srch_inf);
2327 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
2328 struct cifs_fid *fid)
2330 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2334 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2335 * the number of credits and return true. Otherwise - return false.
2338 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
2340 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2341 int scredits, in_flight;
2343 if (shdr->Status != STATUS_PENDING)
2346 if (shdr->CreditRequest) {
2347 spin_lock(&server->req_lock);
2348 server->credits += le16_to_cpu(shdr->CreditRequest);
2349 scredits = server->credits;
2350 in_flight = server->in_flight;
2351 spin_unlock(&server->req_lock);
2352 wake_up(&server->request_q);
2354 trace_smb3_pend_credits(server->CurrentMid,
2355 server->conn_id, server->hostname, scredits,
2356 le16_to_cpu(shdr->CreditRequest), in_flight);
2357 cifs_dbg(FYI, "%s: status pending add %u credits total=%d\n",
2358 __func__, le16_to_cpu(shdr->CreditRequest), scredits);
2365 smb2_is_session_expired(char *buf)
2367 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2369 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
2370 shdr->Status != STATUS_USER_SESSION_DELETED)
2373 trace_smb3_ses_expired(le32_to_cpu(shdr->Id.SyncId.TreeId),
2374 le64_to_cpu(shdr->SessionId),
2375 le16_to_cpu(shdr->Command),
2376 le64_to_cpu(shdr->MessageId));
2377 cifs_dbg(FYI, "Session expired or deleted\n");
2383 smb2_is_status_io_timeout(char *buf)
2385 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2387 if (shdr->Status == STATUS_IO_TIMEOUT)
2394 smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server)
2396 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2397 struct TCP_Server_Info *pserver;
2398 struct cifs_ses *ses;
2399 struct cifs_tcon *tcon;
2401 if (shdr->Status != STATUS_NETWORK_NAME_DELETED)
2404 /* If server is a channel, select the primary channel */
2405 pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
2407 spin_lock(&cifs_tcp_ses_lock);
2408 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
2409 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
2410 if (tcon->tid == le32_to_cpu(shdr->Id.SyncId.TreeId)) {
2411 spin_lock(&tcon->tc_lock);
2412 tcon->need_reconnect = true;
2413 spin_unlock(&tcon->tc_lock);
2414 spin_unlock(&cifs_tcp_ses_lock);
2415 pr_warn_once("Server share %s deleted.\n",
2421 spin_unlock(&cifs_tcp_ses_lock);
2425 smb2_oplock_response(struct cifs_tcon *tcon, __u64 persistent_fid,
2426 __u64 volatile_fid, __u16 net_fid, struct cifsInodeInfo *cinode)
2428 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
2429 return SMB2_lease_break(0, tcon, cinode->lease_key,
2430 smb2_get_lease_state(cinode));
2432 return SMB2_oplock_break(0, tcon, persistent_fid, volatile_fid,
2433 CIFS_CACHE_READ(cinode) ? 1 : 0);
2437 smb2_set_related(struct smb_rqst *rqst)
2439 struct smb2_hdr *shdr;
2441 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2443 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2446 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2449 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
2452 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
2454 struct smb2_hdr *shdr;
2455 struct cifs_ses *ses = tcon->ses;
2456 struct TCP_Server_Info *server = ses->server;
2457 unsigned long len = smb_rqst_len(server, rqst);
2460 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2462 cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2466 /* SMB headers in a compound are 8 byte aligned. */
2468 /* No padding needed */
2472 num_padding = 8 - (len & 7);
2473 if (!smb3_encryption_required(tcon)) {
2475 * If we do not have encryption then we can just add an extra
2476 * iov for the padding.
2478 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2479 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2484 * We can not add a small padding iov for the encryption case
2485 * because the encryption framework can not handle the padding
2487 * We have to flatten this into a single buffer and add
2488 * the padding to it.
2490 for (i = 1; i < rqst->rq_nvec; i++) {
2491 memcpy(rqst->rq_iov[0].iov_base +
2492 rqst->rq_iov[0].iov_len,
2493 rqst->rq_iov[i].iov_base,
2494 rqst->rq_iov[i].iov_len);
2495 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2497 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2499 rqst->rq_iov[0].iov_len += num_padding;
2505 shdr->NextCommand = cpu_to_le32(len);
2509 * Passes the query info response back to the caller on success.
2510 * Caller need to free this with free_rsp_buf().
2513 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2514 const char *path, u32 desired_access,
2515 u32 class, u32 type, u32 output_len,
2516 struct kvec *rsp, int *buftype,
2517 struct cifs_sb_info *cifs_sb)
2519 struct cifs_ses *ses = tcon->ses;
2520 struct TCP_Server_Info *server = cifs_pick_channel(ses);
2521 int flags = CIFS_CP_CREATE_CLOSE_OP;
2522 struct smb_rqst rqst[3];
2523 int resp_buftype[3];
2524 struct kvec rsp_iov[3];
2525 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2526 struct kvec qi_iov[1];
2527 struct kvec close_iov[1];
2528 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2529 struct cifs_open_parms oparms;
2530 struct cifs_fid fid;
2533 struct cached_fid *cfid = NULL;
2537 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2541 if (smb3_encryption_required(tcon))
2542 flags |= CIFS_TRANSFORM_REQ;
2544 memset(rqst, 0, sizeof(rqst));
2545 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2546 memset(rsp_iov, 0, sizeof(rsp_iov));
2549 * We can only call this for things we know are directories.
2551 if (!strcmp(path, ""))
2552 open_cached_dir(xid, tcon, path, cifs_sb, false,
2553 &cfid); /* cfid null if open dir failed */
2555 memset(&open_iov, 0, sizeof(open_iov));
2556 rqst[0].rq_iov = open_iov;
2557 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2559 oparms = (struct cifs_open_parms) {
2562 .desired_access = desired_access,
2563 .disposition = FILE_OPEN,
2564 .create_options = cifs_create_options(cifs_sb, 0),
2568 rc = SMB2_open_init(tcon, server,
2569 &rqst[0], &oplock, &oparms, utf16_path);
2572 smb2_set_next_command(tcon, &rqst[0]);
2574 memset(&qi_iov, 0, sizeof(qi_iov));
2575 rqst[1].rq_iov = qi_iov;
2576 rqst[1].rq_nvec = 1;
2579 rc = SMB2_query_info_init(tcon, server,
2581 cfid->fid.persistent_fid,
2582 cfid->fid.volatile_fid,
2587 rc = SMB2_query_info_init(tcon, server,
2598 smb2_set_next_command(tcon, &rqst[1]);
2599 smb2_set_related(&rqst[1]);
2602 memset(&close_iov, 0, sizeof(close_iov));
2603 rqst[2].rq_iov = close_iov;
2604 rqst[2].rq_nvec = 1;
2606 rc = SMB2_close_init(tcon, server,
2607 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2610 smb2_set_related(&rqst[2]);
2613 rc = compound_send_recv(xid, ses, server,
2615 &resp_buftype[1], &rsp_iov[1]);
2617 rc = compound_send_recv(xid, ses, server,
2619 resp_buftype, rsp_iov);
2622 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2623 if (rc == -EREMCHG) {
2624 tcon->need_reconnect = true;
2625 pr_warn_once("server share %s deleted\n",
2631 *buftype = resp_buftype[1];
2635 SMB2_open_free(&rqst[0]);
2636 SMB2_query_info_free(&rqst[1]);
2637 SMB2_close_free(&rqst[2]);
2638 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2639 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2641 close_cached_dir(cfid);
2646 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2647 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2649 struct smb2_query_info_rsp *rsp;
2650 struct smb2_fs_full_size_info *info = NULL;
2651 struct kvec rsp_iov = {NULL, 0};
2652 int buftype = CIFS_NO_BUFFER;
2656 rc = smb2_query_info_compound(xid, tcon, "",
2657 FILE_READ_ATTRIBUTES,
2658 FS_FULL_SIZE_INFORMATION,
2659 SMB2_O_INFO_FILESYSTEM,
2660 sizeof(struct smb2_fs_full_size_info),
2661 &rsp_iov, &buftype, cifs_sb);
2665 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2666 buf->f_type = SMB2_SUPER_MAGIC;
2667 info = (struct smb2_fs_full_size_info *)(
2668 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2669 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2670 le32_to_cpu(rsp->OutputBufferLength),
2672 sizeof(struct smb2_fs_full_size_info));
2674 smb2_copy_fs_info_to_kstatfs(info, buf);
2677 free_rsp_buf(buftype, rsp_iov.iov_base);
2682 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2683 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2686 __le16 srch_path = 0; /* Null - open root of share */
2687 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2688 struct cifs_open_parms oparms;
2689 struct cifs_fid fid;
2691 if (!tcon->posix_extensions)
2692 return smb2_queryfs(xid, tcon, cifs_sb, buf);
2694 oparms = (struct cifs_open_parms) {
2697 .desired_access = FILE_READ_ATTRIBUTES,
2698 .disposition = FILE_OPEN,
2699 .create_options = cifs_create_options(cifs_sb, 0),
2703 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
2708 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2709 fid.volatile_fid, buf);
2710 buf->f_type = SMB2_SUPER_MAGIC;
2711 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2716 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2718 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2719 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2723 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2724 __u64 length, __u32 type, int lock, int unlock, bool wait)
2726 if (unlock && !lock)
2727 type = SMB2_LOCKFLAG_UNLOCK;
2728 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2729 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2730 current->tgid, length, offset, type, wait);
2734 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2736 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2740 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2742 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2746 smb2_new_lease_key(struct cifs_fid *fid)
2748 generate_random_uuid(fid->lease_key);
2752 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2753 const char *search_name,
2754 struct dfs_info3_param **target_nodes,
2755 unsigned int *num_of_nodes,
2756 const struct nls_table *nls_codepage, int remap)
2759 __le16 *utf16_path = NULL;
2760 int utf16_path_len = 0;
2761 struct cifs_tcon *tcon;
2762 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2763 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2764 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2765 int retry_count = 0;
2767 cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name);
2770 * Try to use the IPC tcon, otherwise just use any
2772 tcon = ses->tcon_ipc;
2774 spin_lock(&cifs_tcp_ses_lock);
2775 tcon = list_first_entry_or_null(&ses->tcon_list,
2780 spin_unlock(&cifs_tcp_ses_lock);
2784 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2790 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2792 nls_codepage, remap);
2798 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2799 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2805 /* Highest DFS referral version understood */
2806 dfs_req->MaxReferralLevel = DFS_VERSION;
2808 /* Path to resolve in an UTF-16 null-terminated string */
2809 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2812 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2813 FSCTL_DFS_GET_REFERRALS,
2814 (char *)dfs_req, dfs_req_size, CIFSMaxBufSize,
2815 (char **)&dfs_rsp, &dfs_rsp_size);
2816 if (!is_retryable_error(rc))
2818 usleep_range(512, 2048);
2819 } while (++retry_count < 5);
2822 if (!is_retryable_error(rc) && rc != -ENOENT && rc != -EOPNOTSUPP)
2823 cifs_tcon_dbg(VFS, "%s: ioctl error: rc=%d\n", __func__, rc);
2827 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
2828 num_of_nodes, target_nodes,
2829 nls_codepage, remap, search_name,
2830 true /* is_unicode */);
2832 cifs_tcon_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc);
2837 if (tcon && !tcon->ipc) {
2838 /* ipc tcons are not refcounted */
2839 spin_lock(&cifs_tcp_ses_lock);
2841 /* tc_count can never go negative */
2842 WARN_ON(tcon->tc_count < 0);
2843 spin_unlock(&cifs_tcp_ses_lock);
2852 parse_reparse_posix(struct reparse_posix_data *symlink_buf,
2853 u32 plen, char **target_path,
2854 struct cifs_sb_info *cifs_sb)
2858 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
2859 len = le16_to_cpu(symlink_buf->ReparseDataLength);
2861 if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
2862 cifs_dbg(VFS, "%lld not a supported symlink type\n",
2863 le64_to_cpu(symlink_buf->InodeType));
2867 *target_path = cifs_strndup_from_utf16(
2868 symlink_buf->PathBuffer,
2869 len, true, cifs_sb->local_nls);
2870 if (!(*target_path))
2873 convert_delimiter(*target_path, '/');
2874 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2880 parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
2881 u32 plen, char **target_path,
2882 struct cifs_sb_info *cifs_sb)
2884 unsigned int sub_len;
2885 unsigned int sub_offset;
2887 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */
2889 sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset);
2890 sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength);
2891 if (sub_offset + 20 > plen ||
2892 sub_offset + sub_len + 20 > plen) {
2893 cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
2897 *target_path = cifs_strndup_from_utf16(
2898 symlink_buf->PathBuffer + sub_offset,
2899 sub_len, true, cifs_sb->local_nls);
2900 if (!(*target_path))
2903 convert_delimiter(*target_path, '/');
2904 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2910 parse_reparse_point(struct reparse_data_buffer *buf,
2911 u32 plen, char **target_path,
2912 struct cifs_sb_info *cifs_sb)
2914 if (plen < sizeof(struct reparse_data_buffer)) {
2915 cifs_dbg(VFS, "reparse buffer is too small. Must be at least 8 bytes but was %d\n",
2920 if (plen < le16_to_cpu(buf->ReparseDataLength) +
2921 sizeof(struct reparse_data_buffer)) {
2922 cifs_dbg(VFS, "srv returned invalid reparse buf length: %d\n",
2927 /* See MS-FSCC 2.1.2 */
2928 switch (le32_to_cpu(buf->ReparseTag)) {
2929 case IO_REPARSE_TAG_NFS:
2930 return parse_reparse_posix(
2931 (struct reparse_posix_data *)buf,
2932 plen, target_path, cifs_sb);
2933 case IO_REPARSE_TAG_SYMLINK:
2934 return parse_reparse_symlink(
2935 (struct reparse_symlink_data_buffer *)buf,
2936 plen, target_path, cifs_sb);
2938 cifs_dbg(VFS, "srv returned unknown symlink buffer tag:0x%08x\n",
2939 le32_to_cpu(buf->ReparseTag));
2945 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
2946 struct cifs_sb_info *cifs_sb, const char *full_path,
2947 char **target_path, bool is_reparse_point)
2950 __le16 *utf16_path = NULL;
2951 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2952 struct cifs_open_parms oparms;
2953 struct cifs_fid fid;
2954 struct kvec err_iov = {NULL, 0};
2955 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2956 int flags = CIFS_CP_CREATE_CLOSE_OP;
2957 struct smb_rqst rqst[3];
2958 int resp_buftype[3];
2959 struct kvec rsp_iov[3];
2960 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2961 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2962 struct kvec close_iov[1];
2963 struct smb2_create_rsp *create_rsp;
2964 struct smb2_ioctl_rsp *ioctl_rsp;
2965 struct reparse_data_buffer *reparse_buf;
2966 int create_options = is_reparse_point ? OPEN_REPARSE_POINT : 0;
2969 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2971 *target_path = NULL;
2973 if (smb3_encryption_required(tcon))
2974 flags |= CIFS_TRANSFORM_REQ;
2976 memset(rqst, 0, sizeof(rqst));
2977 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2978 memset(rsp_iov, 0, sizeof(rsp_iov));
2980 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
2985 memset(&open_iov, 0, sizeof(open_iov));
2986 rqst[0].rq_iov = open_iov;
2987 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2989 oparms = (struct cifs_open_parms) {
2992 .desired_access = FILE_READ_ATTRIBUTES,
2993 .disposition = FILE_OPEN,
2994 .create_options = cifs_create_options(cifs_sb, create_options),
2998 rc = SMB2_open_init(tcon, server,
2999 &rqst[0], &oplock, &oparms, utf16_path);
3002 smb2_set_next_command(tcon, &rqst[0]);
3006 memset(&io_iov, 0, sizeof(io_iov));
3007 rqst[1].rq_iov = io_iov;
3008 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3010 rc = SMB2_ioctl_init(tcon, server,
3011 &rqst[1], fid.persistent_fid,
3012 fid.volatile_fid, FSCTL_GET_REPARSE_POINT, NULL, 0,
3014 MAX_SMB2_CREATE_RESPONSE_SIZE -
3015 MAX_SMB2_CLOSE_RESPONSE_SIZE);
3019 smb2_set_next_command(tcon, &rqst[1]);
3020 smb2_set_related(&rqst[1]);
3024 memset(&close_iov, 0, sizeof(close_iov));
3025 rqst[2].rq_iov = close_iov;
3026 rqst[2].rq_nvec = 1;
3028 rc = SMB2_close_init(tcon, server,
3029 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3033 smb2_set_related(&rqst[2]);
3035 rc = compound_send_recv(xid, tcon->ses, server,
3037 resp_buftype, rsp_iov);
3039 create_rsp = rsp_iov[0].iov_base;
3040 if (create_rsp && create_rsp->hdr.Status)
3041 err_iov = rsp_iov[0];
3042 ioctl_rsp = rsp_iov[1].iov_base;
3045 * Open was successful and we got an ioctl response.
3047 if ((rc == 0) && (is_reparse_point)) {
3048 /* See MS-FSCC 2.3.23 */
3050 reparse_buf = (struct reparse_data_buffer *)
3051 ((char *)ioctl_rsp +
3052 le32_to_cpu(ioctl_rsp->OutputOffset));
3053 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3055 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3056 rsp_iov[1].iov_len) {
3057 cifs_tcon_dbg(VFS, "srv returned invalid ioctl len: %d\n",
3063 rc = parse_reparse_point(reparse_buf, plen, target_path,
3068 if (!rc || !err_iov.iov_base) {
3073 rc = smb2_parse_symlink_response(cifs_sb, &err_iov, target_path);
3076 cifs_dbg(FYI, "query symlink rc %d\n", rc);
3078 SMB2_open_free(&rqst[0]);
3079 SMB2_ioctl_free(&rqst[1]);
3080 SMB2_close_free(&rqst[2]);
3081 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3082 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3083 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3088 smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
3089 struct cifs_sb_info *cifs_sb, const char *full_path,
3093 __le16 *utf16_path = NULL;
3094 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3095 struct cifs_open_parms oparms;
3096 struct cifs_fid fid;
3097 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
3098 int flags = CIFS_CP_CREATE_CLOSE_OP;
3099 struct smb_rqst rqst[3];
3100 int resp_buftype[3];
3101 struct kvec rsp_iov[3];
3102 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
3103 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
3104 struct kvec close_iov[1];
3105 struct smb2_ioctl_rsp *ioctl_rsp;
3106 struct reparse_data_buffer *reparse_buf;
3109 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
3111 if (smb3_encryption_required(tcon))
3112 flags |= CIFS_TRANSFORM_REQ;
3114 memset(rqst, 0, sizeof(rqst));
3115 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
3116 memset(rsp_iov, 0, sizeof(rsp_iov));
3118 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
3123 * setup smb2open - TODO add optimization to call cifs_get_readable_path
3124 * to see if there is a handle already open that we can use
3126 memset(&open_iov, 0, sizeof(open_iov));
3127 rqst[0].rq_iov = open_iov;
3128 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
3130 oparms = (struct cifs_open_parms) {
3133 .desired_access = FILE_READ_ATTRIBUTES,
3134 .disposition = FILE_OPEN,
3135 .create_options = cifs_create_options(cifs_sb, OPEN_REPARSE_POINT),
3139 rc = SMB2_open_init(tcon, server,
3140 &rqst[0], &oplock, &oparms, utf16_path);
3143 smb2_set_next_command(tcon, &rqst[0]);
3147 memset(&io_iov, 0, sizeof(io_iov));
3148 rqst[1].rq_iov = io_iov;
3149 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3151 rc = SMB2_ioctl_init(tcon, server,
3152 &rqst[1], COMPOUND_FID,
3153 COMPOUND_FID, FSCTL_GET_REPARSE_POINT, NULL, 0,
3155 MAX_SMB2_CREATE_RESPONSE_SIZE -
3156 MAX_SMB2_CLOSE_RESPONSE_SIZE);
3160 smb2_set_next_command(tcon, &rqst[1]);
3161 smb2_set_related(&rqst[1]);
3165 memset(&close_iov, 0, sizeof(close_iov));
3166 rqst[2].rq_iov = close_iov;
3167 rqst[2].rq_nvec = 1;
3169 rc = SMB2_close_init(tcon, server,
3170 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3174 smb2_set_related(&rqst[2]);
3176 rc = compound_send_recv(xid, tcon->ses, server,
3178 resp_buftype, rsp_iov);
3180 ioctl_rsp = rsp_iov[1].iov_base;
3183 * Open was successful and we got an ioctl response.
3186 /* See MS-FSCC 2.3.23 */
3188 reparse_buf = (struct reparse_data_buffer *)
3189 ((char *)ioctl_rsp +
3190 le32_to_cpu(ioctl_rsp->OutputOffset));
3191 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3193 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3194 rsp_iov[1].iov_len) {
3195 cifs_tcon_dbg(FYI, "srv returned invalid ioctl len: %d\n",
3200 *tag = le32_to_cpu(reparse_buf->ReparseTag);
3205 SMB2_open_free(&rqst[0]);
3206 SMB2_ioctl_free(&rqst[1]);
3207 SMB2_close_free(&rqst[2]);
3208 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3209 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3210 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3214 static struct cifs_ntsd *
3215 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
3216 const struct cifs_fid *cifsfid, u32 *pacllen, u32 info)
3218 struct cifs_ntsd *pntsd = NULL;
3220 int rc = -EOPNOTSUPP;
3221 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3224 return ERR_CAST(tlink);
3227 cifs_dbg(FYI, "trying to get acl\n");
3229 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
3230 cifsfid->volatile_fid, (void **)&pntsd, pacllen,
3234 cifs_put_tlink(tlink);
3236 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3243 static struct cifs_ntsd *
3244 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
3245 const char *path, u32 *pacllen, u32 info)
3247 struct cifs_ntsd *pntsd = NULL;
3248 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3251 struct cifs_tcon *tcon;
3252 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3253 struct cifs_fid fid;
3254 struct cifs_open_parms oparms;
3257 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
3259 return ERR_CAST(tlink);
3261 tcon = tlink_tcon(tlink);
3264 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3271 oparms = (struct cifs_open_parms) {
3274 .desired_access = READ_CONTROL,
3275 .disposition = FILE_OPEN,
3277 * When querying an ACL, even if the file is a symlink
3278 * we want to open the source not the target, and so
3279 * the protocol requires that the client specify this
3280 * flag when opening a reparse point
3282 .create_options = cifs_create_options(cifs_sb, 0) |
3287 if (info & SACL_SECINFO)
3288 oparms.desired_access |= SYSTEM_SECURITY;
3290 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
3294 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3295 fid.volatile_fid, (void **)&pntsd, pacllen,
3297 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3300 cifs_put_tlink(tlink);
3303 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3310 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
3311 struct inode *inode, const char *path, int aclflag)
3313 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3315 int rc, access_flags = 0;
3316 struct cifs_tcon *tcon;
3317 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
3318 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3319 struct cifs_fid fid;
3320 struct cifs_open_parms oparms;
3323 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
3325 return PTR_ERR(tlink);
3327 tcon = tlink_tcon(tlink);
3330 if (aclflag & CIFS_ACL_OWNER || aclflag & CIFS_ACL_GROUP)
3331 access_flags |= WRITE_OWNER;
3332 if (aclflag & CIFS_ACL_SACL)
3333 access_flags |= SYSTEM_SECURITY;
3334 if (aclflag & CIFS_ACL_DACL)
3335 access_flags |= WRITE_DAC;
3337 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3344 oparms = (struct cifs_open_parms) {
3346 .desired_access = access_flags,
3347 .create_options = cifs_create_options(cifs_sb, 0),
3348 .disposition = FILE_OPEN,
3353 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
3357 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3358 fid.volatile_fid, pnntsd, acllen, aclflag);
3359 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3362 cifs_put_tlink(tlink);
3367 /* Retrieve an ACL from the server */
3368 static struct cifs_ntsd *
3369 get_smb2_acl(struct cifs_sb_info *cifs_sb,
3370 struct inode *inode, const char *path,
3371 u32 *pacllen, u32 info)
3373 struct cifs_ntsd *pntsd = NULL;
3374 struct cifsFileInfo *open_file = NULL;
3376 if (inode && !(info & SACL_SECINFO))
3377 open_file = find_readable_file(CIFS_I(inode), true);
3378 if (!open_file || (info & SACL_SECINFO))
3379 return get_smb2_acl_by_path(cifs_sb, path, pacllen, info);
3381 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen, info);
3382 cifsFileInfo_put(open_file);
3386 static long smb3_zero_data(struct file *file, struct cifs_tcon *tcon,
3387 loff_t offset, loff_t len, unsigned int xid)
3389 struct cifsFileInfo *cfile = file->private_data;
3390 struct file_zero_data_information fsctl_buf;
3392 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3394 fsctl_buf.FileOffset = cpu_to_le64(offset);
3395 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3397 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3398 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3400 sizeof(struct file_zero_data_information),
3404 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3405 loff_t offset, loff_t len, bool keep_size)
3407 struct cifs_ses *ses = tcon->ses;
3408 struct inode *inode = file_inode(file);
3409 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3410 struct cifsFileInfo *cfile = file->private_data;
3417 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3418 ses->Suid, offset, len);
3421 filemap_invalidate_lock(inode->i_mapping);
3424 * We zero the range through ioctl, so we need remove the page caches
3425 * first, otherwise the data may be inconsistent with the server.
3427 truncate_pagecache_range(inode, offset, offset + len - 1);
3429 /* if file not oplocked can't be sure whether asking to extend size */
3431 if (keep_size == false && !CIFS_CACHE_READ(cifsi))
3432 goto zero_range_exit;
3434 rc = smb3_zero_data(file, tcon, offset, len, xid);
3436 goto zero_range_exit;
3439 * do we also need to change the size of the file?
3441 if (keep_size == false && i_size_read(inode) < offset + len) {
3442 eof = cpu_to_le64(offset + len);
3443 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3444 cfile->fid.volatile_fid, cfile->pid, &eof);
3448 filemap_invalidate_unlock(inode->i_mapping);
3449 inode_unlock(inode);
3452 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
3453 ses->Suid, offset, len, rc);
3455 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
3456 ses->Suid, offset, len);
3460 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
3461 loff_t offset, loff_t len)
3463 struct inode *inode = file_inode(file);
3464 struct cifsFileInfo *cfile = file->private_data;
3465 struct file_zero_data_information fsctl_buf;
3468 __u8 set_sparse = 1;
3473 /* Need to make file sparse, if not already, before freeing range. */
3474 /* Consider adding equivalent for compressed since it could also work */
3475 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
3480 filemap_invalidate_lock(inode->i_mapping);
3482 * We implement the punch hole through ioctl, so we need remove the page
3483 * caches first, otherwise the data may be inconsistent with the server.
3485 truncate_pagecache_range(inode, offset, offset + len - 1);
3487 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3489 fsctl_buf.FileOffset = cpu_to_le64(offset);
3490 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3492 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3493 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3495 sizeof(struct file_zero_data_information),
3496 CIFSMaxBufSize, NULL, NULL);
3497 filemap_invalidate_unlock(inode->i_mapping);
3499 inode_unlock(inode);
3504 static int smb3_simple_fallocate_write_range(unsigned int xid,
3505 struct cifs_tcon *tcon,
3506 struct cifsFileInfo *cfile,
3507 loff_t off, loff_t len,
3510 struct cifs_io_parms io_parms = {0};
3515 io_parms.netfid = cfile->fid.netfid;
3516 io_parms.pid = current->tgid;
3517 io_parms.tcon = tcon;
3518 io_parms.persistent_fid = cfile->fid.persistent_fid;
3519 io_parms.volatile_fid = cfile->fid.volatile_fid;
3522 io_parms.offset = off;
3523 io_parms.length = len;
3524 if (io_parms.length > SMB2_MAX_BUFFER_SIZE)
3525 io_parms.length = SMB2_MAX_BUFFER_SIZE;
3526 /* iov[0] is reserved for smb header */
3527 iov[1].iov_base = buf;
3528 iov[1].iov_len = io_parms.length;
3529 rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
3541 static int smb3_simple_fallocate_range(unsigned int xid,
3542 struct cifs_tcon *tcon,
3543 struct cifsFileInfo *cfile,
3544 loff_t off, loff_t len)
3546 struct file_allocated_range_buffer in_data, *out_data = NULL, *tmp_data;
3552 in_data.file_offset = cpu_to_le64(off);
3553 in_data.length = cpu_to_le64(len);
3554 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3555 cfile->fid.volatile_fid,
3556 FSCTL_QUERY_ALLOCATED_RANGES,
3557 (char *)&in_data, sizeof(in_data),
3558 1024 * sizeof(struct file_allocated_range_buffer),
3559 (char **)&out_data, &out_data_len);
3563 buf = kzalloc(1024 * 1024, GFP_KERNEL);
3569 tmp_data = out_data;
3572 * The rest of the region is unmapped so write it all.
3574 if (out_data_len == 0) {
3575 rc = smb3_simple_fallocate_write_range(xid, tcon,
3576 cfile, off, len, buf);
3580 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3585 if (off < le64_to_cpu(tmp_data->file_offset)) {
3587 * We are at a hole. Write until the end of the region
3588 * or until the next allocated data,
3589 * whichever comes next.
3591 l = le64_to_cpu(tmp_data->file_offset) - off;
3594 rc = smb3_simple_fallocate_write_range(xid, tcon,
3595 cfile, off, l, buf);
3604 * We are at a section of allocated data, just skip forward
3605 * until the end of the data or the end of the region
3606 * we are supposed to fallocate, whichever comes first.
3608 l = le64_to_cpu(tmp_data->length);
3614 tmp_data = &tmp_data[1];
3615 out_data_len -= sizeof(struct file_allocated_range_buffer);
3625 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3626 loff_t off, loff_t len, bool keep_size)
3628 struct inode *inode;
3629 struct cifsInodeInfo *cifsi;
3630 struct cifsFileInfo *cfile = file->private_data;
3631 long rc = -EOPNOTSUPP;
3637 inode = d_inode(cfile->dentry);
3638 cifsi = CIFS_I(inode);
3640 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3641 tcon->ses->Suid, off, len);
3642 /* if file not oplocked can't be sure whether asking to extend size */
3643 if (!CIFS_CACHE_READ(cifsi))
3644 if (keep_size == false) {
3645 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3646 tcon->tid, tcon->ses->Suid, off, len, rc);
3652 * Extending the file
3654 if ((keep_size == false) && i_size_read(inode) < off + len) {
3655 rc = inode_newsize_ok(inode, off + len);
3659 if (cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)
3660 smb2_set_sparse(xid, tcon, cfile, inode, false);
3662 eof = cpu_to_le64(off + len);
3663 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3664 cfile->fid.volatile_fid, cfile->pid, &eof);
3666 cifsi->server_eof = off + len;
3667 cifs_setsize(inode, off + len);
3668 cifs_truncate_page(inode->i_mapping, inode->i_size);
3669 truncate_setsize(inode, off + len);
3675 * Files are non-sparse by default so falloc may be a no-op
3676 * Must check if file sparse. If not sparse, and since we are not
3677 * extending then no need to do anything since file already allocated
3679 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
3684 if (keep_size == true) {
3686 * We can not preallocate pages beyond the end of the file
3689 if (off >= i_size_read(inode)) {
3694 * For fallocates that are partially beyond the end of file,
3695 * clamp len so we only fallocate up to the end of file.
3697 if (off + len > i_size_read(inode)) {
3698 len = i_size_read(inode) - off;
3702 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3704 * At this point, we are trying to fallocate an internal
3705 * regions of a sparse file. Since smb2 does not have a
3706 * fallocate command we have two otions on how to emulate this.
3707 * We can either turn the entire file to become non-sparse
3708 * which we only do if the fallocate is for virtually
3709 * the whole file, or we can overwrite the region with zeroes
3710 * using SMB2_write, which could be prohibitevly expensive
3714 * We are only trying to fallocate a small region so
3715 * just write it with zero.
3717 if (len <= 1024 * 1024) {
3718 rc = smb3_simple_fallocate_range(xid, tcon, cfile,
3724 * Check if falloc starts within first few pages of file
3725 * and ends within a few pages of the end of file to
3726 * ensure that most of file is being forced to be
3727 * fallocated now. If so then setting whole file sparse
3728 * ie potentially making a few extra pages at the beginning
3729 * or end of the file non-sparse via set_sparse is harmless.
3731 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
3737 smb2_set_sparse(xid, tcon, cfile, inode, false);
3742 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3743 tcon->ses->Suid, off, len, rc);
3745 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3746 tcon->ses->Suid, off, len);
3752 static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
3753 loff_t off, loff_t len)
3757 struct inode *inode = file_inode(file);
3758 struct cifsFileInfo *cfile = file->private_data;
3759 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3767 old_eof = i_size_read(inode);
3768 if ((off >= old_eof) ||
3769 off + len >= old_eof) {
3774 filemap_invalidate_lock(inode->i_mapping);
3775 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof - 1);
3779 truncate_pagecache_range(inode, off, old_eof);
3781 rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
3782 old_eof - off - len, off);
3786 eof = cpu_to_le64(old_eof - len);
3787 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3788 cfile->fid.volatile_fid, cfile->pid, &eof);
3794 cifsi->server_eof = i_size_read(inode) - len;
3795 truncate_setsize(inode, cifsi->server_eof);
3798 filemap_invalidate_unlock(inode->i_mapping);
3800 inode_unlock(inode);
3805 static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
3806 loff_t off, loff_t len)
3810 struct cifsFileInfo *cfile = file->private_data;
3811 struct inode *inode = file_inode(file);
3813 __u64 count, old_eof;
3819 old_eof = i_size_read(inode);
3820 if (off >= old_eof) {
3825 count = old_eof - off;
3826 eof = cpu_to_le64(old_eof + len);
3828 filemap_invalidate_lock(inode->i_mapping);
3829 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof + len - 1);
3832 truncate_pagecache_range(inode, off, old_eof);
3834 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3835 cfile->fid.volatile_fid, cfile->pid, &eof);
3839 rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len);
3843 rc = smb3_zero_data(file, tcon, off, len, xid);
3849 filemap_invalidate_unlock(inode->i_mapping);
3851 inode_unlock(inode);
3856 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3858 struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3859 struct cifsInodeInfo *cifsi;
3860 struct inode *inode;
3862 struct file_allocated_range_buffer in_data, *out_data = NULL;
3866 if (whence != SEEK_HOLE && whence != SEEK_DATA)
3867 return generic_file_llseek(file, offset, whence);
3869 inode = d_inode(cfile->dentry);
3870 cifsi = CIFS_I(inode);
3872 if (offset < 0 || offset >= i_size_read(inode))
3877 * We need to be sure that all dirty pages are written as they
3878 * might fill holes on the server.
3879 * Note that we also MUST flush any written pages since at least
3880 * some servers (Windows2016) will not reflect recent writes in
3881 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3883 wrcfile = find_writable_file(cifsi, FIND_WR_ANY);
3885 filemap_write_and_wait(inode->i_mapping);
3886 smb2_flush_file(xid, tcon, &wrcfile->fid);
3887 cifsFileInfo_put(wrcfile);
3890 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3891 if (whence == SEEK_HOLE)
3892 offset = i_size_read(inode);
3896 in_data.file_offset = cpu_to_le64(offset);
3897 in_data.length = cpu_to_le64(i_size_read(inode));
3899 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3900 cfile->fid.volatile_fid,
3901 FSCTL_QUERY_ALLOCATED_RANGES,
3902 (char *)&in_data, sizeof(in_data),
3903 sizeof(struct file_allocated_range_buffer),
3904 (char **)&out_data, &out_data_len);
3910 if (whence == SEEK_HOLE && out_data_len == 0)
3913 if (whence == SEEK_DATA && out_data_len == 0) {
3918 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3922 if (whence == SEEK_DATA) {
3923 offset = le64_to_cpu(out_data->file_offset);
3926 if (offset < le64_to_cpu(out_data->file_offset))
3929 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3935 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3940 static int smb3_fiemap(struct cifs_tcon *tcon,
3941 struct cifsFileInfo *cfile,
3942 struct fiemap_extent_info *fei, u64 start, u64 len)
3945 struct file_allocated_range_buffer in_data, *out_data;
3947 int i, num, rc, flags, last_blob;
3950 rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0);
3956 in_data.file_offset = cpu_to_le64(start);
3957 in_data.length = cpu_to_le64(len);
3959 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3960 cfile->fid.volatile_fid,
3961 FSCTL_QUERY_ALLOCATED_RANGES,
3962 (char *)&in_data, sizeof(in_data),
3963 1024 * sizeof(struct file_allocated_range_buffer),
3964 (char **)&out_data, &out_data_len);
3973 if (out_data_len && out_data_len < sizeof(struct file_allocated_range_buffer)) {
3977 if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3982 num = out_data_len / sizeof(struct file_allocated_range_buffer);
3983 for (i = 0; i < num; i++) {
3985 if (i == num - 1 && last_blob)
3986 flags |= FIEMAP_EXTENT_LAST;
3988 rc = fiemap_fill_next_extent(fei,
3989 le64_to_cpu(out_data[i].file_offset),
3990 le64_to_cpu(out_data[i].file_offset),
3991 le64_to_cpu(out_data[i].length),
4002 next = le64_to_cpu(out_data[num - 1].file_offset) +
4003 le64_to_cpu(out_data[num - 1].length);
4004 len = len - (next - start);
4015 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
4016 loff_t off, loff_t len)
4018 /* KEEP_SIZE already checked for by do_fallocate */
4019 if (mode & FALLOC_FL_PUNCH_HOLE)
4020 return smb3_punch_hole(file, tcon, off, len);
4021 else if (mode & FALLOC_FL_ZERO_RANGE) {
4022 if (mode & FALLOC_FL_KEEP_SIZE)
4023 return smb3_zero_range(file, tcon, off, len, true);
4024 return smb3_zero_range(file, tcon, off, len, false);
4025 } else if (mode == FALLOC_FL_KEEP_SIZE)
4026 return smb3_simple_falloc(file, tcon, off, len, true);
4027 else if (mode == FALLOC_FL_COLLAPSE_RANGE)
4028 return smb3_collapse_range(file, tcon, off, len);
4029 else if (mode == FALLOC_FL_INSERT_RANGE)
4030 return smb3_insert_range(file, tcon, off, len);
4032 return smb3_simple_falloc(file, tcon, off, len, false);
4038 smb2_downgrade_oplock(struct TCP_Server_Info *server,
4039 struct cifsInodeInfo *cinode, __u32 oplock,
4040 unsigned int epoch, bool *purge_cache)
4042 server->ops->set_oplock_level(cinode, oplock, 0, NULL);
4046 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4047 unsigned int epoch, bool *purge_cache);
4050 smb3_downgrade_oplock(struct TCP_Server_Info *server,
4051 struct cifsInodeInfo *cinode, __u32 oplock,
4052 unsigned int epoch, bool *purge_cache)
4054 unsigned int old_state = cinode->oplock;
4055 unsigned int old_epoch = cinode->epoch;
4056 unsigned int new_state;
4058 if (epoch > old_epoch) {
4059 smb21_set_oplock_level(cinode, oplock, 0, NULL);
4060 cinode->epoch = epoch;
4063 new_state = cinode->oplock;
4064 *purge_cache = false;
4066 if ((old_state & CIFS_CACHE_READ_FLG) != 0 &&
4067 (new_state & CIFS_CACHE_READ_FLG) == 0)
4068 *purge_cache = true;
4069 else if (old_state == new_state && (epoch - old_epoch > 1))
4070 *purge_cache = true;
4074 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4075 unsigned int epoch, bool *purge_cache)
4078 cinode->lease_granted = false;
4079 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
4081 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
4082 cinode->oplock = CIFS_CACHE_RHW_FLG;
4083 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
4084 &cinode->vfs_inode);
4085 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
4086 cinode->oplock = CIFS_CACHE_RW_FLG;
4087 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
4088 &cinode->vfs_inode);
4089 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
4090 cinode->oplock = CIFS_CACHE_READ_FLG;
4091 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
4092 &cinode->vfs_inode);
4098 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4099 unsigned int epoch, bool *purge_cache)
4101 char message[5] = {0};
4102 unsigned int new_oplock = 0;
4105 cinode->lease_granted = true;
4106 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
4109 /* Check if the server granted an oplock rather than a lease */
4110 if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4111 return smb2_set_oplock_level(cinode, oplock, epoch,
4114 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
4115 new_oplock |= CIFS_CACHE_READ_FLG;
4116 strcat(message, "R");
4118 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
4119 new_oplock |= CIFS_CACHE_HANDLE_FLG;
4120 strcat(message, "H");
4122 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
4123 new_oplock |= CIFS_CACHE_WRITE_FLG;
4124 strcat(message, "W");
4127 strncpy(message, "None", sizeof(message));
4129 cinode->oplock = new_oplock;
4130 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
4131 &cinode->vfs_inode);
4135 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4136 unsigned int epoch, bool *purge_cache)
4138 unsigned int old_oplock = cinode->oplock;
4140 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
4143 *purge_cache = false;
4144 if (old_oplock == CIFS_CACHE_READ_FLG) {
4145 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
4146 (epoch - cinode->epoch > 0))
4147 *purge_cache = true;
4148 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4149 (epoch - cinode->epoch > 1))
4150 *purge_cache = true;
4151 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4152 (epoch - cinode->epoch > 1))
4153 *purge_cache = true;
4154 else if (cinode->oplock == 0 &&
4155 (epoch - cinode->epoch > 0))
4156 *purge_cache = true;
4157 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
4158 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4159 (epoch - cinode->epoch > 0))
4160 *purge_cache = true;
4161 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4162 (epoch - cinode->epoch > 1))
4163 *purge_cache = true;
4165 cinode->epoch = epoch;
4169 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
4171 smb2_is_read_op(__u32 oplock)
4173 return oplock == SMB2_OPLOCK_LEVEL_II;
4175 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
4178 smb21_is_read_op(__u32 oplock)
4180 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
4181 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
4185 map_oplock_to_lease(u8 oplock)
4187 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4188 return SMB2_LEASE_WRITE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE;
4189 else if (oplock == SMB2_OPLOCK_LEVEL_II)
4190 return SMB2_LEASE_READ_CACHING_LE;
4191 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
4192 return SMB2_LEASE_HANDLE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE |
4193 SMB2_LEASE_WRITE_CACHING_LE;
4198 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
4200 struct create_lease *buf;
4202 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
4206 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4207 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4209 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4210 (struct create_lease, lcontext));
4211 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
4212 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4213 (struct create_lease, Name));
4214 buf->ccontext.NameLength = cpu_to_le16(4);
4215 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4224 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
4226 struct create_lease_v2 *buf;
4228 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
4232 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4233 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4235 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4236 (struct create_lease_v2, lcontext));
4237 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
4238 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4239 (struct create_lease_v2, Name));
4240 buf->ccontext.NameLength = cpu_to_le16(4);
4241 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4250 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4252 struct create_lease *lc = (struct create_lease *)buf;
4254 *epoch = 0; /* not used */
4255 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4256 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4257 return le32_to_cpu(lc->lcontext.LeaseState);
4261 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4263 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
4265 *epoch = le16_to_cpu(lc->lcontext.Epoch);
4266 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4267 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4269 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
4270 return le32_to_cpu(lc->lcontext.LeaseState);
4274 smb2_wp_retry_size(struct inode *inode)
4276 return min_t(unsigned int, CIFS_SB(inode->i_sb)->ctx->wsize,
4277 SMB2_MAX_BUFFER_SIZE);
4281 smb2_dir_needs_close(struct cifsFileInfo *cfile)
4283 return !cfile->invalidHandle;
4287 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
4288 struct smb_rqst *old_rq, __le16 cipher_type)
4290 struct smb2_hdr *shdr =
4291 (struct smb2_hdr *)old_rq->rq_iov[0].iov_base;
4293 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
4294 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
4295 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
4296 tr_hdr->Flags = cpu_to_le16(0x01);
4297 if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4298 (cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4299 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4301 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4302 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
4305 static void *smb2_aead_req_alloc(struct crypto_aead *tfm, const struct smb_rqst *rqst,
4306 int num_rqst, const u8 *sig, u8 **iv,
4307 struct aead_request **req, struct scatterlist **sgl,
4308 unsigned int *num_sgs)
4310 unsigned int req_size = sizeof(**req) + crypto_aead_reqsize(tfm);
4311 unsigned int iv_size = crypto_aead_ivsize(tfm);
4315 *num_sgs = cifs_get_num_sgs(rqst, num_rqst, sig);
4318 len += crypto_aead_alignmask(tfm) & ~(crypto_tfm_ctx_alignment() - 1);
4319 len = ALIGN(len, crypto_tfm_ctx_alignment());
4321 len = ALIGN(len, __alignof__(struct scatterlist));
4322 len += *num_sgs * sizeof(**sgl);
4324 p = kmalloc(len, GFP_ATOMIC);
4328 *iv = (u8 *)PTR_ALIGN(p, crypto_aead_alignmask(tfm) + 1);
4329 *req = (struct aead_request *)PTR_ALIGN(*iv + iv_size,
4330 crypto_tfm_ctx_alignment());
4331 *sgl = (struct scatterlist *)PTR_ALIGN((u8 *)*req + req_size,
4332 __alignof__(struct scatterlist));
4336 static void *smb2_get_aead_req(struct crypto_aead *tfm, const struct smb_rqst *rqst,
4337 int num_rqst, const u8 *sig, u8 **iv,
4338 struct aead_request **req, struct scatterlist **sgl)
4340 unsigned int off, len, skip;
4341 struct scatterlist *sg;
4342 unsigned int num_sgs;
4347 p = smb2_aead_req_alloc(tfm, rqst, num_rqst, sig, iv, req, sgl, &num_sgs);
4351 sg_init_table(*sgl, num_sgs);
4355 * The first rqst has a transform header where the
4356 * first 20 bytes are not part of the encrypted blob.
4360 /* Assumes the first rqst has a transform header as the first iov.
4362 * rqst[0].rq_iov[0] is transform header
4363 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
4364 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
4366 for (i = 0; i < num_rqst; i++) {
4367 for (j = 0; j < rqst[i].rq_nvec; j++) {
4368 struct kvec *iov = &rqst[i].rq_iov[j];
4370 addr = (unsigned long)iov->iov_base + skip;
4371 len = iov->iov_len - skip;
4372 sg = cifs_sg_set_buf(sg, (void *)addr, len);
4374 /* See the above comment on the 'skip' assignment */
4377 for (j = 0; j < rqst[i].rq_npages; j++) {
4378 rqst_page_get_length(&rqst[i], j, &len, &off);
4379 sg_set_page(sg++, rqst[i].rq_pages[j], len, off);
4382 cifs_sg_set_buf(sg, sig, SMB2_SIGNATURE_SIZE);
4388 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
4390 struct TCP_Server_Info *pserver;
4391 struct cifs_ses *ses;
4394 /* If server is a channel, select the primary channel */
4395 pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
4397 spin_lock(&cifs_tcp_ses_lock);
4398 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
4399 if (ses->Suid == ses_id) {
4400 spin_lock(&ses->ses_lock);
4401 ses_enc_key = enc ? ses->smb3encryptionkey :
4402 ses->smb3decryptionkey;
4403 memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE);
4404 spin_unlock(&ses->ses_lock);
4405 spin_unlock(&cifs_tcp_ses_lock);
4409 spin_unlock(&cifs_tcp_ses_lock);
4414 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
4415 * iov[0] - transform header (associate data),
4416 * iov[1-N] - SMB2 header and pages - data to encrypt.
4417 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4421 crypt_message(struct TCP_Server_Info *server, int num_rqst,
4422 struct smb_rqst *rqst, int enc)
4424 struct smb2_transform_hdr *tr_hdr =
4425 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
4426 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
4428 struct scatterlist *sg;
4429 u8 sign[SMB2_SIGNATURE_SIZE] = {};
4430 u8 key[SMB3_ENC_DEC_KEY_SIZE];
4431 struct aead_request *req;
4433 DECLARE_CRYPTO_WAIT(wait);
4434 struct crypto_aead *tfm;
4435 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4438 rc = smb2_get_enc_key(server, le64_to_cpu(tr_hdr->SessionId), enc, key);
4440 cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
4445 rc = smb3_crypto_aead_allocate(server);
4447 cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
4451 tfm = enc ? server->secmech.enc : server->secmech.dec;
4453 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
4454 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4455 rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
4457 rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE);
4460 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
4464 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
4466 cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
4470 creq = smb2_get_aead_req(tfm, rqst, num_rqst, sign, &iv, &req, &sg);
4471 if (unlikely(!creq))
4475 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
4476 crypt_len += SMB2_SIGNATURE_SIZE;
4479 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4480 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4481 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4484 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4487 aead_request_set_tfm(req, tfm);
4488 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
4489 aead_request_set_ad(req, assoc_data_len);
4491 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
4492 crypto_req_done, &wait);
4494 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
4495 : crypto_aead_decrypt(req), &wait);
4498 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
4500 kfree_sensitive(creq);
4505 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
4509 for (i = 0; i < num_rqst; i++) {
4510 if (rqst[i].rq_pages) {
4511 for (j = rqst[i].rq_npages - 1; j >= 0; j--)
4512 put_page(rqst[i].rq_pages[j]);
4513 kfree(rqst[i].rq_pages);
4519 * This function will initialize new_rq and encrypt the content.
4520 * The first entry, new_rq[0], only contains a single iov which contains
4521 * a smb2_transform_hdr and is pre-allocated by the caller.
4522 * This function then populates new_rq[1+] with the content from olq_rq[0+].
4524 * The end result is an array of smb_rqst structures where the first structure
4525 * only contains a single iov for the transform header which we then can pass
4526 * to crypt_message().
4528 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4529 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
4532 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
4533 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
4535 struct page **pages;
4536 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
4537 unsigned int npages;
4538 unsigned int orig_len = 0;
4542 for (i = 1; i < num_rqst; i++) {
4543 struct smb_rqst *old = &old_rq[i - 1];
4544 struct smb_rqst *new = &new_rq[i];
4546 orig_len += smb_rqst_len(server, old);
4547 new->rq_iov = old->rq_iov;
4548 new->rq_nvec = old->rq_nvec;
4550 npages = old->rq_npages;
4554 pages = kmalloc_array(npages, sizeof(struct page *),
4559 new->rq_pages = pages;
4560 new->rq_npages = npages;
4561 new->rq_offset = old->rq_offset;
4562 new->rq_pagesz = old->rq_pagesz;
4563 new->rq_tailsz = old->rq_tailsz;
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++) {
4573 unsigned int offset, len;
4575 rqst_page_get_length(new, j, &len, &offset);
4577 memcpy_page(new->rq_pages[j], offset,
4578 old->rq_pages[j], offset, len);
4582 /* fill the 1st iov with a transform header */
4583 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
4585 rc = crypt_message(server, num_rqst, new_rq, 1);
4586 cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
4593 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
4598 smb3_is_transform_hdr(void *buf)
4600 struct smb2_transform_hdr *trhdr = buf;
4602 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
4606 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
4607 unsigned int buf_data_size, struct page **pages,
4608 unsigned int npages, unsigned int page_data_size,
4612 struct smb_rqst rqst = {NULL};
4615 iov[0].iov_base = buf;
4616 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
4617 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
4618 iov[1].iov_len = buf_data_size;
4622 rqst.rq_pages = pages;
4623 rqst.rq_npages = npages;
4624 rqst.rq_pagesz = PAGE_SIZE;
4625 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
4627 rc = crypt_message(server, 1, &rqst, 0);
4628 cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
4633 memmove(buf, iov[1].iov_base, buf_data_size);
4636 server->total_read = buf_data_size + page_data_size;
4642 read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
4643 unsigned int npages, unsigned int len)
4648 for (i = 0; i < npages; i++) {
4649 struct page *page = pages[i];
4653 if (len >= PAGE_SIZE) {
4654 /* enough data to fill the page */
4658 zero_user(page, len, PAGE_SIZE - len);
4661 length = cifs_read_page_from_socket(server, page, 0, n);
4664 server->total_read += length;
4671 init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
4672 unsigned int cur_off, struct bio_vec **page_vec)
4674 struct bio_vec *bvec;
4677 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
4681 for (i = 0; i < npages; i++) {
4682 bvec[i].bv_page = pages[i];
4683 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
4684 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
4685 data_size -= bvec[i].bv_len;
4688 if (data_size != 0) {
4689 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
4699 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
4700 char *buf, unsigned int buf_len, struct page **pages,
4701 unsigned int npages, unsigned int page_data_size,
4704 unsigned int data_offset;
4705 unsigned int data_len;
4706 unsigned int cur_off;
4707 unsigned int cur_page_idx;
4708 unsigned int pad_len;
4709 struct cifs_readdata *rdata = mid->callback_data;
4710 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
4711 struct bio_vec *bvec = NULL;
4712 struct iov_iter iter;
4715 bool use_rdma_mr = false;
4717 if (shdr->Command != SMB2_READ) {
4718 cifs_server_dbg(VFS, "only big read responses are supported\n");
4722 if (server->ops->is_session_expired &&
4723 server->ops->is_session_expired(buf)) {
4725 cifs_reconnect(server, true);
4729 if (server->ops->is_status_pending &&
4730 server->ops->is_status_pending(buf, server))
4733 /* set up first two iov to get credits */
4734 rdata->iov[0].iov_base = buf;
4735 rdata->iov[0].iov_len = 0;
4736 rdata->iov[1].iov_base = buf;
4737 rdata->iov[1].iov_len =
4738 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
4739 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
4740 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
4741 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
4742 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
4744 rdata->result = server->ops->map_error(buf, true);
4745 if (rdata->result != 0) {
4746 cifs_dbg(FYI, "%s: server returned error %d\n",
4747 __func__, rdata->result);
4748 /* normal error on read response */
4750 mid->mid_state = MID_RESPONSE_RECEIVED;
4752 dequeue_mid(mid, false);
4756 data_offset = server->ops->read_data_offset(buf);
4757 #ifdef CONFIG_CIFS_SMB_DIRECT
4758 use_rdma_mr = rdata->mr;
4760 data_len = server->ops->read_data_length(buf, use_rdma_mr);
4762 if (data_offset < server->vals->read_rsp_size) {
4764 * win2k8 sometimes sends an offset of 0 when the read
4765 * is beyond the EOF. Treat it as if the data starts just after
4768 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
4769 __func__, data_offset);
4770 data_offset = server->vals->read_rsp_size;
4771 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
4772 /* data_offset is beyond the end of smallbuf */
4773 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
4774 __func__, data_offset);
4775 rdata->result = -EIO;
4777 mid->mid_state = MID_RESPONSE_MALFORMED;
4779 dequeue_mid(mid, rdata->result);
4783 pad_len = data_offset - server->vals->read_rsp_size;
4785 if (buf_len <= data_offset) {
4786 /* read response payload is in pages */
4787 cur_page_idx = pad_len / PAGE_SIZE;
4788 cur_off = pad_len % PAGE_SIZE;
4790 if (cur_page_idx != 0) {
4791 /* data offset is beyond the 1st page of response */
4792 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
4793 __func__, data_offset);
4794 rdata->result = -EIO;
4796 mid->mid_state = MID_RESPONSE_MALFORMED;
4798 dequeue_mid(mid, rdata->result);
4802 if (data_len > page_data_size - pad_len) {
4803 /* data_len is corrupt -- discard frame */
4804 rdata->result = -EIO;
4806 mid->mid_state = MID_RESPONSE_MALFORMED;
4808 dequeue_mid(mid, rdata->result);
4812 rdata->result = init_read_bvec(pages, npages, page_data_size,
4814 if (rdata->result != 0) {
4816 mid->mid_state = MID_RESPONSE_MALFORMED;
4818 dequeue_mid(mid, rdata->result);
4822 iov_iter_bvec(&iter, WRITE, bvec, npages, data_len);
4823 } else if (buf_len >= data_offset + data_len) {
4824 /* read response payload is in buf */
4825 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
4826 iov.iov_base = buf + data_offset;
4827 iov.iov_len = data_len;
4828 iov_iter_kvec(&iter, WRITE, &iov, 1, data_len);
4830 /* read response payload cannot be in both buf and pages */
4831 WARN_ONCE(1, "buf can not contain only a part of read data");
4832 rdata->result = -EIO;
4834 mid->mid_state = MID_RESPONSE_MALFORMED;
4836 dequeue_mid(mid, rdata->result);
4840 length = rdata->copy_into_pages(server, rdata, &iter);
4848 mid->mid_state = MID_RESPONSE_RECEIVED;
4850 dequeue_mid(mid, false);
4854 struct smb2_decrypt_work {
4855 struct work_struct decrypt;
4856 struct TCP_Server_Info *server;
4857 struct page **ppages;
4859 unsigned int npages;
4864 static void smb2_decrypt_offload(struct work_struct *work)
4866 struct smb2_decrypt_work *dw = container_of(work,
4867 struct smb2_decrypt_work, decrypt);
4869 struct mid_q_entry *mid;
4871 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
4872 dw->ppages, dw->npages, dw->len, true);
4874 cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
4878 dw->server->lstrp = jiffies;
4879 mid = smb2_find_dequeue_mid(dw->server, dw->buf);
4881 cifs_dbg(FYI, "mid not found\n");
4883 mid->decrypted = true;
4884 rc = handle_read_data(dw->server, mid, dw->buf,
4885 dw->server->vals->read_rsp_size,
4886 dw->ppages, dw->npages, dw->len,
4889 #ifdef CONFIG_CIFS_STATS2
4890 mid->when_received = jiffies;
4892 if (dw->server->ops->is_network_name_deleted)
4893 dw->server->ops->is_network_name_deleted(dw->buf,
4898 spin_lock(&dw->server->srv_lock);
4899 if (dw->server->tcpStatus == CifsNeedReconnect) {
4900 spin_lock(&dw->server->mid_lock);
4901 mid->mid_state = MID_RETRY_NEEDED;
4902 spin_unlock(&dw->server->mid_lock);
4903 spin_unlock(&dw->server->srv_lock);
4906 spin_lock(&dw->server->mid_lock);
4907 mid->mid_state = MID_REQUEST_SUBMITTED;
4908 mid->mid_flags &= ~(MID_DELETED);
4909 list_add_tail(&mid->qhead,
4910 &dw->server->pending_mid_q);
4911 spin_unlock(&dw->server->mid_lock);
4912 spin_unlock(&dw->server->srv_lock);
4919 for (i = dw->npages-1; i >= 0; i--)
4920 put_page(dw->ppages[i]);
4923 cifs_small_buf_release(dw->buf);
4929 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
4932 char *buf = server->smallbuf;
4933 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4934 unsigned int npages;
4935 struct page **pages;
4937 unsigned int buflen = server->pdu_size;
4940 struct smb2_decrypt_work *dw;
4943 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
4944 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
4946 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
4949 server->total_read += rc;
4951 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
4952 server->vals->read_rsp_size;
4953 npages = DIV_ROUND_UP(len, PAGE_SIZE);
4955 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
4961 for (; i < npages; i++) {
4962 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4969 /* read read data into pages */
4970 rc = read_data_into_pages(server, pages, npages, len);
4974 rc = cifs_discard_remaining_data(server);
4979 * For large reads, offload to different thread for better performance,
4980 * use more cores decrypting which can be expensive
4983 if ((server->min_offload) && (server->in_flight > 1) &&
4984 (server->pdu_size >= server->min_offload)) {
4985 dw = kmalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL);
4987 goto non_offloaded_decrypt;
4989 dw->buf = server->smallbuf;
4990 server->smallbuf = (char *)cifs_small_buf_get();
4992 INIT_WORK(&dw->decrypt, smb2_decrypt_offload);
4994 dw->npages = npages;
4995 dw->server = server;
4998 queue_work(decrypt_wq, &dw->decrypt);
4999 *num_mids = 0; /* worker thread takes care of finding mid */
5003 non_offloaded_decrypt:
5004 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
5005 pages, npages, len, false);
5009 *mid = smb2_find_mid(server, buf);
5011 cifs_dbg(FYI, "mid not found\n");
5013 cifs_dbg(FYI, "mid found\n");
5014 (*mid)->decrypted = true;
5015 rc = handle_read_data(server, *mid, buf,
5016 server->vals->read_rsp_size,
5017 pages, npages, len, false);
5019 if (server->ops->is_network_name_deleted) {
5020 server->ops->is_network_name_deleted(buf,
5027 for (i = i - 1; i >= 0; i--)
5032 cifs_discard_remaining_data(server);
5037 receive_encrypted_standard(struct TCP_Server_Info *server,
5038 struct mid_q_entry **mids, char **bufs,
5042 char *buf = server->smallbuf;
5043 struct smb2_hdr *shdr;
5044 unsigned int pdu_length = server->pdu_size;
5045 unsigned int buf_size;
5046 struct mid_q_entry *mid_entry;
5048 char *next_buffer = NULL;
5052 /* switch to large buffer if too big for a small one */
5053 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
5054 server->large_buf = true;
5055 memcpy(server->bigbuf, buf, server->total_read);
5056 buf = server->bigbuf;
5059 /* now read the rest */
5060 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
5061 pdu_length - HEADER_SIZE(server) + 1);
5064 server->total_read += length;
5066 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
5067 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0, false);
5071 next_is_large = server->large_buf;
5073 shdr = (struct smb2_hdr *)buf;
5074 if (shdr->NextCommand) {
5076 next_buffer = (char *)cifs_buf_get();
5078 next_buffer = (char *)cifs_small_buf_get();
5080 buf + le32_to_cpu(shdr->NextCommand),
5081 pdu_length - le32_to_cpu(shdr->NextCommand));
5084 mid_entry = smb2_find_mid(server, buf);
5085 if (mid_entry == NULL)
5086 cifs_dbg(FYI, "mid not found\n");
5088 cifs_dbg(FYI, "mid found\n");
5089 mid_entry->decrypted = true;
5090 mid_entry->resp_buf_size = server->pdu_size;
5093 if (*num_mids >= MAX_COMPOUND) {
5094 cifs_server_dbg(VFS, "too many PDUs in compound\n");
5097 bufs[*num_mids] = buf;
5098 mids[(*num_mids)++] = mid_entry;
5100 if (mid_entry && mid_entry->handle)
5101 ret = mid_entry->handle(server, mid_entry);
5103 ret = cifs_handle_standard(server, mid_entry);
5105 if (ret == 0 && shdr->NextCommand) {
5106 pdu_length -= le32_to_cpu(shdr->NextCommand);
5107 server->large_buf = next_is_large;
5109 server->bigbuf = buf = next_buffer;
5111 server->smallbuf = buf = next_buffer;
5113 } else if (ret != 0) {
5115 * ret != 0 here means that we didn't get to handle_mid() thus
5116 * server->smallbuf and server->bigbuf are still valid. We need
5117 * to free next_buffer because it is not going to be used
5121 free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer);
5123 free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer);
5130 smb3_receive_transform(struct TCP_Server_Info *server,
5131 struct mid_q_entry **mids, char **bufs, int *num_mids)
5133 char *buf = server->smallbuf;
5134 unsigned int pdu_length = server->pdu_size;
5135 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
5136 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
5138 if (pdu_length < sizeof(struct smb2_transform_hdr) +
5139 sizeof(struct smb2_hdr)) {
5140 cifs_server_dbg(VFS, "Transform message is too small (%u)\n",
5142 cifs_reconnect(server, true);
5143 return -ECONNABORTED;
5146 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
5147 cifs_server_dbg(VFS, "Transform message is broken\n");
5148 cifs_reconnect(server, true);
5149 return -ECONNABORTED;
5152 /* TODO: add support for compounds containing READ. */
5153 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
5154 return receive_encrypted_read(server, &mids[0], num_mids);
5157 return receive_encrypted_standard(server, mids, bufs, num_mids);
5161 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
5163 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
5165 return handle_read_data(server, mid, buf, server->pdu_size,
5170 smb2_next_header(char *buf)
5172 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
5173 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
5175 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
5176 return sizeof(struct smb2_transform_hdr) +
5177 le32_to_cpu(t_hdr->OriginalMessageSize);
5179 return le32_to_cpu(hdr->NextCommand);
5183 smb2_make_node(unsigned int xid, struct inode *inode,
5184 struct dentry *dentry, struct cifs_tcon *tcon,
5185 const char *full_path, umode_t mode, dev_t dev)
5187 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
5189 struct cifs_open_info_data buf = {};
5190 struct cifs_io_parms io_parms = {0};
5192 struct cifs_fid fid;
5193 struct cifs_open_parms oparms;
5194 unsigned int bytes_written;
5195 struct win_dev *pdev;
5199 * Check if mounted with mount parm 'sfu' mount parm.
5200 * SFU emulation should work with all servers, but only
5201 * supports block and char device (no socket & fifo),
5202 * and was used by default in earlier versions of Windows
5204 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
5208 * TODO: Add ability to create instead via reparse point. Windows (e.g.
5209 * their current NFS server) uses this approach to expose special files
5210 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
5213 if (!S_ISCHR(mode) && !S_ISBLK(mode))
5216 cifs_dbg(FYI, "sfu compat create special file\n");
5218 oparms = (struct cifs_open_parms) {
5221 .desired_access = GENERIC_WRITE,
5222 .create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR |
5223 CREATE_OPTION_SPECIAL),
5224 .disposition = FILE_CREATE,
5229 if (tcon->ses->server->oplocks)
5230 oplock = REQ_OPLOCK;
5233 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, &buf);
5238 * BB Do not bother to decode buf since no local inode yet to put
5239 * timestamps in, but we can reuse it safely.
5242 pdev = (struct win_dev *)&buf.fi;
5243 io_parms.pid = current->tgid;
5244 io_parms.tcon = tcon;
5245 io_parms.offset = 0;
5246 io_parms.length = sizeof(struct win_dev);
5247 iov[1].iov_base = &buf.fi;
5248 iov[1].iov_len = sizeof(struct win_dev);
5249 if (S_ISCHR(mode)) {
5250 memcpy(pdev->type, "IntxCHR", 8);
5251 pdev->major = cpu_to_le64(MAJOR(dev));
5252 pdev->minor = cpu_to_le64(MINOR(dev));
5253 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5254 &bytes_written, iov, 1);
5255 } else if (S_ISBLK(mode)) {
5256 memcpy(pdev->type, "IntxBLK", 8);
5257 pdev->major = cpu_to_le64(MAJOR(dev));
5258 pdev->minor = cpu_to_le64(MINOR(dev));
5259 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5260 &bytes_written, iov, 1);
5262 tcon->ses->server->ops->close(xid, tcon, &fid);
5265 /* FIXME: add code here to set EAs */
5267 cifs_free_open_info(&buf);
5271 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5272 struct smb_version_operations smb20_operations = {
5273 .compare_fids = smb2_compare_fids,
5274 .setup_request = smb2_setup_request,
5275 .setup_async_request = smb2_setup_async_request,
5276 .check_receive = smb2_check_receive,
5277 .add_credits = smb2_add_credits,
5278 .set_credits = smb2_set_credits,
5279 .get_credits_field = smb2_get_credits_field,
5280 .get_credits = smb2_get_credits,
5281 .wait_mtu_credits = cifs_wait_mtu_credits,
5282 .get_next_mid = smb2_get_next_mid,
5283 .revert_current_mid = smb2_revert_current_mid,
5284 .read_data_offset = smb2_read_data_offset,
5285 .read_data_length = smb2_read_data_length,
5286 .map_error = map_smb2_to_linux_error,
5287 .find_mid = smb2_find_mid,
5288 .check_message = smb2_check_message,
5289 .dump_detail = smb2_dump_detail,
5290 .clear_stats = smb2_clear_stats,
5291 .print_stats = smb2_print_stats,
5292 .is_oplock_break = smb2_is_valid_oplock_break,
5293 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5294 .downgrade_oplock = smb2_downgrade_oplock,
5295 .need_neg = smb2_need_neg,
5296 .negotiate = smb2_negotiate,
5297 .negotiate_wsize = smb2_negotiate_wsize,
5298 .negotiate_rsize = smb2_negotiate_rsize,
5299 .sess_setup = SMB2_sess_setup,
5300 .logoff = SMB2_logoff,
5301 .tree_connect = SMB2_tcon,
5302 .tree_disconnect = SMB2_tdis,
5303 .qfs_tcon = smb2_qfs_tcon,
5304 .is_path_accessible = smb2_is_path_accessible,
5305 .can_echo = smb2_can_echo,
5307 .query_path_info = smb2_query_path_info,
5308 .get_srv_inum = smb2_get_srv_inum,
5309 .query_file_info = smb2_query_file_info,
5310 .set_path_size = smb2_set_path_size,
5311 .set_file_size = smb2_set_file_size,
5312 .set_file_info = smb2_set_file_info,
5313 .set_compression = smb2_set_compression,
5314 .mkdir = smb2_mkdir,
5315 .mkdir_setinfo = smb2_mkdir_setinfo,
5316 .rmdir = smb2_rmdir,
5317 .unlink = smb2_unlink,
5318 .rename = smb2_rename_path,
5319 .create_hardlink = smb2_create_hardlink,
5320 .query_symlink = smb2_query_symlink,
5321 .query_mf_symlink = smb3_query_mf_symlink,
5322 .create_mf_symlink = smb3_create_mf_symlink,
5323 .open = smb2_open_file,
5324 .set_fid = smb2_set_fid,
5325 .close = smb2_close_file,
5326 .flush = smb2_flush_file,
5327 .async_readv = smb2_async_readv,
5328 .async_writev = smb2_async_writev,
5329 .sync_read = smb2_sync_read,
5330 .sync_write = smb2_sync_write,
5331 .query_dir_first = smb2_query_dir_first,
5332 .query_dir_next = smb2_query_dir_next,
5333 .close_dir = smb2_close_dir,
5334 .calc_smb_size = smb2_calc_size,
5335 .is_status_pending = smb2_is_status_pending,
5336 .is_session_expired = smb2_is_session_expired,
5337 .oplock_response = smb2_oplock_response,
5338 .queryfs = smb2_queryfs,
5339 .mand_lock = smb2_mand_lock,
5340 .mand_unlock_range = smb2_unlock_range,
5341 .push_mand_locks = smb2_push_mandatory_locks,
5342 .get_lease_key = smb2_get_lease_key,
5343 .set_lease_key = smb2_set_lease_key,
5344 .new_lease_key = smb2_new_lease_key,
5345 .calc_signature = smb2_calc_signature,
5346 .is_read_op = smb2_is_read_op,
5347 .set_oplock_level = smb2_set_oplock_level,
5348 .create_lease_buf = smb2_create_lease_buf,
5349 .parse_lease_buf = smb2_parse_lease_buf,
5350 .copychunk_range = smb2_copychunk_range,
5351 .wp_retry_size = smb2_wp_retry_size,
5352 .dir_needs_close = smb2_dir_needs_close,
5353 .get_dfs_refer = smb2_get_dfs_refer,
5354 .select_sectype = smb2_select_sectype,
5355 #ifdef CONFIG_CIFS_XATTR
5356 .query_all_EAs = smb2_query_eas,
5357 .set_EA = smb2_set_ea,
5358 #endif /* CIFS_XATTR */
5359 .get_acl = get_smb2_acl,
5360 .get_acl_by_fid = get_smb2_acl_by_fid,
5361 .set_acl = set_smb2_acl,
5362 .next_header = smb2_next_header,
5363 .ioctl_query_info = smb2_ioctl_query_info,
5364 .make_node = smb2_make_node,
5365 .fiemap = smb3_fiemap,
5366 .llseek = smb3_llseek,
5367 .is_status_io_timeout = smb2_is_status_io_timeout,
5368 .is_network_name_deleted = smb2_is_network_name_deleted,
5370 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
5372 struct smb_version_operations smb21_operations = {
5373 .compare_fids = smb2_compare_fids,
5374 .setup_request = smb2_setup_request,
5375 .setup_async_request = smb2_setup_async_request,
5376 .check_receive = smb2_check_receive,
5377 .add_credits = smb2_add_credits,
5378 .set_credits = smb2_set_credits,
5379 .get_credits_field = smb2_get_credits_field,
5380 .get_credits = smb2_get_credits,
5381 .wait_mtu_credits = smb2_wait_mtu_credits,
5382 .adjust_credits = smb2_adjust_credits,
5383 .get_next_mid = smb2_get_next_mid,
5384 .revert_current_mid = smb2_revert_current_mid,
5385 .read_data_offset = smb2_read_data_offset,
5386 .read_data_length = smb2_read_data_length,
5387 .map_error = map_smb2_to_linux_error,
5388 .find_mid = smb2_find_mid,
5389 .check_message = smb2_check_message,
5390 .dump_detail = smb2_dump_detail,
5391 .clear_stats = smb2_clear_stats,
5392 .print_stats = smb2_print_stats,
5393 .is_oplock_break = smb2_is_valid_oplock_break,
5394 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5395 .downgrade_oplock = smb2_downgrade_oplock,
5396 .need_neg = smb2_need_neg,
5397 .negotiate = smb2_negotiate,
5398 .negotiate_wsize = smb2_negotiate_wsize,
5399 .negotiate_rsize = smb2_negotiate_rsize,
5400 .sess_setup = SMB2_sess_setup,
5401 .logoff = SMB2_logoff,
5402 .tree_connect = SMB2_tcon,
5403 .tree_disconnect = SMB2_tdis,
5404 .qfs_tcon = smb2_qfs_tcon,
5405 .is_path_accessible = smb2_is_path_accessible,
5406 .can_echo = smb2_can_echo,
5408 .query_path_info = smb2_query_path_info,
5409 .get_srv_inum = smb2_get_srv_inum,
5410 .query_file_info = smb2_query_file_info,
5411 .set_path_size = smb2_set_path_size,
5412 .set_file_size = smb2_set_file_size,
5413 .set_file_info = smb2_set_file_info,
5414 .set_compression = smb2_set_compression,
5415 .mkdir = smb2_mkdir,
5416 .mkdir_setinfo = smb2_mkdir_setinfo,
5417 .rmdir = smb2_rmdir,
5418 .unlink = smb2_unlink,
5419 .rename = smb2_rename_path,
5420 .create_hardlink = smb2_create_hardlink,
5421 .query_symlink = smb2_query_symlink,
5422 .query_mf_symlink = smb3_query_mf_symlink,
5423 .create_mf_symlink = smb3_create_mf_symlink,
5424 .open = smb2_open_file,
5425 .set_fid = smb2_set_fid,
5426 .close = smb2_close_file,
5427 .flush = smb2_flush_file,
5428 .async_readv = smb2_async_readv,
5429 .async_writev = smb2_async_writev,
5430 .sync_read = smb2_sync_read,
5431 .sync_write = smb2_sync_write,
5432 .query_dir_first = smb2_query_dir_first,
5433 .query_dir_next = smb2_query_dir_next,
5434 .close_dir = smb2_close_dir,
5435 .calc_smb_size = smb2_calc_size,
5436 .is_status_pending = smb2_is_status_pending,
5437 .is_session_expired = smb2_is_session_expired,
5438 .oplock_response = smb2_oplock_response,
5439 .queryfs = smb2_queryfs,
5440 .mand_lock = smb2_mand_lock,
5441 .mand_unlock_range = smb2_unlock_range,
5442 .push_mand_locks = smb2_push_mandatory_locks,
5443 .get_lease_key = smb2_get_lease_key,
5444 .set_lease_key = smb2_set_lease_key,
5445 .new_lease_key = smb2_new_lease_key,
5446 .calc_signature = smb2_calc_signature,
5447 .is_read_op = smb21_is_read_op,
5448 .set_oplock_level = smb21_set_oplock_level,
5449 .create_lease_buf = smb2_create_lease_buf,
5450 .parse_lease_buf = smb2_parse_lease_buf,
5451 .copychunk_range = smb2_copychunk_range,
5452 .wp_retry_size = smb2_wp_retry_size,
5453 .dir_needs_close = smb2_dir_needs_close,
5454 .enum_snapshots = smb3_enum_snapshots,
5455 .notify = smb3_notify,
5456 .get_dfs_refer = smb2_get_dfs_refer,
5457 .select_sectype = smb2_select_sectype,
5458 #ifdef CONFIG_CIFS_XATTR
5459 .query_all_EAs = smb2_query_eas,
5460 .set_EA = smb2_set_ea,
5461 #endif /* CIFS_XATTR */
5462 .get_acl = get_smb2_acl,
5463 .get_acl_by_fid = get_smb2_acl_by_fid,
5464 .set_acl = set_smb2_acl,
5465 .next_header = smb2_next_header,
5466 .ioctl_query_info = smb2_ioctl_query_info,
5467 .make_node = smb2_make_node,
5468 .fiemap = smb3_fiemap,
5469 .llseek = smb3_llseek,
5470 .is_status_io_timeout = smb2_is_status_io_timeout,
5471 .is_network_name_deleted = smb2_is_network_name_deleted,
5474 struct smb_version_operations smb30_operations = {
5475 .compare_fids = smb2_compare_fids,
5476 .setup_request = smb2_setup_request,
5477 .setup_async_request = smb2_setup_async_request,
5478 .check_receive = smb2_check_receive,
5479 .add_credits = smb2_add_credits,
5480 .set_credits = smb2_set_credits,
5481 .get_credits_field = smb2_get_credits_field,
5482 .get_credits = smb2_get_credits,
5483 .wait_mtu_credits = smb2_wait_mtu_credits,
5484 .adjust_credits = smb2_adjust_credits,
5485 .get_next_mid = smb2_get_next_mid,
5486 .revert_current_mid = smb2_revert_current_mid,
5487 .read_data_offset = smb2_read_data_offset,
5488 .read_data_length = smb2_read_data_length,
5489 .map_error = map_smb2_to_linux_error,
5490 .find_mid = smb2_find_mid,
5491 .check_message = smb2_check_message,
5492 .dump_detail = smb2_dump_detail,
5493 .clear_stats = smb2_clear_stats,
5494 .print_stats = smb2_print_stats,
5495 .dump_share_caps = smb2_dump_share_caps,
5496 .is_oplock_break = smb2_is_valid_oplock_break,
5497 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5498 .downgrade_oplock = smb3_downgrade_oplock,
5499 .need_neg = smb2_need_neg,
5500 .negotiate = smb2_negotiate,
5501 .negotiate_wsize = smb3_negotiate_wsize,
5502 .negotiate_rsize = smb3_negotiate_rsize,
5503 .sess_setup = SMB2_sess_setup,
5504 .logoff = SMB2_logoff,
5505 .tree_connect = SMB2_tcon,
5506 .tree_disconnect = SMB2_tdis,
5507 .qfs_tcon = smb3_qfs_tcon,
5508 .is_path_accessible = smb2_is_path_accessible,
5509 .can_echo = smb2_can_echo,
5511 .query_path_info = smb2_query_path_info,
5512 /* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */
5513 .query_reparse_tag = smb2_query_reparse_tag,
5514 .get_srv_inum = smb2_get_srv_inum,
5515 .query_file_info = smb2_query_file_info,
5516 .set_path_size = smb2_set_path_size,
5517 .set_file_size = smb2_set_file_size,
5518 .set_file_info = smb2_set_file_info,
5519 .set_compression = smb2_set_compression,
5520 .mkdir = smb2_mkdir,
5521 .mkdir_setinfo = smb2_mkdir_setinfo,
5522 .rmdir = smb2_rmdir,
5523 .unlink = smb2_unlink,
5524 .rename = smb2_rename_path,
5525 .create_hardlink = smb2_create_hardlink,
5526 .query_symlink = smb2_query_symlink,
5527 .query_mf_symlink = smb3_query_mf_symlink,
5528 .create_mf_symlink = smb3_create_mf_symlink,
5529 .open = smb2_open_file,
5530 .set_fid = smb2_set_fid,
5531 .close = smb2_close_file,
5532 .close_getattr = smb2_close_getattr,
5533 .flush = smb2_flush_file,
5534 .async_readv = smb2_async_readv,
5535 .async_writev = smb2_async_writev,
5536 .sync_read = smb2_sync_read,
5537 .sync_write = smb2_sync_write,
5538 .query_dir_first = smb2_query_dir_first,
5539 .query_dir_next = smb2_query_dir_next,
5540 .close_dir = smb2_close_dir,
5541 .calc_smb_size = smb2_calc_size,
5542 .is_status_pending = smb2_is_status_pending,
5543 .is_session_expired = smb2_is_session_expired,
5544 .oplock_response = smb2_oplock_response,
5545 .queryfs = smb2_queryfs,
5546 .mand_lock = smb2_mand_lock,
5547 .mand_unlock_range = smb2_unlock_range,
5548 .push_mand_locks = smb2_push_mandatory_locks,
5549 .get_lease_key = smb2_get_lease_key,
5550 .set_lease_key = smb2_set_lease_key,
5551 .new_lease_key = smb2_new_lease_key,
5552 .generate_signingkey = generate_smb30signingkey,
5553 .calc_signature = smb3_calc_signature,
5554 .set_integrity = smb3_set_integrity,
5555 .is_read_op = smb21_is_read_op,
5556 .set_oplock_level = smb3_set_oplock_level,
5557 .create_lease_buf = smb3_create_lease_buf,
5558 .parse_lease_buf = smb3_parse_lease_buf,
5559 .copychunk_range = smb2_copychunk_range,
5560 .duplicate_extents = smb2_duplicate_extents,
5561 .validate_negotiate = smb3_validate_negotiate,
5562 .wp_retry_size = smb2_wp_retry_size,
5563 .dir_needs_close = smb2_dir_needs_close,
5564 .fallocate = smb3_fallocate,
5565 .enum_snapshots = smb3_enum_snapshots,
5566 .notify = smb3_notify,
5567 .init_transform_rq = smb3_init_transform_rq,
5568 .is_transform_hdr = smb3_is_transform_hdr,
5569 .receive_transform = smb3_receive_transform,
5570 .get_dfs_refer = smb2_get_dfs_refer,
5571 .select_sectype = smb2_select_sectype,
5572 #ifdef CONFIG_CIFS_XATTR
5573 .query_all_EAs = smb2_query_eas,
5574 .set_EA = smb2_set_ea,
5575 #endif /* CIFS_XATTR */
5576 .get_acl = get_smb2_acl,
5577 .get_acl_by_fid = get_smb2_acl_by_fid,
5578 .set_acl = set_smb2_acl,
5579 .next_header = smb2_next_header,
5580 .ioctl_query_info = smb2_ioctl_query_info,
5581 .make_node = smb2_make_node,
5582 .fiemap = smb3_fiemap,
5583 .llseek = smb3_llseek,
5584 .is_status_io_timeout = smb2_is_status_io_timeout,
5585 .is_network_name_deleted = smb2_is_network_name_deleted,
5588 struct smb_version_operations smb311_operations = {
5589 .compare_fids = smb2_compare_fids,
5590 .setup_request = smb2_setup_request,
5591 .setup_async_request = smb2_setup_async_request,
5592 .check_receive = smb2_check_receive,
5593 .add_credits = smb2_add_credits,
5594 .set_credits = smb2_set_credits,
5595 .get_credits_field = smb2_get_credits_field,
5596 .get_credits = smb2_get_credits,
5597 .wait_mtu_credits = smb2_wait_mtu_credits,
5598 .adjust_credits = smb2_adjust_credits,
5599 .get_next_mid = smb2_get_next_mid,
5600 .revert_current_mid = smb2_revert_current_mid,
5601 .read_data_offset = smb2_read_data_offset,
5602 .read_data_length = smb2_read_data_length,
5603 .map_error = map_smb2_to_linux_error,
5604 .find_mid = smb2_find_mid,
5605 .check_message = smb2_check_message,
5606 .dump_detail = smb2_dump_detail,
5607 .clear_stats = smb2_clear_stats,
5608 .print_stats = smb2_print_stats,
5609 .dump_share_caps = smb2_dump_share_caps,
5610 .is_oplock_break = smb2_is_valid_oplock_break,
5611 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5612 .downgrade_oplock = smb3_downgrade_oplock,
5613 .need_neg = smb2_need_neg,
5614 .negotiate = smb2_negotiate,
5615 .negotiate_wsize = smb3_negotiate_wsize,
5616 .negotiate_rsize = smb3_negotiate_rsize,
5617 .sess_setup = SMB2_sess_setup,
5618 .logoff = SMB2_logoff,
5619 .tree_connect = SMB2_tcon,
5620 .tree_disconnect = SMB2_tdis,
5621 .qfs_tcon = smb3_qfs_tcon,
5622 .is_path_accessible = smb2_is_path_accessible,
5623 .can_echo = smb2_can_echo,
5625 .query_path_info = smb2_query_path_info,
5626 .query_reparse_tag = smb2_query_reparse_tag,
5627 .get_srv_inum = smb2_get_srv_inum,
5628 .query_file_info = smb2_query_file_info,
5629 .set_path_size = smb2_set_path_size,
5630 .set_file_size = smb2_set_file_size,
5631 .set_file_info = smb2_set_file_info,
5632 .set_compression = smb2_set_compression,
5633 .mkdir = smb2_mkdir,
5634 .mkdir_setinfo = smb2_mkdir_setinfo,
5635 .posix_mkdir = smb311_posix_mkdir,
5636 .rmdir = smb2_rmdir,
5637 .unlink = smb2_unlink,
5638 .rename = smb2_rename_path,
5639 .create_hardlink = smb2_create_hardlink,
5640 .query_symlink = smb2_query_symlink,
5641 .query_mf_symlink = smb3_query_mf_symlink,
5642 .create_mf_symlink = smb3_create_mf_symlink,
5643 .open = smb2_open_file,
5644 .set_fid = smb2_set_fid,
5645 .close = smb2_close_file,
5646 .close_getattr = smb2_close_getattr,
5647 .flush = smb2_flush_file,
5648 .async_readv = smb2_async_readv,
5649 .async_writev = smb2_async_writev,
5650 .sync_read = smb2_sync_read,
5651 .sync_write = smb2_sync_write,
5652 .query_dir_first = smb2_query_dir_first,
5653 .query_dir_next = smb2_query_dir_next,
5654 .close_dir = smb2_close_dir,
5655 .calc_smb_size = smb2_calc_size,
5656 .is_status_pending = smb2_is_status_pending,
5657 .is_session_expired = smb2_is_session_expired,
5658 .oplock_response = smb2_oplock_response,
5659 .queryfs = smb311_queryfs,
5660 .mand_lock = smb2_mand_lock,
5661 .mand_unlock_range = smb2_unlock_range,
5662 .push_mand_locks = smb2_push_mandatory_locks,
5663 .get_lease_key = smb2_get_lease_key,
5664 .set_lease_key = smb2_set_lease_key,
5665 .new_lease_key = smb2_new_lease_key,
5666 .generate_signingkey = generate_smb311signingkey,
5667 .calc_signature = smb3_calc_signature,
5668 .set_integrity = smb3_set_integrity,
5669 .is_read_op = smb21_is_read_op,
5670 .set_oplock_level = smb3_set_oplock_level,
5671 .create_lease_buf = smb3_create_lease_buf,
5672 .parse_lease_buf = smb3_parse_lease_buf,
5673 .copychunk_range = smb2_copychunk_range,
5674 .duplicate_extents = smb2_duplicate_extents,
5675 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
5676 .wp_retry_size = smb2_wp_retry_size,
5677 .dir_needs_close = smb2_dir_needs_close,
5678 .fallocate = smb3_fallocate,
5679 .enum_snapshots = smb3_enum_snapshots,
5680 .notify = smb3_notify,
5681 .init_transform_rq = smb3_init_transform_rq,
5682 .is_transform_hdr = smb3_is_transform_hdr,
5683 .receive_transform = smb3_receive_transform,
5684 .get_dfs_refer = smb2_get_dfs_refer,
5685 .select_sectype = smb2_select_sectype,
5686 #ifdef CONFIG_CIFS_XATTR
5687 .query_all_EAs = smb2_query_eas,
5688 .set_EA = smb2_set_ea,
5689 #endif /* CIFS_XATTR */
5690 .get_acl = get_smb2_acl,
5691 .get_acl_by_fid = get_smb2_acl_by_fid,
5692 .set_acl = set_smb2_acl,
5693 .next_header = smb2_next_header,
5694 .ioctl_query_info = smb2_ioctl_query_info,
5695 .make_node = smb2_make_node,
5696 .fiemap = smb3_fiemap,
5697 .llseek = smb3_llseek,
5698 .is_status_io_timeout = smb2_is_status_io_timeout,
5699 .is_network_name_deleted = smb2_is_network_name_deleted,
5702 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5703 struct smb_version_values smb20_values = {
5704 .version_string = SMB20_VERSION_STRING,
5705 .protocol_id = SMB20_PROT_ID,
5706 .req_capabilities = 0, /* MBZ */
5707 .large_lock_type = 0,
5708 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5709 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5710 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5711 .header_size = sizeof(struct smb2_hdr),
5712 .header_preamble_size = 0,
5713 .max_header_size = MAX_SMB2_HDR_SIZE,
5714 .read_rsp_size = sizeof(struct smb2_read_rsp),
5715 .lock_cmd = SMB2_LOCK,
5717 .cap_nt_find = SMB2_NT_FIND,
5718 .cap_large_files = SMB2_LARGE_FILES,
5719 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5720 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5721 .create_lease_size = sizeof(struct create_lease),
5723 #endif /* ALLOW_INSECURE_LEGACY */
5725 struct smb_version_values smb21_values = {
5726 .version_string = SMB21_VERSION_STRING,
5727 .protocol_id = SMB21_PROT_ID,
5728 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
5729 .large_lock_type = 0,
5730 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5731 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5732 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5733 .header_size = sizeof(struct smb2_hdr),
5734 .header_preamble_size = 0,
5735 .max_header_size = MAX_SMB2_HDR_SIZE,
5736 .read_rsp_size = sizeof(struct smb2_read_rsp),
5737 .lock_cmd = SMB2_LOCK,
5739 .cap_nt_find = SMB2_NT_FIND,
5740 .cap_large_files = SMB2_LARGE_FILES,
5741 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5742 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5743 .create_lease_size = sizeof(struct create_lease),
5746 struct smb_version_values smb3any_values = {
5747 .version_string = SMB3ANY_VERSION_STRING,
5748 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5749 .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,
5750 .large_lock_type = 0,
5751 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5752 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5753 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5754 .header_size = sizeof(struct smb2_hdr),
5755 .header_preamble_size = 0,
5756 .max_header_size = MAX_SMB2_HDR_SIZE,
5757 .read_rsp_size = sizeof(struct smb2_read_rsp),
5758 .lock_cmd = SMB2_LOCK,
5760 .cap_nt_find = SMB2_NT_FIND,
5761 .cap_large_files = SMB2_LARGE_FILES,
5762 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5763 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5764 .create_lease_size = sizeof(struct create_lease_v2),
5767 struct smb_version_values smbdefault_values = {
5768 .version_string = SMBDEFAULT_VERSION_STRING,
5769 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5770 .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,
5771 .large_lock_type = 0,
5772 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5773 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5774 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5775 .header_size = sizeof(struct smb2_hdr),
5776 .header_preamble_size = 0,
5777 .max_header_size = MAX_SMB2_HDR_SIZE,
5778 .read_rsp_size = sizeof(struct smb2_read_rsp),
5779 .lock_cmd = SMB2_LOCK,
5781 .cap_nt_find = SMB2_NT_FIND,
5782 .cap_large_files = SMB2_LARGE_FILES,
5783 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5784 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5785 .create_lease_size = sizeof(struct create_lease_v2),
5788 struct smb_version_values smb30_values = {
5789 .version_string = SMB30_VERSION_STRING,
5790 .protocol_id = SMB30_PROT_ID,
5791 .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,
5792 .large_lock_type = 0,
5793 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5794 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5795 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5796 .header_size = sizeof(struct smb2_hdr),
5797 .header_preamble_size = 0,
5798 .max_header_size = MAX_SMB2_HDR_SIZE,
5799 .read_rsp_size = sizeof(struct smb2_read_rsp),
5800 .lock_cmd = SMB2_LOCK,
5802 .cap_nt_find = SMB2_NT_FIND,
5803 .cap_large_files = SMB2_LARGE_FILES,
5804 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5805 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5806 .create_lease_size = sizeof(struct create_lease_v2),
5809 struct smb_version_values smb302_values = {
5810 .version_string = SMB302_VERSION_STRING,
5811 .protocol_id = SMB302_PROT_ID,
5812 .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,
5813 .large_lock_type = 0,
5814 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5815 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5816 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5817 .header_size = sizeof(struct smb2_hdr),
5818 .header_preamble_size = 0,
5819 .max_header_size = MAX_SMB2_HDR_SIZE,
5820 .read_rsp_size = sizeof(struct smb2_read_rsp),
5821 .lock_cmd = SMB2_LOCK,
5823 .cap_nt_find = SMB2_NT_FIND,
5824 .cap_large_files = SMB2_LARGE_FILES,
5825 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5826 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5827 .create_lease_size = sizeof(struct create_lease_v2),
5830 struct smb_version_values smb311_values = {
5831 .version_string = SMB311_VERSION_STRING,
5832 .protocol_id = SMB311_PROT_ID,
5833 .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,
5834 .large_lock_type = 0,
5835 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5836 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5837 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5838 .header_size = sizeof(struct smb2_hdr),
5839 .header_preamble_size = 0,
5840 .max_header_size = MAX_SMB2_HDR_SIZE,
5841 .read_rsp_size = sizeof(struct smb2_read_rsp),
5842 .lock_cmd = SMB2_LOCK,
5844 .cap_nt_find = SMB2_NT_FIND,
5845 .cap_large_files = SMB2_LARGE_FILES,
5846 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5847 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5848 .create_lease_size = sizeof(struct create_lease_v2),