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 iface = niface = NULL;
622 list_for_each_entry_safe(iface, niface, &ses->iface_list,
624 ret = iface_cmp(iface, &tmp_iface);
626 /* just get a ref so that it doesn't get picked/freed */
627 iface->is_active = 1;
628 kref_get(&iface->refcount);
630 spin_unlock(&ses->iface_lock);
632 } else if (ret < 0) {
633 /* all remaining ifaces are slower */
634 kref_get(&iface->refcount);
638 spin_unlock(&ses->iface_lock);
640 /* no match. insert the entry in the list */
641 info = kmalloc(sizeof(struct cifs_server_iface),
647 memcpy(info, &tmp_iface, sizeof(tmp_iface));
649 /* add this new entry to the list */
650 kref_init(&info->refcount);
653 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, ses->iface_count);
654 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
655 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
656 le32_to_cpu(p->Capability));
658 spin_lock(&ses->iface_lock);
659 if (!list_entry_is_head(iface, &ses->iface_list, iface_head)) {
660 list_add_tail(&info->iface_head, &iface->iface_head);
661 kref_put(&iface->refcount, release_iface);
663 list_add_tail(&info->iface_head, &ses->iface_list);
666 spin_unlock(&ses->iface_lock);
667 ses->iface_last_update = jiffies;
670 next = le32_to_cpu(p->Next);
672 bytes_left -= sizeof(*p);
675 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
680 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
685 /* Azure rounds the buffer size up 8, to a 16 byte boundary */
686 if ((bytes_left > 8) || p->Next)
687 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
690 if (!ses->iface_count) {
700 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon, bool in_mount)
703 unsigned int ret_data_len = 0;
704 struct network_interface_info_ioctl_rsp *out_buf = NULL;
705 struct cifs_ses *ses = tcon->ses;
707 /* do not query too frequently */
708 if (ses->iface_last_update &&
709 time_before(jiffies, ses->iface_last_update +
710 (SMB_INTERFACE_POLL_INTERVAL * HZ)))
713 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
714 FSCTL_QUERY_NETWORK_INTERFACE_INFO,
715 NULL /* no data input */, 0 /* no data input */,
716 CIFSMaxBufSize, (char **)&out_buf, &ret_data_len);
717 if (rc == -EOPNOTSUPP) {
719 "server does not support query network interfaces\n");
721 } else if (rc != 0) {
722 cifs_tcon_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
726 rc = parse_server_interfaces(out_buf, ret_data_len, ses, in_mount);
736 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
737 struct cifs_sb_info *cifs_sb)
740 __le16 srch_path = 0; /* Null - open root of share */
741 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
742 struct cifs_open_parms oparms;
744 struct cached_fid *cfid = NULL;
746 oparms = (struct cifs_open_parms) {
749 .desired_access = FILE_READ_ATTRIBUTES,
750 .disposition = FILE_OPEN,
751 .create_options = cifs_create_options(cifs_sb, 0),
755 rc = open_cached_dir(xid, tcon, "", cifs_sb, false, &cfid);
757 memcpy(&fid, &cfid->fid, sizeof(struct cifs_fid));
759 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
764 SMB3_request_interfaces(xid, tcon, true /* called during mount */);
766 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
767 FS_ATTRIBUTE_INFORMATION);
768 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
769 FS_DEVICE_INFORMATION);
770 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
771 FS_VOLUME_INFORMATION);
772 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
773 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
775 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
777 close_cached_dir(cfid);
781 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
782 struct cifs_sb_info *cifs_sb)
785 __le16 srch_path = 0; /* Null - open root of share */
786 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
787 struct cifs_open_parms oparms;
790 oparms = (struct cifs_open_parms) {
793 .desired_access = FILE_READ_ATTRIBUTES,
794 .disposition = FILE_OPEN,
795 .create_options = cifs_create_options(cifs_sb, 0),
799 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
804 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
805 FS_ATTRIBUTE_INFORMATION);
806 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
807 FS_DEVICE_INFORMATION);
808 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
812 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
813 struct cifs_sb_info *cifs_sb, const char *full_path)
816 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
817 int err_buftype = CIFS_NO_BUFFER;
818 struct cifs_open_parms oparms;
819 struct kvec err_iov = {};
821 struct cached_fid *cfid;
825 rc = open_cached_dir(xid, tcon, full_path, cifs_sb, true, &cfid);
827 if (cfid->has_lease) {
828 close_cached_dir(cfid);
831 close_cached_dir(cfid);
834 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
838 oparms = (struct cifs_open_parms) {
841 .desired_access = FILE_READ_ATTRIBUTES,
842 .disposition = FILE_OPEN,
843 .create_options = cifs_create_options(cifs_sb, 0),
847 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
848 &err_iov, &err_buftype);
850 struct smb2_hdr *hdr = err_iov.iov_base;
852 if (unlikely(!hdr || err_buftype == CIFS_NO_BUFFER))
855 if (rc != -EREMOTE && hdr->Status == STATUS_OBJECT_NAME_INVALID) {
856 rc2 = cifs_inval_name_dfs_link_error(xid, tcon, cifs_sb,
865 if (rc == -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) && cifs_sb &&
866 (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS))
871 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
874 free_rsp_buf(err_buftype, err_iov.iov_base);
879 static int smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
880 struct cifs_sb_info *cifs_sb, const char *full_path,
881 u64 *uniqueid, struct cifs_open_info_data *data)
883 *uniqueid = le64_to_cpu(data->fi.IndexNumber);
887 static int smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
888 struct cifsFileInfo *cfile, struct cifs_open_info_data *data)
890 struct cifs_fid *fid = &cfile->fid;
892 if (cfile->symlink_target) {
893 data->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
894 if (!data->symlink_target)
897 return SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, &data->fi);
900 #ifdef CONFIG_CIFS_XATTR
902 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
903 struct smb2_file_full_ea_info *src, size_t src_size,
904 const unsigned char *ea_name)
907 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
909 size_t buf_size = dst_size;
910 size_t name_len, value_len, user_name_len;
912 while (src_size > 0) {
913 name_len = (size_t)src->ea_name_length;
914 value_len = (size_t)le16_to_cpu(src->ea_value_length);
919 if (src_size < 8 + name_len + 1 + value_len) {
920 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
925 name = &src->ea_data[0];
926 value = &src->ea_data[src->ea_name_length + 1];
929 if (ea_name_len == name_len &&
930 memcmp(ea_name, name, name_len) == 0) {
934 if (dst_size < value_len) {
938 memcpy(dst, value, value_len);
942 /* 'user.' plus a terminating null */
943 user_name_len = 5 + 1 + name_len;
946 /* skip copy - calc size only */
948 } else if (dst_size >= user_name_len) {
949 dst_size -= user_name_len;
950 memcpy(dst, "user.", 5);
952 memcpy(dst, src->ea_data, name_len);
958 /* stop before overrun buffer */
964 if (!src->next_entry_offset)
967 if (src_size < le32_to_cpu(src->next_entry_offset)) {
968 /* stop before overrun buffer */
972 src_size -= le32_to_cpu(src->next_entry_offset);
973 src = (void *)((char *)src +
974 le32_to_cpu(src->next_entry_offset));
977 /* didn't find the named attribute */
986 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
987 const unsigned char *path, const unsigned char *ea_name,
988 char *ea_data, size_t buf_size,
989 struct cifs_sb_info *cifs_sb)
992 struct kvec rsp_iov = {NULL, 0};
993 int buftype = CIFS_NO_BUFFER;
994 struct smb2_query_info_rsp *rsp;
995 struct smb2_file_full_ea_info *info = NULL;
997 rc = smb2_query_info_compound(xid, tcon, path,
999 FILE_FULL_EA_INFORMATION,
1002 MAX_SMB2_CREATE_RESPONSE_SIZE -
1003 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1004 &rsp_iov, &buftype, cifs_sb);
1007 * If ea_name is NULL (listxattr) and there are no EAs,
1008 * return 0 as it's not an error. Otherwise, the specified
1009 * ea_name was not found.
1011 if (!ea_name && rc == -ENODATA)
1016 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
1017 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1018 le32_to_cpu(rsp->OutputBufferLength),
1020 sizeof(struct smb2_file_full_ea_info));
1024 info = (struct smb2_file_full_ea_info *)(
1025 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1026 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
1027 le32_to_cpu(rsp->OutputBufferLength), ea_name);
1030 free_rsp_buf(buftype, rsp_iov.iov_base);
1036 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
1037 const char *path, const char *ea_name, const void *ea_value,
1038 const __u16 ea_value_len, const struct nls_table *nls_codepage,
1039 struct cifs_sb_info *cifs_sb)
1041 struct cifs_ses *ses = tcon->ses;
1042 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1043 __le16 *utf16_path = NULL;
1044 int ea_name_len = strlen(ea_name);
1045 int flags = CIFS_CP_CREATE_CLOSE_OP;
1047 struct smb_rqst rqst[3];
1048 int resp_buftype[3];
1049 struct kvec rsp_iov[3];
1050 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1051 struct cifs_open_parms oparms;
1052 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1053 struct cifs_fid fid;
1054 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1055 unsigned int size[1];
1057 struct smb2_file_full_ea_info *ea = NULL;
1058 struct kvec close_iov[1];
1059 struct smb2_query_info_rsp *rsp;
1060 int rc, used_len = 0;
1062 if (smb3_encryption_required(tcon))
1063 flags |= CIFS_TRANSFORM_REQ;
1065 if (ea_name_len > 255)
1068 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1072 memset(rqst, 0, sizeof(rqst));
1073 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1074 memset(rsp_iov, 0, sizeof(rsp_iov));
1076 if (ses->server->ops->query_all_EAs) {
1078 rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1084 /* If we are adding a attribute we should first check
1085 * if there will be enough space available to store
1086 * the new EA. If not we should not add it since we
1087 * would not be able to even read the EAs back.
1089 rc = smb2_query_info_compound(xid, tcon, path,
1091 FILE_FULL_EA_INFORMATION,
1094 MAX_SMB2_CREATE_RESPONSE_SIZE -
1095 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1096 &rsp_iov[1], &resp_buftype[1], cifs_sb);
1098 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1099 used_len = le32_to_cpu(rsp->OutputBufferLength);
1101 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1102 resp_buftype[1] = CIFS_NO_BUFFER;
1103 memset(&rsp_iov[1], 0, sizeof(rsp_iov[1]));
1106 /* Use a fudge factor of 256 bytes in case we collide
1107 * with a different set_EAs command.
1109 if(CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1110 MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 <
1111 used_len + ea_name_len + ea_value_len + 1) {
1119 memset(&open_iov, 0, sizeof(open_iov));
1120 rqst[0].rq_iov = open_iov;
1121 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1123 oparms = (struct cifs_open_parms) {
1126 .desired_access = FILE_WRITE_EA,
1127 .disposition = FILE_OPEN,
1128 .create_options = cifs_create_options(cifs_sb, 0),
1132 rc = SMB2_open_init(tcon, server,
1133 &rqst[0], &oplock, &oparms, utf16_path);
1136 smb2_set_next_command(tcon, &rqst[0]);
1140 memset(&si_iov, 0, sizeof(si_iov));
1141 rqst[1].rq_iov = si_iov;
1142 rqst[1].rq_nvec = 1;
1144 len = sizeof(*ea) + ea_name_len + ea_value_len + 1;
1145 ea = kzalloc(len, GFP_KERNEL);
1151 ea->ea_name_length = ea_name_len;
1152 ea->ea_value_length = cpu_to_le16(ea_value_len);
1153 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
1154 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
1159 rc = SMB2_set_info_init(tcon, server,
1160 &rqst[1], COMPOUND_FID,
1161 COMPOUND_FID, current->tgid,
1162 FILE_FULL_EA_INFORMATION,
1163 SMB2_O_INFO_FILE, 0, data, size);
1166 smb2_set_next_command(tcon, &rqst[1]);
1167 smb2_set_related(&rqst[1]);
1171 memset(&close_iov, 0, sizeof(close_iov));
1172 rqst[2].rq_iov = close_iov;
1173 rqst[2].rq_nvec = 1;
1174 rc = SMB2_close_init(tcon, server,
1175 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1178 smb2_set_related(&rqst[2]);
1180 rc = compound_send_recv(xid, ses, server,
1182 resp_buftype, rsp_iov);
1183 /* no need to bump num_remote_opens because handle immediately closed */
1188 SMB2_open_free(&rqst[0]);
1189 SMB2_set_info_free(&rqst[1]);
1190 SMB2_close_free(&rqst[2]);
1191 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1192 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1193 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1199 smb2_can_echo(struct TCP_Server_Info *server)
1201 return server->echoes;
1205 smb2_clear_stats(struct cifs_tcon *tcon)
1209 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1210 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1211 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1216 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1218 seq_puts(m, "\n\tShare Capabilities:");
1219 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1220 seq_puts(m, " DFS,");
1221 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1222 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1223 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1224 seq_puts(m, " SCALEOUT,");
1225 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1226 seq_puts(m, " CLUSTER,");
1227 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1228 seq_puts(m, " ASYMMETRIC,");
1229 if (tcon->capabilities == 0)
1230 seq_puts(m, " None");
1231 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1232 seq_puts(m, " Aligned,");
1233 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1234 seq_puts(m, " Partition Aligned,");
1235 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1236 seq_puts(m, " SSD,");
1237 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1238 seq_puts(m, " TRIM-support,");
1240 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1241 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1242 if (tcon->perf_sector_size)
1243 seq_printf(m, "\tOptimal sector size: 0x%x",
1244 tcon->perf_sector_size);
1245 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1249 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1251 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1252 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1255 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1256 * totals (requests sent) since those SMBs are per-session not per tcon
1258 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1259 (long long)(tcon->bytes_read),
1260 (long long)(tcon->bytes_written));
1261 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1262 atomic_read(&tcon->num_local_opens),
1263 atomic_read(&tcon->num_remote_opens));
1264 seq_printf(m, "\nTreeConnects: %d total %d failed",
1265 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1266 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1267 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1268 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1269 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1270 seq_printf(m, "\nCreates: %d total %d failed",
1271 atomic_read(&sent[SMB2_CREATE_HE]),
1272 atomic_read(&failed[SMB2_CREATE_HE]));
1273 seq_printf(m, "\nCloses: %d total %d failed",
1274 atomic_read(&sent[SMB2_CLOSE_HE]),
1275 atomic_read(&failed[SMB2_CLOSE_HE]));
1276 seq_printf(m, "\nFlushes: %d total %d failed",
1277 atomic_read(&sent[SMB2_FLUSH_HE]),
1278 atomic_read(&failed[SMB2_FLUSH_HE]));
1279 seq_printf(m, "\nReads: %d total %d failed",
1280 atomic_read(&sent[SMB2_READ_HE]),
1281 atomic_read(&failed[SMB2_READ_HE]));
1282 seq_printf(m, "\nWrites: %d total %d failed",
1283 atomic_read(&sent[SMB2_WRITE_HE]),
1284 atomic_read(&failed[SMB2_WRITE_HE]));
1285 seq_printf(m, "\nLocks: %d total %d failed",
1286 atomic_read(&sent[SMB2_LOCK_HE]),
1287 atomic_read(&failed[SMB2_LOCK_HE]));
1288 seq_printf(m, "\nIOCTLs: %d total %d failed",
1289 atomic_read(&sent[SMB2_IOCTL_HE]),
1290 atomic_read(&failed[SMB2_IOCTL_HE]));
1291 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1292 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1293 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1294 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1295 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1296 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1297 seq_printf(m, "\nQueryInfos: %d total %d failed",
1298 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1299 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1300 seq_printf(m, "\nSetInfos: %d total %d failed",
1301 atomic_read(&sent[SMB2_SET_INFO_HE]),
1302 atomic_read(&failed[SMB2_SET_INFO_HE]));
1303 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1304 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1305 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1309 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1311 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1312 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1314 cfile->fid.persistent_fid = fid->persistent_fid;
1315 cfile->fid.volatile_fid = fid->volatile_fid;
1316 cfile->fid.access = fid->access;
1317 #ifdef CONFIG_CIFS_DEBUG2
1318 cfile->fid.mid = fid->mid;
1319 #endif /* CIFS_DEBUG2 */
1320 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1322 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1323 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1327 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1328 struct cifs_fid *fid)
1330 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1334 smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon,
1335 struct cifsFileInfo *cfile)
1337 struct smb2_file_network_open_info file_inf;
1338 struct inode *inode;
1341 rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid,
1342 cfile->fid.volatile_fid, &file_inf);
1346 inode = d_inode(cfile->dentry);
1348 spin_lock(&inode->i_lock);
1349 CIFS_I(inode)->time = jiffies;
1351 /* Creation time should not need to be updated on close */
1352 if (file_inf.LastWriteTime)
1353 inode->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime);
1354 if (file_inf.ChangeTime)
1355 inode->i_ctime = cifs_NTtimeToUnix(file_inf.ChangeTime);
1356 if (file_inf.LastAccessTime)
1357 inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime);
1360 * i_blocks is not related to (i_size / i_blksize),
1361 * but instead 512 byte (2**9) size is required for
1362 * calculating num blocks.
1364 if (le64_to_cpu(file_inf.AllocationSize) > 4096)
1366 (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9;
1368 /* End of file and Attributes should not have to be updated on close */
1369 spin_unlock(&inode->i_lock);
1373 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1374 u64 persistent_fid, u64 volatile_fid,
1375 struct copychunk_ioctl *pcchunk)
1378 unsigned int ret_data_len;
1379 struct resume_key_req *res_key;
1381 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1382 FSCTL_SRV_REQUEST_RESUME_KEY, NULL, 0 /* no input */,
1383 CIFSMaxBufSize, (char **)&res_key, &ret_data_len);
1385 if (rc == -EOPNOTSUPP) {
1386 pr_warn_once("Server share %s does not support copy range\n", tcon->tree_name);
1387 goto req_res_key_exit;
1389 cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1390 goto req_res_key_exit;
1392 if (ret_data_len < sizeof(struct resume_key_req)) {
1393 cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n");
1395 goto req_res_key_exit;
1397 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1405 struct smb_rqst rqst[3];
1406 struct kvec rsp_iov[3];
1407 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1408 struct kvec qi_iov[1];
1409 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
1410 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1411 struct kvec close_iov[1];
1415 smb2_ioctl_query_info(const unsigned int xid,
1416 struct cifs_tcon *tcon,
1417 struct cifs_sb_info *cifs_sb,
1418 __le16 *path, int is_dir,
1421 struct iqi_vars *vars;
1422 struct smb_rqst *rqst;
1423 struct kvec *rsp_iov;
1424 struct cifs_ses *ses = tcon->ses;
1425 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1426 char __user *arg = (char __user *)p;
1427 struct smb_query_info qi;
1428 struct smb_query_info __user *pqi;
1430 int flags = CIFS_CP_CREATE_CLOSE_OP;
1431 struct smb2_query_info_rsp *qi_rsp = NULL;
1432 struct smb2_ioctl_rsp *io_rsp = NULL;
1433 void *buffer = NULL;
1434 int resp_buftype[3];
1435 struct cifs_open_parms oparms;
1436 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1437 struct cifs_fid fid;
1438 unsigned int size[2];
1440 int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR;
1441 void (*free_req1_func)(struct smb_rqst *r);
1443 vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
1446 rqst = &vars->rqst[0];
1447 rsp_iov = &vars->rsp_iov[0];
1449 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1451 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info))) {
1455 if (qi.output_buffer_length > 1024) {
1460 if (!ses || !server) {
1465 if (smb3_encryption_required(tcon))
1466 flags |= CIFS_TRANSFORM_REQ;
1468 if (qi.output_buffer_length) {
1469 buffer = memdup_user(arg + sizeof(struct smb_query_info), qi.output_buffer_length);
1470 if (IS_ERR(buffer)) {
1471 rc = PTR_ERR(buffer);
1477 rqst[0].rq_iov = &vars->open_iov[0];
1478 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1480 oparms = (struct cifs_open_parms) {
1482 .disposition = FILE_OPEN,
1483 .create_options = cifs_create_options(cifs_sb, create_options),
1487 if (qi.flags & PASSTHRU_FSCTL) {
1488 switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1489 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1490 oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1492 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1493 oparms.desired_access = GENERIC_ALL;
1495 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1496 oparms.desired_access = GENERIC_READ;
1498 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1499 oparms.desired_access = GENERIC_WRITE;
1502 } else if (qi.flags & PASSTHRU_SET_INFO) {
1503 oparms.desired_access = GENERIC_WRITE;
1505 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1508 rc = SMB2_open_init(tcon, server,
1509 &rqst[0], &oplock, &oparms, path);
1511 goto free_output_buffer;
1512 smb2_set_next_command(tcon, &rqst[0]);
1515 if (qi.flags & PASSTHRU_FSCTL) {
1516 /* Can eventually relax perm check since server enforces too */
1517 if (!capable(CAP_SYS_ADMIN)) {
1521 rqst[1].rq_iov = &vars->io_iov[0];
1522 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1524 rc = SMB2_ioctl_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1525 qi.info_type, buffer, qi.output_buffer_length,
1526 CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1527 MAX_SMB2_CLOSE_RESPONSE_SIZE);
1528 free_req1_func = SMB2_ioctl_free;
1529 } else if (qi.flags == PASSTHRU_SET_INFO) {
1530 /* Can eventually relax perm check since server enforces too */
1531 if (!capable(CAP_SYS_ADMIN)) {
1535 if (qi.output_buffer_length < 8) {
1539 rqst[1].rq_iov = &vars->si_iov[0];
1540 rqst[1].rq_nvec = 1;
1542 /* MS-FSCC 2.4.13 FileEndOfFileInformation */
1546 rc = SMB2_set_info_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1547 current->tgid, FILE_END_OF_FILE_INFORMATION,
1548 SMB2_O_INFO_FILE, 0, data, size);
1549 free_req1_func = SMB2_set_info_free;
1550 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1551 rqst[1].rq_iov = &vars->qi_iov[0];
1552 rqst[1].rq_nvec = 1;
1554 rc = SMB2_query_info_init(tcon, server,
1555 &rqst[1], COMPOUND_FID,
1556 COMPOUND_FID, qi.file_info_class,
1557 qi.info_type, qi.additional_information,
1558 qi.input_buffer_length,
1559 qi.output_buffer_length, buffer);
1560 free_req1_func = SMB2_query_info_free;
1561 } else { /* unknown flags */
1562 cifs_tcon_dbg(VFS, "Invalid passthru query flags: 0x%x\n",
1569 smb2_set_next_command(tcon, &rqst[1]);
1570 smb2_set_related(&rqst[1]);
1573 rqst[2].rq_iov = &vars->close_iov[0];
1574 rqst[2].rq_nvec = 1;
1576 rc = SMB2_close_init(tcon, server,
1577 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1580 smb2_set_related(&rqst[2]);
1582 rc = compound_send_recv(xid, ses, server,
1584 resp_buftype, rsp_iov);
1588 /* No need to bump num_remote_opens since handle immediately closed */
1589 if (qi.flags & PASSTHRU_FSCTL) {
1590 pqi = (struct smb_query_info __user *)arg;
1591 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1592 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1593 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1594 if (qi.input_buffer_length > 0 &&
1595 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length
1596 > rsp_iov[1].iov_len) {
1601 if (copy_to_user(&pqi->input_buffer_length,
1602 &qi.input_buffer_length,
1603 sizeof(qi.input_buffer_length))) {
1608 if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1609 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1610 qi.input_buffer_length))
1613 pqi = (struct smb_query_info __user *)arg;
1614 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1615 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1616 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1617 if (copy_to_user(&pqi->input_buffer_length,
1618 &qi.input_buffer_length,
1619 sizeof(qi.input_buffer_length))) {
1624 if (copy_to_user(pqi + 1, qi_rsp->Buffer,
1625 qi.input_buffer_length))
1630 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1631 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1632 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1633 SMB2_close_free(&rqst[2]);
1635 free_req1_func(&rqst[1]);
1637 SMB2_open_free(&rqst[0]);
1646 smb2_copychunk_range(const unsigned int xid,
1647 struct cifsFileInfo *srcfile,
1648 struct cifsFileInfo *trgtfile, u64 src_off,
1649 u64 len, u64 dest_off)
1652 unsigned int ret_data_len;
1653 struct copychunk_ioctl *pcchunk;
1654 struct copychunk_ioctl_rsp *retbuf = NULL;
1655 struct cifs_tcon *tcon;
1656 int chunks_copied = 0;
1657 bool chunk_sizes_updated = false;
1658 ssize_t bytes_written, total_bytes_written = 0;
1660 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1661 if (pcchunk == NULL)
1664 cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
1665 /* Request a key from the server to identify the source of the copy */
1666 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1667 srcfile->fid.persistent_fid,
1668 srcfile->fid.volatile_fid, pcchunk);
1670 /* Note: request_res_key sets res_key null only if rc !=0 */
1674 /* For now array only one chunk long, will make more flexible later */
1675 pcchunk->ChunkCount = cpu_to_le32(1);
1676 pcchunk->Reserved = 0;
1677 pcchunk->Reserved2 = 0;
1679 tcon = tlink_tcon(trgtfile->tlink);
1682 pcchunk->SourceOffset = cpu_to_le64(src_off);
1683 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1685 cpu_to_le32(min_t(u64, len, tcon->max_bytes_chunk));
1687 /* Request server copy to target from src identified by key */
1690 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1691 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1692 (char *)pcchunk, sizeof(struct copychunk_ioctl),
1693 CIFSMaxBufSize, (char **)&retbuf, &ret_data_len);
1696 sizeof(struct copychunk_ioctl_rsp)) {
1697 cifs_tcon_dbg(VFS, "Invalid cchunk response size\n");
1701 if (retbuf->TotalBytesWritten == 0) {
1702 cifs_dbg(FYI, "no bytes copied\n");
1707 * Check if server claimed to write more than we asked
1709 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1710 le32_to_cpu(pcchunk->Length)) {
1711 cifs_tcon_dbg(VFS, "Invalid copy chunk response\n");
1715 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1716 cifs_tcon_dbg(VFS, "Invalid num chunks written\n");
1722 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1723 src_off += bytes_written;
1724 dest_off += bytes_written;
1725 len -= bytes_written;
1726 total_bytes_written += bytes_written;
1728 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1729 le32_to_cpu(retbuf->ChunksWritten),
1730 le32_to_cpu(retbuf->ChunkBytesWritten),
1732 } else if (rc == -EINVAL) {
1733 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1736 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1737 le32_to_cpu(retbuf->ChunksWritten),
1738 le32_to_cpu(retbuf->ChunkBytesWritten),
1739 le32_to_cpu(retbuf->TotalBytesWritten));
1742 * Check if this is the first request using these sizes,
1743 * (ie check if copy succeed once with original sizes
1744 * and check if the server gave us different sizes after
1745 * we already updated max sizes on previous request).
1746 * if not then why is the server returning an error now
1748 if ((chunks_copied != 0) || chunk_sizes_updated)
1751 /* Check that server is not asking us to grow size */
1752 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1753 tcon->max_bytes_chunk)
1754 tcon->max_bytes_chunk =
1755 le32_to_cpu(retbuf->ChunkBytesWritten);
1757 goto cchunk_out; /* server gave us bogus size */
1759 /* No need to change MaxChunks since already set to 1 */
1760 chunk_sizes_updated = true;
1771 return total_bytes_written;
1775 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1776 struct cifs_fid *fid)
1778 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1782 smb2_read_data_offset(char *buf)
1784 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1786 return rsp->DataOffset;
1790 smb2_read_data_length(char *buf, bool in_remaining)
1792 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1795 return le32_to_cpu(rsp->DataRemaining);
1797 return le32_to_cpu(rsp->DataLength);
1802 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1803 struct cifs_io_parms *parms, unsigned int *bytes_read,
1804 char **buf, int *buf_type)
1806 parms->persistent_fid = pfid->persistent_fid;
1807 parms->volatile_fid = pfid->volatile_fid;
1808 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1812 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1813 struct cifs_io_parms *parms, unsigned int *written,
1814 struct kvec *iov, unsigned long nr_segs)
1817 parms->persistent_fid = pfid->persistent_fid;
1818 parms->volatile_fid = pfid->volatile_fid;
1819 return SMB2_write(xid, parms, written, iov, nr_segs);
1822 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1823 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1824 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1826 struct cifsInodeInfo *cifsi;
1829 cifsi = CIFS_I(inode);
1831 /* if file already sparse don't bother setting sparse again */
1832 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1833 return true; /* already sparse */
1835 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1836 return true; /* already not sparse */
1839 * Can't check for sparse support on share the usual way via the
1840 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1841 * since Samba server doesn't set the flag on the share, yet
1842 * supports the set sparse FSCTL and returns sparse correctly
1843 * in the file attributes. If we fail setting sparse though we
1844 * mark that server does not support sparse files for this share
1845 * to avoid repeatedly sending the unsupported fsctl to server
1846 * if the file is repeatedly extended.
1848 if (tcon->broken_sparse_sup)
1851 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1852 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1853 &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
1855 tcon->broken_sparse_sup = true;
1856 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1861 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1863 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1869 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1870 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1872 __le64 eof = cpu_to_le64(size);
1873 struct inode *inode;
1876 * If extending file more than one page make sparse. Many Linux fs
1877 * make files sparse by default when extending via ftruncate
1879 inode = d_inode(cfile->dentry);
1881 if (!set_alloc && (size > inode->i_size + 8192)) {
1882 __u8 set_sparse = 1;
1884 /* whether set sparse succeeds or not, extend the file */
1885 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1888 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1889 cfile->fid.volatile_fid, cfile->pid, &eof);
1893 smb2_duplicate_extents(const unsigned int xid,
1894 struct cifsFileInfo *srcfile,
1895 struct cifsFileInfo *trgtfile, u64 src_off,
1896 u64 len, u64 dest_off)
1899 unsigned int ret_data_len;
1900 struct inode *inode;
1901 struct duplicate_extents_to_file dup_ext_buf;
1902 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1904 /* server fileays advertise duplicate extent support with this flag */
1905 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1906 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1909 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1910 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1911 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1912 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1913 dup_ext_buf.ByteCount = cpu_to_le64(len);
1914 cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
1915 src_off, dest_off, len);
1917 inode = d_inode(trgtfile->dentry);
1918 if (inode->i_size < dest_off + len) {
1919 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1921 goto duplicate_extents_out;
1924 * Although also could set plausible allocation size (i_blocks)
1925 * here in addition to setting the file size, in reflink
1926 * it is likely that the target file is sparse. Its allocation
1927 * size will be queried on next revalidate, but it is important
1928 * to make sure that file's cached size is updated immediately
1930 cifs_setsize(inode, dest_off + len);
1932 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1933 trgtfile->fid.volatile_fid,
1934 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1935 (char *)&dup_ext_buf,
1936 sizeof(struct duplicate_extents_to_file),
1937 CIFSMaxBufSize, NULL,
1940 if (ret_data_len > 0)
1941 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
1943 duplicate_extents_out:
1948 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1949 struct cifsFileInfo *cfile)
1951 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1952 cfile->fid.volatile_fid);
1956 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
1957 struct cifsFileInfo *cfile)
1959 struct fsctl_set_integrity_information_req integr_info;
1960 unsigned int ret_data_len;
1962 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
1963 integr_info.Flags = 0;
1964 integr_info.Reserved = 0;
1966 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1967 cfile->fid.volatile_fid,
1968 FSCTL_SET_INTEGRITY_INFORMATION,
1969 (char *)&integr_info,
1970 sizeof(struct fsctl_set_integrity_information_req),
1971 CIFSMaxBufSize, NULL,
1976 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
1977 #define GMT_TOKEN_SIZE 50
1979 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
1982 * Input buffer contains (empty) struct smb_snapshot array with size filled in
1983 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
1986 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
1987 struct cifsFileInfo *cfile, void __user *ioc_buf)
1989 char *retbuf = NULL;
1990 unsigned int ret_data_len = 0;
1992 u32 max_response_size;
1993 struct smb_snapshot_array snapshot_in;
1996 * On the first query to enumerate the list of snapshots available
1997 * for this volume the buffer begins with 0 (number of snapshots
1998 * which can be returned is zero since at that point we do not know
1999 * how big the buffer needs to be). On the second query,
2000 * it (ret_data_len) is set to number of snapshots so we can
2001 * know to set the maximum response size larger (see below).
2003 if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
2007 * Note that for snapshot queries that servers like Azure expect that
2008 * the first query be minimal size (and just used to get the number/size
2009 * of previous versions) so response size must be specified as EXACTLY
2010 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
2013 if (ret_data_len == 0)
2014 max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
2016 max_response_size = CIFSMaxBufSize;
2018 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2019 cfile->fid.volatile_fid,
2020 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
2021 NULL, 0 /* no input data */, max_response_size,
2024 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
2029 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
2031 if (copy_from_user(&snapshot_in, ioc_buf,
2032 sizeof(struct smb_snapshot_array))) {
2039 * Check for min size, ie not large enough to fit even one GMT
2040 * token (snapshot). On the first ioctl some users may pass in
2041 * smaller size (or zero) to simply get the size of the array
2042 * so the user space caller can allocate sufficient memory
2043 * and retry the ioctl again with larger array size sufficient
2044 * to hold all of the snapshot GMT tokens on the second try.
2046 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
2047 ret_data_len = sizeof(struct smb_snapshot_array);
2050 * We return struct SRV_SNAPSHOT_ARRAY, followed by
2051 * the snapshot array (of 50 byte GMT tokens) each
2052 * representing an available previous version of the data
2054 if (ret_data_len > (snapshot_in.snapshot_array_size +
2055 sizeof(struct smb_snapshot_array)))
2056 ret_data_len = snapshot_in.snapshot_array_size +
2057 sizeof(struct smb_snapshot_array);
2059 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
2070 smb3_notify(const unsigned int xid, struct file *pfile,
2071 void __user *ioc_buf, bool return_changes)
2073 struct smb3_notify_info notify;
2074 struct smb3_notify_info __user *pnotify_buf;
2075 struct dentry *dentry = pfile->f_path.dentry;
2076 struct inode *inode = file_inode(pfile);
2077 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2078 struct cifs_open_parms oparms;
2079 struct cifs_fid fid;
2080 struct cifs_tcon *tcon;
2081 const unsigned char *path;
2082 char *returned_ioctl_info = NULL;
2083 void *page = alloc_dentry_path();
2084 __le16 *utf16_path = NULL;
2085 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2089 path = build_path_from_dentry(dentry, page);
2095 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2096 if (utf16_path == NULL) {
2101 if (return_changes) {
2102 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify_info))) {
2107 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify))) {
2111 notify.data_len = 0;
2114 tcon = cifs_sb_master_tcon(cifs_sb);
2115 oparms = (struct cifs_open_parms) {
2118 .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
2119 .disposition = FILE_OPEN,
2120 .create_options = cifs_create_options(cifs_sb, 0),
2124 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
2129 rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid,
2130 notify.watch_tree, notify.completion_filter,
2131 notify.data_len, &returned_ioctl_info, &ret_len);
2133 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2135 cifs_dbg(FYI, "change notify for path %s rc %d\n", path, rc);
2136 if (return_changes && (ret_len > 0) && (notify.data_len > 0)) {
2137 if (ret_len > notify.data_len)
2138 ret_len = notify.data_len;
2139 pnotify_buf = (struct smb3_notify_info __user *)ioc_buf;
2140 if (copy_to_user(pnotify_buf->notify_data, returned_ioctl_info, ret_len))
2142 else if (copy_to_user(&pnotify_buf->data_len, &ret_len, sizeof(ret_len)))
2145 kfree(returned_ioctl_info);
2147 free_dentry_path(page);
2153 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
2154 const char *path, struct cifs_sb_info *cifs_sb,
2155 struct cifs_fid *fid, __u16 search_flags,
2156 struct cifs_search_info *srch_inf)
2159 struct smb_rqst rqst[2];
2160 struct kvec rsp_iov[2];
2161 int resp_buftype[2];
2162 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2163 struct kvec qd_iov[SMB2_QUERY_DIRECTORY_IOV_SIZE];
2165 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2166 struct cifs_open_parms oparms;
2167 struct smb2_query_directory_rsp *qd_rsp = NULL;
2168 struct smb2_create_rsp *op_rsp = NULL;
2169 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2170 int retry_count = 0;
2172 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2176 if (smb3_encryption_required(tcon))
2177 flags |= CIFS_TRANSFORM_REQ;
2179 memset(rqst, 0, sizeof(rqst));
2180 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
2181 memset(rsp_iov, 0, sizeof(rsp_iov));
2184 memset(&open_iov, 0, sizeof(open_iov));
2185 rqst[0].rq_iov = open_iov;
2186 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2188 oparms = (struct cifs_open_parms) {
2191 .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
2192 .disposition = FILE_OPEN,
2193 .create_options = cifs_create_options(cifs_sb, 0),
2197 rc = SMB2_open_init(tcon, server,
2198 &rqst[0], &oplock, &oparms, utf16_path);
2201 smb2_set_next_command(tcon, &rqst[0]);
2203 /* Query directory */
2204 srch_inf->entries_in_buffer = 0;
2205 srch_inf->index_of_last_entry = 2;
2207 memset(&qd_iov, 0, sizeof(qd_iov));
2208 rqst[1].rq_iov = qd_iov;
2209 rqst[1].rq_nvec = SMB2_QUERY_DIRECTORY_IOV_SIZE;
2211 rc = SMB2_query_directory_init(xid, tcon, server,
2213 COMPOUND_FID, COMPOUND_FID,
2214 0, srch_inf->info_level);
2218 smb2_set_related(&rqst[1]);
2221 rc = compound_send_recv(xid, tcon->ses, server,
2223 resp_buftype, rsp_iov);
2225 if (rc == -EAGAIN && retry_count++ < 10)
2228 /* If the open failed there is nothing to do */
2229 op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
2230 if (op_rsp == NULL || op_rsp->hdr.Status != STATUS_SUCCESS) {
2231 cifs_dbg(FYI, "query_dir_first: open failed rc=%d\n", rc);
2234 fid->persistent_fid = op_rsp->PersistentFileId;
2235 fid->volatile_fid = op_rsp->VolatileFileId;
2237 /* Anything else than ENODATA means a genuine error */
2238 if (rc && rc != -ENODATA) {
2239 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2240 cifs_dbg(FYI, "query_dir_first: query directory failed rc=%d\n", rc);
2241 trace_smb3_query_dir_err(xid, fid->persistent_fid,
2242 tcon->tid, tcon->ses->Suid, 0, 0, rc);
2246 atomic_inc(&tcon->num_remote_opens);
2248 qd_rsp = (struct smb2_query_directory_rsp *)rsp_iov[1].iov_base;
2249 if (qd_rsp->hdr.Status == STATUS_NO_MORE_FILES) {
2250 trace_smb3_query_dir_done(xid, fid->persistent_fid,
2251 tcon->tid, tcon->ses->Suid, 0, 0);
2252 srch_inf->endOfSearch = true;
2257 rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1],
2260 trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid,
2261 tcon->ses->Suid, 0, 0, rc);
2264 resp_buftype[1] = CIFS_NO_BUFFER;
2266 trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid,
2267 tcon->ses->Suid, 0, srch_inf->entries_in_buffer);
2271 SMB2_open_free(&rqst[0]);
2272 SMB2_query_directory_free(&rqst[1]);
2273 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2274 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2279 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
2280 struct cifs_fid *fid, __u16 search_flags,
2281 struct cifs_search_info *srch_inf)
2283 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
2284 fid->volatile_fid, 0, srch_inf);
2288 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
2289 struct cifs_fid *fid)
2291 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2295 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2296 * the number of credits and return true. Otherwise - return false.
2299 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
2301 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2302 int scredits, in_flight;
2304 if (shdr->Status != STATUS_PENDING)
2307 if (shdr->CreditRequest) {
2308 spin_lock(&server->req_lock);
2309 server->credits += le16_to_cpu(shdr->CreditRequest);
2310 scredits = server->credits;
2311 in_flight = server->in_flight;
2312 spin_unlock(&server->req_lock);
2313 wake_up(&server->request_q);
2315 trace_smb3_pend_credits(server->CurrentMid,
2316 server->conn_id, server->hostname, scredits,
2317 le16_to_cpu(shdr->CreditRequest), in_flight);
2318 cifs_dbg(FYI, "%s: status pending add %u credits total=%d\n",
2319 __func__, le16_to_cpu(shdr->CreditRequest), scredits);
2326 smb2_is_session_expired(char *buf)
2328 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2330 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
2331 shdr->Status != STATUS_USER_SESSION_DELETED)
2334 trace_smb3_ses_expired(le32_to_cpu(shdr->Id.SyncId.TreeId),
2335 le64_to_cpu(shdr->SessionId),
2336 le16_to_cpu(shdr->Command),
2337 le64_to_cpu(shdr->MessageId));
2338 cifs_dbg(FYI, "Session expired or deleted\n");
2344 smb2_is_status_io_timeout(char *buf)
2346 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2348 if (shdr->Status == STATUS_IO_TIMEOUT)
2355 smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server)
2357 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2358 struct TCP_Server_Info *pserver;
2359 struct cifs_ses *ses;
2360 struct cifs_tcon *tcon;
2362 if (shdr->Status != STATUS_NETWORK_NAME_DELETED)
2365 /* If server is a channel, select the primary channel */
2366 pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
2368 spin_lock(&cifs_tcp_ses_lock);
2369 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
2370 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
2371 if (tcon->tid == le32_to_cpu(shdr->Id.SyncId.TreeId)) {
2372 spin_lock(&tcon->tc_lock);
2373 tcon->need_reconnect = true;
2374 spin_unlock(&tcon->tc_lock);
2375 spin_unlock(&cifs_tcp_ses_lock);
2376 pr_warn_once("Server share %s deleted.\n",
2382 spin_unlock(&cifs_tcp_ses_lock);
2386 smb2_oplock_response(struct cifs_tcon *tcon, __u64 persistent_fid,
2387 __u64 volatile_fid, __u16 net_fid, struct cifsInodeInfo *cinode)
2389 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
2390 return SMB2_lease_break(0, tcon, cinode->lease_key,
2391 smb2_get_lease_state(cinode));
2393 return SMB2_oplock_break(0, tcon, persistent_fid, volatile_fid,
2394 CIFS_CACHE_READ(cinode) ? 1 : 0);
2398 smb2_set_related(struct smb_rqst *rqst)
2400 struct smb2_hdr *shdr;
2402 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2404 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2407 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2410 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
2413 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
2415 struct smb2_hdr *shdr;
2416 struct cifs_ses *ses = tcon->ses;
2417 struct TCP_Server_Info *server = ses->server;
2418 unsigned long len = smb_rqst_len(server, rqst);
2421 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2423 cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2427 /* SMB headers in a compound are 8 byte aligned. */
2429 /* No padding needed */
2433 num_padding = 8 - (len & 7);
2434 if (!smb3_encryption_required(tcon)) {
2436 * If we do not have encryption then we can just add an extra
2437 * iov for the padding.
2439 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2440 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2445 * We can not add a small padding iov for the encryption case
2446 * because the encryption framework can not handle the padding
2448 * We have to flatten this into a single buffer and add
2449 * the padding to it.
2451 for (i = 1; i < rqst->rq_nvec; i++) {
2452 memcpy(rqst->rq_iov[0].iov_base +
2453 rqst->rq_iov[0].iov_len,
2454 rqst->rq_iov[i].iov_base,
2455 rqst->rq_iov[i].iov_len);
2456 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2458 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2460 rqst->rq_iov[0].iov_len += num_padding;
2466 shdr->NextCommand = cpu_to_le32(len);
2470 * Passes the query info response back to the caller on success.
2471 * Caller need to free this with free_rsp_buf().
2474 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2475 const char *path, u32 desired_access,
2476 u32 class, u32 type, u32 output_len,
2477 struct kvec *rsp, int *buftype,
2478 struct cifs_sb_info *cifs_sb)
2480 struct cifs_ses *ses = tcon->ses;
2481 struct TCP_Server_Info *server = cifs_pick_channel(ses);
2482 int flags = CIFS_CP_CREATE_CLOSE_OP;
2483 struct smb_rqst rqst[3];
2484 int resp_buftype[3];
2485 struct kvec rsp_iov[3];
2486 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2487 struct kvec qi_iov[1];
2488 struct kvec close_iov[1];
2489 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2490 struct cifs_open_parms oparms;
2491 struct cifs_fid fid;
2494 struct cached_fid *cfid = NULL;
2498 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2502 if (smb3_encryption_required(tcon))
2503 flags |= CIFS_TRANSFORM_REQ;
2505 memset(rqst, 0, sizeof(rqst));
2506 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2507 memset(rsp_iov, 0, sizeof(rsp_iov));
2510 * We can only call this for things we know are directories.
2512 if (!strcmp(path, ""))
2513 open_cached_dir(xid, tcon, path, cifs_sb, false,
2514 &cfid); /* cfid null if open dir failed */
2516 memset(&open_iov, 0, sizeof(open_iov));
2517 rqst[0].rq_iov = open_iov;
2518 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2520 oparms = (struct cifs_open_parms) {
2523 .desired_access = desired_access,
2524 .disposition = FILE_OPEN,
2525 .create_options = cifs_create_options(cifs_sb, 0),
2529 rc = SMB2_open_init(tcon, server,
2530 &rqst[0], &oplock, &oparms, utf16_path);
2533 smb2_set_next_command(tcon, &rqst[0]);
2535 memset(&qi_iov, 0, sizeof(qi_iov));
2536 rqst[1].rq_iov = qi_iov;
2537 rqst[1].rq_nvec = 1;
2540 rc = SMB2_query_info_init(tcon, server,
2542 cfid->fid.persistent_fid,
2543 cfid->fid.volatile_fid,
2548 rc = SMB2_query_info_init(tcon, server,
2559 smb2_set_next_command(tcon, &rqst[1]);
2560 smb2_set_related(&rqst[1]);
2563 memset(&close_iov, 0, sizeof(close_iov));
2564 rqst[2].rq_iov = close_iov;
2565 rqst[2].rq_nvec = 1;
2567 rc = SMB2_close_init(tcon, server,
2568 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2571 smb2_set_related(&rqst[2]);
2574 rc = compound_send_recv(xid, ses, server,
2576 &resp_buftype[1], &rsp_iov[1]);
2578 rc = compound_send_recv(xid, ses, server,
2580 resp_buftype, rsp_iov);
2583 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2584 if (rc == -EREMCHG) {
2585 tcon->need_reconnect = true;
2586 pr_warn_once("server share %s deleted\n",
2592 *buftype = resp_buftype[1];
2596 SMB2_open_free(&rqst[0]);
2597 SMB2_query_info_free(&rqst[1]);
2598 SMB2_close_free(&rqst[2]);
2599 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2600 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2602 close_cached_dir(cfid);
2607 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2608 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2610 struct smb2_query_info_rsp *rsp;
2611 struct smb2_fs_full_size_info *info = NULL;
2612 struct kvec rsp_iov = {NULL, 0};
2613 int buftype = CIFS_NO_BUFFER;
2617 rc = smb2_query_info_compound(xid, tcon, "",
2618 FILE_READ_ATTRIBUTES,
2619 FS_FULL_SIZE_INFORMATION,
2620 SMB2_O_INFO_FILESYSTEM,
2621 sizeof(struct smb2_fs_full_size_info),
2622 &rsp_iov, &buftype, cifs_sb);
2626 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2627 buf->f_type = SMB2_SUPER_MAGIC;
2628 info = (struct smb2_fs_full_size_info *)(
2629 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2630 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2631 le32_to_cpu(rsp->OutputBufferLength),
2633 sizeof(struct smb2_fs_full_size_info));
2635 smb2_copy_fs_info_to_kstatfs(info, buf);
2638 free_rsp_buf(buftype, rsp_iov.iov_base);
2643 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2644 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2647 __le16 srch_path = 0; /* Null - open root of share */
2648 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2649 struct cifs_open_parms oparms;
2650 struct cifs_fid fid;
2652 if (!tcon->posix_extensions)
2653 return smb2_queryfs(xid, tcon, cifs_sb, buf);
2655 oparms = (struct cifs_open_parms) {
2658 .desired_access = FILE_READ_ATTRIBUTES,
2659 .disposition = FILE_OPEN,
2660 .create_options = cifs_create_options(cifs_sb, 0),
2664 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
2669 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2670 fid.volatile_fid, buf);
2671 buf->f_type = SMB2_SUPER_MAGIC;
2672 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2677 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2679 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2680 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2684 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2685 __u64 length, __u32 type, int lock, int unlock, bool wait)
2687 if (unlock && !lock)
2688 type = SMB2_LOCKFLAG_UNLOCK;
2689 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2690 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2691 current->tgid, length, offset, type, wait);
2695 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2697 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2701 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2703 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2707 smb2_new_lease_key(struct cifs_fid *fid)
2709 generate_random_uuid(fid->lease_key);
2713 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2714 const char *search_name,
2715 struct dfs_info3_param **target_nodes,
2716 unsigned int *num_of_nodes,
2717 const struct nls_table *nls_codepage, int remap)
2720 __le16 *utf16_path = NULL;
2721 int utf16_path_len = 0;
2722 struct cifs_tcon *tcon;
2723 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2724 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2725 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2726 int retry_count = 0;
2728 cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name);
2731 * Try to use the IPC tcon, otherwise just use any
2733 tcon = ses->tcon_ipc;
2735 spin_lock(&cifs_tcp_ses_lock);
2736 tcon = list_first_entry_or_null(&ses->tcon_list,
2741 spin_unlock(&cifs_tcp_ses_lock);
2745 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2751 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2753 nls_codepage, remap);
2759 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2760 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2766 /* Highest DFS referral version understood */
2767 dfs_req->MaxReferralLevel = DFS_VERSION;
2769 /* Path to resolve in an UTF-16 null-terminated string */
2770 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2773 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2774 FSCTL_DFS_GET_REFERRALS,
2775 (char *)dfs_req, dfs_req_size, CIFSMaxBufSize,
2776 (char **)&dfs_rsp, &dfs_rsp_size);
2777 if (!is_retryable_error(rc))
2779 usleep_range(512, 2048);
2780 } while (++retry_count < 5);
2783 if (!is_retryable_error(rc) && rc != -ENOENT && rc != -EOPNOTSUPP)
2784 cifs_tcon_dbg(VFS, "%s: ioctl error: rc=%d\n", __func__, rc);
2788 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
2789 num_of_nodes, target_nodes,
2790 nls_codepage, remap, search_name,
2791 true /* is_unicode */);
2793 cifs_tcon_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc);
2798 if (tcon && !tcon->ipc) {
2799 /* ipc tcons are not refcounted */
2800 spin_lock(&cifs_tcp_ses_lock);
2802 /* tc_count can never go negative */
2803 WARN_ON(tcon->tc_count < 0);
2804 spin_unlock(&cifs_tcp_ses_lock);
2813 parse_reparse_posix(struct reparse_posix_data *symlink_buf,
2814 u32 plen, char **target_path,
2815 struct cifs_sb_info *cifs_sb)
2819 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
2820 len = le16_to_cpu(symlink_buf->ReparseDataLength);
2822 if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
2823 cifs_dbg(VFS, "%lld not a supported symlink type\n",
2824 le64_to_cpu(symlink_buf->InodeType));
2828 *target_path = cifs_strndup_from_utf16(
2829 symlink_buf->PathBuffer,
2830 len, true, cifs_sb->local_nls);
2831 if (!(*target_path))
2834 convert_delimiter(*target_path, '/');
2835 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2841 parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
2842 u32 plen, char **target_path,
2843 struct cifs_sb_info *cifs_sb)
2845 unsigned int sub_len;
2846 unsigned int sub_offset;
2848 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */
2850 sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset);
2851 sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength);
2852 if (sub_offset + 20 > plen ||
2853 sub_offset + sub_len + 20 > plen) {
2854 cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
2858 *target_path = cifs_strndup_from_utf16(
2859 symlink_buf->PathBuffer + sub_offset,
2860 sub_len, true, cifs_sb->local_nls);
2861 if (!(*target_path))
2864 convert_delimiter(*target_path, '/');
2865 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2871 parse_reparse_point(struct reparse_data_buffer *buf,
2872 u32 plen, char **target_path,
2873 struct cifs_sb_info *cifs_sb)
2875 if (plen < sizeof(struct reparse_data_buffer)) {
2876 cifs_dbg(VFS, "reparse buffer is too small. Must be at least 8 bytes but was %d\n",
2881 if (plen < le16_to_cpu(buf->ReparseDataLength) +
2882 sizeof(struct reparse_data_buffer)) {
2883 cifs_dbg(VFS, "srv returned invalid reparse buf length: %d\n",
2888 /* See MS-FSCC 2.1.2 */
2889 switch (le32_to_cpu(buf->ReparseTag)) {
2890 case IO_REPARSE_TAG_NFS:
2891 return parse_reparse_posix(
2892 (struct reparse_posix_data *)buf,
2893 plen, target_path, cifs_sb);
2894 case IO_REPARSE_TAG_SYMLINK:
2895 return parse_reparse_symlink(
2896 (struct reparse_symlink_data_buffer *)buf,
2897 plen, target_path, cifs_sb);
2899 cifs_dbg(VFS, "srv returned unknown symlink buffer tag:0x%08x\n",
2900 le32_to_cpu(buf->ReparseTag));
2906 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
2907 struct cifs_sb_info *cifs_sb, const char *full_path,
2908 char **target_path, bool is_reparse_point)
2911 __le16 *utf16_path = NULL;
2912 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2913 struct cifs_open_parms oparms;
2914 struct cifs_fid fid;
2915 struct kvec err_iov = {NULL, 0};
2916 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2917 int flags = CIFS_CP_CREATE_CLOSE_OP;
2918 struct smb_rqst rqst[3];
2919 int resp_buftype[3];
2920 struct kvec rsp_iov[3];
2921 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2922 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2923 struct kvec close_iov[1];
2924 struct smb2_create_rsp *create_rsp;
2925 struct smb2_ioctl_rsp *ioctl_rsp;
2926 struct reparse_data_buffer *reparse_buf;
2927 int create_options = is_reparse_point ? OPEN_REPARSE_POINT : 0;
2930 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2932 *target_path = NULL;
2934 if (smb3_encryption_required(tcon))
2935 flags |= CIFS_TRANSFORM_REQ;
2937 memset(rqst, 0, sizeof(rqst));
2938 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2939 memset(rsp_iov, 0, sizeof(rsp_iov));
2941 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
2946 memset(&open_iov, 0, sizeof(open_iov));
2947 rqst[0].rq_iov = open_iov;
2948 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2950 oparms = (struct cifs_open_parms) {
2953 .desired_access = FILE_READ_ATTRIBUTES,
2954 .disposition = FILE_OPEN,
2955 .create_options = cifs_create_options(cifs_sb, create_options),
2959 rc = SMB2_open_init(tcon, server,
2960 &rqst[0], &oplock, &oparms, utf16_path);
2963 smb2_set_next_command(tcon, &rqst[0]);
2967 memset(&io_iov, 0, sizeof(io_iov));
2968 rqst[1].rq_iov = io_iov;
2969 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
2971 rc = SMB2_ioctl_init(tcon, server,
2972 &rqst[1], fid.persistent_fid,
2973 fid.volatile_fid, FSCTL_GET_REPARSE_POINT, NULL, 0,
2975 MAX_SMB2_CREATE_RESPONSE_SIZE -
2976 MAX_SMB2_CLOSE_RESPONSE_SIZE);
2980 smb2_set_next_command(tcon, &rqst[1]);
2981 smb2_set_related(&rqst[1]);
2985 memset(&close_iov, 0, sizeof(close_iov));
2986 rqst[2].rq_iov = close_iov;
2987 rqst[2].rq_nvec = 1;
2989 rc = SMB2_close_init(tcon, server,
2990 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2994 smb2_set_related(&rqst[2]);
2996 rc = compound_send_recv(xid, tcon->ses, server,
2998 resp_buftype, rsp_iov);
3000 create_rsp = rsp_iov[0].iov_base;
3001 if (create_rsp && create_rsp->hdr.Status)
3002 err_iov = rsp_iov[0];
3003 ioctl_rsp = rsp_iov[1].iov_base;
3006 * Open was successful and we got an ioctl response.
3008 if ((rc == 0) && (is_reparse_point)) {
3009 /* See MS-FSCC 2.3.23 */
3011 reparse_buf = (struct reparse_data_buffer *)
3012 ((char *)ioctl_rsp +
3013 le32_to_cpu(ioctl_rsp->OutputOffset));
3014 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3016 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3017 rsp_iov[1].iov_len) {
3018 cifs_tcon_dbg(VFS, "srv returned invalid ioctl len: %d\n",
3024 rc = parse_reparse_point(reparse_buf, plen, target_path,
3029 if (!rc || !err_iov.iov_base) {
3034 rc = smb2_parse_symlink_response(cifs_sb, &err_iov, target_path);
3037 cifs_dbg(FYI, "query symlink rc %d\n", rc);
3039 SMB2_open_free(&rqst[0]);
3040 SMB2_ioctl_free(&rqst[1]);
3041 SMB2_close_free(&rqst[2]);
3042 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3043 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3044 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3049 smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
3050 struct cifs_sb_info *cifs_sb, const char *full_path,
3054 __le16 *utf16_path = NULL;
3055 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3056 struct cifs_open_parms oparms;
3057 struct cifs_fid fid;
3058 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
3059 int flags = CIFS_CP_CREATE_CLOSE_OP;
3060 struct smb_rqst rqst[3];
3061 int resp_buftype[3];
3062 struct kvec rsp_iov[3];
3063 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
3064 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
3065 struct kvec close_iov[1];
3066 struct smb2_ioctl_rsp *ioctl_rsp;
3067 struct reparse_data_buffer *reparse_buf;
3070 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
3072 if (smb3_encryption_required(tcon))
3073 flags |= CIFS_TRANSFORM_REQ;
3075 memset(rqst, 0, sizeof(rqst));
3076 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
3077 memset(rsp_iov, 0, sizeof(rsp_iov));
3079 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
3084 * setup smb2open - TODO add optimization to call cifs_get_readable_path
3085 * to see if there is a handle already open that we can use
3087 memset(&open_iov, 0, sizeof(open_iov));
3088 rqst[0].rq_iov = open_iov;
3089 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
3091 oparms = (struct cifs_open_parms) {
3094 .desired_access = FILE_READ_ATTRIBUTES,
3095 .disposition = FILE_OPEN,
3096 .create_options = cifs_create_options(cifs_sb, OPEN_REPARSE_POINT),
3100 rc = SMB2_open_init(tcon, server,
3101 &rqst[0], &oplock, &oparms, utf16_path);
3104 smb2_set_next_command(tcon, &rqst[0]);
3108 memset(&io_iov, 0, sizeof(io_iov));
3109 rqst[1].rq_iov = io_iov;
3110 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3112 rc = SMB2_ioctl_init(tcon, server,
3113 &rqst[1], COMPOUND_FID,
3114 COMPOUND_FID, FSCTL_GET_REPARSE_POINT, NULL, 0,
3116 MAX_SMB2_CREATE_RESPONSE_SIZE -
3117 MAX_SMB2_CLOSE_RESPONSE_SIZE);
3121 smb2_set_next_command(tcon, &rqst[1]);
3122 smb2_set_related(&rqst[1]);
3126 memset(&close_iov, 0, sizeof(close_iov));
3127 rqst[2].rq_iov = close_iov;
3128 rqst[2].rq_nvec = 1;
3130 rc = SMB2_close_init(tcon, server,
3131 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3135 smb2_set_related(&rqst[2]);
3137 rc = compound_send_recv(xid, tcon->ses, server,
3139 resp_buftype, rsp_iov);
3141 ioctl_rsp = rsp_iov[1].iov_base;
3144 * Open was successful and we got an ioctl response.
3147 /* See MS-FSCC 2.3.23 */
3149 reparse_buf = (struct reparse_data_buffer *)
3150 ((char *)ioctl_rsp +
3151 le32_to_cpu(ioctl_rsp->OutputOffset));
3152 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3154 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3155 rsp_iov[1].iov_len) {
3156 cifs_tcon_dbg(FYI, "srv returned invalid ioctl len: %d\n",
3161 *tag = le32_to_cpu(reparse_buf->ReparseTag);
3166 SMB2_open_free(&rqst[0]);
3167 SMB2_ioctl_free(&rqst[1]);
3168 SMB2_close_free(&rqst[2]);
3169 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3170 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3171 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3175 static struct cifs_ntsd *
3176 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
3177 const struct cifs_fid *cifsfid, u32 *pacllen, u32 info)
3179 struct cifs_ntsd *pntsd = NULL;
3181 int rc = -EOPNOTSUPP;
3182 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3185 return ERR_CAST(tlink);
3188 cifs_dbg(FYI, "trying to get acl\n");
3190 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
3191 cifsfid->volatile_fid, (void **)&pntsd, pacllen,
3195 cifs_put_tlink(tlink);
3197 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3204 static struct cifs_ntsd *
3205 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
3206 const char *path, u32 *pacllen, u32 info)
3208 struct cifs_ntsd *pntsd = NULL;
3209 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3212 struct cifs_tcon *tcon;
3213 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3214 struct cifs_fid fid;
3215 struct cifs_open_parms oparms;
3218 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
3220 return ERR_CAST(tlink);
3222 tcon = tlink_tcon(tlink);
3225 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3232 oparms = (struct cifs_open_parms) {
3235 .desired_access = READ_CONTROL,
3236 .disposition = FILE_OPEN,
3238 * When querying an ACL, even if the file is a symlink
3239 * we want to open the source not the target, and so
3240 * the protocol requires that the client specify this
3241 * flag when opening a reparse point
3243 .create_options = cifs_create_options(cifs_sb, 0) |
3248 if (info & SACL_SECINFO)
3249 oparms.desired_access |= SYSTEM_SECURITY;
3251 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
3255 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3256 fid.volatile_fid, (void **)&pntsd, pacllen,
3258 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3261 cifs_put_tlink(tlink);
3264 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3271 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
3272 struct inode *inode, const char *path, int aclflag)
3274 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3276 int rc, access_flags = 0;
3277 struct cifs_tcon *tcon;
3278 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
3279 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3280 struct cifs_fid fid;
3281 struct cifs_open_parms oparms;
3284 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
3286 return PTR_ERR(tlink);
3288 tcon = tlink_tcon(tlink);
3291 if (aclflag & CIFS_ACL_OWNER || aclflag & CIFS_ACL_GROUP)
3292 access_flags |= WRITE_OWNER;
3293 if (aclflag & CIFS_ACL_SACL)
3294 access_flags |= SYSTEM_SECURITY;
3295 if (aclflag & CIFS_ACL_DACL)
3296 access_flags |= WRITE_DAC;
3298 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3305 oparms = (struct cifs_open_parms) {
3307 .desired_access = access_flags,
3308 .create_options = cifs_create_options(cifs_sb, 0),
3309 .disposition = FILE_OPEN,
3314 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
3318 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3319 fid.volatile_fid, pnntsd, acllen, aclflag);
3320 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3323 cifs_put_tlink(tlink);
3328 /* Retrieve an ACL from the server */
3329 static struct cifs_ntsd *
3330 get_smb2_acl(struct cifs_sb_info *cifs_sb,
3331 struct inode *inode, const char *path,
3332 u32 *pacllen, u32 info)
3334 struct cifs_ntsd *pntsd = NULL;
3335 struct cifsFileInfo *open_file = NULL;
3337 if (inode && !(info & SACL_SECINFO))
3338 open_file = find_readable_file(CIFS_I(inode), true);
3339 if (!open_file || (info & SACL_SECINFO))
3340 return get_smb2_acl_by_path(cifs_sb, path, pacllen, info);
3342 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen, info);
3343 cifsFileInfo_put(open_file);
3347 static long smb3_zero_data(struct file *file, struct cifs_tcon *tcon,
3348 loff_t offset, loff_t len, unsigned int xid)
3350 struct cifsFileInfo *cfile = file->private_data;
3351 struct file_zero_data_information fsctl_buf;
3353 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3355 fsctl_buf.FileOffset = cpu_to_le64(offset);
3356 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3358 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3359 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3361 sizeof(struct file_zero_data_information),
3365 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3366 loff_t offset, loff_t len, bool keep_size)
3368 struct cifs_ses *ses = tcon->ses;
3369 struct inode *inode = file_inode(file);
3370 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3371 struct cifsFileInfo *cfile = file->private_data;
3378 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3379 ses->Suid, offset, len);
3382 filemap_invalidate_lock(inode->i_mapping);
3385 * We zero the range through ioctl, so we need remove the page caches
3386 * first, otherwise the data may be inconsistent with the server.
3388 truncate_pagecache_range(inode, offset, offset + len - 1);
3390 /* if file not oplocked can't be sure whether asking to extend size */
3392 if (keep_size == false && !CIFS_CACHE_READ(cifsi))
3393 goto zero_range_exit;
3395 rc = smb3_zero_data(file, tcon, offset, len, xid);
3397 goto zero_range_exit;
3400 * do we also need to change the size of the file?
3402 if (keep_size == false && i_size_read(inode) < offset + len) {
3403 eof = cpu_to_le64(offset + len);
3404 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3405 cfile->fid.volatile_fid, cfile->pid, &eof);
3409 filemap_invalidate_unlock(inode->i_mapping);
3410 inode_unlock(inode);
3413 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
3414 ses->Suid, offset, len, rc);
3416 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
3417 ses->Suid, offset, len);
3421 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
3422 loff_t offset, loff_t len)
3424 struct inode *inode = file_inode(file);
3425 struct cifsFileInfo *cfile = file->private_data;
3426 struct file_zero_data_information fsctl_buf;
3429 __u8 set_sparse = 1;
3434 /* Need to make file sparse, if not already, before freeing range. */
3435 /* Consider adding equivalent for compressed since it could also work */
3436 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
3441 filemap_invalidate_lock(inode->i_mapping);
3443 * We implement the punch hole through ioctl, so we need remove the page
3444 * caches first, otherwise the data may be inconsistent with the server.
3446 truncate_pagecache_range(inode, offset, offset + len - 1);
3448 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3450 fsctl_buf.FileOffset = cpu_to_le64(offset);
3451 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3453 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3454 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3456 sizeof(struct file_zero_data_information),
3457 CIFSMaxBufSize, NULL, NULL);
3458 filemap_invalidate_unlock(inode->i_mapping);
3460 inode_unlock(inode);
3465 static int smb3_simple_fallocate_write_range(unsigned int xid,
3466 struct cifs_tcon *tcon,
3467 struct cifsFileInfo *cfile,
3468 loff_t off, loff_t len,
3471 struct cifs_io_parms io_parms = {0};
3476 io_parms.netfid = cfile->fid.netfid;
3477 io_parms.pid = current->tgid;
3478 io_parms.tcon = tcon;
3479 io_parms.persistent_fid = cfile->fid.persistent_fid;
3480 io_parms.volatile_fid = cfile->fid.volatile_fid;
3483 io_parms.offset = off;
3484 io_parms.length = len;
3485 if (io_parms.length > SMB2_MAX_BUFFER_SIZE)
3486 io_parms.length = SMB2_MAX_BUFFER_SIZE;
3487 /* iov[0] is reserved for smb header */
3488 iov[1].iov_base = buf;
3489 iov[1].iov_len = io_parms.length;
3490 rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
3502 static int smb3_simple_fallocate_range(unsigned int xid,
3503 struct cifs_tcon *tcon,
3504 struct cifsFileInfo *cfile,
3505 loff_t off, loff_t len)
3507 struct file_allocated_range_buffer in_data, *out_data = NULL, *tmp_data;
3513 in_data.file_offset = cpu_to_le64(off);
3514 in_data.length = cpu_to_le64(len);
3515 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3516 cfile->fid.volatile_fid,
3517 FSCTL_QUERY_ALLOCATED_RANGES,
3518 (char *)&in_data, sizeof(in_data),
3519 1024 * sizeof(struct file_allocated_range_buffer),
3520 (char **)&out_data, &out_data_len);
3524 buf = kzalloc(1024 * 1024, GFP_KERNEL);
3530 tmp_data = out_data;
3533 * The rest of the region is unmapped so write it all.
3535 if (out_data_len == 0) {
3536 rc = smb3_simple_fallocate_write_range(xid, tcon,
3537 cfile, off, len, buf);
3541 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3546 if (off < le64_to_cpu(tmp_data->file_offset)) {
3548 * We are at a hole. Write until the end of the region
3549 * or until the next allocated data,
3550 * whichever comes next.
3552 l = le64_to_cpu(tmp_data->file_offset) - off;
3555 rc = smb3_simple_fallocate_write_range(xid, tcon,
3556 cfile, off, l, buf);
3565 * We are at a section of allocated data, just skip forward
3566 * until the end of the data or the end of the region
3567 * we are supposed to fallocate, whichever comes first.
3569 l = le64_to_cpu(tmp_data->length);
3575 tmp_data = &tmp_data[1];
3576 out_data_len -= sizeof(struct file_allocated_range_buffer);
3586 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3587 loff_t off, loff_t len, bool keep_size)
3589 struct inode *inode;
3590 struct cifsInodeInfo *cifsi;
3591 struct cifsFileInfo *cfile = file->private_data;
3592 long rc = -EOPNOTSUPP;
3598 inode = d_inode(cfile->dentry);
3599 cifsi = CIFS_I(inode);
3601 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3602 tcon->ses->Suid, off, len);
3603 /* if file not oplocked can't be sure whether asking to extend size */
3604 if (!CIFS_CACHE_READ(cifsi))
3605 if (keep_size == false) {
3606 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3607 tcon->tid, tcon->ses->Suid, off, len, rc);
3613 * Extending the file
3615 if ((keep_size == false) && i_size_read(inode) < off + len) {
3616 rc = inode_newsize_ok(inode, off + len);
3620 if (cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)
3621 smb2_set_sparse(xid, tcon, cfile, inode, false);
3623 eof = cpu_to_le64(off + len);
3624 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3625 cfile->fid.volatile_fid, cfile->pid, &eof);
3627 cifsi->server_eof = off + len;
3628 cifs_setsize(inode, off + len);
3629 cifs_truncate_page(inode->i_mapping, inode->i_size);
3630 truncate_setsize(inode, off + len);
3636 * Files are non-sparse by default so falloc may be a no-op
3637 * Must check if file sparse. If not sparse, and since we are not
3638 * extending then no need to do anything since file already allocated
3640 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
3645 if (keep_size == true) {
3647 * We can not preallocate pages beyond the end of the file
3650 if (off >= i_size_read(inode)) {
3655 * For fallocates that are partially beyond the end of file,
3656 * clamp len so we only fallocate up to the end of file.
3658 if (off + len > i_size_read(inode)) {
3659 len = i_size_read(inode) - off;
3663 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3665 * At this point, we are trying to fallocate an internal
3666 * regions of a sparse file. Since smb2 does not have a
3667 * fallocate command we have two otions on how to emulate this.
3668 * We can either turn the entire file to become non-sparse
3669 * which we only do if the fallocate is for virtually
3670 * the whole file, or we can overwrite the region with zeroes
3671 * using SMB2_write, which could be prohibitevly expensive
3675 * We are only trying to fallocate a small region so
3676 * just write it with zero.
3678 if (len <= 1024 * 1024) {
3679 rc = smb3_simple_fallocate_range(xid, tcon, cfile,
3685 * Check if falloc starts within first few pages of file
3686 * and ends within a few pages of the end of file to
3687 * ensure that most of file is being forced to be
3688 * fallocated now. If so then setting whole file sparse
3689 * ie potentially making a few extra pages at the beginning
3690 * or end of the file non-sparse via set_sparse is harmless.
3692 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
3698 smb2_set_sparse(xid, tcon, cfile, inode, false);
3703 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3704 tcon->ses->Suid, off, len, rc);
3706 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3707 tcon->ses->Suid, off, len);
3713 static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
3714 loff_t off, loff_t len)
3718 struct inode *inode = file_inode(file);
3719 struct cifsFileInfo *cfile = file->private_data;
3720 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3728 old_eof = i_size_read(inode);
3729 if ((off >= old_eof) ||
3730 off + len >= old_eof) {
3735 filemap_invalidate_lock(inode->i_mapping);
3736 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof - 1);
3740 truncate_pagecache_range(inode, off, old_eof);
3742 rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
3743 old_eof - off - len, off);
3747 eof = cpu_to_le64(old_eof - len);
3748 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3749 cfile->fid.volatile_fid, cfile->pid, &eof);
3755 cifsi->server_eof = i_size_read(inode) - len;
3756 truncate_setsize(inode, cifsi->server_eof);
3757 fscache_resize_cookie(cifs_inode_cookie(inode), cifsi->server_eof);
3759 filemap_invalidate_unlock(inode->i_mapping);
3761 inode_unlock(inode);
3766 static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
3767 loff_t off, loff_t len)
3771 struct cifsFileInfo *cfile = file->private_data;
3772 struct inode *inode = file_inode(file);
3774 __u64 count, old_eof;
3780 old_eof = i_size_read(inode);
3781 if (off >= old_eof) {
3786 count = old_eof - off;
3787 eof = cpu_to_le64(old_eof + len);
3789 filemap_invalidate_lock(inode->i_mapping);
3790 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof + len - 1);
3793 truncate_pagecache_range(inode, off, old_eof);
3795 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3796 cfile->fid.volatile_fid, cfile->pid, &eof);
3800 rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len);
3804 rc = smb3_zero_data(file, tcon, off, len, xid);
3810 filemap_invalidate_unlock(inode->i_mapping);
3812 inode_unlock(inode);
3817 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3819 struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3820 struct cifsInodeInfo *cifsi;
3821 struct inode *inode;
3823 struct file_allocated_range_buffer in_data, *out_data = NULL;
3827 if (whence != SEEK_HOLE && whence != SEEK_DATA)
3828 return generic_file_llseek(file, offset, whence);
3830 inode = d_inode(cfile->dentry);
3831 cifsi = CIFS_I(inode);
3833 if (offset < 0 || offset >= i_size_read(inode))
3838 * We need to be sure that all dirty pages are written as they
3839 * might fill holes on the server.
3840 * Note that we also MUST flush any written pages since at least
3841 * some servers (Windows2016) will not reflect recent writes in
3842 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3844 wrcfile = find_writable_file(cifsi, FIND_WR_ANY);
3846 filemap_write_and_wait(inode->i_mapping);
3847 smb2_flush_file(xid, tcon, &wrcfile->fid);
3848 cifsFileInfo_put(wrcfile);
3851 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3852 if (whence == SEEK_HOLE)
3853 offset = i_size_read(inode);
3857 in_data.file_offset = cpu_to_le64(offset);
3858 in_data.length = cpu_to_le64(i_size_read(inode));
3860 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3861 cfile->fid.volatile_fid,
3862 FSCTL_QUERY_ALLOCATED_RANGES,
3863 (char *)&in_data, sizeof(in_data),
3864 sizeof(struct file_allocated_range_buffer),
3865 (char **)&out_data, &out_data_len);
3871 if (whence == SEEK_HOLE && out_data_len == 0)
3874 if (whence == SEEK_DATA && out_data_len == 0) {
3879 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3883 if (whence == SEEK_DATA) {
3884 offset = le64_to_cpu(out_data->file_offset);
3887 if (offset < le64_to_cpu(out_data->file_offset))
3890 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3896 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3901 static int smb3_fiemap(struct cifs_tcon *tcon,
3902 struct cifsFileInfo *cfile,
3903 struct fiemap_extent_info *fei, u64 start, u64 len)
3906 struct file_allocated_range_buffer in_data, *out_data;
3908 int i, num, rc, flags, last_blob;
3911 rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0);
3917 in_data.file_offset = cpu_to_le64(start);
3918 in_data.length = cpu_to_le64(len);
3920 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3921 cfile->fid.volatile_fid,
3922 FSCTL_QUERY_ALLOCATED_RANGES,
3923 (char *)&in_data, sizeof(in_data),
3924 1024 * sizeof(struct file_allocated_range_buffer),
3925 (char **)&out_data, &out_data_len);
3934 if (out_data_len && out_data_len < sizeof(struct file_allocated_range_buffer)) {
3938 if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3943 num = out_data_len / sizeof(struct file_allocated_range_buffer);
3944 for (i = 0; i < num; i++) {
3946 if (i == num - 1 && last_blob)
3947 flags |= FIEMAP_EXTENT_LAST;
3949 rc = fiemap_fill_next_extent(fei,
3950 le64_to_cpu(out_data[i].file_offset),
3951 le64_to_cpu(out_data[i].file_offset),
3952 le64_to_cpu(out_data[i].length),
3963 next = le64_to_cpu(out_data[num - 1].file_offset) +
3964 le64_to_cpu(out_data[num - 1].length);
3965 len = len - (next - start);
3976 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
3977 loff_t off, loff_t len)
3979 /* KEEP_SIZE already checked for by do_fallocate */
3980 if (mode & FALLOC_FL_PUNCH_HOLE)
3981 return smb3_punch_hole(file, tcon, off, len);
3982 else if (mode & FALLOC_FL_ZERO_RANGE) {
3983 if (mode & FALLOC_FL_KEEP_SIZE)
3984 return smb3_zero_range(file, tcon, off, len, true);
3985 return smb3_zero_range(file, tcon, off, len, false);
3986 } else if (mode == FALLOC_FL_KEEP_SIZE)
3987 return smb3_simple_falloc(file, tcon, off, len, true);
3988 else if (mode == FALLOC_FL_COLLAPSE_RANGE)
3989 return smb3_collapse_range(file, tcon, off, len);
3990 else if (mode == FALLOC_FL_INSERT_RANGE)
3991 return smb3_insert_range(file, tcon, off, len);
3993 return smb3_simple_falloc(file, tcon, off, len, false);
3999 smb2_downgrade_oplock(struct TCP_Server_Info *server,
4000 struct cifsInodeInfo *cinode, __u32 oplock,
4001 unsigned int epoch, bool *purge_cache)
4003 server->ops->set_oplock_level(cinode, oplock, 0, NULL);
4007 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4008 unsigned int epoch, bool *purge_cache);
4011 smb3_downgrade_oplock(struct TCP_Server_Info *server,
4012 struct cifsInodeInfo *cinode, __u32 oplock,
4013 unsigned int epoch, bool *purge_cache)
4015 unsigned int old_state = cinode->oplock;
4016 unsigned int old_epoch = cinode->epoch;
4017 unsigned int new_state;
4019 if (epoch > old_epoch) {
4020 smb21_set_oplock_level(cinode, oplock, 0, NULL);
4021 cinode->epoch = epoch;
4024 new_state = cinode->oplock;
4025 *purge_cache = false;
4027 if ((old_state & CIFS_CACHE_READ_FLG) != 0 &&
4028 (new_state & CIFS_CACHE_READ_FLG) == 0)
4029 *purge_cache = true;
4030 else if (old_state == new_state && (epoch - old_epoch > 1))
4031 *purge_cache = true;
4035 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4036 unsigned int epoch, bool *purge_cache)
4039 cinode->lease_granted = false;
4040 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
4042 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
4043 cinode->oplock = CIFS_CACHE_RHW_FLG;
4044 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
4045 &cinode->netfs.inode);
4046 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
4047 cinode->oplock = CIFS_CACHE_RW_FLG;
4048 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
4049 &cinode->netfs.inode);
4050 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
4051 cinode->oplock = CIFS_CACHE_READ_FLG;
4052 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
4053 &cinode->netfs.inode);
4059 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4060 unsigned int epoch, bool *purge_cache)
4062 char message[5] = {0};
4063 unsigned int new_oplock = 0;
4066 cinode->lease_granted = true;
4067 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
4070 /* Check if the server granted an oplock rather than a lease */
4071 if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4072 return smb2_set_oplock_level(cinode, oplock, epoch,
4075 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
4076 new_oplock |= CIFS_CACHE_READ_FLG;
4077 strcat(message, "R");
4079 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
4080 new_oplock |= CIFS_CACHE_HANDLE_FLG;
4081 strcat(message, "H");
4083 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
4084 new_oplock |= CIFS_CACHE_WRITE_FLG;
4085 strcat(message, "W");
4088 strncpy(message, "None", sizeof(message));
4090 cinode->oplock = new_oplock;
4091 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
4092 &cinode->netfs.inode);
4096 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4097 unsigned int epoch, bool *purge_cache)
4099 unsigned int old_oplock = cinode->oplock;
4101 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
4104 *purge_cache = false;
4105 if (old_oplock == CIFS_CACHE_READ_FLG) {
4106 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
4107 (epoch - cinode->epoch > 0))
4108 *purge_cache = true;
4109 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4110 (epoch - cinode->epoch > 1))
4111 *purge_cache = true;
4112 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4113 (epoch - cinode->epoch > 1))
4114 *purge_cache = true;
4115 else if (cinode->oplock == 0 &&
4116 (epoch - cinode->epoch > 0))
4117 *purge_cache = true;
4118 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
4119 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4120 (epoch - cinode->epoch > 0))
4121 *purge_cache = true;
4122 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4123 (epoch - cinode->epoch > 1))
4124 *purge_cache = true;
4126 cinode->epoch = epoch;
4130 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
4132 smb2_is_read_op(__u32 oplock)
4134 return oplock == SMB2_OPLOCK_LEVEL_II;
4136 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
4139 smb21_is_read_op(__u32 oplock)
4141 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
4142 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
4146 map_oplock_to_lease(u8 oplock)
4148 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4149 return SMB2_LEASE_WRITE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE;
4150 else if (oplock == SMB2_OPLOCK_LEVEL_II)
4151 return SMB2_LEASE_READ_CACHING_LE;
4152 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
4153 return SMB2_LEASE_HANDLE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE |
4154 SMB2_LEASE_WRITE_CACHING_LE;
4159 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
4161 struct create_lease *buf;
4163 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
4167 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4168 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4170 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4171 (struct create_lease, lcontext));
4172 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
4173 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4174 (struct create_lease, Name));
4175 buf->ccontext.NameLength = cpu_to_le16(4);
4176 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4185 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
4187 struct create_lease_v2 *buf;
4189 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
4193 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4194 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4196 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4197 (struct create_lease_v2, lcontext));
4198 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
4199 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4200 (struct create_lease_v2, Name));
4201 buf->ccontext.NameLength = cpu_to_le16(4);
4202 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4211 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4213 struct create_lease *lc = (struct create_lease *)buf;
4215 *epoch = 0; /* not used */
4216 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4217 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4218 return le32_to_cpu(lc->lcontext.LeaseState);
4222 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4224 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
4226 *epoch = le16_to_cpu(lc->lcontext.Epoch);
4227 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4228 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4230 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
4231 return le32_to_cpu(lc->lcontext.LeaseState);
4235 smb2_wp_retry_size(struct inode *inode)
4237 return min_t(unsigned int, CIFS_SB(inode->i_sb)->ctx->wsize,
4238 SMB2_MAX_BUFFER_SIZE);
4242 smb2_dir_needs_close(struct cifsFileInfo *cfile)
4244 return !cfile->invalidHandle;
4248 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
4249 struct smb_rqst *old_rq, __le16 cipher_type)
4251 struct smb2_hdr *shdr =
4252 (struct smb2_hdr *)old_rq->rq_iov[0].iov_base;
4254 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
4255 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
4256 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
4257 tr_hdr->Flags = cpu_to_le16(0x01);
4258 if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4259 (cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4260 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4262 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4263 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
4266 static void *smb2_aead_req_alloc(struct crypto_aead *tfm, const struct smb_rqst *rqst,
4267 int num_rqst, const u8 *sig, u8 **iv,
4268 struct aead_request **req, struct sg_table *sgt,
4269 unsigned int *num_sgs, size_t *sensitive_size)
4271 unsigned int req_size = sizeof(**req) + crypto_aead_reqsize(tfm);
4272 unsigned int iv_size = crypto_aead_ivsize(tfm);
4276 *num_sgs = cifs_get_num_sgs(rqst, num_rqst, sig);
4277 if (IS_ERR_VALUE((long)(int)*num_sgs))
4278 return ERR_PTR(*num_sgs);
4281 len += crypto_aead_alignmask(tfm) & ~(crypto_tfm_ctx_alignment() - 1);
4282 len = ALIGN(len, crypto_tfm_ctx_alignment());
4284 len = ALIGN(len, __alignof__(struct scatterlist));
4285 len += array_size(*num_sgs, sizeof(struct scatterlist));
4286 *sensitive_size = len;
4288 p = kvzalloc(len, GFP_NOFS);
4290 return ERR_PTR(-ENOMEM);
4292 *iv = (u8 *)PTR_ALIGN(p, crypto_aead_alignmask(tfm) + 1);
4293 *req = (struct aead_request *)PTR_ALIGN(*iv + iv_size,
4294 crypto_tfm_ctx_alignment());
4295 sgt->sgl = (struct scatterlist *)PTR_ALIGN((u8 *)*req + req_size,
4296 __alignof__(struct scatterlist));
4300 static void *smb2_get_aead_req(struct crypto_aead *tfm, struct smb_rqst *rqst,
4301 int num_rqst, const u8 *sig, u8 **iv,
4302 struct aead_request **req, struct scatterlist **sgl,
4303 size_t *sensitive_size)
4305 struct sg_table sgtable = {};
4306 unsigned int skip, num_sgs, i, j;
4310 p = smb2_aead_req_alloc(tfm, rqst, num_rqst, sig, iv, req, &sgtable,
4311 &num_sgs, sensitive_size);
4315 sg_init_marker(sgtable.sgl, num_sgs);
4318 * The first rqst has a transform header where the
4319 * first 20 bytes are not part of the encrypted blob.
4323 for (i = 0; i < num_rqst; i++) {
4324 struct iov_iter *iter = &rqst[i].rq_iter;
4325 size_t count = iov_iter_count(iter);
4327 for (j = 0; j < rqst[i].rq_nvec; j++) {
4328 cifs_sg_set_buf(&sgtable,
4329 rqst[i].rq_iov[j].iov_base + skip,
4330 rqst[i].rq_iov[j].iov_len - skip);
4332 /* See the above comment on the 'skip' assignment */
4335 sgtable.orig_nents = sgtable.nents;
4337 rc = netfs_extract_iter_to_sg(iter, count, &sgtable,
4338 num_sgs - sgtable.nents, 0);
4339 iov_iter_revert(iter, rc);
4340 sgtable.orig_nents = sgtable.nents;
4343 cifs_sg_set_buf(&sgtable, sig, SMB2_SIGNATURE_SIZE);
4344 sg_mark_end(&sgtable.sgl[sgtable.nents - 1]);
4350 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
4352 struct TCP_Server_Info *pserver;
4353 struct cifs_ses *ses;
4356 /* If server is a channel, select the primary channel */
4357 pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
4359 spin_lock(&cifs_tcp_ses_lock);
4360 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
4361 if (ses->Suid == ses_id) {
4362 spin_lock(&ses->ses_lock);
4363 ses_enc_key = enc ? ses->smb3encryptionkey :
4364 ses->smb3decryptionkey;
4365 memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE);
4366 spin_unlock(&ses->ses_lock);
4367 spin_unlock(&cifs_tcp_ses_lock);
4371 spin_unlock(&cifs_tcp_ses_lock);
4376 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
4377 * iov[0] - transform header (associate data),
4378 * iov[1-N] - SMB2 header and pages - data to encrypt.
4379 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4383 crypt_message(struct TCP_Server_Info *server, int num_rqst,
4384 struct smb_rqst *rqst, int enc)
4386 struct smb2_transform_hdr *tr_hdr =
4387 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
4388 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
4390 struct scatterlist *sg;
4391 u8 sign[SMB2_SIGNATURE_SIZE] = {};
4392 u8 key[SMB3_ENC_DEC_KEY_SIZE];
4393 struct aead_request *req;
4395 DECLARE_CRYPTO_WAIT(wait);
4396 struct crypto_aead *tfm;
4397 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4399 size_t sensitive_size;
4401 rc = smb2_get_enc_key(server, le64_to_cpu(tr_hdr->SessionId), enc, key);
4403 cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
4408 rc = smb3_crypto_aead_allocate(server);
4410 cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
4414 tfm = enc ? server->secmech.enc : server->secmech.dec;
4416 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
4417 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4418 rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
4420 rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE);
4423 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
4427 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
4429 cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
4433 creq = smb2_get_aead_req(tfm, rqst, num_rqst, sign, &iv, &req, &sg,
4436 return PTR_ERR(creq);
4439 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
4440 crypt_len += SMB2_SIGNATURE_SIZE;
4443 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4444 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4445 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4448 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4451 aead_request_set_tfm(req, tfm);
4452 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
4453 aead_request_set_ad(req, assoc_data_len);
4455 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
4456 crypto_req_done, &wait);
4458 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
4459 : crypto_aead_decrypt(req), &wait);
4462 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
4464 kvfree_sensitive(creq, sensitive_size);
4469 * Clear a read buffer, discarding the folios which have XA_MARK_0 set.
4471 static void cifs_clear_xarray_buffer(struct xarray *buffer)
4473 struct folio *folio;
4475 XA_STATE(xas, buffer, 0);
4478 xas_for_each_marked(&xas, folio, ULONG_MAX, XA_MARK_0) {
4486 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
4490 for (i = 0; i < num_rqst; i++)
4491 if (!xa_empty(&rqst[i].rq_buffer))
4492 cifs_clear_xarray_buffer(&rqst[i].rq_buffer);
4496 * This function will initialize new_rq and encrypt the content.
4497 * The first entry, new_rq[0], only contains a single iov which contains
4498 * a smb2_transform_hdr and is pre-allocated by the caller.
4499 * This function then populates new_rq[1+] with the content from olq_rq[0+].
4501 * The end result is an array of smb_rqst structures where the first structure
4502 * only contains a single iov for the transform header which we then can pass
4503 * to crypt_message().
4505 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4506 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
4509 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
4510 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
4512 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
4514 unsigned int orig_len = 0;
4518 for (i = 1; i < num_rqst; i++) {
4519 struct smb_rqst *old = &old_rq[i - 1];
4520 struct smb_rqst *new = &new_rq[i];
4521 struct xarray *buffer = &new->rq_buffer;
4522 size_t size = iov_iter_count(&old->rq_iter), seg, copied = 0;
4524 orig_len += smb_rqst_len(server, old);
4525 new->rq_iov = old->rq_iov;
4526 new->rq_nvec = old->rq_nvec;
4531 unsigned int npages = DIV_ROUND_UP(size, PAGE_SIZE);
4533 for (j = 0; j < npages; j++) {
4537 page = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4541 o = xa_store(buffer, j, page, GFP_KERNEL);
4548 xa_set_mark(buffer, j, XA_MARK_0);
4550 seg = min_t(size_t, size - copied, PAGE_SIZE);
4551 if (copy_page_from_iter(page, 0, seg, &old->rq_iter) != seg) {
4557 iov_iter_xarray(&new->rq_iter, ITER_SOURCE,
4559 new->rq_iter_size = size;
4563 /* fill the 1st iov with a transform header */
4564 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
4566 rc = crypt_message(server, num_rqst, new_rq, 1);
4567 cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
4574 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
4579 smb3_is_transform_hdr(void *buf)
4581 struct smb2_transform_hdr *trhdr = buf;
4583 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
4587 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
4588 unsigned int buf_data_size, struct iov_iter *iter,
4592 struct smb_rqst rqst = {NULL};
4593 size_t iter_size = 0;
4596 iov[0].iov_base = buf;
4597 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
4598 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
4599 iov[1].iov_len = buf_data_size;
4604 rqst.rq_iter = *iter;
4605 rqst.rq_iter_size = iov_iter_count(iter);
4606 iter_size = iov_iter_count(iter);
4609 rc = crypt_message(server, 1, &rqst, 0);
4610 cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
4615 memmove(buf, iov[1].iov_base, buf_data_size);
4618 server->total_read = buf_data_size + iter_size;
4624 cifs_copy_pages_to_iter(struct xarray *pages, unsigned int data_size,
4625 unsigned int skip, struct iov_iter *iter)
4628 unsigned long index;
4630 xa_for_each(pages, index, page) {
4631 size_t n, len = min_t(unsigned int, PAGE_SIZE - skip, data_size);
4633 n = copy_page_to_iter(page, skip, len, iter);
4635 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
4646 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
4647 char *buf, unsigned int buf_len, struct xarray *pages,
4648 unsigned int pages_len, bool is_offloaded)
4650 unsigned int data_offset;
4651 unsigned int data_len;
4652 unsigned int cur_off;
4653 unsigned int cur_page_idx;
4654 unsigned int pad_len;
4655 struct cifs_readdata *rdata = mid->callback_data;
4656 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
4658 bool use_rdma_mr = false;
4660 if (shdr->Command != SMB2_READ) {
4661 cifs_server_dbg(VFS, "only big read responses are supported\n");
4665 if (server->ops->is_session_expired &&
4666 server->ops->is_session_expired(buf)) {
4668 cifs_reconnect(server, true);
4672 if (server->ops->is_status_pending &&
4673 server->ops->is_status_pending(buf, server))
4676 /* set up first two iov to get credits */
4677 rdata->iov[0].iov_base = buf;
4678 rdata->iov[0].iov_len = 0;
4679 rdata->iov[1].iov_base = buf;
4680 rdata->iov[1].iov_len =
4681 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
4682 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
4683 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
4684 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
4685 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
4687 rdata->result = server->ops->map_error(buf, true);
4688 if (rdata->result != 0) {
4689 cifs_dbg(FYI, "%s: server returned error %d\n",
4690 __func__, rdata->result);
4691 /* normal error on read response */
4693 mid->mid_state = MID_RESPONSE_RECEIVED;
4695 dequeue_mid(mid, false);
4699 data_offset = server->ops->read_data_offset(buf);
4700 #ifdef CONFIG_CIFS_SMB_DIRECT
4701 use_rdma_mr = rdata->mr;
4703 data_len = server->ops->read_data_length(buf, use_rdma_mr);
4705 if (data_offset < server->vals->read_rsp_size) {
4707 * win2k8 sometimes sends an offset of 0 when the read
4708 * is beyond the EOF. Treat it as if the data starts just after
4711 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
4712 __func__, data_offset);
4713 data_offset = server->vals->read_rsp_size;
4714 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
4715 /* data_offset is beyond the end of smallbuf */
4716 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
4717 __func__, data_offset);
4718 rdata->result = -EIO;
4720 mid->mid_state = MID_RESPONSE_MALFORMED;
4722 dequeue_mid(mid, rdata->result);
4726 pad_len = data_offset - server->vals->read_rsp_size;
4728 if (buf_len <= data_offset) {
4729 /* read response payload is in pages */
4730 cur_page_idx = pad_len / PAGE_SIZE;
4731 cur_off = pad_len % PAGE_SIZE;
4733 if (cur_page_idx != 0) {
4734 /* data offset is beyond the 1st page of response */
4735 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
4736 __func__, data_offset);
4737 rdata->result = -EIO;
4739 mid->mid_state = MID_RESPONSE_MALFORMED;
4741 dequeue_mid(mid, rdata->result);
4745 if (data_len > pages_len - pad_len) {
4746 /* data_len is corrupt -- discard frame */
4747 rdata->result = -EIO;
4749 mid->mid_state = MID_RESPONSE_MALFORMED;
4751 dequeue_mid(mid, rdata->result);
4755 /* Copy the data to the output I/O iterator. */
4756 rdata->result = cifs_copy_pages_to_iter(pages, pages_len,
4757 cur_off, &rdata->iter);
4758 if (rdata->result != 0) {
4760 mid->mid_state = MID_RESPONSE_MALFORMED;
4762 dequeue_mid(mid, rdata->result);
4765 rdata->got_bytes = pages_len;
4767 } else if (buf_len >= data_offset + data_len) {
4768 /* read response payload is in buf */
4769 WARN_ONCE(pages && !xa_empty(pages),
4770 "read data can be either in buf or in pages");
4771 length = copy_to_iter(buf + data_offset, data_len, &rdata->iter);
4774 rdata->got_bytes = data_len;
4776 /* read response payload cannot be in both buf and pages */
4777 WARN_ONCE(1, "buf can not contain only a part of read data");
4778 rdata->result = -EIO;
4780 mid->mid_state = MID_RESPONSE_MALFORMED;
4782 dequeue_mid(mid, rdata->result);
4787 mid->mid_state = MID_RESPONSE_RECEIVED;
4789 dequeue_mid(mid, false);
4793 struct smb2_decrypt_work {
4794 struct work_struct decrypt;
4795 struct TCP_Server_Info *server;
4796 struct xarray buffer;
4802 static void smb2_decrypt_offload(struct work_struct *work)
4804 struct smb2_decrypt_work *dw = container_of(work,
4805 struct smb2_decrypt_work, decrypt);
4807 struct mid_q_entry *mid;
4808 struct iov_iter iter;
4810 iov_iter_xarray(&iter, ITER_DEST, &dw->buffer, 0, dw->len);
4811 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
4814 cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
4818 dw->server->lstrp = jiffies;
4819 mid = smb2_find_dequeue_mid(dw->server, dw->buf);
4821 cifs_dbg(FYI, "mid not found\n");
4823 mid->decrypted = true;
4824 rc = handle_read_data(dw->server, mid, dw->buf,
4825 dw->server->vals->read_rsp_size,
4826 &dw->buffer, dw->len,
4829 #ifdef CONFIG_CIFS_STATS2
4830 mid->when_received = jiffies;
4832 if (dw->server->ops->is_network_name_deleted)
4833 dw->server->ops->is_network_name_deleted(dw->buf,
4838 spin_lock(&dw->server->srv_lock);
4839 if (dw->server->tcpStatus == CifsNeedReconnect) {
4840 spin_lock(&dw->server->mid_lock);
4841 mid->mid_state = MID_RETRY_NEEDED;
4842 spin_unlock(&dw->server->mid_lock);
4843 spin_unlock(&dw->server->srv_lock);
4846 spin_lock(&dw->server->mid_lock);
4847 mid->mid_state = MID_REQUEST_SUBMITTED;
4848 mid->mid_flags &= ~(MID_DELETED);
4849 list_add_tail(&mid->qhead,
4850 &dw->server->pending_mid_q);
4851 spin_unlock(&dw->server->mid_lock);
4852 spin_unlock(&dw->server->srv_lock);
4859 cifs_clear_xarray_buffer(&dw->buffer);
4860 cifs_small_buf_release(dw->buf);
4866 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
4870 char *buf = server->smallbuf;
4871 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4872 struct iov_iter iter;
4873 unsigned int len, npages;
4874 unsigned int buflen = server->pdu_size;
4877 struct smb2_decrypt_work *dw;
4879 dw = kzalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL);
4882 xa_init(&dw->buffer);
4883 INIT_WORK(&dw->decrypt, smb2_decrypt_offload);
4884 dw->server = server;
4887 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
4888 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
4890 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
4893 server->total_read += rc;
4895 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
4896 server->vals->read_rsp_size;
4898 npages = DIV_ROUND_UP(len, PAGE_SIZE);
4901 for (; i < npages; i++) {
4904 page = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4908 old = xa_store(&dw->buffer, i, page, GFP_KERNEL);
4909 if (xa_is_err(old)) {
4914 xa_set_mark(&dw->buffer, i, XA_MARK_0);
4917 iov_iter_xarray(&iter, ITER_DEST, &dw->buffer, 0, npages * PAGE_SIZE);
4919 /* Read the data into the buffer and clear excess bufferage. */
4920 rc = cifs_read_iter_from_socket(server, &iter, dw->len);
4924 server->total_read += rc;
4925 if (rc < npages * PAGE_SIZE)
4926 iov_iter_zero(npages * PAGE_SIZE - rc, &iter);
4927 iov_iter_revert(&iter, npages * PAGE_SIZE);
4928 iov_iter_truncate(&iter, dw->len);
4930 rc = cifs_discard_remaining_data(server);
4935 * For large reads, offload to different thread for better performance,
4936 * use more cores decrypting which can be expensive
4939 if ((server->min_offload) && (server->in_flight > 1) &&
4940 (server->pdu_size >= server->min_offload)) {
4941 dw->buf = server->smallbuf;
4942 server->smallbuf = (char *)cifs_small_buf_get();
4944 queue_work(decrypt_wq, &dw->decrypt);
4945 *num_mids = 0; /* worker thread takes care of finding mid */
4949 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
4954 *mid = smb2_find_mid(server, buf);
4956 cifs_dbg(FYI, "mid not found\n");
4958 cifs_dbg(FYI, "mid found\n");
4959 (*mid)->decrypted = true;
4960 rc = handle_read_data(server, *mid, buf,
4961 server->vals->read_rsp_size,
4962 &dw->buffer, dw->len, false);
4964 if (server->ops->is_network_name_deleted) {
4965 server->ops->is_network_name_deleted(buf,
4972 cifs_clear_xarray_buffer(&dw->buffer);
4977 cifs_discard_remaining_data(server);
4982 receive_encrypted_standard(struct TCP_Server_Info *server,
4983 struct mid_q_entry **mids, char **bufs,
4987 char *buf = server->smallbuf;
4988 struct smb2_hdr *shdr;
4989 unsigned int pdu_length = server->pdu_size;
4990 unsigned int buf_size;
4991 struct mid_q_entry *mid_entry;
4993 char *next_buffer = NULL;
4997 /* switch to large buffer if too big for a small one */
4998 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
4999 server->large_buf = true;
5000 memcpy(server->bigbuf, buf, server->total_read);
5001 buf = server->bigbuf;
5004 /* now read the rest */
5005 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
5006 pdu_length - HEADER_SIZE(server) + 1);
5009 server->total_read += length;
5011 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
5012 length = decrypt_raw_data(server, buf, buf_size, NULL, false);
5016 next_is_large = server->large_buf;
5018 shdr = (struct smb2_hdr *)buf;
5019 if (shdr->NextCommand) {
5021 next_buffer = (char *)cifs_buf_get();
5023 next_buffer = (char *)cifs_small_buf_get();
5025 buf + le32_to_cpu(shdr->NextCommand),
5026 pdu_length - le32_to_cpu(shdr->NextCommand));
5029 mid_entry = smb2_find_mid(server, buf);
5030 if (mid_entry == NULL)
5031 cifs_dbg(FYI, "mid not found\n");
5033 cifs_dbg(FYI, "mid found\n");
5034 mid_entry->decrypted = true;
5035 mid_entry->resp_buf_size = server->pdu_size;
5038 if (*num_mids >= MAX_COMPOUND) {
5039 cifs_server_dbg(VFS, "too many PDUs in compound\n");
5042 bufs[*num_mids] = buf;
5043 mids[(*num_mids)++] = mid_entry;
5045 if (mid_entry && mid_entry->handle)
5046 ret = mid_entry->handle(server, mid_entry);
5048 ret = cifs_handle_standard(server, mid_entry);
5050 if (ret == 0 && shdr->NextCommand) {
5051 pdu_length -= le32_to_cpu(shdr->NextCommand);
5052 server->large_buf = next_is_large;
5054 server->bigbuf = buf = next_buffer;
5056 server->smallbuf = buf = next_buffer;
5058 } else if (ret != 0) {
5060 * ret != 0 here means that we didn't get to handle_mid() thus
5061 * server->smallbuf and server->bigbuf are still valid. We need
5062 * to free next_buffer because it is not going to be used
5066 free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer);
5068 free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer);
5075 smb3_receive_transform(struct TCP_Server_Info *server,
5076 struct mid_q_entry **mids, char **bufs, int *num_mids)
5078 char *buf = server->smallbuf;
5079 unsigned int pdu_length = server->pdu_size;
5080 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
5081 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
5083 if (pdu_length < sizeof(struct smb2_transform_hdr) +
5084 sizeof(struct smb2_hdr)) {
5085 cifs_server_dbg(VFS, "Transform message is too small (%u)\n",
5087 cifs_reconnect(server, true);
5088 return -ECONNABORTED;
5091 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
5092 cifs_server_dbg(VFS, "Transform message is broken\n");
5093 cifs_reconnect(server, true);
5094 return -ECONNABORTED;
5097 /* TODO: add support for compounds containing READ. */
5098 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
5099 return receive_encrypted_read(server, &mids[0], num_mids);
5102 return receive_encrypted_standard(server, mids, bufs, num_mids);
5106 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
5108 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
5110 return handle_read_data(server, mid, buf, server->pdu_size,
5115 smb2_next_header(char *buf)
5117 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
5118 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
5120 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
5121 return sizeof(struct smb2_transform_hdr) +
5122 le32_to_cpu(t_hdr->OriginalMessageSize);
5124 return le32_to_cpu(hdr->NextCommand);
5128 smb2_make_node(unsigned int xid, struct inode *inode,
5129 struct dentry *dentry, struct cifs_tcon *tcon,
5130 const char *full_path, umode_t mode, dev_t dev)
5132 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
5134 struct cifs_open_info_data buf = {};
5135 struct cifs_io_parms io_parms = {0};
5137 struct cifs_fid fid;
5138 struct cifs_open_parms oparms;
5139 unsigned int bytes_written;
5140 struct win_dev *pdev;
5144 * Check if mounted with mount parm 'sfu' mount parm.
5145 * SFU emulation should work with all servers, but only
5146 * supports block and char device (no socket & fifo),
5147 * and was used by default in earlier versions of Windows
5149 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
5153 * TODO: Add ability to create instead via reparse point. Windows (e.g.
5154 * their current NFS server) uses this approach to expose special files
5155 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
5158 if (!S_ISCHR(mode) && !S_ISBLK(mode))
5161 cifs_dbg(FYI, "sfu compat create special file\n");
5163 oparms = (struct cifs_open_parms) {
5166 .desired_access = GENERIC_WRITE,
5167 .create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR |
5168 CREATE_OPTION_SPECIAL),
5169 .disposition = FILE_CREATE,
5174 if (tcon->ses->server->oplocks)
5175 oplock = REQ_OPLOCK;
5178 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, &buf);
5183 * BB Do not bother to decode buf since no local inode yet to put
5184 * timestamps in, but we can reuse it safely.
5187 pdev = (struct win_dev *)&buf.fi;
5188 io_parms.pid = current->tgid;
5189 io_parms.tcon = tcon;
5190 io_parms.offset = 0;
5191 io_parms.length = sizeof(struct win_dev);
5192 iov[1].iov_base = &buf.fi;
5193 iov[1].iov_len = sizeof(struct win_dev);
5194 if (S_ISCHR(mode)) {
5195 memcpy(pdev->type, "IntxCHR", 8);
5196 pdev->major = cpu_to_le64(MAJOR(dev));
5197 pdev->minor = cpu_to_le64(MINOR(dev));
5198 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5199 &bytes_written, iov, 1);
5200 } else if (S_ISBLK(mode)) {
5201 memcpy(pdev->type, "IntxBLK", 8);
5202 pdev->major = cpu_to_le64(MAJOR(dev));
5203 pdev->minor = cpu_to_le64(MINOR(dev));
5204 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5205 &bytes_written, iov, 1);
5207 tcon->ses->server->ops->close(xid, tcon, &fid);
5210 /* FIXME: add code here to set EAs */
5212 cifs_free_open_info(&buf);
5216 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5217 struct smb_version_operations smb20_operations = {
5218 .compare_fids = smb2_compare_fids,
5219 .setup_request = smb2_setup_request,
5220 .setup_async_request = smb2_setup_async_request,
5221 .check_receive = smb2_check_receive,
5222 .add_credits = smb2_add_credits,
5223 .set_credits = smb2_set_credits,
5224 .get_credits_field = smb2_get_credits_field,
5225 .get_credits = smb2_get_credits,
5226 .wait_mtu_credits = cifs_wait_mtu_credits,
5227 .get_next_mid = smb2_get_next_mid,
5228 .revert_current_mid = smb2_revert_current_mid,
5229 .read_data_offset = smb2_read_data_offset,
5230 .read_data_length = smb2_read_data_length,
5231 .map_error = map_smb2_to_linux_error,
5232 .find_mid = smb2_find_mid,
5233 .check_message = smb2_check_message,
5234 .dump_detail = smb2_dump_detail,
5235 .clear_stats = smb2_clear_stats,
5236 .print_stats = smb2_print_stats,
5237 .is_oplock_break = smb2_is_valid_oplock_break,
5238 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5239 .downgrade_oplock = smb2_downgrade_oplock,
5240 .need_neg = smb2_need_neg,
5241 .negotiate = smb2_negotiate,
5242 .negotiate_wsize = smb2_negotiate_wsize,
5243 .negotiate_rsize = smb2_negotiate_rsize,
5244 .sess_setup = SMB2_sess_setup,
5245 .logoff = SMB2_logoff,
5246 .tree_connect = SMB2_tcon,
5247 .tree_disconnect = SMB2_tdis,
5248 .qfs_tcon = smb2_qfs_tcon,
5249 .is_path_accessible = smb2_is_path_accessible,
5250 .can_echo = smb2_can_echo,
5252 .query_path_info = smb2_query_path_info,
5253 .get_srv_inum = smb2_get_srv_inum,
5254 .query_file_info = smb2_query_file_info,
5255 .set_path_size = smb2_set_path_size,
5256 .set_file_size = smb2_set_file_size,
5257 .set_file_info = smb2_set_file_info,
5258 .set_compression = smb2_set_compression,
5259 .mkdir = smb2_mkdir,
5260 .mkdir_setinfo = smb2_mkdir_setinfo,
5261 .rmdir = smb2_rmdir,
5262 .unlink = smb2_unlink,
5263 .rename = smb2_rename_path,
5264 .create_hardlink = smb2_create_hardlink,
5265 .query_symlink = smb2_query_symlink,
5266 .query_mf_symlink = smb3_query_mf_symlink,
5267 .create_mf_symlink = smb3_create_mf_symlink,
5268 .open = smb2_open_file,
5269 .set_fid = smb2_set_fid,
5270 .close = smb2_close_file,
5271 .flush = smb2_flush_file,
5272 .async_readv = smb2_async_readv,
5273 .async_writev = smb2_async_writev,
5274 .sync_read = smb2_sync_read,
5275 .sync_write = smb2_sync_write,
5276 .query_dir_first = smb2_query_dir_first,
5277 .query_dir_next = smb2_query_dir_next,
5278 .close_dir = smb2_close_dir,
5279 .calc_smb_size = smb2_calc_size,
5280 .is_status_pending = smb2_is_status_pending,
5281 .is_session_expired = smb2_is_session_expired,
5282 .oplock_response = smb2_oplock_response,
5283 .queryfs = smb2_queryfs,
5284 .mand_lock = smb2_mand_lock,
5285 .mand_unlock_range = smb2_unlock_range,
5286 .push_mand_locks = smb2_push_mandatory_locks,
5287 .get_lease_key = smb2_get_lease_key,
5288 .set_lease_key = smb2_set_lease_key,
5289 .new_lease_key = smb2_new_lease_key,
5290 .calc_signature = smb2_calc_signature,
5291 .is_read_op = smb2_is_read_op,
5292 .set_oplock_level = smb2_set_oplock_level,
5293 .create_lease_buf = smb2_create_lease_buf,
5294 .parse_lease_buf = smb2_parse_lease_buf,
5295 .copychunk_range = smb2_copychunk_range,
5296 .wp_retry_size = smb2_wp_retry_size,
5297 .dir_needs_close = smb2_dir_needs_close,
5298 .get_dfs_refer = smb2_get_dfs_refer,
5299 .select_sectype = smb2_select_sectype,
5300 #ifdef CONFIG_CIFS_XATTR
5301 .query_all_EAs = smb2_query_eas,
5302 .set_EA = smb2_set_ea,
5303 #endif /* CIFS_XATTR */
5304 .get_acl = get_smb2_acl,
5305 .get_acl_by_fid = get_smb2_acl_by_fid,
5306 .set_acl = set_smb2_acl,
5307 .next_header = smb2_next_header,
5308 .ioctl_query_info = smb2_ioctl_query_info,
5309 .make_node = smb2_make_node,
5310 .fiemap = smb3_fiemap,
5311 .llseek = smb3_llseek,
5312 .is_status_io_timeout = smb2_is_status_io_timeout,
5313 .is_network_name_deleted = smb2_is_network_name_deleted,
5315 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
5317 struct smb_version_operations smb21_operations = {
5318 .compare_fids = smb2_compare_fids,
5319 .setup_request = smb2_setup_request,
5320 .setup_async_request = smb2_setup_async_request,
5321 .check_receive = smb2_check_receive,
5322 .add_credits = smb2_add_credits,
5323 .set_credits = smb2_set_credits,
5324 .get_credits_field = smb2_get_credits_field,
5325 .get_credits = smb2_get_credits,
5326 .wait_mtu_credits = smb2_wait_mtu_credits,
5327 .adjust_credits = smb2_adjust_credits,
5328 .get_next_mid = smb2_get_next_mid,
5329 .revert_current_mid = smb2_revert_current_mid,
5330 .read_data_offset = smb2_read_data_offset,
5331 .read_data_length = smb2_read_data_length,
5332 .map_error = map_smb2_to_linux_error,
5333 .find_mid = smb2_find_mid,
5334 .check_message = smb2_check_message,
5335 .dump_detail = smb2_dump_detail,
5336 .clear_stats = smb2_clear_stats,
5337 .print_stats = smb2_print_stats,
5338 .is_oplock_break = smb2_is_valid_oplock_break,
5339 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5340 .downgrade_oplock = smb2_downgrade_oplock,
5341 .need_neg = smb2_need_neg,
5342 .negotiate = smb2_negotiate,
5343 .negotiate_wsize = smb2_negotiate_wsize,
5344 .negotiate_rsize = smb2_negotiate_rsize,
5345 .sess_setup = SMB2_sess_setup,
5346 .logoff = SMB2_logoff,
5347 .tree_connect = SMB2_tcon,
5348 .tree_disconnect = SMB2_tdis,
5349 .qfs_tcon = smb2_qfs_tcon,
5350 .is_path_accessible = smb2_is_path_accessible,
5351 .can_echo = smb2_can_echo,
5353 .query_path_info = smb2_query_path_info,
5354 .get_srv_inum = smb2_get_srv_inum,
5355 .query_file_info = smb2_query_file_info,
5356 .set_path_size = smb2_set_path_size,
5357 .set_file_size = smb2_set_file_size,
5358 .set_file_info = smb2_set_file_info,
5359 .set_compression = smb2_set_compression,
5360 .mkdir = smb2_mkdir,
5361 .mkdir_setinfo = smb2_mkdir_setinfo,
5362 .rmdir = smb2_rmdir,
5363 .unlink = smb2_unlink,
5364 .rename = smb2_rename_path,
5365 .create_hardlink = smb2_create_hardlink,
5366 .query_symlink = smb2_query_symlink,
5367 .query_mf_symlink = smb3_query_mf_symlink,
5368 .create_mf_symlink = smb3_create_mf_symlink,
5369 .open = smb2_open_file,
5370 .set_fid = smb2_set_fid,
5371 .close = smb2_close_file,
5372 .flush = smb2_flush_file,
5373 .async_readv = smb2_async_readv,
5374 .async_writev = smb2_async_writev,
5375 .sync_read = smb2_sync_read,
5376 .sync_write = smb2_sync_write,
5377 .query_dir_first = smb2_query_dir_first,
5378 .query_dir_next = smb2_query_dir_next,
5379 .close_dir = smb2_close_dir,
5380 .calc_smb_size = smb2_calc_size,
5381 .is_status_pending = smb2_is_status_pending,
5382 .is_session_expired = smb2_is_session_expired,
5383 .oplock_response = smb2_oplock_response,
5384 .queryfs = smb2_queryfs,
5385 .mand_lock = smb2_mand_lock,
5386 .mand_unlock_range = smb2_unlock_range,
5387 .push_mand_locks = smb2_push_mandatory_locks,
5388 .get_lease_key = smb2_get_lease_key,
5389 .set_lease_key = smb2_set_lease_key,
5390 .new_lease_key = smb2_new_lease_key,
5391 .calc_signature = smb2_calc_signature,
5392 .is_read_op = smb21_is_read_op,
5393 .set_oplock_level = smb21_set_oplock_level,
5394 .create_lease_buf = smb2_create_lease_buf,
5395 .parse_lease_buf = smb2_parse_lease_buf,
5396 .copychunk_range = smb2_copychunk_range,
5397 .wp_retry_size = smb2_wp_retry_size,
5398 .dir_needs_close = smb2_dir_needs_close,
5399 .enum_snapshots = smb3_enum_snapshots,
5400 .notify = smb3_notify,
5401 .get_dfs_refer = smb2_get_dfs_refer,
5402 .select_sectype = smb2_select_sectype,
5403 #ifdef CONFIG_CIFS_XATTR
5404 .query_all_EAs = smb2_query_eas,
5405 .set_EA = smb2_set_ea,
5406 #endif /* CIFS_XATTR */
5407 .get_acl = get_smb2_acl,
5408 .get_acl_by_fid = get_smb2_acl_by_fid,
5409 .set_acl = set_smb2_acl,
5410 .next_header = smb2_next_header,
5411 .ioctl_query_info = smb2_ioctl_query_info,
5412 .make_node = smb2_make_node,
5413 .fiemap = smb3_fiemap,
5414 .llseek = smb3_llseek,
5415 .is_status_io_timeout = smb2_is_status_io_timeout,
5416 .is_network_name_deleted = smb2_is_network_name_deleted,
5419 struct smb_version_operations smb30_operations = {
5420 .compare_fids = smb2_compare_fids,
5421 .setup_request = smb2_setup_request,
5422 .setup_async_request = smb2_setup_async_request,
5423 .check_receive = smb2_check_receive,
5424 .add_credits = smb2_add_credits,
5425 .set_credits = smb2_set_credits,
5426 .get_credits_field = smb2_get_credits_field,
5427 .get_credits = smb2_get_credits,
5428 .wait_mtu_credits = smb2_wait_mtu_credits,
5429 .adjust_credits = smb2_adjust_credits,
5430 .get_next_mid = smb2_get_next_mid,
5431 .revert_current_mid = smb2_revert_current_mid,
5432 .read_data_offset = smb2_read_data_offset,
5433 .read_data_length = smb2_read_data_length,
5434 .map_error = map_smb2_to_linux_error,
5435 .find_mid = smb2_find_mid,
5436 .check_message = smb2_check_message,
5437 .dump_detail = smb2_dump_detail,
5438 .clear_stats = smb2_clear_stats,
5439 .print_stats = smb2_print_stats,
5440 .dump_share_caps = smb2_dump_share_caps,
5441 .is_oplock_break = smb2_is_valid_oplock_break,
5442 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5443 .downgrade_oplock = smb3_downgrade_oplock,
5444 .need_neg = smb2_need_neg,
5445 .negotiate = smb2_negotiate,
5446 .negotiate_wsize = smb3_negotiate_wsize,
5447 .negotiate_rsize = smb3_negotiate_rsize,
5448 .sess_setup = SMB2_sess_setup,
5449 .logoff = SMB2_logoff,
5450 .tree_connect = SMB2_tcon,
5451 .tree_disconnect = SMB2_tdis,
5452 .qfs_tcon = smb3_qfs_tcon,
5453 .is_path_accessible = smb2_is_path_accessible,
5454 .can_echo = smb2_can_echo,
5456 .query_path_info = smb2_query_path_info,
5457 /* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */
5458 .query_reparse_tag = smb2_query_reparse_tag,
5459 .get_srv_inum = smb2_get_srv_inum,
5460 .query_file_info = smb2_query_file_info,
5461 .set_path_size = smb2_set_path_size,
5462 .set_file_size = smb2_set_file_size,
5463 .set_file_info = smb2_set_file_info,
5464 .set_compression = smb2_set_compression,
5465 .mkdir = smb2_mkdir,
5466 .mkdir_setinfo = smb2_mkdir_setinfo,
5467 .rmdir = smb2_rmdir,
5468 .unlink = smb2_unlink,
5469 .rename = smb2_rename_path,
5470 .create_hardlink = smb2_create_hardlink,
5471 .query_symlink = smb2_query_symlink,
5472 .query_mf_symlink = smb3_query_mf_symlink,
5473 .create_mf_symlink = smb3_create_mf_symlink,
5474 .open = smb2_open_file,
5475 .set_fid = smb2_set_fid,
5476 .close = smb2_close_file,
5477 .close_getattr = smb2_close_getattr,
5478 .flush = smb2_flush_file,
5479 .async_readv = smb2_async_readv,
5480 .async_writev = smb2_async_writev,
5481 .sync_read = smb2_sync_read,
5482 .sync_write = smb2_sync_write,
5483 .query_dir_first = smb2_query_dir_first,
5484 .query_dir_next = smb2_query_dir_next,
5485 .close_dir = smb2_close_dir,
5486 .calc_smb_size = smb2_calc_size,
5487 .is_status_pending = smb2_is_status_pending,
5488 .is_session_expired = smb2_is_session_expired,
5489 .oplock_response = smb2_oplock_response,
5490 .queryfs = smb2_queryfs,
5491 .mand_lock = smb2_mand_lock,
5492 .mand_unlock_range = smb2_unlock_range,
5493 .push_mand_locks = smb2_push_mandatory_locks,
5494 .get_lease_key = smb2_get_lease_key,
5495 .set_lease_key = smb2_set_lease_key,
5496 .new_lease_key = smb2_new_lease_key,
5497 .generate_signingkey = generate_smb30signingkey,
5498 .calc_signature = smb3_calc_signature,
5499 .set_integrity = smb3_set_integrity,
5500 .is_read_op = smb21_is_read_op,
5501 .set_oplock_level = smb3_set_oplock_level,
5502 .create_lease_buf = smb3_create_lease_buf,
5503 .parse_lease_buf = smb3_parse_lease_buf,
5504 .copychunk_range = smb2_copychunk_range,
5505 .duplicate_extents = smb2_duplicate_extents,
5506 .validate_negotiate = smb3_validate_negotiate,
5507 .wp_retry_size = smb2_wp_retry_size,
5508 .dir_needs_close = smb2_dir_needs_close,
5509 .fallocate = smb3_fallocate,
5510 .enum_snapshots = smb3_enum_snapshots,
5511 .notify = smb3_notify,
5512 .init_transform_rq = smb3_init_transform_rq,
5513 .is_transform_hdr = smb3_is_transform_hdr,
5514 .receive_transform = smb3_receive_transform,
5515 .get_dfs_refer = smb2_get_dfs_refer,
5516 .select_sectype = smb2_select_sectype,
5517 #ifdef CONFIG_CIFS_XATTR
5518 .query_all_EAs = smb2_query_eas,
5519 .set_EA = smb2_set_ea,
5520 #endif /* CIFS_XATTR */
5521 .get_acl = get_smb2_acl,
5522 .get_acl_by_fid = get_smb2_acl_by_fid,
5523 .set_acl = set_smb2_acl,
5524 .next_header = smb2_next_header,
5525 .ioctl_query_info = smb2_ioctl_query_info,
5526 .make_node = smb2_make_node,
5527 .fiemap = smb3_fiemap,
5528 .llseek = smb3_llseek,
5529 .is_status_io_timeout = smb2_is_status_io_timeout,
5530 .is_network_name_deleted = smb2_is_network_name_deleted,
5533 struct smb_version_operations smb311_operations = {
5534 .compare_fids = smb2_compare_fids,
5535 .setup_request = smb2_setup_request,
5536 .setup_async_request = smb2_setup_async_request,
5537 .check_receive = smb2_check_receive,
5538 .add_credits = smb2_add_credits,
5539 .set_credits = smb2_set_credits,
5540 .get_credits_field = smb2_get_credits_field,
5541 .get_credits = smb2_get_credits,
5542 .wait_mtu_credits = smb2_wait_mtu_credits,
5543 .adjust_credits = smb2_adjust_credits,
5544 .get_next_mid = smb2_get_next_mid,
5545 .revert_current_mid = smb2_revert_current_mid,
5546 .read_data_offset = smb2_read_data_offset,
5547 .read_data_length = smb2_read_data_length,
5548 .map_error = map_smb2_to_linux_error,
5549 .find_mid = smb2_find_mid,
5550 .check_message = smb2_check_message,
5551 .dump_detail = smb2_dump_detail,
5552 .clear_stats = smb2_clear_stats,
5553 .print_stats = smb2_print_stats,
5554 .dump_share_caps = smb2_dump_share_caps,
5555 .is_oplock_break = smb2_is_valid_oplock_break,
5556 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5557 .downgrade_oplock = smb3_downgrade_oplock,
5558 .need_neg = smb2_need_neg,
5559 .negotiate = smb2_negotiate,
5560 .negotiate_wsize = smb3_negotiate_wsize,
5561 .negotiate_rsize = smb3_negotiate_rsize,
5562 .sess_setup = SMB2_sess_setup,
5563 .logoff = SMB2_logoff,
5564 .tree_connect = SMB2_tcon,
5565 .tree_disconnect = SMB2_tdis,
5566 .qfs_tcon = smb3_qfs_tcon,
5567 .is_path_accessible = smb2_is_path_accessible,
5568 .can_echo = smb2_can_echo,
5570 .query_path_info = smb2_query_path_info,
5571 .query_reparse_tag = smb2_query_reparse_tag,
5572 .get_srv_inum = smb2_get_srv_inum,
5573 .query_file_info = smb2_query_file_info,
5574 .set_path_size = smb2_set_path_size,
5575 .set_file_size = smb2_set_file_size,
5576 .set_file_info = smb2_set_file_info,
5577 .set_compression = smb2_set_compression,
5578 .mkdir = smb2_mkdir,
5579 .mkdir_setinfo = smb2_mkdir_setinfo,
5580 .posix_mkdir = smb311_posix_mkdir,
5581 .rmdir = smb2_rmdir,
5582 .unlink = smb2_unlink,
5583 .rename = smb2_rename_path,
5584 .create_hardlink = smb2_create_hardlink,
5585 .query_symlink = smb2_query_symlink,
5586 .query_mf_symlink = smb3_query_mf_symlink,
5587 .create_mf_symlink = smb3_create_mf_symlink,
5588 .open = smb2_open_file,
5589 .set_fid = smb2_set_fid,
5590 .close = smb2_close_file,
5591 .close_getattr = smb2_close_getattr,
5592 .flush = smb2_flush_file,
5593 .async_readv = smb2_async_readv,
5594 .async_writev = smb2_async_writev,
5595 .sync_read = smb2_sync_read,
5596 .sync_write = smb2_sync_write,
5597 .query_dir_first = smb2_query_dir_first,
5598 .query_dir_next = smb2_query_dir_next,
5599 .close_dir = smb2_close_dir,
5600 .calc_smb_size = smb2_calc_size,
5601 .is_status_pending = smb2_is_status_pending,
5602 .is_session_expired = smb2_is_session_expired,
5603 .oplock_response = smb2_oplock_response,
5604 .queryfs = smb311_queryfs,
5605 .mand_lock = smb2_mand_lock,
5606 .mand_unlock_range = smb2_unlock_range,
5607 .push_mand_locks = smb2_push_mandatory_locks,
5608 .get_lease_key = smb2_get_lease_key,
5609 .set_lease_key = smb2_set_lease_key,
5610 .new_lease_key = smb2_new_lease_key,
5611 .generate_signingkey = generate_smb311signingkey,
5612 .calc_signature = smb3_calc_signature,
5613 .set_integrity = smb3_set_integrity,
5614 .is_read_op = smb21_is_read_op,
5615 .set_oplock_level = smb3_set_oplock_level,
5616 .create_lease_buf = smb3_create_lease_buf,
5617 .parse_lease_buf = smb3_parse_lease_buf,
5618 .copychunk_range = smb2_copychunk_range,
5619 .duplicate_extents = smb2_duplicate_extents,
5620 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
5621 .wp_retry_size = smb2_wp_retry_size,
5622 .dir_needs_close = smb2_dir_needs_close,
5623 .fallocate = smb3_fallocate,
5624 .enum_snapshots = smb3_enum_snapshots,
5625 .notify = smb3_notify,
5626 .init_transform_rq = smb3_init_transform_rq,
5627 .is_transform_hdr = smb3_is_transform_hdr,
5628 .receive_transform = smb3_receive_transform,
5629 .get_dfs_refer = smb2_get_dfs_refer,
5630 .select_sectype = smb2_select_sectype,
5631 #ifdef CONFIG_CIFS_XATTR
5632 .query_all_EAs = smb2_query_eas,
5633 .set_EA = smb2_set_ea,
5634 #endif /* CIFS_XATTR */
5635 .get_acl = get_smb2_acl,
5636 .get_acl_by_fid = get_smb2_acl_by_fid,
5637 .set_acl = set_smb2_acl,
5638 .next_header = smb2_next_header,
5639 .ioctl_query_info = smb2_ioctl_query_info,
5640 .make_node = smb2_make_node,
5641 .fiemap = smb3_fiemap,
5642 .llseek = smb3_llseek,
5643 .is_status_io_timeout = smb2_is_status_io_timeout,
5644 .is_network_name_deleted = smb2_is_network_name_deleted,
5647 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5648 struct smb_version_values smb20_values = {
5649 .version_string = SMB20_VERSION_STRING,
5650 .protocol_id = SMB20_PROT_ID,
5651 .req_capabilities = 0, /* MBZ */
5652 .large_lock_type = 0,
5653 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5654 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5655 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5656 .header_size = sizeof(struct smb2_hdr),
5657 .header_preamble_size = 0,
5658 .max_header_size = MAX_SMB2_HDR_SIZE,
5659 .read_rsp_size = sizeof(struct smb2_read_rsp),
5660 .lock_cmd = SMB2_LOCK,
5662 .cap_nt_find = SMB2_NT_FIND,
5663 .cap_large_files = SMB2_LARGE_FILES,
5664 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5665 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5666 .create_lease_size = sizeof(struct create_lease),
5668 #endif /* ALLOW_INSECURE_LEGACY */
5670 struct smb_version_values smb21_values = {
5671 .version_string = SMB21_VERSION_STRING,
5672 .protocol_id = SMB21_PROT_ID,
5673 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
5674 .large_lock_type = 0,
5675 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5676 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5677 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5678 .header_size = sizeof(struct smb2_hdr),
5679 .header_preamble_size = 0,
5680 .max_header_size = MAX_SMB2_HDR_SIZE,
5681 .read_rsp_size = sizeof(struct smb2_read_rsp),
5682 .lock_cmd = SMB2_LOCK,
5684 .cap_nt_find = SMB2_NT_FIND,
5685 .cap_large_files = SMB2_LARGE_FILES,
5686 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5687 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5688 .create_lease_size = sizeof(struct create_lease),
5691 struct smb_version_values smb3any_values = {
5692 .version_string = SMB3ANY_VERSION_STRING,
5693 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5694 .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,
5695 .large_lock_type = 0,
5696 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5697 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5698 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5699 .header_size = sizeof(struct smb2_hdr),
5700 .header_preamble_size = 0,
5701 .max_header_size = MAX_SMB2_HDR_SIZE,
5702 .read_rsp_size = sizeof(struct smb2_read_rsp),
5703 .lock_cmd = SMB2_LOCK,
5705 .cap_nt_find = SMB2_NT_FIND,
5706 .cap_large_files = SMB2_LARGE_FILES,
5707 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5708 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5709 .create_lease_size = sizeof(struct create_lease_v2),
5712 struct smb_version_values smbdefault_values = {
5713 .version_string = SMBDEFAULT_VERSION_STRING,
5714 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5715 .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,
5716 .large_lock_type = 0,
5717 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5718 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5719 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5720 .header_size = sizeof(struct smb2_hdr),
5721 .header_preamble_size = 0,
5722 .max_header_size = MAX_SMB2_HDR_SIZE,
5723 .read_rsp_size = sizeof(struct smb2_read_rsp),
5724 .lock_cmd = SMB2_LOCK,
5726 .cap_nt_find = SMB2_NT_FIND,
5727 .cap_large_files = SMB2_LARGE_FILES,
5728 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5729 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5730 .create_lease_size = sizeof(struct create_lease_v2),
5733 struct smb_version_values smb30_values = {
5734 .version_string = SMB30_VERSION_STRING,
5735 .protocol_id = SMB30_PROT_ID,
5736 .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,
5737 .large_lock_type = 0,
5738 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5739 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5740 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5741 .header_size = sizeof(struct smb2_hdr),
5742 .header_preamble_size = 0,
5743 .max_header_size = MAX_SMB2_HDR_SIZE,
5744 .read_rsp_size = sizeof(struct smb2_read_rsp),
5745 .lock_cmd = SMB2_LOCK,
5747 .cap_nt_find = SMB2_NT_FIND,
5748 .cap_large_files = SMB2_LARGE_FILES,
5749 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5750 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5751 .create_lease_size = sizeof(struct create_lease_v2),
5754 struct smb_version_values smb302_values = {
5755 .version_string = SMB302_VERSION_STRING,
5756 .protocol_id = SMB302_PROT_ID,
5757 .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,
5758 .large_lock_type = 0,
5759 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5760 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5761 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5762 .header_size = sizeof(struct smb2_hdr),
5763 .header_preamble_size = 0,
5764 .max_header_size = MAX_SMB2_HDR_SIZE,
5765 .read_rsp_size = sizeof(struct smb2_read_rsp),
5766 .lock_cmd = SMB2_LOCK,
5768 .cap_nt_find = SMB2_NT_FIND,
5769 .cap_large_files = SMB2_LARGE_FILES,
5770 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5771 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5772 .create_lease_size = sizeof(struct create_lease_v2),
5775 struct smb_version_values smb311_values = {
5776 .version_string = SMB311_VERSION_STRING,
5777 .protocol_id = SMB311_PROT_ID,
5778 .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,
5779 .large_lock_type = 0,
5780 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5781 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5782 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5783 .header_size = sizeof(struct smb2_hdr),
5784 .header_preamble_size = 0,
5785 .max_header_size = MAX_SMB2_HDR_SIZE,
5786 .read_rsp_size = sizeof(struct smb2_read_rsp),
5787 .lock_cmd = SMB2_LOCK,
5789 .cap_nt_find = SMB2_NT_FIND,
5790 .cap_large_files = SMB2_LARGE_FILES,
5791 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5792 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5793 .create_lease_size = sizeof(struct create_lease_v2),