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 ses->iface_count = 0;
535 * Go through iface_list and do kref_put to remove
536 * any unused ifaces. ifaces in use will be removed
537 * when the last user calls a kref_put on it
539 list_for_each_entry_safe(iface, niface, &ses->iface_list,
541 iface->is_active = 0;
542 kref_put(&iface->refcount, release_iface);
544 spin_unlock(&ses->iface_lock);
547 * Samba server e.g. can return an empty interface list in some cases,
548 * which would only be a problem if we were requesting multichannel
550 if (bytes_left == 0) {
551 /* avoid spamming logs every 10 minutes, so log only in mount */
552 if ((ses->chan_max > 1) && in_mount)
554 "multichannel not available\n"
555 "Empty network interface list returned by server %s\n",
556 ses->server->hostname);
561 while (bytes_left >= sizeof(*p)) {
562 memset(&tmp_iface, 0, sizeof(tmp_iface));
563 tmp_iface.speed = le64_to_cpu(p->LinkSpeed);
564 tmp_iface.rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE) ? 1 : 0;
565 tmp_iface.rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE) ? 1 : 0;
569 * The kernel and wire socket structures have the same
570 * layout and use network byte order but make the
571 * conversion explicit in case either one changes.
574 addr4 = (struct sockaddr_in *)&tmp_iface.sockaddr;
575 p4 = (struct iface_info_ipv4 *)p->Buffer;
576 addr4->sin_family = AF_INET;
577 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
579 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
580 addr4->sin_port = cpu_to_be16(CIFS_PORT);
582 cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
586 addr6 = (struct sockaddr_in6 *)&tmp_iface.sockaddr;
587 p6 = (struct iface_info_ipv6 *)p->Buffer;
588 addr6->sin6_family = AF_INET6;
589 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
591 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
592 addr6->sin6_flowinfo = 0;
593 addr6->sin6_scope_id = 0;
594 addr6->sin6_port = cpu_to_be16(CIFS_PORT);
596 cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
601 "%s: skipping unsupported socket family\n",
607 * The iface_list is assumed to be sorted by speed.
608 * Check if the new interface exists in that list.
609 * NEVER change iface. it could be in use.
610 * Add a new one instead
612 spin_lock(&ses->iface_lock);
613 iface = niface = NULL;
614 list_for_each_entry_safe(iface, niface, &ses->iface_list,
616 ret = iface_cmp(iface, &tmp_iface);
618 /* just get a ref so that it doesn't get picked/freed */
619 iface->is_active = 1;
620 kref_get(&iface->refcount);
621 spin_unlock(&ses->iface_lock);
623 } else if (ret < 0) {
624 /* all remaining ifaces are slower */
625 kref_get(&iface->refcount);
629 spin_unlock(&ses->iface_lock);
631 /* no match. insert the entry in the list */
632 info = kmalloc(sizeof(struct cifs_server_iface),
638 memcpy(info, &tmp_iface, sizeof(tmp_iface));
640 /* add this new entry to the list */
641 kref_init(&info->refcount);
644 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, ses->iface_count);
645 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
646 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
647 le32_to_cpu(p->Capability));
649 spin_lock(&ses->iface_lock);
650 if (!list_entry_is_head(iface, &ses->iface_list, iface_head)) {
651 list_add_tail(&info->iface_head, &iface->iface_head);
652 kref_put(&iface->refcount, release_iface);
654 list_add_tail(&info->iface_head, &ses->iface_list);
657 spin_unlock(&ses->iface_lock);
658 ses->iface_last_update = jiffies;
661 next = le32_to_cpu(p->Next);
663 bytes_left -= sizeof(*p);
666 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
671 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
676 /* Azure rounds the buffer size up 8, to a 16 byte boundary */
677 if ((bytes_left > 8) || p->Next)
678 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
681 if (!ses->iface_count) {
691 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon, bool in_mount)
694 unsigned int ret_data_len = 0;
695 struct network_interface_info_ioctl_rsp *out_buf = NULL;
696 struct cifs_ses *ses = tcon->ses;
698 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
699 FSCTL_QUERY_NETWORK_INTERFACE_INFO,
700 NULL /* no data input */, 0 /* no data input */,
701 CIFSMaxBufSize, (char **)&out_buf, &ret_data_len);
702 if (rc == -EOPNOTSUPP) {
704 "server does not support query network interfaces\n");
706 } else if (rc != 0) {
707 cifs_tcon_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
711 rc = parse_server_interfaces(out_buf, ret_data_len, ses, in_mount);
721 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
722 struct cifs_sb_info *cifs_sb)
725 __le16 srch_path = 0; /* Null - open root of share */
726 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
727 struct cifs_open_parms oparms;
729 struct cached_fid *cfid = NULL;
732 oparms.desired_access = FILE_READ_ATTRIBUTES;
733 oparms.disposition = FILE_OPEN;
734 oparms.create_options = cifs_create_options(cifs_sb, 0);
736 oparms.reconnect = false;
738 rc = open_cached_dir(xid, tcon, "", cifs_sb, false, &cfid);
740 memcpy(&fid, &cfid->fid, sizeof(struct cifs_fid));
742 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
747 SMB3_request_interfaces(xid, tcon, true /* called during mount */);
749 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
750 FS_ATTRIBUTE_INFORMATION);
751 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
752 FS_DEVICE_INFORMATION);
753 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
754 FS_VOLUME_INFORMATION);
755 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
756 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
758 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
760 close_cached_dir(cfid);
764 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
765 struct cifs_sb_info *cifs_sb)
768 __le16 srch_path = 0; /* Null - open root of share */
769 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
770 struct cifs_open_parms oparms;
774 oparms.desired_access = FILE_READ_ATTRIBUTES;
775 oparms.disposition = FILE_OPEN;
776 oparms.create_options = cifs_create_options(cifs_sb, 0);
778 oparms.reconnect = false;
780 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
785 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
786 FS_ATTRIBUTE_INFORMATION);
787 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
788 FS_DEVICE_INFORMATION);
789 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
793 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
794 struct cifs_sb_info *cifs_sb, const char *full_path)
798 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
799 int err_buftype = CIFS_NO_BUFFER;
800 struct cifs_open_parms oparms;
801 struct kvec err_iov = {};
803 struct cached_fid *cfid;
805 rc = open_cached_dir(xid, tcon, full_path, cifs_sb, true, &cfid);
807 if (cfid->has_lease) {
808 close_cached_dir(cfid);
811 close_cached_dir(cfid);
814 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
819 oparms.desired_access = FILE_READ_ATTRIBUTES;
820 oparms.disposition = FILE_OPEN;
821 oparms.create_options = cifs_create_options(cifs_sb, 0);
823 oparms.reconnect = false;
825 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
826 &err_iov, &err_buftype);
828 struct smb2_hdr *hdr = err_iov.iov_base;
830 if (unlikely(!hdr || err_buftype == CIFS_NO_BUFFER))
833 * Handle weird Windows SMB server behaviour. It responds with
834 * STATUS_OBJECT_NAME_INVALID code to SMB2 QUERY_INFO request
835 * for "\<server>\<dfsname>\<linkpath>" DFS reference,
836 * where <dfsname> contains non-ASCII unicode symbols.
838 if (rc != -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) &&
839 hdr->Status == STATUS_OBJECT_NAME_INVALID)
841 if (rc == -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) && cifs_sb &&
842 (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS))
847 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
850 free_rsp_buf(err_buftype, err_iov.iov_base);
855 static int smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
856 struct cifs_sb_info *cifs_sb, const char *full_path,
857 u64 *uniqueid, struct cifs_open_info_data *data)
859 *uniqueid = le64_to_cpu(data->fi.IndexNumber);
863 static int smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
864 struct cifsFileInfo *cfile, struct cifs_open_info_data *data)
866 struct cifs_fid *fid = &cfile->fid;
868 if (cfile->symlink_target) {
869 data->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
870 if (!data->symlink_target)
873 return SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, &data->fi);
876 #ifdef CONFIG_CIFS_XATTR
878 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
879 struct smb2_file_full_ea_info *src, size_t src_size,
880 const unsigned char *ea_name)
883 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
885 size_t buf_size = dst_size;
886 size_t name_len, value_len, user_name_len;
888 while (src_size > 0) {
889 name_len = (size_t)src->ea_name_length;
890 value_len = (size_t)le16_to_cpu(src->ea_value_length);
895 if (src_size < 8 + name_len + 1 + value_len) {
896 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
901 name = &src->ea_data[0];
902 value = &src->ea_data[src->ea_name_length + 1];
905 if (ea_name_len == name_len &&
906 memcmp(ea_name, name, name_len) == 0) {
910 if (dst_size < value_len) {
914 memcpy(dst, value, value_len);
918 /* 'user.' plus a terminating null */
919 user_name_len = 5 + 1 + name_len;
922 /* skip copy - calc size only */
924 } else if (dst_size >= user_name_len) {
925 dst_size -= user_name_len;
926 memcpy(dst, "user.", 5);
928 memcpy(dst, src->ea_data, name_len);
934 /* stop before overrun buffer */
940 if (!src->next_entry_offset)
943 if (src_size < le32_to_cpu(src->next_entry_offset)) {
944 /* stop before overrun buffer */
948 src_size -= le32_to_cpu(src->next_entry_offset);
949 src = (void *)((char *)src +
950 le32_to_cpu(src->next_entry_offset));
953 /* didn't find the named attribute */
962 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
963 const unsigned char *path, const unsigned char *ea_name,
964 char *ea_data, size_t buf_size,
965 struct cifs_sb_info *cifs_sb)
968 struct kvec rsp_iov = {NULL, 0};
969 int buftype = CIFS_NO_BUFFER;
970 struct smb2_query_info_rsp *rsp;
971 struct smb2_file_full_ea_info *info = NULL;
973 rc = smb2_query_info_compound(xid, tcon, path,
975 FILE_FULL_EA_INFORMATION,
978 MAX_SMB2_CREATE_RESPONSE_SIZE -
979 MAX_SMB2_CLOSE_RESPONSE_SIZE,
980 &rsp_iov, &buftype, cifs_sb);
983 * If ea_name is NULL (listxattr) and there are no EAs,
984 * return 0 as it's not an error. Otherwise, the specified
985 * ea_name was not found.
987 if (!ea_name && rc == -ENODATA)
992 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
993 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
994 le32_to_cpu(rsp->OutputBufferLength),
996 sizeof(struct smb2_file_full_ea_info));
1000 info = (struct smb2_file_full_ea_info *)(
1001 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1002 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
1003 le32_to_cpu(rsp->OutputBufferLength), ea_name);
1006 free_rsp_buf(buftype, rsp_iov.iov_base);
1012 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
1013 const char *path, const char *ea_name, const void *ea_value,
1014 const __u16 ea_value_len, const struct nls_table *nls_codepage,
1015 struct cifs_sb_info *cifs_sb)
1017 struct cifs_ses *ses = tcon->ses;
1018 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1019 __le16 *utf16_path = NULL;
1020 int ea_name_len = strlen(ea_name);
1021 int flags = CIFS_CP_CREATE_CLOSE_OP;
1023 struct smb_rqst rqst[3];
1024 int resp_buftype[3];
1025 struct kvec rsp_iov[3];
1026 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1027 struct cifs_open_parms oparms;
1028 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1029 struct cifs_fid fid;
1030 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1031 unsigned int size[1];
1033 struct smb2_file_full_ea_info *ea = NULL;
1034 struct kvec close_iov[1];
1035 struct smb2_query_info_rsp *rsp;
1036 int rc, used_len = 0;
1038 if (smb3_encryption_required(tcon))
1039 flags |= CIFS_TRANSFORM_REQ;
1041 if (ea_name_len > 255)
1044 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1048 memset(rqst, 0, sizeof(rqst));
1049 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1050 memset(rsp_iov, 0, sizeof(rsp_iov));
1052 if (ses->server->ops->query_all_EAs) {
1054 rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1060 /* If we are adding a attribute we should first check
1061 * if there will be enough space available to store
1062 * the new EA. If not we should not add it since we
1063 * would not be able to even read the EAs back.
1065 rc = smb2_query_info_compound(xid, tcon, path,
1067 FILE_FULL_EA_INFORMATION,
1070 MAX_SMB2_CREATE_RESPONSE_SIZE -
1071 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1072 &rsp_iov[1], &resp_buftype[1], cifs_sb);
1074 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1075 used_len = le32_to_cpu(rsp->OutputBufferLength);
1077 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1078 resp_buftype[1] = CIFS_NO_BUFFER;
1079 memset(&rsp_iov[1], 0, sizeof(rsp_iov[1]));
1082 /* Use a fudge factor of 256 bytes in case we collide
1083 * with a different set_EAs command.
1085 if(CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1086 MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 <
1087 used_len + ea_name_len + ea_value_len + 1) {
1095 memset(&open_iov, 0, sizeof(open_iov));
1096 rqst[0].rq_iov = open_iov;
1097 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1099 memset(&oparms, 0, sizeof(oparms));
1101 oparms.desired_access = FILE_WRITE_EA;
1102 oparms.disposition = FILE_OPEN;
1103 oparms.create_options = cifs_create_options(cifs_sb, 0);
1105 oparms.reconnect = false;
1107 rc = SMB2_open_init(tcon, server,
1108 &rqst[0], &oplock, &oparms, utf16_path);
1111 smb2_set_next_command(tcon, &rqst[0]);
1115 memset(&si_iov, 0, sizeof(si_iov));
1116 rqst[1].rq_iov = si_iov;
1117 rqst[1].rq_nvec = 1;
1119 len = sizeof(*ea) + ea_name_len + ea_value_len + 1;
1120 ea = kzalloc(len, GFP_KERNEL);
1126 ea->ea_name_length = ea_name_len;
1127 ea->ea_value_length = cpu_to_le16(ea_value_len);
1128 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
1129 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
1134 rc = SMB2_set_info_init(tcon, server,
1135 &rqst[1], COMPOUND_FID,
1136 COMPOUND_FID, current->tgid,
1137 FILE_FULL_EA_INFORMATION,
1138 SMB2_O_INFO_FILE, 0, data, size);
1141 smb2_set_next_command(tcon, &rqst[1]);
1142 smb2_set_related(&rqst[1]);
1146 memset(&close_iov, 0, sizeof(close_iov));
1147 rqst[2].rq_iov = close_iov;
1148 rqst[2].rq_nvec = 1;
1149 rc = SMB2_close_init(tcon, server,
1150 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1153 smb2_set_related(&rqst[2]);
1155 rc = compound_send_recv(xid, ses, server,
1157 resp_buftype, rsp_iov);
1158 /* no need to bump num_remote_opens because handle immediately closed */
1163 SMB2_open_free(&rqst[0]);
1164 SMB2_set_info_free(&rqst[1]);
1165 SMB2_close_free(&rqst[2]);
1166 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1167 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1168 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1174 smb2_can_echo(struct TCP_Server_Info *server)
1176 return server->echoes;
1180 smb2_clear_stats(struct cifs_tcon *tcon)
1184 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1185 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1186 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1191 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1193 seq_puts(m, "\n\tShare Capabilities:");
1194 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1195 seq_puts(m, " DFS,");
1196 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1197 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1198 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1199 seq_puts(m, " SCALEOUT,");
1200 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1201 seq_puts(m, " CLUSTER,");
1202 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1203 seq_puts(m, " ASYMMETRIC,");
1204 if (tcon->capabilities == 0)
1205 seq_puts(m, " None");
1206 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1207 seq_puts(m, " Aligned,");
1208 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1209 seq_puts(m, " Partition Aligned,");
1210 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1211 seq_puts(m, " SSD,");
1212 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1213 seq_puts(m, " TRIM-support,");
1215 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1216 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1217 if (tcon->perf_sector_size)
1218 seq_printf(m, "\tOptimal sector size: 0x%x",
1219 tcon->perf_sector_size);
1220 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1224 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1226 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1227 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1230 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1231 * totals (requests sent) since those SMBs are per-session not per tcon
1233 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1234 (long long)(tcon->bytes_read),
1235 (long long)(tcon->bytes_written));
1236 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1237 atomic_read(&tcon->num_local_opens),
1238 atomic_read(&tcon->num_remote_opens));
1239 seq_printf(m, "\nTreeConnects: %d total %d failed",
1240 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1241 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1242 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1243 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1244 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1245 seq_printf(m, "\nCreates: %d total %d failed",
1246 atomic_read(&sent[SMB2_CREATE_HE]),
1247 atomic_read(&failed[SMB2_CREATE_HE]));
1248 seq_printf(m, "\nCloses: %d total %d failed",
1249 atomic_read(&sent[SMB2_CLOSE_HE]),
1250 atomic_read(&failed[SMB2_CLOSE_HE]));
1251 seq_printf(m, "\nFlushes: %d total %d failed",
1252 atomic_read(&sent[SMB2_FLUSH_HE]),
1253 atomic_read(&failed[SMB2_FLUSH_HE]));
1254 seq_printf(m, "\nReads: %d total %d failed",
1255 atomic_read(&sent[SMB2_READ_HE]),
1256 atomic_read(&failed[SMB2_READ_HE]));
1257 seq_printf(m, "\nWrites: %d total %d failed",
1258 atomic_read(&sent[SMB2_WRITE_HE]),
1259 atomic_read(&failed[SMB2_WRITE_HE]));
1260 seq_printf(m, "\nLocks: %d total %d failed",
1261 atomic_read(&sent[SMB2_LOCK_HE]),
1262 atomic_read(&failed[SMB2_LOCK_HE]));
1263 seq_printf(m, "\nIOCTLs: %d total %d failed",
1264 atomic_read(&sent[SMB2_IOCTL_HE]),
1265 atomic_read(&failed[SMB2_IOCTL_HE]));
1266 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1267 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1268 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1269 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1270 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1271 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1272 seq_printf(m, "\nQueryInfos: %d total %d failed",
1273 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1274 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1275 seq_printf(m, "\nSetInfos: %d total %d failed",
1276 atomic_read(&sent[SMB2_SET_INFO_HE]),
1277 atomic_read(&failed[SMB2_SET_INFO_HE]));
1278 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1279 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1280 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1284 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1286 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1287 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1289 cfile->fid.persistent_fid = fid->persistent_fid;
1290 cfile->fid.volatile_fid = fid->volatile_fid;
1291 cfile->fid.access = fid->access;
1292 #ifdef CONFIG_CIFS_DEBUG2
1293 cfile->fid.mid = fid->mid;
1294 #endif /* CIFS_DEBUG2 */
1295 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1297 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1298 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1302 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1303 struct cifs_fid *fid)
1305 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1309 smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon,
1310 struct cifsFileInfo *cfile)
1312 struct smb2_file_network_open_info file_inf;
1313 struct inode *inode;
1316 rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid,
1317 cfile->fid.volatile_fid, &file_inf);
1321 inode = d_inode(cfile->dentry);
1323 spin_lock(&inode->i_lock);
1324 CIFS_I(inode)->time = jiffies;
1326 /* Creation time should not need to be updated on close */
1327 if (file_inf.LastWriteTime)
1328 inode->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime);
1329 if (file_inf.ChangeTime)
1330 inode->i_ctime = cifs_NTtimeToUnix(file_inf.ChangeTime);
1331 if (file_inf.LastAccessTime)
1332 inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime);
1335 * i_blocks is not related to (i_size / i_blksize),
1336 * but instead 512 byte (2**9) size is required for
1337 * calculating num blocks.
1339 if (le64_to_cpu(file_inf.AllocationSize) > 4096)
1341 (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9;
1343 /* End of file and Attributes should not have to be updated on close */
1344 spin_unlock(&inode->i_lock);
1348 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1349 u64 persistent_fid, u64 volatile_fid,
1350 struct copychunk_ioctl *pcchunk)
1353 unsigned int ret_data_len;
1354 struct resume_key_req *res_key;
1356 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1357 FSCTL_SRV_REQUEST_RESUME_KEY, NULL, 0 /* no input */,
1358 CIFSMaxBufSize, (char **)&res_key, &ret_data_len);
1360 if (rc == -EOPNOTSUPP) {
1361 pr_warn_once("Server share %s does not support copy range\n", tcon->tree_name);
1362 goto req_res_key_exit;
1364 cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1365 goto req_res_key_exit;
1367 if (ret_data_len < sizeof(struct resume_key_req)) {
1368 cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n");
1370 goto req_res_key_exit;
1372 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1380 struct smb_rqst rqst[3];
1381 struct kvec rsp_iov[3];
1382 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1383 struct kvec qi_iov[1];
1384 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
1385 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1386 struct kvec close_iov[1];
1390 smb2_ioctl_query_info(const unsigned int xid,
1391 struct cifs_tcon *tcon,
1392 struct cifs_sb_info *cifs_sb,
1393 __le16 *path, int is_dir,
1396 struct iqi_vars *vars;
1397 struct smb_rqst *rqst;
1398 struct kvec *rsp_iov;
1399 struct cifs_ses *ses = tcon->ses;
1400 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1401 char __user *arg = (char __user *)p;
1402 struct smb_query_info qi;
1403 struct smb_query_info __user *pqi;
1405 int flags = CIFS_CP_CREATE_CLOSE_OP;
1406 struct smb2_query_info_rsp *qi_rsp = NULL;
1407 struct smb2_ioctl_rsp *io_rsp = NULL;
1408 void *buffer = NULL;
1409 int resp_buftype[3];
1410 struct cifs_open_parms oparms;
1411 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1412 struct cifs_fid fid;
1413 unsigned int size[2];
1415 int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR;
1416 void (*free_req1_func)(struct smb_rqst *r);
1418 vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
1421 rqst = &vars->rqst[0];
1422 rsp_iov = &vars->rsp_iov[0];
1424 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1426 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info))) {
1430 if (qi.output_buffer_length > 1024) {
1435 if (!ses || !server) {
1440 if (smb3_encryption_required(tcon))
1441 flags |= CIFS_TRANSFORM_REQ;
1443 if (qi.output_buffer_length) {
1444 buffer = memdup_user(arg + sizeof(struct smb_query_info), qi.output_buffer_length);
1445 if (IS_ERR(buffer)) {
1446 rc = PTR_ERR(buffer);
1452 rqst[0].rq_iov = &vars->open_iov[0];
1453 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1455 memset(&oparms, 0, sizeof(oparms));
1457 oparms.disposition = FILE_OPEN;
1458 oparms.create_options = cifs_create_options(cifs_sb, create_options);
1460 oparms.reconnect = false;
1462 if (qi.flags & PASSTHRU_FSCTL) {
1463 switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1464 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1465 oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1467 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1468 oparms.desired_access = GENERIC_ALL;
1470 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1471 oparms.desired_access = GENERIC_READ;
1473 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1474 oparms.desired_access = GENERIC_WRITE;
1477 } else if (qi.flags & PASSTHRU_SET_INFO) {
1478 oparms.desired_access = GENERIC_WRITE;
1480 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1483 rc = SMB2_open_init(tcon, server,
1484 &rqst[0], &oplock, &oparms, path);
1486 goto free_output_buffer;
1487 smb2_set_next_command(tcon, &rqst[0]);
1490 if (qi.flags & PASSTHRU_FSCTL) {
1491 /* Can eventually relax perm check since server enforces too */
1492 if (!capable(CAP_SYS_ADMIN)) {
1496 rqst[1].rq_iov = &vars->io_iov[0];
1497 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1499 rc = SMB2_ioctl_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1500 qi.info_type, buffer, qi.output_buffer_length,
1501 CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1502 MAX_SMB2_CLOSE_RESPONSE_SIZE);
1503 free_req1_func = SMB2_ioctl_free;
1504 } else if (qi.flags == PASSTHRU_SET_INFO) {
1505 /* Can eventually relax perm check since server enforces too */
1506 if (!capable(CAP_SYS_ADMIN)) {
1510 if (qi.output_buffer_length < 8) {
1514 rqst[1].rq_iov = &vars->si_iov[0];
1515 rqst[1].rq_nvec = 1;
1517 /* MS-FSCC 2.4.13 FileEndOfFileInformation */
1521 rc = SMB2_set_info_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1522 current->tgid, FILE_END_OF_FILE_INFORMATION,
1523 SMB2_O_INFO_FILE, 0, data, size);
1524 free_req1_func = SMB2_set_info_free;
1525 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1526 rqst[1].rq_iov = &vars->qi_iov[0];
1527 rqst[1].rq_nvec = 1;
1529 rc = SMB2_query_info_init(tcon, server,
1530 &rqst[1], COMPOUND_FID,
1531 COMPOUND_FID, qi.file_info_class,
1532 qi.info_type, qi.additional_information,
1533 qi.input_buffer_length,
1534 qi.output_buffer_length, buffer);
1535 free_req1_func = SMB2_query_info_free;
1536 } else { /* unknown flags */
1537 cifs_tcon_dbg(VFS, "Invalid passthru query flags: 0x%x\n",
1544 smb2_set_next_command(tcon, &rqst[1]);
1545 smb2_set_related(&rqst[1]);
1548 rqst[2].rq_iov = &vars->close_iov[0];
1549 rqst[2].rq_nvec = 1;
1551 rc = SMB2_close_init(tcon, server,
1552 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1555 smb2_set_related(&rqst[2]);
1557 rc = compound_send_recv(xid, ses, server,
1559 resp_buftype, rsp_iov);
1563 /* No need to bump num_remote_opens since handle immediately closed */
1564 if (qi.flags & PASSTHRU_FSCTL) {
1565 pqi = (struct smb_query_info __user *)arg;
1566 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1567 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1568 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1569 if (qi.input_buffer_length > 0 &&
1570 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length
1571 > rsp_iov[1].iov_len) {
1576 if (copy_to_user(&pqi->input_buffer_length,
1577 &qi.input_buffer_length,
1578 sizeof(qi.input_buffer_length))) {
1583 if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1584 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1585 qi.input_buffer_length))
1588 pqi = (struct smb_query_info __user *)arg;
1589 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1590 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1591 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1592 if (copy_to_user(&pqi->input_buffer_length,
1593 &qi.input_buffer_length,
1594 sizeof(qi.input_buffer_length))) {
1599 if (copy_to_user(pqi + 1, qi_rsp->Buffer,
1600 qi.input_buffer_length))
1605 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1606 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1607 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1608 SMB2_close_free(&rqst[2]);
1610 free_req1_func(&rqst[1]);
1612 SMB2_open_free(&rqst[0]);
1621 smb2_copychunk_range(const unsigned int xid,
1622 struct cifsFileInfo *srcfile,
1623 struct cifsFileInfo *trgtfile, u64 src_off,
1624 u64 len, u64 dest_off)
1627 unsigned int ret_data_len;
1628 struct copychunk_ioctl *pcchunk;
1629 struct copychunk_ioctl_rsp *retbuf = NULL;
1630 struct cifs_tcon *tcon;
1631 int chunks_copied = 0;
1632 bool chunk_sizes_updated = false;
1633 ssize_t bytes_written, total_bytes_written = 0;
1635 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1636 if (pcchunk == NULL)
1639 cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
1640 /* Request a key from the server to identify the source of the copy */
1641 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1642 srcfile->fid.persistent_fid,
1643 srcfile->fid.volatile_fid, pcchunk);
1645 /* Note: request_res_key sets res_key null only if rc !=0 */
1649 /* For now array only one chunk long, will make more flexible later */
1650 pcchunk->ChunkCount = cpu_to_le32(1);
1651 pcchunk->Reserved = 0;
1652 pcchunk->Reserved2 = 0;
1654 tcon = tlink_tcon(trgtfile->tlink);
1657 pcchunk->SourceOffset = cpu_to_le64(src_off);
1658 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1660 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
1662 /* Request server copy to target from src identified by key */
1665 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1666 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1667 (char *)pcchunk, sizeof(struct copychunk_ioctl),
1668 CIFSMaxBufSize, (char **)&retbuf, &ret_data_len);
1671 sizeof(struct copychunk_ioctl_rsp)) {
1672 cifs_tcon_dbg(VFS, "Invalid cchunk response size\n");
1676 if (retbuf->TotalBytesWritten == 0) {
1677 cifs_dbg(FYI, "no bytes copied\n");
1682 * Check if server claimed to write more than we asked
1684 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1685 le32_to_cpu(pcchunk->Length)) {
1686 cifs_tcon_dbg(VFS, "Invalid copy chunk response\n");
1690 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1691 cifs_tcon_dbg(VFS, "Invalid num chunks written\n");
1697 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1698 src_off += bytes_written;
1699 dest_off += bytes_written;
1700 len -= bytes_written;
1701 total_bytes_written += bytes_written;
1703 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1704 le32_to_cpu(retbuf->ChunksWritten),
1705 le32_to_cpu(retbuf->ChunkBytesWritten),
1707 } else if (rc == -EINVAL) {
1708 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1711 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1712 le32_to_cpu(retbuf->ChunksWritten),
1713 le32_to_cpu(retbuf->ChunkBytesWritten),
1714 le32_to_cpu(retbuf->TotalBytesWritten));
1717 * Check if this is the first request using these sizes,
1718 * (ie check if copy succeed once with original sizes
1719 * and check if the server gave us different sizes after
1720 * we already updated max sizes on previous request).
1721 * if not then why is the server returning an error now
1723 if ((chunks_copied != 0) || chunk_sizes_updated)
1726 /* Check that server is not asking us to grow size */
1727 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1728 tcon->max_bytes_chunk)
1729 tcon->max_bytes_chunk =
1730 le32_to_cpu(retbuf->ChunkBytesWritten);
1732 goto cchunk_out; /* server gave us bogus size */
1734 /* No need to change MaxChunks since already set to 1 */
1735 chunk_sizes_updated = true;
1746 return total_bytes_written;
1750 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1751 struct cifs_fid *fid)
1753 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1757 smb2_read_data_offset(char *buf)
1759 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1761 return rsp->DataOffset;
1765 smb2_read_data_length(char *buf, bool in_remaining)
1767 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1770 return le32_to_cpu(rsp->DataRemaining);
1772 return le32_to_cpu(rsp->DataLength);
1777 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1778 struct cifs_io_parms *parms, unsigned int *bytes_read,
1779 char **buf, int *buf_type)
1781 parms->persistent_fid = pfid->persistent_fid;
1782 parms->volatile_fid = pfid->volatile_fid;
1783 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1787 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1788 struct cifs_io_parms *parms, unsigned int *written,
1789 struct kvec *iov, unsigned long nr_segs)
1792 parms->persistent_fid = pfid->persistent_fid;
1793 parms->volatile_fid = pfid->volatile_fid;
1794 return SMB2_write(xid, parms, written, iov, nr_segs);
1797 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1798 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1799 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1801 struct cifsInodeInfo *cifsi;
1804 cifsi = CIFS_I(inode);
1806 /* if file already sparse don't bother setting sparse again */
1807 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1808 return true; /* already sparse */
1810 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1811 return true; /* already not sparse */
1814 * Can't check for sparse support on share the usual way via the
1815 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1816 * since Samba server doesn't set the flag on the share, yet
1817 * supports the set sparse FSCTL and returns sparse correctly
1818 * in the file attributes. If we fail setting sparse though we
1819 * mark that server does not support sparse files for this share
1820 * to avoid repeatedly sending the unsupported fsctl to server
1821 * if the file is repeatedly extended.
1823 if (tcon->broken_sparse_sup)
1826 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1827 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1828 &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
1830 tcon->broken_sparse_sup = true;
1831 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1836 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1838 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1844 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1845 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1847 __le64 eof = cpu_to_le64(size);
1848 struct inode *inode;
1851 * If extending file more than one page make sparse. Many Linux fs
1852 * make files sparse by default when extending via ftruncate
1854 inode = d_inode(cfile->dentry);
1856 if (!set_alloc && (size > inode->i_size + 8192)) {
1857 __u8 set_sparse = 1;
1859 /* whether set sparse succeeds or not, extend the file */
1860 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1863 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1864 cfile->fid.volatile_fid, cfile->pid, &eof);
1868 smb2_duplicate_extents(const unsigned int xid,
1869 struct cifsFileInfo *srcfile,
1870 struct cifsFileInfo *trgtfile, u64 src_off,
1871 u64 len, u64 dest_off)
1874 unsigned int ret_data_len;
1875 struct inode *inode;
1876 struct duplicate_extents_to_file dup_ext_buf;
1877 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1879 /* server fileays advertise duplicate extent support with this flag */
1880 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1881 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1884 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1885 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1886 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1887 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1888 dup_ext_buf.ByteCount = cpu_to_le64(len);
1889 cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
1890 src_off, dest_off, len);
1892 inode = d_inode(trgtfile->dentry);
1893 if (inode->i_size < dest_off + len) {
1894 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1896 goto duplicate_extents_out;
1899 * Although also could set plausible allocation size (i_blocks)
1900 * here in addition to setting the file size, in reflink
1901 * it is likely that the target file is sparse. Its allocation
1902 * size will be queried on next revalidate, but it is important
1903 * to make sure that file's cached size is updated immediately
1905 cifs_setsize(inode, dest_off + len);
1907 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1908 trgtfile->fid.volatile_fid,
1909 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1910 (char *)&dup_ext_buf,
1911 sizeof(struct duplicate_extents_to_file),
1912 CIFSMaxBufSize, NULL,
1915 if (ret_data_len > 0)
1916 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
1918 duplicate_extents_out:
1923 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1924 struct cifsFileInfo *cfile)
1926 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1927 cfile->fid.volatile_fid);
1931 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
1932 struct cifsFileInfo *cfile)
1934 struct fsctl_set_integrity_information_req integr_info;
1935 unsigned int ret_data_len;
1937 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
1938 integr_info.Flags = 0;
1939 integr_info.Reserved = 0;
1941 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1942 cfile->fid.volatile_fid,
1943 FSCTL_SET_INTEGRITY_INFORMATION,
1944 (char *)&integr_info,
1945 sizeof(struct fsctl_set_integrity_information_req),
1946 CIFSMaxBufSize, NULL,
1951 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
1952 #define GMT_TOKEN_SIZE 50
1954 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
1957 * Input buffer contains (empty) struct smb_snapshot array with size filled in
1958 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
1961 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
1962 struct cifsFileInfo *cfile, void __user *ioc_buf)
1964 char *retbuf = NULL;
1965 unsigned int ret_data_len = 0;
1967 u32 max_response_size;
1968 struct smb_snapshot_array snapshot_in;
1971 * On the first query to enumerate the list of snapshots available
1972 * for this volume the buffer begins with 0 (number of snapshots
1973 * which can be returned is zero since at that point we do not know
1974 * how big the buffer needs to be). On the second query,
1975 * it (ret_data_len) is set to number of snapshots so we can
1976 * know to set the maximum response size larger (see below).
1978 if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
1982 * Note that for snapshot queries that servers like Azure expect that
1983 * the first query be minimal size (and just used to get the number/size
1984 * of previous versions) so response size must be specified as EXACTLY
1985 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
1988 if (ret_data_len == 0)
1989 max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
1991 max_response_size = CIFSMaxBufSize;
1993 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1994 cfile->fid.volatile_fid,
1995 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
1996 NULL, 0 /* no input data */, max_response_size,
1999 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
2004 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
2006 if (copy_from_user(&snapshot_in, ioc_buf,
2007 sizeof(struct smb_snapshot_array))) {
2014 * Check for min size, ie not large enough to fit even one GMT
2015 * token (snapshot). On the first ioctl some users may pass in
2016 * smaller size (or zero) to simply get the size of the array
2017 * so the user space caller can allocate sufficient memory
2018 * and retry the ioctl again with larger array size sufficient
2019 * to hold all of the snapshot GMT tokens on the second try.
2021 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
2022 ret_data_len = sizeof(struct smb_snapshot_array);
2025 * We return struct SRV_SNAPSHOT_ARRAY, followed by
2026 * the snapshot array (of 50 byte GMT tokens) each
2027 * representing an available previous version of the data
2029 if (ret_data_len > (snapshot_in.snapshot_array_size +
2030 sizeof(struct smb_snapshot_array)))
2031 ret_data_len = snapshot_in.snapshot_array_size +
2032 sizeof(struct smb_snapshot_array);
2034 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
2045 smb3_notify(const unsigned int xid, struct file *pfile,
2046 void __user *ioc_buf, bool return_changes)
2048 struct smb3_notify_info notify;
2049 struct smb3_notify_info __user *pnotify_buf;
2050 struct dentry *dentry = pfile->f_path.dentry;
2051 struct inode *inode = file_inode(pfile);
2052 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2053 struct cifs_open_parms oparms;
2054 struct cifs_fid fid;
2055 struct cifs_tcon *tcon;
2056 const unsigned char *path;
2057 char *returned_ioctl_info = NULL;
2058 void *page = alloc_dentry_path();
2059 __le16 *utf16_path = NULL;
2060 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2064 path = build_path_from_dentry(dentry, page);
2070 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2071 if (utf16_path == NULL) {
2076 if (return_changes) {
2077 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify_info))) {
2082 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify))) {
2086 notify.data_len = 0;
2089 tcon = cifs_sb_master_tcon(cifs_sb);
2091 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
2092 oparms.disposition = FILE_OPEN;
2093 oparms.create_options = cifs_create_options(cifs_sb, 0);
2095 oparms.reconnect = false;
2097 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
2102 rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid,
2103 notify.watch_tree, notify.completion_filter,
2104 notify.data_len, &returned_ioctl_info, &ret_len);
2106 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2108 cifs_dbg(FYI, "change notify for path %s rc %d\n", path, rc);
2109 if (return_changes && (ret_len > 0) && (notify.data_len > 0)) {
2110 if (ret_len > notify.data_len)
2111 ret_len = notify.data_len;
2112 pnotify_buf = (struct smb3_notify_info __user *)ioc_buf;
2113 if (copy_to_user(pnotify_buf->notify_data, returned_ioctl_info, ret_len))
2115 else if (copy_to_user(&pnotify_buf->data_len, &ret_len, sizeof(ret_len)))
2118 kfree(returned_ioctl_info);
2120 free_dentry_path(page);
2126 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
2127 const char *path, struct cifs_sb_info *cifs_sb,
2128 struct cifs_fid *fid, __u16 search_flags,
2129 struct cifs_search_info *srch_inf)
2132 struct smb_rqst rqst[2];
2133 struct kvec rsp_iov[2];
2134 int resp_buftype[2];
2135 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2136 struct kvec qd_iov[SMB2_QUERY_DIRECTORY_IOV_SIZE];
2138 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2139 struct cifs_open_parms oparms;
2140 struct smb2_query_directory_rsp *qd_rsp = NULL;
2141 struct smb2_create_rsp *op_rsp = NULL;
2142 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2143 int retry_count = 0;
2145 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2149 if (smb3_encryption_required(tcon))
2150 flags |= CIFS_TRANSFORM_REQ;
2152 memset(rqst, 0, sizeof(rqst));
2153 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
2154 memset(rsp_iov, 0, sizeof(rsp_iov));
2157 memset(&open_iov, 0, sizeof(open_iov));
2158 rqst[0].rq_iov = open_iov;
2159 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2162 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
2163 oparms.disposition = FILE_OPEN;
2164 oparms.create_options = cifs_create_options(cifs_sb, 0);
2166 oparms.reconnect = false;
2168 rc = SMB2_open_init(tcon, server,
2169 &rqst[0], &oplock, &oparms, utf16_path);
2172 smb2_set_next_command(tcon, &rqst[0]);
2174 /* Query directory */
2175 srch_inf->entries_in_buffer = 0;
2176 srch_inf->index_of_last_entry = 2;
2178 memset(&qd_iov, 0, sizeof(qd_iov));
2179 rqst[1].rq_iov = qd_iov;
2180 rqst[1].rq_nvec = SMB2_QUERY_DIRECTORY_IOV_SIZE;
2182 rc = SMB2_query_directory_init(xid, tcon, server,
2184 COMPOUND_FID, COMPOUND_FID,
2185 0, srch_inf->info_level);
2189 smb2_set_related(&rqst[1]);
2192 rc = compound_send_recv(xid, tcon->ses, server,
2194 resp_buftype, rsp_iov);
2196 if (rc == -EAGAIN && retry_count++ < 10)
2199 /* If the open failed there is nothing to do */
2200 op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
2201 if (op_rsp == NULL || op_rsp->hdr.Status != STATUS_SUCCESS) {
2202 cifs_dbg(FYI, "query_dir_first: open failed rc=%d\n", rc);
2205 fid->persistent_fid = op_rsp->PersistentFileId;
2206 fid->volatile_fid = op_rsp->VolatileFileId;
2208 /* Anything else than ENODATA means a genuine error */
2209 if (rc && rc != -ENODATA) {
2210 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2211 cifs_dbg(FYI, "query_dir_first: query directory failed rc=%d\n", rc);
2212 trace_smb3_query_dir_err(xid, fid->persistent_fid,
2213 tcon->tid, tcon->ses->Suid, 0, 0, rc);
2217 atomic_inc(&tcon->num_remote_opens);
2219 qd_rsp = (struct smb2_query_directory_rsp *)rsp_iov[1].iov_base;
2220 if (qd_rsp->hdr.Status == STATUS_NO_MORE_FILES) {
2221 trace_smb3_query_dir_done(xid, fid->persistent_fid,
2222 tcon->tid, tcon->ses->Suid, 0, 0);
2223 srch_inf->endOfSearch = true;
2228 rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1],
2231 trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid,
2232 tcon->ses->Suid, 0, 0, rc);
2235 resp_buftype[1] = CIFS_NO_BUFFER;
2237 trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid,
2238 tcon->ses->Suid, 0, srch_inf->entries_in_buffer);
2242 SMB2_open_free(&rqst[0]);
2243 SMB2_query_directory_free(&rqst[1]);
2244 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2245 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2250 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
2251 struct cifs_fid *fid, __u16 search_flags,
2252 struct cifs_search_info *srch_inf)
2254 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
2255 fid->volatile_fid, 0, srch_inf);
2259 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
2260 struct cifs_fid *fid)
2262 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2266 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2267 * the number of credits and return true. Otherwise - return false.
2270 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
2272 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2273 int scredits, in_flight;
2275 if (shdr->Status != STATUS_PENDING)
2278 if (shdr->CreditRequest) {
2279 spin_lock(&server->req_lock);
2280 server->credits += le16_to_cpu(shdr->CreditRequest);
2281 scredits = server->credits;
2282 in_flight = server->in_flight;
2283 spin_unlock(&server->req_lock);
2284 wake_up(&server->request_q);
2286 trace_smb3_pend_credits(server->CurrentMid,
2287 server->conn_id, server->hostname, scredits,
2288 le16_to_cpu(shdr->CreditRequest), in_flight);
2289 cifs_dbg(FYI, "%s: status pending add %u credits total=%d\n",
2290 __func__, le16_to_cpu(shdr->CreditRequest), scredits);
2297 smb2_is_session_expired(char *buf)
2299 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2301 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
2302 shdr->Status != STATUS_USER_SESSION_DELETED)
2305 trace_smb3_ses_expired(le32_to_cpu(shdr->Id.SyncId.TreeId),
2306 le64_to_cpu(shdr->SessionId),
2307 le16_to_cpu(shdr->Command),
2308 le64_to_cpu(shdr->MessageId));
2309 cifs_dbg(FYI, "Session expired or deleted\n");
2315 smb2_is_status_io_timeout(char *buf)
2317 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2319 if (shdr->Status == STATUS_IO_TIMEOUT)
2326 smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server)
2328 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2329 struct TCP_Server_Info *pserver;
2330 struct cifs_ses *ses;
2331 struct cifs_tcon *tcon;
2333 if (shdr->Status != STATUS_NETWORK_NAME_DELETED)
2336 /* If server is a channel, select the primary channel */
2337 pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
2339 spin_lock(&cifs_tcp_ses_lock);
2340 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
2341 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
2342 if (tcon->tid == le32_to_cpu(shdr->Id.SyncId.TreeId)) {
2343 spin_lock(&tcon->tc_lock);
2344 tcon->need_reconnect = true;
2345 spin_unlock(&tcon->tc_lock);
2346 spin_unlock(&cifs_tcp_ses_lock);
2347 pr_warn_once("Server share %s deleted.\n",
2353 spin_unlock(&cifs_tcp_ses_lock);
2357 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
2358 struct cifsInodeInfo *cinode)
2360 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
2361 return SMB2_lease_break(0, tcon, cinode->lease_key,
2362 smb2_get_lease_state(cinode));
2364 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
2366 CIFS_CACHE_READ(cinode) ? 1 : 0);
2370 smb2_set_related(struct smb_rqst *rqst)
2372 struct smb2_hdr *shdr;
2374 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2376 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2379 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2382 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
2385 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
2387 struct smb2_hdr *shdr;
2388 struct cifs_ses *ses = tcon->ses;
2389 struct TCP_Server_Info *server = ses->server;
2390 unsigned long len = smb_rqst_len(server, rqst);
2393 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2395 cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2399 /* SMB headers in a compound are 8 byte aligned. */
2401 /* No padding needed */
2405 num_padding = 8 - (len & 7);
2406 if (!smb3_encryption_required(tcon)) {
2408 * If we do not have encryption then we can just add an extra
2409 * iov for the padding.
2411 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2412 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2417 * We can not add a small padding iov for the encryption case
2418 * because the encryption framework can not handle the padding
2420 * We have to flatten this into a single buffer and add
2421 * the padding to it.
2423 for (i = 1; i < rqst->rq_nvec; i++) {
2424 memcpy(rqst->rq_iov[0].iov_base +
2425 rqst->rq_iov[0].iov_len,
2426 rqst->rq_iov[i].iov_base,
2427 rqst->rq_iov[i].iov_len);
2428 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2430 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2432 rqst->rq_iov[0].iov_len += num_padding;
2438 shdr->NextCommand = cpu_to_le32(len);
2442 * Passes the query info response back to the caller on success.
2443 * Caller need to free this with free_rsp_buf().
2446 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2447 const char *path, u32 desired_access,
2448 u32 class, u32 type, u32 output_len,
2449 struct kvec *rsp, int *buftype,
2450 struct cifs_sb_info *cifs_sb)
2452 struct cifs_ses *ses = tcon->ses;
2453 struct TCP_Server_Info *server = cifs_pick_channel(ses);
2454 int flags = CIFS_CP_CREATE_CLOSE_OP;
2455 struct smb_rqst rqst[3];
2456 int resp_buftype[3];
2457 struct kvec rsp_iov[3];
2458 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2459 struct kvec qi_iov[1];
2460 struct kvec close_iov[1];
2461 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2462 struct cifs_open_parms oparms;
2463 struct cifs_fid fid;
2466 struct cached_fid *cfid = NULL;
2470 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2474 if (smb3_encryption_required(tcon))
2475 flags |= CIFS_TRANSFORM_REQ;
2477 memset(rqst, 0, sizeof(rqst));
2478 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2479 memset(rsp_iov, 0, sizeof(rsp_iov));
2482 * We can only call this for things we know are directories.
2484 if (!strcmp(path, ""))
2485 open_cached_dir(xid, tcon, path, cifs_sb, false,
2486 &cfid); /* cfid null if open dir failed */
2488 memset(&open_iov, 0, sizeof(open_iov));
2489 rqst[0].rq_iov = open_iov;
2490 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2493 oparms.desired_access = desired_access;
2494 oparms.disposition = FILE_OPEN;
2495 oparms.create_options = cifs_create_options(cifs_sb, 0);
2497 oparms.reconnect = false;
2499 rc = SMB2_open_init(tcon, server,
2500 &rqst[0], &oplock, &oparms, utf16_path);
2503 smb2_set_next_command(tcon, &rqst[0]);
2505 memset(&qi_iov, 0, sizeof(qi_iov));
2506 rqst[1].rq_iov = qi_iov;
2507 rqst[1].rq_nvec = 1;
2510 rc = SMB2_query_info_init(tcon, server,
2512 cfid->fid.persistent_fid,
2513 cfid->fid.volatile_fid,
2518 rc = SMB2_query_info_init(tcon, server,
2529 smb2_set_next_command(tcon, &rqst[1]);
2530 smb2_set_related(&rqst[1]);
2533 memset(&close_iov, 0, sizeof(close_iov));
2534 rqst[2].rq_iov = close_iov;
2535 rqst[2].rq_nvec = 1;
2537 rc = SMB2_close_init(tcon, server,
2538 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2541 smb2_set_related(&rqst[2]);
2544 rc = compound_send_recv(xid, ses, server,
2546 &resp_buftype[1], &rsp_iov[1]);
2548 rc = compound_send_recv(xid, ses, server,
2550 resp_buftype, rsp_iov);
2553 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2554 if (rc == -EREMCHG) {
2555 tcon->need_reconnect = true;
2556 pr_warn_once("server share %s deleted\n",
2562 *buftype = resp_buftype[1];
2566 SMB2_open_free(&rqst[0]);
2567 SMB2_query_info_free(&rqst[1]);
2568 SMB2_close_free(&rqst[2]);
2569 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2570 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2572 close_cached_dir(cfid);
2577 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2578 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2580 struct smb2_query_info_rsp *rsp;
2581 struct smb2_fs_full_size_info *info = NULL;
2582 struct kvec rsp_iov = {NULL, 0};
2583 int buftype = CIFS_NO_BUFFER;
2587 rc = smb2_query_info_compound(xid, tcon, "",
2588 FILE_READ_ATTRIBUTES,
2589 FS_FULL_SIZE_INFORMATION,
2590 SMB2_O_INFO_FILESYSTEM,
2591 sizeof(struct smb2_fs_full_size_info),
2592 &rsp_iov, &buftype, cifs_sb);
2596 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2597 buf->f_type = SMB2_SUPER_MAGIC;
2598 info = (struct smb2_fs_full_size_info *)(
2599 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2600 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2601 le32_to_cpu(rsp->OutputBufferLength),
2603 sizeof(struct smb2_fs_full_size_info));
2605 smb2_copy_fs_info_to_kstatfs(info, buf);
2608 free_rsp_buf(buftype, rsp_iov.iov_base);
2613 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2614 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2617 __le16 srch_path = 0; /* Null - open root of share */
2618 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2619 struct cifs_open_parms oparms;
2620 struct cifs_fid fid;
2622 if (!tcon->posix_extensions)
2623 return smb2_queryfs(xid, tcon, cifs_sb, buf);
2626 oparms.desired_access = FILE_READ_ATTRIBUTES;
2627 oparms.disposition = FILE_OPEN;
2628 oparms.create_options = cifs_create_options(cifs_sb, 0);
2630 oparms.reconnect = false;
2632 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
2637 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2638 fid.volatile_fid, buf);
2639 buf->f_type = SMB2_SUPER_MAGIC;
2640 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2645 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2647 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2648 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2652 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2653 __u64 length, __u32 type, int lock, int unlock, bool wait)
2655 if (unlock && !lock)
2656 type = SMB2_LOCKFLAG_UNLOCK;
2657 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2658 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2659 current->tgid, length, offset, type, wait);
2663 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2665 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2669 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2671 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2675 smb2_new_lease_key(struct cifs_fid *fid)
2677 generate_random_uuid(fid->lease_key);
2681 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2682 const char *search_name,
2683 struct dfs_info3_param **target_nodes,
2684 unsigned int *num_of_nodes,
2685 const struct nls_table *nls_codepage, int remap)
2688 __le16 *utf16_path = NULL;
2689 int utf16_path_len = 0;
2690 struct cifs_tcon *tcon;
2691 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2692 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2693 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2694 int retry_count = 0;
2696 cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name);
2699 * Try to use the IPC tcon, otherwise just use any
2701 tcon = ses->tcon_ipc;
2703 spin_lock(&cifs_tcp_ses_lock);
2704 tcon = list_first_entry_or_null(&ses->tcon_list,
2709 spin_unlock(&cifs_tcp_ses_lock);
2713 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2719 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2721 nls_codepage, remap);
2727 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2728 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2734 /* Highest DFS referral version understood */
2735 dfs_req->MaxReferralLevel = DFS_VERSION;
2737 /* Path to resolve in an UTF-16 null-terminated string */
2738 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2741 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2742 FSCTL_DFS_GET_REFERRALS,
2743 (char *)dfs_req, dfs_req_size, CIFSMaxBufSize,
2744 (char **)&dfs_rsp, &dfs_rsp_size);
2745 if (!is_retryable_error(rc))
2747 usleep_range(512, 2048);
2748 } while (++retry_count < 5);
2751 if (!is_retryable_error(rc) && rc != -ENOENT && rc != -EOPNOTSUPP)
2752 cifs_tcon_dbg(VFS, "%s: ioctl error: rc=%d\n", __func__, rc);
2756 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
2757 num_of_nodes, target_nodes,
2758 nls_codepage, remap, search_name,
2759 true /* is_unicode */);
2761 cifs_tcon_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc);
2766 if (tcon && !tcon->ipc) {
2767 /* ipc tcons are not refcounted */
2768 spin_lock(&cifs_tcp_ses_lock);
2770 /* tc_count can never go negative */
2771 WARN_ON(tcon->tc_count < 0);
2772 spin_unlock(&cifs_tcp_ses_lock);
2781 parse_reparse_posix(struct reparse_posix_data *symlink_buf,
2782 u32 plen, char **target_path,
2783 struct cifs_sb_info *cifs_sb)
2787 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
2788 len = le16_to_cpu(symlink_buf->ReparseDataLength);
2790 if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
2791 cifs_dbg(VFS, "%lld not a supported symlink type\n",
2792 le64_to_cpu(symlink_buf->InodeType));
2796 *target_path = cifs_strndup_from_utf16(
2797 symlink_buf->PathBuffer,
2798 len, true, cifs_sb->local_nls);
2799 if (!(*target_path))
2802 convert_delimiter(*target_path, '/');
2803 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2809 parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
2810 u32 plen, char **target_path,
2811 struct cifs_sb_info *cifs_sb)
2813 unsigned int sub_len;
2814 unsigned int sub_offset;
2816 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */
2818 sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset);
2819 sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength);
2820 if (sub_offset + 20 > plen ||
2821 sub_offset + sub_len + 20 > plen) {
2822 cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
2826 *target_path = cifs_strndup_from_utf16(
2827 symlink_buf->PathBuffer + sub_offset,
2828 sub_len, true, cifs_sb->local_nls);
2829 if (!(*target_path))
2832 convert_delimiter(*target_path, '/');
2833 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2839 parse_reparse_point(struct reparse_data_buffer *buf,
2840 u32 plen, char **target_path,
2841 struct cifs_sb_info *cifs_sb)
2843 if (plen < sizeof(struct reparse_data_buffer)) {
2844 cifs_dbg(VFS, "reparse buffer is too small. Must be at least 8 bytes but was %d\n",
2849 if (plen < le16_to_cpu(buf->ReparseDataLength) +
2850 sizeof(struct reparse_data_buffer)) {
2851 cifs_dbg(VFS, "srv returned invalid reparse buf length: %d\n",
2856 /* See MS-FSCC 2.1.2 */
2857 switch (le32_to_cpu(buf->ReparseTag)) {
2858 case IO_REPARSE_TAG_NFS:
2859 return parse_reparse_posix(
2860 (struct reparse_posix_data *)buf,
2861 plen, target_path, cifs_sb);
2862 case IO_REPARSE_TAG_SYMLINK:
2863 return parse_reparse_symlink(
2864 (struct reparse_symlink_data_buffer *)buf,
2865 plen, target_path, cifs_sb);
2867 cifs_dbg(VFS, "srv returned unknown symlink buffer tag:0x%08x\n",
2868 le32_to_cpu(buf->ReparseTag));
2874 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
2875 struct cifs_sb_info *cifs_sb, const char *full_path,
2876 char **target_path, bool is_reparse_point)
2879 __le16 *utf16_path = NULL;
2880 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2881 struct cifs_open_parms oparms;
2882 struct cifs_fid fid;
2883 struct kvec err_iov = {NULL, 0};
2884 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2885 int flags = CIFS_CP_CREATE_CLOSE_OP;
2886 struct smb_rqst rqst[3];
2887 int resp_buftype[3];
2888 struct kvec rsp_iov[3];
2889 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2890 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2891 struct kvec close_iov[1];
2892 struct smb2_create_rsp *create_rsp;
2893 struct smb2_ioctl_rsp *ioctl_rsp;
2894 struct reparse_data_buffer *reparse_buf;
2895 int create_options = is_reparse_point ? OPEN_REPARSE_POINT : 0;
2898 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2900 *target_path = NULL;
2902 if (smb3_encryption_required(tcon))
2903 flags |= CIFS_TRANSFORM_REQ;
2905 memset(rqst, 0, sizeof(rqst));
2906 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2907 memset(rsp_iov, 0, sizeof(rsp_iov));
2909 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
2914 memset(&open_iov, 0, sizeof(open_iov));
2915 rqst[0].rq_iov = open_iov;
2916 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2918 memset(&oparms, 0, sizeof(oparms));
2920 oparms.desired_access = FILE_READ_ATTRIBUTES;
2921 oparms.disposition = FILE_OPEN;
2922 oparms.create_options = cifs_create_options(cifs_sb, create_options);
2924 oparms.reconnect = false;
2926 rc = SMB2_open_init(tcon, server,
2927 &rqst[0], &oplock, &oparms, utf16_path);
2930 smb2_set_next_command(tcon, &rqst[0]);
2934 memset(&io_iov, 0, sizeof(io_iov));
2935 rqst[1].rq_iov = io_iov;
2936 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
2938 rc = SMB2_ioctl_init(tcon, server,
2939 &rqst[1], fid.persistent_fid,
2940 fid.volatile_fid, FSCTL_GET_REPARSE_POINT, NULL, 0,
2942 MAX_SMB2_CREATE_RESPONSE_SIZE -
2943 MAX_SMB2_CLOSE_RESPONSE_SIZE);
2947 smb2_set_next_command(tcon, &rqst[1]);
2948 smb2_set_related(&rqst[1]);
2952 memset(&close_iov, 0, sizeof(close_iov));
2953 rqst[2].rq_iov = close_iov;
2954 rqst[2].rq_nvec = 1;
2956 rc = SMB2_close_init(tcon, server,
2957 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2961 smb2_set_related(&rqst[2]);
2963 rc = compound_send_recv(xid, tcon->ses, server,
2965 resp_buftype, rsp_iov);
2967 create_rsp = rsp_iov[0].iov_base;
2968 if (create_rsp && create_rsp->hdr.Status)
2969 err_iov = rsp_iov[0];
2970 ioctl_rsp = rsp_iov[1].iov_base;
2973 * Open was successful and we got an ioctl response.
2975 if ((rc == 0) && (is_reparse_point)) {
2976 /* See MS-FSCC 2.3.23 */
2978 reparse_buf = (struct reparse_data_buffer *)
2979 ((char *)ioctl_rsp +
2980 le32_to_cpu(ioctl_rsp->OutputOffset));
2981 plen = le32_to_cpu(ioctl_rsp->OutputCount);
2983 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
2984 rsp_iov[1].iov_len) {
2985 cifs_tcon_dbg(VFS, "srv returned invalid ioctl len: %d\n",
2991 rc = parse_reparse_point(reparse_buf, plen, target_path,
2996 if (!rc || !err_iov.iov_base) {
3001 rc = smb2_parse_symlink_response(cifs_sb, &err_iov, target_path);
3004 cifs_dbg(FYI, "query symlink rc %d\n", rc);
3006 SMB2_open_free(&rqst[0]);
3007 SMB2_ioctl_free(&rqst[1]);
3008 SMB2_close_free(&rqst[2]);
3009 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3010 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3011 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3016 smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
3017 struct cifs_sb_info *cifs_sb, const char *full_path,
3021 __le16 *utf16_path = NULL;
3022 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3023 struct cifs_open_parms oparms;
3024 struct cifs_fid fid;
3025 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
3026 int flags = CIFS_CP_CREATE_CLOSE_OP;
3027 struct smb_rqst rqst[3];
3028 int resp_buftype[3];
3029 struct kvec rsp_iov[3];
3030 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
3031 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
3032 struct kvec close_iov[1];
3033 struct smb2_ioctl_rsp *ioctl_rsp;
3034 struct reparse_data_buffer *reparse_buf;
3037 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
3039 if (smb3_encryption_required(tcon))
3040 flags |= CIFS_TRANSFORM_REQ;
3042 memset(rqst, 0, sizeof(rqst));
3043 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
3044 memset(rsp_iov, 0, sizeof(rsp_iov));
3046 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
3051 * setup smb2open - TODO add optimization to call cifs_get_readable_path
3052 * to see if there is a handle already open that we can use
3054 memset(&open_iov, 0, sizeof(open_iov));
3055 rqst[0].rq_iov = open_iov;
3056 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
3058 memset(&oparms, 0, sizeof(oparms));
3060 oparms.desired_access = FILE_READ_ATTRIBUTES;
3061 oparms.disposition = FILE_OPEN;
3062 oparms.create_options = cifs_create_options(cifs_sb, OPEN_REPARSE_POINT);
3064 oparms.reconnect = false;
3066 rc = SMB2_open_init(tcon, server,
3067 &rqst[0], &oplock, &oparms, utf16_path);
3070 smb2_set_next_command(tcon, &rqst[0]);
3074 memset(&io_iov, 0, sizeof(io_iov));
3075 rqst[1].rq_iov = io_iov;
3076 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3078 rc = SMB2_ioctl_init(tcon, server,
3079 &rqst[1], COMPOUND_FID,
3080 COMPOUND_FID, FSCTL_GET_REPARSE_POINT, NULL, 0,
3082 MAX_SMB2_CREATE_RESPONSE_SIZE -
3083 MAX_SMB2_CLOSE_RESPONSE_SIZE);
3087 smb2_set_next_command(tcon, &rqst[1]);
3088 smb2_set_related(&rqst[1]);
3092 memset(&close_iov, 0, sizeof(close_iov));
3093 rqst[2].rq_iov = close_iov;
3094 rqst[2].rq_nvec = 1;
3096 rc = SMB2_close_init(tcon, server,
3097 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3101 smb2_set_related(&rqst[2]);
3103 rc = compound_send_recv(xid, tcon->ses, server,
3105 resp_buftype, rsp_iov);
3107 ioctl_rsp = rsp_iov[1].iov_base;
3110 * Open was successful and we got an ioctl response.
3113 /* See MS-FSCC 2.3.23 */
3115 reparse_buf = (struct reparse_data_buffer *)
3116 ((char *)ioctl_rsp +
3117 le32_to_cpu(ioctl_rsp->OutputOffset));
3118 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3120 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3121 rsp_iov[1].iov_len) {
3122 cifs_tcon_dbg(FYI, "srv returned invalid ioctl len: %d\n",
3127 *tag = le32_to_cpu(reparse_buf->ReparseTag);
3132 SMB2_open_free(&rqst[0]);
3133 SMB2_ioctl_free(&rqst[1]);
3134 SMB2_close_free(&rqst[2]);
3135 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3136 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3137 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3141 static struct cifs_ntsd *
3142 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
3143 const struct cifs_fid *cifsfid, u32 *pacllen, u32 info)
3145 struct cifs_ntsd *pntsd = NULL;
3147 int rc = -EOPNOTSUPP;
3148 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3151 return ERR_CAST(tlink);
3154 cifs_dbg(FYI, "trying to get acl\n");
3156 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
3157 cifsfid->volatile_fid, (void **)&pntsd, pacllen,
3161 cifs_put_tlink(tlink);
3163 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3170 static struct cifs_ntsd *
3171 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
3172 const char *path, u32 *pacllen, u32 info)
3174 struct cifs_ntsd *pntsd = NULL;
3175 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3178 struct cifs_tcon *tcon;
3179 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3180 struct cifs_fid fid;
3181 struct cifs_open_parms oparms;
3184 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
3186 return ERR_CAST(tlink);
3188 tcon = tlink_tcon(tlink);
3191 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3199 oparms.desired_access = READ_CONTROL;
3200 oparms.disposition = FILE_OPEN;
3202 * When querying an ACL, even if the file is a symlink we want to open
3203 * the source not the target, and so the protocol requires that the
3204 * client specify this flag when opening a reparse point
3206 oparms.create_options = cifs_create_options(cifs_sb, 0) | OPEN_REPARSE_POINT;
3208 oparms.reconnect = false;
3210 if (info & SACL_SECINFO)
3211 oparms.desired_access |= SYSTEM_SECURITY;
3213 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
3217 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3218 fid.volatile_fid, (void **)&pntsd, pacllen,
3220 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3223 cifs_put_tlink(tlink);
3226 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3233 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
3234 struct inode *inode, const char *path, int aclflag)
3236 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3238 int rc, access_flags = 0;
3239 struct cifs_tcon *tcon;
3240 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
3241 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3242 struct cifs_fid fid;
3243 struct cifs_open_parms oparms;
3246 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
3248 return PTR_ERR(tlink);
3250 tcon = tlink_tcon(tlink);
3253 if (aclflag & CIFS_ACL_OWNER || aclflag & CIFS_ACL_GROUP)
3254 access_flags |= WRITE_OWNER;
3255 if (aclflag & CIFS_ACL_SACL)
3256 access_flags |= SYSTEM_SECURITY;
3257 if (aclflag & CIFS_ACL_DACL)
3258 access_flags |= WRITE_DAC;
3260 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3268 oparms.desired_access = access_flags;
3269 oparms.create_options = cifs_create_options(cifs_sb, 0);
3270 oparms.disposition = FILE_OPEN;
3273 oparms.reconnect = false;
3275 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
3279 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3280 fid.volatile_fid, pnntsd, acllen, aclflag);
3281 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3284 cifs_put_tlink(tlink);
3289 /* Retrieve an ACL from the server */
3290 static struct cifs_ntsd *
3291 get_smb2_acl(struct cifs_sb_info *cifs_sb,
3292 struct inode *inode, const char *path,
3293 u32 *pacllen, u32 info)
3295 struct cifs_ntsd *pntsd = NULL;
3296 struct cifsFileInfo *open_file = NULL;
3298 if (inode && !(info & SACL_SECINFO))
3299 open_file = find_readable_file(CIFS_I(inode), true);
3300 if (!open_file || (info & SACL_SECINFO))
3301 return get_smb2_acl_by_path(cifs_sb, path, pacllen, info);
3303 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen, info);
3304 cifsFileInfo_put(open_file);
3308 static long smb3_zero_data(struct file *file, struct cifs_tcon *tcon,
3309 loff_t offset, loff_t len, unsigned int xid)
3311 struct cifsFileInfo *cfile = file->private_data;
3312 struct file_zero_data_information fsctl_buf;
3314 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3316 fsctl_buf.FileOffset = cpu_to_le64(offset);
3317 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3319 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3320 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3322 sizeof(struct file_zero_data_information),
3326 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3327 loff_t offset, loff_t len, bool keep_size)
3329 struct cifs_ses *ses = tcon->ses;
3330 struct inode *inode = file_inode(file);
3331 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3332 struct cifsFileInfo *cfile = file->private_data;
3339 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3340 ses->Suid, offset, len);
3343 filemap_invalidate_lock(inode->i_mapping);
3346 * We zero the range through ioctl, so we need remove the page caches
3347 * first, otherwise the data may be inconsistent with the server.
3349 truncate_pagecache_range(inode, offset, offset + len - 1);
3351 /* if file not oplocked can't be sure whether asking to extend size */
3353 if (keep_size == false && !CIFS_CACHE_READ(cifsi))
3354 goto zero_range_exit;
3356 rc = smb3_zero_data(file, tcon, offset, len, xid);
3358 goto zero_range_exit;
3361 * do we also need to change the size of the file?
3363 if (keep_size == false && i_size_read(inode) < offset + len) {
3364 eof = cpu_to_le64(offset + len);
3365 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3366 cfile->fid.volatile_fid, cfile->pid, &eof);
3370 filemap_invalidate_unlock(inode->i_mapping);
3371 inode_unlock(inode);
3374 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
3375 ses->Suid, offset, len, rc);
3377 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
3378 ses->Suid, offset, len);
3382 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
3383 loff_t offset, loff_t len)
3385 struct inode *inode = file_inode(file);
3386 struct cifsFileInfo *cfile = file->private_data;
3387 struct file_zero_data_information fsctl_buf;
3390 __u8 set_sparse = 1;
3395 /* Need to make file sparse, if not already, before freeing range. */
3396 /* Consider adding equivalent for compressed since it could also work */
3397 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
3402 filemap_invalidate_lock(inode->i_mapping);
3404 * We implement the punch hole through ioctl, so we need remove the page
3405 * caches first, otherwise the data may be inconsistent with the server.
3407 truncate_pagecache_range(inode, offset, offset + len - 1);
3409 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3411 fsctl_buf.FileOffset = cpu_to_le64(offset);
3412 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3414 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3415 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3417 sizeof(struct file_zero_data_information),
3418 CIFSMaxBufSize, NULL, NULL);
3419 filemap_invalidate_unlock(inode->i_mapping);
3421 inode_unlock(inode);
3426 static int smb3_simple_fallocate_write_range(unsigned int xid,
3427 struct cifs_tcon *tcon,
3428 struct cifsFileInfo *cfile,
3429 loff_t off, loff_t len,
3432 struct cifs_io_parms io_parms = {0};
3437 io_parms.netfid = cfile->fid.netfid;
3438 io_parms.pid = current->tgid;
3439 io_parms.tcon = tcon;
3440 io_parms.persistent_fid = cfile->fid.persistent_fid;
3441 io_parms.volatile_fid = cfile->fid.volatile_fid;
3444 io_parms.offset = off;
3445 io_parms.length = len;
3446 if (io_parms.length > SMB2_MAX_BUFFER_SIZE)
3447 io_parms.length = SMB2_MAX_BUFFER_SIZE;
3448 /* iov[0] is reserved for smb header */
3449 iov[1].iov_base = buf;
3450 iov[1].iov_len = io_parms.length;
3451 rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
3463 static int smb3_simple_fallocate_range(unsigned int xid,
3464 struct cifs_tcon *tcon,
3465 struct cifsFileInfo *cfile,
3466 loff_t off, loff_t len)
3468 struct file_allocated_range_buffer in_data, *out_data = NULL, *tmp_data;
3474 in_data.file_offset = cpu_to_le64(off);
3475 in_data.length = cpu_to_le64(len);
3476 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3477 cfile->fid.volatile_fid,
3478 FSCTL_QUERY_ALLOCATED_RANGES,
3479 (char *)&in_data, sizeof(in_data),
3480 1024 * sizeof(struct file_allocated_range_buffer),
3481 (char **)&out_data, &out_data_len);
3485 buf = kzalloc(1024 * 1024, GFP_KERNEL);
3491 tmp_data = out_data;
3494 * The rest of the region is unmapped so write it all.
3496 if (out_data_len == 0) {
3497 rc = smb3_simple_fallocate_write_range(xid, tcon,
3498 cfile, off, len, buf);
3502 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3507 if (off < le64_to_cpu(tmp_data->file_offset)) {
3509 * We are at a hole. Write until the end of the region
3510 * or until the next allocated data,
3511 * whichever comes next.
3513 l = le64_to_cpu(tmp_data->file_offset) - off;
3516 rc = smb3_simple_fallocate_write_range(xid, tcon,
3517 cfile, off, l, buf);
3526 * We are at a section of allocated data, just skip forward
3527 * until the end of the data or the end of the region
3528 * we are supposed to fallocate, whichever comes first.
3530 l = le64_to_cpu(tmp_data->length);
3536 tmp_data = &tmp_data[1];
3537 out_data_len -= sizeof(struct file_allocated_range_buffer);
3547 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3548 loff_t off, loff_t len, bool keep_size)
3550 struct inode *inode;
3551 struct cifsInodeInfo *cifsi;
3552 struct cifsFileInfo *cfile = file->private_data;
3553 long rc = -EOPNOTSUPP;
3559 inode = d_inode(cfile->dentry);
3560 cifsi = CIFS_I(inode);
3562 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3563 tcon->ses->Suid, off, len);
3564 /* if file not oplocked can't be sure whether asking to extend size */
3565 if (!CIFS_CACHE_READ(cifsi))
3566 if (keep_size == false) {
3567 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3568 tcon->tid, tcon->ses->Suid, off, len, rc);
3574 * Extending the file
3576 if ((keep_size == false) && i_size_read(inode) < off + len) {
3577 rc = inode_newsize_ok(inode, off + len);
3581 if (cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)
3582 smb2_set_sparse(xid, tcon, cfile, inode, false);
3584 eof = cpu_to_le64(off + len);
3585 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3586 cfile->fid.volatile_fid, cfile->pid, &eof);
3588 cifsi->server_eof = off + len;
3589 cifs_setsize(inode, off + len);
3590 cifs_truncate_page(inode->i_mapping, inode->i_size);
3591 truncate_setsize(inode, off + len);
3597 * Files are non-sparse by default so falloc may be a no-op
3598 * Must check if file sparse. If not sparse, and since we are not
3599 * extending then no need to do anything since file already allocated
3601 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
3606 if (keep_size == true) {
3608 * We can not preallocate pages beyond the end of the file
3611 if (off >= i_size_read(inode)) {
3616 * For fallocates that are partially beyond the end of file,
3617 * clamp len so we only fallocate up to the end of file.
3619 if (off + len > i_size_read(inode)) {
3620 len = i_size_read(inode) - off;
3624 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3626 * At this point, we are trying to fallocate an internal
3627 * regions of a sparse file. Since smb2 does not have a
3628 * fallocate command we have two otions on how to emulate this.
3629 * We can either turn the entire file to become non-sparse
3630 * which we only do if the fallocate is for virtually
3631 * the whole file, or we can overwrite the region with zeroes
3632 * using SMB2_write, which could be prohibitevly expensive
3636 * We are only trying to fallocate a small region so
3637 * just write it with zero.
3639 if (len <= 1024 * 1024) {
3640 rc = smb3_simple_fallocate_range(xid, tcon, cfile,
3646 * Check if falloc starts within first few pages of file
3647 * and ends within a few pages of the end of file to
3648 * ensure that most of file is being forced to be
3649 * fallocated now. If so then setting whole file sparse
3650 * ie potentially making a few extra pages at the beginning
3651 * or end of the file non-sparse via set_sparse is harmless.
3653 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
3659 smb2_set_sparse(xid, tcon, cfile, inode, false);
3664 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3665 tcon->ses->Suid, off, len, rc);
3667 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3668 tcon->ses->Suid, off, len);
3674 static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
3675 loff_t off, loff_t len)
3679 struct inode *inode = file_inode(file);
3680 struct cifsFileInfo *cfile = file->private_data;
3681 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3689 old_eof = i_size_read(inode);
3690 if ((off >= old_eof) ||
3691 off + len >= old_eof) {
3696 filemap_invalidate_lock(inode->i_mapping);
3697 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof - 1);
3701 truncate_pagecache_range(inode, off, old_eof);
3703 rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
3704 old_eof - off - len, off);
3708 eof = cpu_to_le64(old_eof - len);
3709 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3710 cfile->fid.volatile_fid, cfile->pid, &eof);
3716 cifsi->server_eof = i_size_read(inode) - len;
3717 truncate_setsize(inode, cifsi->server_eof);
3718 fscache_resize_cookie(cifs_inode_cookie(inode), cifsi->server_eof);
3720 filemap_invalidate_unlock(inode->i_mapping);
3722 inode_unlock(inode);
3727 static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
3728 loff_t off, loff_t len)
3732 struct cifsFileInfo *cfile = file->private_data;
3733 struct inode *inode = file_inode(file);
3735 __u64 count, old_eof;
3741 old_eof = i_size_read(inode);
3742 if (off >= old_eof) {
3747 count = old_eof - off;
3748 eof = cpu_to_le64(old_eof + len);
3750 filemap_invalidate_lock(inode->i_mapping);
3751 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof + len - 1);
3754 truncate_pagecache_range(inode, off, old_eof);
3756 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3757 cfile->fid.volatile_fid, cfile->pid, &eof);
3761 rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len);
3765 rc = smb3_zero_data(file, tcon, off, len, xid);
3771 filemap_invalidate_unlock(inode->i_mapping);
3773 inode_unlock(inode);
3778 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3780 struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3781 struct cifsInodeInfo *cifsi;
3782 struct inode *inode;
3784 struct file_allocated_range_buffer in_data, *out_data = NULL;
3788 if (whence != SEEK_HOLE && whence != SEEK_DATA)
3789 return generic_file_llseek(file, offset, whence);
3791 inode = d_inode(cfile->dentry);
3792 cifsi = CIFS_I(inode);
3794 if (offset < 0 || offset >= i_size_read(inode))
3799 * We need to be sure that all dirty pages are written as they
3800 * might fill holes on the server.
3801 * Note that we also MUST flush any written pages since at least
3802 * some servers (Windows2016) will not reflect recent writes in
3803 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3805 wrcfile = find_writable_file(cifsi, FIND_WR_ANY);
3807 filemap_write_and_wait(inode->i_mapping);
3808 smb2_flush_file(xid, tcon, &wrcfile->fid);
3809 cifsFileInfo_put(wrcfile);
3812 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3813 if (whence == SEEK_HOLE)
3814 offset = i_size_read(inode);
3818 in_data.file_offset = cpu_to_le64(offset);
3819 in_data.length = cpu_to_le64(i_size_read(inode));
3821 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3822 cfile->fid.volatile_fid,
3823 FSCTL_QUERY_ALLOCATED_RANGES,
3824 (char *)&in_data, sizeof(in_data),
3825 sizeof(struct file_allocated_range_buffer),
3826 (char **)&out_data, &out_data_len);
3832 if (whence == SEEK_HOLE && out_data_len == 0)
3835 if (whence == SEEK_DATA && out_data_len == 0) {
3840 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3844 if (whence == SEEK_DATA) {
3845 offset = le64_to_cpu(out_data->file_offset);
3848 if (offset < le64_to_cpu(out_data->file_offset))
3851 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3857 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3862 static int smb3_fiemap(struct cifs_tcon *tcon,
3863 struct cifsFileInfo *cfile,
3864 struct fiemap_extent_info *fei, u64 start, u64 len)
3867 struct file_allocated_range_buffer in_data, *out_data;
3869 int i, num, rc, flags, last_blob;
3872 rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0);
3878 in_data.file_offset = cpu_to_le64(start);
3879 in_data.length = cpu_to_le64(len);
3881 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3882 cfile->fid.volatile_fid,
3883 FSCTL_QUERY_ALLOCATED_RANGES,
3884 (char *)&in_data, sizeof(in_data),
3885 1024 * sizeof(struct file_allocated_range_buffer),
3886 (char **)&out_data, &out_data_len);
3895 if (out_data_len && out_data_len < sizeof(struct file_allocated_range_buffer)) {
3899 if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3904 num = out_data_len / sizeof(struct file_allocated_range_buffer);
3905 for (i = 0; i < num; i++) {
3907 if (i == num - 1 && last_blob)
3908 flags |= FIEMAP_EXTENT_LAST;
3910 rc = fiemap_fill_next_extent(fei,
3911 le64_to_cpu(out_data[i].file_offset),
3912 le64_to_cpu(out_data[i].file_offset),
3913 le64_to_cpu(out_data[i].length),
3924 next = le64_to_cpu(out_data[num - 1].file_offset) +
3925 le64_to_cpu(out_data[num - 1].length);
3926 len = len - (next - start);
3937 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
3938 loff_t off, loff_t len)
3940 /* KEEP_SIZE already checked for by do_fallocate */
3941 if (mode & FALLOC_FL_PUNCH_HOLE)
3942 return smb3_punch_hole(file, tcon, off, len);
3943 else if (mode & FALLOC_FL_ZERO_RANGE) {
3944 if (mode & FALLOC_FL_KEEP_SIZE)
3945 return smb3_zero_range(file, tcon, off, len, true);
3946 return smb3_zero_range(file, tcon, off, len, false);
3947 } else if (mode == FALLOC_FL_KEEP_SIZE)
3948 return smb3_simple_falloc(file, tcon, off, len, true);
3949 else if (mode == FALLOC_FL_COLLAPSE_RANGE)
3950 return smb3_collapse_range(file, tcon, off, len);
3951 else if (mode == FALLOC_FL_INSERT_RANGE)
3952 return smb3_insert_range(file, tcon, off, len);
3954 return smb3_simple_falloc(file, tcon, off, len, false);
3960 smb2_downgrade_oplock(struct TCP_Server_Info *server,
3961 struct cifsInodeInfo *cinode, __u32 oplock,
3962 unsigned int epoch, bool *purge_cache)
3964 server->ops->set_oplock_level(cinode, oplock, 0, NULL);
3968 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3969 unsigned int epoch, bool *purge_cache);
3972 smb3_downgrade_oplock(struct TCP_Server_Info *server,
3973 struct cifsInodeInfo *cinode, __u32 oplock,
3974 unsigned int epoch, bool *purge_cache)
3976 unsigned int old_state = cinode->oplock;
3977 unsigned int old_epoch = cinode->epoch;
3978 unsigned int new_state;
3980 if (epoch > old_epoch) {
3981 smb21_set_oplock_level(cinode, oplock, 0, NULL);
3982 cinode->epoch = epoch;
3985 new_state = cinode->oplock;
3986 *purge_cache = false;
3988 if ((old_state & CIFS_CACHE_READ_FLG) != 0 &&
3989 (new_state & CIFS_CACHE_READ_FLG) == 0)
3990 *purge_cache = true;
3991 else if (old_state == new_state && (epoch - old_epoch > 1))
3992 *purge_cache = true;
3996 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3997 unsigned int epoch, bool *purge_cache)
4000 cinode->lease_granted = false;
4001 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
4003 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
4004 cinode->oplock = CIFS_CACHE_RHW_FLG;
4005 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
4006 &cinode->netfs.inode);
4007 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
4008 cinode->oplock = CIFS_CACHE_RW_FLG;
4009 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
4010 &cinode->netfs.inode);
4011 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
4012 cinode->oplock = CIFS_CACHE_READ_FLG;
4013 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
4014 &cinode->netfs.inode);
4020 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4021 unsigned int epoch, bool *purge_cache)
4023 char message[5] = {0};
4024 unsigned int new_oplock = 0;
4027 cinode->lease_granted = true;
4028 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
4031 /* Check if the server granted an oplock rather than a lease */
4032 if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4033 return smb2_set_oplock_level(cinode, oplock, epoch,
4036 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
4037 new_oplock |= CIFS_CACHE_READ_FLG;
4038 strcat(message, "R");
4040 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
4041 new_oplock |= CIFS_CACHE_HANDLE_FLG;
4042 strcat(message, "H");
4044 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
4045 new_oplock |= CIFS_CACHE_WRITE_FLG;
4046 strcat(message, "W");
4049 strncpy(message, "None", sizeof(message));
4051 cinode->oplock = new_oplock;
4052 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
4053 &cinode->netfs.inode);
4057 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4058 unsigned int epoch, bool *purge_cache)
4060 unsigned int old_oplock = cinode->oplock;
4062 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
4065 *purge_cache = false;
4066 if (old_oplock == CIFS_CACHE_READ_FLG) {
4067 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
4068 (epoch - cinode->epoch > 0))
4069 *purge_cache = true;
4070 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4071 (epoch - cinode->epoch > 1))
4072 *purge_cache = true;
4073 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4074 (epoch - cinode->epoch > 1))
4075 *purge_cache = true;
4076 else if (cinode->oplock == 0 &&
4077 (epoch - cinode->epoch > 0))
4078 *purge_cache = true;
4079 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
4080 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4081 (epoch - cinode->epoch > 0))
4082 *purge_cache = true;
4083 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4084 (epoch - cinode->epoch > 1))
4085 *purge_cache = true;
4087 cinode->epoch = epoch;
4091 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
4093 smb2_is_read_op(__u32 oplock)
4095 return oplock == SMB2_OPLOCK_LEVEL_II;
4097 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
4100 smb21_is_read_op(__u32 oplock)
4102 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
4103 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
4107 map_oplock_to_lease(u8 oplock)
4109 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4110 return SMB2_LEASE_WRITE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE;
4111 else if (oplock == SMB2_OPLOCK_LEVEL_II)
4112 return SMB2_LEASE_READ_CACHING_LE;
4113 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
4114 return SMB2_LEASE_HANDLE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE |
4115 SMB2_LEASE_WRITE_CACHING_LE;
4120 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
4122 struct create_lease *buf;
4124 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
4128 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4129 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4131 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4132 (struct create_lease, lcontext));
4133 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
4134 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4135 (struct create_lease, Name));
4136 buf->ccontext.NameLength = cpu_to_le16(4);
4137 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4146 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
4148 struct create_lease_v2 *buf;
4150 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
4154 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4155 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4157 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4158 (struct create_lease_v2, lcontext));
4159 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
4160 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4161 (struct create_lease_v2, Name));
4162 buf->ccontext.NameLength = cpu_to_le16(4);
4163 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4172 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4174 struct create_lease *lc = (struct create_lease *)buf;
4176 *epoch = 0; /* not used */
4177 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4178 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4179 return le32_to_cpu(lc->lcontext.LeaseState);
4183 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4185 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
4187 *epoch = le16_to_cpu(lc->lcontext.Epoch);
4188 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4189 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4191 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
4192 return le32_to_cpu(lc->lcontext.LeaseState);
4196 smb2_wp_retry_size(struct inode *inode)
4198 return min_t(unsigned int, CIFS_SB(inode->i_sb)->ctx->wsize,
4199 SMB2_MAX_BUFFER_SIZE);
4203 smb2_dir_needs_close(struct cifsFileInfo *cfile)
4205 return !cfile->invalidHandle;
4209 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
4210 struct smb_rqst *old_rq, __le16 cipher_type)
4212 struct smb2_hdr *shdr =
4213 (struct smb2_hdr *)old_rq->rq_iov[0].iov_base;
4215 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
4216 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
4217 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
4218 tr_hdr->Flags = cpu_to_le16(0x01);
4219 if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4220 (cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4221 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4223 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4224 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
4227 static void *smb2_aead_req_alloc(struct crypto_aead *tfm, const struct smb_rqst *rqst,
4228 int num_rqst, const u8 *sig, u8 **iv,
4229 struct aead_request **req, struct scatterlist **sgl,
4230 unsigned int *num_sgs)
4232 unsigned int req_size = sizeof(**req) + crypto_aead_reqsize(tfm);
4233 unsigned int iv_size = crypto_aead_ivsize(tfm);
4237 *num_sgs = cifs_get_num_sgs(rqst, num_rqst, sig);
4240 len += crypto_aead_alignmask(tfm) & ~(crypto_tfm_ctx_alignment() - 1);
4241 len = ALIGN(len, crypto_tfm_ctx_alignment());
4243 len = ALIGN(len, __alignof__(struct scatterlist));
4244 len += *num_sgs * sizeof(**sgl);
4246 p = kmalloc(len, GFP_ATOMIC);
4250 *iv = (u8 *)PTR_ALIGN(p, crypto_aead_alignmask(tfm) + 1);
4251 *req = (struct aead_request *)PTR_ALIGN(*iv + iv_size,
4252 crypto_tfm_ctx_alignment());
4253 *sgl = (struct scatterlist *)PTR_ALIGN((u8 *)*req + req_size,
4254 __alignof__(struct scatterlist));
4258 static void *smb2_get_aead_req(struct crypto_aead *tfm, const struct smb_rqst *rqst,
4259 int num_rqst, const u8 *sig, u8 **iv,
4260 struct aead_request **req, struct scatterlist **sgl)
4262 unsigned int off, len, skip;
4263 struct scatterlist *sg;
4264 unsigned int num_sgs;
4269 p = smb2_aead_req_alloc(tfm, rqst, num_rqst, sig, iv, req, sgl, &num_sgs);
4273 sg_init_table(*sgl, num_sgs);
4276 /* Assumes the first rqst has a transform header as the first iov.
4278 * rqst[0].rq_iov[0] is transform header
4279 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
4280 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
4282 for (i = 0; i < num_rqst; i++) {
4284 * The first rqst has a transform header where the
4285 * first 20 bytes are not part of the encrypted blob.
4287 for (j = 0; j < rqst[i].rq_nvec; j++) {
4288 struct kvec *iov = &rqst[i].rq_iov[j];
4290 skip = (i == 0) && (j == 0) ? 20 : 0;
4291 addr = (unsigned long)iov->iov_base + skip;
4292 len = iov->iov_len - skip;
4293 sg = cifs_sg_set_buf(sg, (void *)addr, len);
4295 for (j = 0; j < rqst[i].rq_npages; j++) {
4296 rqst_page_get_length(&rqst[i], j, &len, &off);
4297 sg_set_page(sg++, rqst[i].rq_pages[j], len, off);
4300 cifs_sg_set_buf(sg, sig, SMB2_SIGNATURE_SIZE);
4306 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
4308 struct TCP_Server_Info *pserver;
4309 struct cifs_ses *ses;
4312 /* If server is a channel, select the primary channel */
4313 pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
4315 spin_lock(&cifs_tcp_ses_lock);
4316 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
4317 if (ses->Suid == ses_id) {
4318 spin_lock(&ses->ses_lock);
4319 ses_enc_key = enc ? ses->smb3encryptionkey :
4320 ses->smb3decryptionkey;
4321 memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE);
4322 spin_unlock(&ses->ses_lock);
4323 spin_unlock(&cifs_tcp_ses_lock);
4327 spin_unlock(&cifs_tcp_ses_lock);
4332 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
4333 * iov[0] - transform header (associate data),
4334 * iov[1-N] - SMB2 header and pages - data to encrypt.
4335 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4339 crypt_message(struct TCP_Server_Info *server, int num_rqst,
4340 struct smb_rqst *rqst, int enc)
4342 struct smb2_transform_hdr *tr_hdr =
4343 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
4344 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
4346 struct scatterlist *sg;
4347 u8 sign[SMB2_SIGNATURE_SIZE] = {};
4348 u8 key[SMB3_ENC_DEC_KEY_SIZE];
4349 struct aead_request *req;
4351 DECLARE_CRYPTO_WAIT(wait);
4352 struct crypto_aead *tfm;
4353 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4356 rc = smb2_get_enc_key(server, le64_to_cpu(tr_hdr->SessionId), enc, key);
4358 cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
4363 rc = smb3_crypto_aead_allocate(server);
4365 cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
4369 tfm = enc ? server->secmech.enc : server->secmech.dec;
4371 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
4372 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4373 rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
4375 rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE);
4378 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
4382 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
4384 cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
4388 creq = smb2_get_aead_req(tfm, rqst, num_rqst, sign, &iv, &req, &sg);
4389 if (unlikely(!creq))
4393 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
4394 crypt_len += SMB2_SIGNATURE_SIZE;
4397 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4398 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4399 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4402 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4405 aead_request_set_tfm(req, tfm);
4406 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
4407 aead_request_set_ad(req, assoc_data_len);
4409 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
4410 crypto_req_done, &wait);
4412 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
4413 : crypto_aead_decrypt(req), &wait);
4416 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
4418 kfree_sensitive(creq);
4423 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
4427 for (i = 0; i < num_rqst; i++) {
4428 if (rqst[i].rq_pages) {
4429 for (j = rqst[i].rq_npages - 1; j >= 0; j--)
4430 put_page(rqst[i].rq_pages[j]);
4431 kfree(rqst[i].rq_pages);
4437 * This function will initialize new_rq and encrypt the content.
4438 * The first entry, new_rq[0], only contains a single iov which contains
4439 * a smb2_transform_hdr and is pre-allocated by the caller.
4440 * This function then populates new_rq[1+] with the content from olq_rq[0+].
4442 * The end result is an array of smb_rqst structures where the first structure
4443 * only contains a single iov for the transform header which we then can pass
4444 * to crypt_message().
4446 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4447 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
4450 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
4451 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
4453 struct page **pages;
4454 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
4455 unsigned int npages;
4456 unsigned int orig_len = 0;
4460 for (i = 1; i < num_rqst; i++) {
4461 struct smb_rqst *old = &old_rq[i - 1];
4462 struct smb_rqst *new = &new_rq[i];
4464 orig_len += smb_rqst_len(server, old);
4465 new->rq_iov = old->rq_iov;
4466 new->rq_nvec = old->rq_nvec;
4468 npages = old->rq_npages;
4472 pages = kmalloc_array(npages, sizeof(struct page *),
4477 new->rq_pages = pages;
4478 new->rq_npages = npages;
4479 new->rq_offset = old->rq_offset;
4480 new->rq_pagesz = old->rq_pagesz;
4481 new->rq_tailsz = old->rq_tailsz;
4483 for (j = 0; j < npages; j++) {
4484 pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4489 /* copy pages form the old */
4490 for (j = 0; j < npages; j++) {
4492 unsigned int offset, len;
4494 rqst_page_get_length(new, j, &len, &offset);
4496 dst = kmap_local_page(new->rq_pages[j]) + offset;
4497 src = kmap_local_page(old->rq_pages[j]) + offset;
4499 memcpy(dst, src, len);
4500 kunmap(new->rq_pages[j]);
4501 kunmap(old->rq_pages[j]);
4505 /* fill the 1st iov with a transform header */
4506 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
4508 rc = crypt_message(server, num_rqst, new_rq, 1);
4509 cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
4516 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
4521 smb3_is_transform_hdr(void *buf)
4523 struct smb2_transform_hdr *trhdr = buf;
4525 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
4529 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
4530 unsigned int buf_data_size, struct page **pages,
4531 unsigned int npages, unsigned int page_data_size,
4535 struct smb_rqst rqst = {NULL};
4538 iov[0].iov_base = buf;
4539 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
4540 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
4541 iov[1].iov_len = buf_data_size;
4545 rqst.rq_pages = pages;
4546 rqst.rq_npages = npages;
4547 rqst.rq_pagesz = PAGE_SIZE;
4548 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
4550 rc = crypt_message(server, 1, &rqst, 0);
4551 cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
4556 memmove(buf, iov[1].iov_base, buf_data_size);
4559 server->total_read = buf_data_size + page_data_size;
4565 read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
4566 unsigned int npages, unsigned int len)
4571 for (i = 0; i < npages; i++) {
4572 struct page *page = pages[i];
4576 if (len >= PAGE_SIZE) {
4577 /* enough data to fill the page */
4581 zero_user(page, len, PAGE_SIZE - len);
4584 length = cifs_read_page_from_socket(server, page, 0, n);
4587 server->total_read += length;
4594 init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
4595 unsigned int cur_off, struct bio_vec **page_vec)
4597 struct bio_vec *bvec;
4600 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
4604 for (i = 0; i < npages; i++) {
4605 bvec[i].bv_page = pages[i];
4606 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
4607 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
4608 data_size -= bvec[i].bv_len;
4611 if (data_size != 0) {
4612 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
4622 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
4623 char *buf, unsigned int buf_len, struct page **pages,
4624 unsigned int npages, unsigned int page_data_size,
4627 unsigned int data_offset;
4628 unsigned int data_len;
4629 unsigned int cur_off;
4630 unsigned int cur_page_idx;
4631 unsigned int pad_len;
4632 struct cifs_readdata *rdata = mid->callback_data;
4633 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
4634 struct bio_vec *bvec = NULL;
4635 struct iov_iter iter;
4638 bool use_rdma_mr = false;
4640 if (shdr->Command != SMB2_READ) {
4641 cifs_server_dbg(VFS, "only big read responses are supported\n");
4645 if (server->ops->is_session_expired &&
4646 server->ops->is_session_expired(buf)) {
4648 cifs_reconnect(server, true);
4652 if (server->ops->is_status_pending &&
4653 server->ops->is_status_pending(buf, server))
4656 /* set up first two iov to get credits */
4657 rdata->iov[0].iov_base = buf;
4658 rdata->iov[0].iov_len = 0;
4659 rdata->iov[1].iov_base = buf;
4660 rdata->iov[1].iov_len =
4661 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
4662 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
4663 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
4664 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
4665 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
4667 rdata->result = server->ops->map_error(buf, true);
4668 if (rdata->result != 0) {
4669 cifs_dbg(FYI, "%s: server returned error %d\n",
4670 __func__, rdata->result);
4671 /* normal error on read response */
4673 mid->mid_state = MID_RESPONSE_RECEIVED;
4675 dequeue_mid(mid, false);
4679 data_offset = server->ops->read_data_offset(buf);
4680 #ifdef CONFIG_CIFS_SMB_DIRECT
4681 use_rdma_mr = rdata->mr;
4683 data_len = server->ops->read_data_length(buf, use_rdma_mr);
4685 if (data_offset < server->vals->read_rsp_size) {
4687 * win2k8 sometimes sends an offset of 0 when the read
4688 * is beyond the EOF. Treat it as if the data starts just after
4691 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
4692 __func__, data_offset);
4693 data_offset = server->vals->read_rsp_size;
4694 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
4695 /* data_offset is beyond the end of smallbuf */
4696 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
4697 __func__, data_offset);
4698 rdata->result = -EIO;
4700 mid->mid_state = MID_RESPONSE_MALFORMED;
4702 dequeue_mid(mid, rdata->result);
4706 pad_len = data_offset - server->vals->read_rsp_size;
4708 if (buf_len <= data_offset) {
4709 /* read response payload is in pages */
4710 cur_page_idx = pad_len / PAGE_SIZE;
4711 cur_off = pad_len % PAGE_SIZE;
4713 if (cur_page_idx != 0) {
4714 /* data offset is beyond the 1st page of response */
4715 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
4716 __func__, data_offset);
4717 rdata->result = -EIO;
4719 mid->mid_state = MID_RESPONSE_MALFORMED;
4721 dequeue_mid(mid, rdata->result);
4725 if (data_len > page_data_size - pad_len) {
4726 /* data_len is corrupt -- discard frame */
4727 rdata->result = -EIO;
4729 mid->mid_state = MID_RESPONSE_MALFORMED;
4731 dequeue_mid(mid, rdata->result);
4735 rdata->result = init_read_bvec(pages, npages, page_data_size,
4737 if (rdata->result != 0) {
4739 mid->mid_state = MID_RESPONSE_MALFORMED;
4741 dequeue_mid(mid, rdata->result);
4745 iov_iter_bvec(&iter, ITER_SOURCE, bvec, npages, data_len);
4746 } else if (buf_len >= data_offset + data_len) {
4747 /* read response payload is in buf */
4748 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
4749 iov.iov_base = buf + data_offset;
4750 iov.iov_len = data_len;
4751 iov_iter_kvec(&iter, ITER_SOURCE, &iov, 1, data_len);
4753 /* read response payload cannot be in both buf and pages */
4754 WARN_ONCE(1, "buf can not contain only a part of read data");
4755 rdata->result = -EIO;
4757 mid->mid_state = MID_RESPONSE_MALFORMED;
4759 dequeue_mid(mid, rdata->result);
4763 length = rdata->copy_into_pages(server, rdata, &iter);
4771 mid->mid_state = MID_RESPONSE_RECEIVED;
4773 dequeue_mid(mid, false);
4777 struct smb2_decrypt_work {
4778 struct work_struct decrypt;
4779 struct TCP_Server_Info *server;
4780 struct page **ppages;
4782 unsigned int npages;
4787 static void smb2_decrypt_offload(struct work_struct *work)
4789 struct smb2_decrypt_work *dw = container_of(work,
4790 struct smb2_decrypt_work, decrypt);
4792 struct mid_q_entry *mid;
4794 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
4795 dw->ppages, dw->npages, dw->len, true);
4797 cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
4801 dw->server->lstrp = jiffies;
4802 mid = smb2_find_dequeue_mid(dw->server, dw->buf);
4804 cifs_dbg(FYI, "mid not found\n");
4806 mid->decrypted = true;
4807 rc = handle_read_data(dw->server, mid, dw->buf,
4808 dw->server->vals->read_rsp_size,
4809 dw->ppages, dw->npages, dw->len,
4812 #ifdef CONFIG_CIFS_STATS2
4813 mid->when_received = jiffies;
4815 if (dw->server->ops->is_network_name_deleted)
4816 dw->server->ops->is_network_name_deleted(dw->buf,
4821 spin_lock(&dw->server->srv_lock);
4822 if (dw->server->tcpStatus == CifsNeedReconnect) {
4823 spin_lock(&dw->server->mid_lock);
4824 mid->mid_state = MID_RETRY_NEEDED;
4825 spin_unlock(&dw->server->mid_lock);
4826 spin_unlock(&dw->server->srv_lock);
4829 spin_lock(&dw->server->mid_lock);
4830 mid->mid_state = MID_REQUEST_SUBMITTED;
4831 mid->mid_flags &= ~(MID_DELETED);
4832 list_add_tail(&mid->qhead,
4833 &dw->server->pending_mid_q);
4834 spin_unlock(&dw->server->mid_lock);
4835 spin_unlock(&dw->server->srv_lock);
4842 for (i = dw->npages-1; i >= 0; i--)
4843 put_page(dw->ppages[i]);
4846 cifs_small_buf_release(dw->buf);
4852 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
4855 char *buf = server->smallbuf;
4856 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4857 unsigned int npages;
4858 struct page **pages;
4860 unsigned int buflen = server->pdu_size;
4863 struct smb2_decrypt_work *dw;
4866 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
4867 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
4869 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
4872 server->total_read += rc;
4874 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
4875 server->vals->read_rsp_size;
4876 npages = DIV_ROUND_UP(len, PAGE_SIZE);
4878 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
4884 for (; i < npages; i++) {
4885 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4892 /* read read data into pages */
4893 rc = read_data_into_pages(server, pages, npages, len);
4897 rc = cifs_discard_remaining_data(server);
4902 * For large reads, offload to different thread for better performance,
4903 * use more cores decrypting which can be expensive
4906 if ((server->min_offload) && (server->in_flight > 1) &&
4907 (server->pdu_size >= server->min_offload)) {
4908 dw = kmalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL);
4910 goto non_offloaded_decrypt;
4912 dw->buf = server->smallbuf;
4913 server->smallbuf = (char *)cifs_small_buf_get();
4915 INIT_WORK(&dw->decrypt, smb2_decrypt_offload);
4917 dw->npages = npages;
4918 dw->server = server;
4921 queue_work(decrypt_wq, &dw->decrypt);
4922 *num_mids = 0; /* worker thread takes care of finding mid */
4926 non_offloaded_decrypt:
4927 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
4928 pages, npages, len, false);
4932 *mid = smb2_find_mid(server, buf);
4934 cifs_dbg(FYI, "mid not found\n");
4936 cifs_dbg(FYI, "mid found\n");
4937 (*mid)->decrypted = true;
4938 rc = handle_read_data(server, *mid, buf,
4939 server->vals->read_rsp_size,
4940 pages, npages, len, false);
4942 if (server->ops->is_network_name_deleted) {
4943 server->ops->is_network_name_deleted(buf,
4950 for (i = i - 1; i >= 0; i--)
4955 cifs_discard_remaining_data(server);
4960 receive_encrypted_standard(struct TCP_Server_Info *server,
4961 struct mid_q_entry **mids, char **bufs,
4965 char *buf = server->smallbuf;
4966 struct smb2_hdr *shdr;
4967 unsigned int pdu_length = server->pdu_size;
4968 unsigned int buf_size;
4969 struct mid_q_entry *mid_entry;
4971 char *next_buffer = NULL;
4975 /* switch to large buffer if too big for a small one */
4976 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
4977 server->large_buf = true;
4978 memcpy(server->bigbuf, buf, server->total_read);
4979 buf = server->bigbuf;
4982 /* now read the rest */
4983 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
4984 pdu_length - HEADER_SIZE(server) + 1);
4987 server->total_read += length;
4989 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
4990 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0, false);
4994 next_is_large = server->large_buf;
4996 shdr = (struct smb2_hdr *)buf;
4997 if (shdr->NextCommand) {
4999 next_buffer = (char *)cifs_buf_get();
5001 next_buffer = (char *)cifs_small_buf_get();
5003 buf + le32_to_cpu(shdr->NextCommand),
5004 pdu_length - le32_to_cpu(shdr->NextCommand));
5007 mid_entry = smb2_find_mid(server, buf);
5008 if (mid_entry == NULL)
5009 cifs_dbg(FYI, "mid not found\n");
5011 cifs_dbg(FYI, "mid found\n");
5012 mid_entry->decrypted = true;
5013 mid_entry->resp_buf_size = server->pdu_size;
5016 if (*num_mids >= MAX_COMPOUND) {
5017 cifs_server_dbg(VFS, "too many PDUs in compound\n");
5020 bufs[*num_mids] = buf;
5021 mids[(*num_mids)++] = mid_entry;
5023 if (mid_entry && mid_entry->handle)
5024 ret = mid_entry->handle(server, mid_entry);
5026 ret = cifs_handle_standard(server, mid_entry);
5028 if (ret == 0 && shdr->NextCommand) {
5029 pdu_length -= le32_to_cpu(shdr->NextCommand);
5030 server->large_buf = next_is_large;
5032 server->bigbuf = buf = next_buffer;
5034 server->smallbuf = buf = next_buffer;
5036 } else if (ret != 0) {
5038 * ret != 0 here means that we didn't get to handle_mid() thus
5039 * server->smallbuf and server->bigbuf are still valid. We need
5040 * to free next_buffer because it is not going to be used
5044 free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer);
5046 free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer);
5053 smb3_receive_transform(struct TCP_Server_Info *server,
5054 struct mid_q_entry **mids, char **bufs, int *num_mids)
5056 char *buf = server->smallbuf;
5057 unsigned int pdu_length = server->pdu_size;
5058 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
5059 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
5061 if (pdu_length < sizeof(struct smb2_transform_hdr) +
5062 sizeof(struct smb2_hdr)) {
5063 cifs_server_dbg(VFS, "Transform message is too small (%u)\n",
5065 cifs_reconnect(server, true);
5066 return -ECONNABORTED;
5069 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
5070 cifs_server_dbg(VFS, "Transform message is broken\n");
5071 cifs_reconnect(server, true);
5072 return -ECONNABORTED;
5075 /* TODO: add support for compounds containing READ. */
5076 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
5077 return receive_encrypted_read(server, &mids[0], num_mids);
5080 return receive_encrypted_standard(server, mids, bufs, num_mids);
5084 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
5086 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
5088 return handle_read_data(server, mid, buf, server->pdu_size,
5093 smb2_next_header(char *buf)
5095 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
5096 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
5098 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
5099 return sizeof(struct smb2_transform_hdr) +
5100 le32_to_cpu(t_hdr->OriginalMessageSize);
5102 return le32_to_cpu(hdr->NextCommand);
5106 smb2_make_node(unsigned int xid, struct inode *inode,
5107 struct dentry *dentry, struct cifs_tcon *tcon,
5108 const char *full_path, umode_t mode, dev_t dev)
5110 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
5112 struct cifs_open_info_data buf = {};
5113 struct cifs_io_parms io_parms = {0};
5115 struct cifs_fid fid;
5116 struct cifs_open_parms oparms;
5117 unsigned int bytes_written;
5118 struct win_dev *pdev;
5122 * Check if mounted with mount parm 'sfu' mount parm.
5123 * SFU emulation should work with all servers, but only
5124 * supports block and char device (no socket & fifo),
5125 * and was used by default in earlier versions of Windows
5127 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
5131 * TODO: Add ability to create instead via reparse point. Windows (e.g.
5132 * their current NFS server) uses this approach to expose special files
5133 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
5136 if (!S_ISCHR(mode) && !S_ISBLK(mode))
5139 cifs_dbg(FYI, "sfu compat create special file\n");
5142 oparms.cifs_sb = cifs_sb;
5143 oparms.desired_access = GENERIC_WRITE;
5144 oparms.create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR |
5145 CREATE_OPTION_SPECIAL);
5146 oparms.disposition = FILE_CREATE;
5147 oparms.path = full_path;
5149 oparms.reconnect = false;
5151 if (tcon->ses->server->oplocks)
5152 oplock = REQ_OPLOCK;
5155 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, &buf);
5160 * BB Do not bother to decode buf since no local inode yet to put
5161 * timestamps in, but we can reuse it safely.
5164 pdev = (struct win_dev *)&buf.fi;
5165 io_parms.pid = current->tgid;
5166 io_parms.tcon = tcon;
5167 io_parms.offset = 0;
5168 io_parms.length = sizeof(struct win_dev);
5169 iov[1].iov_base = &buf.fi;
5170 iov[1].iov_len = sizeof(struct win_dev);
5171 if (S_ISCHR(mode)) {
5172 memcpy(pdev->type, "IntxCHR", 8);
5173 pdev->major = cpu_to_le64(MAJOR(dev));
5174 pdev->minor = cpu_to_le64(MINOR(dev));
5175 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5176 &bytes_written, iov, 1);
5177 } else if (S_ISBLK(mode)) {
5178 memcpy(pdev->type, "IntxBLK", 8);
5179 pdev->major = cpu_to_le64(MAJOR(dev));
5180 pdev->minor = cpu_to_le64(MINOR(dev));
5181 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5182 &bytes_written, iov, 1);
5184 tcon->ses->server->ops->close(xid, tcon, &fid);
5187 /* FIXME: add code here to set EAs */
5189 cifs_free_open_info(&buf);
5193 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5194 struct smb_version_operations smb20_operations = {
5195 .compare_fids = smb2_compare_fids,
5196 .setup_request = smb2_setup_request,
5197 .setup_async_request = smb2_setup_async_request,
5198 .check_receive = smb2_check_receive,
5199 .add_credits = smb2_add_credits,
5200 .set_credits = smb2_set_credits,
5201 .get_credits_field = smb2_get_credits_field,
5202 .get_credits = smb2_get_credits,
5203 .wait_mtu_credits = cifs_wait_mtu_credits,
5204 .get_next_mid = smb2_get_next_mid,
5205 .revert_current_mid = smb2_revert_current_mid,
5206 .read_data_offset = smb2_read_data_offset,
5207 .read_data_length = smb2_read_data_length,
5208 .map_error = map_smb2_to_linux_error,
5209 .find_mid = smb2_find_mid,
5210 .check_message = smb2_check_message,
5211 .dump_detail = smb2_dump_detail,
5212 .clear_stats = smb2_clear_stats,
5213 .print_stats = smb2_print_stats,
5214 .is_oplock_break = smb2_is_valid_oplock_break,
5215 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5216 .downgrade_oplock = smb2_downgrade_oplock,
5217 .need_neg = smb2_need_neg,
5218 .negotiate = smb2_negotiate,
5219 .negotiate_wsize = smb2_negotiate_wsize,
5220 .negotiate_rsize = smb2_negotiate_rsize,
5221 .sess_setup = SMB2_sess_setup,
5222 .logoff = SMB2_logoff,
5223 .tree_connect = SMB2_tcon,
5224 .tree_disconnect = SMB2_tdis,
5225 .qfs_tcon = smb2_qfs_tcon,
5226 .is_path_accessible = smb2_is_path_accessible,
5227 .can_echo = smb2_can_echo,
5229 .query_path_info = smb2_query_path_info,
5230 .get_srv_inum = smb2_get_srv_inum,
5231 .query_file_info = smb2_query_file_info,
5232 .set_path_size = smb2_set_path_size,
5233 .set_file_size = smb2_set_file_size,
5234 .set_file_info = smb2_set_file_info,
5235 .set_compression = smb2_set_compression,
5236 .mkdir = smb2_mkdir,
5237 .mkdir_setinfo = smb2_mkdir_setinfo,
5238 .rmdir = smb2_rmdir,
5239 .unlink = smb2_unlink,
5240 .rename = smb2_rename_path,
5241 .create_hardlink = smb2_create_hardlink,
5242 .query_symlink = smb2_query_symlink,
5243 .query_mf_symlink = smb3_query_mf_symlink,
5244 .create_mf_symlink = smb3_create_mf_symlink,
5245 .open = smb2_open_file,
5246 .set_fid = smb2_set_fid,
5247 .close = smb2_close_file,
5248 .flush = smb2_flush_file,
5249 .async_readv = smb2_async_readv,
5250 .async_writev = smb2_async_writev,
5251 .sync_read = smb2_sync_read,
5252 .sync_write = smb2_sync_write,
5253 .query_dir_first = smb2_query_dir_first,
5254 .query_dir_next = smb2_query_dir_next,
5255 .close_dir = smb2_close_dir,
5256 .calc_smb_size = smb2_calc_size,
5257 .is_status_pending = smb2_is_status_pending,
5258 .is_session_expired = smb2_is_session_expired,
5259 .oplock_response = smb2_oplock_response,
5260 .queryfs = smb2_queryfs,
5261 .mand_lock = smb2_mand_lock,
5262 .mand_unlock_range = smb2_unlock_range,
5263 .push_mand_locks = smb2_push_mandatory_locks,
5264 .get_lease_key = smb2_get_lease_key,
5265 .set_lease_key = smb2_set_lease_key,
5266 .new_lease_key = smb2_new_lease_key,
5267 .calc_signature = smb2_calc_signature,
5268 .is_read_op = smb2_is_read_op,
5269 .set_oplock_level = smb2_set_oplock_level,
5270 .create_lease_buf = smb2_create_lease_buf,
5271 .parse_lease_buf = smb2_parse_lease_buf,
5272 .copychunk_range = smb2_copychunk_range,
5273 .wp_retry_size = smb2_wp_retry_size,
5274 .dir_needs_close = smb2_dir_needs_close,
5275 .get_dfs_refer = smb2_get_dfs_refer,
5276 .select_sectype = smb2_select_sectype,
5277 #ifdef CONFIG_CIFS_XATTR
5278 .query_all_EAs = smb2_query_eas,
5279 .set_EA = smb2_set_ea,
5280 #endif /* CIFS_XATTR */
5281 .get_acl = get_smb2_acl,
5282 .get_acl_by_fid = get_smb2_acl_by_fid,
5283 .set_acl = set_smb2_acl,
5284 .next_header = smb2_next_header,
5285 .ioctl_query_info = smb2_ioctl_query_info,
5286 .make_node = smb2_make_node,
5287 .fiemap = smb3_fiemap,
5288 .llseek = smb3_llseek,
5289 .is_status_io_timeout = smb2_is_status_io_timeout,
5290 .is_network_name_deleted = smb2_is_network_name_deleted,
5292 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
5294 struct smb_version_operations smb21_operations = {
5295 .compare_fids = smb2_compare_fids,
5296 .setup_request = smb2_setup_request,
5297 .setup_async_request = smb2_setup_async_request,
5298 .check_receive = smb2_check_receive,
5299 .add_credits = smb2_add_credits,
5300 .set_credits = smb2_set_credits,
5301 .get_credits_field = smb2_get_credits_field,
5302 .get_credits = smb2_get_credits,
5303 .wait_mtu_credits = smb2_wait_mtu_credits,
5304 .adjust_credits = smb2_adjust_credits,
5305 .get_next_mid = smb2_get_next_mid,
5306 .revert_current_mid = smb2_revert_current_mid,
5307 .read_data_offset = smb2_read_data_offset,
5308 .read_data_length = smb2_read_data_length,
5309 .map_error = map_smb2_to_linux_error,
5310 .find_mid = smb2_find_mid,
5311 .check_message = smb2_check_message,
5312 .dump_detail = smb2_dump_detail,
5313 .clear_stats = smb2_clear_stats,
5314 .print_stats = smb2_print_stats,
5315 .is_oplock_break = smb2_is_valid_oplock_break,
5316 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5317 .downgrade_oplock = smb2_downgrade_oplock,
5318 .need_neg = smb2_need_neg,
5319 .negotiate = smb2_negotiate,
5320 .negotiate_wsize = smb2_negotiate_wsize,
5321 .negotiate_rsize = smb2_negotiate_rsize,
5322 .sess_setup = SMB2_sess_setup,
5323 .logoff = SMB2_logoff,
5324 .tree_connect = SMB2_tcon,
5325 .tree_disconnect = SMB2_tdis,
5326 .qfs_tcon = smb2_qfs_tcon,
5327 .is_path_accessible = smb2_is_path_accessible,
5328 .can_echo = smb2_can_echo,
5330 .query_path_info = smb2_query_path_info,
5331 .get_srv_inum = smb2_get_srv_inum,
5332 .query_file_info = smb2_query_file_info,
5333 .set_path_size = smb2_set_path_size,
5334 .set_file_size = smb2_set_file_size,
5335 .set_file_info = smb2_set_file_info,
5336 .set_compression = smb2_set_compression,
5337 .mkdir = smb2_mkdir,
5338 .mkdir_setinfo = smb2_mkdir_setinfo,
5339 .rmdir = smb2_rmdir,
5340 .unlink = smb2_unlink,
5341 .rename = smb2_rename_path,
5342 .create_hardlink = smb2_create_hardlink,
5343 .query_symlink = smb2_query_symlink,
5344 .query_mf_symlink = smb3_query_mf_symlink,
5345 .create_mf_symlink = smb3_create_mf_symlink,
5346 .open = smb2_open_file,
5347 .set_fid = smb2_set_fid,
5348 .close = smb2_close_file,
5349 .flush = smb2_flush_file,
5350 .async_readv = smb2_async_readv,
5351 .async_writev = smb2_async_writev,
5352 .sync_read = smb2_sync_read,
5353 .sync_write = smb2_sync_write,
5354 .query_dir_first = smb2_query_dir_first,
5355 .query_dir_next = smb2_query_dir_next,
5356 .close_dir = smb2_close_dir,
5357 .calc_smb_size = smb2_calc_size,
5358 .is_status_pending = smb2_is_status_pending,
5359 .is_session_expired = smb2_is_session_expired,
5360 .oplock_response = smb2_oplock_response,
5361 .queryfs = smb2_queryfs,
5362 .mand_lock = smb2_mand_lock,
5363 .mand_unlock_range = smb2_unlock_range,
5364 .push_mand_locks = smb2_push_mandatory_locks,
5365 .get_lease_key = smb2_get_lease_key,
5366 .set_lease_key = smb2_set_lease_key,
5367 .new_lease_key = smb2_new_lease_key,
5368 .calc_signature = smb2_calc_signature,
5369 .is_read_op = smb21_is_read_op,
5370 .set_oplock_level = smb21_set_oplock_level,
5371 .create_lease_buf = smb2_create_lease_buf,
5372 .parse_lease_buf = smb2_parse_lease_buf,
5373 .copychunk_range = smb2_copychunk_range,
5374 .wp_retry_size = smb2_wp_retry_size,
5375 .dir_needs_close = smb2_dir_needs_close,
5376 .enum_snapshots = smb3_enum_snapshots,
5377 .notify = smb3_notify,
5378 .get_dfs_refer = smb2_get_dfs_refer,
5379 .select_sectype = smb2_select_sectype,
5380 #ifdef CONFIG_CIFS_XATTR
5381 .query_all_EAs = smb2_query_eas,
5382 .set_EA = smb2_set_ea,
5383 #endif /* CIFS_XATTR */
5384 .get_acl = get_smb2_acl,
5385 .get_acl_by_fid = get_smb2_acl_by_fid,
5386 .set_acl = set_smb2_acl,
5387 .next_header = smb2_next_header,
5388 .ioctl_query_info = smb2_ioctl_query_info,
5389 .make_node = smb2_make_node,
5390 .fiemap = smb3_fiemap,
5391 .llseek = smb3_llseek,
5392 .is_status_io_timeout = smb2_is_status_io_timeout,
5393 .is_network_name_deleted = smb2_is_network_name_deleted,
5396 struct smb_version_operations smb30_operations = {
5397 .compare_fids = smb2_compare_fids,
5398 .setup_request = smb2_setup_request,
5399 .setup_async_request = smb2_setup_async_request,
5400 .check_receive = smb2_check_receive,
5401 .add_credits = smb2_add_credits,
5402 .set_credits = smb2_set_credits,
5403 .get_credits_field = smb2_get_credits_field,
5404 .get_credits = smb2_get_credits,
5405 .wait_mtu_credits = smb2_wait_mtu_credits,
5406 .adjust_credits = smb2_adjust_credits,
5407 .get_next_mid = smb2_get_next_mid,
5408 .revert_current_mid = smb2_revert_current_mid,
5409 .read_data_offset = smb2_read_data_offset,
5410 .read_data_length = smb2_read_data_length,
5411 .map_error = map_smb2_to_linux_error,
5412 .find_mid = smb2_find_mid,
5413 .check_message = smb2_check_message,
5414 .dump_detail = smb2_dump_detail,
5415 .clear_stats = smb2_clear_stats,
5416 .print_stats = smb2_print_stats,
5417 .dump_share_caps = smb2_dump_share_caps,
5418 .is_oplock_break = smb2_is_valid_oplock_break,
5419 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5420 .downgrade_oplock = smb3_downgrade_oplock,
5421 .need_neg = smb2_need_neg,
5422 .negotiate = smb2_negotiate,
5423 .negotiate_wsize = smb3_negotiate_wsize,
5424 .negotiate_rsize = smb3_negotiate_rsize,
5425 .sess_setup = SMB2_sess_setup,
5426 .logoff = SMB2_logoff,
5427 .tree_connect = SMB2_tcon,
5428 .tree_disconnect = SMB2_tdis,
5429 .qfs_tcon = smb3_qfs_tcon,
5430 .is_path_accessible = smb2_is_path_accessible,
5431 .can_echo = smb2_can_echo,
5433 .query_path_info = smb2_query_path_info,
5434 /* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */
5435 .query_reparse_tag = smb2_query_reparse_tag,
5436 .get_srv_inum = smb2_get_srv_inum,
5437 .query_file_info = smb2_query_file_info,
5438 .set_path_size = smb2_set_path_size,
5439 .set_file_size = smb2_set_file_size,
5440 .set_file_info = smb2_set_file_info,
5441 .set_compression = smb2_set_compression,
5442 .mkdir = smb2_mkdir,
5443 .mkdir_setinfo = smb2_mkdir_setinfo,
5444 .rmdir = smb2_rmdir,
5445 .unlink = smb2_unlink,
5446 .rename = smb2_rename_path,
5447 .create_hardlink = smb2_create_hardlink,
5448 .query_symlink = smb2_query_symlink,
5449 .query_mf_symlink = smb3_query_mf_symlink,
5450 .create_mf_symlink = smb3_create_mf_symlink,
5451 .open = smb2_open_file,
5452 .set_fid = smb2_set_fid,
5453 .close = smb2_close_file,
5454 .close_getattr = smb2_close_getattr,
5455 .flush = smb2_flush_file,
5456 .async_readv = smb2_async_readv,
5457 .async_writev = smb2_async_writev,
5458 .sync_read = smb2_sync_read,
5459 .sync_write = smb2_sync_write,
5460 .query_dir_first = smb2_query_dir_first,
5461 .query_dir_next = smb2_query_dir_next,
5462 .close_dir = smb2_close_dir,
5463 .calc_smb_size = smb2_calc_size,
5464 .is_status_pending = smb2_is_status_pending,
5465 .is_session_expired = smb2_is_session_expired,
5466 .oplock_response = smb2_oplock_response,
5467 .queryfs = smb2_queryfs,
5468 .mand_lock = smb2_mand_lock,
5469 .mand_unlock_range = smb2_unlock_range,
5470 .push_mand_locks = smb2_push_mandatory_locks,
5471 .get_lease_key = smb2_get_lease_key,
5472 .set_lease_key = smb2_set_lease_key,
5473 .new_lease_key = smb2_new_lease_key,
5474 .generate_signingkey = generate_smb30signingkey,
5475 .calc_signature = smb3_calc_signature,
5476 .set_integrity = smb3_set_integrity,
5477 .is_read_op = smb21_is_read_op,
5478 .set_oplock_level = smb3_set_oplock_level,
5479 .create_lease_buf = smb3_create_lease_buf,
5480 .parse_lease_buf = smb3_parse_lease_buf,
5481 .copychunk_range = smb2_copychunk_range,
5482 .duplicate_extents = smb2_duplicate_extents,
5483 .validate_negotiate = smb3_validate_negotiate,
5484 .wp_retry_size = smb2_wp_retry_size,
5485 .dir_needs_close = smb2_dir_needs_close,
5486 .fallocate = smb3_fallocate,
5487 .enum_snapshots = smb3_enum_snapshots,
5488 .notify = smb3_notify,
5489 .init_transform_rq = smb3_init_transform_rq,
5490 .is_transform_hdr = smb3_is_transform_hdr,
5491 .receive_transform = smb3_receive_transform,
5492 .get_dfs_refer = smb2_get_dfs_refer,
5493 .select_sectype = smb2_select_sectype,
5494 #ifdef CONFIG_CIFS_XATTR
5495 .query_all_EAs = smb2_query_eas,
5496 .set_EA = smb2_set_ea,
5497 #endif /* CIFS_XATTR */
5498 .get_acl = get_smb2_acl,
5499 .get_acl_by_fid = get_smb2_acl_by_fid,
5500 .set_acl = set_smb2_acl,
5501 .next_header = smb2_next_header,
5502 .ioctl_query_info = smb2_ioctl_query_info,
5503 .make_node = smb2_make_node,
5504 .fiemap = smb3_fiemap,
5505 .llseek = smb3_llseek,
5506 .is_status_io_timeout = smb2_is_status_io_timeout,
5507 .is_network_name_deleted = smb2_is_network_name_deleted,
5510 struct smb_version_operations smb311_operations = {
5511 .compare_fids = smb2_compare_fids,
5512 .setup_request = smb2_setup_request,
5513 .setup_async_request = smb2_setup_async_request,
5514 .check_receive = smb2_check_receive,
5515 .add_credits = smb2_add_credits,
5516 .set_credits = smb2_set_credits,
5517 .get_credits_field = smb2_get_credits_field,
5518 .get_credits = smb2_get_credits,
5519 .wait_mtu_credits = smb2_wait_mtu_credits,
5520 .adjust_credits = smb2_adjust_credits,
5521 .get_next_mid = smb2_get_next_mid,
5522 .revert_current_mid = smb2_revert_current_mid,
5523 .read_data_offset = smb2_read_data_offset,
5524 .read_data_length = smb2_read_data_length,
5525 .map_error = map_smb2_to_linux_error,
5526 .find_mid = smb2_find_mid,
5527 .check_message = smb2_check_message,
5528 .dump_detail = smb2_dump_detail,
5529 .clear_stats = smb2_clear_stats,
5530 .print_stats = smb2_print_stats,
5531 .dump_share_caps = smb2_dump_share_caps,
5532 .is_oplock_break = smb2_is_valid_oplock_break,
5533 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5534 .downgrade_oplock = smb3_downgrade_oplock,
5535 .need_neg = smb2_need_neg,
5536 .negotiate = smb2_negotiate,
5537 .negotiate_wsize = smb3_negotiate_wsize,
5538 .negotiate_rsize = smb3_negotiate_rsize,
5539 .sess_setup = SMB2_sess_setup,
5540 .logoff = SMB2_logoff,
5541 .tree_connect = SMB2_tcon,
5542 .tree_disconnect = SMB2_tdis,
5543 .qfs_tcon = smb3_qfs_tcon,
5544 .is_path_accessible = smb2_is_path_accessible,
5545 .can_echo = smb2_can_echo,
5547 .query_path_info = smb2_query_path_info,
5548 .query_reparse_tag = smb2_query_reparse_tag,
5549 .get_srv_inum = smb2_get_srv_inum,
5550 .query_file_info = smb2_query_file_info,
5551 .set_path_size = smb2_set_path_size,
5552 .set_file_size = smb2_set_file_size,
5553 .set_file_info = smb2_set_file_info,
5554 .set_compression = smb2_set_compression,
5555 .mkdir = smb2_mkdir,
5556 .mkdir_setinfo = smb2_mkdir_setinfo,
5557 .posix_mkdir = smb311_posix_mkdir,
5558 .rmdir = smb2_rmdir,
5559 .unlink = smb2_unlink,
5560 .rename = smb2_rename_path,
5561 .create_hardlink = smb2_create_hardlink,
5562 .query_symlink = smb2_query_symlink,
5563 .query_mf_symlink = smb3_query_mf_symlink,
5564 .create_mf_symlink = smb3_create_mf_symlink,
5565 .open = smb2_open_file,
5566 .set_fid = smb2_set_fid,
5567 .close = smb2_close_file,
5568 .close_getattr = smb2_close_getattr,
5569 .flush = smb2_flush_file,
5570 .async_readv = smb2_async_readv,
5571 .async_writev = smb2_async_writev,
5572 .sync_read = smb2_sync_read,
5573 .sync_write = smb2_sync_write,
5574 .query_dir_first = smb2_query_dir_first,
5575 .query_dir_next = smb2_query_dir_next,
5576 .close_dir = smb2_close_dir,
5577 .calc_smb_size = smb2_calc_size,
5578 .is_status_pending = smb2_is_status_pending,
5579 .is_session_expired = smb2_is_session_expired,
5580 .oplock_response = smb2_oplock_response,
5581 .queryfs = smb311_queryfs,
5582 .mand_lock = smb2_mand_lock,
5583 .mand_unlock_range = smb2_unlock_range,
5584 .push_mand_locks = smb2_push_mandatory_locks,
5585 .get_lease_key = smb2_get_lease_key,
5586 .set_lease_key = smb2_set_lease_key,
5587 .new_lease_key = smb2_new_lease_key,
5588 .generate_signingkey = generate_smb311signingkey,
5589 .calc_signature = smb3_calc_signature,
5590 .set_integrity = smb3_set_integrity,
5591 .is_read_op = smb21_is_read_op,
5592 .set_oplock_level = smb3_set_oplock_level,
5593 .create_lease_buf = smb3_create_lease_buf,
5594 .parse_lease_buf = smb3_parse_lease_buf,
5595 .copychunk_range = smb2_copychunk_range,
5596 .duplicate_extents = smb2_duplicate_extents,
5597 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
5598 .wp_retry_size = smb2_wp_retry_size,
5599 .dir_needs_close = smb2_dir_needs_close,
5600 .fallocate = smb3_fallocate,
5601 .enum_snapshots = smb3_enum_snapshots,
5602 .notify = smb3_notify,
5603 .init_transform_rq = smb3_init_transform_rq,
5604 .is_transform_hdr = smb3_is_transform_hdr,
5605 .receive_transform = smb3_receive_transform,
5606 .get_dfs_refer = smb2_get_dfs_refer,
5607 .select_sectype = smb2_select_sectype,
5608 #ifdef CONFIG_CIFS_XATTR
5609 .query_all_EAs = smb2_query_eas,
5610 .set_EA = smb2_set_ea,
5611 #endif /* CIFS_XATTR */
5612 .get_acl = get_smb2_acl,
5613 .get_acl_by_fid = get_smb2_acl_by_fid,
5614 .set_acl = set_smb2_acl,
5615 .next_header = smb2_next_header,
5616 .ioctl_query_info = smb2_ioctl_query_info,
5617 .make_node = smb2_make_node,
5618 .fiemap = smb3_fiemap,
5619 .llseek = smb3_llseek,
5620 .is_status_io_timeout = smb2_is_status_io_timeout,
5621 .is_network_name_deleted = smb2_is_network_name_deleted,
5624 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5625 struct smb_version_values smb20_values = {
5626 .version_string = SMB20_VERSION_STRING,
5627 .protocol_id = SMB20_PROT_ID,
5628 .req_capabilities = 0, /* MBZ */
5629 .large_lock_type = 0,
5630 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5631 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5632 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5633 .header_size = sizeof(struct smb2_hdr),
5634 .header_preamble_size = 0,
5635 .max_header_size = MAX_SMB2_HDR_SIZE,
5636 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5637 .lock_cmd = SMB2_LOCK,
5639 .cap_nt_find = SMB2_NT_FIND,
5640 .cap_large_files = SMB2_LARGE_FILES,
5641 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5642 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5643 .create_lease_size = sizeof(struct create_lease),
5645 #endif /* ALLOW_INSECURE_LEGACY */
5647 struct smb_version_values smb21_values = {
5648 .version_string = SMB21_VERSION_STRING,
5649 .protocol_id = SMB21_PROT_ID,
5650 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
5651 .large_lock_type = 0,
5652 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5653 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5654 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5655 .header_size = sizeof(struct smb2_hdr),
5656 .header_preamble_size = 0,
5657 .max_header_size = MAX_SMB2_HDR_SIZE,
5658 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5659 .lock_cmd = SMB2_LOCK,
5661 .cap_nt_find = SMB2_NT_FIND,
5662 .cap_large_files = SMB2_LARGE_FILES,
5663 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5664 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5665 .create_lease_size = sizeof(struct create_lease),
5668 struct smb_version_values smb3any_values = {
5669 .version_string = SMB3ANY_VERSION_STRING,
5670 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5671 .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,
5672 .large_lock_type = 0,
5673 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5674 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5675 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5676 .header_size = sizeof(struct smb2_hdr),
5677 .header_preamble_size = 0,
5678 .max_header_size = MAX_SMB2_HDR_SIZE,
5679 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5680 .lock_cmd = SMB2_LOCK,
5682 .cap_nt_find = SMB2_NT_FIND,
5683 .cap_large_files = SMB2_LARGE_FILES,
5684 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5685 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5686 .create_lease_size = sizeof(struct create_lease_v2),
5689 struct smb_version_values smbdefault_values = {
5690 .version_string = SMBDEFAULT_VERSION_STRING,
5691 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5692 .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,
5693 .large_lock_type = 0,
5694 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5695 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5696 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5697 .header_size = sizeof(struct smb2_hdr),
5698 .header_preamble_size = 0,
5699 .max_header_size = MAX_SMB2_HDR_SIZE,
5700 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5701 .lock_cmd = SMB2_LOCK,
5703 .cap_nt_find = SMB2_NT_FIND,
5704 .cap_large_files = SMB2_LARGE_FILES,
5705 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5706 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5707 .create_lease_size = sizeof(struct create_lease_v2),
5710 struct smb_version_values smb30_values = {
5711 .version_string = SMB30_VERSION_STRING,
5712 .protocol_id = SMB30_PROT_ID,
5713 .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,
5714 .large_lock_type = 0,
5715 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5716 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5717 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5718 .header_size = sizeof(struct smb2_hdr),
5719 .header_preamble_size = 0,
5720 .max_header_size = MAX_SMB2_HDR_SIZE,
5721 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5722 .lock_cmd = SMB2_LOCK,
5724 .cap_nt_find = SMB2_NT_FIND,
5725 .cap_large_files = SMB2_LARGE_FILES,
5726 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5727 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5728 .create_lease_size = sizeof(struct create_lease_v2),
5731 struct smb_version_values smb302_values = {
5732 .version_string = SMB302_VERSION_STRING,
5733 .protocol_id = SMB302_PROT_ID,
5734 .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,
5735 .large_lock_type = 0,
5736 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5737 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5738 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5739 .header_size = sizeof(struct smb2_hdr),
5740 .header_preamble_size = 0,
5741 .max_header_size = MAX_SMB2_HDR_SIZE,
5742 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5743 .lock_cmd = SMB2_LOCK,
5745 .cap_nt_find = SMB2_NT_FIND,
5746 .cap_large_files = SMB2_LARGE_FILES,
5747 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5748 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5749 .create_lease_size = sizeof(struct create_lease_v2),
5752 struct smb_version_values smb311_values = {
5753 .version_string = SMB311_VERSION_STRING,
5754 .protocol_id = SMB311_PROT_ID,
5755 .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,
5756 .large_lock_type = 0,
5757 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5758 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5759 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5760 .header_size = sizeof(struct smb2_hdr),
5761 .header_preamble_size = 0,
5762 .max_header_size = MAX_SMB2_HDR_SIZE,
5763 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5764 .lock_cmd = SMB2_LOCK,
5766 .cap_nt_find = SMB2_NT_FIND,
5767 .cap_large_files = SMB2_LARGE_FILES,
5768 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5769 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5770 .create_lease_size = sizeof(struct create_lease_v2),