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 server->oplock_credits = server->echo_credits = 0;
38 switch (server->credits) {
42 server->echoes = false;
43 server->oplocks = false;
46 server->echoes = true;
47 server->oplocks = false;
48 server->echo_credits = 1;
51 server->echoes = true;
53 server->oplocks = true;
54 server->oplock_credits = 1;
56 server->oplocks = false;
58 server->echo_credits = 1;
60 server->credits -= server->echo_credits + server->oplock_credits;
61 return server->credits + server->echo_credits + server->oplock_credits;
65 smb2_add_credits(struct TCP_Server_Info *server,
66 const struct cifs_credits *credits, const int optype)
69 int scredits, in_flight;
70 unsigned int add = credits->value;
71 unsigned int instance = credits->instance;
72 bool reconnect_detected = false;
73 bool reconnect_with_invalid_credits = false;
75 spin_lock(&server->req_lock);
76 val = server->ops->get_credits_field(server, optype);
78 /* eg found case where write overlapping reconnect messed up credits */
79 if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0))
80 reconnect_with_invalid_credits = true;
82 if ((instance == 0) || (instance == server->reconnect_instance))
85 reconnect_detected = true;
88 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
89 pr_warn_once("server overflowed SMB3 credits\n");
90 trace_smb3_overflow_credits(server->CurrentMid,
91 server->conn_id, server->hostname, *val,
92 add, server->in_flight);
95 if (server->in_flight == 0 &&
96 ((optype & CIFS_OP_MASK) != CIFS_NEG_OP) &&
97 ((optype & CIFS_OP_MASK) != CIFS_SESS_OP))
98 rc = change_conf(server);
100 * Sometimes server returns 0 credits on oplock break ack - we need to
101 * rebalance credits in this case.
103 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
105 if (server->credits > 1) {
107 server->oplock_credits++;
111 in_flight = server->in_flight;
112 spin_unlock(&server->req_lock);
113 wake_up(&server->request_q);
115 if (reconnect_detected) {
116 trace_smb3_reconnect_detected(server->CurrentMid,
117 server->conn_id, server->hostname, scredits, add, in_flight);
119 cifs_dbg(FYI, "trying to put %d credits from the old server instance %d\n",
123 if (reconnect_with_invalid_credits) {
124 trace_smb3_reconnect_with_invalid_credits(server->CurrentMid,
125 server->conn_id, server->hostname, scredits, add, in_flight);
126 cifs_dbg(FYI, "Negotiate operation when server credits is non-zero. Optype: %d, server credits: %d, credits added: %d\n",
127 optype, scredits, add);
130 spin_lock(&server->srv_lock);
131 if (server->tcpStatus == CifsNeedReconnect
132 || server->tcpStatus == CifsExiting) {
133 spin_unlock(&server->srv_lock);
136 spin_unlock(&server->srv_lock);
140 /* change_conf hasn't been executed */
143 cifs_server_dbg(VFS, "Possible client or server bug - zero credits\n");
146 cifs_server_dbg(VFS, "disabling echoes and oplocks\n");
149 cifs_dbg(FYI, "disabling oplocks\n");
152 /* change_conf rebalanced credits for different types */
156 trace_smb3_add_credits(server->CurrentMid,
157 server->conn_id, server->hostname, scredits, add, in_flight);
158 cifs_dbg(FYI, "%s: added %u credits total=%d\n", __func__, add, scredits);
162 smb2_set_credits(struct TCP_Server_Info *server, const int val)
164 int scredits, in_flight;
166 spin_lock(&server->req_lock);
167 server->credits = val;
169 server->reconnect_instance++;
170 scredits = server->credits;
171 in_flight = server->in_flight;
172 spin_unlock(&server->req_lock);
174 trace_smb3_set_credits(server->CurrentMid,
175 server->conn_id, server->hostname, scredits, val, in_flight);
176 cifs_dbg(FYI, "%s: set %u credits\n", __func__, val);
178 /* don't log while holding the lock */
180 cifs_dbg(FYI, "set credits to 1 due to smb2 reconnect\n");
184 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
188 return &server->echo_credits;
190 return &server->oplock_credits;
192 return &server->credits;
197 smb2_get_credits(struct mid_q_entry *mid)
199 return mid->credits_received;
203 smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
204 unsigned int *num, struct cifs_credits *credits)
207 unsigned int scredits, in_flight;
209 spin_lock(&server->req_lock);
211 if (server->credits <= 0) {
212 spin_unlock(&server->req_lock);
213 cifs_num_waiters_inc(server);
214 rc = wait_event_killable(server->request_q,
215 has_credits(server, &server->credits, 1));
216 cifs_num_waiters_dec(server);
219 spin_lock(&server->req_lock);
221 spin_unlock(&server->req_lock);
222 spin_lock(&server->srv_lock);
223 if (server->tcpStatus == CifsExiting) {
224 spin_unlock(&server->srv_lock);
227 spin_unlock(&server->srv_lock);
229 spin_lock(&server->req_lock);
230 scredits = server->credits;
231 /* can deadlock with reopen */
233 *num = SMB2_MAX_BUFFER_SIZE;
235 credits->instance = 0;
239 /* leave some credits for reopen and other ops */
241 *num = min_t(unsigned int, size,
242 scredits * SMB2_MAX_BUFFER_SIZE);
245 DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
246 credits->instance = server->reconnect_instance;
247 server->credits -= credits->value;
249 if (server->in_flight > server->max_in_flight)
250 server->max_in_flight = server->in_flight;
254 scredits = server->credits;
255 in_flight = server->in_flight;
256 spin_unlock(&server->req_lock);
258 trace_smb3_wait_credits(server->CurrentMid,
259 server->conn_id, server->hostname, scredits, -(credits->value), in_flight);
260 cifs_dbg(FYI, "%s: removed %u credits total=%d\n",
261 __func__, credits->value, scredits);
267 smb2_adjust_credits(struct TCP_Server_Info *server,
268 struct cifs_credits *credits,
269 const unsigned int payload_size)
271 int new_val = DIV_ROUND_UP(payload_size, SMB2_MAX_BUFFER_SIZE);
272 int scredits, in_flight;
274 if (!credits->value || credits->value == new_val)
277 if (credits->value < new_val) {
278 trace_smb3_too_many_credits(server->CurrentMid,
279 server->conn_id, server->hostname, 0, credits->value - new_val, 0);
280 cifs_server_dbg(VFS, "request has less credits (%d) than required (%d)",
281 credits->value, new_val);
286 spin_lock(&server->req_lock);
288 if (server->reconnect_instance != credits->instance) {
289 scredits = server->credits;
290 in_flight = server->in_flight;
291 spin_unlock(&server->req_lock);
293 trace_smb3_reconnect_detected(server->CurrentMid,
294 server->conn_id, server->hostname, scredits,
295 credits->value - new_val, in_flight);
296 cifs_server_dbg(VFS, "trying to return %d credits to old session\n",
297 credits->value - new_val);
301 server->credits += credits->value - new_val;
302 scredits = server->credits;
303 in_flight = server->in_flight;
304 spin_unlock(&server->req_lock);
305 wake_up(&server->request_q);
307 trace_smb3_adj_credits(server->CurrentMid,
308 server->conn_id, server->hostname, scredits,
309 credits->value - new_val, in_flight);
310 cifs_dbg(FYI, "%s: adjust added %u credits total=%d\n",
311 __func__, credits->value - new_val, scredits);
313 credits->value = new_val;
319 smb2_get_next_mid(struct TCP_Server_Info *server)
322 /* for SMB2 we need the current value */
323 spin_lock(&server->mid_lock);
324 mid = server->CurrentMid++;
325 spin_unlock(&server->mid_lock);
330 smb2_revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
332 spin_lock(&server->mid_lock);
333 if (server->CurrentMid >= val)
334 server->CurrentMid -= val;
335 spin_unlock(&server->mid_lock);
338 static struct mid_q_entry *
339 __smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue)
341 struct mid_q_entry *mid;
342 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
343 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
345 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
346 cifs_server_dbg(VFS, "Encrypted frame parsing not supported yet\n");
350 spin_lock(&server->mid_lock);
351 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
352 if ((mid->mid == wire_mid) &&
353 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
354 (mid->command == shdr->Command)) {
355 kref_get(&mid->refcount);
357 list_del_init(&mid->qhead);
358 mid->mid_flags |= MID_DELETED;
360 spin_unlock(&server->mid_lock);
364 spin_unlock(&server->mid_lock);
368 static struct mid_q_entry *
369 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
371 return __smb2_find_mid(server, buf, false);
374 static struct mid_q_entry *
375 smb2_find_dequeue_mid(struct TCP_Server_Info *server, char *buf)
377 return __smb2_find_mid(server, buf, true);
381 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
383 #ifdef CONFIG_CIFS_DEBUG2
384 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
386 cifs_server_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
387 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
388 shdr->Id.SyncId.ProcessId);
389 cifs_server_dbg(VFS, "smb buf %p len %u\n", buf,
390 server->ops->calc_smb_size(buf));
395 smb2_need_neg(struct TCP_Server_Info *server)
397 return server->max_read == 0;
401 smb2_negotiate(const unsigned int xid,
402 struct cifs_ses *ses,
403 struct TCP_Server_Info *server)
407 spin_lock(&server->mid_lock);
408 server->CurrentMid = 0;
409 spin_unlock(&server->mid_lock);
410 rc = SMB2_negotiate(xid, ses, server);
411 /* BB we probably don't need to retry with modern servers */
418 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
420 struct TCP_Server_Info *server = tcon->ses->server;
423 /* start with specified wsize, or default */
424 wsize = ctx->wsize ? ctx->wsize : CIFS_DEFAULT_IOSIZE;
425 wsize = min_t(unsigned int, wsize, server->max_write);
426 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
427 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
433 smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
435 struct TCP_Server_Info *server = tcon->ses->server;
438 /* start with specified wsize, or default */
439 wsize = ctx->wsize ? ctx->wsize : SMB3_DEFAULT_IOSIZE;
440 wsize = min_t(unsigned int, wsize, server->max_write);
441 #ifdef CONFIG_CIFS_SMB_DIRECT
445 * Account for SMB2 data transfer packet header and
446 * possible encryption header
448 wsize = min_t(unsigned int,
450 server->smbd_conn->max_fragmented_send_size -
451 SMB2_READWRITE_PDU_HEADER_SIZE -
452 sizeof(struct smb2_transform_hdr));
454 wsize = min_t(unsigned int,
455 wsize, server->smbd_conn->max_readwrite_size);
458 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
459 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
465 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
467 struct TCP_Server_Info *server = tcon->ses->server;
470 /* start with specified rsize, or default */
471 rsize = ctx->rsize ? ctx->rsize : CIFS_DEFAULT_IOSIZE;
472 rsize = min_t(unsigned int, rsize, server->max_read);
474 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
475 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
481 smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
483 struct TCP_Server_Info *server = tcon->ses->server;
486 /* start with specified rsize, or default */
487 rsize = ctx->rsize ? ctx->rsize : SMB3_DEFAULT_IOSIZE;
488 rsize = min_t(unsigned int, rsize, server->max_read);
489 #ifdef CONFIG_CIFS_SMB_DIRECT
493 * Account for SMB2 data transfer packet header and
494 * possible encryption header
496 rsize = min_t(unsigned int,
498 server->smbd_conn->max_fragmented_recv_size -
499 SMB2_READWRITE_PDU_HEADER_SIZE -
500 sizeof(struct smb2_transform_hdr));
502 rsize = min_t(unsigned int,
503 rsize, server->smbd_conn->max_readwrite_size);
507 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
508 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
514 parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
515 size_t buf_len, struct cifs_ses *ses, bool in_mount)
517 struct network_interface_info_ioctl_rsp *p;
518 struct sockaddr_in *addr4;
519 struct sockaddr_in6 *addr6;
520 struct iface_info_ipv4 *p4;
521 struct iface_info_ipv6 *p6;
522 struct cifs_server_iface *info = NULL, *iface = NULL, *niface = NULL;
523 struct cifs_server_iface tmp_iface;
529 bytes_left = buf_len;
532 spin_lock(&ses->iface_lock);
533 /* do not query too frequently, this time with lock held */
534 if (ses->iface_last_update &&
535 time_before(jiffies, ses->iface_last_update +
536 (SMB_INTERFACE_POLL_INTERVAL * HZ))) {
537 spin_unlock(&ses->iface_lock);
542 * Go through iface_list and do kref_put to remove
543 * any unused ifaces. ifaces in use will be removed
544 * when the last user calls a kref_put on it
546 list_for_each_entry_safe(iface, niface, &ses->iface_list,
548 iface->is_active = 0;
549 kref_put(&iface->refcount, release_iface);
552 spin_unlock(&ses->iface_lock);
555 * Samba server e.g. can return an empty interface list in some cases,
556 * which would only be a problem if we were requesting multichannel
558 if (bytes_left == 0) {
559 /* avoid spamming logs every 10 minutes, so log only in mount */
560 if ((ses->chan_max > 1) && in_mount)
562 "multichannel not available\n"
563 "Empty network interface list returned by server %s\n",
564 ses->server->hostname);
569 while (bytes_left >= sizeof(*p)) {
570 memset(&tmp_iface, 0, sizeof(tmp_iface));
571 tmp_iface.speed = le64_to_cpu(p->LinkSpeed);
572 tmp_iface.rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE) ? 1 : 0;
573 tmp_iface.rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE) ? 1 : 0;
577 * The kernel and wire socket structures have the same
578 * layout and use network byte order but make the
579 * conversion explicit in case either one changes.
582 addr4 = (struct sockaddr_in *)&tmp_iface.sockaddr;
583 p4 = (struct iface_info_ipv4 *)p->Buffer;
584 addr4->sin_family = AF_INET;
585 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
587 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
588 addr4->sin_port = cpu_to_be16(CIFS_PORT);
590 cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
594 addr6 = (struct sockaddr_in6 *)&tmp_iface.sockaddr;
595 p6 = (struct iface_info_ipv6 *)p->Buffer;
596 addr6->sin6_family = AF_INET6;
597 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
599 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
600 addr6->sin6_flowinfo = 0;
601 addr6->sin6_scope_id = 0;
602 addr6->sin6_port = cpu_to_be16(CIFS_PORT);
604 cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
609 "%s: skipping unsupported socket family\n",
615 * The iface_list is assumed to be sorted by speed.
616 * Check if the new interface exists in that list.
617 * NEVER change iface. it could be in use.
618 * Add a new one instead
620 spin_lock(&ses->iface_lock);
621 list_for_each_entry_safe(iface, niface, &ses->iface_list,
623 ret = iface_cmp(iface, &tmp_iface);
625 /* just get a ref so that it doesn't get picked/freed */
626 iface->is_active = 1;
627 kref_get(&iface->refcount);
629 spin_unlock(&ses->iface_lock);
631 } else if (ret < 0) {
632 /* all remaining ifaces are slower */
633 kref_get(&iface->refcount);
637 spin_unlock(&ses->iface_lock);
639 /* no match. insert the entry in the list */
640 info = kmalloc(sizeof(struct cifs_server_iface),
646 memcpy(info, &tmp_iface, sizeof(tmp_iface));
648 /* add this new entry to the list */
649 kref_init(&info->refcount);
652 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, ses->iface_count);
653 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
654 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
655 le32_to_cpu(p->Capability));
657 spin_lock(&ses->iface_lock);
658 if (!list_entry_is_head(iface, &ses->iface_list, iface_head)) {
659 list_add_tail(&info->iface_head, &iface->iface_head);
660 kref_put(&iface->refcount, release_iface);
662 list_add_tail(&info->iface_head, &ses->iface_list);
665 spin_unlock(&ses->iface_lock);
666 ses->iface_last_update = jiffies;
669 next = le32_to_cpu(p->Next);
671 bytes_left -= sizeof(*p);
674 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
679 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
684 /* Azure rounds the buffer size up 8, to a 16 byte boundary */
685 if ((bytes_left > 8) || p->Next)
686 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
689 if (!ses->iface_count) {
699 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon, bool in_mount)
702 unsigned int ret_data_len = 0;
703 struct network_interface_info_ioctl_rsp *out_buf = NULL;
704 struct cifs_ses *ses = tcon->ses;
706 /* do not query too frequently */
707 if (ses->iface_last_update &&
708 time_before(jiffies, ses->iface_last_update +
709 (SMB_INTERFACE_POLL_INTERVAL * HZ)))
712 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
713 FSCTL_QUERY_NETWORK_INTERFACE_INFO,
714 NULL /* no data input */, 0 /* no data input */,
715 CIFSMaxBufSize, (char **)&out_buf, &ret_data_len);
716 if (rc == -EOPNOTSUPP) {
718 "server does not support query network interfaces\n");
720 } else if (rc != 0) {
721 cifs_tcon_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
725 rc = parse_server_interfaces(out_buf, ret_data_len, ses, in_mount);
735 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
736 struct cifs_sb_info *cifs_sb)
739 __le16 srch_path = 0; /* Null - open root of share */
740 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
741 struct cifs_open_parms oparms;
743 struct cached_fid *cfid = NULL;
745 oparms = (struct cifs_open_parms) {
748 .desired_access = FILE_READ_ATTRIBUTES,
749 .disposition = FILE_OPEN,
750 .create_options = cifs_create_options(cifs_sb, 0),
754 rc = open_cached_dir(xid, tcon, "", cifs_sb, false, &cfid);
756 memcpy(&fid, &cfid->fid, sizeof(struct cifs_fid));
758 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
763 SMB3_request_interfaces(xid, tcon, true /* called during mount */);
765 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
766 FS_ATTRIBUTE_INFORMATION);
767 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
768 FS_DEVICE_INFORMATION);
769 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
770 FS_VOLUME_INFORMATION);
771 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
772 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
774 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
776 close_cached_dir(cfid);
780 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
781 struct cifs_sb_info *cifs_sb)
784 __le16 srch_path = 0; /* Null - open root of share */
785 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
786 struct cifs_open_parms oparms;
789 oparms = (struct cifs_open_parms) {
792 .desired_access = FILE_READ_ATTRIBUTES,
793 .disposition = FILE_OPEN,
794 .create_options = cifs_create_options(cifs_sb, 0),
798 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
803 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
804 FS_ATTRIBUTE_INFORMATION);
805 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
806 FS_DEVICE_INFORMATION);
807 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
811 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
812 struct cifs_sb_info *cifs_sb, const char *full_path)
815 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
816 int err_buftype = CIFS_NO_BUFFER;
817 struct cifs_open_parms oparms;
818 struct kvec err_iov = {};
820 struct cached_fid *cfid;
824 rc = open_cached_dir(xid, tcon, full_path, cifs_sb, true, &cfid);
826 if (cfid->has_lease) {
827 close_cached_dir(cfid);
830 close_cached_dir(cfid);
833 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
837 oparms = (struct cifs_open_parms) {
840 .desired_access = FILE_READ_ATTRIBUTES,
841 .disposition = FILE_OPEN,
842 .create_options = cifs_create_options(cifs_sb, 0),
846 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
847 &err_iov, &err_buftype);
849 struct smb2_hdr *hdr = err_iov.iov_base;
851 if (unlikely(!hdr || err_buftype == CIFS_NO_BUFFER))
854 if (rc != -EREMOTE && hdr->Status == STATUS_OBJECT_NAME_INVALID) {
855 rc2 = cifs_inval_name_dfs_link_error(xid, tcon, cifs_sb,
864 if (rc == -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) && cifs_sb &&
865 (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS))
870 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
873 free_rsp_buf(err_buftype, err_iov.iov_base);
878 static int smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
879 struct cifs_sb_info *cifs_sb, const char *full_path,
880 u64 *uniqueid, struct cifs_open_info_data *data)
882 *uniqueid = le64_to_cpu(data->fi.IndexNumber);
886 static int smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
887 struct cifsFileInfo *cfile, struct cifs_open_info_data *data)
889 struct cifs_fid *fid = &cfile->fid;
891 if (cfile->symlink_target) {
892 data->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
893 if (!data->symlink_target)
896 return SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, &data->fi);
899 #ifdef CONFIG_CIFS_XATTR
901 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
902 struct smb2_file_full_ea_info *src, size_t src_size,
903 const unsigned char *ea_name)
906 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
908 size_t buf_size = dst_size;
909 size_t name_len, value_len, user_name_len;
911 while (src_size > 0) {
912 name_len = (size_t)src->ea_name_length;
913 value_len = (size_t)le16_to_cpu(src->ea_value_length);
918 if (src_size < 8 + name_len + 1 + value_len) {
919 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
924 name = &src->ea_data[0];
925 value = &src->ea_data[src->ea_name_length + 1];
928 if (ea_name_len == name_len &&
929 memcmp(ea_name, name, name_len) == 0) {
933 if (dst_size < value_len) {
937 memcpy(dst, value, value_len);
941 /* 'user.' plus a terminating null */
942 user_name_len = 5 + 1 + name_len;
945 /* skip copy - calc size only */
947 } else if (dst_size >= user_name_len) {
948 dst_size -= user_name_len;
949 memcpy(dst, "user.", 5);
951 memcpy(dst, src->ea_data, name_len);
957 /* stop before overrun buffer */
963 if (!src->next_entry_offset)
966 if (src_size < le32_to_cpu(src->next_entry_offset)) {
967 /* stop before overrun buffer */
971 src_size -= le32_to_cpu(src->next_entry_offset);
972 src = (void *)((char *)src +
973 le32_to_cpu(src->next_entry_offset));
976 /* didn't find the named attribute */
985 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
986 const unsigned char *path, const unsigned char *ea_name,
987 char *ea_data, size_t buf_size,
988 struct cifs_sb_info *cifs_sb)
991 struct kvec rsp_iov = {NULL, 0};
992 int buftype = CIFS_NO_BUFFER;
993 struct smb2_query_info_rsp *rsp;
994 struct smb2_file_full_ea_info *info = NULL;
996 rc = smb2_query_info_compound(xid, tcon, path,
998 FILE_FULL_EA_INFORMATION,
1001 MAX_SMB2_CREATE_RESPONSE_SIZE -
1002 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1003 &rsp_iov, &buftype, cifs_sb);
1006 * If ea_name is NULL (listxattr) and there are no EAs,
1007 * return 0 as it's not an error. Otherwise, the specified
1008 * ea_name was not found.
1010 if (!ea_name && rc == -ENODATA)
1015 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
1016 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1017 le32_to_cpu(rsp->OutputBufferLength),
1019 sizeof(struct smb2_file_full_ea_info));
1023 info = (struct smb2_file_full_ea_info *)(
1024 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1025 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
1026 le32_to_cpu(rsp->OutputBufferLength), ea_name);
1029 free_rsp_buf(buftype, rsp_iov.iov_base);
1035 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
1036 const char *path, const char *ea_name, const void *ea_value,
1037 const __u16 ea_value_len, const struct nls_table *nls_codepage,
1038 struct cifs_sb_info *cifs_sb)
1040 struct cifs_ses *ses = tcon->ses;
1041 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1042 __le16 *utf16_path = NULL;
1043 int ea_name_len = strlen(ea_name);
1044 int flags = CIFS_CP_CREATE_CLOSE_OP;
1046 struct smb_rqst rqst[3];
1047 int resp_buftype[3];
1048 struct kvec rsp_iov[3];
1049 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1050 struct cifs_open_parms oparms;
1051 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1052 struct cifs_fid fid;
1053 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1054 unsigned int size[1];
1056 struct smb2_file_full_ea_info *ea = NULL;
1057 struct kvec close_iov[1];
1058 struct smb2_query_info_rsp *rsp;
1059 int rc, used_len = 0;
1061 if (smb3_encryption_required(tcon))
1062 flags |= CIFS_TRANSFORM_REQ;
1064 if (ea_name_len > 255)
1067 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1071 memset(rqst, 0, sizeof(rqst));
1072 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1073 memset(rsp_iov, 0, sizeof(rsp_iov));
1075 if (ses->server->ops->query_all_EAs) {
1077 rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1083 /* If we are adding a attribute we should first check
1084 * if there will be enough space available to store
1085 * the new EA. If not we should not add it since we
1086 * would not be able to even read the EAs back.
1088 rc = smb2_query_info_compound(xid, tcon, path,
1090 FILE_FULL_EA_INFORMATION,
1093 MAX_SMB2_CREATE_RESPONSE_SIZE -
1094 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1095 &rsp_iov[1], &resp_buftype[1], cifs_sb);
1097 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1098 used_len = le32_to_cpu(rsp->OutputBufferLength);
1100 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1101 resp_buftype[1] = CIFS_NO_BUFFER;
1102 memset(&rsp_iov[1], 0, sizeof(rsp_iov[1]));
1105 /* Use a fudge factor of 256 bytes in case we collide
1106 * with a different set_EAs command.
1108 if(CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1109 MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 <
1110 used_len + ea_name_len + ea_value_len + 1) {
1118 memset(&open_iov, 0, sizeof(open_iov));
1119 rqst[0].rq_iov = open_iov;
1120 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1122 oparms = (struct cifs_open_parms) {
1125 .desired_access = FILE_WRITE_EA,
1126 .disposition = FILE_OPEN,
1127 .create_options = cifs_create_options(cifs_sb, 0),
1131 rc = SMB2_open_init(tcon, server,
1132 &rqst[0], &oplock, &oparms, utf16_path);
1135 smb2_set_next_command(tcon, &rqst[0]);
1139 memset(&si_iov, 0, sizeof(si_iov));
1140 rqst[1].rq_iov = si_iov;
1141 rqst[1].rq_nvec = 1;
1143 len = sizeof(*ea) + ea_name_len + ea_value_len + 1;
1144 ea = kzalloc(len, GFP_KERNEL);
1150 ea->ea_name_length = ea_name_len;
1151 ea->ea_value_length = cpu_to_le16(ea_value_len);
1152 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
1153 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
1158 rc = SMB2_set_info_init(tcon, server,
1159 &rqst[1], COMPOUND_FID,
1160 COMPOUND_FID, current->tgid,
1161 FILE_FULL_EA_INFORMATION,
1162 SMB2_O_INFO_FILE, 0, data, size);
1165 smb2_set_next_command(tcon, &rqst[1]);
1166 smb2_set_related(&rqst[1]);
1170 memset(&close_iov, 0, sizeof(close_iov));
1171 rqst[2].rq_iov = close_iov;
1172 rqst[2].rq_nvec = 1;
1173 rc = SMB2_close_init(tcon, server,
1174 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1177 smb2_set_related(&rqst[2]);
1179 rc = compound_send_recv(xid, ses, server,
1181 resp_buftype, rsp_iov);
1182 /* no need to bump num_remote_opens because handle immediately closed */
1187 SMB2_open_free(&rqst[0]);
1188 SMB2_set_info_free(&rqst[1]);
1189 SMB2_close_free(&rqst[2]);
1190 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1191 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1192 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1198 smb2_can_echo(struct TCP_Server_Info *server)
1200 return server->echoes;
1204 smb2_clear_stats(struct cifs_tcon *tcon)
1208 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1209 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1210 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1215 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1217 seq_puts(m, "\n\tShare Capabilities:");
1218 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1219 seq_puts(m, " DFS,");
1220 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1221 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1222 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1223 seq_puts(m, " SCALEOUT,");
1224 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1225 seq_puts(m, " CLUSTER,");
1226 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1227 seq_puts(m, " ASYMMETRIC,");
1228 if (tcon->capabilities == 0)
1229 seq_puts(m, " None");
1230 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1231 seq_puts(m, " Aligned,");
1232 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1233 seq_puts(m, " Partition Aligned,");
1234 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1235 seq_puts(m, " SSD,");
1236 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1237 seq_puts(m, " TRIM-support,");
1239 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1240 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1241 if (tcon->perf_sector_size)
1242 seq_printf(m, "\tOptimal sector size: 0x%x",
1243 tcon->perf_sector_size);
1244 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1248 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1250 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1251 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1254 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1255 * totals (requests sent) since those SMBs are per-session not per tcon
1257 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1258 (long long)(tcon->bytes_read),
1259 (long long)(tcon->bytes_written));
1260 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1261 atomic_read(&tcon->num_local_opens),
1262 atomic_read(&tcon->num_remote_opens));
1263 seq_printf(m, "\nTreeConnects: %d total %d failed",
1264 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1265 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1266 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1267 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1268 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1269 seq_printf(m, "\nCreates: %d total %d failed",
1270 atomic_read(&sent[SMB2_CREATE_HE]),
1271 atomic_read(&failed[SMB2_CREATE_HE]));
1272 seq_printf(m, "\nCloses: %d total %d failed",
1273 atomic_read(&sent[SMB2_CLOSE_HE]),
1274 atomic_read(&failed[SMB2_CLOSE_HE]));
1275 seq_printf(m, "\nFlushes: %d total %d failed",
1276 atomic_read(&sent[SMB2_FLUSH_HE]),
1277 atomic_read(&failed[SMB2_FLUSH_HE]));
1278 seq_printf(m, "\nReads: %d total %d failed",
1279 atomic_read(&sent[SMB2_READ_HE]),
1280 atomic_read(&failed[SMB2_READ_HE]));
1281 seq_printf(m, "\nWrites: %d total %d failed",
1282 atomic_read(&sent[SMB2_WRITE_HE]),
1283 atomic_read(&failed[SMB2_WRITE_HE]));
1284 seq_printf(m, "\nLocks: %d total %d failed",
1285 atomic_read(&sent[SMB2_LOCK_HE]),
1286 atomic_read(&failed[SMB2_LOCK_HE]));
1287 seq_printf(m, "\nIOCTLs: %d total %d failed",
1288 atomic_read(&sent[SMB2_IOCTL_HE]),
1289 atomic_read(&failed[SMB2_IOCTL_HE]));
1290 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1291 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1292 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1293 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1294 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1295 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1296 seq_printf(m, "\nQueryInfos: %d total %d failed",
1297 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1298 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1299 seq_printf(m, "\nSetInfos: %d total %d failed",
1300 atomic_read(&sent[SMB2_SET_INFO_HE]),
1301 atomic_read(&failed[SMB2_SET_INFO_HE]));
1302 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1303 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1304 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1308 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1310 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1311 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1313 cfile->fid.persistent_fid = fid->persistent_fid;
1314 cfile->fid.volatile_fid = fid->volatile_fid;
1315 cfile->fid.access = fid->access;
1316 #ifdef CONFIG_CIFS_DEBUG2
1317 cfile->fid.mid = fid->mid;
1318 #endif /* CIFS_DEBUG2 */
1319 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1321 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1322 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1326 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1327 struct cifs_fid *fid)
1329 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1333 smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon,
1334 struct cifsFileInfo *cfile)
1336 struct smb2_file_network_open_info file_inf;
1337 struct inode *inode;
1340 rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid,
1341 cfile->fid.volatile_fid, &file_inf);
1345 inode = d_inode(cfile->dentry);
1347 spin_lock(&inode->i_lock);
1348 CIFS_I(inode)->time = jiffies;
1350 /* Creation time should not need to be updated on close */
1351 if (file_inf.LastWriteTime)
1352 inode->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime);
1353 if (file_inf.ChangeTime)
1354 inode->i_ctime = cifs_NTtimeToUnix(file_inf.ChangeTime);
1355 if (file_inf.LastAccessTime)
1356 inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime);
1359 * i_blocks is not related to (i_size / i_blksize),
1360 * but instead 512 byte (2**9) size is required for
1361 * calculating num blocks.
1363 if (le64_to_cpu(file_inf.AllocationSize) > 4096)
1365 (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9;
1367 /* End of file and Attributes should not have to be updated on close */
1368 spin_unlock(&inode->i_lock);
1372 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1373 u64 persistent_fid, u64 volatile_fid,
1374 struct copychunk_ioctl *pcchunk)
1377 unsigned int ret_data_len;
1378 struct resume_key_req *res_key;
1380 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1381 FSCTL_SRV_REQUEST_RESUME_KEY, NULL, 0 /* no input */,
1382 CIFSMaxBufSize, (char **)&res_key, &ret_data_len);
1384 if (rc == -EOPNOTSUPP) {
1385 pr_warn_once("Server share %s does not support copy range\n", tcon->tree_name);
1386 goto req_res_key_exit;
1388 cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1389 goto req_res_key_exit;
1391 if (ret_data_len < sizeof(struct resume_key_req)) {
1392 cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n");
1394 goto req_res_key_exit;
1396 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1404 struct smb_rqst rqst[3];
1405 struct kvec rsp_iov[3];
1406 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1407 struct kvec qi_iov[1];
1408 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
1409 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1410 struct kvec close_iov[1];
1414 smb2_ioctl_query_info(const unsigned int xid,
1415 struct cifs_tcon *tcon,
1416 struct cifs_sb_info *cifs_sb,
1417 __le16 *path, int is_dir,
1420 struct iqi_vars *vars;
1421 struct smb_rqst *rqst;
1422 struct kvec *rsp_iov;
1423 struct cifs_ses *ses = tcon->ses;
1424 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1425 char __user *arg = (char __user *)p;
1426 struct smb_query_info qi;
1427 struct smb_query_info __user *pqi;
1429 int flags = CIFS_CP_CREATE_CLOSE_OP;
1430 struct smb2_query_info_rsp *qi_rsp = NULL;
1431 struct smb2_ioctl_rsp *io_rsp = NULL;
1432 void *buffer = NULL;
1433 int resp_buftype[3];
1434 struct cifs_open_parms oparms;
1435 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1436 struct cifs_fid fid;
1437 unsigned int size[2];
1439 int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR;
1440 void (*free_req1_func)(struct smb_rqst *r);
1442 vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
1445 rqst = &vars->rqst[0];
1446 rsp_iov = &vars->rsp_iov[0];
1448 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1450 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info))) {
1454 if (qi.output_buffer_length > 1024) {
1459 if (!ses || !server) {
1464 if (smb3_encryption_required(tcon))
1465 flags |= CIFS_TRANSFORM_REQ;
1467 if (qi.output_buffer_length) {
1468 buffer = memdup_user(arg + sizeof(struct smb_query_info), qi.output_buffer_length);
1469 if (IS_ERR(buffer)) {
1470 rc = PTR_ERR(buffer);
1476 rqst[0].rq_iov = &vars->open_iov[0];
1477 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1479 oparms = (struct cifs_open_parms) {
1481 .disposition = FILE_OPEN,
1482 .create_options = cifs_create_options(cifs_sb, create_options),
1486 if (qi.flags & PASSTHRU_FSCTL) {
1487 switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1488 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1489 oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1491 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1492 oparms.desired_access = GENERIC_ALL;
1494 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1495 oparms.desired_access = GENERIC_READ;
1497 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1498 oparms.desired_access = GENERIC_WRITE;
1501 } else if (qi.flags & PASSTHRU_SET_INFO) {
1502 oparms.desired_access = GENERIC_WRITE;
1504 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1507 rc = SMB2_open_init(tcon, server,
1508 &rqst[0], &oplock, &oparms, path);
1510 goto free_output_buffer;
1511 smb2_set_next_command(tcon, &rqst[0]);
1514 if (qi.flags & PASSTHRU_FSCTL) {
1515 /* Can eventually relax perm check since server enforces too */
1516 if (!capable(CAP_SYS_ADMIN)) {
1520 rqst[1].rq_iov = &vars->io_iov[0];
1521 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1523 rc = SMB2_ioctl_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1524 qi.info_type, buffer, qi.output_buffer_length,
1525 CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1526 MAX_SMB2_CLOSE_RESPONSE_SIZE);
1527 free_req1_func = SMB2_ioctl_free;
1528 } else if (qi.flags == PASSTHRU_SET_INFO) {
1529 /* Can eventually relax perm check since server enforces too */
1530 if (!capable(CAP_SYS_ADMIN)) {
1534 if (qi.output_buffer_length < 8) {
1538 rqst[1].rq_iov = &vars->si_iov[0];
1539 rqst[1].rq_nvec = 1;
1541 /* MS-FSCC 2.4.13 FileEndOfFileInformation */
1545 rc = SMB2_set_info_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1546 current->tgid, FILE_END_OF_FILE_INFORMATION,
1547 SMB2_O_INFO_FILE, 0, data, size);
1548 free_req1_func = SMB2_set_info_free;
1549 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1550 rqst[1].rq_iov = &vars->qi_iov[0];
1551 rqst[1].rq_nvec = 1;
1553 rc = SMB2_query_info_init(tcon, server,
1554 &rqst[1], COMPOUND_FID,
1555 COMPOUND_FID, qi.file_info_class,
1556 qi.info_type, qi.additional_information,
1557 qi.input_buffer_length,
1558 qi.output_buffer_length, buffer);
1559 free_req1_func = SMB2_query_info_free;
1560 } else { /* unknown flags */
1561 cifs_tcon_dbg(VFS, "Invalid passthru query flags: 0x%x\n",
1568 smb2_set_next_command(tcon, &rqst[1]);
1569 smb2_set_related(&rqst[1]);
1572 rqst[2].rq_iov = &vars->close_iov[0];
1573 rqst[2].rq_nvec = 1;
1575 rc = SMB2_close_init(tcon, server,
1576 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1579 smb2_set_related(&rqst[2]);
1581 rc = compound_send_recv(xid, ses, server,
1583 resp_buftype, rsp_iov);
1587 /* No need to bump num_remote_opens since handle immediately closed */
1588 if (qi.flags & PASSTHRU_FSCTL) {
1589 pqi = (struct smb_query_info __user *)arg;
1590 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1591 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1592 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1593 if (qi.input_buffer_length > 0 &&
1594 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length
1595 > rsp_iov[1].iov_len) {
1600 if (copy_to_user(&pqi->input_buffer_length,
1601 &qi.input_buffer_length,
1602 sizeof(qi.input_buffer_length))) {
1607 if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1608 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1609 qi.input_buffer_length))
1612 pqi = (struct smb_query_info __user *)arg;
1613 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1614 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1615 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1616 if (copy_to_user(&pqi->input_buffer_length,
1617 &qi.input_buffer_length,
1618 sizeof(qi.input_buffer_length))) {
1623 if (copy_to_user(pqi + 1, qi_rsp->Buffer,
1624 qi.input_buffer_length))
1629 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1630 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1631 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1632 SMB2_close_free(&rqst[2]);
1634 free_req1_func(&rqst[1]);
1636 SMB2_open_free(&rqst[0]);
1645 smb2_copychunk_range(const unsigned int xid,
1646 struct cifsFileInfo *srcfile,
1647 struct cifsFileInfo *trgtfile, u64 src_off,
1648 u64 len, u64 dest_off)
1651 unsigned int ret_data_len;
1652 struct copychunk_ioctl *pcchunk;
1653 struct copychunk_ioctl_rsp *retbuf = NULL;
1654 struct cifs_tcon *tcon;
1655 int chunks_copied = 0;
1656 bool chunk_sizes_updated = false;
1657 ssize_t bytes_written, total_bytes_written = 0;
1659 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1660 if (pcchunk == NULL)
1663 cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
1664 /* Request a key from the server to identify the source of the copy */
1665 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1666 srcfile->fid.persistent_fid,
1667 srcfile->fid.volatile_fid, pcchunk);
1669 /* Note: request_res_key sets res_key null only if rc !=0 */
1673 /* For now array only one chunk long, will make more flexible later */
1674 pcchunk->ChunkCount = cpu_to_le32(1);
1675 pcchunk->Reserved = 0;
1676 pcchunk->Reserved2 = 0;
1678 tcon = tlink_tcon(trgtfile->tlink);
1681 pcchunk->SourceOffset = cpu_to_le64(src_off);
1682 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1684 cpu_to_le32(min_t(u64, len, tcon->max_bytes_chunk));
1686 /* Request server copy to target from src identified by key */
1689 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1690 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1691 (char *)pcchunk, sizeof(struct copychunk_ioctl),
1692 CIFSMaxBufSize, (char **)&retbuf, &ret_data_len);
1695 sizeof(struct copychunk_ioctl_rsp)) {
1696 cifs_tcon_dbg(VFS, "Invalid cchunk response size\n");
1700 if (retbuf->TotalBytesWritten == 0) {
1701 cifs_dbg(FYI, "no bytes copied\n");
1706 * Check if server claimed to write more than we asked
1708 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1709 le32_to_cpu(pcchunk->Length)) {
1710 cifs_tcon_dbg(VFS, "Invalid copy chunk response\n");
1714 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1715 cifs_tcon_dbg(VFS, "Invalid num chunks written\n");
1721 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1722 src_off += bytes_written;
1723 dest_off += bytes_written;
1724 len -= bytes_written;
1725 total_bytes_written += bytes_written;
1727 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1728 le32_to_cpu(retbuf->ChunksWritten),
1729 le32_to_cpu(retbuf->ChunkBytesWritten),
1731 } else if (rc == -EINVAL) {
1732 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1735 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1736 le32_to_cpu(retbuf->ChunksWritten),
1737 le32_to_cpu(retbuf->ChunkBytesWritten),
1738 le32_to_cpu(retbuf->TotalBytesWritten));
1741 * Check if this is the first request using these sizes,
1742 * (ie check if copy succeed once with original sizes
1743 * and check if the server gave us different sizes after
1744 * we already updated max sizes on previous request).
1745 * if not then why is the server returning an error now
1747 if ((chunks_copied != 0) || chunk_sizes_updated)
1750 /* Check that server is not asking us to grow size */
1751 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1752 tcon->max_bytes_chunk)
1753 tcon->max_bytes_chunk =
1754 le32_to_cpu(retbuf->ChunkBytesWritten);
1756 goto cchunk_out; /* server gave us bogus size */
1758 /* No need to change MaxChunks since already set to 1 */
1759 chunk_sizes_updated = true;
1770 return total_bytes_written;
1774 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1775 struct cifs_fid *fid)
1777 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1781 smb2_read_data_offset(char *buf)
1783 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1785 return rsp->DataOffset;
1789 smb2_read_data_length(char *buf, bool in_remaining)
1791 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1794 return le32_to_cpu(rsp->DataRemaining);
1796 return le32_to_cpu(rsp->DataLength);
1801 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1802 struct cifs_io_parms *parms, unsigned int *bytes_read,
1803 char **buf, int *buf_type)
1805 parms->persistent_fid = pfid->persistent_fid;
1806 parms->volatile_fid = pfid->volatile_fid;
1807 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1811 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1812 struct cifs_io_parms *parms, unsigned int *written,
1813 struct kvec *iov, unsigned long nr_segs)
1816 parms->persistent_fid = pfid->persistent_fid;
1817 parms->volatile_fid = pfid->volatile_fid;
1818 return SMB2_write(xid, parms, written, iov, nr_segs);
1821 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1822 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1823 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1825 struct cifsInodeInfo *cifsi;
1828 cifsi = CIFS_I(inode);
1830 /* if file already sparse don't bother setting sparse again */
1831 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1832 return true; /* already sparse */
1834 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1835 return true; /* already not sparse */
1838 * Can't check for sparse support on share the usual way via the
1839 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1840 * since Samba server doesn't set the flag on the share, yet
1841 * supports the set sparse FSCTL and returns sparse correctly
1842 * in the file attributes. If we fail setting sparse though we
1843 * mark that server does not support sparse files for this share
1844 * to avoid repeatedly sending the unsupported fsctl to server
1845 * if the file is repeatedly extended.
1847 if (tcon->broken_sparse_sup)
1850 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1851 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1852 &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
1854 tcon->broken_sparse_sup = true;
1855 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1860 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1862 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1868 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1869 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1871 __le64 eof = cpu_to_le64(size);
1872 struct inode *inode;
1875 * If extending file more than one page make sparse. Many Linux fs
1876 * make files sparse by default when extending via ftruncate
1878 inode = d_inode(cfile->dentry);
1880 if (!set_alloc && (size > inode->i_size + 8192)) {
1881 __u8 set_sparse = 1;
1883 /* whether set sparse succeeds or not, extend the file */
1884 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1887 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1888 cfile->fid.volatile_fid, cfile->pid, &eof);
1892 smb2_duplicate_extents(const unsigned int xid,
1893 struct cifsFileInfo *srcfile,
1894 struct cifsFileInfo *trgtfile, u64 src_off,
1895 u64 len, u64 dest_off)
1898 unsigned int ret_data_len;
1899 struct inode *inode;
1900 struct duplicate_extents_to_file dup_ext_buf;
1901 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1903 /* server fileays advertise duplicate extent support with this flag */
1904 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1905 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1908 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1909 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1910 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1911 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1912 dup_ext_buf.ByteCount = cpu_to_le64(len);
1913 cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
1914 src_off, dest_off, len);
1916 inode = d_inode(trgtfile->dentry);
1917 if (inode->i_size < dest_off + len) {
1918 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1920 goto duplicate_extents_out;
1923 * Although also could set plausible allocation size (i_blocks)
1924 * here in addition to setting the file size, in reflink
1925 * it is likely that the target file is sparse. Its allocation
1926 * size will be queried on next revalidate, but it is important
1927 * to make sure that file's cached size is updated immediately
1929 cifs_setsize(inode, dest_off + len);
1931 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1932 trgtfile->fid.volatile_fid,
1933 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1934 (char *)&dup_ext_buf,
1935 sizeof(struct duplicate_extents_to_file),
1936 CIFSMaxBufSize, NULL,
1939 if (ret_data_len > 0)
1940 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
1942 duplicate_extents_out:
1947 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1948 struct cifsFileInfo *cfile)
1950 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1951 cfile->fid.volatile_fid);
1955 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
1956 struct cifsFileInfo *cfile)
1958 struct fsctl_set_integrity_information_req integr_info;
1959 unsigned int ret_data_len;
1961 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
1962 integr_info.Flags = 0;
1963 integr_info.Reserved = 0;
1965 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1966 cfile->fid.volatile_fid,
1967 FSCTL_SET_INTEGRITY_INFORMATION,
1968 (char *)&integr_info,
1969 sizeof(struct fsctl_set_integrity_information_req),
1970 CIFSMaxBufSize, NULL,
1975 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
1976 #define GMT_TOKEN_SIZE 50
1978 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
1981 * Input buffer contains (empty) struct smb_snapshot array with size filled in
1982 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
1985 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
1986 struct cifsFileInfo *cfile, void __user *ioc_buf)
1988 char *retbuf = NULL;
1989 unsigned int ret_data_len = 0;
1991 u32 max_response_size;
1992 struct smb_snapshot_array snapshot_in;
1995 * On the first query to enumerate the list of snapshots available
1996 * for this volume the buffer begins with 0 (number of snapshots
1997 * which can be returned is zero since at that point we do not know
1998 * how big the buffer needs to be). On the second query,
1999 * it (ret_data_len) is set to number of snapshots so we can
2000 * know to set the maximum response size larger (see below).
2002 if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
2006 * Note that for snapshot queries that servers like Azure expect that
2007 * the first query be minimal size (and just used to get the number/size
2008 * of previous versions) so response size must be specified as EXACTLY
2009 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
2012 if (ret_data_len == 0)
2013 max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
2015 max_response_size = CIFSMaxBufSize;
2017 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2018 cfile->fid.volatile_fid,
2019 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
2020 NULL, 0 /* no input data */, max_response_size,
2023 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
2028 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
2030 if (copy_from_user(&snapshot_in, ioc_buf,
2031 sizeof(struct smb_snapshot_array))) {
2038 * Check for min size, ie not large enough to fit even one GMT
2039 * token (snapshot). On the first ioctl some users may pass in
2040 * smaller size (or zero) to simply get the size of the array
2041 * so the user space caller can allocate sufficient memory
2042 * and retry the ioctl again with larger array size sufficient
2043 * to hold all of the snapshot GMT tokens on the second try.
2045 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
2046 ret_data_len = sizeof(struct smb_snapshot_array);
2049 * We return struct SRV_SNAPSHOT_ARRAY, followed by
2050 * the snapshot array (of 50 byte GMT tokens) each
2051 * representing an available previous version of the data
2053 if (ret_data_len > (snapshot_in.snapshot_array_size +
2054 sizeof(struct smb_snapshot_array)))
2055 ret_data_len = snapshot_in.snapshot_array_size +
2056 sizeof(struct smb_snapshot_array);
2058 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
2069 smb3_notify(const unsigned int xid, struct file *pfile,
2070 void __user *ioc_buf, bool return_changes)
2072 struct smb3_notify_info notify;
2073 struct smb3_notify_info __user *pnotify_buf;
2074 struct dentry *dentry = pfile->f_path.dentry;
2075 struct inode *inode = file_inode(pfile);
2076 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2077 struct cifs_open_parms oparms;
2078 struct cifs_fid fid;
2079 struct cifs_tcon *tcon;
2080 const unsigned char *path;
2081 char *returned_ioctl_info = NULL;
2082 void *page = alloc_dentry_path();
2083 __le16 *utf16_path = NULL;
2084 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2088 path = build_path_from_dentry(dentry, page);
2094 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2095 if (utf16_path == NULL) {
2100 if (return_changes) {
2101 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify_info))) {
2106 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify))) {
2110 notify.data_len = 0;
2113 tcon = cifs_sb_master_tcon(cifs_sb);
2114 oparms = (struct cifs_open_parms) {
2117 .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
2118 .disposition = FILE_OPEN,
2119 .create_options = cifs_create_options(cifs_sb, 0),
2123 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
2128 rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid,
2129 notify.watch_tree, notify.completion_filter,
2130 notify.data_len, &returned_ioctl_info, &ret_len);
2132 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2134 cifs_dbg(FYI, "change notify for path %s rc %d\n", path, rc);
2135 if (return_changes && (ret_len > 0) && (notify.data_len > 0)) {
2136 if (ret_len > notify.data_len)
2137 ret_len = notify.data_len;
2138 pnotify_buf = (struct smb3_notify_info __user *)ioc_buf;
2139 if (copy_to_user(pnotify_buf->notify_data, returned_ioctl_info, ret_len))
2141 else if (copy_to_user(&pnotify_buf->data_len, &ret_len, sizeof(ret_len)))
2144 kfree(returned_ioctl_info);
2146 free_dentry_path(page);
2152 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
2153 const char *path, struct cifs_sb_info *cifs_sb,
2154 struct cifs_fid *fid, __u16 search_flags,
2155 struct cifs_search_info *srch_inf)
2158 struct smb_rqst rqst[2];
2159 struct kvec rsp_iov[2];
2160 int resp_buftype[2];
2161 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2162 struct kvec qd_iov[SMB2_QUERY_DIRECTORY_IOV_SIZE];
2164 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2165 struct cifs_open_parms oparms;
2166 struct smb2_query_directory_rsp *qd_rsp = NULL;
2167 struct smb2_create_rsp *op_rsp = NULL;
2168 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2169 int retry_count = 0;
2171 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2175 if (smb3_encryption_required(tcon))
2176 flags |= CIFS_TRANSFORM_REQ;
2178 memset(rqst, 0, sizeof(rqst));
2179 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
2180 memset(rsp_iov, 0, sizeof(rsp_iov));
2183 memset(&open_iov, 0, sizeof(open_iov));
2184 rqst[0].rq_iov = open_iov;
2185 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2187 oparms = (struct cifs_open_parms) {
2190 .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
2191 .disposition = FILE_OPEN,
2192 .create_options = cifs_create_options(cifs_sb, 0),
2196 rc = SMB2_open_init(tcon, server,
2197 &rqst[0], &oplock, &oparms, utf16_path);
2200 smb2_set_next_command(tcon, &rqst[0]);
2202 /* Query directory */
2203 srch_inf->entries_in_buffer = 0;
2204 srch_inf->index_of_last_entry = 2;
2206 memset(&qd_iov, 0, sizeof(qd_iov));
2207 rqst[1].rq_iov = qd_iov;
2208 rqst[1].rq_nvec = SMB2_QUERY_DIRECTORY_IOV_SIZE;
2210 rc = SMB2_query_directory_init(xid, tcon, server,
2212 COMPOUND_FID, COMPOUND_FID,
2213 0, srch_inf->info_level);
2217 smb2_set_related(&rqst[1]);
2220 rc = compound_send_recv(xid, tcon->ses, server,
2222 resp_buftype, rsp_iov);
2224 if (rc == -EAGAIN && retry_count++ < 10)
2227 /* If the open failed there is nothing to do */
2228 op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
2229 if (op_rsp == NULL || op_rsp->hdr.Status != STATUS_SUCCESS) {
2230 cifs_dbg(FYI, "query_dir_first: open failed rc=%d\n", rc);
2233 fid->persistent_fid = op_rsp->PersistentFileId;
2234 fid->volatile_fid = op_rsp->VolatileFileId;
2236 /* Anything else than ENODATA means a genuine error */
2237 if (rc && rc != -ENODATA) {
2238 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2239 cifs_dbg(FYI, "query_dir_first: query directory failed rc=%d\n", rc);
2240 trace_smb3_query_dir_err(xid, fid->persistent_fid,
2241 tcon->tid, tcon->ses->Suid, 0, 0, rc);
2245 atomic_inc(&tcon->num_remote_opens);
2247 qd_rsp = (struct smb2_query_directory_rsp *)rsp_iov[1].iov_base;
2248 if (qd_rsp->hdr.Status == STATUS_NO_MORE_FILES) {
2249 trace_smb3_query_dir_done(xid, fid->persistent_fid,
2250 tcon->tid, tcon->ses->Suid, 0, 0);
2251 srch_inf->endOfSearch = true;
2256 rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1],
2259 trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid,
2260 tcon->ses->Suid, 0, 0, rc);
2263 resp_buftype[1] = CIFS_NO_BUFFER;
2265 trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid,
2266 tcon->ses->Suid, 0, srch_inf->entries_in_buffer);
2270 SMB2_open_free(&rqst[0]);
2271 SMB2_query_directory_free(&rqst[1]);
2272 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2273 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2278 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
2279 struct cifs_fid *fid, __u16 search_flags,
2280 struct cifs_search_info *srch_inf)
2282 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
2283 fid->volatile_fid, 0, srch_inf);
2287 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
2288 struct cifs_fid *fid)
2290 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2294 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2295 * the number of credits and return true. Otherwise - return false.
2298 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
2300 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2301 int scredits, in_flight;
2303 if (shdr->Status != STATUS_PENDING)
2306 if (shdr->CreditRequest) {
2307 spin_lock(&server->req_lock);
2308 server->credits += le16_to_cpu(shdr->CreditRequest);
2309 scredits = server->credits;
2310 in_flight = server->in_flight;
2311 spin_unlock(&server->req_lock);
2312 wake_up(&server->request_q);
2314 trace_smb3_pend_credits(server->CurrentMid,
2315 server->conn_id, server->hostname, scredits,
2316 le16_to_cpu(shdr->CreditRequest), in_flight);
2317 cifs_dbg(FYI, "%s: status pending add %u credits total=%d\n",
2318 __func__, le16_to_cpu(shdr->CreditRequest), scredits);
2325 smb2_is_session_expired(char *buf)
2327 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2329 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
2330 shdr->Status != STATUS_USER_SESSION_DELETED)
2333 trace_smb3_ses_expired(le32_to_cpu(shdr->Id.SyncId.TreeId),
2334 le64_to_cpu(shdr->SessionId),
2335 le16_to_cpu(shdr->Command),
2336 le64_to_cpu(shdr->MessageId));
2337 cifs_dbg(FYI, "Session expired or deleted\n");
2343 smb2_is_status_io_timeout(char *buf)
2345 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2347 if (shdr->Status == STATUS_IO_TIMEOUT)
2354 smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server)
2356 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2357 struct TCP_Server_Info *pserver;
2358 struct cifs_ses *ses;
2359 struct cifs_tcon *tcon;
2361 if (shdr->Status != STATUS_NETWORK_NAME_DELETED)
2364 /* If server is a channel, select the primary channel */
2365 pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
2367 spin_lock(&cifs_tcp_ses_lock);
2368 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
2369 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
2370 if (tcon->tid == le32_to_cpu(shdr->Id.SyncId.TreeId)) {
2371 spin_lock(&tcon->tc_lock);
2372 tcon->need_reconnect = true;
2373 spin_unlock(&tcon->tc_lock);
2374 spin_unlock(&cifs_tcp_ses_lock);
2375 pr_warn_once("Server share %s deleted.\n",
2381 spin_unlock(&cifs_tcp_ses_lock);
2385 smb2_oplock_response(struct cifs_tcon *tcon, __u64 persistent_fid,
2386 __u64 volatile_fid, __u16 net_fid, struct cifsInodeInfo *cinode)
2388 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
2389 return SMB2_lease_break(0, tcon, cinode->lease_key,
2390 smb2_get_lease_state(cinode));
2392 return SMB2_oplock_break(0, tcon, persistent_fid, volatile_fid,
2393 CIFS_CACHE_READ(cinode) ? 1 : 0);
2397 smb2_set_related(struct smb_rqst *rqst)
2399 struct smb2_hdr *shdr;
2401 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2403 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2406 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2409 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
2412 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
2414 struct smb2_hdr *shdr;
2415 struct cifs_ses *ses = tcon->ses;
2416 struct TCP_Server_Info *server = ses->server;
2417 unsigned long len = smb_rqst_len(server, rqst);
2420 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2422 cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2426 /* SMB headers in a compound are 8 byte aligned. */
2428 /* No padding needed */
2432 num_padding = 8 - (len & 7);
2433 if (!smb3_encryption_required(tcon)) {
2435 * If we do not have encryption then we can just add an extra
2436 * iov for the padding.
2438 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2439 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2444 * We can not add a small padding iov for the encryption case
2445 * because the encryption framework can not handle the padding
2447 * We have to flatten this into a single buffer and add
2448 * the padding to it.
2450 for (i = 1; i < rqst->rq_nvec; i++) {
2451 memcpy(rqst->rq_iov[0].iov_base +
2452 rqst->rq_iov[0].iov_len,
2453 rqst->rq_iov[i].iov_base,
2454 rqst->rq_iov[i].iov_len);
2455 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2457 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2459 rqst->rq_iov[0].iov_len += num_padding;
2465 shdr->NextCommand = cpu_to_le32(len);
2469 * Passes the query info response back to the caller on success.
2470 * Caller need to free this with free_rsp_buf().
2473 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2474 const char *path, u32 desired_access,
2475 u32 class, u32 type, u32 output_len,
2476 struct kvec *rsp, int *buftype,
2477 struct cifs_sb_info *cifs_sb)
2479 struct cifs_ses *ses = tcon->ses;
2480 struct TCP_Server_Info *server = cifs_pick_channel(ses);
2481 int flags = CIFS_CP_CREATE_CLOSE_OP;
2482 struct smb_rqst rqst[3];
2483 int resp_buftype[3];
2484 struct kvec rsp_iov[3];
2485 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2486 struct kvec qi_iov[1];
2487 struct kvec close_iov[1];
2488 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2489 struct cifs_open_parms oparms;
2490 struct cifs_fid fid;
2493 struct cached_fid *cfid = NULL;
2497 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2501 if (smb3_encryption_required(tcon))
2502 flags |= CIFS_TRANSFORM_REQ;
2504 memset(rqst, 0, sizeof(rqst));
2505 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2506 memset(rsp_iov, 0, sizeof(rsp_iov));
2509 * We can only call this for things we know are directories.
2511 if (!strcmp(path, ""))
2512 open_cached_dir(xid, tcon, path, cifs_sb, false,
2513 &cfid); /* cfid null if open dir failed */
2515 memset(&open_iov, 0, sizeof(open_iov));
2516 rqst[0].rq_iov = open_iov;
2517 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2519 oparms = (struct cifs_open_parms) {
2522 .desired_access = desired_access,
2523 .disposition = FILE_OPEN,
2524 .create_options = cifs_create_options(cifs_sb, 0),
2528 rc = SMB2_open_init(tcon, server,
2529 &rqst[0], &oplock, &oparms, utf16_path);
2532 smb2_set_next_command(tcon, &rqst[0]);
2534 memset(&qi_iov, 0, sizeof(qi_iov));
2535 rqst[1].rq_iov = qi_iov;
2536 rqst[1].rq_nvec = 1;
2539 rc = SMB2_query_info_init(tcon, server,
2541 cfid->fid.persistent_fid,
2542 cfid->fid.volatile_fid,
2547 rc = SMB2_query_info_init(tcon, server,
2558 smb2_set_next_command(tcon, &rqst[1]);
2559 smb2_set_related(&rqst[1]);
2562 memset(&close_iov, 0, sizeof(close_iov));
2563 rqst[2].rq_iov = close_iov;
2564 rqst[2].rq_nvec = 1;
2566 rc = SMB2_close_init(tcon, server,
2567 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2570 smb2_set_related(&rqst[2]);
2573 rc = compound_send_recv(xid, ses, server,
2575 &resp_buftype[1], &rsp_iov[1]);
2577 rc = compound_send_recv(xid, ses, server,
2579 resp_buftype, rsp_iov);
2582 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2583 if (rc == -EREMCHG) {
2584 tcon->need_reconnect = true;
2585 pr_warn_once("server share %s deleted\n",
2591 *buftype = resp_buftype[1];
2595 SMB2_open_free(&rqst[0]);
2596 SMB2_query_info_free(&rqst[1]);
2597 SMB2_close_free(&rqst[2]);
2598 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2599 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2601 close_cached_dir(cfid);
2606 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2607 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2609 struct smb2_query_info_rsp *rsp;
2610 struct smb2_fs_full_size_info *info = NULL;
2611 struct kvec rsp_iov = {NULL, 0};
2612 int buftype = CIFS_NO_BUFFER;
2616 rc = smb2_query_info_compound(xid, tcon, "",
2617 FILE_READ_ATTRIBUTES,
2618 FS_FULL_SIZE_INFORMATION,
2619 SMB2_O_INFO_FILESYSTEM,
2620 sizeof(struct smb2_fs_full_size_info),
2621 &rsp_iov, &buftype, cifs_sb);
2625 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2626 buf->f_type = SMB2_SUPER_MAGIC;
2627 info = (struct smb2_fs_full_size_info *)(
2628 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2629 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2630 le32_to_cpu(rsp->OutputBufferLength),
2632 sizeof(struct smb2_fs_full_size_info));
2634 smb2_copy_fs_info_to_kstatfs(info, buf);
2637 free_rsp_buf(buftype, rsp_iov.iov_base);
2642 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2643 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2646 __le16 srch_path = 0; /* Null - open root of share */
2647 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2648 struct cifs_open_parms oparms;
2649 struct cifs_fid fid;
2651 if (!tcon->posix_extensions)
2652 return smb2_queryfs(xid, tcon, cifs_sb, buf);
2654 oparms = (struct cifs_open_parms) {
2657 .desired_access = FILE_READ_ATTRIBUTES,
2658 .disposition = FILE_OPEN,
2659 .create_options = cifs_create_options(cifs_sb, 0),
2663 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
2668 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2669 fid.volatile_fid, buf);
2670 buf->f_type = SMB2_SUPER_MAGIC;
2671 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2676 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2678 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2679 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2683 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2684 __u64 length, __u32 type, int lock, int unlock, bool wait)
2686 if (unlock && !lock)
2687 type = SMB2_LOCKFLAG_UNLOCK;
2688 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2689 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2690 current->tgid, length, offset, type, wait);
2694 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2696 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2700 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2702 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2706 smb2_new_lease_key(struct cifs_fid *fid)
2708 generate_random_uuid(fid->lease_key);
2712 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2713 const char *search_name,
2714 struct dfs_info3_param **target_nodes,
2715 unsigned int *num_of_nodes,
2716 const struct nls_table *nls_codepage, int remap)
2719 __le16 *utf16_path = NULL;
2720 int utf16_path_len = 0;
2721 struct cifs_tcon *tcon;
2722 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2723 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2724 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2725 int retry_count = 0;
2727 cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name);
2730 * Try to use the IPC tcon, otherwise just use any
2732 tcon = ses->tcon_ipc;
2734 spin_lock(&cifs_tcp_ses_lock);
2735 tcon = list_first_entry_or_null(&ses->tcon_list,
2740 spin_unlock(&cifs_tcp_ses_lock);
2744 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2750 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2752 nls_codepage, remap);
2758 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2759 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2765 /* Highest DFS referral version understood */
2766 dfs_req->MaxReferralLevel = DFS_VERSION;
2768 /* Path to resolve in an UTF-16 null-terminated string */
2769 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2772 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2773 FSCTL_DFS_GET_REFERRALS,
2774 (char *)dfs_req, dfs_req_size, CIFSMaxBufSize,
2775 (char **)&dfs_rsp, &dfs_rsp_size);
2776 if (!is_retryable_error(rc))
2778 usleep_range(512, 2048);
2779 } while (++retry_count < 5);
2782 if (!is_retryable_error(rc) && rc != -ENOENT && rc != -EOPNOTSUPP)
2783 cifs_tcon_dbg(VFS, "%s: ioctl error: rc=%d\n", __func__, rc);
2787 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
2788 num_of_nodes, target_nodes,
2789 nls_codepage, remap, search_name,
2790 true /* is_unicode */);
2792 cifs_tcon_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc);
2797 if (tcon && !tcon->ipc) {
2798 /* ipc tcons are not refcounted */
2799 spin_lock(&cifs_tcp_ses_lock);
2801 /* tc_count can never go negative */
2802 WARN_ON(tcon->tc_count < 0);
2803 spin_unlock(&cifs_tcp_ses_lock);
2812 parse_reparse_posix(struct reparse_posix_data *symlink_buf,
2813 u32 plen, char **target_path,
2814 struct cifs_sb_info *cifs_sb)
2818 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
2819 len = le16_to_cpu(symlink_buf->ReparseDataLength);
2821 if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
2822 cifs_dbg(VFS, "%lld not a supported symlink type\n",
2823 le64_to_cpu(symlink_buf->InodeType));
2827 *target_path = cifs_strndup_from_utf16(
2828 symlink_buf->PathBuffer,
2829 len, true, cifs_sb->local_nls);
2830 if (!(*target_path))
2833 convert_delimiter(*target_path, '/');
2834 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2840 parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
2841 u32 plen, char **target_path,
2842 struct cifs_sb_info *cifs_sb)
2844 unsigned int sub_len;
2845 unsigned int sub_offset;
2847 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */
2849 sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset);
2850 sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength);
2851 if (sub_offset + 20 > plen ||
2852 sub_offset + sub_len + 20 > plen) {
2853 cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
2857 *target_path = cifs_strndup_from_utf16(
2858 symlink_buf->PathBuffer + sub_offset,
2859 sub_len, true, cifs_sb->local_nls);
2860 if (!(*target_path))
2863 convert_delimiter(*target_path, '/');
2864 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2870 parse_reparse_point(struct reparse_data_buffer *buf,
2871 u32 plen, char **target_path,
2872 struct cifs_sb_info *cifs_sb)
2874 if (plen < sizeof(struct reparse_data_buffer)) {
2875 cifs_dbg(VFS, "reparse buffer is too small. Must be at least 8 bytes but was %d\n",
2880 if (plen < le16_to_cpu(buf->ReparseDataLength) +
2881 sizeof(struct reparse_data_buffer)) {
2882 cifs_dbg(VFS, "srv returned invalid reparse buf length: %d\n",
2887 /* See MS-FSCC 2.1.2 */
2888 switch (le32_to_cpu(buf->ReparseTag)) {
2889 case IO_REPARSE_TAG_NFS:
2890 return parse_reparse_posix(
2891 (struct reparse_posix_data *)buf,
2892 plen, target_path, cifs_sb);
2893 case IO_REPARSE_TAG_SYMLINK:
2894 return parse_reparse_symlink(
2895 (struct reparse_symlink_data_buffer *)buf,
2896 plen, target_path, cifs_sb);
2898 cifs_dbg(VFS, "srv returned unknown symlink buffer tag:0x%08x\n",
2899 le32_to_cpu(buf->ReparseTag));
2905 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
2906 struct cifs_sb_info *cifs_sb, const char *full_path,
2907 char **target_path, bool is_reparse_point)
2910 __le16 *utf16_path = NULL;
2911 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2912 struct cifs_open_parms oparms;
2913 struct cifs_fid fid;
2914 struct kvec err_iov = {NULL, 0};
2915 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2916 int flags = CIFS_CP_CREATE_CLOSE_OP;
2917 struct smb_rqst rqst[3];
2918 int resp_buftype[3];
2919 struct kvec rsp_iov[3];
2920 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2921 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2922 struct kvec close_iov[1];
2923 struct smb2_create_rsp *create_rsp;
2924 struct smb2_ioctl_rsp *ioctl_rsp;
2925 struct reparse_data_buffer *reparse_buf;
2926 int create_options = is_reparse_point ? OPEN_REPARSE_POINT : 0;
2929 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2931 *target_path = NULL;
2933 if (smb3_encryption_required(tcon))
2934 flags |= CIFS_TRANSFORM_REQ;
2936 memset(rqst, 0, sizeof(rqst));
2937 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2938 memset(rsp_iov, 0, sizeof(rsp_iov));
2940 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
2945 memset(&open_iov, 0, sizeof(open_iov));
2946 rqst[0].rq_iov = open_iov;
2947 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2949 oparms = (struct cifs_open_parms) {
2952 .desired_access = FILE_READ_ATTRIBUTES,
2953 .disposition = FILE_OPEN,
2954 .create_options = cifs_create_options(cifs_sb, create_options),
2958 rc = SMB2_open_init(tcon, server,
2959 &rqst[0], &oplock, &oparms, utf16_path);
2962 smb2_set_next_command(tcon, &rqst[0]);
2966 memset(&io_iov, 0, sizeof(io_iov));
2967 rqst[1].rq_iov = io_iov;
2968 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
2970 rc = SMB2_ioctl_init(tcon, server,
2971 &rqst[1], fid.persistent_fid,
2972 fid.volatile_fid, FSCTL_GET_REPARSE_POINT, NULL, 0,
2974 MAX_SMB2_CREATE_RESPONSE_SIZE -
2975 MAX_SMB2_CLOSE_RESPONSE_SIZE);
2979 smb2_set_next_command(tcon, &rqst[1]);
2980 smb2_set_related(&rqst[1]);
2984 memset(&close_iov, 0, sizeof(close_iov));
2985 rqst[2].rq_iov = close_iov;
2986 rqst[2].rq_nvec = 1;
2988 rc = SMB2_close_init(tcon, server,
2989 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2993 smb2_set_related(&rqst[2]);
2995 rc = compound_send_recv(xid, tcon->ses, server,
2997 resp_buftype, rsp_iov);
2999 create_rsp = rsp_iov[0].iov_base;
3000 if (create_rsp && create_rsp->hdr.Status)
3001 err_iov = rsp_iov[0];
3002 ioctl_rsp = rsp_iov[1].iov_base;
3005 * Open was successful and we got an ioctl response.
3007 if ((rc == 0) && (is_reparse_point)) {
3008 /* See MS-FSCC 2.3.23 */
3010 reparse_buf = (struct reparse_data_buffer *)
3011 ((char *)ioctl_rsp +
3012 le32_to_cpu(ioctl_rsp->OutputOffset));
3013 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3015 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3016 rsp_iov[1].iov_len) {
3017 cifs_tcon_dbg(VFS, "srv returned invalid ioctl len: %d\n",
3023 rc = parse_reparse_point(reparse_buf, plen, target_path,
3028 if (!rc || !err_iov.iov_base) {
3033 rc = smb2_parse_symlink_response(cifs_sb, &err_iov, target_path);
3036 cifs_dbg(FYI, "query symlink rc %d\n", rc);
3038 SMB2_open_free(&rqst[0]);
3039 SMB2_ioctl_free(&rqst[1]);
3040 SMB2_close_free(&rqst[2]);
3041 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3042 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3043 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3048 smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
3049 struct cifs_sb_info *cifs_sb, const char *full_path,
3053 __le16 *utf16_path = NULL;
3054 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3055 struct cifs_open_parms oparms;
3056 struct cifs_fid fid;
3057 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
3058 int flags = CIFS_CP_CREATE_CLOSE_OP;
3059 struct smb_rqst rqst[3];
3060 int resp_buftype[3];
3061 struct kvec rsp_iov[3];
3062 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
3063 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
3064 struct kvec close_iov[1];
3065 struct smb2_ioctl_rsp *ioctl_rsp;
3066 struct reparse_data_buffer *reparse_buf;
3069 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
3071 if (smb3_encryption_required(tcon))
3072 flags |= CIFS_TRANSFORM_REQ;
3074 memset(rqst, 0, sizeof(rqst));
3075 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
3076 memset(rsp_iov, 0, sizeof(rsp_iov));
3078 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
3083 * setup smb2open - TODO add optimization to call cifs_get_readable_path
3084 * to see if there is a handle already open that we can use
3086 memset(&open_iov, 0, sizeof(open_iov));
3087 rqst[0].rq_iov = open_iov;
3088 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
3090 oparms = (struct cifs_open_parms) {
3093 .desired_access = FILE_READ_ATTRIBUTES,
3094 .disposition = FILE_OPEN,
3095 .create_options = cifs_create_options(cifs_sb, OPEN_REPARSE_POINT),
3099 rc = SMB2_open_init(tcon, server,
3100 &rqst[0], &oplock, &oparms, utf16_path);
3103 smb2_set_next_command(tcon, &rqst[0]);
3107 memset(&io_iov, 0, sizeof(io_iov));
3108 rqst[1].rq_iov = io_iov;
3109 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3111 rc = SMB2_ioctl_init(tcon, server,
3112 &rqst[1], COMPOUND_FID,
3113 COMPOUND_FID, FSCTL_GET_REPARSE_POINT, NULL, 0,
3115 MAX_SMB2_CREATE_RESPONSE_SIZE -
3116 MAX_SMB2_CLOSE_RESPONSE_SIZE);
3120 smb2_set_next_command(tcon, &rqst[1]);
3121 smb2_set_related(&rqst[1]);
3125 memset(&close_iov, 0, sizeof(close_iov));
3126 rqst[2].rq_iov = close_iov;
3127 rqst[2].rq_nvec = 1;
3129 rc = SMB2_close_init(tcon, server,
3130 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3134 smb2_set_related(&rqst[2]);
3136 rc = compound_send_recv(xid, tcon->ses, server,
3138 resp_buftype, rsp_iov);
3140 ioctl_rsp = rsp_iov[1].iov_base;
3143 * Open was successful and we got an ioctl response.
3146 /* See MS-FSCC 2.3.23 */
3148 reparse_buf = (struct reparse_data_buffer *)
3149 ((char *)ioctl_rsp +
3150 le32_to_cpu(ioctl_rsp->OutputOffset));
3151 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3153 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3154 rsp_iov[1].iov_len) {
3155 cifs_tcon_dbg(FYI, "srv returned invalid ioctl len: %d\n",
3160 *tag = le32_to_cpu(reparse_buf->ReparseTag);
3165 SMB2_open_free(&rqst[0]);
3166 SMB2_ioctl_free(&rqst[1]);
3167 SMB2_close_free(&rqst[2]);
3168 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3169 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3170 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3174 static struct cifs_ntsd *
3175 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
3176 const struct cifs_fid *cifsfid, u32 *pacllen, u32 info)
3178 struct cifs_ntsd *pntsd = NULL;
3180 int rc = -EOPNOTSUPP;
3181 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3184 return ERR_CAST(tlink);
3187 cifs_dbg(FYI, "trying to get acl\n");
3189 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
3190 cifsfid->volatile_fid, (void **)&pntsd, pacllen,
3194 cifs_put_tlink(tlink);
3196 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3203 static struct cifs_ntsd *
3204 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
3205 const char *path, u32 *pacllen, u32 info)
3207 struct cifs_ntsd *pntsd = NULL;
3208 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3211 struct cifs_tcon *tcon;
3212 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3213 struct cifs_fid fid;
3214 struct cifs_open_parms oparms;
3217 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
3219 return ERR_CAST(tlink);
3221 tcon = tlink_tcon(tlink);
3224 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3231 oparms = (struct cifs_open_parms) {
3234 .desired_access = READ_CONTROL,
3235 .disposition = FILE_OPEN,
3237 * When querying an ACL, even if the file is a symlink
3238 * we want to open the source not the target, and so
3239 * the protocol requires that the client specify this
3240 * flag when opening a reparse point
3242 .create_options = cifs_create_options(cifs_sb, 0) |
3247 if (info & SACL_SECINFO)
3248 oparms.desired_access |= SYSTEM_SECURITY;
3250 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
3254 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3255 fid.volatile_fid, (void **)&pntsd, pacllen,
3257 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3260 cifs_put_tlink(tlink);
3263 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3270 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
3271 struct inode *inode, const char *path, int aclflag)
3273 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3275 int rc, access_flags = 0;
3276 struct cifs_tcon *tcon;
3277 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
3278 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3279 struct cifs_fid fid;
3280 struct cifs_open_parms oparms;
3283 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
3285 return PTR_ERR(tlink);
3287 tcon = tlink_tcon(tlink);
3290 if (aclflag & CIFS_ACL_OWNER || aclflag & CIFS_ACL_GROUP)
3291 access_flags |= WRITE_OWNER;
3292 if (aclflag & CIFS_ACL_SACL)
3293 access_flags |= SYSTEM_SECURITY;
3294 if (aclflag & CIFS_ACL_DACL)
3295 access_flags |= WRITE_DAC;
3297 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3304 oparms = (struct cifs_open_parms) {
3306 .desired_access = access_flags,
3307 .create_options = cifs_create_options(cifs_sb, 0),
3308 .disposition = FILE_OPEN,
3313 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
3317 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3318 fid.volatile_fid, pnntsd, acllen, aclflag);
3319 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3322 cifs_put_tlink(tlink);
3327 /* Retrieve an ACL from the server */
3328 static struct cifs_ntsd *
3329 get_smb2_acl(struct cifs_sb_info *cifs_sb,
3330 struct inode *inode, const char *path,
3331 u32 *pacllen, u32 info)
3333 struct cifs_ntsd *pntsd = NULL;
3334 struct cifsFileInfo *open_file = NULL;
3336 if (inode && !(info & SACL_SECINFO))
3337 open_file = find_readable_file(CIFS_I(inode), true);
3338 if (!open_file || (info & SACL_SECINFO))
3339 return get_smb2_acl_by_path(cifs_sb, path, pacllen, info);
3341 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen, info);
3342 cifsFileInfo_put(open_file);
3346 static long smb3_zero_data(struct file *file, struct cifs_tcon *tcon,
3347 loff_t offset, loff_t len, unsigned int xid)
3349 struct cifsFileInfo *cfile = file->private_data;
3350 struct file_zero_data_information fsctl_buf;
3352 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3354 fsctl_buf.FileOffset = cpu_to_le64(offset);
3355 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3357 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3358 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3360 sizeof(struct file_zero_data_information),
3364 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3365 loff_t offset, loff_t len, bool keep_size)
3367 struct cifs_ses *ses = tcon->ses;
3368 struct inode *inode = file_inode(file);
3369 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3370 struct cifsFileInfo *cfile = file->private_data;
3377 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3378 ses->Suid, offset, len);
3381 filemap_invalidate_lock(inode->i_mapping);
3384 * We zero the range through ioctl, so we need remove the page caches
3385 * first, otherwise the data may be inconsistent with the server.
3387 truncate_pagecache_range(inode, offset, offset + len - 1);
3389 /* if file not oplocked can't be sure whether asking to extend size */
3391 if (keep_size == false && !CIFS_CACHE_READ(cifsi))
3392 goto zero_range_exit;
3394 rc = smb3_zero_data(file, tcon, offset, len, xid);
3396 goto zero_range_exit;
3399 * do we also need to change the size of the file?
3401 if (keep_size == false && i_size_read(inode) < offset + len) {
3402 eof = cpu_to_le64(offset + len);
3403 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3404 cfile->fid.volatile_fid, cfile->pid, &eof);
3408 filemap_invalidate_unlock(inode->i_mapping);
3409 inode_unlock(inode);
3412 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
3413 ses->Suid, offset, len, rc);
3415 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
3416 ses->Suid, offset, len);
3420 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
3421 loff_t offset, loff_t len)
3423 struct inode *inode = file_inode(file);
3424 struct cifsFileInfo *cfile = file->private_data;
3425 struct file_zero_data_information fsctl_buf;
3428 __u8 set_sparse = 1;
3433 /* Need to make file sparse, if not already, before freeing range. */
3434 /* Consider adding equivalent for compressed since it could also work */
3435 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
3440 filemap_invalidate_lock(inode->i_mapping);
3442 * We implement the punch hole through ioctl, so we need remove the page
3443 * caches first, otherwise the data may be inconsistent with the server.
3445 truncate_pagecache_range(inode, offset, offset + len - 1);
3447 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3449 fsctl_buf.FileOffset = cpu_to_le64(offset);
3450 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3452 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3453 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3455 sizeof(struct file_zero_data_information),
3456 CIFSMaxBufSize, NULL, NULL);
3457 filemap_invalidate_unlock(inode->i_mapping);
3459 inode_unlock(inode);
3464 static int smb3_simple_fallocate_write_range(unsigned int xid,
3465 struct cifs_tcon *tcon,
3466 struct cifsFileInfo *cfile,
3467 loff_t off, loff_t len,
3470 struct cifs_io_parms io_parms = {0};
3475 io_parms.netfid = cfile->fid.netfid;
3476 io_parms.pid = current->tgid;
3477 io_parms.tcon = tcon;
3478 io_parms.persistent_fid = cfile->fid.persistent_fid;
3479 io_parms.volatile_fid = cfile->fid.volatile_fid;
3482 io_parms.offset = off;
3483 io_parms.length = len;
3484 if (io_parms.length > SMB2_MAX_BUFFER_SIZE)
3485 io_parms.length = SMB2_MAX_BUFFER_SIZE;
3486 /* iov[0] is reserved for smb header */
3487 iov[1].iov_base = buf;
3488 iov[1].iov_len = io_parms.length;
3489 rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
3501 static int smb3_simple_fallocate_range(unsigned int xid,
3502 struct cifs_tcon *tcon,
3503 struct cifsFileInfo *cfile,
3504 loff_t off, loff_t len)
3506 struct file_allocated_range_buffer in_data, *out_data = NULL, *tmp_data;
3512 in_data.file_offset = cpu_to_le64(off);
3513 in_data.length = cpu_to_le64(len);
3514 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3515 cfile->fid.volatile_fid,
3516 FSCTL_QUERY_ALLOCATED_RANGES,
3517 (char *)&in_data, sizeof(in_data),
3518 1024 * sizeof(struct file_allocated_range_buffer),
3519 (char **)&out_data, &out_data_len);
3523 buf = kzalloc(1024 * 1024, GFP_KERNEL);
3529 tmp_data = out_data;
3532 * The rest of the region is unmapped so write it all.
3534 if (out_data_len == 0) {
3535 rc = smb3_simple_fallocate_write_range(xid, tcon,
3536 cfile, off, len, buf);
3540 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3545 if (off < le64_to_cpu(tmp_data->file_offset)) {
3547 * We are at a hole. Write until the end of the region
3548 * or until the next allocated data,
3549 * whichever comes next.
3551 l = le64_to_cpu(tmp_data->file_offset) - off;
3554 rc = smb3_simple_fallocate_write_range(xid, tcon,
3555 cfile, off, l, buf);
3564 * We are at a section of allocated data, just skip forward
3565 * until the end of the data or the end of the region
3566 * we are supposed to fallocate, whichever comes first.
3568 l = le64_to_cpu(tmp_data->length);
3574 tmp_data = &tmp_data[1];
3575 out_data_len -= sizeof(struct file_allocated_range_buffer);
3585 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3586 loff_t off, loff_t len, bool keep_size)
3588 struct inode *inode;
3589 struct cifsInodeInfo *cifsi;
3590 struct cifsFileInfo *cfile = file->private_data;
3591 long rc = -EOPNOTSUPP;
3597 inode = d_inode(cfile->dentry);
3598 cifsi = CIFS_I(inode);
3600 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3601 tcon->ses->Suid, off, len);
3602 /* if file not oplocked can't be sure whether asking to extend size */
3603 if (!CIFS_CACHE_READ(cifsi))
3604 if (keep_size == false) {
3605 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3606 tcon->tid, tcon->ses->Suid, off, len, rc);
3612 * Extending the file
3614 if ((keep_size == false) && i_size_read(inode) < off + len) {
3615 rc = inode_newsize_ok(inode, off + len);
3619 if (cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)
3620 smb2_set_sparse(xid, tcon, cfile, inode, false);
3622 eof = cpu_to_le64(off + len);
3623 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3624 cfile->fid.volatile_fid, cfile->pid, &eof);
3626 cifsi->server_eof = off + len;
3627 cifs_setsize(inode, off + len);
3628 cifs_truncate_page(inode->i_mapping, inode->i_size);
3629 truncate_setsize(inode, off + len);
3635 * Files are non-sparse by default so falloc may be a no-op
3636 * Must check if file sparse. If not sparse, and since we are not
3637 * extending then no need to do anything since file already allocated
3639 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
3644 if (keep_size == true) {
3646 * We can not preallocate pages beyond the end of the file
3649 if (off >= i_size_read(inode)) {
3654 * For fallocates that are partially beyond the end of file,
3655 * clamp len so we only fallocate up to the end of file.
3657 if (off + len > i_size_read(inode)) {
3658 len = i_size_read(inode) - off;
3662 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3664 * At this point, we are trying to fallocate an internal
3665 * regions of a sparse file. Since smb2 does not have a
3666 * fallocate command we have two otions on how to emulate this.
3667 * We can either turn the entire file to become non-sparse
3668 * which we only do if the fallocate is for virtually
3669 * the whole file, or we can overwrite the region with zeroes
3670 * using SMB2_write, which could be prohibitevly expensive
3674 * We are only trying to fallocate a small region so
3675 * just write it with zero.
3677 if (len <= 1024 * 1024) {
3678 rc = smb3_simple_fallocate_range(xid, tcon, cfile,
3684 * Check if falloc starts within first few pages of file
3685 * and ends within a few pages of the end of file to
3686 * ensure that most of file is being forced to be
3687 * fallocated now. If so then setting whole file sparse
3688 * ie potentially making a few extra pages at the beginning
3689 * or end of the file non-sparse via set_sparse is harmless.
3691 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
3697 smb2_set_sparse(xid, tcon, cfile, inode, false);
3702 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3703 tcon->ses->Suid, off, len, rc);
3705 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3706 tcon->ses->Suid, off, len);
3712 static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
3713 loff_t off, loff_t len)
3717 struct inode *inode = file_inode(file);
3718 struct cifsFileInfo *cfile = file->private_data;
3719 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3727 old_eof = i_size_read(inode);
3728 if ((off >= old_eof) ||
3729 off + len >= old_eof) {
3734 filemap_invalidate_lock(inode->i_mapping);
3735 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof - 1);
3739 truncate_pagecache_range(inode, off, old_eof);
3741 rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
3742 old_eof - off - len, off);
3746 eof = cpu_to_le64(old_eof - len);
3747 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3748 cfile->fid.volatile_fid, cfile->pid, &eof);
3754 cifsi->server_eof = i_size_read(inode) - len;
3755 truncate_setsize(inode, cifsi->server_eof);
3756 fscache_resize_cookie(cifs_inode_cookie(inode), cifsi->server_eof);
3758 filemap_invalidate_unlock(inode->i_mapping);
3760 inode_unlock(inode);
3765 static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
3766 loff_t off, loff_t len)
3770 struct cifsFileInfo *cfile = file->private_data;
3771 struct inode *inode = file_inode(file);
3773 __u64 count, old_eof;
3779 old_eof = i_size_read(inode);
3780 if (off >= old_eof) {
3785 count = old_eof - off;
3786 eof = cpu_to_le64(old_eof + len);
3788 filemap_invalidate_lock(inode->i_mapping);
3789 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof + len - 1);
3792 truncate_pagecache_range(inode, off, old_eof);
3794 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3795 cfile->fid.volatile_fid, cfile->pid, &eof);
3799 rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len);
3803 rc = smb3_zero_data(file, tcon, off, len, xid);
3809 filemap_invalidate_unlock(inode->i_mapping);
3811 inode_unlock(inode);
3816 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3818 struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3819 struct cifsInodeInfo *cifsi;
3820 struct inode *inode;
3822 struct file_allocated_range_buffer in_data, *out_data = NULL;
3826 if (whence != SEEK_HOLE && whence != SEEK_DATA)
3827 return generic_file_llseek(file, offset, whence);
3829 inode = d_inode(cfile->dentry);
3830 cifsi = CIFS_I(inode);
3832 if (offset < 0 || offset >= i_size_read(inode))
3837 * We need to be sure that all dirty pages are written as they
3838 * might fill holes on the server.
3839 * Note that we also MUST flush any written pages since at least
3840 * some servers (Windows2016) will not reflect recent writes in
3841 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3843 wrcfile = find_writable_file(cifsi, FIND_WR_ANY);
3845 filemap_write_and_wait(inode->i_mapping);
3846 smb2_flush_file(xid, tcon, &wrcfile->fid);
3847 cifsFileInfo_put(wrcfile);
3850 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3851 if (whence == SEEK_HOLE)
3852 offset = i_size_read(inode);
3856 in_data.file_offset = cpu_to_le64(offset);
3857 in_data.length = cpu_to_le64(i_size_read(inode));
3859 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3860 cfile->fid.volatile_fid,
3861 FSCTL_QUERY_ALLOCATED_RANGES,
3862 (char *)&in_data, sizeof(in_data),
3863 sizeof(struct file_allocated_range_buffer),
3864 (char **)&out_data, &out_data_len);
3870 if (whence == SEEK_HOLE && out_data_len == 0)
3873 if (whence == SEEK_DATA && out_data_len == 0) {
3878 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3882 if (whence == SEEK_DATA) {
3883 offset = le64_to_cpu(out_data->file_offset);
3886 if (offset < le64_to_cpu(out_data->file_offset))
3889 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3895 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3900 static int smb3_fiemap(struct cifs_tcon *tcon,
3901 struct cifsFileInfo *cfile,
3902 struct fiemap_extent_info *fei, u64 start, u64 len)
3905 struct file_allocated_range_buffer in_data, *out_data;
3907 int i, num, rc, flags, last_blob;
3910 rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0);
3916 in_data.file_offset = cpu_to_le64(start);
3917 in_data.length = cpu_to_le64(len);
3919 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3920 cfile->fid.volatile_fid,
3921 FSCTL_QUERY_ALLOCATED_RANGES,
3922 (char *)&in_data, sizeof(in_data),
3923 1024 * sizeof(struct file_allocated_range_buffer),
3924 (char **)&out_data, &out_data_len);
3933 if (out_data_len && out_data_len < sizeof(struct file_allocated_range_buffer)) {
3937 if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3942 num = out_data_len / sizeof(struct file_allocated_range_buffer);
3943 for (i = 0; i < num; i++) {
3945 if (i == num - 1 && last_blob)
3946 flags |= FIEMAP_EXTENT_LAST;
3948 rc = fiemap_fill_next_extent(fei,
3949 le64_to_cpu(out_data[i].file_offset),
3950 le64_to_cpu(out_data[i].file_offset),
3951 le64_to_cpu(out_data[i].length),
3962 next = le64_to_cpu(out_data[num - 1].file_offset) +
3963 le64_to_cpu(out_data[num - 1].length);
3964 len = len - (next - start);
3975 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
3976 loff_t off, loff_t len)
3978 /* KEEP_SIZE already checked for by do_fallocate */
3979 if (mode & FALLOC_FL_PUNCH_HOLE)
3980 return smb3_punch_hole(file, tcon, off, len);
3981 else if (mode & FALLOC_FL_ZERO_RANGE) {
3982 if (mode & FALLOC_FL_KEEP_SIZE)
3983 return smb3_zero_range(file, tcon, off, len, true);
3984 return smb3_zero_range(file, tcon, off, len, false);
3985 } else if (mode == FALLOC_FL_KEEP_SIZE)
3986 return smb3_simple_falloc(file, tcon, off, len, true);
3987 else if (mode == FALLOC_FL_COLLAPSE_RANGE)
3988 return smb3_collapse_range(file, tcon, off, len);
3989 else if (mode == FALLOC_FL_INSERT_RANGE)
3990 return smb3_insert_range(file, tcon, off, len);
3992 return smb3_simple_falloc(file, tcon, off, len, false);
3998 smb2_downgrade_oplock(struct TCP_Server_Info *server,
3999 struct cifsInodeInfo *cinode, __u32 oplock,
4000 unsigned int epoch, bool *purge_cache)
4002 server->ops->set_oplock_level(cinode, oplock, 0, NULL);
4006 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4007 unsigned int epoch, bool *purge_cache);
4010 smb3_downgrade_oplock(struct TCP_Server_Info *server,
4011 struct cifsInodeInfo *cinode, __u32 oplock,
4012 unsigned int epoch, bool *purge_cache)
4014 unsigned int old_state = cinode->oplock;
4015 unsigned int old_epoch = cinode->epoch;
4016 unsigned int new_state;
4018 if (epoch > old_epoch) {
4019 smb21_set_oplock_level(cinode, oplock, 0, NULL);
4020 cinode->epoch = epoch;
4023 new_state = cinode->oplock;
4024 *purge_cache = false;
4026 if ((old_state & CIFS_CACHE_READ_FLG) != 0 &&
4027 (new_state & CIFS_CACHE_READ_FLG) == 0)
4028 *purge_cache = true;
4029 else if (old_state == new_state && (epoch - old_epoch > 1))
4030 *purge_cache = true;
4034 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4035 unsigned int epoch, bool *purge_cache)
4038 cinode->lease_granted = false;
4039 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
4041 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
4042 cinode->oplock = CIFS_CACHE_RHW_FLG;
4043 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
4044 &cinode->netfs.inode);
4045 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
4046 cinode->oplock = CIFS_CACHE_RW_FLG;
4047 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
4048 &cinode->netfs.inode);
4049 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
4050 cinode->oplock = CIFS_CACHE_READ_FLG;
4051 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
4052 &cinode->netfs.inode);
4058 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4059 unsigned int epoch, bool *purge_cache)
4061 char message[5] = {0};
4062 unsigned int new_oplock = 0;
4065 cinode->lease_granted = true;
4066 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
4069 /* Check if the server granted an oplock rather than a lease */
4070 if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4071 return smb2_set_oplock_level(cinode, oplock, epoch,
4074 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
4075 new_oplock |= CIFS_CACHE_READ_FLG;
4076 strcat(message, "R");
4078 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
4079 new_oplock |= CIFS_CACHE_HANDLE_FLG;
4080 strcat(message, "H");
4082 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
4083 new_oplock |= CIFS_CACHE_WRITE_FLG;
4084 strcat(message, "W");
4087 strncpy(message, "None", sizeof(message));
4089 cinode->oplock = new_oplock;
4090 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
4091 &cinode->netfs.inode);
4095 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4096 unsigned int epoch, bool *purge_cache)
4098 unsigned int old_oplock = cinode->oplock;
4100 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
4103 *purge_cache = false;
4104 if (old_oplock == CIFS_CACHE_READ_FLG) {
4105 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
4106 (epoch - cinode->epoch > 0))
4107 *purge_cache = true;
4108 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4109 (epoch - cinode->epoch > 1))
4110 *purge_cache = true;
4111 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4112 (epoch - cinode->epoch > 1))
4113 *purge_cache = true;
4114 else if (cinode->oplock == 0 &&
4115 (epoch - cinode->epoch > 0))
4116 *purge_cache = true;
4117 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
4118 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4119 (epoch - cinode->epoch > 0))
4120 *purge_cache = true;
4121 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4122 (epoch - cinode->epoch > 1))
4123 *purge_cache = true;
4125 cinode->epoch = epoch;
4129 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
4131 smb2_is_read_op(__u32 oplock)
4133 return oplock == SMB2_OPLOCK_LEVEL_II;
4135 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
4138 smb21_is_read_op(__u32 oplock)
4140 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
4141 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
4145 map_oplock_to_lease(u8 oplock)
4147 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4148 return SMB2_LEASE_WRITE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE;
4149 else if (oplock == SMB2_OPLOCK_LEVEL_II)
4150 return SMB2_LEASE_READ_CACHING_LE;
4151 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
4152 return SMB2_LEASE_HANDLE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE |
4153 SMB2_LEASE_WRITE_CACHING_LE;
4158 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
4160 struct create_lease *buf;
4162 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
4166 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4167 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4169 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4170 (struct create_lease, lcontext));
4171 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
4172 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4173 (struct create_lease, Name));
4174 buf->ccontext.NameLength = cpu_to_le16(4);
4175 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4184 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
4186 struct create_lease_v2 *buf;
4188 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
4192 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4193 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4195 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4196 (struct create_lease_v2, lcontext));
4197 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
4198 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4199 (struct create_lease_v2, Name));
4200 buf->ccontext.NameLength = cpu_to_le16(4);
4201 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4210 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4212 struct create_lease *lc = (struct create_lease *)buf;
4214 *epoch = 0; /* not used */
4215 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4216 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4217 return le32_to_cpu(lc->lcontext.LeaseState);
4221 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4223 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
4225 *epoch = le16_to_cpu(lc->lcontext.Epoch);
4226 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4227 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4229 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
4230 return le32_to_cpu(lc->lcontext.LeaseState);
4234 smb2_wp_retry_size(struct inode *inode)
4236 return min_t(unsigned int, CIFS_SB(inode->i_sb)->ctx->wsize,
4237 SMB2_MAX_BUFFER_SIZE);
4241 smb2_dir_needs_close(struct cifsFileInfo *cfile)
4243 return !cfile->invalidHandle;
4247 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
4248 struct smb_rqst *old_rq, __le16 cipher_type)
4250 struct smb2_hdr *shdr =
4251 (struct smb2_hdr *)old_rq->rq_iov[0].iov_base;
4253 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
4254 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
4255 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
4256 tr_hdr->Flags = cpu_to_le16(0x01);
4257 if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4258 (cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4259 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4261 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4262 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
4265 static void *smb2_aead_req_alloc(struct crypto_aead *tfm, const struct smb_rqst *rqst,
4266 int num_rqst, const u8 *sig, u8 **iv,
4267 struct aead_request **req, struct sg_table *sgt,
4268 unsigned int *num_sgs, size_t *sensitive_size)
4270 unsigned int req_size = sizeof(**req) + crypto_aead_reqsize(tfm);
4271 unsigned int iv_size = crypto_aead_ivsize(tfm);
4275 *num_sgs = cifs_get_num_sgs(rqst, num_rqst, sig);
4276 if (IS_ERR_VALUE((long)(int)*num_sgs))
4277 return ERR_PTR(*num_sgs);
4280 len += crypto_aead_alignmask(tfm) & ~(crypto_tfm_ctx_alignment() - 1);
4281 len = ALIGN(len, crypto_tfm_ctx_alignment());
4283 len = ALIGN(len, __alignof__(struct scatterlist));
4284 len += array_size(*num_sgs, sizeof(struct scatterlist));
4285 *sensitive_size = len;
4287 p = kvzalloc(len, GFP_NOFS);
4289 return ERR_PTR(-ENOMEM);
4291 *iv = (u8 *)PTR_ALIGN(p, crypto_aead_alignmask(tfm) + 1);
4292 *req = (struct aead_request *)PTR_ALIGN(*iv + iv_size,
4293 crypto_tfm_ctx_alignment());
4294 sgt->sgl = (struct scatterlist *)PTR_ALIGN((u8 *)*req + req_size,
4295 __alignof__(struct scatterlist));
4299 static void *smb2_get_aead_req(struct crypto_aead *tfm, struct smb_rqst *rqst,
4300 int num_rqst, const u8 *sig, u8 **iv,
4301 struct aead_request **req, struct scatterlist **sgl,
4302 size_t *sensitive_size)
4304 struct sg_table sgtable = {};
4305 unsigned int skip, num_sgs, i, j;
4309 p = smb2_aead_req_alloc(tfm, rqst, num_rqst, sig, iv, req, &sgtable,
4310 &num_sgs, sensitive_size);
4314 sg_init_marker(sgtable.sgl, num_sgs);
4317 * The first rqst has a transform header where the
4318 * first 20 bytes are not part of the encrypted blob.
4322 for (i = 0; i < num_rqst; i++) {
4323 struct iov_iter *iter = &rqst[i].rq_iter;
4324 size_t count = iov_iter_count(iter);
4326 for (j = 0; j < rqst[i].rq_nvec; j++) {
4327 cifs_sg_set_buf(&sgtable,
4328 rqst[i].rq_iov[j].iov_base + skip,
4329 rqst[i].rq_iov[j].iov_len - skip);
4331 /* See the above comment on the 'skip' assignment */
4334 sgtable.orig_nents = sgtable.nents;
4336 rc = netfs_extract_iter_to_sg(iter, count, &sgtable,
4337 num_sgs - sgtable.nents, 0);
4338 iov_iter_revert(iter, rc);
4339 sgtable.orig_nents = sgtable.nents;
4342 cifs_sg_set_buf(&sgtable, sig, SMB2_SIGNATURE_SIZE);
4343 sg_mark_end(&sgtable.sgl[sgtable.nents - 1]);
4349 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
4351 struct TCP_Server_Info *pserver;
4352 struct cifs_ses *ses;
4355 /* If server is a channel, select the primary channel */
4356 pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
4358 spin_lock(&cifs_tcp_ses_lock);
4359 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
4360 if (ses->Suid == ses_id) {
4361 spin_lock(&ses->ses_lock);
4362 ses_enc_key = enc ? ses->smb3encryptionkey :
4363 ses->smb3decryptionkey;
4364 memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE);
4365 spin_unlock(&ses->ses_lock);
4366 spin_unlock(&cifs_tcp_ses_lock);
4370 spin_unlock(&cifs_tcp_ses_lock);
4375 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
4376 * iov[0] - transform header (associate data),
4377 * iov[1-N] - SMB2 header and pages - data to encrypt.
4378 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4382 crypt_message(struct TCP_Server_Info *server, int num_rqst,
4383 struct smb_rqst *rqst, int enc)
4385 struct smb2_transform_hdr *tr_hdr =
4386 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
4387 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
4389 struct scatterlist *sg;
4390 u8 sign[SMB2_SIGNATURE_SIZE] = {};
4391 u8 key[SMB3_ENC_DEC_KEY_SIZE];
4392 struct aead_request *req;
4394 DECLARE_CRYPTO_WAIT(wait);
4395 struct crypto_aead *tfm;
4396 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4398 size_t sensitive_size;
4400 rc = smb2_get_enc_key(server, le64_to_cpu(tr_hdr->SessionId), enc, key);
4402 cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
4407 rc = smb3_crypto_aead_allocate(server);
4409 cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
4413 tfm = enc ? server->secmech.enc : server->secmech.dec;
4415 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
4416 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4417 rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
4419 rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE);
4422 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
4426 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
4428 cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
4432 creq = smb2_get_aead_req(tfm, rqst, num_rqst, sign, &iv, &req, &sg,
4435 return PTR_ERR(creq);
4438 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
4439 crypt_len += SMB2_SIGNATURE_SIZE;
4442 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4443 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4444 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4447 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4450 aead_request_set_tfm(req, tfm);
4451 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
4452 aead_request_set_ad(req, assoc_data_len);
4454 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
4455 crypto_req_done, &wait);
4457 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
4458 : crypto_aead_decrypt(req), &wait);
4461 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
4463 kvfree_sensitive(creq, sensitive_size);
4468 * Clear a read buffer, discarding the folios which have XA_MARK_0 set.
4470 static void cifs_clear_xarray_buffer(struct xarray *buffer)
4472 struct folio *folio;
4474 XA_STATE(xas, buffer, 0);
4477 xas_for_each_marked(&xas, folio, ULONG_MAX, XA_MARK_0) {
4485 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
4489 for (i = 0; i < num_rqst; i++)
4490 if (!xa_empty(&rqst[i].rq_buffer))
4491 cifs_clear_xarray_buffer(&rqst[i].rq_buffer);
4495 * This function will initialize new_rq and encrypt the content.
4496 * The first entry, new_rq[0], only contains a single iov which contains
4497 * a smb2_transform_hdr and is pre-allocated by the caller.
4498 * This function then populates new_rq[1+] with the content from olq_rq[0+].
4500 * The end result is an array of smb_rqst structures where the first structure
4501 * only contains a single iov for the transform header which we then can pass
4502 * to crypt_message().
4504 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4505 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
4508 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
4509 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
4511 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
4513 unsigned int orig_len = 0;
4517 for (i = 1; i < num_rqst; i++) {
4518 struct smb_rqst *old = &old_rq[i - 1];
4519 struct smb_rqst *new = &new_rq[i];
4520 struct xarray *buffer = &new->rq_buffer;
4521 size_t size = iov_iter_count(&old->rq_iter), seg, copied = 0;
4523 orig_len += smb_rqst_len(server, old);
4524 new->rq_iov = old->rq_iov;
4525 new->rq_nvec = old->rq_nvec;
4530 unsigned int npages = DIV_ROUND_UP(size, PAGE_SIZE);
4532 for (j = 0; j < npages; j++) {
4536 page = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4540 o = xa_store(buffer, j, page, GFP_KERNEL);
4547 xa_set_mark(buffer, j, XA_MARK_0);
4549 seg = min_t(size_t, size - copied, PAGE_SIZE);
4550 if (copy_page_from_iter(page, 0, seg, &old->rq_iter) != seg) {
4556 iov_iter_xarray(&new->rq_iter, ITER_SOURCE,
4558 new->rq_iter_size = size;
4562 /* fill the 1st iov with a transform header */
4563 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
4565 rc = crypt_message(server, num_rqst, new_rq, 1);
4566 cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
4573 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
4578 smb3_is_transform_hdr(void *buf)
4580 struct smb2_transform_hdr *trhdr = buf;
4582 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
4586 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
4587 unsigned int buf_data_size, struct iov_iter *iter,
4591 struct smb_rqst rqst = {NULL};
4592 size_t iter_size = 0;
4595 iov[0].iov_base = buf;
4596 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
4597 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
4598 iov[1].iov_len = buf_data_size;
4603 rqst.rq_iter = *iter;
4604 rqst.rq_iter_size = iov_iter_count(iter);
4605 iter_size = iov_iter_count(iter);
4608 rc = crypt_message(server, 1, &rqst, 0);
4609 cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
4614 memmove(buf, iov[1].iov_base, buf_data_size);
4617 server->total_read = buf_data_size + iter_size;
4623 cifs_copy_pages_to_iter(struct xarray *pages, unsigned int data_size,
4624 unsigned int skip, struct iov_iter *iter)
4627 unsigned long index;
4629 xa_for_each(pages, index, page) {
4630 size_t n, len = min_t(unsigned int, PAGE_SIZE - skip, data_size);
4632 n = copy_page_to_iter(page, skip, len, iter);
4634 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
4645 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
4646 char *buf, unsigned int buf_len, struct xarray *pages,
4647 unsigned int pages_len, bool is_offloaded)
4649 unsigned int data_offset;
4650 unsigned int data_len;
4651 unsigned int cur_off;
4652 unsigned int cur_page_idx;
4653 unsigned int pad_len;
4654 struct cifs_readdata *rdata = mid->callback_data;
4655 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
4657 bool use_rdma_mr = false;
4659 if (shdr->Command != SMB2_READ) {
4660 cifs_server_dbg(VFS, "only big read responses are supported\n");
4664 if (server->ops->is_session_expired &&
4665 server->ops->is_session_expired(buf)) {
4667 cifs_reconnect(server, true);
4671 if (server->ops->is_status_pending &&
4672 server->ops->is_status_pending(buf, server))
4675 /* set up first two iov to get credits */
4676 rdata->iov[0].iov_base = buf;
4677 rdata->iov[0].iov_len = 0;
4678 rdata->iov[1].iov_base = buf;
4679 rdata->iov[1].iov_len =
4680 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
4681 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
4682 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
4683 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
4684 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
4686 rdata->result = server->ops->map_error(buf, true);
4687 if (rdata->result != 0) {
4688 cifs_dbg(FYI, "%s: server returned error %d\n",
4689 __func__, rdata->result);
4690 /* normal error on read response */
4692 mid->mid_state = MID_RESPONSE_RECEIVED;
4694 dequeue_mid(mid, false);
4698 data_offset = server->ops->read_data_offset(buf);
4699 #ifdef CONFIG_CIFS_SMB_DIRECT
4700 use_rdma_mr = rdata->mr;
4702 data_len = server->ops->read_data_length(buf, use_rdma_mr);
4704 if (data_offset < server->vals->read_rsp_size) {
4706 * win2k8 sometimes sends an offset of 0 when the read
4707 * is beyond the EOF. Treat it as if the data starts just after
4710 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
4711 __func__, data_offset);
4712 data_offset = server->vals->read_rsp_size;
4713 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
4714 /* data_offset is beyond the end of smallbuf */
4715 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
4716 __func__, data_offset);
4717 rdata->result = -EIO;
4719 mid->mid_state = MID_RESPONSE_MALFORMED;
4721 dequeue_mid(mid, rdata->result);
4725 pad_len = data_offset - server->vals->read_rsp_size;
4727 if (buf_len <= data_offset) {
4728 /* read response payload is in pages */
4729 cur_page_idx = pad_len / PAGE_SIZE;
4730 cur_off = pad_len % PAGE_SIZE;
4732 if (cur_page_idx != 0) {
4733 /* data offset is beyond the 1st page of response */
4734 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
4735 __func__, data_offset);
4736 rdata->result = -EIO;
4738 mid->mid_state = MID_RESPONSE_MALFORMED;
4740 dequeue_mid(mid, rdata->result);
4744 if (data_len > pages_len - pad_len) {
4745 /* data_len is corrupt -- discard frame */
4746 rdata->result = -EIO;
4748 mid->mid_state = MID_RESPONSE_MALFORMED;
4750 dequeue_mid(mid, rdata->result);
4754 /* Copy the data to the output I/O iterator. */
4755 rdata->result = cifs_copy_pages_to_iter(pages, pages_len,
4756 cur_off, &rdata->iter);
4757 if (rdata->result != 0) {
4759 mid->mid_state = MID_RESPONSE_MALFORMED;
4761 dequeue_mid(mid, rdata->result);
4764 rdata->got_bytes = pages_len;
4766 } else if (buf_len >= data_offset + data_len) {
4767 /* read response payload is in buf */
4768 WARN_ONCE(pages && !xa_empty(pages),
4769 "read data can be either in buf or in pages");
4770 length = copy_to_iter(buf + data_offset, data_len, &rdata->iter);
4773 rdata->got_bytes = data_len;
4775 /* read response payload cannot be in both buf and pages */
4776 WARN_ONCE(1, "buf can not contain only a part of read data");
4777 rdata->result = -EIO;
4779 mid->mid_state = MID_RESPONSE_MALFORMED;
4781 dequeue_mid(mid, rdata->result);
4786 mid->mid_state = MID_RESPONSE_RECEIVED;
4788 dequeue_mid(mid, false);
4792 struct smb2_decrypt_work {
4793 struct work_struct decrypt;
4794 struct TCP_Server_Info *server;
4795 struct xarray buffer;
4801 static void smb2_decrypt_offload(struct work_struct *work)
4803 struct smb2_decrypt_work *dw = container_of(work,
4804 struct smb2_decrypt_work, decrypt);
4806 struct mid_q_entry *mid;
4807 struct iov_iter iter;
4809 iov_iter_xarray(&iter, ITER_DEST, &dw->buffer, 0, dw->len);
4810 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
4813 cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
4817 dw->server->lstrp = jiffies;
4818 mid = smb2_find_dequeue_mid(dw->server, dw->buf);
4820 cifs_dbg(FYI, "mid not found\n");
4822 mid->decrypted = true;
4823 rc = handle_read_data(dw->server, mid, dw->buf,
4824 dw->server->vals->read_rsp_size,
4825 &dw->buffer, dw->len,
4828 #ifdef CONFIG_CIFS_STATS2
4829 mid->when_received = jiffies;
4831 if (dw->server->ops->is_network_name_deleted)
4832 dw->server->ops->is_network_name_deleted(dw->buf,
4837 spin_lock(&dw->server->srv_lock);
4838 if (dw->server->tcpStatus == CifsNeedReconnect) {
4839 spin_lock(&dw->server->mid_lock);
4840 mid->mid_state = MID_RETRY_NEEDED;
4841 spin_unlock(&dw->server->mid_lock);
4842 spin_unlock(&dw->server->srv_lock);
4845 spin_lock(&dw->server->mid_lock);
4846 mid->mid_state = MID_REQUEST_SUBMITTED;
4847 mid->mid_flags &= ~(MID_DELETED);
4848 list_add_tail(&mid->qhead,
4849 &dw->server->pending_mid_q);
4850 spin_unlock(&dw->server->mid_lock);
4851 spin_unlock(&dw->server->srv_lock);
4858 cifs_clear_xarray_buffer(&dw->buffer);
4859 cifs_small_buf_release(dw->buf);
4865 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
4869 char *buf = server->smallbuf;
4870 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4871 struct iov_iter iter;
4872 unsigned int len, npages;
4873 unsigned int buflen = server->pdu_size;
4876 struct smb2_decrypt_work *dw;
4878 dw = kzalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL);
4881 xa_init(&dw->buffer);
4882 INIT_WORK(&dw->decrypt, smb2_decrypt_offload);
4883 dw->server = server;
4886 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
4887 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
4889 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
4892 server->total_read += rc;
4894 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
4895 server->vals->read_rsp_size;
4897 npages = DIV_ROUND_UP(len, PAGE_SIZE);
4900 for (; i < npages; i++) {
4903 page = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4907 old = xa_store(&dw->buffer, i, page, GFP_KERNEL);
4908 if (xa_is_err(old)) {
4913 xa_set_mark(&dw->buffer, i, XA_MARK_0);
4916 iov_iter_xarray(&iter, ITER_DEST, &dw->buffer, 0, npages * PAGE_SIZE);
4918 /* Read the data into the buffer and clear excess bufferage. */
4919 rc = cifs_read_iter_from_socket(server, &iter, dw->len);
4923 server->total_read += rc;
4924 if (rc < npages * PAGE_SIZE)
4925 iov_iter_zero(npages * PAGE_SIZE - rc, &iter);
4926 iov_iter_revert(&iter, npages * PAGE_SIZE);
4927 iov_iter_truncate(&iter, dw->len);
4929 rc = cifs_discard_remaining_data(server);
4934 * For large reads, offload to different thread for better performance,
4935 * use more cores decrypting which can be expensive
4938 if ((server->min_offload) && (server->in_flight > 1) &&
4939 (server->pdu_size >= server->min_offload)) {
4940 dw->buf = server->smallbuf;
4941 server->smallbuf = (char *)cifs_small_buf_get();
4943 queue_work(decrypt_wq, &dw->decrypt);
4944 *num_mids = 0; /* worker thread takes care of finding mid */
4948 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
4953 *mid = smb2_find_mid(server, buf);
4955 cifs_dbg(FYI, "mid not found\n");
4957 cifs_dbg(FYI, "mid found\n");
4958 (*mid)->decrypted = true;
4959 rc = handle_read_data(server, *mid, buf,
4960 server->vals->read_rsp_size,
4961 &dw->buffer, dw->len, false);
4963 if (server->ops->is_network_name_deleted) {
4964 server->ops->is_network_name_deleted(buf,
4971 cifs_clear_xarray_buffer(&dw->buffer);
4976 cifs_discard_remaining_data(server);
4981 receive_encrypted_standard(struct TCP_Server_Info *server,
4982 struct mid_q_entry **mids, char **bufs,
4986 char *buf = server->smallbuf;
4987 struct smb2_hdr *shdr;
4988 unsigned int pdu_length = server->pdu_size;
4989 unsigned int buf_size;
4990 struct mid_q_entry *mid_entry;
4992 char *next_buffer = NULL;
4996 /* switch to large buffer if too big for a small one */
4997 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
4998 server->large_buf = true;
4999 memcpy(server->bigbuf, buf, server->total_read);
5000 buf = server->bigbuf;
5003 /* now read the rest */
5004 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
5005 pdu_length - HEADER_SIZE(server) + 1);
5008 server->total_read += length;
5010 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
5011 length = decrypt_raw_data(server, buf, buf_size, NULL, false);
5015 next_is_large = server->large_buf;
5017 shdr = (struct smb2_hdr *)buf;
5018 if (shdr->NextCommand) {
5020 next_buffer = (char *)cifs_buf_get();
5022 next_buffer = (char *)cifs_small_buf_get();
5024 buf + le32_to_cpu(shdr->NextCommand),
5025 pdu_length - le32_to_cpu(shdr->NextCommand));
5028 mid_entry = smb2_find_mid(server, buf);
5029 if (mid_entry == NULL)
5030 cifs_dbg(FYI, "mid not found\n");
5032 cifs_dbg(FYI, "mid found\n");
5033 mid_entry->decrypted = true;
5034 mid_entry->resp_buf_size = server->pdu_size;
5037 if (*num_mids >= MAX_COMPOUND) {
5038 cifs_server_dbg(VFS, "too many PDUs in compound\n");
5041 bufs[*num_mids] = buf;
5042 mids[(*num_mids)++] = mid_entry;
5044 if (mid_entry && mid_entry->handle)
5045 ret = mid_entry->handle(server, mid_entry);
5047 ret = cifs_handle_standard(server, mid_entry);
5049 if (ret == 0 && shdr->NextCommand) {
5050 pdu_length -= le32_to_cpu(shdr->NextCommand);
5051 server->large_buf = next_is_large;
5053 server->bigbuf = buf = next_buffer;
5055 server->smallbuf = buf = next_buffer;
5057 } else if (ret != 0) {
5059 * ret != 0 here means that we didn't get to handle_mid() thus
5060 * server->smallbuf and server->bigbuf are still valid. We need
5061 * to free next_buffer because it is not going to be used
5065 free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer);
5067 free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer);
5074 smb3_receive_transform(struct TCP_Server_Info *server,
5075 struct mid_q_entry **mids, char **bufs, int *num_mids)
5077 char *buf = server->smallbuf;
5078 unsigned int pdu_length = server->pdu_size;
5079 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
5080 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
5082 if (pdu_length < sizeof(struct smb2_transform_hdr) +
5083 sizeof(struct smb2_hdr)) {
5084 cifs_server_dbg(VFS, "Transform message is too small (%u)\n",
5086 cifs_reconnect(server, true);
5087 return -ECONNABORTED;
5090 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
5091 cifs_server_dbg(VFS, "Transform message is broken\n");
5092 cifs_reconnect(server, true);
5093 return -ECONNABORTED;
5096 /* TODO: add support for compounds containing READ. */
5097 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
5098 return receive_encrypted_read(server, &mids[0], num_mids);
5101 return receive_encrypted_standard(server, mids, bufs, num_mids);
5105 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
5107 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
5109 return handle_read_data(server, mid, buf, server->pdu_size,
5114 smb2_next_header(char *buf)
5116 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
5117 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
5119 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
5120 return sizeof(struct smb2_transform_hdr) +
5121 le32_to_cpu(t_hdr->OriginalMessageSize);
5123 return le32_to_cpu(hdr->NextCommand);
5127 smb2_make_node(unsigned int xid, struct inode *inode,
5128 struct dentry *dentry, struct cifs_tcon *tcon,
5129 const char *full_path, umode_t mode, dev_t dev)
5131 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
5133 struct cifs_open_info_data buf = {};
5134 struct cifs_io_parms io_parms = {0};
5136 struct cifs_fid fid;
5137 struct cifs_open_parms oparms;
5138 unsigned int bytes_written;
5139 struct win_dev *pdev;
5143 * Check if mounted with mount parm 'sfu' mount parm.
5144 * SFU emulation should work with all servers, but only
5145 * supports block and char device (no socket & fifo),
5146 * and was used by default in earlier versions of Windows
5148 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
5152 * TODO: Add ability to create instead via reparse point. Windows (e.g.
5153 * their current NFS server) uses this approach to expose special files
5154 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
5157 if (!S_ISCHR(mode) && !S_ISBLK(mode))
5160 cifs_dbg(FYI, "sfu compat create special file\n");
5162 oparms = (struct cifs_open_parms) {
5165 .desired_access = GENERIC_WRITE,
5166 .create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR |
5167 CREATE_OPTION_SPECIAL),
5168 .disposition = FILE_CREATE,
5173 if (tcon->ses->server->oplocks)
5174 oplock = REQ_OPLOCK;
5177 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, &buf);
5182 * BB Do not bother to decode buf since no local inode yet to put
5183 * timestamps in, but we can reuse it safely.
5186 pdev = (struct win_dev *)&buf.fi;
5187 io_parms.pid = current->tgid;
5188 io_parms.tcon = tcon;
5189 io_parms.offset = 0;
5190 io_parms.length = sizeof(struct win_dev);
5191 iov[1].iov_base = &buf.fi;
5192 iov[1].iov_len = sizeof(struct win_dev);
5193 if (S_ISCHR(mode)) {
5194 memcpy(pdev->type, "IntxCHR", 8);
5195 pdev->major = cpu_to_le64(MAJOR(dev));
5196 pdev->minor = cpu_to_le64(MINOR(dev));
5197 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5198 &bytes_written, iov, 1);
5199 } else if (S_ISBLK(mode)) {
5200 memcpy(pdev->type, "IntxBLK", 8);
5201 pdev->major = cpu_to_le64(MAJOR(dev));
5202 pdev->minor = cpu_to_le64(MINOR(dev));
5203 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5204 &bytes_written, iov, 1);
5206 tcon->ses->server->ops->close(xid, tcon, &fid);
5209 /* FIXME: add code here to set EAs */
5211 cifs_free_open_info(&buf);
5215 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5216 struct smb_version_operations smb20_operations = {
5217 .compare_fids = smb2_compare_fids,
5218 .setup_request = smb2_setup_request,
5219 .setup_async_request = smb2_setup_async_request,
5220 .check_receive = smb2_check_receive,
5221 .add_credits = smb2_add_credits,
5222 .set_credits = smb2_set_credits,
5223 .get_credits_field = smb2_get_credits_field,
5224 .get_credits = smb2_get_credits,
5225 .wait_mtu_credits = cifs_wait_mtu_credits,
5226 .get_next_mid = smb2_get_next_mid,
5227 .revert_current_mid = smb2_revert_current_mid,
5228 .read_data_offset = smb2_read_data_offset,
5229 .read_data_length = smb2_read_data_length,
5230 .map_error = map_smb2_to_linux_error,
5231 .find_mid = smb2_find_mid,
5232 .check_message = smb2_check_message,
5233 .dump_detail = smb2_dump_detail,
5234 .clear_stats = smb2_clear_stats,
5235 .print_stats = smb2_print_stats,
5236 .is_oplock_break = smb2_is_valid_oplock_break,
5237 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5238 .downgrade_oplock = smb2_downgrade_oplock,
5239 .need_neg = smb2_need_neg,
5240 .negotiate = smb2_negotiate,
5241 .negotiate_wsize = smb2_negotiate_wsize,
5242 .negotiate_rsize = smb2_negotiate_rsize,
5243 .sess_setup = SMB2_sess_setup,
5244 .logoff = SMB2_logoff,
5245 .tree_connect = SMB2_tcon,
5246 .tree_disconnect = SMB2_tdis,
5247 .qfs_tcon = smb2_qfs_tcon,
5248 .is_path_accessible = smb2_is_path_accessible,
5249 .can_echo = smb2_can_echo,
5251 .query_path_info = smb2_query_path_info,
5252 .get_srv_inum = smb2_get_srv_inum,
5253 .query_file_info = smb2_query_file_info,
5254 .set_path_size = smb2_set_path_size,
5255 .set_file_size = smb2_set_file_size,
5256 .set_file_info = smb2_set_file_info,
5257 .set_compression = smb2_set_compression,
5258 .mkdir = smb2_mkdir,
5259 .mkdir_setinfo = smb2_mkdir_setinfo,
5260 .rmdir = smb2_rmdir,
5261 .unlink = smb2_unlink,
5262 .rename = smb2_rename_path,
5263 .create_hardlink = smb2_create_hardlink,
5264 .query_symlink = smb2_query_symlink,
5265 .query_mf_symlink = smb3_query_mf_symlink,
5266 .create_mf_symlink = smb3_create_mf_symlink,
5267 .open = smb2_open_file,
5268 .set_fid = smb2_set_fid,
5269 .close = smb2_close_file,
5270 .flush = smb2_flush_file,
5271 .async_readv = smb2_async_readv,
5272 .async_writev = smb2_async_writev,
5273 .sync_read = smb2_sync_read,
5274 .sync_write = smb2_sync_write,
5275 .query_dir_first = smb2_query_dir_first,
5276 .query_dir_next = smb2_query_dir_next,
5277 .close_dir = smb2_close_dir,
5278 .calc_smb_size = smb2_calc_size,
5279 .is_status_pending = smb2_is_status_pending,
5280 .is_session_expired = smb2_is_session_expired,
5281 .oplock_response = smb2_oplock_response,
5282 .queryfs = smb2_queryfs,
5283 .mand_lock = smb2_mand_lock,
5284 .mand_unlock_range = smb2_unlock_range,
5285 .push_mand_locks = smb2_push_mandatory_locks,
5286 .get_lease_key = smb2_get_lease_key,
5287 .set_lease_key = smb2_set_lease_key,
5288 .new_lease_key = smb2_new_lease_key,
5289 .calc_signature = smb2_calc_signature,
5290 .is_read_op = smb2_is_read_op,
5291 .set_oplock_level = smb2_set_oplock_level,
5292 .create_lease_buf = smb2_create_lease_buf,
5293 .parse_lease_buf = smb2_parse_lease_buf,
5294 .copychunk_range = smb2_copychunk_range,
5295 .wp_retry_size = smb2_wp_retry_size,
5296 .dir_needs_close = smb2_dir_needs_close,
5297 .get_dfs_refer = smb2_get_dfs_refer,
5298 .select_sectype = smb2_select_sectype,
5299 #ifdef CONFIG_CIFS_XATTR
5300 .query_all_EAs = smb2_query_eas,
5301 .set_EA = smb2_set_ea,
5302 #endif /* CIFS_XATTR */
5303 .get_acl = get_smb2_acl,
5304 .get_acl_by_fid = get_smb2_acl_by_fid,
5305 .set_acl = set_smb2_acl,
5306 .next_header = smb2_next_header,
5307 .ioctl_query_info = smb2_ioctl_query_info,
5308 .make_node = smb2_make_node,
5309 .fiemap = smb3_fiemap,
5310 .llseek = smb3_llseek,
5311 .is_status_io_timeout = smb2_is_status_io_timeout,
5312 .is_network_name_deleted = smb2_is_network_name_deleted,
5314 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
5316 struct smb_version_operations smb21_operations = {
5317 .compare_fids = smb2_compare_fids,
5318 .setup_request = smb2_setup_request,
5319 .setup_async_request = smb2_setup_async_request,
5320 .check_receive = smb2_check_receive,
5321 .add_credits = smb2_add_credits,
5322 .set_credits = smb2_set_credits,
5323 .get_credits_field = smb2_get_credits_field,
5324 .get_credits = smb2_get_credits,
5325 .wait_mtu_credits = smb2_wait_mtu_credits,
5326 .adjust_credits = smb2_adjust_credits,
5327 .get_next_mid = smb2_get_next_mid,
5328 .revert_current_mid = smb2_revert_current_mid,
5329 .read_data_offset = smb2_read_data_offset,
5330 .read_data_length = smb2_read_data_length,
5331 .map_error = map_smb2_to_linux_error,
5332 .find_mid = smb2_find_mid,
5333 .check_message = smb2_check_message,
5334 .dump_detail = smb2_dump_detail,
5335 .clear_stats = smb2_clear_stats,
5336 .print_stats = smb2_print_stats,
5337 .is_oplock_break = smb2_is_valid_oplock_break,
5338 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5339 .downgrade_oplock = smb2_downgrade_oplock,
5340 .need_neg = smb2_need_neg,
5341 .negotiate = smb2_negotiate,
5342 .negotiate_wsize = smb2_negotiate_wsize,
5343 .negotiate_rsize = smb2_negotiate_rsize,
5344 .sess_setup = SMB2_sess_setup,
5345 .logoff = SMB2_logoff,
5346 .tree_connect = SMB2_tcon,
5347 .tree_disconnect = SMB2_tdis,
5348 .qfs_tcon = smb2_qfs_tcon,
5349 .is_path_accessible = smb2_is_path_accessible,
5350 .can_echo = smb2_can_echo,
5352 .query_path_info = smb2_query_path_info,
5353 .get_srv_inum = smb2_get_srv_inum,
5354 .query_file_info = smb2_query_file_info,
5355 .set_path_size = smb2_set_path_size,
5356 .set_file_size = smb2_set_file_size,
5357 .set_file_info = smb2_set_file_info,
5358 .set_compression = smb2_set_compression,
5359 .mkdir = smb2_mkdir,
5360 .mkdir_setinfo = smb2_mkdir_setinfo,
5361 .rmdir = smb2_rmdir,
5362 .unlink = smb2_unlink,
5363 .rename = smb2_rename_path,
5364 .create_hardlink = smb2_create_hardlink,
5365 .query_symlink = smb2_query_symlink,
5366 .query_mf_symlink = smb3_query_mf_symlink,
5367 .create_mf_symlink = smb3_create_mf_symlink,
5368 .open = smb2_open_file,
5369 .set_fid = smb2_set_fid,
5370 .close = smb2_close_file,
5371 .flush = smb2_flush_file,
5372 .async_readv = smb2_async_readv,
5373 .async_writev = smb2_async_writev,
5374 .sync_read = smb2_sync_read,
5375 .sync_write = smb2_sync_write,
5376 .query_dir_first = smb2_query_dir_first,
5377 .query_dir_next = smb2_query_dir_next,
5378 .close_dir = smb2_close_dir,
5379 .calc_smb_size = smb2_calc_size,
5380 .is_status_pending = smb2_is_status_pending,
5381 .is_session_expired = smb2_is_session_expired,
5382 .oplock_response = smb2_oplock_response,
5383 .queryfs = smb2_queryfs,
5384 .mand_lock = smb2_mand_lock,
5385 .mand_unlock_range = smb2_unlock_range,
5386 .push_mand_locks = smb2_push_mandatory_locks,
5387 .get_lease_key = smb2_get_lease_key,
5388 .set_lease_key = smb2_set_lease_key,
5389 .new_lease_key = smb2_new_lease_key,
5390 .calc_signature = smb2_calc_signature,
5391 .is_read_op = smb21_is_read_op,
5392 .set_oplock_level = smb21_set_oplock_level,
5393 .create_lease_buf = smb2_create_lease_buf,
5394 .parse_lease_buf = smb2_parse_lease_buf,
5395 .copychunk_range = smb2_copychunk_range,
5396 .wp_retry_size = smb2_wp_retry_size,
5397 .dir_needs_close = smb2_dir_needs_close,
5398 .enum_snapshots = smb3_enum_snapshots,
5399 .notify = smb3_notify,
5400 .get_dfs_refer = smb2_get_dfs_refer,
5401 .select_sectype = smb2_select_sectype,
5402 #ifdef CONFIG_CIFS_XATTR
5403 .query_all_EAs = smb2_query_eas,
5404 .set_EA = smb2_set_ea,
5405 #endif /* CIFS_XATTR */
5406 .get_acl = get_smb2_acl,
5407 .get_acl_by_fid = get_smb2_acl_by_fid,
5408 .set_acl = set_smb2_acl,
5409 .next_header = smb2_next_header,
5410 .ioctl_query_info = smb2_ioctl_query_info,
5411 .make_node = smb2_make_node,
5412 .fiemap = smb3_fiemap,
5413 .llseek = smb3_llseek,
5414 .is_status_io_timeout = smb2_is_status_io_timeout,
5415 .is_network_name_deleted = smb2_is_network_name_deleted,
5418 struct smb_version_operations smb30_operations = {
5419 .compare_fids = smb2_compare_fids,
5420 .setup_request = smb2_setup_request,
5421 .setup_async_request = smb2_setup_async_request,
5422 .check_receive = smb2_check_receive,
5423 .add_credits = smb2_add_credits,
5424 .set_credits = smb2_set_credits,
5425 .get_credits_field = smb2_get_credits_field,
5426 .get_credits = smb2_get_credits,
5427 .wait_mtu_credits = smb2_wait_mtu_credits,
5428 .adjust_credits = smb2_adjust_credits,
5429 .get_next_mid = smb2_get_next_mid,
5430 .revert_current_mid = smb2_revert_current_mid,
5431 .read_data_offset = smb2_read_data_offset,
5432 .read_data_length = smb2_read_data_length,
5433 .map_error = map_smb2_to_linux_error,
5434 .find_mid = smb2_find_mid,
5435 .check_message = smb2_check_message,
5436 .dump_detail = smb2_dump_detail,
5437 .clear_stats = smb2_clear_stats,
5438 .print_stats = smb2_print_stats,
5439 .dump_share_caps = smb2_dump_share_caps,
5440 .is_oplock_break = smb2_is_valid_oplock_break,
5441 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5442 .downgrade_oplock = smb3_downgrade_oplock,
5443 .need_neg = smb2_need_neg,
5444 .negotiate = smb2_negotiate,
5445 .negotiate_wsize = smb3_negotiate_wsize,
5446 .negotiate_rsize = smb3_negotiate_rsize,
5447 .sess_setup = SMB2_sess_setup,
5448 .logoff = SMB2_logoff,
5449 .tree_connect = SMB2_tcon,
5450 .tree_disconnect = SMB2_tdis,
5451 .qfs_tcon = smb3_qfs_tcon,
5452 .is_path_accessible = smb2_is_path_accessible,
5453 .can_echo = smb2_can_echo,
5455 .query_path_info = smb2_query_path_info,
5456 /* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */
5457 .query_reparse_tag = smb2_query_reparse_tag,
5458 .get_srv_inum = smb2_get_srv_inum,
5459 .query_file_info = smb2_query_file_info,
5460 .set_path_size = smb2_set_path_size,
5461 .set_file_size = smb2_set_file_size,
5462 .set_file_info = smb2_set_file_info,
5463 .set_compression = smb2_set_compression,
5464 .mkdir = smb2_mkdir,
5465 .mkdir_setinfo = smb2_mkdir_setinfo,
5466 .rmdir = smb2_rmdir,
5467 .unlink = smb2_unlink,
5468 .rename = smb2_rename_path,
5469 .create_hardlink = smb2_create_hardlink,
5470 .query_symlink = smb2_query_symlink,
5471 .query_mf_symlink = smb3_query_mf_symlink,
5472 .create_mf_symlink = smb3_create_mf_symlink,
5473 .open = smb2_open_file,
5474 .set_fid = smb2_set_fid,
5475 .close = smb2_close_file,
5476 .close_getattr = smb2_close_getattr,
5477 .flush = smb2_flush_file,
5478 .async_readv = smb2_async_readv,
5479 .async_writev = smb2_async_writev,
5480 .sync_read = smb2_sync_read,
5481 .sync_write = smb2_sync_write,
5482 .query_dir_first = smb2_query_dir_first,
5483 .query_dir_next = smb2_query_dir_next,
5484 .close_dir = smb2_close_dir,
5485 .calc_smb_size = smb2_calc_size,
5486 .is_status_pending = smb2_is_status_pending,
5487 .is_session_expired = smb2_is_session_expired,
5488 .oplock_response = smb2_oplock_response,
5489 .queryfs = smb2_queryfs,
5490 .mand_lock = smb2_mand_lock,
5491 .mand_unlock_range = smb2_unlock_range,
5492 .push_mand_locks = smb2_push_mandatory_locks,
5493 .get_lease_key = smb2_get_lease_key,
5494 .set_lease_key = smb2_set_lease_key,
5495 .new_lease_key = smb2_new_lease_key,
5496 .generate_signingkey = generate_smb30signingkey,
5497 .calc_signature = smb3_calc_signature,
5498 .set_integrity = smb3_set_integrity,
5499 .is_read_op = smb21_is_read_op,
5500 .set_oplock_level = smb3_set_oplock_level,
5501 .create_lease_buf = smb3_create_lease_buf,
5502 .parse_lease_buf = smb3_parse_lease_buf,
5503 .copychunk_range = smb2_copychunk_range,
5504 .duplicate_extents = smb2_duplicate_extents,
5505 .validate_negotiate = smb3_validate_negotiate,
5506 .wp_retry_size = smb2_wp_retry_size,
5507 .dir_needs_close = smb2_dir_needs_close,
5508 .fallocate = smb3_fallocate,
5509 .enum_snapshots = smb3_enum_snapshots,
5510 .notify = smb3_notify,
5511 .init_transform_rq = smb3_init_transform_rq,
5512 .is_transform_hdr = smb3_is_transform_hdr,
5513 .receive_transform = smb3_receive_transform,
5514 .get_dfs_refer = smb2_get_dfs_refer,
5515 .select_sectype = smb2_select_sectype,
5516 #ifdef CONFIG_CIFS_XATTR
5517 .query_all_EAs = smb2_query_eas,
5518 .set_EA = smb2_set_ea,
5519 #endif /* CIFS_XATTR */
5520 .get_acl = get_smb2_acl,
5521 .get_acl_by_fid = get_smb2_acl_by_fid,
5522 .set_acl = set_smb2_acl,
5523 .next_header = smb2_next_header,
5524 .ioctl_query_info = smb2_ioctl_query_info,
5525 .make_node = smb2_make_node,
5526 .fiemap = smb3_fiemap,
5527 .llseek = smb3_llseek,
5528 .is_status_io_timeout = smb2_is_status_io_timeout,
5529 .is_network_name_deleted = smb2_is_network_name_deleted,
5532 struct smb_version_operations smb311_operations = {
5533 .compare_fids = smb2_compare_fids,
5534 .setup_request = smb2_setup_request,
5535 .setup_async_request = smb2_setup_async_request,
5536 .check_receive = smb2_check_receive,
5537 .add_credits = smb2_add_credits,
5538 .set_credits = smb2_set_credits,
5539 .get_credits_field = smb2_get_credits_field,
5540 .get_credits = smb2_get_credits,
5541 .wait_mtu_credits = smb2_wait_mtu_credits,
5542 .adjust_credits = smb2_adjust_credits,
5543 .get_next_mid = smb2_get_next_mid,
5544 .revert_current_mid = smb2_revert_current_mid,
5545 .read_data_offset = smb2_read_data_offset,
5546 .read_data_length = smb2_read_data_length,
5547 .map_error = map_smb2_to_linux_error,
5548 .find_mid = smb2_find_mid,
5549 .check_message = smb2_check_message,
5550 .dump_detail = smb2_dump_detail,
5551 .clear_stats = smb2_clear_stats,
5552 .print_stats = smb2_print_stats,
5553 .dump_share_caps = smb2_dump_share_caps,
5554 .is_oplock_break = smb2_is_valid_oplock_break,
5555 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5556 .downgrade_oplock = smb3_downgrade_oplock,
5557 .need_neg = smb2_need_neg,
5558 .negotiate = smb2_negotiate,
5559 .negotiate_wsize = smb3_negotiate_wsize,
5560 .negotiate_rsize = smb3_negotiate_rsize,
5561 .sess_setup = SMB2_sess_setup,
5562 .logoff = SMB2_logoff,
5563 .tree_connect = SMB2_tcon,
5564 .tree_disconnect = SMB2_tdis,
5565 .qfs_tcon = smb3_qfs_tcon,
5566 .is_path_accessible = smb2_is_path_accessible,
5567 .can_echo = smb2_can_echo,
5569 .query_path_info = smb2_query_path_info,
5570 .query_reparse_tag = smb2_query_reparse_tag,
5571 .get_srv_inum = smb2_get_srv_inum,
5572 .query_file_info = smb2_query_file_info,
5573 .set_path_size = smb2_set_path_size,
5574 .set_file_size = smb2_set_file_size,
5575 .set_file_info = smb2_set_file_info,
5576 .set_compression = smb2_set_compression,
5577 .mkdir = smb2_mkdir,
5578 .mkdir_setinfo = smb2_mkdir_setinfo,
5579 .posix_mkdir = smb311_posix_mkdir,
5580 .rmdir = smb2_rmdir,
5581 .unlink = smb2_unlink,
5582 .rename = smb2_rename_path,
5583 .create_hardlink = smb2_create_hardlink,
5584 .query_symlink = smb2_query_symlink,
5585 .query_mf_symlink = smb3_query_mf_symlink,
5586 .create_mf_symlink = smb3_create_mf_symlink,
5587 .open = smb2_open_file,
5588 .set_fid = smb2_set_fid,
5589 .close = smb2_close_file,
5590 .close_getattr = smb2_close_getattr,
5591 .flush = smb2_flush_file,
5592 .async_readv = smb2_async_readv,
5593 .async_writev = smb2_async_writev,
5594 .sync_read = smb2_sync_read,
5595 .sync_write = smb2_sync_write,
5596 .query_dir_first = smb2_query_dir_first,
5597 .query_dir_next = smb2_query_dir_next,
5598 .close_dir = smb2_close_dir,
5599 .calc_smb_size = smb2_calc_size,
5600 .is_status_pending = smb2_is_status_pending,
5601 .is_session_expired = smb2_is_session_expired,
5602 .oplock_response = smb2_oplock_response,
5603 .queryfs = smb311_queryfs,
5604 .mand_lock = smb2_mand_lock,
5605 .mand_unlock_range = smb2_unlock_range,
5606 .push_mand_locks = smb2_push_mandatory_locks,
5607 .get_lease_key = smb2_get_lease_key,
5608 .set_lease_key = smb2_set_lease_key,
5609 .new_lease_key = smb2_new_lease_key,
5610 .generate_signingkey = generate_smb311signingkey,
5611 .calc_signature = smb3_calc_signature,
5612 .set_integrity = smb3_set_integrity,
5613 .is_read_op = smb21_is_read_op,
5614 .set_oplock_level = smb3_set_oplock_level,
5615 .create_lease_buf = smb3_create_lease_buf,
5616 .parse_lease_buf = smb3_parse_lease_buf,
5617 .copychunk_range = smb2_copychunk_range,
5618 .duplicate_extents = smb2_duplicate_extents,
5619 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
5620 .wp_retry_size = smb2_wp_retry_size,
5621 .dir_needs_close = smb2_dir_needs_close,
5622 .fallocate = smb3_fallocate,
5623 .enum_snapshots = smb3_enum_snapshots,
5624 .notify = smb3_notify,
5625 .init_transform_rq = smb3_init_transform_rq,
5626 .is_transform_hdr = smb3_is_transform_hdr,
5627 .receive_transform = smb3_receive_transform,
5628 .get_dfs_refer = smb2_get_dfs_refer,
5629 .select_sectype = smb2_select_sectype,
5630 #ifdef CONFIG_CIFS_XATTR
5631 .query_all_EAs = smb2_query_eas,
5632 .set_EA = smb2_set_ea,
5633 #endif /* CIFS_XATTR */
5634 .get_acl = get_smb2_acl,
5635 .get_acl_by_fid = get_smb2_acl_by_fid,
5636 .set_acl = set_smb2_acl,
5637 .next_header = smb2_next_header,
5638 .ioctl_query_info = smb2_ioctl_query_info,
5639 .make_node = smb2_make_node,
5640 .fiemap = smb3_fiemap,
5641 .llseek = smb3_llseek,
5642 .is_status_io_timeout = smb2_is_status_io_timeout,
5643 .is_network_name_deleted = smb2_is_network_name_deleted,
5646 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5647 struct smb_version_values smb20_values = {
5648 .version_string = SMB20_VERSION_STRING,
5649 .protocol_id = SMB20_PROT_ID,
5650 .req_capabilities = 0, /* MBZ */
5651 .large_lock_type = 0,
5652 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5653 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5654 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5655 .header_size = sizeof(struct smb2_hdr),
5656 .header_preamble_size = 0,
5657 .max_header_size = MAX_SMB2_HDR_SIZE,
5658 .read_rsp_size = sizeof(struct smb2_read_rsp),
5659 .lock_cmd = SMB2_LOCK,
5661 .cap_nt_find = SMB2_NT_FIND,
5662 .cap_large_files = SMB2_LARGE_FILES,
5663 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5664 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5665 .create_lease_size = sizeof(struct create_lease),
5667 #endif /* ALLOW_INSECURE_LEGACY */
5669 struct smb_version_values smb21_values = {
5670 .version_string = SMB21_VERSION_STRING,
5671 .protocol_id = SMB21_PROT_ID,
5672 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
5673 .large_lock_type = 0,
5674 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5675 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5676 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5677 .header_size = sizeof(struct smb2_hdr),
5678 .header_preamble_size = 0,
5679 .max_header_size = MAX_SMB2_HDR_SIZE,
5680 .read_rsp_size = sizeof(struct smb2_read_rsp),
5681 .lock_cmd = SMB2_LOCK,
5683 .cap_nt_find = SMB2_NT_FIND,
5684 .cap_large_files = SMB2_LARGE_FILES,
5685 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5686 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5687 .create_lease_size = sizeof(struct create_lease),
5690 struct smb_version_values smb3any_values = {
5691 .version_string = SMB3ANY_VERSION_STRING,
5692 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5693 .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,
5694 .large_lock_type = 0,
5695 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5696 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5697 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5698 .header_size = sizeof(struct smb2_hdr),
5699 .header_preamble_size = 0,
5700 .max_header_size = MAX_SMB2_HDR_SIZE,
5701 .read_rsp_size = sizeof(struct smb2_read_rsp),
5702 .lock_cmd = SMB2_LOCK,
5704 .cap_nt_find = SMB2_NT_FIND,
5705 .cap_large_files = SMB2_LARGE_FILES,
5706 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5707 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5708 .create_lease_size = sizeof(struct create_lease_v2),
5711 struct smb_version_values smbdefault_values = {
5712 .version_string = SMBDEFAULT_VERSION_STRING,
5713 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5714 .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,
5715 .large_lock_type = 0,
5716 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5717 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5718 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5719 .header_size = sizeof(struct smb2_hdr),
5720 .header_preamble_size = 0,
5721 .max_header_size = MAX_SMB2_HDR_SIZE,
5722 .read_rsp_size = sizeof(struct smb2_read_rsp),
5723 .lock_cmd = SMB2_LOCK,
5725 .cap_nt_find = SMB2_NT_FIND,
5726 .cap_large_files = SMB2_LARGE_FILES,
5727 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5728 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5729 .create_lease_size = sizeof(struct create_lease_v2),
5732 struct smb_version_values smb30_values = {
5733 .version_string = SMB30_VERSION_STRING,
5734 .protocol_id = SMB30_PROT_ID,
5735 .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,
5736 .large_lock_type = 0,
5737 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5738 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5739 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5740 .header_size = sizeof(struct smb2_hdr),
5741 .header_preamble_size = 0,
5742 .max_header_size = MAX_SMB2_HDR_SIZE,
5743 .read_rsp_size = sizeof(struct smb2_read_rsp),
5744 .lock_cmd = SMB2_LOCK,
5746 .cap_nt_find = SMB2_NT_FIND,
5747 .cap_large_files = SMB2_LARGE_FILES,
5748 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5749 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5750 .create_lease_size = sizeof(struct create_lease_v2),
5753 struct smb_version_values smb302_values = {
5754 .version_string = SMB302_VERSION_STRING,
5755 .protocol_id = SMB302_PROT_ID,
5756 .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,
5757 .large_lock_type = 0,
5758 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5759 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5760 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5761 .header_size = sizeof(struct smb2_hdr),
5762 .header_preamble_size = 0,
5763 .max_header_size = MAX_SMB2_HDR_SIZE,
5764 .read_rsp_size = sizeof(struct smb2_read_rsp),
5765 .lock_cmd = SMB2_LOCK,
5767 .cap_nt_find = SMB2_NT_FIND,
5768 .cap_large_files = SMB2_LARGE_FILES,
5769 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5770 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5771 .create_lease_size = sizeof(struct create_lease_v2),
5774 struct smb_version_values smb311_values = {
5775 .version_string = SMB311_VERSION_STRING,
5776 .protocol_id = SMB311_PROT_ID,
5777 .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,
5778 .large_lock_type = 0,
5779 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5780 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5781 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5782 .header_size = sizeof(struct smb2_hdr),
5783 .header_preamble_size = 0,
5784 .max_header_size = MAX_SMB2_HDR_SIZE,
5785 .read_rsp_size = sizeof(struct smb2_read_rsp),
5786 .lock_cmd = SMB2_LOCK,
5788 .cap_nt_find = SMB2_NT_FIND,
5789 .cap_large_files = SMB2_LARGE_FILES,
5790 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5791 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5792 .create_lease_size = sizeof(struct create_lease_v2),