1 // SPDX-License-Identifier: GPL-2.0
3 * SMB2 version specific operations
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 struct cifs_open_parms oparms;
801 struct cached_fid *cfid;
803 rc = open_cached_dir(xid, tcon, full_path, cifs_sb, true, &cfid);
805 if (cfid->has_lease) {
806 close_cached_dir(cfid);
809 close_cached_dir(cfid);
812 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
817 oparms.desired_access = FILE_READ_ATTRIBUTES;
818 oparms.disposition = FILE_OPEN;
819 oparms.create_options = cifs_create_options(cifs_sb, 0);
821 oparms.reconnect = false;
823 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
830 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
835 static int smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
836 struct cifs_sb_info *cifs_sb, const char *full_path,
837 u64 *uniqueid, struct cifs_open_info_data *data)
839 *uniqueid = le64_to_cpu(data->fi.IndexNumber);
843 static int smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
844 struct cifsFileInfo *cfile, struct cifs_open_info_data *data)
846 struct cifs_fid *fid = &cfile->fid;
848 if (cfile->symlink_target) {
849 data->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
850 if (!data->symlink_target)
853 return SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, &data->fi);
856 #ifdef CONFIG_CIFS_XATTR
858 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
859 struct smb2_file_full_ea_info *src, size_t src_size,
860 const unsigned char *ea_name)
863 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
865 size_t buf_size = dst_size;
866 size_t name_len, value_len, user_name_len;
868 while (src_size > 0) {
869 name_len = (size_t)src->ea_name_length;
870 value_len = (size_t)le16_to_cpu(src->ea_value_length);
875 if (src_size < 8 + name_len + 1 + value_len) {
876 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
881 name = &src->ea_data[0];
882 value = &src->ea_data[src->ea_name_length + 1];
885 if (ea_name_len == name_len &&
886 memcmp(ea_name, name, name_len) == 0) {
890 if (dst_size < value_len) {
894 memcpy(dst, value, value_len);
898 /* 'user.' plus a terminating null */
899 user_name_len = 5 + 1 + name_len;
902 /* skip copy - calc size only */
904 } else if (dst_size >= user_name_len) {
905 dst_size -= user_name_len;
906 memcpy(dst, "user.", 5);
908 memcpy(dst, src->ea_data, name_len);
914 /* stop before overrun buffer */
920 if (!src->next_entry_offset)
923 if (src_size < le32_to_cpu(src->next_entry_offset)) {
924 /* stop before overrun buffer */
928 src_size -= le32_to_cpu(src->next_entry_offset);
929 src = (void *)((char *)src +
930 le32_to_cpu(src->next_entry_offset));
933 /* didn't find the named attribute */
942 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
943 const unsigned char *path, const unsigned char *ea_name,
944 char *ea_data, size_t buf_size,
945 struct cifs_sb_info *cifs_sb)
948 struct kvec rsp_iov = {NULL, 0};
949 int buftype = CIFS_NO_BUFFER;
950 struct smb2_query_info_rsp *rsp;
951 struct smb2_file_full_ea_info *info = NULL;
953 rc = smb2_query_info_compound(xid, tcon, path,
955 FILE_FULL_EA_INFORMATION,
958 MAX_SMB2_CREATE_RESPONSE_SIZE -
959 MAX_SMB2_CLOSE_RESPONSE_SIZE,
960 &rsp_iov, &buftype, cifs_sb);
963 * If ea_name is NULL (listxattr) and there are no EAs,
964 * return 0 as it's not an error. Otherwise, the specified
965 * ea_name was not found.
967 if (!ea_name && rc == -ENODATA)
972 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
973 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
974 le32_to_cpu(rsp->OutputBufferLength),
976 sizeof(struct smb2_file_full_ea_info));
980 info = (struct smb2_file_full_ea_info *)(
981 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
982 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
983 le32_to_cpu(rsp->OutputBufferLength), ea_name);
986 free_rsp_buf(buftype, rsp_iov.iov_base);
992 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
993 const char *path, const char *ea_name, const void *ea_value,
994 const __u16 ea_value_len, const struct nls_table *nls_codepage,
995 struct cifs_sb_info *cifs_sb)
997 struct cifs_ses *ses = tcon->ses;
998 struct TCP_Server_Info *server = cifs_pick_channel(ses);
999 __le16 *utf16_path = NULL;
1000 int ea_name_len = strlen(ea_name);
1001 int flags = CIFS_CP_CREATE_CLOSE_OP;
1003 struct smb_rqst rqst[3];
1004 int resp_buftype[3];
1005 struct kvec rsp_iov[3];
1006 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1007 struct cifs_open_parms oparms;
1008 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1009 struct cifs_fid fid;
1010 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1011 unsigned int size[1];
1013 struct smb2_file_full_ea_info *ea = NULL;
1014 struct kvec close_iov[1];
1015 struct smb2_query_info_rsp *rsp;
1016 int rc, used_len = 0;
1018 if (smb3_encryption_required(tcon))
1019 flags |= CIFS_TRANSFORM_REQ;
1021 if (ea_name_len > 255)
1024 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1028 memset(rqst, 0, sizeof(rqst));
1029 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1030 memset(rsp_iov, 0, sizeof(rsp_iov));
1032 if (ses->server->ops->query_all_EAs) {
1034 rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1040 /* If we are adding a attribute we should first check
1041 * if there will be enough space available to store
1042 * the new EA. If not we should not add it since we
1043 * would not be able to even read the EAs back.
1045 rc = smb2_query_info_compound(xid, tcon, path,
1047 FILE_FULL_EA_INFORMATION,
1050 MAX_SMB2_CREATE_RESPONSE_SIZE -
1051 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1052 &rsp_iov[1], &resp_buftype[1], cifs_sb);
1054 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1055 used_len = le32_to_cpu(rsp->OutputBufferLength);
1057 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1058 resp_buftype[1] = CIFS_NO_BUFFER;
1059 memset(&rsp_iov[1], 0, sizeof(rsp_iov[1]));
1062 /* Use a fudge factor of 256 bytes in case we collide
1063 * with a different set_EAs command.
1065 if(CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1066 MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 <
1067 used_len + ea_name_len + ea_value_len + 1) {
1075 memset(&open_iov, 0, sizeof(open_iov));
1076 rqst[0].rq_iov = open_iov;
1077 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1079 memset(&oparms, 0, sizeof(oparms));
1081 oparms.desired_access = FILE_WRITE_EA;
1082 oparms.disposition = FILE_OPEN;
1083 oparms.create_options = cifs_create_options(cifs_sb, 0);
1085 oparms.reconnect = false;
1087 rc = SMB2_open_init(tcon, server,
1088 &rqst[0], &oplock, &oparms, utf16_path);
1091 smb2_set_next_command(tcon, &rqst[0]);
1095 memset(&si_iov, 0, sizeof(si_iov));
1096 rqst[1].rq_iov = si_iov;
1097 rqst[1].rq_nvec = 1;
1099 len = sizeof(*ea) + ea_name_len + ea_value_len + 1;
1100 ea = kzalloc(len, GFP_KERNEL);
1106 ea->ea_name_length = ea_name_len;
1107 ea->ea_value_length = cpu_to_le16(ea_value_len);
1108 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
1109 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
1114 rc = SMB2_set_info_init(tcon, server,
1115 &rqst[1], COMPOUND_FID,
1116 COMPOUND_FID, current->tgid,
1117 FILE_FULL_EA_INFORMATION,
1118 SMB2_O_INFO_FILE, 0, data, size);
1119 smb2_set_next_command(tcon, &rqst[1]);
1120 smb2_set_related(&rqst[1]);
1124 memset(&close_iov, 0, sizeof(close_iov));
1125 rqst[2].rq_iov = close_iov;
1126 rqst[2].rq_nvec = 1;
1127 rc = SMB2_close_init(tcon, server,
1128 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1129 smb2_set_related(&rqst[2]);
1131 rc = compound_send_recv(xid, ses, server,
1133 resp_buftype, rsp_iov);
1134 /* no need to bump num_remote_opens because handle immediately closed */
1139 SMB2_open_free(&rqst[0]);
1140 SMB2_set_info_free(&rqst[1]);
1141 SMB2_close_free(&rqst[2]);
1142 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1143 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1144 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1150 smb2_can_echo(struct TCP_Server_Info *server)
1152 return server->echoes;
1156 smb2_clear_stats(struct cifs_tcon *tcon)
1160 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1161 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1162 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1167 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1169 seq_puts(m, "\n\tShare Capabilities:");
1170 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1171 seq_puts(m, " DFS,");
1172 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1173 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1174 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1175 seq_puts(m, " SCALEOUT,");
1176 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1177 seq_puts(m, " CLUSTER,");
1178 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1179 seq_puts(m, " ASYMMETRIC,");
1180 if (tcon->capabilities == 0)
1181 seq_puts(m, " None");
1182 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1183 seq_puts(m, " Aligned,");
1184 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1185 seq_puts(m, " Partition Aligned,");
1186 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1187 seq_puts(m, " SSD,");
1188 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1189 seq_puts(m, " TRIM-support,");
1191 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1192 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1193 if (tcon->perf_sector_size)
1194 seq_printf(m, "\tOptimal sector size: 0x%x",
1195 tcon->perf_sector_size);
1196 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1200 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1202 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1203 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1206 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1207 * totals (requests sent) since those SMBs are per-session not per tcon
1209 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1210 (long long)(tcon->bytes_read),
1211 (long long)(tcon->bytes_written));
1212 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1213 atomic_read(&tcon->num_local_opens),
1214 atomic_read(&tcon->num_remote_opens));
1215 seq_printf(m, "\nTreeConnects: %d total %d failed",
1216 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1217 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1218 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1219 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1220 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1221 seq_printf(m, "\nCreates: %d total %d failed",
1222 atomic_read(&sent[SMB2_CREATE_HE]),
1223 atomic_read(&failed[SMB2_CREATE_HE]));
1224 seq_printf(m, "\nCloses: %d total %d failed",
1225 atomic_read(&sent[SMB2_CLOSE_HE]),
1226 atomic_read(&failed[SMB2_CLOSE_HE]));
1227 seq_printf(m, "\nFlushes: %d total %d failed",
1228 atomic_read(&sent[SMB2_FLUSH_HE]),
1229 atomic_read(&failed[SMB2_FLUSH_HE]));
1230 seq_printf(m, "\nReads: %d total %d failed",
1231 atomic_read(&sent[SMB2_READ_HE]),
1232 atomic_read(&failed[SMB2_READ_HE]));
1233 seq_printf(m, "\nWrites: %d total %d failed",
1234 atomic_read(&sent[SMB2_WRITE_HE]),
1235 atomic_read(&failed[SMB2_WRITE_HE]));
1236 seq_printf(m, "\nLocks: %d total %d failed",
1237 atomic_read(&sent[SMB2_LOCK_HE]),
1238 atomic_read(&failed[SMB2_LOCK_HE]));
1239 seq_printf(m, "\nIOCTLs: %d total %d failed",
1240 atomic_read(&sent[SMB2_IOCTL_HE]),
1241 atomic_read(&failed[SMB2_IOCTL_HE]));
1242 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1243 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1244 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1245 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1246 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1247 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1248 seq_printf(m, "\nQueryInfos: %d total %d failed",
1249 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1250 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1251 seq_printf(m, "\nSetInfos: %d total %d failed",
1252 atomic_read(&sent[SMB2_SET_INFO_HE]),
1253 atomic_read(&failed[SMB2_SET_INFO_HE]));
1254 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1255 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1256 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1260 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1262 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1263 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1265 cfile->fid.persistent_fid = fid->persistent_fid;
1266 cfile->fid.volatile_fid = fid->volatile_fid;
1267 cfile->fid.access = fid->access;
1268 #ifdef CONFIG_CIFS_DEBUG2
1269 cfile->fid.mid = fid->mid;
1270 #endif /* CIFS_DEBUG2 */
1271 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1273 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1274 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1278 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1279 struct cifs_fid *fid)
1281 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1285 smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon,
1286 struct cifsFileInfo *cfile)
1288 struct smb2_file_network_open_info file_inf;
1289 struct inode *inode;
1292 rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid,
1293 cfile->fid.volatile_fid, &file_inf);
1297 inode = d_inode(cfile->dentry);
1299 spin_lock(&inode->i_lock);
1300 CIFS_I(inode)->time = jiffies;
1302 /* Creation time should not need to be updated on close */
1303 if (file_inf.LastWriteTime)
1304 inode->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime);
1305 if (file_inf.ChangeTime)
1306 inode->i_ctime = cifs_NTtimeToUnix(file_inf.ChangeTime);
1307 if (file_inf.LastAccessTime)
1308 inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime);
1311 * i_blocks is not related to (i_size / i_blksize),
1312 * but instead 512 byte (2**9) size is required for
1313 * calculating num blocks.
1315 if (le64_to_cpu(file_inf.AllocationSize) > 4096)
1317 (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9;
1319 /* End of file and Attributes should not have to be updated on close */
1320 spin_unlock(&inode->i_lock);
1324 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1325 u64 persistent_fid, u64 volatile_fid,
1326 struct copychunk_ioctl *pcchunk)
1329 unsigned int ret_data_len;
1330 struct resume_key_req *res_key;
1332 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1333 FSCTL_SRV_REQUEST_RESUME_KEY, NULL, 0 /* no input */,
1334 CIFSMaxBufSize, (char **)&res_key, &ret_data_len);
1336 if (rc == -EOPNOTSUPP) {
1337 pr_warn_once("Server share %s does not support copy range\n", tcon->tree_name);
1338 goto req_res_key_exit;
1340 cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1341 goto req_res_key_exit;
1343 if (ret_data_len < sizeof(struct resume_key_req)) {
1344 cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n");
1346 goto req_res_key_exit;
1348 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1356 struct smb_rqst rqst[3];
1357 struct kvec rsp_iov[3];
1358 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1359 struct kvec qi_iov[1];
1360 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
1361 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1362 struct kvec close_iov[1];
1366 smb2_ioctl_query_info(const unsigned int xid,
1367 struct cifs_tcon *tcon,
1368 struct cifs_sb_info *cifs_sb,
1369 __le16 *path, int is_dir,
1372 struct iqi_vars *vars;
1373 struct smb_rqst *rqst;
1374 struct kvec *rsp_iov;
1375 struct cifs_ses *ses = tcon->ses;
1376 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1377 char __user *arg = (char __user *)p;
1378 struct smb_query_info qi;
1379 struct smb_query_info __user *pqi;
1381 int flags = CIFS_CP_CREATE_CLOSE_OP;
1382 struct smb2_query_info_rsp *qi_rsp = NULL;
1383 struct smb2_ioctl_rsp *io_rsp = NULL;
1384 void *buffer = NULL;
1385 int resp_buftype[3];
1386 struct cifs_open_parms oparms;
1387 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1388 struct cifs_fid fid;
1389 unsigned int size[2];
1391 int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR;
1392 void (*free_req1_func)(struct smb_rqst *r);
1394 vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
1397 rqst = &vars->rqst[0];
1398 rsp_iov = &vars->rsp_iov[0];
1400 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1402 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info))) {
1406 if (qi.output_buffer_length > 1024) {
1411 if (!ses || !server) {
1416 if (smb3_encryption_required(tcon))
1417 flags |= CIFS_TRANSFORM_REQ;
1419 if (qi.output_buffer_length) {
1420 buffer = memdup_user(arg + sizeof(struct smb_query_info), qi.output_buffer_length);
1421 if (IS_ERR(buffer)) {
1422 rc = PTR_ERR(buffer);
1428 rqst[0].rq_iov = &vars->open_iov[0];
1429 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1431 memset(&oparms, 0, sizeof(oparms));
1433 oparms.disposition = FILE_OPEN;
1434 oparms.create_options = cifs_create_options(cifs_sb, create_options);
1436 oparms.reconnect = false;
1438 if (qi.flags & PASSTHRU_FSCTL) {
1439 switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1440 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1441 oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1443 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1444 oparms.desired_access = GENERIC_ALL;
1446 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1447 oparms.desired_access = GENERIC_READ;
1449 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1450 oparms.desired_access = GENERIC_WRITE;
1453 } else if (qi.flags & PASSTHRU_SET_INFO) {
1454 oparms.desired_access = GENERIC_WRITE;
1456 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1459 rc = SMB2_open_init(tcon, server,
1460 &rqst[0], &oplock, &oparms, path);
1462 goto free_output_buffer;
1463 smb2_set_next_command(tcon, &rqst[0]);
1466 if (qi.flags & PASSTHRU_FSCTL) {
1467 /* Can eventually relax perm check since server enforces too */
1468 if (!capable(CAP_SYS_ADMIN)) {
1472 rqst[1].rq_iov = &vars->io_iov[0];
1473 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1475 rc = SMB2_ioctl_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1476 qi.info_type, buffer, qi.output_buffer_length,
1477 CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1478 MAX_SMB2_CLOSE_RESPONSE_SIZE);
1479 free_req1_func = SMB2_ioctl_free;
1480 } else if (qi.flags == PASSTHRU_SET_INFO) {
1481 /* Can eventually relax perm check since server enforces too */
1482 if (!capable(CAP_SYS_ADMIN)) {
1486 if (qi.output_buffer_length < 8) {
1490 rqst[1].rq_iov = &vars->si_iov[0];
1491 rqst[1].rq_nvec = 1;
1493 /* MS-FSCC 2.4.13 FileEndOfFileInformation */
1497 rc = SMB2_set_info_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1498 current->tgid, FILE_END_OF_FILE_INFORMATION,
1499 SMB2_O_INFO_FILE, 0, data, size);
1500 free_req1_func = SMB2_set_info_free;
1501 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1502 rqst[1].rq_iov = &vars->qi_iov[0];
1503 rqst[1].rq_nvec = 1;
1505 rc = SMB2_query_info_init(tcon, server,
1506 &rqst[1], COMPOUND_FID,
1507 COMPOUND_FID, qi.file_info_class,
1508 qi.info_type, qi.additional_information,
1509 qi.input_buffer_length,
1510 qi.output_buffer_length, buffer);
1511 free_req1_func = SMB2_query_info_free;
1512 } else { /* unknown flags */
1513 cifs_tcon_dbg(VFS, "Invalid passthru query flags: 0x%x\n",
1520 smb2_set_next_command(tcon, &rqst[1]);
1521 smb2_set_related(&rqst[1]);
1524 rqst[2].rq_iov = &vars->close_iov[0];
1525 rqst[2].rq_nvec = 1;
1527 rc = SMB2_close_init(tcon, server,
1528 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1531 smb2_set_related(&rqst[2]);
1533 rc = compound_send_recv(xid, ses, server,
1535 resp_buftype, rsp_iov);
1539 /* No need to bump num_remote_opens since handle immediately closed */
1540 if (qi.flags & PASSTHRU_FSCTL) {
1541 pqi = (struct smb_query_info __user *)arg;
1542 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1543 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1544 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1545 if (qi.input_buffer_length > 0 &&
1546 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length
1547 > rsp_iov[1].iov_len) {
1552 if (copy_to_user(&pqi->input_buffer_length,
1553 &qi.input_buffer_length,
1554 sizeof(qi.input_buffer_length))) {
1559 if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1560 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1561 qi.input_buffer_length))
1564 pqi = (struct smb_query_info __user *)arg;
1565 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1566 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1567 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1568 if (copy_to_user(&pqi->input_buffer_length,
1569 &qi.input_buffer_length,
1570 sizeof(qi.input_buffer_length))) {
1575 if (copy_to_user(pqi + 1, qi_rsp->Buffer,
1576 qi.input_buffer_length))
1581 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1582 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1583 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1584 SMB2_close_free(&rqst[2]);
1586 free_req1_func(&rqst[1]);
1588 SMB2_open_free(&rqst[0]);
1597 smb2_copychunk_range(const unsigned int xid,
1598 struct cifsFileInfo *srcfile,
1599 struct cifsFileInfo *trgtfile, u64 src_off,
1600 u64 len, u64 dest_off)
1603 unsigned int ret_data_len;
1604 struct copychunk_ioctl *pcchunk;
1605 struct copychunk_ioctl_rsp *retbuf = NULL;
1606 struct cifs_tcon *tcon;
1607 int chunks_copied = 0;
1608 bool chunk_sizes_updated = false;
1609 ssize_t bytes_written, total_bytes_written = 0;
1611 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1612 if (pcchunk == NULL)
1615 cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
1616 /* Request a key from the server to identify the source of the copy */
1617 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1618 srcfile->fid.persistent_fid,
1619 srcfile->fid.volatile_fid, pcchunk);
1621 /* Note: request_res_key sets res_key null only if rc !=0 */
1625 /* For now array only one chunk long, will make more flexible later */
1626 pcchunk->ChunkCount = cpu_to_le32(1);
1627 pcchunk->Reserved = 0;
1628 pcchunk->Reserved2 = 0;
1630 tcon = tlink_tcon(trgtfile->tlink);
1633 pcchunk->SourceOffset = cpu_to_le64(src_off);
1634 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1636 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
1638 /* Request server copy to target from src identified by key */
1641 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1642 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1643 (char *)pcchunk, sizeof(struct copychunk_ioctl),
1644 CIFSMaxBufSize, (char **)&retbuf, &ret_data_len);
1647 sizeof(struct copychunk_ioctl_rsp)) {
1648 cifs_tcon_dbg(VFS, "Invalid cchunk response size\n");
1652 if (retbuf->TotalBytesWritten == 0) {
1653 cifs_dbg(FYI, "no bytes copied\n");
1658 * Check if server claimed to write more than we asked
1660 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1661 le32_to_cpu(pcchunk->Length)) {
1662 cifs_tcon_dbg(VFS, "Invalid copy chunk response\n");
1666 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1667 cifs_tcon_dbg(VFS, "Invalid num chunks written\n");
1673 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1674 src_off += bytes_written;
1675 dest_off += bytes_written;
1676 len -= bytes_written;
1677 total_bytes_written += bytes_written;
1679 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1680 le32_to_cpu(retbuf->ChunksWritten),
1681 le32_to_cpu(retbuf->ChunkBytesWritten),
1683 } else if (rc == -EINVAL) {
1684 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1687 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1688 le32_to_cpu(retbuf->ChunksWritten),
1689 le32_to_cpu(retbuf->ChunkBytesWritten),
1690 le32_to_cpu(retbuf->TotalBytesWritten));
1693 * Check if this is the first request using these sizes,
1694 * (ie check if copy succeed once with original sizes
1695 * and check if the server gave us different sizes after
1696 * we already updated max sizes on previous request).
1697 * if not then why is the server returning an error now
1699 if ((chunks_copied != 0) || chunk_sizes_updated)
1702 /* Check that server is not asking us to grow size */
1703 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1704 tcon->max_bytes_chunk)
1705 tcon->max_bytes_chunk =
1706 le32_to_cpu(retbuf->ChunkBytesWritten);
1708 goto cchunk_out; /* server gave us bogus size */
1710 /* No need to change MaxChunks since already set to 1 */
1711 chunk_sizes_updated = true;
1722 return total_bytes_written;
1726 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1727 struct cifs_fid *fid)
1729 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1733 smb2_read_data_offset(char *buf)
1735 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1737 return rsp->DataOffset;
1741 smb2_read_data_length(char *buf, bool in_remaining)
1743 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1746 return le32_to_cpu(rsp->DataRemaining);
1748 return le32_to_cpu(rsp->DataLength);
1753 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1754 struct cifs_io_parms *parms, unsigned int *bytes_read,
1755 char **buf, int *buf_type)
1757 parms->persistent_fid = pfid->persistent_fid;
1758 parms->volatile_fid = pfid->volatile_fid;
1759 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1763 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1764 struct cifs_io_parms *parms, unsigned int *written,
1765 struct kvec *iov, unsigned long nr_segs)
1768 parms->persistent_fid = pfid->persistent_fid;
1769 parms->volatile_fid = pfid->volatile_fid;
1770 return SMB2_write(xid, parms, written, iov, nr_segs);
1773 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1774 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1775 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1777 struct cifsInodeInfo *cifsi;
1780 cifsi = CIFS_I(inode);
1782 /* if file already sparse don't bother setting sparse again */
1783 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1784 return true; /* already sparse */
1786 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1787 return true; /* already not sparse */
1790 * Can't check for sparse support on share the usual way via the
1791 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1792 * since Samba server doesn't set the flag on the share, yet
1793 * supports the set sparse FSCTL and returns sparse correctly
1794 * in the file attributes. If we fail setting sparse though we
1795 * mark that server does not support sparse files for this share
1796 * to avoid repeatedly sending the unsupported fsctl to server
1797 * if the file is repeatedly extended.
1799 if (tcon->broken_sparse_sup)
1802 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1803 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1804 &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
1806 tcon->broken_sparse_sup = true;
1807 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1812 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1814 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1820 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1821 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1823 __le64 eof = cpu_to_le64(size);
1824 struct inode *inode;
1827 * If extending file more than one page make sparse. Many Linux fs
1828 * make files sparse by default when extending via ftruncate
1830 inode = d_inode(cfile->dentry);
1832 if (!set_alloc && (size > inode->i_size + 8192)) {
1833 __u8 set_sparse = 1;
1835 /* whether set sparse succeeds or not, extend the file */
1836 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1839 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1840 cfile->fid.volatile_fid, cfile->pid, &eof);
1844 smb2_duplicate_extents(const unsigned int xid,
1845 struct cifsFileInfo *srcfile,
1846 struct cifsFileInfo *trgtfile, u64 src_off,
1847 u64 len, u64 dest_off)
1850 unsigned int ret_data_len;
1851 struct inode *inode;
1852 struct duplicate_extents_to_file dup_ext_buf;
1853 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1855 /* server fileays advertise duplicate extent support with this flag */
1856 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1857 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1860 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1861 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1862 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1863 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1864 dup_ext_buf.ByteCount = cpu_to_le64(len);
1865 cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
1866 src_off, dest_off, len);
1868 inode = d_inode(trgtfile->dentry);
1869 if (inode->i_size < dest_off + len) {
1870 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1872 goto duplicate_extents_out;
1875 * Although also could set plausible allocation size (i_blocks)
1876 * here in addition to setting the file size, in reflink
1877 * it is likely that the target file is sparse. Its allocation
1878 * size will be queried on next revalidate, but it is important
1879 * to make sure that file's cached size is updated immediately
1881 cifs_setsize(inode, dest_off + len);
1883 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1884 trgtfile->fid.volatile_fid,
1885 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1886 (char *)&dup_ext_buf,
1887 sizeof(struct duplicate_extents_to_file),
1888 CIFSMaxBufSize, NULL,
1891 if (ret_data_len > 0)
1892 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
1894 duplicate_extents_out:
1899 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1900 struct cifsFileInfo *cfile)
1902 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1903 cfile->fid.volatile_fid);
1907 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
1908 struct cifsFileInfo *cfile)
1910 struct fsctl_set_integrity_information_req integr_info;
1911 unsigned int ret_data_len;
1913 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
1914 integr_info.Flags = 0;
1915 integr_info.Reserved = 0;
1917 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1918 cfile->fid.volatile_fid,
1919 FSCTL_SET_INTEGRITY_INFORMATION,
1920 (char *)&integr_info,
1921 sizeof(struct fsctl_set_integrity_information_req),
1922 CIFSMaxBufSize, NULL,
1927 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
1928 #define GMT_TOKEN_SIZE 50
1930 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
1933 * Input buffer contains (empty) struct smb_snapshot array with size filled in
1934 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
1937 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
1938 struct cifsFileInfo *cfile, void __user *ioc_buf)
1940 char *retbuf = NULL;
1941 unsigned int ret_data_len = 0;
1943 u32 max_response_size;
1944 struct smb_snapshot_array snapshot_in;
1947 * On the first query to enumerate the list of snapshots available
1948 * for this volume the buffer begins with 0 (number of snapshots
1949 * which can be returned is zero since at that point we do not know
1950 * how big the buffer needs to be). On the second query,
1951 * it (ret_data_len) is set to number of snapshots so we can
1952 * know to set the maximum response size larger (see below).
1954 if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
1958 * Note that for snapshot queries that servers like Azure expect that
1959 * the first query be minimal size (and just used to get the number/size
1960 * of previous versions) so response size must be specified as EXACTLY
1961 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
1964 if (ret_data_len == 0)
1965 max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
1967 max_response_size = CIFSMaxBufSize;
1969 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1970 cfile->fid.volatile_fid,
1971 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
1972 NULL, 0 /* no input data */, max_response_size,
1975 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
1980 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
1982 if (copy_from_user(&snapshot_in, ioc_buf,
1983 sizeof(struct smb_snapshot_array))) {
1990 * Check for min size, ie not large enough to fit even one GMT
1991 * token (snapshot). On the first ioctl some users may pass in
1992 * smaller size (or zero) to simply get the size of the array
1993 * so the user space caller can allocate sufficient memory
1994 * and retry the ioctl again with larger array size sufficient
1995 * to hold all of the snapshot GMT tokens on the second try.
1997 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
1998 ret_data_len = sizeof(struct smb_snapshot_array);
2001 * We return struct SRV_SNAPSHOT_ARRAY, followed by
2002 * the snapshot array (of 50 byte GMT tokens) each
2003 * representing an available previous version of the data
2005 if (ret_data_len > (snapshot_in.snapshot_array_size +
2006 sizeof(struct smb_snapshot_array)))
2007 ret_data_len = snapshot_in.snapshot_array_size +
2008 sizeof(struct smb_snapshot_array);
2010 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
2021 smb3_notify(const unsigned int xid, struct file *pfile,
2022 void __user *ioc_buf, bool return_changes)
2024 struct smb3_notify_info notify;
2025 struct smb3_notify_info __user *pnotify_buf;
2026 struct dentry *dentry = pfile->f_path.dentry;
2027 struct inode *inode = file_inode(pfile);
2028 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2029 struct cifs_open_parms oparms;
2030 struct cifs_fid fid;
2031 struct cifs_tcon *tcon;
2032 const unsigned char *path;
2033 char *returned_ioctl_info = NULL;
2034 void *page = alloc_dentry_path();
2035 __le16 *utf16_path = NULL;
2036 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2040 path = build_path_from_dentry(dentry, page);
2046 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2047 if (utf16_path == NULL) {
2052 if (return_changes) {
2053 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify_info))) {
2058 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify))) {
2062 notify.data_len = 0;
2065 tcon = cifs_sb_master_tcon(cifs_sb);
2067 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
2068 oparms.disposition = FILE_OPEN;
2069 oparms.create_options = cifs_create_options(cifs_sb, 0);
2071 oparms.reconnect = false;
2073 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
2078 rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid,
2079 notify.watch_tree, notify.completion_filter,
2080 notify.data_len, &returned_ioctl_info, &ret_len);
2082 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2084 cifs_dbg(FYI, "change notify for path %s rc %d\n", path, rc);
2085 if (return_changes && (ret_len > 0) && (notify.data_len > 0)) {
2086 if (ret_len > notify.data_len)
2087 ret_len = notify.data_len;
2088 pnotify_buf = (struct smb3_notify_info __user *)ioc_buf;
2089 if (copy_to_user(pnotify_buf->notify_data, returned_ioctl_info, ret_len))
2091 else if (copy_to_user(&pnotify_buf->data_len, &ret_len, sizeof(ret_len)))
2094 kfree(returned_ioctl_info);
2096 free_dentry_path(page);
2102 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
2103 const char *path, struct cifs_sb_info *cifs_sb,
2104 struct cifs_fid *fid, __u16 search_flags,
2105 struct cifs_search_info *srch_inf)
2108 struct smb_rqst rqst[2];
2109 struct kvec rsp_iov[2];
2110 int resp_buftype[2];
2111 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2112 struct kvec qd_iov[SMB2_QUERY_DIRECTORY_IOV_SIZE];
2114 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2115 struct cifs_open_parms oparms;
2116 struct smb2_query_directory_rsp *qd_rsp = NULL;
2117 struct smb2_create_rsp *op_rsp = NULL;
2118 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2119 int retry_count = 0;
2121 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2125 if (smb3_encryption_required(tcon))
2126 flags |= CIFS_TRANSFORM_REQ;
2128 memset(rqst, 0, sizeof(rqst));
2129 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
2130 memset(rsp_iov, 0, sizeof(rsp_iov));
2133 memset(&open_iov, 0, sizeof(open_iov));
2134 rqst[0].rq_iov = open_iov;
2135 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2138 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
2139 oparms.disposition = FILE_OPEN;
2140 oparms.create_options = cifs_create_options(cifs_sb, 0);
2142 oparms.reconnect = false;
2144 rc = SMB2_open_init(tcon, server,
2145 &rqst[0], &oplock, &oparms, utf16_path);
2148 smb2_set_next_command(tcon, &rqst[0]);
2150 /* Query directory */
2151 srch_inf->entries_in_buffer = 0;
2152 srch_inf->index_of_last_entry = 2;
2154 memset(&qd_iov, 0, sizeof(qd_iov));
2155 rqst[1].rq_iov = qd_iov;
2156 rqst[1].rq_nvec = SMB2_QUERY_DIRECTORY_IOV_SIZE;
2158 rc = SMB2_query_directory_init(xid, tcon, server,
2160 COMPOUND_FID, COMPOUND_FID,
2161 0, srch_inf->info_level);
2165 smb2_set_related(&rqst[1]);
2168 rc = compound_send_recv(xid, tcon->ses, server,
2170 resp_buftype, rsp_iov);
2172 if (rc == -EAGAIN && retry_count++ < 10)
2175 /* If the open failed there is nothing to do */
2176 op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
2177 if (op_rsp == NULL || op_rsp->hdr.Status != STATUS_SUCCESS) {
2178 cifs_dbg(FYI, "query_dir_first: open failed rc=%d\n", rc);
2181 fid->persistent_fid = op_rsp->PersistentFileId;
2182 fid->volatile_fid = op_rsp->VolatileFileId;
2184 /* Anything else than ENODATA means a genuine error */
2185 if (rc && rc != -ENODATA) {
2186 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2187 cifs_dbg(FYI, "query_dir_first: query directory failed rc=%d\n", rc);
2188 trace_smb3_query_dir_err(xid, fid->persistent_fid,
2189 tcon->tid, tcon->ses->Suid, 0, 0, rc);
2193 atomic_inc(&tcon->num_remote_opens);
2195 qd_rsp = (struct smb2_query_directory_rsp *)rsp_iov[1].iov_base;
2196 if (qd_rsp->hdr.Status == STATUS_NO_MORE_FILES) {
2197 trace_smb3_query_dir_done(xid, fid->persistent_fid,
2198 tcon->tid, tcon->ses->Suid, 0, 0);
2199 srch_inf->endOfSearch = true;
2204 rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1],
2207 trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid,
2208 tcon->ses->Suid, 0, 0, rc);
2211 resp_buftype[1] = CIFS_NO_BUFFER;
2213 trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid,
2214 tcon->ses->Suid, 0, srch_inf->entries_in_buffer);
2218 SMB2_open_free(&rqst[0]);
2219 SMB2_query_directory_free(&rqst[1]);
2220 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2221 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2226 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
2227 struct cifs_fid *fid, __u16 search_flags,
2228 struct cifs_search_info *srch_inf)
2230 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
2231 fid->volatile_fid, 0, srch_inf);
2235 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
2236 struct cifs_fid *fid)
2238 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2242 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2243 * the number of credits and return true. Otherwise - return false.
2246 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
2248 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2249 int scredits, in_flight;
2251 if (shdr->Status != STATUS_PENDING)
2254 if (shdr->CreditRequest) {
2255 spin_lock(&server->req_lock);
2256 server->credits += le16_to_cpu(shdr->CreditRequest);
2257 scredits = server->credits;
2258 in_flight = server->in_flight;
2259 spin_unlock(&server->req_lock);
2260 wake_up(&server->request_q);
2262 trace_smb3_pend_credits(server->CurrentMid,
2263 server->conn_id, server->hostname, scredits,
2264 le16_to_cpu(shdr->CreditRequest), in_flight);
2265 cifs_dbg(FYI, "%s: status pending add %u credits total=%d\n",
2266 __func__, le16_to_cpu(shdr->CreditRequest), scredits);
2273 smb2_is_session_expired(char *buf)
2275 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2277 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
2278 shdr->Status != STATUS_USER_SESSION_DELETED)
2281 trace_smb3_ses_expired(le32_to_cpu(shdr->Id.SyncId.TreeId),
2282 le64_to_cpu(shdr->SessionId),
2283 le16_to_cpu(shdr->Command),
2284 le64_to_cpu(shdr->MessageId));
2285 cifs_dbg(FYI, "Session expired or deleted\n");
2291 smb2_is_status_io_timeout(char *buf)
2293 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2295 if (shdr->Status == STATUS_IO_TIMEOUT)
2302 smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server)
2304 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2305 struct TCP_Server_Info *pserver;
2306 struct cifs_ses *ses;
2307 struct cifs_tcon *tcon;
2309 if (shdr->Status != STATUS_NETWORK_NAME_DELETED)
2312 /* If server is a channel, select the primary channel */
2313 pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
2315 spin_lock(&cifs_tcp_ses_lock);
2316 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
2317 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
2318 if (tcon->tid == le32_to_cpu(shdr->Id.SyncId.TreeId)) {
2319 spin_lock(&tcon->tc_lock);
2320 tcon->need_reconnect = true;
2321 spin_unlock(&tcon->tc_lock);
2322 spin_unlock(&cifs_tcp_ses_lock);
2323 pr_warn_once("Server share %s deleted.\n",
2329 spin_unlock(&cifs_tcp_ses_lock);
2333 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
2334 struct cifsInodeInfo *cinode)
2336 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
2337 return SMB2_lease_break(0, tcon, cinode->lease_key,
2338 smb2_get_lease_state(cinode));
2340 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
2342 CIFS_CACHE_READ(cinode) ? 1 : 0);
2346 smb2_set_related(struct smb_rqst *rqst)
2348 struct smb2_hdr *shdr;
2350 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2352 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2355 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2358 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
2361 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
2363 struct smb2_hdr *shdr;
2364 struct cifs_ses *ses = tcon->ses;
2365 struct TCP_Server_Info *server = ses->server;
2366 unsigned long len = smb_rqst_len(server, rqst);
2369 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2371 cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2375 /* SMB headers in a compound are 8 byte aligned. */
2377 /* No padding needed */
2381 num_padding = 8 - (len & 7);
2382 if (!smb3_encryption_required(tcon)) {
2384 * If we do not have encryption then we can just add an extra
2385 * iov for the padding.
2387 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2388 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2393 * We can not add a small padding iov for the encryption case
2394 * because the encryption framework can not handle the padding
2396 * We have to flatten this into a single buffer and add
2397 * the padding to it.
2399 for (i = 1; i < rqst->rq_nvec; i++) {
2400 memcpy(rqst->rq_iov[0].iov_base +
2401 rqst->rq_iov[0].iov_len,
2402 rqst->rq_iov[i].iov_base,
2403 rqst->rq_iov[i].iov_len);
2404 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2406 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2408 rqst->rq_iov[0].iov_len += num_padding;
2414 shdr->NextCommand = cpu_to_le32(len);
2418 * Passes the query info response back to the caller on success.
2419 * Caller need to free this with free_rsp_buf().
2422 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2423 const char *path, u32 desired_access,
2424 u32 class, u32 type, u32 output_len,
2425 struct kvec *rsp, int *buftype,
2426 struct cifs_sb_info *cifs_sb)
2428 struct cifs_ses *ses = tcon->ses;
2429 struct TCP_Server_Info *server = cifs_pick_channel(ses);
2430 int flags = CIFS_CP_CREATE_CLOSE_OP;
2431 struct smb_rqst rqst[3];
2432 int resp_buftype[3];
2433 struct kvec rsp_iov[3];
2434 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2435 struct kvec qi_iov[1];
2436 struct kvec close_iov[1];
2437 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2438 struct cifs_open_parms oparms;
2439 struct cifs_fid fid;
2442 struct cached_fid *cfid = NULL;
2446 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2450 if (smb3_encryption_required(tcon))
2451 flags |= CIFS_TRANSFORM_REQ;
2453 memset(rqst, 0, sizeof(rqst));
2454 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2455 memset(rsp_iov, 0, sizeof(rsp_iov));
2458 * We can only call this for things we know are directories.
2460 if (!strcmp(path, ""))
2461 open_cached_dir(xid, tcon, path, cifs_sb, false,
2462 &cfid); /* cfid null if open dir failed */
2464 memset(&open_iov, 0, sizeof(open_iov));
2465 rqst[0].rq_iov = open_iov;
2466 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2469 oparms.desired_access = desired_access;
2470 oparms.disposition = FILE_OPEN;
2471 oparms.create_options = cifs_create_options(cifs_sb, 0);
2473 oparms.reconnect = false;
2475 rc = SMB2_open_init(tcon, server,
2476 &rqst[0], &oplock, &oparms, utf16_path);
2479 smb2_set_next_command(tcon, &rqst[0]);
2481 memset(&qi_iov, 0, sizeof(qi_iov));
2482 rqst[1].rq_iov = qi_iov;
2483 rqst[1].rq_nvec = 1;
2486 rc = SMB2_query_info_init(tcon, server,
2488 cfid->fid.persistent_fid,
2489 cfid->fid.volatile_fid,
2494 rc = SMB2_query_info_init(tcon, server,
2505 smb2_set_next_command(tcon, &rqst[1]);
2506 smb2_set_related(&rqst[1]);
2509 memset(&close_iov, 0, sizeof(close_iov));
2510 rqst[2].rq_iov = close_iov;
2511 rqst[2].rq_nvec = 1;
2513 rc = SMB2_close_init(tcon, server,
2514 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2517 smb2_set_related(&rqst[2]);
2520 rc = compound_send_recv(xid, ses, server,
2522 &resp_buftype[1], &rsp_iov[1]);
2524 rc = compound_send_recv(xid, ses, server,
2526 resp_buftype, rsp_iov);
2529 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2530 if (rc == -EREMCHG) {
2531 tcon->need_reconnect = true;
2532 pr_warn_once("server share %s deleted\n",
2538 *buftype = resp_buftype[1];
2542 SMB2_open_free(&rqst[0]);
2543 SMB2_query_info_free(&rqst[1]);
2544 SMB2_close_free(&rqst[2]);
2545 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2546 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2548 close_cached_dir(cfid);
2553 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2554 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2556 struct smb2_query_info_rsp *rsp;
2557 struct smb2_fs_full_size_info *info = NULL;
2558 struct kvec rsp_iov = {NULL, 0};
2559 int buftype = CIFS_NO_BUFFER;
2563 rc = smb2_query_info_compound(xid, tcon, "",
2564 FILE_READ_ATTRIBUTES,
2565 FS_FULL_SIZE_INFORMATION,
2566 SMB2_O_INFO_FILESYSTEM,
2567 sizeof(struct smb2_fs_full_size_info),
2568 &rsp_iov, &buftype, cifs_sb);
2572 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2573 buf->f_type = SMB2_SUPER_MAGIC;
2574 info = (struct smb2_fs_full_size_info *)(
2575 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2576 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2577 le32_to_cpu(rsp->OutputBufferLength),
2579 sizeof(struct smb2_fs_full_size_info));
2581 smb2_copy_fs_info_to_kstatfs(info, buf);
2584 free_rsp_buf(buftype, rsp_iov.iov_base);
2589 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2590 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2593 __le16 srch_path = 0; /* Null - open root of share */
2594 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2595 struct cifs_open_parms oparms;
2596 struct cifs_fid fid;
2598 if (!tcon->posix_extensions)
2599 return smb2_queryfs(xid, tcon, cifs_sb, buf);
2602 oparms.desired_access = FILE_READ_ATTRIBUTES;
2603 oparms.disposition = FILE_OPEN;
2604 oparms.create_options = cifs_create_options(cifs_sb, 0);
2606 oparms.reconnect = false;
2608 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
2613 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2614 fid.volatile_fid, buf);
2615 buf->f_type = SMB2_SUPER_MAGIC;
2616 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2621 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2623 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2624 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2628 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2629 __u64 length, __u32 type, int lock, int unlock, bool wait)
2631 if (unlock && !lock)
2632 type = SMB2_LOCKFLAG_UNLOCK;
2633 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2634 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2635 current->tgid, length, offset, type, wait);
2639 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2641 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2645 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2647 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2651 smb2_new_lease_key(struct cifs_fid *fid)
2653 generate_random_uuid(fid->lease_key);
2657 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2658 const char *search_name,
2659 struct dfs_info3_param **target_nodes,
2660 unsigned int *num_of_nodes,
2661 const struct nls_table *nls_codepage, int remap)
2664 __le16 *utf16_path = NULL;
2665 int utf16_path_len = 0;
2666 struct cifs_tcon *tcon;
2667 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2668 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2669 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2670 int retry_count = 0;
2672 cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name);
2675 * Try to use the IPC tcon, otherwise just use any
2677 tcon = ses->tcon_ipc;
2679 spin_lock(&cifs_tcp_ses_lock);
2680 tcon = list_first_entry_or_null(&ses->tcon_list,
2685 spin_unlock(&cifs_tcp_ses_lock);
2689 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2695 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2697 nls_codepage, remap);
2703 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2704 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2710 /* Highest DFS referral version understood */
2711 dfs_req->MaxReferralLevel = DFS_VERSION;
2713 /* Path to resolve in an UTF-16 null-terminated string */
2714 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2717 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2718 FSCTL_DFS_GET_REFERRALS,
2719 (char *)dfs_req, dfs_req_size, CIFSMaxBufSize,
2720 (char **)&dfs_rsp, &dfs_rsp_size);
2721 if (!is_retryable_error(rc))
2723 usleep_range(512, 2048);
2724 } while (++retry_count < 5);
2727 if (!is_retryable_error(rc) && rc != -ENOENT && rc != -EOPNOTSUPP)
2728 cifs_tcon_dbg(VFS, "%s: ioctl error: rc=%d\n", __func__, rc);
2732 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
2733 num_of_nodes, target_nodes,
2734 nls_codepage, remap, search_name,
2735 true /* is_unicode */);
2737 cifs_tcon_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc);
2742 if (tcon && !tcon->ipc) {
2743 /* ipc tcons are not refcounted */
2744 spin_lock(&cifs_tcp_ses_lock);
2746 /* tc_count can never go negative */
2747 WARN_ON(tcon->tc_count < 0);
2748 spin_unlock(&cifs_tcp_ses_lock);
2757 parse_reparse_posix(struct reparse_posix_data *symlink_buf,
2758 u32 plen, char **target_path,
2759 struct cifs_sb_info *cifs_sb)
2763 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
2764 len = le16_to_cpu(symlink_buf->ReparseDataLength);
2766 if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
2767 cifs_dbg(VFS, "%lld not a supported symlink type\n",
2768 le64_to_cpu(symlink_buf->InodeType));
2772 *target_path = cifs_strndup_from_utf16(
2773 symlink_buf->PathBuffer,
2774 len, true, cifs_sb->local_nls);
2775 if (!(*target_path))
2778 convert_delimiter(*target_path, '/');
2779 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2785 parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
2786 u32 plen, char **target_path,
2787 struct cifs_sb_info *cifs_sb)
2789 unsigned int sub_len;
2790 unsigned int sub_offset;
2792 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */
2794 sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset);
2795 sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength);
2796 if (sub_offset + 20 > plen ||
2797 sub_offset + sub_len + 20 > plen) {
2798 cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
2802 *target_path = cifs_strndup_from_utf16(
2803 symlink_buf->PathBuffer + sub_offset,
2804 sub_len, true, cifs_sb->local_nls);
2805 if (!(*target_path))
2808 convert_delimiter(*target_path, '/');
2809 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2815 parse_reparse_point(struct reparse_data_buffer *buf,
2816 u32 plen, char **target_path,
2817 struct cifs_sb_info *cifs_sb)
2819 if (plen < sizeof(struct reparse_data_buffer)) {
2820 cifs_dbg(VFS, "reparse buffer is too small. Must be at least 8 bytes but was %d\n",
2825 if (plen < le16_to_cpu(buf->ReparseDataLength) +
2826 sizeof(struct reparse_data_buffer)) {
2827 cifs_dbg(VFS, "srv returned invalid reparse buf length: %d\n",
2832 /* See MS-FSCC 2.1.2 */
2833 switch (le32_to_cpu(buf->ReparseTag)) {
2834 case IO_REPARSE_TAG_NFS:
2835 return parse_reparse_posix(
2836 (struct reparse_posix_data *)buf,
2837 plen, target_path, cifs_sb);
2838 case IO_REPARSE_TAG_SYMLINK:
2839 return parse_reparse_symlink(
2840 (struct reparse_symlink_data_buffer *)buf,
2841 plen, target_path, cifs_sb);
2843 cifs_dbg(VFS, "srv returned unknown symlink buffer tag:0x%08x\n",
2844 le32_to_cpu(buf->ReparseTag));
2850 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
2851 struct cifs_sb_info *cifs_sb, const char *full_path,
2852 char **target_path, bool is_reparse_point)
2855 __le16 *utf16_path = NULL;
2856 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2857 struct cifs_open_parms oparms;
2858 struct cifs_fid fid;
2859 struct kvec err_iov = {NULL, 0};
2860 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2861 int flags = CIFS_CP_CREATE_CLOSE_OP;
2862 struct smb_rqst rqst[3];
2863 int resp_buftype[3];
2864 struct kvec rsp_iov[3];
2865 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2866 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2867 struct kvec close_iov[1];
2868 struct smb2_create_rsp *create_rsp;
2869 struct smb2_ioctl_rsp *ioctl_rsp;
2870 struct reparse_data_buffer *reparse_buf;
2871 int create_options = is_reparse_point ? OPEN_REPARSE_POINT : 0;
2874 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2876 *target_path = NULL;
2878 if (smb3_encryption_required(tcon))
2879 flags |= CIFS_TRANSFORM_REQ;
2881 memset(rqst, 0, sizeof(rqst));
2882 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2883 memset(rsp_iov, 0, sizeof(rsp_iov));
2885 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
2890 memset(&open_iov, 0, sizeof(open_iov));
2891 rqst[0].rq_iov = open_iov;
2892 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2894 memset(&oparms, 0, sizeof(oparms));
2896 oparms.desired_access = FILE_READ_ATTRIBUTES;
2897 oparms.disposition = FILE_OPEN;
2898 oparms.create_options = cifs_create_options(cifs_sb, create_options);
2900 oparms.reconnect = false;
2902 rc = SMB2_open_init(tcon, server,
2903 &rqst[0], &oplock, &oparms, utf16_path);
2906 smb2_set_next_command(tcon, &rqst[0]);
2910 memset(&io_iov, 0, sizeof(io_iov));
2911 rqst[1].rq_iov = io_iov;
2912 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
2914 rc = SMB2_ioctl_init(tcon, server,
2915 &rqst[1], fid.persistent_fid,
2916 fid.volatile_fid, FSCTL_GET_REPARSE_POINT, NULL, 0,
2918 MAX_SMB2_CREATE_RESPONSE_SIZE -
2919 MAX_SMB2_CLOSE_RESPONSE_SIZE);
2923 smb2_set_next_command(tcon, &rqst[1]);
2924 smb2_set_related(&rqst[1]);
2928 memset(&close_iov, 0, sizeof(close_iov));
2929 rqst[2].rq_iov = close_iov;
2930 rqst[2].rq_nvec = 1;
2932 rc = SMB2_close_init(tcon, server,
2933 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2937 smb2_set_related(&rqst[2]);
2939 rc = compound_send_recv(xid, tcon->ses, server,
2941 resp_buftype, rsp_iov);
2943 create_rsp = rsp_iov[0].iov_base;
2944 if (create_rsp && create_rsp->hdr.Status)
2945 err_iov = rsp_iov[0];
2946 ioctl_rsp = rsp_iov[1].iov_base;
2949 * Open was successful and we got an ioctl response.
2951 if ((rc == 0) && (is_reparse_point)) {
2952 /* See MS-FSCC 2.3.23 */
2954 reparse_buf = (struct reparse_data_buffer *)
2955 ((char *)ioctl_rsp +
2956 le32_to_cpu(ioctl_rsp->OutputOffset));
2957 plen = le32_to_cpu(ioctl_rsp->OutputCount);
2959 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
2960 rsp_iov[1].iov_len) {
2961 cifs_tcon_dbg(VFS, "srv returned invalid ioctl len: %d\n",
2967 rc = parse_reparse_point(reparse_buf, plen, target_path,
2972 if (!rc || !err_iov.iov_base) {
2977 rc = smb2_parse_symlink_response(cifs_sb, &err_iov, target_path);
2980 cifs_dbg(FYI, "query symlink rc %d\n", rc);
2982 SMB2_open_free(&rqst[0]);
2983 SMB2_ioctl_free(&rqst[1]);
2984 SMB2_close_free(&rqst[2]);
2985 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2986 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2987 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2992 smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
2993 struct cifs_sb_info *cifs_sb, const char *full_path,
2997 __le16 *utf16_path = NULL;
2998 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2999 struct cifs_open_parms oparms;
3000 struct cifs_fid fid;
3001 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
3002 int flags = CIFS_CP_CREATE_CLOSE_OP;
3003 struct smb_rqst rqst[3];
3004 int resp_buftype[3];
3005 struct kvec rsp_iov[3];
3006 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
3007 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
3008 struct kvec close_iov[1];
3009 struct smb2_ioctl_rsp *ioctl_rsp;
3010 struct reparse_data_buffer *reparse_buf;
3013 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
3015 if (smb3_encryption_required(tcon))
3016 flags |= CIFS_TRANSFORM_REQ;
3018 memset(rqst, 0, sizeof(rqst));
3019 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
3020 memset(rsp_iov, 0, sizeof(rsp_iov));
3022 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
3027 * setup smb2open - TODO add optimization to call cifs_get_readable_path
3028 * to see if there is a handle already open that we can use
3030 memset(&open_iov, 0, sizeof(open_iov));
3031 rqst[0].rq_iov = open_iov;
3032 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
3034 memset(&oparms, 0, sizeof(oparms));
3036 oparms.desired_access = FILE_READ_ATTRIBUTES;
3037 oparms.disposition = FILE_OPEN;
3038 oparms.create_options = cifs_create_options(cifs_sb, OPEN_REPARSE_POINT);
3040 oparms.reconnect = false;
3042 rc = SMB2_open_init(tcon, server,
3043 &rqst[0], &oplock, &oparms, utf16_path);
3046 smb2_set_next_command(tcon, &rqst[0]);
3050 memset(&io_iov, 0, sizeof(io_iov));
3051 rqst[1].rq_iov = io_iov;
3052 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3054 rc = SMB2_ioctl_init(tcon, server,
3055 &rqst[1], COMPOUND_FID,
3056 COMPOUND_FID, FSCTL_GET_REPARSE_POINT, NULL, 0,
3058 MAX_SMB2_CREATE_RESPONSE_SIZE -
3059 MAX_SMB2_CLOSE_RESPONSE_SIZE);
3063 smb2_set_next_command(tcon, &rqst[1]);
3064 smb2_set_related(&rqst[1]);
3068 memset(&close_iov, 0, sizeof(close_iov));
3069 rqst[2].rq_iov = close_iov;
3070 rqst[2].rq_nvec = 1;
3072 rc = SMB2_close_init(tcon, server,
3073 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3077 smb2_set_related(&rqst[2]);
3079 rc = compound_send_recv(xid, tcon->ses, server,
3081 resp_buftype, rsp_iov);
3083 ioctl_rsp = rsp_iov[1].iov_base;
3086 * Open was successful and we got an ioctl response.
3089 /* See MS-FSCC 2.3.23 */
3091 reparse_buf = (struct reparse_data_buffer *)
3092 ((char *)ioctl_rsp +
3093 le32_to_cpu(ioctl_rsp->OutputOffset));
3094 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3096 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3097 rsp_iov[1].iov_len) {
3098 cifs_tcon_dbg(FYI, "srv returned invalid ioctl len: %d\n",
3103 *tag = le32_to_cpu(reparse_buf->ReparseTag);
3108 SMB2_open_free(&rqst[0]);
3109 SMB2_ioctl_free(&rqst[1]);
3110 SMB2_close_free(&rqst[2]);
3111 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3112 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3113 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3117 static struct cifs_ntsd *
3118 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
3119 const struct cifs_fid *cifsfid, u32 *pacllen, u32 info)
3121 struct cifs_ntsd *pntsd = NULL;
3123 int rc = -EOPNOTSUPP;
3124 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3127 return ERR_CAST(tlink);
3130 cifs_dbg(FYI, "trying to get acl\n");
3132 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
3133 cifsfid->volatile_fid, (void **)&pntsd, pacllen,
3137 cifs_put_tlink(tlink);
3139 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3146 static struct cifs_ntsd *
3147 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
3148 const char *path, u32 *pacllen, u32 info)
3150 struct cifs_ntsd *pntsd = NULL;
3151 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3154 struct cifs_tcon *tcon;
3155 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3156 struct cifs_fid fid;
3157 struct cifs_open_parms oparms;
3160 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
3162 return ERR_CAST(tlink);
3164 tcon = tlink_tcon(tlink);
3167 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3175 oparms.desired_access = READ_CONTROL;
3176 oparms.disposition = FILE_OPEN;
3178 * When querying an ACL, even if the file is a symlink we want to open
3179 * the source not the target, and so the protocol requires that the
3180 * client specify this flag when opening a reparse point
3182 oparms.create_options = cifs_create_options(cifs_sb, 0) | OPEN_REPARSE_POINT;
3184 oparms.reconnect = false;
3186 if (info & SACL_SECINFO)
3187 oparms.desired_access |= SYSTEM_SECURITY;
3189 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
3193 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3194 fid.volatile_fid, (void **)&pntsd, pacllen,
3196 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3199 cifs_put_tlink(tlink);
3202 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3209 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
3210 struct inode *inode, const char *path, int aclflag)
3212 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3214 int rc, access_flags = 0;
3215 struct cifs_tcon *tcon;
3216 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
3217 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3218 struct cifs_fid fid;
3219 struct cifs_open_parms oparms;
3222 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
3224 return PTR_ERR(tlink);
3226 tcon = tlink_tcon(tlink);
3229 if (aclflag & CIFS_ACL_OWNER || aclflag & CIFS_ACL_GROUP)
3230 access_flags |= WRITE_OWNER;
3231 if (aclflag & CIFS_ACL_SACL)
3232 access_flags |= SYSTEM_SECURITY;
3233 if (aclflag & CIFS_ACL_DACL)
3234 access_flags |= WRITE_DAC;
3236 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3244 oparms.desired_access = access_flags;
3245 oparms.create_options = cifs_create_options(cifs_sb, 0);
3246 oparms.disposition = FILE_OPEN;
3249 oparms.reconnect = false;
3251 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
3255 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3256 fid.volatile_fid, pnntsd, acllen, aclflag);
3257 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3260 cifs_put_tlink(tlink);
3265 /* Retrieve an ACL from the server */
3266 static struct cifs_ntsd *
3267 get_smb2_acl(struct cifs_sb_info *cifs_sb,
3268 struct inode *inode, const char *path,
3269 u32 *pacllen, u32 info)
3271 struct cifs_ntsd *pntsd = NULL;
3272 struct cifsFileInfo *open_file = NULL;
3274 if (inode && !(info & SACL_SECINFO))
3275 open_file = find_readable_file(CIFS_I(inode), true);
3276 if (!open_file || (info & SACL_SECINFO))
3277 return get_smb2_acl_by_path(cifs_sb, path, pacllen, info);
3279 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen, info);
3280 cifsFileInfo_put(open_file);
3284 static long smb3_zero_data(struct file *file, struct cifs_tcon *tcon,
3285 loff_t offset, loff_t len, unsigned int xid)
3287 struct cifsFileInfo *cfile = file->private_data;
3288 struct file_zero_data_information fsctl_buf;
3290 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3292 fsctl_buf.FileOffset = cpu_to_le64(offset);
3293 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3295 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3296 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3298 sizeof(struct file_zero_data_information),
3302 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3303 loff_t offset, loff_t len, bool keep_size)
3305 struct cifs_ses *ses = tcon->ses;
3306 struct inode *inode = file_inode(file);
3307 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3308 struct cifsFileInfo *cfile = file->private_data;
3315 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3316 ses->Suid, offset, len);
3319 filemap_invalidate_lock(inode->i_mapping);
3322 * We zero the range through ioctl, so we need remove the page caches
3323 * first, otherwise the data may be inconsistent with the server.
3325 truncate_pagecache_range(inode, offset, offset + len - 1);
3327 /* if file not oplocked can't be sure whether asking to extend size */
3329 if (keep_size == false && !CIFS_CACHE_READ(cifsi))
3330 goto zero_range_exit;
3332 rc = smb3_zero_data(file, tcon, offset, len, xid);
3334 goto zero_range_exit;
3337 * do we also need to change the size of the file?
3339 if (keep_size == false && i_size_read(inode) < offset + len) {
3340 eof = cpu_to_le64(offset + len);
3341 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3342 cfile->fid.volatile_fid, cfile->pid, &eof);
3346 filemap_invalidate_unlock(inode->i_mapping);
3347 inode_unlock(inode);
3350 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
3351 ses->Suid, offset, len, rc);
3353 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
3354 ses->Suid, offset, len);
3358 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
3359 loff_t offset, loff_t len)
3361 struct inode *inode = file_inode(file);
3362 struct cifsFileInfo *cfile = file->private_data;
3363 struct file_zero_data_information fsctl_buf;
3366 __u8 set_sparse = 1;
3371 /* Need to make file sparse, if not already, before freeing range. */
3372 /* Consider adding equivalent for compressed since it could also work */
3373 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
3378 filemap_invalidate_lock(inode->i_mapping);
3380 * We implement the punch hole through ioctl, so we need remove the page
3381 * caches first, otherwise the data may be inconsistent with the server.
3383 truncate_pagecache_range(inode, offset, offset + len - 1);
3385 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3387 fsctl_buf.FileOffset = cpu_to_le64(offset);
3388 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3390 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3391 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3393 sizeof(struct file_zero_data_information),
3394 CIFSMaxBufSize, NULL, NULL);
3395 filemap_invalidate_unlock(inode->i_mapping);
3397 inode_unlock(inode);
3402 static int smb3_simple_fallocate_write_range(unsigned int xid,
3403 struct cifs_tcon *tcon,
3404 struct cifsFileInfo *cfile,
3405 loff_t off, loff_t len,
3408 struct cifs_io_parms io_parms = {0};
3413 io_parms.netfid = cfile->fid.netfid;
3414 io_parms.pid = current->tgid;
3415 io_parms.tcon = tcon;
3416 io_parms.persistent_fid = cfile->fid.persistent_fid;
3417 io_parms.volatile_fid = cfile->fid.volatile_fid;
3420 io_parms.offset = off;
3421 io_parms.length = len;
3422 if (io_parms.length > SMB2_MAX_BUFFER_SIZE)
3423 io_parms.length = SMB2_MAX_BUFFER_SIZE;
3424 /* iov[0] is reserved for smb header */
3425 iov[1].iov_base = buf;
3426 iov[1].iov_len = io_parms.length;
3427 rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
3439 static int smb3_simple_fallocate_range(unsigned int xid,
3440 struct cifs_tcon *tcon,
3441 struct cifsFileInfo *cfile,
3442 loff_t off, loff_t len)
3444 struct file_allocated_range_buffer in_data, *out_data = NULL, *tmp_data;
3450 in_data.file_offset = cpu_to_le64(off);
3451 in_data.length = cpu_to_le64(len);
3452 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3453 cfile->fid.volatile_fid,
3454 FSCTL_QUERY_ALLOCATED_RANGES,
3455 (char *)&in_data, sizeof(in_data),
3456 1024 * sizeof(struct file_allocated_range_buffer),
3457 (char **)&out_data, &out_data_len);
3461 buf = kzalloc(1024 * 1024, GFP_KERNEL);
3467 tmp_data = out_data;
3470 * The rest of the region is unmapped so write it all.
3472 if (out_data_len == 0) {
3473 rc = smb3_simple_fallocate_write_range(xid, tcon,
3474 cfile, off, len, buf);
3478 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3483 if (off < le64_to_cpu(tmp_data->file_offset)) {
3485 * We are at a hole. Write until the end of the region
3486 * or until the next allocated data,
3487 * whichever comes next.
3489 l = le64_to_cpu(tmp_data->file_offset) - off;
3492 rc = smb3_simple_fallocate_write_range(xid, tcon,
3493 cfile, off, l, buf);
3502 * We are at a section of allocated data, just skip forward
3503 * until the end of the data or the end of the region
3504 * we are supposed to fallocate, whichever comes first.
3506 l = le64_to_cpu(tmp_data->length);
3512 tmp_data = &tmp_data[1];
3513 out_data_len -= sizeof(struct file_allocated_range_buffer);
3523 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3524 loff_t off, loff_t len, bool keep_size)
3526 struct inode *inode;
3527 struct cifsInodeInfo *cifsi;
3528 struct cifsFileInfo *cfile = file->private_data;
3529 long rc = -EOPNOTSUPP;
3535 inode = d_inode(cfile->dentry);
3536 cifsi = CIFS_I(inode);
3538 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3539 tcon->ses->Suid, off, len);
3540 /* if file not oplocked can't be sure whether asking to extend size */
3541 if (!CIFS_CACHE_READ(cifsi))
3542 if (keep_size == false) {
3543 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3544 tcon->tid, tcon->ses->Suid, off, len, rc);
3550 * Extending the file
3552 if ((keep_size == false) && i_size_read(inode) < off + len) {
3553 rc = inode_newsize_ok(inode, off + len);
3557 if (cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)
3558 smb2_set_sparse(xid, tcon, cfile, inode, false);
3560 eof = cpu_to_le64(off + len);
3561 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3562 cfile->fid.volatile_fid, cfile->pid, &eof);
3564 cifsi->server_eof = off + len;
3565 cifs_setsize(inode, off + len);
3566 cifs_truncate_page(inode->i_mapping, inode->i_size);
3567 truncate_setsize(inode, off + len);
3573 * Files are non-sparse by default so falloc may be a no-op
3574 * Must check if file sparse. If not sparse, and since we are not
3575 * extending then no need to do anything since file already allocated
3577 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
3582 if (keep_size == true) {
3584 * We can not preallocate pages beyond the end of the file
3587 if (off >= i_size_read(inode)) {
3592 * For fallocates that are partially beyond the end of file,
3593 * clamp len so we only fallocate up to the end of file.
3595 if (off + len > i_size_read(inode)) {
3596 len = i_size_read(inode) - off;
3600 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3602 * At this point, we are trying to fallocate an internal
3603 * regions of a sparse file. Since smb2 does not have a
3604 * fallocate command we have two otions on how to emulate this.
3605 * We can either turn the entire file to become non-sparse
3606 * which we only do if the fallocate is for virtually
3607 * the whole file, or we can overwrite the region with zeroes
3608 * using SMB2_write, which could be prohibitevly expensive
3612 * We are only trying to fallocate a small region so
3613 * just write it with zero.
3615 if (len <= 1024 * 1024) {
3616 rc = smb3_simple_fallocate_range(xid, tcon, cfile,
3622 * Check if falloc starts within first few pages of file
3623 * and ends within a few pages of the end of file to
3624 * ensure that most of file is being forced to be
3625 * fallocated now. If so then setting whole file sparse
3626 * ie potentially making a few extra pages at the beginning
3627 * or end of the file non-sparse via set_sparse is harmless.
3629 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
3635 smb2_set_sparse(xid, tcon, cfile, inode, false);
3640 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3641 tcon->ses->Suid, off, len, rc);
3643 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3644 tcon->ses->Suid, off, len);
3650 static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
3651 loff_t off, loff_t len)
3655 struct inode *inode = file_inode(file);
3656 struct cifsFileInfo *cfile = file->private_data;
3657 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3665 old_eof = i_size_read(inode);
3666 if ((off >= old_eof) ||
3667 off + len >= old_eof) {
3672 filemap_invalidate_lock(inode->i_mapping);
3673 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof - 1);
3677 truncate_pagecache_range(inode, off, old_eof);
3679 rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
3680 old_eof - off - len, off);
3684 eof = cpu_to_le64(old_eof - len);
3685 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3686 cfile->fid.volatile_fid, cfile->pid, &eof);
3692 cifsi->server_eof = i_size_read(inode) - len;
3693 truncate_setsize(inode, cifsi->server_eof);
3694 fscache_resize_cookie(cifs_inode_cookie(inode), cifsi->server_eof);
3696 filemap_invalidate_unlock(inode->i_mapping);
3698 inode_unlock(inode);
3703 static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
3704 loff_t off, loff_t len)
3708 struct cifsFileInfo *cfile = file->private_data;
3709 struct inode *inode = file_inode(file);
3711 __u64 count, old_eof;
3717 old_eof = i_size_read(inode);
3718 if (off >= old_eof) {
3723 count = old_eof - off;
3724 eof = cpu_to_le64(old_eof + len);
3726 filemap_invalidate_lock(inode->i_mapping);
3727 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof + len - 1);
3730 truncate_pagecache_range(inode, off, old_eof);
3732 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3733 cfile->fid.volatile_fid, cfile->pid, &eof);
3737 rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len);
3741 rc = smb3_zero_data(file, tcon, off, len, xid);
3747 filemap_invalidate_unlock(inode->i_mapping);
3749 inode_unlock(inode);
3754 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3756 struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3757 struct cifsInodeInfo *cifsi;
3758 struct inode *inode;
3760 struct file_allocated_range_buffer in_data, *out_data = NULL;
3764 if (whence != SEEK_HOLE && whence != SEEK_DATA)
3765 return generic_file_llseek(file, offset, whence);
3767 inode = d_inode(cfile->dentry);
3768 cifsi = CIFS_I(inode);
3770 if (offset < 0 || offset >= i_size_read(inode))
3775 * We need to be sure that all dirty pages are written as they
3776 * might fill holes on the server.
3777 * Note that we also MUST flush any written pages since at least
3778 * some servers (Windows2016) will not reflect recent writes in
3779 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3781 wrcfile = find_writable_file(cifsi, FIND_WR_ANY);
3783 filemap_write_and_wait(inode->i_mapping);
3784 smb2_flush_file(xid, tcon, &wrcfile->fid);
3785 cifsFileInfo_put(wrcfile);
3788 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3789 if (whence == SEEK_HOLE)
3790 offset = i_size_read(inode);
3794 in_data.file_offset = cpu_to_le64(offset);
3795 in_data.length = cpu_to_le64(i_size_read(inode));
3797 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3798 cfile->fid.volatile_fid,
3799 FSCTL_QUERY_ALLOCATED_RANGES,
3800 (char *)&in_data, sizeof(in_data),
3801 sizeof(struct file_allocated_range_buffer),
3802 (char **)&out_data, &out_data_len);
3808 if (whence == SEEK_HOLE && out_data_len == 0)
3811 if (whence == SEEK_DATA && out_data_len == 0) {
3816 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3820 if (whence == SEEK_DATA) {
3821 offset = le64_to_cpu(out_data->file_offset);
3824 if (offset < le64_to_cpu(out_data->file_offset))
3827 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3833 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3838 static int smb3_fiemap(struct cifs_tcon *tcon,
3839 struct cifsFileInfo *cfile,
3840 struct fiemap_extent_info *fei, u64 start, u64 len)
3843 struct file_allocated_range_buffer in_data, *out_data;
3845 int i, num, rc, flags, last_blob;
3848 rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0);
3854 in_data.file_offset = cpu_to_le64(start);
3855 in_data.length = cpu_to_le64(len);
3857 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3858 cfile->fid.volatile_fid,
3859 FSCTL_QUERY_ALLOCATED_RANGES,
3860 (char *)&in_data, sizeof(in_data),
3861 1024 * sizeof(struct file_allocated_range_buffer),
3862 (char **)&out_data, &out_data_len);
3871 if (out_data_len && out_data_len < sizeof(struct file_allocated_range_buffer)) {
3875 if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3880 num = out_data_len / sizeof(struct file_allocated_range_buffer);
3881 for (i = 0; i < num; i++) {
3883 if (i == num - 1 && last_blob)
3884 flags |= FIEMAP_EXTENT_LAST;
3886 rc = fiemap_fill_next_extent(fei,
3887 le64_to_cpu(out_data[i].file_offset),
3888 le64_to_cpu(out_data[i].file_offset),
3889 le64_to_cpu(out_data[i].length),
3900 next = le64_to_cpu(out_data[num - 1].file_offset) +
3901 le64_to_cpu(out_data[num - 1].length);
3902 len = len - (next - start);
3913 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
3914 loff_t off, loff_t len)
3916 /* KEEP_SIZE already checked for by do_fallocate */
3917 if (mode & FALLOC_FL_PUNCH_HOLE)
3918 return smb3_punch_hole(file, tcon, off, len);
3919 else if (mode & FALLOC_FL_ZERO_RANGE) {
3920 if (mode & FALLOC_FL_KEEP_SIZE)
3921 return smb3_zero_range(file, tcon, off, len, true);
3922 return smb3_zero_range(file, tcon, off, len, false);
3923 } else if (mode == FALLOC_FL_KEEP_SIZE)
3924 return smb3_simple_falloc(file, tcon, off, len, true);
3925 else if (mode == FALLOC_FL_COLLAPSE_RANGE)
3926 return smb3_collapse_range(file, tcon, off, len);
3927 else if (mode == FALLOC_FL_INSERT_RANGE)
3928 return smb3_insert_range(file, tcon, off, len);
3930 return smb3_simple_falloc(file, tcon, off, len, false);
3936 smb2_downgrade_oplock(struct TCP_Server_Info *server,
3937 struct cifsInodeInfo *cinode, __u32 oplock,
3938 unsigned int epoch, bool *purge_cache)
3940 server->ops->set_oplock_level(cinode, oplock, 0, NULL);
3944 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3945 unsigned int epoch, bool *purge_cache);
3948 smb3_downgrade_oplock(struct TCP_Server_Info *server,
3949 struct cifsInodeInfo *cinode, __u32 oplock,
3950 unsigned int epoch, bool *purge_cache)
3952 unsigned int old_state = cinode->oplock;
3953 unsigned int old_epoch = cinode->epoch;
3954 unsigned int new_state;
3956 if (epoch > old_epoch) {
3957 smb21_set_oplock_level(cinode, oplock, 0, NULL);
3958 cinode->epoch = epoch;
3961 new_state = cinode->oplock;
3962 *purge_cache = false;
3964 if ((old_state & CIFS_CACHE_READ_FLG) != 0 &&
3965 (new_state & CIFS_CACHE_READ_FLG) == 0)
3966 *purge_cache = true;
3967 else if (old_state == new_state && (epoch - old_epoch > 1))
3968 *purge_cache = true;
3972 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3973 unsigned int epoch, bool *purge_cache)
3976 cinode->lease_granted = false;
3977 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3979 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
3980 cinode->oplock = CIFS_CACHE_RHW_FLG;
3981 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
3982 &cinode->netfs.inode);
3983 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
3984 cinode->oplock = CIFS_CACHE_RW_FLG;
3985 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
3986 &cinode->netfs.inode);
3987 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
3988 cinode->oplock = CIFS_CACHE_READ_FLG;
3989 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
3990 &cinode->netfs.inode);
3996 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3997 unsigned int epoch, bool *purge_cache)
3999 char message[5] = {0};
4000 unsigned int new_oplock = 0;
4003 cinode->lease_granted = true;
4004 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
4007 /* Check if the server granted an oplock rather than a lease */
4008 if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4009 return smb2_set_oplock_level(cinode, oplock, epoch,
4012 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
4013 new_oplock |= CIFS_CACHE_READ_FLG;
4014 strcat(message, "R");
4016 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
4017 new_oplock |= CIFS_CACHE_HANDLE_FLG;
4018 strcat(message, "H");
4020 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
4021 new_oplock |= CIFS_CACHE_WRITE_FLG;
4022 strcat(message, "W");
4025 strncpy(message, "None", sizeof(message));
4027 cinode->oplock = new_oplock;
4028 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
4029 &cinode->netfs.inode);
4033 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4034 unsigned int epoch, bool *purge_cache)
4036 unsigned int old_oplock = cinode->oplock;
4038 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
4041 *purge_cache = false;
4042 if (old_oplock == CIFS_CACHE_READ_FLG) {
4043 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
4044 (epoch - cinode->epoch > 0))
4045 *purge_cache = true;
4046 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4047 (epoch - cinode->epoch > 1))
4048 *purge_cache = true;
4049 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4050 (epoch - cinode->epoch > 1))
4051 *purge_cache = true;
4052 else if (cinode->oplock == 0 &&
4053 (epoch - cinode->epoch > 0))
4054 *purge_cache = true;
4055 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
4056 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4057 (epoch - cinode->epoch > 0))
4058 *purge_cache = true;
4059 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4060 (epoch - cinode->epoch > 1))
4061 *purge_cache = true;
4063 cinode->epoch = epoch;
4067 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
4069 smb2_is_read_op(__u32 oplock)
4071 return oplock == SMB2_OPLOCK_LEVEL_II;
4073 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
4076 smb21_is_read_op(__u32 oplock)
4078 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
4079 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
4083 map_oplock_to_lease(u8 oplock)
4085 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4086 return SMB2_LEASE_WRITE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE;
4087 else if (oplock == SMB2_OPLOCK_LEVEL_II)
4088 return SMB2_LEASE_READ_CACHING_LE;
4089 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
4090 return SMB2_LEASE_HANDLE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE |
4091 SMB2_LEASE_WRITE_CACHING_LE;
4096 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
4098 struct create_lease *buf;
4100 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
4104 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4105 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4107 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4108 (struct create_lease, lcontext));
4109 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
4110 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4111 (struct create_lease, Name));
4112 buf->ccontext.NameLength = cpu_to_le16(4);
4113 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4122 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
4124 struct create_lease_v2 *buf;
4126 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
4130 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4131 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4133 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4134 (struct create_lease_v2, lcontext));
4135 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
4136 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4137 (struct create_lease_v2, Name));
4138 buf->ccontext.NameLength = cpu_to_le16(4);
4139 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4148 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4150 struct create_lease *lc = (struct create_lease *)buf;
4152 *epoch = 0; /* not used */
4153 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4154 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4155 return le32_to_cpu(lc->lcontext.LeaseState);
4159 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4161 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
4163 *epoch = le16_to_cpu(lc->lcontext.Epoch);
4164 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4165 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4167 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
4168 return le32_to_cpu(lc->lcontext.LeaseState);
4172 smb2_wp_retry_size(struct inode *inode)
4174 return min_t(unsigned int, CIFS_SB(inode->i_sb)->ctx->wsize,
4175 SMB2_MAX_BUFFER_SIZE);
4179 smb2_dir_needs_close(struct cifsFileInfo *cfile)
4181 return !cfile->invalidHandle;
4185 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
4186 struct smb_rqst *old_rq, __le16 cipher_type)
4188 struct smb2_hdr *shdr =
4189 (struct smb2_hdr *)old_rq->rq_iov[0].iov_base;
4191 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
4192 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
4193 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
4194 tr_hdr->Flags = cpu_to_le16(0x01);
4195 if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4196 (cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4197 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4199 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4200 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
4203 /* We can not use the normal sg_set_buf() as we will sometimes pass a
4204 * stack object as buf.
4206 static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
4207 unsigned int buflen)
4211 * VMAP_STACK (at least) puts stack into the vmalloc address space
4213 if (is_vmalloc_addr(buf))
4214 addr = vmalloc_to_page(buf);
4216 addr = virt_to_page(buf);
4217 sg_set_page(sg, addr, buflen, offset_in_page(buf));
4220 /* Assumes the first rqst has a transform header as the first iov.
4222 * rqst[0].rq_iov[0] is transform header
4223 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
4224 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
4226 static struct scatterlist *
4227 init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign)
4229 unsigned int sg_len;
4230 struct scatterlist *sg;
4233 unsigned int idx = 0;
4237 for (i = 0; i < num_rqst; i++)
4238 sg_len += rqst[i].rq_nvec + rqst[i].rq_npages;
4240 sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
4244 sg_init_table(sg, sg_len);
4245 for (i = 0; i < num_rqst; i++) {
4246 for (j = 0; j < rqst[i].rq_nvec; j++) {
4248 * The first rqst has a transform header where the
4249 * first 20 bytes are not part of the encrypted blob
4251 skip = (i == 0) && (j == 0) ? 20 : 0;
4252 smb2_sg_set_buf(&sg[idx++],
4253 rqst[i].rq_iov[j].iov_base + skip,
4254 rqst[i].rq_iov[j].iov_len - skip);
4257 for (j = 0; j < rqst[i].rq_npages; j++) {
4258 unsigned int len, offset;
4260 rqst_page_get_length(&rqst[i], j, &len, &offset);
4261 sg_set_page(&sg[idx++], rqst[i].rq_pages[j], len, offset);
4264 smb2_sg_set_buf(&sg[idx], sign, SMB2_SIGNATURE_SIZE);
4269 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
4271 struct TCP_Server_Info *pserver;
4272 struct cifs_ses *ses;
4275 /* If server is a channel, select the primary channel */
4276 pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
4278 spin_lock(&cifs_tcp_ses_lock);
4279 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
4280 if (ses->Suid == ses_id) {
4281 spin_lock(&ses->ses_lock);
4282 ses_enc_key = enc ? ses->smb3encryptionkey :
4283 ses->smb3decryptionkey;
4284 memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE);
4285 spin_unlock(&ses->ses_lock);
4286 spin_unlock(&cifs_tcp_ses_lock);
4290 spin_unlock(&cifs_tcp_ses_lock);
4295 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
4296 * iov[0] - transform header (associate data),
4297 * iov[1-N] - SMB2 header and pages - data to encrypt.
4298 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4302 crypt_message(struct TCP_Server_Info *server, int num_rqst,
4303 struct smb_rqst *rqst, int enc)
4305 struct smb2_transform_hdr *tr_hdr =
4306 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
4307 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
4309 struct scatterlist *sg;
4310 u8 sign[SMB2_SIGNATURE_SIZE] = {};
4311 u8 key[SMB3_ENC_DEC_KEY_SIZE];
4312 struct aead_request *req;
4314 unsigned int iv_len;
4315 DECLARE_CRYPTO_WAIT(wait);
4316 struct crypto_aead *tfm;
4317 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4319 rc = smb2_get_enc_key(server, le64_to_cpu(tr_hdr->SessionId), enc, key);
4321 cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
4326 rc = smb3_crypto_aead_allocate(server);
4328 cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
4332 tfm = enc ? server->secmech.enc : server->secmech.dec;
4334 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
4335 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4336 rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
4338 rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE);
4341 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
4345 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
4347 cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
4351 req = aead_request_alloc(tfm, GFP_KERNEL);
4353 cifs_server_dbg(VFS, "%s: Failed to alloc aead request\n", __func__);
4358 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
4359 crypt_len += SMB2_SIGNATURE_SIZE;
4362 sg = init_sg(num_rqst, rqst, sign);
4364 cifs_server_dbg(VFS, "%s: Failed to init sg\n", __func__);
4369 iv_len = crypto_aead_ivsize(tfm);
4370 iv = kzalloc(iv_len, GFP_KERNEL);
4372 cifs_server_dbg(VFS, "%s: Failed to alloc iv\n", __func__);
4377 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4378 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4379 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4382 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4385 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
4386 aead_request_set_ad(req, assoc_data_len);
4388 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
4389 crypto_req_done, &wait);
4391 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
4392 : crypto_aead_decrypt(req), &wait);
4395 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
4397 kfree_sensitive(iv);
4399 kfree_sensitive(sg);
4401 kfree_sensitive(req);
4406 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
4410 for (i = 0; i < num_rqst; i++) {
4411 if (rqst[i].rq_pages) {
4412 for (j = rqst[i].rq_npages - 1; j >= 0; j--)
4413 put_page(rqst[i].rq_pages[j]);
4414 kfree(rqst[i].rq_pages);
4420 * This function will initialize new_rq and encrypt the content.
4421 * The first entry, new_rq[0], only contains a single iov which contains
4422 * a smb2_transform_hdr and is pre-allocated by the caller.
4423 * This function then populates new_rq[1+] with the content from olq_rq[0+].
4425 * The end result is an array of smb_rqst structures where the first structure
4426 * only contains a single iov for the transform header which we then can pass
4427 * to crypt_message().
4429 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4430 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
4433 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
4434 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
4436 struct page **pages;
4437 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
4438 unsigned int npages;
4439 unsigned int orig_len = 0;
4443 for (i = 1; i < num_rqst; i++) {
4444 npages = old_rq[i - 1].rq_npages;
4445 pages = kmalloc_array(npages, sizeof(struct page *),
4450 new_rq[i].rq_pages = pages;
4451 new_rq[i].rq_npages = npages;
4452 new_rq[i].rq_offset = old_rq[i - 1].rq_offset;
4453 new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz;
4454 new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz;
4455 new_rq[i].rq_iov = old_rq[i - 1].rq_iov;
4456 new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec;
4458 orig_len += smb_rqst_len(server, &old_rq[i - 1]);
4460 for (j = 0; j < npages; j++) {
4461 pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4466 /* copy pages form the old */
4467 for (j = 0; j < npages; j++) {
4469 unsigned int offset, len;
4471 rqst_page_get_length(&new_rq[i], j, &len, &offset);
4473 dst = (char *) kmap(new_rq[i].rq_pages[j]) + offset;
4474 src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset;
4476 memcpy(dst, src, len);
4477 kunmap(new_rq[i].rq_pages[j]);
4478 kunmap(old_rq[i - 1].rq_pages[j]);
4482 /* fill the 1st iov with a transform header */
4483 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
4485 rc = crypt_message(server, num_rqst, new_rq, 1);
4486 cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
4493 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
4498 smb3_is_transform_hdr(void *buf)
4500 struct smb2_transform_hdr *trhdr = buf;
4502 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
4506 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
4507 unsigned int buf_data_size, struct page **pages,
4508 unsigned int npages, unsigned int page_data_size,
4512 struct smb_rqst rqst = {NULL};
4515 iov[0].iov_base = buf;
4516 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
4517 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
4518 iov[1].iov_len = buf_data_size;
4522 rqst.rq_pages = pages;
4523 rqst.rq_npages = npages;
4524 rqst.rq_pagesz = PAGE_SIZE;
4525 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
4527 rc = crypt_message(server, 1, &rqst, 0);
4528 cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
4533 memmove(buf, iov[1].iov_base, buf_data_size);
4536 server->total_read = buf_data_size + page_data_size;
4542 read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
4543 unsigned int npages, unsigned int len)
4548 for (i = 0; i < npages; i++) {
4549 struct page *page = pages[i];
4553 if (len >= PAGE_SIZE) {
4554 /* enough data to fill the page */
4558 zero_user(page, len, PAGE_SIZE - len);
4561 length = cifs_read_page_from_socket(server, page, 0, n);
4564 server->total_read += length;
4571 init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
4572 unsigned int cur_off, struct bio_vec **page_vec)
4574 struct bio_vec *bvec;
4577 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
4581 for (i = 0; i < npages; i++) {
4582 bvec[i].bv_page = pages[i];
4583 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
4584 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
4585 data_size -= bvec[i].bv_len;
4588 if (data_size != 0) {
4589 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
4599 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
4600 char *buf, unsigned int buf_len, struct page **pages,
4601 unsigned int npages, unsigned int page_data_size,
4604 unsigned int data_offset;
4605 unsigned int data_len;
4606 unsigned int cur_off;
4607 unsigned int cur_page_idx;
4608 unsigned int pad_len;
4609 struct cifs_readdata *rdata = mid->callback_data;
4610 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
4611 struct bio_vec *bvec = NULL;
4612 struct iov_iter iter;
4615 bool use_rdma_mr = false;
4617 if (shdr->Command != SMB2_READ) {
4618 cifs_server_dbg(VFS, "only big read responses are supported\n");
4622 if (server->ops->is_session_expired &&
4623 server->ops->is_session_expired(buf)) {
4625 cifs_reconnect(server, true);
4629 if (server->ops->is_status_pending &&
4630 server->ops->is_status_pending(buf, server))
4633 /* set up first two iov to get credits */
4634 rdata->iov[0].iov_base = buf;
4635 rdata->iov[0].iov_len = 0;
4636 rdata->iov[1].iov_base = buf;
4637 rdata->iov[1].iov_len =
4638 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
4639 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
4640 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
4641 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
4642 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
4644 rdata->result = server->ops->map_error(buf, true);
4645 if (rdata->result != 0) {
4646 cifs_dbg(FYI, "%s: server returned error %d\n",
4647 __func__, rdata->result);
4648 /* normal error on read response */
4650 mid->mid_state = MID_RESPONSE_RECEIVED;
4652 dequeue_mid(mid, false);
4656 data_offset = server->ops->read_data_offset(buf);
4657 #ifdef CONFIG_CIFS_SMB_DIRECT
4658 use_rdma_mr = rdata->mr;
4660 data_len = server->ops->read_data_length(buf, use_rdma_mr);
4662 if (data_offset < server->vals->read_rsp_size) {
4664 * win2k8 sometimes sends an offset of 0 when the read
4665 * is beyond the EOF. Treat it as if the data starts just after
4668 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
4669 __func__, data_offset);
4670 data_offset = server->vals->read_rsp_size;
4671 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
4672 /* data_offset is beyond the end of smallbuf */
4673 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
4674 __func__, data_offset);
4675 rdata->result = -EIO;
4677 mid->mid_state = MID_RESPONSE_MALFORMED;
4679 dequeue_mid(mid, rdata->result);
4683 pad_len = data_offset - server->vals->read_rsp_size;
4685 if (buf_len <= data_offset) {
4686 /* read response payload is in pages */
4687 cur_page_idx = pad_len / PAGE_SIZE;
4688 cur_off = pad_len % PAGE_SIZE;
4690 if (cur_page_idx != 0) {
4691 /* data offset is beyond the 1st page of response */
4692 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
4693 __func__, data_offset);
4694 rdata->result = -EIO;
4696 mid->mid_state = MID_RESPONSE_MALFORMED;
4698 dequeue_mid(mid, rdata->result);
4702 if (data_len > page_data_size - pad_len) {
4703 /* data_len is corrupt -- discard frame */
4704 rdata->result = -EIO;
4706 mid->mid_state = MID_RESPONSE_MALFORMED;
4708 dequeue_mid(mid, rdata->result);
4712 rdata->result = init_read_bvec(pages, npages, page_data_size,
4714 if (rdata->result != 0) {
4716 mid->mid_state = MID_RESPONSE_MALFORMED;
4718 dequeue_mid(mid, rdata->result);
4722 iov_iter_bvec(&iter, WRITE, bvec, npages, data_len);
4723 } else if (buf_len >= data_offset + data_len) {
4724 /* read response payload is in buf */
4725 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
4726 iov.iov_base = buf + data_offset;
4727 iov.iov_len = data_len;
4728 iov_iter_kvec(&iter, WRITE, &iov, 1, data_len);
4730 /* read response payload cannot be in both buf and pages */
4731 WARN_ONCE(1, "buf can not contain only a part of read data");
4732 rdata->result = -EIO;
4734 mid->mid_state = MID_RESPONSE_MALFORMED;
4736 dequeue_mid(mid, rdata->result);
4740 length = rdata->copy_into_pages(server, rdata, &iter);
4748 mid->mid_state = MID_RESPONSE_RECEIVED;
4750 dequeue_mid(mid, false);
4754 struct smb2_decrypt_work {
4755 struct work_struct decrypt;
4756 struct TCP_Server_Info *server;
4757 struct page **ppages;
4759 unsigned int npages;
4764 static void smb2_decrypt_offload(struct work_struct *work)
4766 struct smb2_decrypt_work *dw = container_of(work,
4767 struct smb2_decrypt_work, decrypt);
4769 struct mid_q_entry *mid;
4771 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
4772 dw->ppages, dw->npages, dw->len, true);
4774 cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
4778 dw->server->lstrp = jiffies;
4779 mid = smb2_find_dequeue_mid(dw->server, dw->buf);
4781 cifs_dbg(FYI, "mid not found\n");
4783 mid->decrypted = true;
4784 rc = handle_read_data(dw->server, mid, dw->buf,
4785 dw->server->vals->read_rsp_size,
4786 dw->ppages, dw->npages, dw->len,
4789 #ifdef CONFIG_CIFS_STATS2
4790 mid->when_received = jiffies;
4792 if (dw->server->ops->is_network_name_deleted)
4793 dw->server->ops->is_network_name_deleted(dw->buf,
4798 spin_lock(&dw->server->srv_lock);
4799 if (dw->server->tcpStatus == CifsNeedReconnect) {
4800 spin_lock(&dw->server->mid_lock);
4801 mid->mid_state = MID_RETRY_NEEDED;
4802 spin_unlock(&dw->server->mid_lock);
4803 spin_unlock(&dw->server->srv_lock);
4806 spin_lock(&dw->server->mid_lock);
4807 mid->mid_state = MID_REQUEST_SUBMITTED;
4808 mid->mid_flags &= ~(MID_DELETED);
4809 list_add_tail(&mid->qhead,
4810 &dw->server->pending_mid_q);
4811 spin_unlock(&dw->server->mid_lock);
4812 spin_unlock(&dw->server->srv_lock);
4819 for (i = dw->npages-1; i >= 0; i--)
4820 put_page(dw->ppages[i]);
4823 cifs_small_buf_release(dw->buf);
4829 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
4832 char *buf = server->smallbuf;
4833 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4834 unsigned int npages;
4835 struct page **pages;
4837 unsigned int buflen = server->pdu_size;
4840 struct smb2_decrypt_work *dw;
4843 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
4844 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
4846 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
4849 server->total_read += rc;
4851 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
4852 server->vals->read_rsp_size;
4853 npages = DIV_ROUND_UP(len, PAGE_SIZE);
4855 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
4861 for (; i < npages; i++) {
4862 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4869 /* read read data into pages */
4870 rc = read_data_into_pages(server, pages, npages, len);
4874 rc = cifs_discard_remaining_data(server);
4879 * For large reads, offload to different thread for better performance,
4880 * use more cores decrypting which can be expensive
4883 if ((server->min_offload) && (server->in_flight > 1) &&
4884 (server->pdu_size >= server->min_offload)) {
4885 dw = kmalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL);
4887 goto non_offloaded_decrypt;
4889 dw->buf = server->smallbuf;
4890 server->smallbuf = (char *)cifs_small_buf_get();
4892 INIT_WORK(&dw->decrypt, smb2_decrypt_offload);
4894 dw->npages = npages;
4895 dw->server = server;
4898 queue_work(decrypt_wq, &dw->decrypt);
4899 *num_mids = 0; /* worker thread takes care of finding mid */
4903 non_offloaded_decrypt:
4904 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
4905 pages, npages, len, false);
4909 *mid = smb2_find_mid(server, buf);
4911 cifs_dbg(FYI, "mid not found\n");
4913 cifs_dbg(FYI, "mid found\n");
4914 (*mid)->decrypted = true;
4915 rc = handle_read_data(server, *mid, buf,
4916 server->vals->read_rsp_size,
4917 pages, npages, len, false);
4919 if (server->ops->is_network_name_deleted) {
4920 server->ops->is_network_name_deleted(buf,
4927 for (i = i - 1; i >= 0; i--)
4932 cifs_discard_remaining_data(server);
4937 receive_encrypted_standard(struct TCP_Server_Info *server,
4938 struct mid_q_entry **mids, char **bufs,
4942 char *buf = server->smallbuf;
4943 struct smb2_hdr *shdr;
4944 unsigned int pdu_length = server->pdu_size;
4945 unsigned int buf_size;
4946 struct mid_q_entry *mid_entry;
4948 char *next_buffer = NULL;
4952 /* switch to large buffer if too big for a small one */
4953 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
4954 server->large_buf = true;
4955 memcpy(server->bigbuf, buf, server->total_read);
4956 buf = server->bigbuf;
4959 /* now read the rest */
4960 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
4961 pdu_length - HEADER_SIZE(server) + 1);
4964 server->total_read += length;
4966 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
4967 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0, false);
4971 next_is_large = server->large_buf;
4973 shdr = (struct smb2_hdr *)buf;
4974 if (shdr->NextCommand) {
4976 next_buffer = (char *)cifs_buf_get();
4978 next_buffer = (char *)cifs_small_buf_get();
4980 buf + le32_to_cpu(shdr->NextCommand),
4981 pdu_length - le32_to_cpu(shdr->NextCommand));
4984 mid_entry = smb2_find_mid(server, buf);
4985 if (mid_entry == NULL)
4986 cifs_dbg(FYI, "mid not found\n");
4988 cifs_dbg(FYI, "mid found\n");
4989 mid_entry->decrypted = true;
4990 mid_entry->resp_buf_size = server->pdu_size;
4993 if (*num_mids >= MAX_COMPOUND) {
4994 cifs_server_dbg(VFS, "too many PDUs in compound\n");
4997 bufs[*num_mids] = buf;
4998 mids[(*num_mids)++] = mid_entry;
5000 if (mid_entry && mid_entry->handle)
5001 ret = mid_entry->handle(server, mid_entry);
5003 ret = cifs_handle_standard(server, mid_entry);
5005 if (ret == 0 && shdr->NextCommand) {
5006 pdu_length -= le32_to_cpu(shdr->NextCommand);
5007 server->large_buf = next_is_large;
5009 server->bigbuf = buf = next_buffer;
5011 server->smallbuf = buf = next_buffer;
5013 } else if (ret != 0) {
5015 * ret != 0 here means that we didn't get to handle_mid() thus
5016 * server->smallbuf and server->bigbuf are still valid. We need
5017 * to free next_buffer because it is not going to be used
5021 free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer);
5023 free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer);
5030 smb3_receive_transform(struct TCP_Server_Info *server,
5031 struct mid_q_entry **mids, char **bufs, int *num_mids)
5033 char *buf = server->smallbuf;
5034 unsigned int pdu_length = server->pdu_size;
5035 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
5036 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
5038 if (pdu_length < sizeof(struct smb2_transform_hdr) +
5039 sizeof(struct smb2_hdr)) {
5040 cifs_server_dbg(VFS, "Transform message is too small (%u)\n",
5042 cifs_reconnect(server, true);
5043 return -ECONNABORTED;
5046 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
5047 cifs_server_dbg(VFS, "Transform message is broken\n");
5048 cifs_reconnect(server, true);
5049 return -ECONNABORTED;
5052 /* TODO: add support for compounds containing READ. */
5053 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
5054 return receive_encrypted_read(server, &mids[0], num_mids);
5057 return receive_encrypted_standard(server, mids, bufs, num_mids);
5061 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
5063 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
5065 return handle_read_data(server, mid, buf, server->pdu_size,
5070 smb2_next_header(char *buf)
5072 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
5073 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
5075 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
5076 return sizeof(struct smb2_transform_hdr) +
5077 le32_to_cpu(t_hdr->OriginalMessageSize);
5079 return le32_to_cpu(hdr->NextCommand);
5083 smb2_make_node(unsigned int xid, struct inode *inode,
5084 struct dentry *dentry, struct cifs_tcon *tcon,
5085 const char *full_path, umode_t mode, dev_t dev)
5087 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
5089 struct cifs_open_info_data buf = {};
5090 struct cifs_io_parms io_parms = {0};
5092 struct cifs_fid fid;
5093 struct cifs_open_parms oparms;
5094 unsigned int bytes_written;
5095 struct win_dev *pdev;
5099 * Check if mounted with mount parm 'sfu' mount parm.
5100 * SFU emulation should work with all servers, but only
5101 * supports block and char device (no socket & fifo),
5102 * and was used by default in earlier versions of Windows
5104 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
5108 * TODO: Add ability to create instead via reparse point. Windows (e.g.
5109 * their current NFS server) uses this approach to expose special files
5110 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
5113 if (!S_ISCHR(mode) && !S_ISBLK(mode))
5116 cifs_dbg(FYI, "sfu compat create special file\n");
5119 oparms.cifs_sb = cifs_sb;
5120 oparms.desired_access = GENERIC_WRITE;
5121 oparms.create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR |
5122 CREATE_OPTION_SPECIAL);
5123 oparms.disposition = FILE_CREATE;
5124 oparms.path = full_path;
5126 oparms.reconnect = false;
5128 if (tcon->ses->server->oplocks)
5129 oplock = REQ_OPLOCK;
5132 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, &buf);
5137 * BB Do not bother to decode buf since no local inode yet to put
5138 * timestamps in, but we can reuse it safely.
5141 pdev = (struct win_dev *)&buf.fi;
5142 io_parms.pid = current->tgid;
5143 io_parms.tcon = tcon;
5144 io_parms.offset = 0;
5145 io_parms.length = sizeof(struct win_dev);
5146 iov[1].iov_base = &buf.fi;
5147 iov[1].iov_len = sizeof(struct win_dev);
5148 if (S_ISCHR(mode)) {
5149 memcpy(pdev->type, "IntxCHR", 8);
5150 pdev->major = cpu_to_le64(MAJOR(dev));
5151 pdev->minor = cpu_to_le64(MINOR(dev));
5152 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5153 &bytes_written, iov, 1);
5154 } else if (S_ISBLK(mode)) {
5155 memcpy(pdev->type, "IntxBLK", 8);
5156 pdev->major = cpu_to_le64(MAJOR(dev));
5157 pdev->minor = cpu_to_le64(MINOR(dev));
5158 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5159 &bytes_written, iov, 1);
5161 tcon->ses->server->ops->close(xid, tcon, &fid);
5164 /* FIXME: add code here to set EAs */
5166 cifs_free_open_info(&buf);
5170 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5171 struct smb_version_operations smb20_operations = {
5172 .compare_fids = smb2_compare_fids,
5173 .setup_request = smb2_setup_request,
5174 .setup_async_request = smb2_setup_async_request,
5175 .check_receive = smb2_check_receive,
5176 .add_credits = smb2_add_credits,
5177 .set_credits = smb2_set_credits,
5178 .get_credits_field = smb2_get_credits_field,
5179 .get_credits = smb2_get_credits,
5180 .wait_mtu_credits = cifs_wait_mtu_credits,
5181 .get_next_mid = smb2_get_next_mid,
5182 .revert_current_mid = smb2_revert_current_mid,
5183 .read_data_offset = smb2_read_data_offset,
5184 .read_data_length = smb2_read_data_length,
5185 .map_error = map_smb2_to_linux_error,
5186 .find_mid = smb2_find_mid,
5187 .check_message = smb2_check_message,
5188 .dump_detail = smb2_dump_detail,
5189 .clear_stats = smb2_clear_stats,
5190 .print_stats = smb2_print_stats,
5191 .is_oplock_break = smb2_is_valid_oplock_break,
5192 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5193 .downgrade_oplock = smb2_downgrade_oplock,
5194 .need_neg = smb2_need_neg,
5195 .negotiate = smb2_negotiate,
5196 .negotiate_wsize = smb2_negotiate_wsize,
5197 .negotiate_rsize = smb2_negotiate_rsize,
5198 .sess_setup = SMB2_sess_setup,
5199 .logoff = SMB2_logoff,
5200 .tree_connect = SMB2_tcon,
5201 .tree_disconnect = SMB2_tdis,
5202 .qfs_tcon = smb2_qfs_tcon,
5203 .is_path_accessible = smb2_is_path_accessible,
5204 .can_echo = smb2_can_echo,
5206 .query_path_info = smb2_query_path_info,
5207 .get_srv_inum = smb2_get_srv_inum,
5208 .query_file_info = smb2_query_file_info,
5209 .set_path_size = smb2_set_path_size,
5210 .set_file_size = smb2_set_file_size,
5211 .set_file_info = smb2_set_file_info,
5212 .set_compression = smb2_set_compression,
5213 .mkdir = smb2_mkdir,
5214 .mkdir_setinfo = smb2_mkdir_setinfo,
5215 .rmdir = smb2_rmdir,
5216 .unlink = smb2_unlink,
5217 .rename = smb2_rename_path,
5218 .create_hardlink = smb2_create_hardlink,
5219 .query_symlink = smb2_query_symlink,
5220 .query_mf_symlink = smb3_query_mf_symlink,
5221 .create_mf_symlink = smb3_create_mf_symlink,
5222 .open = smb2_open_file,
5223 .set_fid = smb2_set_fid,
5224 .close = smb2_close_file,
5225 .flush = smb2_flush_file,
5226 .async_readv = smb2_async_readv,
5227 .async_writev = smb2_async_writev,
5228 .sync_read = smb2_sync_read,
5229 .sync_write = smb2_sync_write,
5230 .query_dir_first = smb2_query_dir_first,
5231 .query_dir_next = smb2_query_dir_next,
5232 .close_dir = smb2_close_dir,
5233 .calc_smb_size = smb2_calc_size,
5234 .is_status_pending = smb2_is_status_pending,
5235 .is_session_expired = smb2_is_session_expired,
5236 .oplock_response = smb2_oplock_response,
5237 .queryfs = smb2_queryfs,
5238 .mand_lock = smb2_mand_lock,
5239 .mand_unlock_range = smb2_unlock_range,
5240 .push_mand_locks = smb2_push_mandatory_locks,
5241 .get_lease_key = smb2_get_lease_key,
5242 .set_lease_key = smb2_set_lease_key,
5243 .new_lease_key = smb2_new_lease_key,
5244 .calc_signature = smb2_calc_signature,
5245 .is_read_op = smb2_is_read_op,
5246 .set_oplock_level = smb2_set_oplock_level,
5247 .create_lease_buf = smb2_create_lease_buf,
5248 .parse_lease_buf = smb2_parse_lease_buf,
5249 .copychunk_range = smb2_copychunk_range,
5250 .wp_retry_size = smb2_wp_retry_size,
5251 .dir_needs_close = smb2_dir_needs_close,
5252 .get_dfs_refer = smb2_get_dfs_refer,
5253 .select_sectype = smb2_select_sectype,
5254 #ifdef CONFIG_CIFS_XATTR
5255 .query_all_EAs = smb2_query_eas,
5256 .set_EA = smb2_set_ea,
5257 #endif /* CIFS_XATTR */
5258 .get_acl = get_smb2_acl,
5259 .get_acl_by_fid = get_smb2_acl_by_fid,
5260 .set_acl = set_smb2_acl,
5261 .next_header = smb2_next_header,
5262 .ioctl_query_info = smb2_ioctl_query_info,
5263 .make_node = smb2_make_node,
5264 .fiemap = smb3_fiemap,
5265 .llseek = smb3_llseek,
5266 .is_status_io_timeout = smb2_is_status_io_timeout,
5267 .is_network_name_deleted = smb2_is_network_name_deleted,
5269 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
5271 struct smb_version_operations smb21_operations = {
5272 .compare_fids = smb2_compare_fids,
5273 .setup_request = smb2_setup_request,
5274 .setup_async_request = smb2_setup_async_request,
5275 .check_receive = smb2_check_receive,
5276 .add_credits = smb2_add_credits,
5277 .set_credits = smb2_set_credits,
5278 .get_credits_field = smb2_get_credits_field,
5279 .get_credits = smb2_get_credits,
5280 .wait_mtu_credits = smb2_wait_mtu_credits,
5281 .adjust_credits = smb2_adjust_credits,
5282 .get_next_mid = smb2_get_next_mid,
5283 .revert_current_mid = smb2_revert_current_mid,
5284 .read_data_offset = smb2_read_data_offset,
5285 .read_data_length = smb2_read_data_length,
5286 .map_error = map_smb2_to_linux_error,
5287 .find_mid = smb2_find_mid,
5288 .check_message = smb2_check_message,
5289 .dump_detail = smb2_dump_detail,
5290 .clear_stats = smb2_clear_stats,
5291 .print_stats = smb2_print_stats,
5292 .is_oplock_break = smb2_is_valid_oplock_break,
5293 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5294 .downgrade_oplock = smb2_downgrade_oplock,
5295 .need_neg = smb2_need_neg,
5296 .negotiate = smb2_negotiate,
5297 .negotiate_wsize = smb2_negotiate_wsize,
5298 .negotiate_rsize = smb2_negotiate_rsize,
5299 .sess_setup = SMB2_sess_setup,
5300 .logoff = SMB2_logoff,
5301 .tree_connect = SMB2_tcon,
5302 .tree_disconnect = SMB2_tdis,
5303 .qfs_tcon = smb2_qfs_tcon,
5304 .is_path_accessible = smb2_is_path_accessible,
5305 .can_echo = smb2_can_echo,
5307 .query_path_info = smb2_query_path_info,
5308 .get_srv_inum = smb2_get_srv_inum,
5309 .query_file_info = smb2_query_file_info,
5310 .set_path_size = smb2_set_path_size,
5311 .set_file_size = smb2_set_file_size,
5312 .set_file_info = smb2_set_file_info,
5313 .set_compression = smb2_set_compression,
5314 .mkdir = smb2_mkdir,
5315 .mkdir_setinfo = smb2_mkdir_setinfo,
5316 .rmdir = smb2_rmdir,
5317 .unlink = smb2_unlink,
5318 .rename = smb2_rename_path,
5319 .create_hardlink = smb2_create_hardlink,
5320 .query_symlink = smb2_query_symlink,
5321 .query_mf_symlink = smb3_query_mf_symlink,
5322 .create_mf_symlink = smb3_create_mf_symlink,
5323 .open = smb2_open_file,
5324 .set_fid = smb2_set_fid,
5325 .close = smb2_close_file,
5326 .flush = smb2_flush_file,
5327 .async_readv = smb2_async_readv,
5328 .async_writev = smb2_async_writev,
5329 .sync_read = smb2_sync_read,
5330 .sync_write = smb2_sync_write,
5331 .query_dir_first = smb2_query_dir_first,
5332 .query_dir_next = smb2_query_dir_next,
5333 .close_dir = smb2_close_dir,
5334 .calc_smb_size = smb2_calc_size,
5335 .is_status_pending = smb2_is_status_pending,
5336 .is_session_expired = smb2_is_session_expired,
5337 .oplock_response = smb2_oplock_response,
5338 .queryfs = smb2_queryfs,
5339 .mand_lock = smb2_mand_lock,
5340 .mand_unlock_range = smb2_unlock_range,
5341 .push_mand_locks = smb2_push_mandatory_locks,
5342 .get_lease_key = smb2_get_lease_key,
5343 .set_lease_key = smb2_set_lease_key,
5344 .new_lease_key = smb2_new_lease_key,
5345 .calc_signature = smb2_calc_signature,
5346 .is_read_op = smb21_is_read_op,
5347 .set_oplock_level = smb21_set_oplock_level,
5348 .create_lease_buf = smb2_create_lease_buf,
5349 .parse_lease_buf = smb2_parse_lease_buf,
5350 .copychunk_range = smb2_copychunk_range,
5351 .wp_retry_size = smb2_wp_retry_size,
5352 .dir_needs_close = smb2_dir_needs_close,
5353 .enum_snapshots = smb3_enum_snapshots,
5354 .notify = smb3_notify,
5355 .get_dfs_refer = smb2_get_dfs_refer,
5356 .select_sectype = smb2_select_sectype,
5357 #ifdef CONFIG_CIFS_XATTR
5358 .query_all_EAs = smb2_query_eas,
5359 .set_EA = smb2_set_ea,
5360 #endif /* CIFS_XATTR */
5361 .get_acl = get_smb2_acl,
5362 .get_acl_by_fid = get_smb2_acl_by_fid,
5363 .set_acl = set_smb2_acl,
5364 .next_header = smb2_next_header,
5365 .ioctl_query_info = smb2_ioctl_query_info,
5366 .make_node = smb2_make_node,
5367 .fiemap = smb3_fiemap,
5368 .llseek = smb3_llseek,
5369 .is_status_io_timeout = smb2_is_status_io_timeout,
5370 .is_network_name_deleted = smb2_is_network_name_deleted,
5373 struct smb_version_operations smb30_operations = {
5374 .compare_fids = smb2_compare_fids,
5375 .setup_request = smb2_setup_request,
5376 .setup_async_request = smb2_setup_async_request,
5377 .check_receive = smb2_check_receive,
5378 .add_credits = smb2_add_credits,
5379 .set_credits = smb2_set_credits,
5380 .get_credits_field = smb2_get_credits_field,
5381 .get_credits = smb2_get_credits,
5382 .wait_mtu_credits = smb2_wait_mtu_credits,
5383 .adjust_credits = smb2_adjust_credits,
5384 .get_next_mid = smb2_get_next_mid,
5385 .revert_current_mid = smb2_revert_current_mid,
5386 .read_data_offset = smb2_read_data_offset,
5387 .read_data_length = smb2_read_data_length,
5388 .map_error = map_smb2_to_linux_error,
5389 .find_mid = smb2_find_mid,
5390 .check_message = smb2_check_message,
5391 .dump_detail = smb2_dump_detail,
5392 .clear_stats = smb2_clear_stats,
5393 .print_stats = smb2_print_stats,
5394 .dump_share_caps = smb2_dump_share_caps,
5395 .is_oplock_break = smb2_is_valid_oplock_break,
5396 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5397 .downgrade_oplock = smb3_downgrade_oplock,
5398 .need_neg = smb2_need_neg,
5399 .negotiate = smb2_negotiate,
5400 .negotiate_wsize = smb3_negotiate_wsize,
5401 .negotiate_rsize = smb3_negotiate_rsize,
5402 .sess_setup = SMB2_sess_setup,
5403 .logoff = SMB2_logoff,
5404 .tree_connect = SMB2_tcon,
5405 .tree_disconnect = SMB2_tdis,
5406 .qfs_tcon = smb3_qfs_tcon,
5407 .is_path_accessible = smb2_is_path_accessible,
5408 .can_echo = smb2_can_echo,
5410 .query_path_info = smb2_query_path_info,
5411 /* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */
5412 .query_reparse_tag = smb2_query_reparse_tag,
5413 .get_srv_inum = smb2_get_srv_inum,
5414 .query_file_info = smb2_query_file_info,
5415 .set_path_size = smb2_set_path_size,
5416 .set_file_size = smb2_set_file_size,
5417 .set_file_info = smb2_set_file_info,
5418 .set_compression = smb2_set_compression,
5419 .mkdir = smb2_mkdir,
5420 .mkdir_setinfo = smb2_mkdir_setinfo,
5421 .rmdir = smb2_rmdir,
5422 .unlink = smb2_unlink,
5423 .rename = smb2_rename_path,
5424 .create_hardlink = smb2_create_hardlink,
5425 .query_symlink = smb2_query_symlink,
5426 .query_mf_symlink = smb3_query_mf_symlink,
5427 .create_mf_symlink = smb3_create_mf_symlink,
5428 .open = smb2_open_file,
5429 .set_fid = smb2_set_fid,
5430 .close = smb2_close_file,
5431 .close_getattr = smb2_close_getattr,
5432 .flush = smb2_flush_file,
5433 .async_readv = smb2_async_readv,
5434 .async_writev = smb2_async_writev,
5435 .sync_read = smb2_sync_read,
5436 .sync_write = smb2_sync_write,
5437 .query_dir_first = smb2_query_dir_first,
5438 .query_dir_next = smb2_query_dir_next,
5439 .close_dir = smb2_close_dir,
5440 .calc_smb_size = smb2_calc_size,
5441 .is_status_pending = smb2_is_status_pending,
5442 .is_session_expired = smb2_is_session_expired,
5443 .oplock_response = smb2_oplock_response,
5444 .queryfs = smb2_queryfs,
5445 .mand_lock = smb2_mand_lock,
5446 .mand_unlock_range = smb2_unlock_range,
5447 .push_mand_locks = smb2_push_mandatory_locks,
5448 .get_lease_key = smb2_get_lease_key,
5449 .set_lease_key = smb2_set_lease_key,
5450 .new_lease_key = smb2_new_lease_key,
5451 .generate_signingkey = generate_smb30signingkey,
5452 .calc_signature = smb3_calc_signature,
5453 .set_integrity = smb3_set_integrity,
5454 .is_read_op = smb21_is_read_op,
5455 .set_oplock_level = smb3_set_oplock_level,
5456 .create_lease_buf = smb3_create_lease_buf,
5457 .parse_lease_buf = smb3_parse_lease_buf,
5458 .copychunk_range = smb2_copychunk_range,
5459 .duplicate_extents = smb2_duplicate_extents,
5460 .validate_negotiate = smb3_validate_negotiate,
5461 .wp_retry_size = smb2_wp_retry_size,
5462 .dir_needs_close = smb2_dir_needs_close,
5463 .fallocate = smb3_fallocate,
5464 .enum_snapshots = smb3_enum_snapshots,
5465 .notify = smb3_notify,
5466 .init_transform_rq = smb3_init_transform_rq,
5467 .is_transform_hdr = smb3_is_transform_hdr,
5468 .receive_transform = smb3_receive_transform,
5469 .get_dfs_refer = smb2_get_dfs_refer,
5470 .select_sectype = smb2_select_sectype,
5471 #ifdef CONFIG_CIFS_XATTR
5472 .query_all_EAs = smb2_query_eas,
5473 .set_EA = smb2_set_ea,
5474 #endif /* CIFS_XATTR */
5475 .get_acl = get_smb2_acl,
5476 .get_acl_by_fid = get_smb2_acl_by_fid,
5477 .set_acl = set_smb2_acl,
5478 .next_header = smb2_next_header,
5479 .ioctl_query_info = smb2_ioctl_query_info,
5480 .make_node = smb2_make_node,
5481 .fiemap = smb3_fiemap,
5482 .llseek = smb3_llseek,
5483 .is_status_io_timeout = smb2_is_status_io_timeout,
5484 .is_network_name_deleted = smb2_is_network_name_deleted,
5487 struct smb_version_operations smb311_operations = {
5488 .compare_fids = smb2_compare_fids,
5489 .setup_request = smb2_setup_request,
5490 .setup_async_request = smb2_setup_async_request,
5491 .check_receive = smb2_check_receive,
5492 .add_credits = smb2_add_credits,
5493 .set_credits = smb2_set_credits,
5494 .get_credits_field = smb2_get_credits_field,
5495 .get_credits = smb2_get_credits,
5496 .wait_mtu_credits = smb2_wait_mtu_credits,
5497 .adjust_credits = smb2_adjust_credits,
5498 .get_next_mid = smb2_get_next_mid,
5499 .revert_current_mid = smb2_revert_current_mid,
5500 .read_data_offset = smb2_read_data_offset,
5501 .read_data_length = smb2_read_data_length,
5502 .map_error = map_smb2_to_linux_error,
5503 .find_mid = smb2_find_mid,
5504 .check_message = smb2_check_message,
5505 .dump_detail = smb2_dump_detail,
5506 .clear_stats = smb2_clear_stats,
5507 .print_stats = smb2_print_stats,
5508 .dump_share_caps = smb2_dump_share_caps,
5509 .is_oplock_break = smb2_is_valid_oplock_break,
5510 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5511 .downgrade_oplock = smb3_downgrade_oplock,
5512 .need_neg = smb2_need_neg,
5513 .negotiate = smb2_negotiate,
5514 .negotiate_wsize = smb3_negotiate_wsize,
5515 .negotiate_rsize = smb3_negotiate_rsize,
5516 .sess_setup = SMB2_sess_setup,
5517 .logoff = SMB2_logoff,
5518 .tree_connect = SMB2_tcon,
5519 .tree_disconnect = SMB2_tdis,
5520 .qfs_tcon = smb3_qfs_tcon,
5521 .is_path_accessible = smb2_is_path_accessible,
5522 .can_echo = smb2_can_echo,
5524 .query_path_info = smb2_query_path_info,
5525 .query_reparse_tag = smb2_query_reparse_tag,
5526 .get_srv_inum = smb2_get_srv_inum,
5527 .query_file_info = smb2_query_file_info,
5528 .set_path_size = smb2_set_path_size,
5529 .set_file_size = smb2_set_file_size,
5530 .set_file_info = smb2_set_file_info,
5531 .set_compression = smb2_set_compression,
5532 .mkdir = smb2_mkdir,
5533 .mkdir_setinfo = smb2_mkdir_setinfo,
5534 .posix_mkdir = smb311_posix_mkdir,
5535 .rmdir = smb2_rmdir,
5536 .unlink = smb2_unlink,
5537 .rename = smb2_rename_path,
5538 .create_hardlink = smb2_create_hardlink,
5539 .query_symlink = smb2_query_symlink,
5540 .query_mf_symlink = smb3_query_mf_symlink,
5541 .create_mf_symlink = smb3_create_mf_symlink,
5542 .open = smb2_open_file,
5543 .set_fid = smb2_set_fid,
5544 .close = smb2_close_file,
5545 .close_getattr = smb2_close_getattr,
5546 .flush = smb2_flush_file,
5547 .async_readv = smb2_async_readv,
5548 .async_writev = smb2_async_writev,
5549 .sync_read = smb2_sync_read,
5550 .sync_write = smb2_sync_write,
5551 .query_dir_first = smb2_query_dir_first,
5552 .query_dir_next = smb2_query_dir_next,
5553 .close_dir = smb2_close_dir,
5554 .calc_smb_size = smb2_calc_size,
5555 .is_status_pending = smb2_is_status_pending,
5556 .is_session_expired = smb2_is_session_expired,
5557 .oplock_response = smb2_oplock_response,
5558 .queryfs = smb311_queryfs,
5559 .mand_lock = smb2_mand_lock,
5560 .mand_unlock_range = smb2_unlock_range,
5561 .push_mand_locks = smb2_push_mandatory_locks,
5562 .get_lease_key = smb2_get_lease_key,
5563 .set_lease_key = smb2_set_lease_key,
5564 .new_lease_key = smb2_new_lease_key,
5565 .generate_signingkey = generate_smb311signingkey,
5566 .calc_signature = smb3_calc_signature,
5567 .set_integrity = smb3_set_integrity,
5568 .is_read_op = smb21_is_read_op,
5569 .set_oplock_level = smb3_set_oplock_level,
5570 .create_lease_buf = smb3_create_lease_buf,
5571 .parse_lease_buf = smb3_parse_lease_buf,
5572 .copychunk_range = smb2_copychunk_range,
5573 .duplicate_extents = smb2_duplicate_extents,
5574 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
5575 .wp_retry_size = smb2_wp_retry_size,
5576 .dir_needs_close = smb2_dir_needs_close,
5577 .fallocate = smb3_fallocate,
5578 .enum_snapshots = smb3_enum_snapshots,
5579 .notify = smb3_notify,
5580 .init_transform_rq = smb3_init_transform_rq,
5581 .is_transform_hdr = smb3_is_transform_hdr,
5582 .receive_transform = smb3_receive_transform,
5583 .get_dfs_refer = smb2_get_dfs_refer,
5584 .select_sectype = smb2_select_sectype,
5585 #ifdef CONFIG_CIFS_XATTR
5586 .query_all_EAs = smb2_query_eas,
5587 .set_EA = smb2_set_ea,
5588 #endif /* CIFS_XATTR */
5589 .get_acl = get_smb2_acl,
5590 .get_acl_by_fid = get_smb2_acl_by_fid,
5591 .set_acl = set_smb2_acl,
5592 .next_header = smb2_next_header,
5593 .ioctl_query_info = smb2_ioctl_query_info,
5594 .make_node = smb2_make_node,
5595 .fiemap = smb3_fiemap,
5596 .llseek = smb3_llseek,
5597 .is_status_io_timeout = smb2_is_status_io_timeout,
5598 .is_network_name_deleted = smb2_is_network_name_deleted,
5601 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5602 struct smb_version_values smb20_values = {
5603 .version_string = SMB20_VERSION_STRING,
5604 .protocol_id = SMB20_PROT_ID,
5605 .req_capabilities = 0, /* MBZ */
5606 .large_lock_type = 0,
5607 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5608 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5609 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5610 .header_size = sizeof(struct smb2_hdr),
5611 .header_preamble_size = 0,
5612 .max_header_size = MAX_SMB2_HDR_SIZE,
5613 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5614 .lock_cmd = SMB2_LOCK,
5616 .cap_nt_find = SMB2_NT_FIND,
5617 .cap_large_files = SMB2_LARGE_FILES,
5618 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5619 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5620 .create_lease_size = sizeof(struct create_lease),
5622 #endif /* ALLOW_INSECURE_LEGACY */
5624 struct smb_version_values smb21_values = {
5625 .version_string = SMB21_VERSION_STRING,
5626 .protocol_id = SMB21_PROT_ID,
5627 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
5628 .large_lock_type = 0,
5629 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5630 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5631 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5632 .header_size = sizeof(struct smb2_hdr),
5633 .header_preamble_size = 0,
5634 .max_header_size = MAX_SMB2_HDR_SIZE,
5635 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5636 .lock_cmd = SMB2_LOCK,
5638 .cap_nt_find = SMB2_NT_FIND,
5639 .cap_large_files = SMB2_LARGE_FILES,
5640 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5641 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5642 .create_lease_size = sizeof(struct create_lease),
5645 struct smb_version_values smb3any_values = {
5646 .version_string = SMB3ANY_VERSION_STRING,
5647 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5648 .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,
5649 .large_lock_type = 0,
5650 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5651 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5652 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5653 .header_size = sizeof(struct smb2_hdr),
5654 .header_preamble_size = 0,
5655 .max_header_size = MAX_SMB2_HDR_SIZE,
5656 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5657 .lock_cmd = SMB2_LOCK,
5659 .cap_nt_find = SMB2_NT_FIND,
5660 .cap_large_files = SMB2_LARGE_FILES,
5661 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5662 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5663 .create_lease_size = sizeof(struct create_lease_v2),
5666 struct smb_version_values smbdefault_values = {
5667 .version_string = SMBDEFAULT_VERSION_STRING,
5668 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5669 .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,
5670 .large_lock_type = 0,
5671 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5672 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5673 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5674 .header_size = sizeof(struct smb2_hdr),
5675 .header_preamble_size = 0,
5676 .max_header_size = MAX_SMB2_HDR_SIZE,
5677 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5678 .lock_cmd = SMB2_LOCK,
5680 .cap_nt_find = SMB2_NT_FIND,
5681 .cap_large_files = SMB2_LARGE_FILES,
5682 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5683 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5684 .create_lease_size = sizeof(struct create_lease_v2),
5687 struct smb_version_values smb30_values = {
5688 .version_string = SMB30_VERSION_STRING,
5689 .protocol_id = SMB30_PROT_ID,
5690 .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,
5691 .large_lock_type = 0,
5692 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5693 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5694 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5695 .header_size = sizeof(struct smb2_hdr),
5696 .header_preamble_size = 0,
5697 .max_header_size = MAX_SMB2_HDR_SIZE,
5698 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5699 .lock_cmd = SMB2_LOCK,
5701 .cap_nt_find = SMB2_NT_FIND,
5702 .cap_large_files = SMB2_LARGE_FILES,
5703 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5704 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5705 .create_lease_size = sizeof(struct create_lease_v2),
5708 struct smb_version_values smb302_values = {
5709 .version_string = SMB302_VERSION_STRING,
5710 .protocol_id = SMB302_PROT_ID,
5711 .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,
5712 .large_lock_type = 0,
5713 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5714 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5715 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5716 .header_size = sizeof(struct smb2_hdr),
5717 .header_preamble_size = 0,
5718 .max_header_size = MAX_SMB2_HDR_SIZE,
5719 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5720 .lock_cmd = SMB2_LOCK,
5722 .cap_nt_find = SMB2_NT_FIND,
5723 .cap_large_files = SMB2_LARGE_FILES,
5724 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5725 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5726 .create_lease_size = sizeof(struct create_lease_v2),
5729 struct smb_version_values smb311_values = {
5730 .version_string = SMB311_VERSION_STRING,
5731 .protocol_id = SMB311_PROT_ID,
5732 .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,
5733 .large_lock_type = 0,
5734 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5735 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5736 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5737 .header_size = sizeof(struct smb2_hdr),
5738 .header_preamble_size = 0,
5739 .max_header_size = MAX_SMB2_HDR_SIZE,
5740 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5741 .lock_cmd = SMB2_LOCK,
5743 .cap_nt_find = SMB2_NT_FIND,
5744 .cap_large_files = SMB2_LARGE_FILES,
5745 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5746 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5747 .create_lease_size = sizeof(struct create_lease_v2),