1 // SPDX-License-Identifier: GPL-2.0
3 * SMB2 version specific operations
5 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
8 #include <linux/pagemap.h>
10 #include <linux/falloc.h>
11 #include <linux/scatterlist.h>
12 #include <linux/uuid.h>
13 #include <linux/sort.h>
14 #include <crypto/aead.h>
15 #include <linux/fiemap.h>
16 #include <uapi/linux/magic.h>
20 #include "smb2proto.h"
21 #include "cifsproto.h"
22 #include "cifs_debug.h"
23 #include "cifs_unicode.h"
24 #include "smb2status.h"
26 #include "cifs_ioctl.h"
27 #include "smbdirect.h"
29 #include "fs_context.h"
30 #include "cached_dir.h"
32 /* Change credits for different ops and return the total number of credits */
34 change_conf(struct TCP_Server_Info *server)
36 server->credits += server->echo_credits + server->oplock_credits;
37 server->oplock_credits = server->echo_credits = 0;
38 switch (server->credits) {
42 server->echoes = false;
43 server->oplocks = false;
46 server->echoes = true;
47 server->oplocks = false;
48 server->echo_credits = 1;
51 server->echoes = true;
53 server->oplocks = true;
54 server->oplock_credits = 1;
56 server->oplocks = false;
58 server->echo_credits = 1;
60 server->credits -= server->echo_credits + server->oplock_credits;
61 return server->credits + server->echo_credits + server->oplock_credits;
65 smb2_add_credits(struct TCP_Server_Info *server,
66 const struct cifs_credits *credits, const int optype)
69 int scredits, in_flight;
70 unsigned int add = credits->value;
71 unsigned int instance = credits->instance;
72 bool reconnect_detected = false;
73 bool reconnect_with_invalid_credits = false;
75 spin_lock(&server->req_lock);
76 val = server->ops->get_credits_field(server, optype);
78 /* eg found case where write overlapping reconnect messed up credits */
79 if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0))
80 reconnect_with_invalid_credits = true;
82 if ((instance == 0) || (instance == server->reconnect_instance))
85 reconnect_detected = true;
88 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
89 pr_warn_once("server overflowed SMB3 credits\n");
90 trace_smb3_overflow_credits(server->CurrentMid,
91 server->conn_id, server->hostname, *val,
92 add, server->in_flight);
95 if (server->in_flight == 0 &&
96 ((optype & CIFS_OP_MASK) != CIFS_NEG_OP) &&
97 ((optype & CIFS_OP_MASK) != CIFS_SESS_OP))
98 rc = change_conf(server);
100 * Sometimes server returns 0 credits on oplock break ack - we need to
101 * rebalance credits in this case.
103 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
105 if (server->credits > 1) {
107 server->oplock_credits++;
111 in_flight = server->in_flight;
112 spin_unlock(&server->req_lock);
113 wake_up(&server->request_q);
115 if (reconnect_detected) {
116 trace_smb3_reconnect_detected(server->CurrentMid,
117 server->conn_id, server->hostname, scredits, add, in_flight);
119 cifs_dbg(FYI, "trying to put %d credits from the old server instance %d\n",
123 if (reconnect_with_invalid_credits) {
124 trace_smb3_reconnect_with_invalid_credits(server->CurrentMid,
125 server->conn_id, server->hostname, scredits, add, in_flight);
126 cifs_dbg(FYI, "Negotiate operation when server credits is non-zero. Optype: %d, server credits: %d, credits added: %d\n",
127 optype, scredits, add);
130 spin_lock(&server->srv_lock);
131 if (server->tcpStatus == CifsNeedReconnect
132 || server->tcpStatus == CifsExiting) {
133 spin_unlock(&server->srv_lock);
136 spin_unlock(&server->srv_lock);
140 /* change_conf hasn't been executed */
143 cifs_server_dbg(VFS, "Possible client or server bug - zero credits\n");
146 cifs_server_dbg(VFS, "disabling echoes and oplocks\n");
149 cifs_dbg(FYI, "disabling oplocks\n");
152 /* change_conf rebalanced credits for different types */
156 trace_smb3_add_credits(server->CurrentMid,
157 server->conn_id, server->hostname, scredits, add, in_flight);
158 cifs_dbg(FYI, "%s: added %u credits total=%d\n", __func__, add, scredits);
162 smb2_set_credits(struct TCP_Server_Info *server, const int val)
164 int scredits, in_flight;
166 spin_lock(&server->req_lock);
167 server->credits = val;
169 server->reconnect_instance++;
170 scredits = server->credits;
171 in_flight = server->in_flight;
172 spin_unlock(&server->req_lock);
174 trace_smb3_set_credits(server->CurrentMid,
175 server->conn_id, server->hostname, scredits, val, in_flight);
176 cifs_dbg(FYI, "%s: set %u credits\n", __func__, val);
178 /* don't log while holding the lock */
180 cifs_dbg(FYI, "set credits to 1 due to smb2 reconnect\n");
184 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
188 return &server->echo_credits;
190 return &server->oplock_credits;
192 return &server->credits;
197 smb2_get_credits(struct mid_q_entry *mid)
199 return mid->credits_received;
203 smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
204 unsigned int *num, struct cifs_credits *credits)
207 unsigned int scredits, in_flight;
209 spin_lock(&server->req_lock);
211 if (server->credits <= 0) {
212 spin_unlock(&server->req_lock);
213 cifs_num_waiters_inc(server);
214 rc = wait_event_killable(server->request_q,
215 has_credits(server, &server->credits, 1));
216 cifs_num_waiters_dec(server);
219 spin_lock(&server->req_lock);
221 spin_unlock(&server->req_lock);
222 spin_lock(&server->srv_lock);
223 if (server->tcpStatus == CifsExiting) {
224 spin_unlock(&server->srv_lock);
227 spin_unlock(&server->srv_lock);
229 spin_lock(&server->req_lock);
230 scredits = server->credits;
231 /* can deadlock with reopen */
233 *num = SMB2_MAX_BUFFER_SIZE;
235 credits->instance = 0;
239 /* leave some credits for reopen and other ops */
241 *num = min_t(unsigned int, size,
242 scredits * SMB2_MAX_BUFFER_SIZE);
245 DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
246 credits->instance = server->reconnect_instance;
247 server->credits -= credits->value;
249 if (server->in_flight > server->max_in_flight)
250 server->max_in_flight = server->in_flight;
254 scredits = server->credits;
255 in_flight = server->in_flight;
256 spin_unlock(&server->req_lock);
258 trace_smb3_wait_credits(server->CurrentMid,
259 server->conn_id, server->hostname, scredits, -(credits->value), in_flight);
260 cifs_dbg(FYI, "%s: removed %u credits total=%d\n",
261 __func__, credits->value, scredits);
267 smb2_adjust_credits(struct TCP_Server_Info *server,
268 struct cifs_credits *credits,
269 const unsigned int payload_size)
271 int new_val = DIV_ROUND_UP(payload_size, SMB2_MAX_BUFFER_SIZE);
272 int scredits, in_flight;
274 if (!credits->value || credits->value == new_val)
277 if (credits->value < new_val) {
278 trace_smb3_too_many_credits(server->CurrentMid,
279 server->conn_id, server->hostname, 0, credits->value - new_val, 0);
280 cifs_server_dbg(VFS, "request has less credits (%d) than required (%d)",
281 credits->value, new_val);
286 spin_lock(&server->req_lock);
288 if (server->reconnect_instance != credits->instance) {
289 scredits = server->credits;
290 in_flight = server->in_flight;
291 spin_unlock(&server->req_lock);
293 trace_smb3_reconnect_detected(server->CurrentMid,
294 server->conn_id, server->hostname, scredits,
295 credits->value - new_val, in_flight);
296 cifs_server_dbg(VFS, "trying to return %d credits to old session\n",
297 credits->value - new_val);
301 server->credits += credits->value - new_val;
302 scredits = server->credits;
303 in_flight = server->in_flight;
304 spin_unlock(&server->req_lock);
305 wake_up(&server->request_q);
307 trace_smb3_adj_credits(server->CurrentMid,
308 server->conn_id, server->hostname, scredits,
309 credits->value - new_val, in_flight);
310 cifs_dbg(FYI, "%s: adjust added %u credits total=%d\n",
311 __func__, credits->value - new_val, scredits);
313 credits->value = new_val;
319 smb2_get_next_mid(struct TCP_Server_Info *server)
322 /* for SMB2 we need the current value */
323 spin_lock(&server->mid_lock);
324 mid = server->CurrentMid++;
325 spin_unlock(&server->mid_lock);
330 smb2_revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
332 spin_lock(&server->mid_lock);
333 if (server->CurrentMid >= val)
334 server->CurrentMid -= val;
335 spin_unlock(&server->mid_lock);
338 static struct mid_q_entry *
339 __smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue)
341 struct mid_q_entry *mid;
342 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
343 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
345 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
346 cifs_server_dbg(VFS, "Encrypted frame parsing not supported yet\n");
350 spin_lock(&server->mid_lock);
351 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
352 if ((mid->mid == wire_mid) &&
353 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
354 (mid->command == shdr->Command)) {
355 kref_get(&mid->refcount);
357 list_del_init(&mid->qhead);
358 mid->mid_flags |= MID_DELETED;
360 spin_unlock(&server->mid_lock);
364 spin_unlock(&server->mid_lock);
368 static struct mid_q_entry *
369 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
371 return __smb2_find_mid(server, buf, false);
374 static struct mid_q_entry *
375 smb2_find_dequeue_mid(struct TCP_Server_Info *server, char *buf)
377 return __smb2_find_mid(server, buf, true);
381 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
383 #ifdef CONFIG_CIFS_DEBUG2
384 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
386 cifs_server_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
387 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
388 shdr->Id.SyncId.ProcessId);
389 cifs_server_dbg(VFS, "smb buf %p len %u\n", buf,
390 server->ops->calc_smb_size(buf));
395 smb2_need_neg(struct TCP_Server_Info *server)
397 return server->max_read == 0;
401 smb2_negotiate(const unsigned int xid,
402 struct cifs_ses *ses,
403 struct TCP_Server_Info *server)
407 spin_lock(&server->mid_lock);
408 server->CurrentMid = 0;
409 spin_unlock(&server->mid_lock);
410 rc = SMB2_negotiate(xid, ses, server);
411 /* BB we probably don't need to retry with modern servers */
418 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
420 struct TCP_Server_Info *server = tcon->ses->server;
423 /* start with specified wsize, or default */
424 wsize = ctx->wsize ? ctx->wsize : CIFS_DEFAULT_IOSIZE;
425 wsize = min_t(unsigned int, wsize, server->max_write);
426 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
427 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
433 smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
435 struct TCP_Server_Info *server = tcon->ses->server;
438 /* start with specified wsize, or default */
439 wsize = ctx->wsize ? ctx->wsize : SMB3_DEFAULT_IOSIZE;
440 wsize = min_t(unsigned int, wsize, server->max_write);
441 #ifdef CONFIG_CIFS_SMB_DIRECT
445 * Account for SMB2 data transfer packet header and
446 * possible encryption header
448 wsize = min_t(unsigned int,
450 server->smbd_conn->max_fragmented_send_size -
451 SMB2_READWRITE_PDU_HEADER_SIZE -
452 sizeof(struct smb2_transform_hdr));
454 wsize = min_t(unsigned int,
455 wsize, server->smbd_conn->max_readwrite_size);
458 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
459 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
465 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
467 struct TCP_Server_Info *server = tcon->ses->server;
470 /* start with specified rsize, or default */
471 rsize = ctx->rsize ? ctx->rsize : CIFS_DEFAULT_IOSIZE;
472 rsize = min_t(unsigned int, rsize, server->max_read);
474 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
475 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
481 smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
483 struct TCP_Server_Info *server = tcon->ses->server;
486 /* start with specified rsize, or default */
487 rsize = ctx->rsize ? ctx->rsize : SMB3_DEFAULT_IOSIZE;
488 rsize = min_t(unsigned int, rsize, server->max_read);
489 #ifdef CONFIG_CIFS_SMB_DIRECT
493 * Account for SMB2 data transfer packet header and
494 * possible encryption header
496 rsize = min_t(unsigned int,
498 server->smbd_conn->max_fragmented_recv_size -
499 SMB2_READWRITE_PDU_HEADER_SIZE -
500 sizeof(struct smb2_transform_hdr));
502 rsize = min_t(unsigned int,
503 rsize, server->smbd_conn->max_readwrite_size);
507 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
508 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
514 parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
516 struct cifs_ses *ses)
518 struct network_interface_info_ioctl_rsp *p;
519 struct sockaddr_in *addr4;
520 struct sockaddr_in6 *addr6;
521 struct iface_info_ipv4 *p4;
522 struct iface_info_ipv6 *p6;
523 struct cifs_server_iface *info = NULL, *iface = NULL, *niface = NULL;
524 struct cifs_server_iface tmp_iface;
530 bytes_left = buf_len;
533 spin_lock(&ses->iface_lock);
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);
546 while (bytes_left >= sizeof(*p)) {
547 memset(&tmp_iface, 0, sizeof(tmp_iface));
548 tmp_iface.speed = le64_to_cpu(p->LinkSpeed);
549 tmp_iface.rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE) ? 1 : 0;
550 tmp_iface.rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE) ? 1 : 0;
554 * The kernel and wire socket structures have the same
555 * layout and use network byte order but make the
556 * conversion explicit in case either one changes.
559 addr4 = (struct sockaddr_in *)&tmp_iface.sockaddr;
560 p4 = (struct iface_info_ipv4 *)p->Buffer;
561 addr4->sin_family = AF_INET;
562 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
564 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
565 addr4->sin_port = cpu_to_be16(CIFS_PORT);
567 cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
571 addr6 = (struct sockaddr_in6 *)&tmp_iface.sockaddr;
572 p6 = (struct iface_info_ipv6 *)p->Buffer;
573 addr6->sin6_family = AF_INET6;
574 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
576 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
577 addr6->sin6_flowinfo = 0;
578 addr6->sin6_scope_id = 0;
579 addr6->sin6_port = cpu_to_be16(CIFS_PORT);
581 cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
586 "%s: skipping unsupported socket family\n",
592 * The iface_list is assumed to be sorted by speed.
593 * Check if the new interface exists in that list.
594 * NEVER change iface. it could be in use.
595 * Add a new one instead
597 spin_lock(&ses->iface_lock);
598 iface = niface = NULL;
599 list_for_each_entry_safe(iface, niface, &ses->iface_list,
601 ret = iface_cmp(iface, &tmp_iface);
603 /* just get a ref so that it doesn't get picked/freed */
604 iface->is_active = 1;
605 kref_get(&iface->refcount);
606 spin_unlock(&ses->iface_lock);
608 } else if (ret < 0) {
609 /* all remaining ifaces are slower */
610 kref_get(&iface->refcount);
614 spin_unlock(&ses->iface_lock);
616 /* no match. insert the entry in the list */
617 info = kmalloc(sizeof(struct cifs_server_iface),
623 memcpy(info, &tmp_iface, sizeof(tmp_iface));
625 /* add this new entry to the list */
626 kref_init(&info->refcount);
629 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, ses->iface_count);
630 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
631 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
632 le32_to_cpu(p->Capability));
634 spin_lock(&ses->iface_lock);
635 if (!list_entry_is_head(iface, &ses->iface_list, iface_head)) {
636 list_add_tail(&info->iface_head, &iface->iface_head);
637 kref_put(&iface->refcount, release_iface);
639 list_add_tail(&info->iface_head, &ses->iface_list);
640 spin_unlock(&ses->iface_lock);
643 ses->iface_last_update = jiffies;
646 next = le32_to_cpu(p->Next);
648 bytes_left -= sizeof(*p);
651 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
656 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
661 /* Azure rounds the buffer size up 8, to a 16 byte boundary */
662 if ((bytes_left > 8) || p->Next)
663 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
666 if (!ses->iface_count) {
676 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
679 unsigned int ret_data_len = 0;
680 struct network_interface_info_ioctl_rsp *out_buf = NULL;
681 struct cifs_ses *ses = tcon->ses;
683 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
684 FSCTL_QUERY_NETWORK_INTERFACE_INFO,
685 NULL /* no data input */, 0 /* no data input */,
686 CIFSMaxBufSize, (char **)&out_buf, &ret_data_len);
687 if (rc == -EOPNOTSUPP) {
689 "server does not support query network interfaces\n");
691 } else if (rc != 0) {
692 cifs_tcon_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
696 rc = parse_server_interfaces(out_buf, ret_data_len, ses);
706 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
707 struct cifs_sb_info *cifs_sb)
710 __le16 srch_path = 0; /* Null - open root of share */
711 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
712 struct cifs_open_parms oparms;
714 struct cached_fid *cfid = NULL;
717 oparms.desired_access = FILE_READ_ATTRIBUTES;
718 oparms.disposition = FILE_OPEN;
719 oparms.create_options = cifs_create_options(cifs_sb, 0);
721 oparms.reconnect = false;
723 rc = open_cached_dir(xid, tcon, "", cifs_sb, false, &cfid);
725 memcpy(&fid, &cfid->fid, sizeof(struct cifs_fid));
727 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
732 SMB3_request_interfaces(xid, tcon);
734 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
735 FS_ATTRIBUTE_INFORMATION);
736 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
737 FS_DEVICE_INFORMATION);
738 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
739 FS_VOLUME_INFORMATION);
740 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
741 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
743 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
745 close_cached_dir(cfid);
749 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
750 struct cifs_sb_info *cifs_sb)
753 __le16 srch_path = 0; /* Null - open root of share */
754 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
755 struct cifs_open_parms oparms;
759 oparms.desired_access = FILE_READ_ATTRIBUTES;
760 oparms.disposition = FILE_OPEN;
761 oparms.create_options = cifs_create_options(cifs_sb, 0);
763 oparms.reconnect = false;
765 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
770 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
771 FS_ATTRIBUTE_INFORMATION);
772 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
773 FS_DEVICE_INFORMATION);
774 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
778 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
779 struct cifs_sb_info *cifs_sb, const char *full_path)
783 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
784 struct cifs_open_parms oparms;
786 struct cached_fid *cfid;
788 rc = open_cached_dir(xid, tcon, full_path, cifs_sb, true, &cfid);
790 if (cfid->is_valid) {
791 close_cached_dir(cfid);
794 close_cached_dir(cfid);
797 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
802 oparms.desired_access = FILE_READ_ATTRIBUTES;
803 oparms.disposition = FILE_OPEN;
804 oparms.create_options = cifs_create_options(cifs_sb, 0);
806 oparms.reconnect = false;
808 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
815 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
821 smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
822 struct cifs_sb_info *cifs_sb, const char *full_path,
823 u64 *uniqueid, FILE_ALL_INFO *data)
825 *uniqueid = le64_to_cpu(data->IndexNumber);
830 smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
831 struct cifs_fid *fid, FILE_ALL_INFO *data)
834 struct smb2_file_all_info *smb2_data;
836 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
838 if (smb2_data == NULL)
841 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
844 move_smb2_info_to_cifs(data, smb2_data);
849 #ifdef CONFIG_CIFS_XATTR
851 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
852 struct smb2_file_full_ea_info *src, size_t src_size,
853 const unsigned char *ea_name)
856 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
858 size_t buf_size = dst_size;
859 size_t name_len, value_len, user_name_len;
861 while (src_size > 0) {
862 name_len = (size_t)src->ea_name_length;
863 value_len = (size_t)le16_to_cpu(src->ea_value_length);
868 if (src_size < 8 + name_len + 1 + value_len) {
869 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
874 name = &src->ea_data[0];
875 value = &src->ea_data[src->ea_name_length + 1];
878 if (ea_name_len == name_len &&
879 memcmp(ea_name, name, name_len) == 0) {
883 if (dst_size < value_len) {
887 memcpy(dst, value, value_len);
891 /* 'user.' plus a terminating null */
892 user_name_len = 5 + 1 + name_len;
895 /* skip copy - calc size only */
897 } else if (dst_size >= user_name_len) {
898 dst_size -= user_name_len;
899 memcpy(dst, "user.", 5);
901 memcpy(dst, src->ea_data, name_len);
907 /* stop before overrun buffer */
913 if (!src->next_entry_offset)
916 if (src_size < le32_to_cpu(src->next_entry_offset)) {
917 /* stop before overrun buffer */
921 src_size -= le32_to_cpu(src->next_entry_offset);
922 src = (void *)((char *)src +
923 le32_to_cpu(src->next_entry_offset));
926 /* didn't find the named attribute */
935 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
936 const unsigned char *path, const unsigned char *ea_name,
937 char *ea_data, size_t buf_size,
938 struct cifs_sb_info *cifs_sb)
941 struct kvec rsp_iov = {NULL, 0};
942 int buftype = CIFS_NO_BUFFER;
943 struct smb2_query_info_rsp *rsp;
944 struct smb2_file_full_ea_info *info = NULL;
946 rc = smb2_query_info_compound(xid, tcon, path,
948 FILE_FULL_EA_INFORMATION,
951 MAX_SMB2_CREATE_RESPONSE_SIZE -
952 MAX_SMB2_CLOSE_RESPONSE_SIZE,
953 &rsp_iov, &buftype, cifs_sb);
956 * If ea_name is NULL (listxattr) and there are no EAs,
957 * return 0 as it's not an error. Otherwise, the specified
958 * ea_name was not found.
960 if (!ea_name && rc == -ENODATA)
965 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
966 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
967 le32_to_cpu(rsp->OutputBufferLength),
969 sizeof(struct smb2_file_full_ea_info));
973 info = (struct smb2_file_full_ea_info *)(
974 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
975 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
976 le32_to_cpu(rsp->OutputBufferLength), ea_name);
979 free_rsp_buf(buftype, rsp_iov.iov_base);
985 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
986 const char *path, const char *ea_name, const void *ea_value,
987 const __u16 ea_value_len, const struct nls_table *nls_codepage,
988 struct cifs_sb_info *cifs_sb)
990 struct cifs_ses *ses = tcon->ses;
991 struct TCP_Server_Info *server = cifs_pick_channel(ses);
992 __le16 *utf16_path = NULL;
993 int ea_name_len = strlen(ea_name);
994 int flags = CIFS_CP_CREATE_CLOSE_OP;
996 struct smb_rqst rqst[3];
998 struct kvec rsp_iov[3];
999 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1000 struct cifs_open_parms oparms;
1001 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1002 struct cifs_fid fid;
1003 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1004 unsigned int size[1];
1006 struct smb2_file_full_ea_info *ea = NULL;
1007 struct kvec close_iov[1];
1008 struct smb2_query_info_rsp *rsp;
1009 int rc, used_len = 0;
1011 if (smb3_encryption_required(tcon))
1012 flags |= CIFS_TRANSFORM_REQ;
1014 if (ea_name_len > 255)
1017 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1021 memset(rqst, 0, sizeof(rqst));
1022 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1023 memset(rsp_iov, 0, sizeof(rsp_iov));
1025 if (ses->server->ops->query_all_EAs) {
1027 rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1033 /* If we are adding a attribute we should first check
1034 * if there will be enough space available to store
1035 * the new EA. If not we should not add it since we
1036 * would not be able to even read the EAs back.
1038 rc = smb2_query_info_compound(xid, tcon, path,
1040 FILE_FULL_EA_INFORMATION,
1043 MAX_SMB2_CREATE_RESPONSE_SIZE -
1044 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1045 &rsp_iov[1], &resp_buftype[1], cifs_sb);
1047 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1048 used_len = le32_to_cpu(rsp->OutputBufferLength);
1050 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1051 resp_buftype[1] = CIFS_NO_BUFFER;
1052 memset(&rsp_iov[1], 0, sizeof(rsp_iov[1]));
1055 /* Use a fudge factor of 256 bytes in case we collide
1056 * with a different set_EAs command.
1058 if(CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1059 MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 <
1060 used_len + ea_name_len + ea_value_len + 1) {
1068 memset(&open_iov, 0, sizeof(open_iov));
1069 rqst[0].rq_iov = open_iov;
1070 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1072 memset(&oparms, 0, sizeof(oparms));
1074 oparms.desired_access = FILE_WRITE_EA;
1075 oparms.disposition = FILE_OPEN;
1076 oparms.create_options = cifs_create_options(cifs_sb, 0);
1078 oparms.reconnect = false;
1080 rc = SMB2_open_init(tcon, server,
1081 &rqst[0], &oplock, &oparms, utf16_path);
1084 smb2_set_next_command(tcon, &rqst[0]);
1088 memset(&si_iov, 0, sizeof(si_iov));
1089 rqst[1].rq_iov = si_iov;
1090 rqst[1].rq_nvec = 1;
1092 len = sizeof(*ea) + ea_name_len + ea_value_len + 1;
1093 ea = kzalloc(len, GFP_KERNEL);
1099 ea->ea_name_length = ea_name_len;
1100 ea->ea_value_length = cpu_to_le16(ea_value_len);
1101 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
1102 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
1107 rc = SMB2_set_info_init(tcon, server,
1108 &rqst[1], COMPOUND_FID,
1109 COMPOUND_FID, current->tgid,
1110 FILE_FULL_EA_INFORMATION,
1111 SMB2_O_INFO_FILE, 0, data, size);
1112 smb2_set_next_command(tcon, &rqst[1]);
1113 smb2_set_related(&rqst[1]);
1117 memset(&close_iov, 0, sizeof(close_iov));
1118 rqst[2].rq_iov = close_iov;
1119 rqst[2].rq_nvec = 1;
1120 rc = SMB2_close_init(tcon, server,
1121 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1122 smb2_set_related(&rqst[2]);
1124 rc = compound_send_recv(xid, ses, server,
1126 resp_buftype, rsp_iov);
1127 /* no need to bump num_remote_opens because handle immediately closed */
1132 SMB2_open_free(&rqst[0]);
1133 SMB2_set_info_free(&rqst[1]);
1134 SMB2_close_free(&rqst[2]);
1135 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1136 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1137 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1143 smb2_can_echo(struct TCP_Server_Info *server)
1145 return server->echoes;
1149 smb2_clear_stats(struct cifs_tcon *tcon)
1153 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1154 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1155 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1160 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1162 seq_puts(m, "\n\tShare Capabilities:");
1163 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1164 seq_puts(m, " DFS,");
1165 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1166 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1167 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1168 seq_puts(m, " SCALEOUT,");
1169 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1170 seq_puts(m, " CLUSTER,");
1171 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1172 seq_puts(m, " ASYMMETRIC,");
1173 if (tcon->capabilities == 0)
1174 seq_puts(m, " None");
1175 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1176 seq_puts(m, " Aligned,");
1177 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1178 seq_puts(m, " Partition Aligned,");
1179 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1180 seq_puts(m, " SSD,");
1181 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1182 seq_puts(m, " TRIM-support,");
1184 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1185 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1186 if (tcon->perf_sector_size)
1187 seq_printf(m, "\tOptimal sector size: 0x%x",
1188 tcon->perf_sector_size);
1189 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1193 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1195 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1196 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1199 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1200 * totals (requests sent) since those SMBs are per-session not per tcon
1202 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1203 (long long)(tcon->bytes_read),
1204 (long long)(tcon->bytes_written));
1205 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1206 atomic_read(&tcon->num_local_opens),
1207 atomic_read(&tcon->num_remote_opens));
1208 seq_printf(m, "\nTreeConnects: %d total %d failed",
1209 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1210 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1211 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1212 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1213 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1214 seq_printf(m, "\nCreates: %d total %d failed",
1215 atomic_read(&sent[SMB2_CREATE_HE]),
1216 atomic_read(&failed[SMB2_CREATE_HE]));
1217 seq_printf(m, "\nCloses: %d total %d failed",
1218 atomic_read(&sent[SMB2_CLOSE_HE]),
1219 atomic_read(&failed[SMB2_CLOSE_HE]));
1220 seq_printf(m, "\nFlushes: %d total %d failed",
1221 atomic_read(&sent[SMB2_FLUSH_HE]),
1222 atomic_read(&failed[SMB2_FLUSH_HE]));
1223 seq_printf(m, "\nReads: %d total %d failed",
1224 atomic_read(&sent[SMB2_READ_HE]),
1225 atomic_read(&failed[SMB2_READ_HE]));
1226 seq_printf(m, "\nWrites: %d total %d failed",
1227 atomic_read(&sent[SMB2_WRITE_HE]),
1228 atomic_read(&failed[SMB2_WRITE_HE]));
1229 seq_printf(m, "\nLocks: %d total %d failed",
1230 atomic_read(&sent[SMB2_LOCK_HE]),
1231 atomic_read(&failed[SMB2_LOCK_HE]));
1232 seq_printf(m, "\nIOCTLs: %d total %d failed",
1233 atomic_read(&sent[SMB2_IOCTL_HE]),
1234 atomic_read(&failed[SMB2_IOCTL_HE]));
1235 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1236 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1237 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1238 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1239 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1240 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1241 seq_printf(m, "\nQueryInfos: %d total %d failed",
1242 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1243 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1244 seq_printf(m, "\nSetInfos: %d total %d failed",
1245 atomic_read(&sent[SMB2_SET_INFO_HE]),
1246 atomic_read(&failed[SMB2_SET_INFO_HE]));
1247 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1248 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1249 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1253 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1255 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1256 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1258 cfile->fid.persistent_fid = fid->persistent_fid;
1259 cfile->fid.volatile_fid = fid->volatile_fid;
1260 cfile->fid.access = fid->access;
1261 #ifdef CONFIG_CIFS_DEBUG2
1262 cfile->fid.mid = fid->mid;
1263 #endif /* CIFS_DEBUG2 */
1264 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1266 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1267 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1271 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1272 struct cifs_fid *fid)
1274 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1278 smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon,
1279 struct cifsFileInfo *cfile)
1281 struct smb2_file_network_open_info file_inf;
1282 struct inode *inode;
1285 rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid,
1286 cfile->fid.volatile_fid, &file_inf);
1290 inode = d_inode(cfile->dentry);
1292 spin_lock(&inode->i_lock);
1293 CIFS_I(inode)->time = jiffies;
1295 /* Creation time should not need to be updated on close */
1296 if (file_inf.LastWriteTime)
1297 inode->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime);
1298 if (file_inf.ChangeTime)
1299 inode->i_ctime = cifs_NTtimeToUnix(file_inf.ChangeTime);
1300 if (file_inf.LastAccessTime)
1301 inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime);
1304 * i_blocks is not related to (i_size / i_blksize),
1305 * but instead 512 byte (2**9) size is required for
1306 * calculating num blocks.
1308 if (le64_to_cpu(file_inf.AllocationSize) > 4096)
1310 (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9;
1312 /* End of file and Attributes should not have to be updated on close */
1313 spin_unlock(&inode->i_lock);
1317 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1318 u64 persistent_fid, u64 volatile_fid,
1319 struct copychunk_ioctl *pcchunk)
1322 unsigned int ret_data_len;
1323 struct resume_key_req *res_key;
1325 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1326 FSCTL_SRV_REQUEST_RESUME_KEY, NULL, 0 /* no input */,
1327 CIFSMaxBufSize, (char **)&res_key, &ret_data_len);
1329 if (rc == -EOPNOTSUPP) {
1330 pr_warn_once("Server share %s does not support copy range\n", tcon->treeName);
1331 goto req_res_key_exit;
1333 cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1334 goto req_res_key_exit;
1336 if (ret_data_len < sizeof(struct resume_key_req)) {
1337 cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n");
1339 goto req_res_key_exit;
1341 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1349 struct smb_rqst rqst[3];
1350 struct kvec rsp_iov[3];
1351 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1352 struct kvec qi_iov[1];
1353 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
1354 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1355 struct kvec close_iov[1];
1359 smb2_ioctl_query_info(const unsigned int xid,
1360 struct cifs_tcon *tcon,
1361 struct cifs_sb_info *cifs_sb,
1362 __le16 *path, int is_dir,
1365 struct iqi_vars *vars;
1366 struct smb_rqst *rqst;
1367 struct kvec *rsp_iov;
1368 struct cifs_ses *ses = tcon->ses;
1369 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1370 char __user *arg = (char __user *)p;
1371 struct smb_query_info qi;
1372 struct smb_query_info __user *pqi;
1374 int flags = CIFS_CP_CREATE_CLOSE_OP;
1375 struct smb2_query_info_rsp *qi_rsp = NULL;
1376 struct smb2_ioctl_rsp *io_rsp = NULL;
1377 void *buffer = NULL;
1378 int resp_buftype[3];
1379 struct cifs_open_parms oparms;
1380 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1381 struct cifs_fid fid;
1382 unsigned int size[2];
1384 int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR;
1385 void (*free_req1_func)(struct smb_rqst *r);
1387 vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
1390 rqst = &vars->rqst[0];
1391 rsp_iov = &vars->rsp_iov[0];
1393 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1395 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info))) {
1399 if (qi.output_buffer_length > 1024) {
1404 if (!ses || !server) {
1409 if (smb3_encryption_required(tcon))
1410 flags |= CIFS_TRANSFORM_REQ;
1412 if (qi.output_buffer_length) {
1413 buffer = memdup_user(arg + sizeof(struct smb_query_info), qi.output_buffer_length);
1414 if (IS_ERR(buffer)) {
1415 rc = PTR_ERR(buffer);
1421 rqst[0].rq_iov = &vars->open_iov[0];
1422 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1424 memset(&oparms, 0, sizeof(oparms));
1426 oparms.disposition = FILE_OPEN;
1427 oparms.create_options = cifs_create_options(cifs_sb, create_options);
1429 oparms.reconnect = false;
1431 if (qi.flags & PASSTHRU_FSCTL) {
1432 switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1433 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1434 oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1436 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1437 oparms.desired_access = GENERIC_ALL;
1439 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1440 oparms.desired_access = GENERIC_READ;
1442 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1443 oparms.desired_access = GENERIC_WRITE;
1446 } else if (qi.flags & PASSTHRU_SET_INFO) {
1447 oparms.desired_access = GENERIC_WRITE;
1449 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1452 rc = SMB2_open_init(tcon, server,
1453 &rqst[0], &oplock, &oparms, path);
1455 goto free_output_buffer;
1456 smb2_set_next_command(tcon, &rqst[0]);
1459 if (qi.flags & PASSTHRU_FSCTL) {
1460 /* Can eventually relax perm check since server enforces too */
1461 if (!capable(CAP_SYS_ADMIN)) {
1465 rqst[1].rq_iov = &vars->io_iov[0];
1466 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1468 rc = SMB2_ioctl_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1469 qi.info_type, buffer, qi.output_buffer_length,
1470 CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1471 MAX_SMB2_CLOSE_RESPONSE_SIZE);
1472 free_req1_func = SMB2_ioctl_free;
1473 } else if (qi.flags == PASSTHRU_SET_INFO) {
1474 /* Can eventually relax perm check since server enforces too */
1475 if (!capable(CAP_SYS_ADMIN)) {
1479 if (qi.output_buffer_length < 8) {
1483 rqst[1].rq_iov = &vars->si_iov[0];
1484 rqst[1].rq_nvec = 1;
1486 /* MS-FSCC 2.4.13 FileEndOfFileInformation */
1490 rc = SMB2_set_info_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1491 current->tgid, FILE_END_OF_FILE_INFORMATION,
1492 SMB2_O_INFO_FILE, 0, data, size);
1493 free_req1_func = SMB2_set_info_free;
1494 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1495 rqst[1].rq_iov = &vars->qi_iov[0];
1496 rqst[1].rq_nvec = 1;
1498 rc = SMB2_query_info_init(tcon, server,
1499 &rqst[1], COMPOUND_FID,
1500 COMPOUND_FID, qi.file_info_class,
1501 qi.info_type, qi.additional_information,
1502 qi.input_buffer_length,
1503 qi.output_buffer_length, buffer);
1504 free_req1_func = SMB2_query_info_free;
1505 } else { /* unknown flags */
1506 cifs_tcon_dbg(VFS, "Invalid passthru query flags: 0x%x\n",
1513 smb2_set_next_command(tcon, &rqst[1]);
1514 smb2_set_related(&rqst[1]);
1517 rqst[2].rq_iov = &vars->close_iov[0];
1518 rqst[2].rq_nvec = 1;
1520 rc = SMB2_close_init(tcon, server,
1521 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1524 smb2_set_related(&rqst[2]);
1526 rc = compound_send_recv(xid, ses, server,
1528 resp_buftype, rsp_iov);
1532 /* No need to bump num_remote_opens since handle immediately closed */
1533 if (qi.flags & PASSTHRU_FSCTL) {
1534 pqi = (struct smb_query_info __user *)arg;
1535 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1536 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1537 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1538 if (qi.input_buffer_length > 0 &&
1539 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length
1540 > rsp_iov[1].iov_len) {
1545 if (copy_to_user(&pqi->input_buffer_length,
1546 &qi.input_buffer_length,
1547 sizeof(qi.input_buffer_length))) {
1552 if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1553 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1554 qi.input_buffer_length))
1557 pqi = (struct smb_query_info __user *)arg;
1558 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1559 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1560 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1561 if (copy_to_user(&pqi->input_buffer_length,
1562 &qi.input_buffer_length,
1563 sizeof(qi.input_buffer_length))) {
1568 if (copy_to_user(pqi + 1, qi_rsp->Buffer,
1569 qi.input_buffer_length))
1574 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1575 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1576 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1577 SMB2_close_free(&rqst[2]);
1579 free_req1_func(&rqst[1]);
1581 SMB2_open_free(&rqst[0]);
1590 smb2_copychunk_range(const unsigned int xid,
1591 struct cifsFileInfo *srcfile,
1592 struct cifsFileInfo *trgtfile, u64 src_off,
1593 u64 len, u64 dest_off)
1596 unsigned int ret_data_len;
1597 struct copychunk_ioctl *pcchunk;
1598 struct copychunk_ioctl_rsp *retbuf = NULL;
1599 struct cifs_tcon *tcon;
1600 int chunks_copied = 0;
1601 bool chunk_sizes_updated = false;
1602 ssize_t bytes_written, total_bytes_written = 0;
1604 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1605 if (pcchunk == NULL)
1608 cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
1609 /* Request a key from the server to identify the source of the copy */
1610 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1611 srcfile->fid.persistent_fid,
1612 srcfile->fid.volatile_fid, pcchunk);
1614 /* Note: request_res_key sets res_key null only if rc !=0 */
1618 /* For now array only one chunk long, will make more flexible later */
1619 pcchunk->ChunkCount = cpu_to_le32(1);
1620 pcchunk->Reserved = 0;
1621 pcchunk->Reserved2 = 0;
1623 tcon = tlink_tcon(trgtfile->tlink);
1626 pcchunk->SourceOffset = cpu_to_le64(src_off);
1627 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1629 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
1631 /* Request server copy to target from src identified by key */
1634 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1635 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1636 (char *)pcchunk, sizeof(struct copychunk_ioctl),
1637 CIFSMaxBufSize, (char **)&retbuf, &ret_data_len);
1640 sizeof(struct copychunk_ioctl_rsp)) {
1641 cifs_tcon_dbg(VFS, "Invalid cchunk response size\n");
1645 if (retbuf->TotalBytesWritten == 0) {
1646 cifs_dbg(FYI, "no bytes copied\n");
1651 * Check if server claimed to write more than we asked
1653 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1654 le32_to_cpu(pcchunk->Length)) {
1655 cifs_tcon_dbg(VFS, "Invalid copy chunk response\n");
1659 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1660 cifs_tcon_dbg(VFS, "Invalid num chunks written\n");
1666 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1667 src_off += bytes_written;
1668 dest_off += bytes_written;
1669 len -= bytes_written;
1670 total_bytes_written += bytes_written;
1672 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1673 le32_to_cpu(retbuf->ChunksWritten),
1674 le32_to_cpu(retbuf->ChunkBytesWritten),
1676 } else if (rc == -EINVAL) {
1677 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1680 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1681 le32_to_cpu(retbuf->ChunksWritten),
1682 le32_to_cpu(retbuf->ChunkBytesWritten),
1683 le32_to_cpu(retbuf->TotalBytesWritten));
1686 * Check if this is the first request using these sizes,
1687 * (ie check if copy succeed once with original sizes
1688 * and check if the server gave us different sizes after
1689 * we already updated max sizes on previous request).
1690 * if not then why is the server returning an error now
1692 if ((chunks_copied != 0) || chunk_sizes_updated)
1695 /* Check that server is not asking us to grow size */
1696 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1697 tcon->max_bytes_chunk)
1698 tcon->max_bytes_chunk =
1699 le32_to_cpu(retbuf->ChunkBytesWritten);
1701 goto cchunk_out; /* server gave us bogus size */
1703 /* No need to change MaxChunks since already set to 1 */
1704 chunk_sizes_updated = true;
1715 return total_bytes_written;
1719 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1720 struct cifs_fid *fid)
1722 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1726 smb2_read_data_offset(char *buf)
1728 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1730 return rsp->DataOffset;
1734 smb2_read_data_length(char *buf, bool in_remaining)
1736 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1739 return le32_to_cpu(rsp->DataRemaining);
1741 return le32_to_cpu(rsp->DataLength);
1746 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1747 struct cifs_io_parms *parms, unsigned int *bytes_read,
1748 char **buf, int *buf_type)
1750 parms->persistent_fid = pfid->persistent_fid;
1751 parms->volatile_fid = pfid->volatile_fid;
1752 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1756 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1757 struct cifs_io_parms *parms, unsigned int *written,
1758 struct kvec *iov, unsigned long nr_segs)
1761 parms->persistent_fid = pfid->persistent_fid;
1762 parms->volatile_fid = pfid->volatile_fid;
1763 return SMB2_write(xid, parms, written, iov, nr_segs);
1766 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1767 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1768 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1770 struct cifsInodeInfo *cifsi;
1773 cifsi = CIFS_I(inode);
1775 /* if file already sparse don't bother setting sparse again */
1776 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1777 return true; /* already sparse */
1779 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1780 return true; /* already not sparse */
1783 * Can't check for sparse support on share the usual way via the
1784 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1785 * since Samba server doesn't set the flag on the share, yet
1786 * supports the set sparse FSCTL and returns sparse correctly
1787 * in the file attributes. If we fail setting sparse though we
1788 * mark that server does not support sparse files for this share
1789 * to avoid repeatedly sending the unsupported fsctl to server
1790 * if the file is repeatedly extended.
1792 if (tcon->broken_sparse_sup)
1795 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1796 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1797 &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
1799 tcon->broken_sparse_sup = true;
1800 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1805 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1807 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1813 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1814 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1816 __le64 eof = cpu_to_le64(size);
1817 struct inode *inode;
1820 * If extending file more than one page make sparse. Many Linux fs
1821 * make files sparse by default when extending via ftruncate
1823 inode = d_inode(cfile->dentry);
1825 if (!set_alloc && (size > inode->i_size + 8192)) {
1826 __u8 set_sparse = 1;
1828 /* whether set sparse succeeds or not, extend the file */
1829 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1832 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1833 cfile->fid.volatile_fid, cfile->pid, &eof);
1837 smb2_duplicate_extents(const unsigned int xid,
1838 struct cifsFileInfo *srcfile,
1839 struct cifsFileInfo *trgtfile, u64 src_off,
1840 u64 len, u64 dest_off)
1843 unsigned int ret_data_len;
1844 struct inode *inode;
1845 struct duplicate_extents_to_file dup_ext_buf;
1846 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1848 /* server fileays advertise duplicate extent support with this flag */
1849 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1850 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1853 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1854 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1855 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1856 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1857 dup_ext_buf.ByteCount = cpu_to_le64(len);
1858 cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
1859 src_off, dest_off, len);
1861 inode = d_inode(trgtfile->dentry);
1862 if (inode->i_size < dest_off + len) {
1863 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1865 goto duplicate_extents_out;
1868 * Although also could set plausible allocation size (i_blocks)
1869 * here in addition to setting the file size, in reflink
1870 * it is likely that the target file is sparse. Its allocation
1871 * size will be queried on next revalidate, but it is important
1872 * to make sure that file's cached size is updated immediately
1874 cifs_setsize(inode, dest_off + len);
1876 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1877 trgtfile->fid.volatile_fid,
1878 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1879 (char *)&dup_ext_buf,
1880 sizeof(struct duplicate_extents_to_file),
1881 CIFSMaxBufSize, NULL,
1884 if (ret_data_len > 0)
1885 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
1887 duplicate_extents_out:
1892 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1893 struct cifsFileInfo *cfile)
1895 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1896 cfile->fid.volatile_fid);
1900 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
1901 struct cifsFileInfo *cfile)
1903 struct fsctl_set_integrity_information_req integr_info;
1904 unsigned int ret_data_len;
1906 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
1907 integr_info.Flags = 0;
1908 integr_info.Reserved = 0;
1910 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1911 cfile->fid.volatile_fid,
1912 FSCTL_SET_INTEGRITY_INFORMATION,
1913 (char *)&integr_info,
1914 sizeof(struct fsctl_set_integrity_information_req),
1915 CIFSMaxBufSize, NULL,
1920 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
1921 #define GMT_TOKEN_SIZE 50
1923 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
1926 * Input buffer contains (empty) struct smb_snapshot array with size filled in
1927 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
1930 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
1931 struct cifsFileInfo *cfile, void __user *ioc_buf)
1933 char *retbuf = NULL;
1934 unsigned int ret_data_len = 0;
1936 u32 max_response_size;
1937 struct smb_snapshot_array snapshot_in;
1940 * On the first query to enumerate the list of snapshots available
1941 * for this volume the buffer begins with 0 (number of snapshots
1942 * which can be returned is zero since at that point we do not know
1943 * how big the buffer needs to be). On the second query,
1944 * it (ret_data_len) is set to number of snapshots so we can
1945 * know to set the maximum response size larger (see below).
1947 if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
1951 * Note that for snapshot queries that servers like Azure expect that
1952 * the first query be minimal size (and just used to get the number/size
1953 * of previous versions) so response size must be specified as EXACTLY
1954 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
1957 if (ret_data_len == 0)
1958 max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
1960 max_response_size = CIFSMaxBufSize;
1962 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1963 cfile->fid.volatile_fid,
1964 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
1965 NULL, 0 /* no input data */, max_response_size,
1968 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
1973 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
1975 if (copy_from_user(&snapshot_in, ioc_buf,
1976 sizeof(struct smb_snapshot_array))) {
1983 * Check for min size, ie not large enough to fit even one GMT
1984 * token (snapshot). On the first ioctl some users may pass in
1985 * smaller size (or zero) to simply get the size of the array
1986 * so the user space caller can allocate sufficient memory
1987 * and retry the ioctl again with larger array size sufficient
1988 * to hold all of the snapshot GMT tokens on the second try.
1990 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
1991 ret_data_len = sizeof(struct smb_snapshot_array);
1994 * We return struct SRV_SNAPSHOT_ARRAY, followed by
1995 * the snapshot array (of 50 byte GMT tokens) each
1996 * representing an available previous version of the data
1998 if (ret_data_len > (snapshot_in.snapshot_array_size +
1999 sizeof(struct smb_snapshot_array)))
2000 ret_data_len = snapshot_in.snapshot_array_size +
2001 sizeof(struct smb_snapshot_array);
2003 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
2014 smb3_notify(const unsigned int xid, struct file *pfile,
2015 void __user *ioc_buf)
2017 struct smb3_notify notify;
2018 struct dentry *dentry = pfile->f_path.dentry;
2019 struct inode *inode = file_inode(pfile);
2020 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2021 struct cifs_open_parms oparms;
2022 struct cifs_fid fid;
2023 struct cifs_tcon *tcon;
2024 const unsigned char *path;
2025 void *page = alloc_dentry_path();
2026 __le16 *utf16_path = NULL;
2027 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2030 path = build_path_from_dentry(dentry, page);
2036 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2037 if (utf16_path == NULL) {
2042 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify))) {
2047 tcon = cifs_sb_master_tcon(cifs_sb);
2049 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
2050 oparms.disposition = FILE_OPEN;
2051 oparms.create_options = cifs_create_options(cifs_sb, 0);
2053 oparms.reconnect = false;
2055 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
2060 rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid,
2061 notify.watch_tree, notify.completion_filter);
2063 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2065 cifs_dbg(FYI, "change notify for path %s rc %d\n", path, rc);
2068 free_dentry_path(page);
2074 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
2075 const char *path, struct cifs_sb_info *cifs_sb,
2076 struct cifs_fid *fid, __u16 search_flags,
2077 struct cifs_search_info *srch_inf)
2080 struct smb_rqst rqst[2];
2081 struct kvec rsp_iov[2];
2082 int resp_buftype[2];
2083 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2084 struct kvec qd_iov[SMB2_QUERY_DIRECTORY_IOV_SIZE];
2086 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2087 struct cifs_open_parms oparms;
2088 struct smb2_query_directory_rsp *qd_rsp = NULL;
2089 struct smb2_create_rsp *op_rsp = NULL;
2090 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2091 int retry_count = 0;
2093 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2097 if (smb3_encryption_required(tcon))
2098 flags |= CIFS_TRANSFORM_REQ;
2100 memset(rqst, 0, sizeof(rqst));
2101 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
2102 memset(rsp_iov, 0, sizeof(rsp_iov));
2105 memset(&open_iov, 0, sizeof(open_iov));
2106 rqst[0].rq_iov = open_iov;
2107 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2110 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
2111 oparms.disposition = FILE_OPEN;
2112 oparms.create_options = cifs_create_options(cifs_sb, 0);
2114 oparms.reconnect = false;
2116 rc = SMB2_open_init(tcon, server,
2117 &rqst[0], &oplock, &oparms, utf16_path);
2120 smb2_set_next_command(tcon, &rqst[0]);
2122 /* Query directory */
2123 srch_inf->entries_in_buffer = 0;
2124 srch_inf->index_of_last_entry = 2;
2126 memset(&qd_iov, 0, sizeof(qd_iov));
2127 rqst[1].rq_iov = qd_iov;
2128 rqst[1].rq_nvec = SMB2_QUERY_DIRECTORY_IOV_SIZE;
2130 rc = SMB2_query_directory_init(xid, tcon, server,
2132 COMPOUND_FID, COMPOUND_FID,
2133 0, srch_inf->info_level);
2137 smb2_set_related(&rqst[1]);
2140 rc = compound_send_recv(xid, tcon->ses, server,
2142 resp_buftype, rsp_iov);
2144 if (rc == -EAGAIN && retry_count++ < 10)
2147 /* If the open failed there is nothing to do */
2148 op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
2149 if (op_rsp == NULL || op_rsp->hdr.Status != STATUS_SUCCESS) {
2150 cifs_dbg(FYI, "query_dir_first: open failed rc=%d\n", rc);
2153 fid->persistent_fid = op_rsp->PersistentFileId;
2154 fid->volatile_fid = op_rsp->VolatileFileId;
2156 /* Anything else than ENODATA means a genuine error */
2157 if (rc && rc != -ENODATA) {
2158 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2159 cifs_dbg(FYI, "query_dir_first: query directory failed rc=%d\n", rc);
2160 trace_smb3_query_dir_err(xid, fid->persistent_fid,
2161 tcon->tid, tcon->ses->Suid, 0, 0, rc);
2165 atomic_inc(&tcon->num_remote_opens);
2167 qd_rsp = (struct smb2_query_directory_rsp *)rsp_iov[1].iov_base;
2168 if (qd_rsp->hdr.Status == STATUS_NO_MORE_FILES) {
2169 trace_smb3_query_dir_done(xid, fid->persistent_fid,
2170 tcon->tid, tcon->ses->Suid, 0, 0);
2171 srch_inf->endOfSearch = true;
2176 rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1],
2179 trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid,
2180 tcon->ses->Suid, 0, 0, rc);
2183 resp_buftype[1] = CIFS_NO_BUFFER;
2185 trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid,
2186 tcon->ses->Suid, 0, srch_inf->entries_in_buffer);
2190 SMB2_open_free(&rqst[0]);
2191 SMB2_query_directory_free(&rqst[1]);
2192 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2193 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2198 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
2199 struct cifs_fid *fid, __u16 search_flags,
2200 struct cifs_search_info *srch_inf)
2202 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
2203 fid->volatile_fid, 0, srch_inf);
2207 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
2208 struct cifs_fid *fid)
2210 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2214 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2215 * the number of credits and return true. Otherwise - return false.
2218 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
2220 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2221 int scredits, in_flight;
2223 if (shdr->Status != STATUS_PENDING)
2226 if (shdr->CreditRequest) {
2227 spin_lock(&server->req_lock);
2228 server->credits += le16_to_cpu(shdr->CreditRequest);
2229 scredits = server->credits;
2230 in_flight = server->in_flight;
2231 spin_unlock(&server->req_lock);
2232 wake_up(&server->request_q);
2234 trace_smb3_pend_credits(server->CurrentMid,
2235 server->conn_id, server->hostname, scredits,
2236 le16_to_cpu(shdr->CreditRequest), in_flight);
2237 cifs_dbg(FYI, "%s: status pending add %u credits total=%d\n",
2238 __func__, le16_to_cpu(shdr->CreditRequest), scredits);
2245 smb2_is_session_expired(char *buf)
2247 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2249 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
2250 shdr->Status != STATUS_USER_SESSION_DELETED)
2253 trace_smb3_ses_expired(le32_to_cpu(shdr->Id.SyncId.TreeId),
2254 le64_to_cpu(shdr->SessionId),
2255 le16_to_cpu(shdr->Command),
2256 le64_to_cpu(shdr->MessageId));
2257 cifs_dbg(FYI, "Session expired or deleted\n");
2263 smb2_is_status_io_timeout(char *buf)
2265 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2267 if (shdr->Status == STATUS_IO_TIMEOUT)
2274 smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server)
2276 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2277 struct cifs_ses *ses;
2278 struct cifs_tcon *tcon;
2280 if (shdr->Status != STATUS_NETWORK_NAME_DELETED)
2283 spin_lock(&cifs_tcp_ses_lock);
2284 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
2285 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
2286 if (tcon->tid == le32_to_cpu(shdr->Id.SyncId.TreeId)) {
2287 spin_lock(&tcon->tc_lock);
2288 tcon->need_reconnect = true;
2289 spin_unlock(&tcon->tc_lock);
2290 spin_unlock(&cifs_tcp_ses_lock);
2291 pr_warn_once("Server share %s deleted.\n",
2297 spin_unlock(&cifs_tcp_ses_lock);
2301 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
2302 struct cifsInodeInfo *cinode)
2304 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
2305 return SMB2_lease_break(0, tcon, cinode->lease_key,
2306 smb2_get_lease_state(cinode));
2308 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
2310 CIFS_CACHE_READ(cinode) ? 1 : 0);
2314 smb2_set_related(struct smb_rqst *rqst)
2316 struct smb2_hdr *shdr;
2318 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2320 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2323 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2326 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
2329 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
2331 struct smb2_hdr *shdr;
2332 struct cifs_ses *ses = tcon->ses;
2333 struct TCP_Server_Info *server = ses->server;
2334 unsigned long len = smb_rqst_len(server, rqst);
2337 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2339 cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2343 /* SMB headers in a compound are 8 byte aligned. */
2345 /* No padding needed */
2349 num_padding = 8 - (len & 7);
2350 if (!smb3_encryption_required(tcon)) {
2352 * If we do not have encryption then we can just add an extra
2353 * iov for the padding.
2355 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2356 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2361 * We can not add a small padding iov for the encryption case
2362 * because the encryption framework can not handle the padding
2364 * We have to flatten this into a single buffer and add
2365 * the padding to it.
2367 for (i = 1; i < rqst->rq_nvec; i++) {
2368 memcpy(rqst->rq_iov[0].iov_base +
2369 rqst->rq_iov[0].iov_len,
2370 rqst->rq_iov[i].iov_base,
2371 rqst->rq_iov[i].iov_len);
2372 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2374 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2376 rqst->rq_iov[0].iov_len += num_padding;
2382 shdr->NextCommand = cpu_to_le32(len);
2386 * Passes the query info response back to the caller on success.
2387 * Caller need to free this with free_rsp_buf().
2390 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2391 const char *path, u32 desired_access,
2392 u32 class, u32 type, u32 output_len,
2393 struct kvec *rsp, int *buftype,
2394 struct cifs_sb_info *cifs_sb)
2396 struct cifs_ses *ses = tcon->ses;
2397 struct TCP_Server_Info *server = cifs_pick_channel(ses);
2398 int flags = CIFS_CP_CREATE_CLOSE_OP;
2399 struct smb_rqst rqst[3];
2400 int resp_buftype[3];
2401 struct kvec rsp_iov[3];
2402 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2403 struct kvec qi_iov[1];
2404 struct kvec close_iov[1];
2405 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2406 struct cifs_open_parms oparms;
2407 struct cifs_fid fid;
2410 struct cached_fid *cfid = NULL;
2414 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2418 if (smb3_encryption_required(tcon))
2419 flags |= CIFS_TRANSFORM_REQ;
2421 memset(rqst, 0, sizeof(rqst));
2422 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2423 memset(rsp_iov, 0, sizeof(rsp_iov));
2426 * We can only call this for things we know are directories.
2428 if (!strcmp(path, ""))
2429 open_cached_dir(xid, tcon, path, cifs_sb, false,
2430 &cfid); /* cfid null if open dir failed */
2432 memset(&open_iov, 0, sizeof(open_iov));
2433 rqst[0].rq_iov = open_iov;
2434 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2437 oparms.desired_access = desired_access;
2438 oparms.disposition = FILE_OPEN;
2439 oparms.create_options = cifs_create_options(cifs_sb, 0);
2441 oparms.reconnect = false;
2443 rc = SMB2_open_init(tcon, server,
2444 &rqst[0], &oplock, &oparms, utf16_path);
2447 smb2_set_next_command(tcon, &rqst[0]);
2449 memset(&qi_iov, 0, sizeof(qi_iov));
2450 rqst[1].rq_iov = qi_iov;
2451 rqst[1].rq_nvec = 1;
2454 rc = SMB2_query_info_init(tcon, server,
2456 cfid->fid.persistent_fid,
2457 cfid->fid.volatile_fid,
2462 rc = SMB2_query_info_init(tcon, server,
2473 smb2_set_next_command(tcon, &rqst[1]);
2474 smb2_set_related(&rqst[1]);
2477 memset(&close_iov, 0, sizeof(close_iov));
2478 rqst[2].rq_iov = close_iov;
2479 rqst[2].rq_nvec = 1;
2481 rc = SMB2_close_init(tcon, server,
2482 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2485 smb2_set_related(&rqst[2]);
2488 rc = compound_send_recv(xid, ses, server,
2490 &resp_buftype[1], &rsp_iov[1]);
2492 rc = compound_send_recv(xid, ses, server,
2494 resp_buftype, rsp_iov);
2497 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2498 if (rc == -EREMCHG) {
2499 tcon->need_reconnect = true;
2500 pr_warn_once("server share %s deleted\n",
2506 *buftype = resp_buftype[1];
2510 SMB2_open_free(&rqst[0]);
2511 SMB2_query_info_free(&rqst[1]);
2512 SMB2_close_free(&rqst[2]);
2513 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2514 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2516 close_cached_dir(cfid);
2521 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2522 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2524 struct smb2_query_info_rsp *rsp;
2525 struct smb2_fs_full_size_info *info = NULL;
2526 struct kvec rsp_iov = {NULL, 0};
2527 int buftype = CIFS_NO_BUFFER;
2531 rc = smb2_query_info_compound(xid, tcon, "",
2532 FILE_READ_ATTRIBUTES,
2533 FS_FULL_SIZE_INFORMATION,
2534 SMB2_O_INFO_FILESYSTEM,
2535 sizeof(struct smb2_fs_full_size_info),
2536 &rsp_iov, &buftype, cifs_sb);
2540 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2541 buf->f_type = SMB2_SUPER_MAGIC;
2542 info = (struct smb2_fs_full_size_info *)(
2543 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2544 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2545 le32_to_cpu(rsp->OutputBufferLength),
2547 sizeof(struct smb2_fs_full_size_info));
2549 smb2_copy_fs_info_to_kstatfs(info, buf);
2552 free_rsp_buf(buftype, rsp_iov.iov_base);
2557 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2558 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2561 __le16 srch_path = 0; /* Null - open root of share */
2562 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2563 struct cifs_open_parms oparms;
2564 struct cifs_fid fid;
2566 if (!tcon->posix_extensions)
2567 return smb2_queryfs(xid, tcon, cifs_sb, buf);
2570 oparms.desired_access = FILE_READ_ATTRIBUTES;
2571 oparms.disposition = FILE_OPEN;
2572 oparms.create_options = cifs_create_options(cifs_sb, 0);
2574 oparms.reconnect = false;
2576 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
2581 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2582 fid.volatile_fid, buf);
2583 buf->f_type = SMB2_SUPER_MAGIC;
2584 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2589 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2591 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2592 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2596 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2597 __u64 length, __u32 type, int lock, int unlock, bool wait)
2599 if (unlock && !lock)
2600 type = SMB2_LOCKFLAG_UNLOCK;
2601 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2602 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2603 current->tgid, length, offset, type, wait);
2607 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2609 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2613 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2615 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2619 smb2_new_lease_key(struct cifs_fid *fid)
2621 generate_random_uuid(fid->lease_key);
2625 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2626 const char *search_name,
2627 struct dfs_info3_param **target_nodes,
2628 unsigned int *num_of_nodes,
2629 const struct nls_table *nls_codepage, int remap)
2632 __le16 *utf16_path = NULL;
2633 int utf16_path_len = 0;
2634 struct cifs_tcon *tcon;
2635 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2636 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2637 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2638 int retry_count = 0;
2640 cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name);
2643 * Try to use the IPC tcon, otherwise just use any
2645 tcon = ses->tcon_ipc;
2647 spin_lock(&cifs_tcp_ses_lock);
2648 tcon = list_first_entry_or_null(&ses->tcon_list,
2653 spin_unlock(&cifs_tcp_ses_lock);
2657 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2663 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2665 nls_codepage, remap);
2671 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2672 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2678 /* Highest DFS referral version understood */
2679 dfs_req->MaxReferralLevel = DFS_VERSION;
2681 /* Path to resolve in an UTF-16 null-terminated string */
2682 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2685 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2686 FSCTL_DFS_GET_REFERRALS,
2687 (char *)dfs_req, dfs_req_size, CIFSMaxBufSize,
2688 (char **)&dfs_rsp, &dfs_rsp_size);
2689 if (!is_retryable_error(rc))
2691 usleep_range(512, 2048);
2692 } while (++retry_count < 5);
2695 if (!is_retryable_error(rc) && rc != -ENOENT && rc != -EOPNOTSUPP)
2696 cifs_tcon_dbg(VFS, "%s: ioctl error: rc=%d\n", __func__, rc);
2700 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
2701 num_of_nodes, target_nodes,
2702 nls_codepage, remap, search_name,
2703 true /* is_unicode */);
2705 cifs_tcon_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc);
2710 if (tcon && !tcon->ipc) {
2711 /* ipc tcons are not refcounted */
2712 spin_lock(&cifs_tcp_ses_lock);
2714 /* tc_count can never go negative */
2715 WARN_ON(tcon->tc_count < 0);
2716 spin_unlock(&cifs_tcp_ses_lock);
2725 parse_reparse_posix(struct reparse_posix_data *symlink_buf,
2726 u32 plen, char **target_path,
2727 struct cifs_sb_info *cifs_sb)
2731 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
2732 len = le16_to_cpu(symlink_buf->ReparseDataLength);
2734 if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
2735 cifs_dbg(VFS, "%lld not a supported symlink type\n",
2736 le64_to_cpu(symlink_buf->InodeType));
2740 *target_path = cifs_strndup_from_utf16(
2741 symlink_buf->PathBuffer,
2742 len, true, cifs_sb->local_nls);
2743 if (!(*target_path))
2746 convert_delimiter(*target_path, '/');
2747 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2753 parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
2754 u32 plen, char **target_path,
2755 struct cifs_sb_info *cifs_sb)
2757 unsigned int sub_len;
2758 unsigned int sub_offset;
2760 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */
2762 sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset);
2763 sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength);
2764 if (sub_offset + 20 > plen ||
2765 sub_offset + sub_len + 20 > plen) {
2766 cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
2770 *target_path = cifs_strndup_from_utf16(
2771 symlink_buf->PathBuffer + sub_offset,
2772 sub_len, true, cifs_sb->local_nls);
2773 if (!(*target_path))
2776 convert_delimiter(*target_path, '/');
2777 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2783 parse_reparse_point(struct reparse_data_buffer *buf,
2784 u32 plen, char **target_path,
2785 struct cifs_sb_info *cifs_sb)
2787 if (plen < sizeof(struct reparse_data_buffer)) {
2788 cifs_dbg(VFS, "reparse buffer is too small. Must be at least 8 bytes but was %d\n",
2793 if (plen < le16_to_cpu(buf->ReparseDataLength) +
2794 sizeof(struct reparse_data_buffer)) {
2795 cifs_dbg(VFS, "srv returned invalid reparse buf length: %d\n",
2800 /* See MS-FSCC 2.1.2 */
2801 switch (le32_to_cpu(buf->ReparseTag)) {
2802 case IO_REPARSE_TAG_NFS:
2803 return parse_reparse_posix(
2804 (struct reparse_posix_data *)buf,
2805 plen, target_path, cifs_sb);
2806 case IO_REPARSE_TAG_SYMLINK:
2807 return parse_reparse_symlink(
2808 (struct reparse_symlink_data_buffer *)buf,
2809 plen, target_path, cifs_sb);
2811 cifs_dbg(VFS, "srv returned unknown symlink buffer tag:0x%08x\n",
2812 le32_to_cpu(buf->ReparseTag));
2817 #define SMB2_SYMLINK_STRUCT_SIZE \
2818 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
2821 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
2822 struct cifs_sb_info *cifs_sb, const char *full_path,
2823 char **target_path, bool is_reparse_point)
2826 __le16 *utf16_path = NULL;
2827 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2828 struct cifs_open_parms oparms;
2829 struct cifs_fid fid;
2830 struct kvec err_iov = {NULL, 0};
2831 struct smb2_err_rsp *err_buf = NULL;
2832 struct smb2_symlink_err_rsp *symlink;
2833 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2834 unsigned int sub_len;
2835 unsigned int sub_offset;
2836 unsigned int print_len;
2837 unsigned int print_offset;
2838 int flags = CIFS_CP_CREATE_CLOSE_OP;
2839 struct smb_rqst rqst[3];
2840 int resp_buftype[3];
2841 struct kvec rsp_iov[3];
2842 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2843 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2844 struct kvec close_iov[1];
2845 struct smb2_create_rsp *create_rsp;
2846 struct smb2_ioctl_rsp *ioctl_rsp;
2847 struct reparse_data_buffer *reparse_buf;
2848 int create_options = is_reparse_point ? OPEN_REPARSE_POINT : 0;
2851 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2853 *target_path = NULL;
2855 if (smb3_encryption_required(tcon))
2856 flags |= CIFS_TRANSFORM_REQ;
2858 memset(rqst, 0, sizeof(rqst));
2859 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2860 memset(rsp_iov, 0, sizeof(rsp_iov));
2862 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
2867 memset(&open_iov, 0, sizeof(open_iov));
2868 rqst[0].rq_iov = open_iov;
2869 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2871 memset(&oparms, 0, sizeof(oparms));
2873 oparms.desired_access = FILE_READ_ATTRIBUTES;
2874 oparms.disposition = FILE_OPEN;
2875 oparms.create_options = cifs_create_options(cifs_sb, create_options);
2877 oparms.reconnect = false;
2879 rc = SMB2_open_init(tcon, server,
2880 &rqst[0], &oplock, &oparms, utf16_path);
2883 smb2_set_next_command(tcon, &rqst[0]);
2887 memset(&io_iov, 0, sizeof(io_iov));
2888 rqst[1].rq_iov = io_iov;
2889 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
2891 rc = SMB2_ioctl_init(tcon, server,
2892 &rqst[1], fid.persistent_fid,
2893 fid.volatile_fid, FSCTL_GET_REPARSE_POINT, NULL, 0,
2895 MAX_SMB2_CREATE_RESPONSE_SIZE -
2896 MAX_SMB2_CLOSE_RESPONSE_SIZE);
2900 smb2_set_next_command(tcon, &rqst[1]);
2901 smb2_set_related(&rqst[1]);
2905 memset(&close_iov, 0, sizeof(close_iov));
2906 rqst[2].rq_iov = close_iov;
2907 rqst[2].rq_nvec = 1;
2909 rc = SMB2_close_init(tcon, server,
2910 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2914 smb2_set_related(&rqst[2]);
2916 rc = compound_send_recv(xid, tcon->ses, server,
2918 resp_buftype, rsp_iov);
2920 create_rsp = rsp_iov[0].iov_base;
2921 if (create_rsp && create_rsp->hdr.Status)
2922 err_iov = rsp_iov[0];
2923 ioctl_rsp = rsp_iov[1].iov_base;
2926 * Open was successful and we got an ioctl response.
2928 if ((rc == 0) && (is_reparse_point)) {
2929 /* See MS-FSCC 2.3.23 */
2931 reparse_buf = (struct reparse_data_buffer *)
2932 ((char *)ioctl_rsp +
2933 le32_to_cpu(ioctl_rsp->OutputOffset));
2934 plen = le32_to_cpu(ioctl_rsp->OutputCount);
2936 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
2937 rsp_iov[1].iov_len) {
2938 cifs_tcon_dbg(VFS, "srv returned invalid ioctl len: %d\n",
2944 rc = parse_reparse_point(reparse_buf, plen, target_path,
2949 if (!rc || !err_iov.iov_base) {
2954 err_buf = err_iov.iov_base;
2955 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
2956 err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) {
2961 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
2962 if (le32_to_cpu(symlink->SymLinkErrorTag) != SYMLINK_ERROR_TAG ||
2963 le32_to_cpu(symlink->ReparseTag) != IO_REPARSE_TAG_SYMLINK) {
2968 /* open must fail on symlink - reset rc */
2970 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
2971 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
2972 print_len = le16_to_cpu(symlink->PrintNameLength);
2973 print_offset = le16_to_cpu(symlink->PrintNameOffset);
2975 if (err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
2980 if (err_iov.iov_len <
2981 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
2986 *target_path = cifs_strndup_from_utf16(
2987 (char *)symlink->PathBuffer + sub_offset,
2988 sub_len, true, cifs_sb->local_nls);
2989 if (!(*target_path)) {
2993 convert_delimiter(*target_path, '/');
2994 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2997 cifs_dbg(FYI, "query symlink rc %d\n", rc);
2999 SMB2_open_free(&rqst[0]);
3000 SMB2_ioctl_free(&rqst[1]);
3001 SMB2_close_free(&rqst[2]);
3002 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3003 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3004 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3009 smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
3010 struct cifs_sb_info *cifs_sb, const char *full_path,
3014 __le16 *utf16_path = NULL;
3015 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3016 struct cifs_open_parms oparms;
3017 struct cifs_fid fid;
3018 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
3019 int flags = CIFS_CP_CREATE_CLOSE_OP;
3020 struct smb_rqst rqst[3];
3021 int resp_buftype[3];
3022 struct kvec rsp_iov[3];
3023 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
3024 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
3025 struct kvec close_iov[1];
3026 struct smb2_ioctl_rsp *ioctl_rsp;
3027 struct reparse_data_buffer *reparse_buf;
3030 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
3032 if (smb3_encryption_required(tcon))
3033 flags |= CIFS_TRANSFORM_REQ;
3035 memset(rqst, 0, sizeof(rqst));
3036 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
3037 memset(rsp_iov, 0, sizeof(rsp_iov));
3039 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
3044 * setup smb2open - TODO add optimization to call cifs_get_readable_path
3045 * to see if there is a handle already open that we can use
3047 memset(&open_iov, 0, sizeof(open_iov));
3048 rqst[0].rq_iov = open_iov;
3049 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
3051 memset(&oparms, 0, sizeof(oparms));
3053 oparms.desired_access = FILE_READ_ATTRIBUTES;
3054 oparms.disposition = FILE_OPEN;
3055 oparms.create_options = cifs_create_options(cifs_sb, OPEN_REPARSE_POINT);
3057 oparms.reconnect = false;
3059 rc = SMB2_open_init(tcon, server,
3060 &rqst[0], &oplock, &oparms, utf16_path);
3063 smb2_set_next_command(tcon, &rqst[0]);
3067 memset(&io_iov, 0, sizeof(io_iov));
3068 rqst[1].rq_iov = io_iov;
3069 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3071 rc = SMB2_ioctl_init(tcon, server,
3072 &rqst[1], COMPOUND_FID,
3073 COMPOUND_FID, FSCTL_GET_REPARSE_POINT, NULL, 0,
3075 MAX_SMB2_CREATE_RESPONSE_SIZE -
3076 MAX_SMB2_CLOSE_RESPONSE_SIZE);
3080 smb2_set_next_command(tcon, &rqst[1]);
3081 smb2_set_related(&rqst[1]);
3085 memset(&close_iov, 0, sizeof(close_iov));
3086 rqst[2].rq_iov = close_iov;
3087 rqst[2].rq_nvec = 1;
3089 rc = SMB2_close_init(tcon, server,
3090 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3094 smb2_set_related(&rqst[2]);
3096 rc = compound_send_recv(xid, tcon->ses, server,
3098 resp_buftype, rsp_iov);
3100 ioctl_rsp = rsp_iov[1].iov_base;
3103 * Open was successful and we got an ioctl response.
3106 /* See MS-FSCC 2.3.23 */
3108 reparse_buf = (struct reparse_data_buffer *)
3109 ((char *)ioctl_rsp +
3110 le32_to_cpu(ioctl_rsp->OutputOffset));
3111 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3113 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3114 rsp_iov[1].iov_len) {
3115 cifs_tcon_dbg(FYI, "srv returned invalid ioctl len: %d\n",
3120 *tag = le32_to_cpu(reparse_buf->ReparseTag);
3125 SMB2_open_free(&rqst[0]);
3126 SMB2_ioctl_free(&rqst[1]);
3127 SMB2_close_free(&rqst[2]);
3128 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3129 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3130 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3134 static struct cifs_ntsd *
3135 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
3136 const struct cifs_fid *cifsfid, u32 *pacllen, u32 info)
3138 struct cifs_ntsd *pntsd = NULL;
3140 int rc = -EOPNOTSUPP;
3141 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3144 return ERR_CAST(tlink);
3147 cifs_dbg(FYI, "trying to get acl\n");
3149 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
3150 cifsfid->volatile_fid, (void **)&pntsd, pacllen,
3154 cifs_put_tlink(tlink);
3156 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3163 static struct cifs_ntsd *
3164 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
3165 const char *path, u32 *pacllen, u32 info)
3167 struct cifs_ntsd *pntsd = NULL;
3168 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3171 struct cifs_tcon *tcon;
3172 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3173 struct cifs_fid fid;
3174 struct cifs_open_parms oparms;
3177 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
3179 return ERR_CAST(tlink);
3181 tcon = tlink_tcon(tlink);
3184 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3192 oparms.desired_access = READ_CONTROL;
3193 oparms.disposition = FILE_OPEN;
3195 * When querying an ACL, even if the file is a symlink we want to open
3196 * the source not the target, and so the protocol requires that the
3197 * client specify this flag when opening a reparse point
3199 oparms.create_options = cifs_create_options(cifs_sb, 0) | OPEN_REPARSE_POINT;
3201 oparms.reconnect = false;
3203 if (info & SACL_SECINFO)
3204 oparms.desired_access |= SYSTEM_SECURITY;
3206 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
3210 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3211 fid.volatile_fid, (void **)&pntsd, pacllen,
3213 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3216 cifs_put_tlink(tlink);
3219 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3226 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
3227 struct inode *inode, const char *path, int aclflag)
3229 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3231 int rc, access_flags = 0;
3232 struct cifs_tcon *tcon;
3233 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
3234 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3235 struct cifs_fid fid;
3236 struct cifs_open_parms oparms;
3239 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
3241 return PTR_ERR(tlink);
3243 tcon = tlink_tcon(tlink);
3246 if (aclflag & CIFS_ACL_OWNER || aclflag & CIFS_ACL_GROUP)
3247 access_flags |= WRITE_OWNER;
3248 if (aclflag & CIFS_ACL_SACL)
3249 access_flags |= SYSTEM_SECURITY;
3250 if (aclflag & CIFS_ACL_DACL)
3251 access_flags |= WRITE_DAC;
3253 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3261 oparms.desired_access = access_flags;
3262 oparms.create_options = cifs_create_options(cifs_sb, 0);
3263 oparms.disposition = FILE_OPEN;
3266 oparms.reconnect = false;
3268 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
3272 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3273 fid.volatile_fid, pnntsd, acllen, aclflag);
3274 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3277 cifs_put_tlink(tlink);
3282 /* Retrieve an ACL from the server */
3283 static struct cifs_ntsd *
3284 get_smb2_acl(struct cifs_sb_info *cifs_sb,
3285 struct inode *inode, const char *path,
3286 u32 *pacllen, u32 info)
3288 struct cifs_ntsd *pntsd = NULL;
3289 struct cifsFileInfo *open_file = NULL;
3291 if (inode && !(info & SACL_SECINFO))
3292 open_file = find_readable_file(CIFS_I(inode), true);
3293 if (!open_file || (info & SACL_SECINFO))
3294 return get_smb2_acl_by_path(cifs_sb, path, pacllen, info);
3296 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen, info);
3297 cifsFileInfo_put(open_file);
3301 static long smb3_zero_data(struct file *file, struct cifs_tcon *tcon,
3302 loff_t offset, loff_t len, unsigned int xid)
3304 struct cifsFileInfo *cfile = file->private_data;
3305 struct file_zero_data_information fsctl_buf;
3307 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3309 fsctl_buf.FileOffset = cpu_to_le64(offset);
3310 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3312 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3313 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3315 sizeof(struct file_zero_data_information),
3319 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3320 loff_t offset, loff_t len, bool keep_size)
3322 struct cifs_ses *ses = tcon->ses;
3323 struct inode *inode = file_inode(file);
3324 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3325 struct cifsFileInfo *cfile = file->private_data;
3332 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3333 ses->Suid, offset, len);
3336 filemap_invalidate_lock(inode->i_mapping);
3339 * We zero the range through ioctl, so we need remove the page caches
3340 * first, otherwise the data may be inconsistent with the server.
3342 truncate_pagecache_range(inode, offset, offset + len - 1);
3344 /* if file not oplocked can't be sure whether asking to extend size */
3346 if (keep_size == false && !CIFS_CACHE_READ(cifsi))
3347 goto zero_range_exit;
3349 rc = smb3_zero_data(file, tcon, offset, len, xid);
3351 goto zero_range_exit;
3354 * do we also need to change the size of the file?
3356 if (keep_size == false && i_size_read(inode) < offset + len) {
3357 eof = cpu_to_le64(offset + len);
3358 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3359 cfile->fid.volatile_fid, cfile->pid, &eof);
3363 filemap_invalidate_unlock(inode->i_mapping);
3364 inode_unlock(inode);
3367 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
3368 ses->Suid, offset, len, rc);
3370 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
3371 ses->Suid, offset, len);
3375 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
3376 loff_t offset, loff_t len)
3378 struct inode *inode = file_inode(file);
3379 struct cifsFileInfo *cfile = file->private_data;
3380 struct file_zero_data_information fsctl_buf;
3383 __u8 set_sparse = 1;
3388 /* Need to make file sparse, if not already, before freeing range. */
3389 /* Consider adding equivalent for compressed since it could also work */
3390 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
3395 filemap_invalidate_lock(inode->i_mapping);
3397 * We implement the punch hole through ioctl, so we need remove the page
3398 * caches first, otherwise the data may be inconsistent with the server.
3400 truncate_pagecache_range(inode, offset, offset + len - 1);
3402 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3404 fsctl_buf.FileOffset = cpu_to_le64(offset);
3405 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3407 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3408 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3410 sizeof(struct file_zero_data_information),
3411 CIFSMaxBufSize, NULL, NULL);
3412 filemap_invalidate_unlock(inode->i_mapping);
3414 inode_unlock(inode);
3419 static int smb3_simple_fallocate_write_range(unsigned int xid,
3420 struct cifs_tcon *tcon,
3421 struct cifsFileInfo *cfile,
3422 loff_t off, loff_t len,
3425 struct cifs_io_parms io_parms = {0};
3430 io_parms.netfid = cfile->fid.netfid;
3431 io_parms.pid = current->tgid;
3432 io_parms.tcon = tcon;
3433 io_parms.persistent_fid = cfile->fid.persistent_fid;
3434 io_parms.volatile_fid = cfile->fid.volatile_fid;
3437 io_parms.offset = off;
3438 io_parms.length = len;
3439 if (io_parms.length > SMB2_MAX_BUFFER_SIZE)
3440 io_parms.length = SMB2_MAX_BUFFER_SIZE;
3441 /* iov[0] is reserved for smb header */
3442 iov[1].iov_base = buf;
3443 iov[1].iov_len = io_parms.length;
3444 rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
3456 static int smb3_simple_fallocate_range(unsigned int xid,
3457 struct cifs_tcon *tcon,
3458 struct cifsFileInfo *cfile,
3459 loff_t off, loff_t len)
3461 struct file_allocated_range_buffer in_data, *out_data = NULL, *tmp_data;
3467 in_data.file_offset = cpu_to_le64(off);
3468 in_data.length = cpu_to_le64(len);
3469 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3470 cfile->fid.volatile_fid,
3471 FSCTL_QUERY_ALLOCATED_RANGES,
3472 (char *)&in_data, sizeof(in_data),
3473 1024 * sizeof(struct file_allocated_range_buffer),
3474 (char **)&out_data, &out_data_len);
3478 buf = kzalloc(1024 * 1024, GFP_KERNEL);
3484 tmp_data = out_data;
3487 * The rest of the region is unmapped so write it all.
3489 if (out_data_len == 0) {
3490 rc = smb3_simple_fallocate_write_range(xid, tcon,
3491 cfile, off, len, buf);
3495 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3500 if (off < le64_to_cpu(tmp_data->file_offset)) {
3502 * We are at a hole. Write until the end of the region
3503 * or until the next allocated data,
3504 * whichever comes next.
3506 l = le64_to_cpu(tmp_data->file_offset) - off;
3509 rc = smb3_simple_fallocate_write_range(xid, tcon,
3510 cfile, off, l, buf);
3519 * We are at a section of allocated data, just skip forward
3520 * until the end of the data or the end of the region
3521 * we are supposed to fallocate, whichever comes first.
3523 l = le64_to_cpu(tmp_data->length);
3529 tmp_data = &tmp_data[1];
3530 out_data_len -= sizeof(struct file_allocated_range_buffer);
3540 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3541 loff_t off, loff_t len, bool keep_size)
3543 struct inode *inode;
3544 struct cifsInodeInfo *cifsi;
3545 struct cifsFileInfo *cfile = file->private_data;
3546 long rc = -EOPNOTSUPP;
3552 inode = d_inode(cfile->dentry);
3553 cifsi = CIFS_I(inode);
3555 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3556 tcon->ses->Suid, off, len);
3557 /* if file not oplocked can't be sure whether asking to extend size */
3558 if (!CIFS_CACHE_READ(cifsi))
3559 if (keep_size == false) {
3560 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3561 tcon->tid, tcon->ses->Suid, off, len, rc);
3567 * Extending the file
3569 if ((keep_size == false) && i_size_read(inode) < off + len) {
3570 rc = inode_newsize_ok(inode, off + len);
3574 if (cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)
3575 smb2_set_sparse(xid, tcon, cfile, inode, false);
3577 eof = cpu_to_le64(off + len);
3578 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3579 cfile->fid.volatile_fid, cfile->pid, &eof);
3581 cifsi->server_eof = off + len;
3582 cifs_setsize(inode, off + len);
3583 cifs_truncate_page(inode->i_mapping, inode->i_size);
3584 truncate_setsize(inode, off + len);
3590 * Files are non-sparse by default so falloc may be a no-op
3591 * Must check if file sparse. If not sparse, and since we are not
3592 * extending then no need to do anything since file already allocated
3594 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
3599 if (keep_size == true) {
3601 * We can not preallocate pages beyond the end of the file
3604 if (off >= i_size_read(inode)) {
3609 * For fallocates that are partially beyond the end of file,
3610 * clamp len so we only fallocate up to the end of file.
3612 if (off + len > i_size_read(inode)) {
3613 len = i_size_read(inode) - off;
3617 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3619 * At this point, we are trying to fallocate an internal
3620 * regions of a sparse file. Since smb2 does not have a
3621 * fallocate command we have two otions on how to emulate this.
3622 * We can either turn the entire file to become non-sparse
3623 * which we only do if the fallocate is for virtually
3624 * the whole file, or we can overwrite the region with zeroes
3625 * using SMB2_write, which could be prohibitevly expensive
3629 * We are only trying to fallocate a small region so
3630 * just write it with zero.
3632 if (len <= 1024 * 1024) {
3633 rc = smb3_simple_fallocate_range(xid, tcon, cfile,
3639 * Check if falloc starts within first few pages of file
3640 * and ends within a few pages of the end of file to
3641 * ensure that most of file is being forced to be
3642 * fallocated now. If so then setting whole file sparse
3643 * ie potentially making a few extra pages at the beginning
3644 * or end of the file non-sparse via set_sparse is harmless.
3646 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
3652 smb2_set_sparse(xid, tcon, cfile, inode, false);
3657 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3658 tcon->ses->Suid, off, len, rc);
3660 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3661 tcon->ses->Suid, off, len);
3667 static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
3668 loff_t off, loff_t len)
3672 struct inode *inode = file_inode(file);
3673 struct cifsFileInfo *cfile = file->private_data;
3674 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3682 old_eof = i_size_read(inode);
3683 if ((off >= old_eof) ||
3684 off + len >= old_eof) {
3689 filemap_invalidate_lock(inode->i_mapping);
3690 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof - 1);
3694 truncate_pagecache_range(inode, off, old_eof);
3696 rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
3697 old_eof - off - len, off);
3701 eof = cpu_to_le64(old_eof - len);
3702 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3703 cfile->fid.volatile_fid, cfile->pid, &eof);
3709 cifsi->server_eof = i_size_read(inode) - len;
3710 truncate_setsize(inode, cifsi->server_eof);
3711 fscache_resize_cookie(cifs_inode_cookie(inode), cifsi->server_eof);
3713 filemap_invalidate_unlock(inode->i_mapping);
3715 inode_unlock(inode);
3720 static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
3721 loff_t off, loff_t len)
3725 struct cifsFileInfo *cfile = file->private_data;
3726 struct inode *inode = file_inode(file);
3728 __u64 count, old_eof;
3734 old_eof = i_size_read(inode);
3735 if (off >= old_eof) {
3740 count = old_eof - off;
3741 eof = cpu_to_le64(old_eof + len);
3743 filemap_invalidate_lock(inode->i_mapping);
3744 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof + len - 1);
3747 truncate_pagecache_range(inode, off, old_eof);
3749 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3750 cfile->fid.volatile_fid, cfile->pid, &eof);
3754 rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len);
3758 rc = smb3_zero_data(file, tcon, off, len, xid);
3764 filemap_invalidate_unlock(inode->i_mapping);
3766 inode_unlock(inode);
3771 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3773 struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3774 struct cifsInodeInfo *cifsi;
3775 struct inode *inode;
3777 struct file_allocated_range_buffer in_data, *out_data = NULL;
3781 if (whence != SEEK_HOLE && whence != SEEK_DATA)
3782 return generic_file_llseek(file, offset, whence);
3784 inode = d_inode(cfile->dentry);
3785 cifsi = CIFS_I(inode);
3787 if (offset < 0 || offset >= i_size_read(inode))
3792 * We need to be sure that all dirty pages are written as they
3793 * might fill holes on the server.
3794 * Note that we also MUST flush any written pages since at least
3795 * some servers (Windows2016) will not reflect recent writes in
3796 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3798 wrcfile = find_writable_file(cifsi, FIND_WR_ANY);
3800 filemap_write_and_wait(inode->i_mapping);
3801 smb2_flush_file(xid, tcon, &wrcfile->fid);
3802 cifsFileInfo_put(wrcfile);
3805 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3806 if (whence == SEEK_HOLE)
3807 offset = i_size_read(inode);
3811 in_data.file_offset = cpu_to_le64(offset);
3812 in_data.length = cpu_to_le64(i_size_read(inode));
3814 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3815 cfile->fid.volatile_fid,
3816 FSCTL_QUERY_ALLOCATED_RANGES,
3817 (char *)&in_data, sizeof(in_data),
3818 sizeof(struct file_allocated_range_buffer),
3819 (char **)&out_data, &out_data_len);
3825 if (whence == SEEK_HOLE && out_data_len == 0)
3828 if (whence == SEEK_DATA && out_data_len == 0) {
3833 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3837 if (whence == SEEK_DATA) {
3838 offset = le64_to_cpu(out_data->file_offset);
3841 if (offset < le64_to_cpu(out_data->file_offset))
3844 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3850 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3855 static int smb3_fiemap(struct cifs_tcon *tcon,
3856 struct cifsFileInfo *cfile,
3857 struct fiemap_extent_info *fei, u64 start, u64 len)
3860 struct file_allocated_range_buffer in_data, *out_data;
3862 int i, num, rc, flags, last_blob;
3865 rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0);
3871 in_data.file_offset = cpu_to_le64(start);
3872 in_data.length = cpu_to_le64(len);
3874 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3875 cfile->fid.volatile_fid,
3876 FSCTL_QUERY_ALLOCATED_RANGES,
3877 (char *)&in_data, sizeof(in_data),
3878 1024 * sizeof(struct file_allocated_range_buffer),
3879 (char **)&out_data, &out_data_len);
3888 if (out_data_len && out_data_len < sizeof(struct file_allocated_range_buffer)) {
3892 if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3897 num = out_data_len / sizeof(struct file_allocated_range_buffer);
3898 for (i = 0; i < num; i++) {
3900 if (i == num - 1 && last_blob)
3901 flags |= FIEMAP_EXTENT_LAST;
3903 rc = fiemap_fill_next_extent(fei,
3904 le64_to_cpu(out_data[i].file_offset),
3905 le64_to_cpu(out_data[i].file_offset),
3906 le64_to_cpu(out_data[i].length),
3917 next = le64_to_cpu(out_data[num - 1].file_offset) +
3918 le64_to_cpu(out_data[num - 1].length);
3919 len = len - (next - start);
3930 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
3931 loff_t off, loff_t len)
3933 /* KEEP_SIZE already checked for by do_fallocate */
3934 if (mode & FALLOC_FL_PUNCH_HOLE)
3935 return smb3_punch_hole(file, tcon, off, len);
3936 else if (mode & FALLOC_FL_ZERO_RANGE) {
3937 if (mode & FALLOC_FL_KEEP_SIZE)
3938 return smb3_zero_range(file, tcon, off, len, true);
3939 return smb3_zero_range(file, tcon, off, len, false);
3940 } else if (mode == FALLOC_FL_KEEP_SIZE)
3941 return smb3_simple_falloc(file, tcon, off, len, true);
3942 else if (mode == FALLOC_FL_COLLAPSE_RANGE)
3943 return smb3_collapse_range(file, tcon, off, len);
3944 else if (mode == FALLOC_FL_INSERT_RANGE)
3945 return smb3_insert_range(file, tcon, off, len);
3947 return smb3_simple_falloc(file, tcon, off, len, false);
3953 smb2_downgrade_oplock(struct TCP_Server_Info *server,
3954 struct cifsInodeInfo *cinode, __u32 oplock,
3955 unsigned int epoch, bool *purge_cache)
3957 server->ops->set_oplock_level(cinode, oplock, 0, NULL);
3961 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3962 unsigned int epoch, bool *purge_cache);
3965 smb3_downgrade_oplock(struct TCP_Server_Info *server,
3966 struct cifsInodeInfo *cinode, __u32 oplock,
3967 unsigned int epoch, bool *purge_cache)
3969 unsigned int old_state = cinode->oplock;
3970 unsigned int old_epoch = cinode->epoch;
3971 unsigned int new_state;
3973 if (epoch > old_epoch) {
3974 smb21_set_oplock_level(cinode, oplock, 0, NULL);
3975 cinode->epoch = epoch;
3978 new_state = cinode->oplock;
3979 *purge_cache = false;
3981 if ((old_state & CIFS_CACHE_READ_FLG) != 0 &&
3982 (new_state & CIFS_CACHE_READ_FLG) == 0)
3983 *purge_cache = true;
3984 else if (old_state == new_state && (epoch - old_epoch > 1))
3985 *purge_cache = true;
3989 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3990 unsigned int epoch, bool *purge_cache)
3993 cinode->lease_granted = false;
3994 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3996 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
3997 cinode->oplock = CIFS_CACHE_RHW_FLG;
3998 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
3999 &cinode->netfs.inode);
4000 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
4001 cinode->oplock = CIFS_CACHE_RW_FLG;
4002 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
4003 &cinode->netfs.inode);
4004 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
4005 cinode->oplock = CIFS_CACHE_READ_FLG;
4006 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
4007 &cinode->netfs.inode);
4013 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4014 unsigned int epoch, bool *purge_cache)
4016 char message[5] = {0};
4017 unsigned int new_oplock = 0;
4020 cinode->lease_granted = true;
4021 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
4024 /* Check if the server granted an oplock rather than a lease */
4025 if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4026 return smb2_set_oplock_level(cinode, oplock, epoch,
4029 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
4030 new_oplock |= CIFS_CACHE_READ_FLG;
4031 strcat(message, "R");
4033 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
4034 new_oplock |= CIFS_CACHE_HANDLE_FLG;
4035 strcat(message, "H");
4037 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
4038 new_oplock |= CIFS_CACHE_WRITE_FLG;
4039 strcat(message, "W");
4042 strncpy(message, "None", sizeof(message));
4044 cinode->oplock = new_oplock;
4045 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
4046 &cinode->netfs.inode);
4050 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4051 unsigned int epoch, bool *purge_cache)
4053 unsigned int old_oplock = cinode->oplock;
4055 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
4058 *purge_cache = false;
4059 if (old_oplock == CIFS_CACHE_READ_FLG) {
4060 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
4061 (epoch - cinode->epoch > 0))
4062 *purge_cache = true;
4063 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4064 (epoch - cinode->epoch > 1))
4065 *purge_cache = true;
4066 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4067 (epoch - cinode->epoch > 1))
4068 *purge_cache = true;
4069 else if (cinode->oplock == 0 &&
4070 (epoch - cinode->epoch > 0))
4071 *purge_cache = true;
4072 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
4073 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4074 (epoch - cinode->epoch > 0))
4075 *purge_cache = true;
4076 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4077 (epoch - cinode->epoch > 1))
4078 *purge_cache = true;
4080 cinode->epoch = epoch;
4084 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
4086 smb2_is_read_op(__u32 oplock)
4088 return oplock == SMB2_OPLOCK_LEVEL_II;
4090 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
4093 smb21_is_read_op(__u32 oplock)
4095 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
4096 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
4100 map_oplock_to_lease(u8 oplock)
4102 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4103 return SMB2_LEASE_WRITE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE;
4104 else if (oplock == SMB2_OPLOCK_LEVEL_II)
4105 return SMB2_LEASE_READ_CACHING_LE;
4106 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
4107 return SMB2_LEASE_HANDLE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE |
4108 SMB2_LEASE_WRITE_CACHING_LE;
4113 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
4115 struct create_lease *buf;
4117 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
4121 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4122 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4124 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4125 (struct create_lease, lcontext));
4126 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
4127 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4128 (struct create_lease, Name));
4129 buf->ccontext.NameLength = cpu_to_le16(4);
4130 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4139 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
4141 struct create_lease_v2 *buf;
4143 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
4147 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4148 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4150 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4151 (struct create_lease_v2, lcontext));
4152 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
4153 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4154 (struct create_lease_v2, Name));
4155 buf->ccontext.NameLength = cpu_to_le16(4);
4156 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4165 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4167 struct create_lease *lc = (struct create_lease *)buf;
4169 *epoch = 0; /* not used */
4170 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4171 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4172 return le32_to_cpu(lc->lcontext.LeaseState);
4176 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4178 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
4180 *epoch = le16_to_cpu(lc->lcontext.Epoch);
4181 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4182 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4184 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
4185 return le32_to_cpu(lc->lcontext.LeaseState);
4189 smb2_wp_retry_size(struct inode *inode)
4191 return min_t(unsigned int, CIFS_SB(inode->i_sb)->ctx->wsize,
4192 SMB2_MAX_BUFFER_SIZE);
4196 smb2_dir_needs_close(struct cifsFileInfo *cfile)
4198 return !cfile->invalidHandle;
4202 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
4203 struct smb_rqst *old_rq, __le16 cipher_type)
4205 struct smb2_hdr *shdr =
4206 (struct smb2_hdr *)old_rq->rq_iov[0].iov_base;
4208 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
4209 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
4210 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
4211 tr_hdr->Flags = cpu_to_le16(0x01);
4212 if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4213 (cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4214 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4216 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4217 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
4220 /* We can not use the normal sg_set_buf() as we will sometimes pass a
4221 * stack object as buf.
4223 static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
4224 unsigned int buflen)
4228 * VMAP_STACK (at least) puts stack into the vmalloc address space
4230 if (is_vmalloc_addr(buf))
4231 addr = vmalloc_to_page(buf);
4233 addr = virt_to_page(buf);
4234 sg_set_page(sg, addr, buflen, offset_in_page(buf));
4237 /* Assumes the first rqst has a transform header as the first iov.
4239 * rqst[0].rq_iov[0] is transform header
4240 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
4241 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
4243 static struct scatterlist *
4244 init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign)
4246 unsigned int sg_len;
4247 struct scatterlist *sg;
4250 unsigned int idx = 0;
4254 for (i = 0; i < num_rqst; i++)
4255 sg_len += rqst[i].rq_nvec + rqst[i].rq_npages;
4257 sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
4261 sg_init_table(sg, sg_len);
4262 for (i = 0; i < num_rqst; i++) {
4263 for (j = 0; j < rqst[i].rq_nvec; j++) {
4265 * The first rqst has a transform header where the
4266 * first 20 bytes are not part of the encrypted blob
4268 skip = (i == 0) && (j == 0) ? 20 : 0;
4269 smb2_sg_set_buf(&sg[idx++],
4270 rqst[i].rq_iov[j].iov_base + skip,
4271 rqst[i].rq_iov[j].iov_len - skip);
4274 for (j = 0; j < rqst[i].rq_npages; j++) {
4275 unsigned int len, offset;
4277 rqst_page_get_length(&rqst[i], j, &len, &offset);
4278 sg_set_page(&sg[idx++], rqst[i].rq_pages[j], len, offset);
4281 smb2_sg_set_buf(&sg[idx], sign, SMB2_SIGNATURE_SIZE);
4286 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
4288 struct cifs_ses *ses;
4291 spin_lock(&cifs_tcp_ses_lock);
4292 list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
4293 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
4294 if (ses->Suid == ses_id) {
4295 spin_lock(&ses->ses_lock);
4296 ses_enc_key = enc ? ses->smb3encryptionkey :
4297 ses->smb3decryptionkey;
4298 memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE);
4299 spin_unlock(&ses->ses_lock);
4300 spin_unlock(&cifs_tcp_ses_lock);
4305 spin_unlock(&cifs_tcp_ses_lock);
4310 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
4311 * iov[0] - transform header (associate data),
4312 * iov[1-N] - SMB2 header and pages - data to encrypt.
4313 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4317 crypt_message(struct TCP_Server_Info *server, int num_rqst,
4318 struct smb_rqst *rqst, int enc)
4320 struct smb2_transform_hdr *tr_hdr =
4321 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
4322 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
4324 struct scatterlist *sg;
4325 u8 sign[SMB2_SIGNATURE_SIZE] = {};
4326 u8 key[SMB3_ENC_DEC_KEY_SIZE];
4327 struct aead_request *req;
4329 unsigned int iv_len;
4330 DECLARE_CRYPTO_WAIT(wait);
4331 struct crypto_aead *tfm;
4332 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4334 rc = smb2_get_enc_key(server, le64_to_cpu(tr_hdr->SessionId), enc, key);
4336 cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
4341 rc = smb3_crypto_aead_allocate(server);
4343 cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
4347 tfm = enc ? server->secmech.ccmaesencrypt :
4348 server->secmech.ccmaesdecrypt;
4350 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
4351 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4352 rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
4354 rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE);
4357 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
4361 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
4363 cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
4367 req = aead_request_alloc(tfm, GFP_KERNEL);
4369 cifs_server_dbg(VFS, "%s: Failed to alloc aead request\n", __func__);
4374 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
4375 crypt_len += SMB2_SIGNATURE_SIZE;
4378 sg = init_sg(num_rqst, rqst, sign);
4380 cifs_server_dbg(VFS, "%s: Failed to init sg\n", __func__);
4385 iv_len = crypto_aead_ivsize(tfm);
4386 iv = kzalloc(iv_len, GFP_KERNEL);
4388 cifs_server_dbg(VFS, "%s: Failed to alloc iv\n", __func__);
4393 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4394 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4395 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4398 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4401 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
4402 aead_request_set_ad(req, assoc_data_len);
4404 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
4405 crypto_req_done, &wait);
4407 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
4408 : crypto_aead_decrypt(req), &wait);
4411 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
4422 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
4426 for (i = 0; i < num_rqst; i++) {
4427 if (rqst[i].rq_pages) {
4428 for (j = rqst[i].rq_npages - 1; j >= 0; j--)
4429 put_page(rqst[i].rq_pages[j]);
4430 kfree(rqst[i].rq_pages);
4436 * This function will initialize new_rq and encrypt the content.
4437 * The first entry, new_rq[0], only contains a single iov which contains
4438 * a smb2_transform_hdr and is pre-allocated by the caller.
4439 * This function then populates new_rq[1+] with the content from olq_rq[0+].
4441 * The end result is an array of smb_rqst structures where the first structure
4442 * only contains a single iov for the transform header which we then can pass
4443 * to crypt_message().
4445 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4446 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
4449 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
4450 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
4452 struct page **pages;
4453 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
4454 unsigned int npages;
4455 unsigned int orig_len = 0;
4459 for (i = 1; i < num_rqst; i++) {
4460 npages = old_rq[i - 1].rq_npages;
4461 pages = kmalloc_array(npages, sizeof(struct page *),
4466 new_rq[i].rq_pages = pages;
4467 new_rq[i].rq_npages = npages;
4468 new_rq[i].rq_offset = old_rq[i - 1].rq_offset;
4469 new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz;
4470 new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz;
4471 new_rq[i].rq_iov = old_rq[i - 1].rq_iov;
4472 new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec;
4474 orig_len += smb_rqst_len(server, &old_rq[i - 1]);
4476 for (j = 0; j < npages; j++) {
4477 pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4482 /* copy pages form the old */
4483 for (j = 0; j < npages; j++) {
4485 unsigned int offset, len;
4487 rqst_page_get_length(&new_rq[i], j, &len, &offset);
4489 dst = (char *) kmap(new_rq[i].rq_pages[j]) + offset;
4490 src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset;
4492 memcpy(dst, src, len);
4493 kunmap(new_rq[i].rq_pages[j]);
4494 kunmap(old_rq[i - 1].rq_pages[j]);
4498 /* fill the 1st iov with a transform header */
4499 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
4501 rc = crypt_message(server, num_rqst, new_rq, 1);
4502 cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
4509 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
4514 smb3_is_transform_hdr(void *buf)
4516 struct smb2_transform_hdr *trhdr = buf;
4518 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
4522 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
4523 unsigned int buf_data_size, struct page **pages,
4524 unsigned int npages, unsigned int page_data_size,
4528 struct smb_rqst rqst = {NULL};
4531 iov[0].iov_base = buf;
4532 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
4533 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
4534 iov[1].iov_len = buf_data_size;
4538 rqst.rq_pages = pages;
4539 rqst.rq_npages = npages;
4540 rqst.rq_pagesz = PAGE_SIZE;
4541 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
4543 rc = crypt_message(server, 1, &rqst, 0);
4544 cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
4549 memmove(buf, iov[1].iov_base, buf_data_size);
4552 server->total_read = buf_data_size + page_data_size;
4558 read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
4559 unsigned int npages, unsigned int len)
4564 for (i = 0; i < npages; i++) {
4565 struct page *page = pages[i];
4569 if (len >= PAGE_SIZE) {
4570 /* enough data to fill the page */
4574 zero_user(page, len, PAGE_SIZE - len);
4577 length = cifs_read_page_from_socket(server, page, 0, n);
4580 server->total_read += length;
4587 init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
4588 unsigned int cur_off, struct bio_vec **page_vec)
4590 struct bio_vec *bvec;
4593 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
4597 for (i = 0; i < npages; i++) {
4598 bvec[i].bv_page = pages[i];
4599 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
4600 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
4601 data_size -= bvec[i].bv_len;
4604 if (data_size != 0) {
4605 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
4615 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
4616 char *buf, unsigned int buf_len, struct page **pages,
4617 unsigned int npages, unsigned int page_data_size,
4620 unsigned int data_offset;
4621 unsigned int data_len;
4622 unsigned int cur_off;
4623 unsigned int cur_page_idx;
4624 unsigned int pad_len;
4625 struct cifs_readdata *rdata = mid->callback_data;
4626 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
4627 struct bio_vec *bvec = NULL;
4628 struct iov_iter iter;
4631 bool use_rdma_mr = false;
4633 if (shdr->Command != SMB2_READ) {
4634 cifs_server_dbg(VFS, "only big read responses are supported\n");
4638 if (server->ops->is_session_expired &&
4639 server->ops->is_session_expired(buf)) {
4641 cifs_reconnect(server, true);
4645 if (server->ops->is_status_pending &&
4646 server->ops->is_status_pending(buf, server))
4649 /* set up first two iov to get credits */
4650 rdata->iov[0].iov_base = buf;
4651 rdata->iov[0].iov_len = 0;
4652 rdata->iov[1].iov_base = buf;
4653 rdata->iov[1].iov_len =
4654 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
4655 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
4656 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
4657 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
4658 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
4660 rdata->result = server->ops->map_error(buf, true);
4661 if (rdata->result != 0) {
4662 cifs_dbg(FYI, "%s: server returned error %d\n",
4663 __func__, rdata->result);
4664 /* normal error on read response */
4666 mid->mid_state = MID_RESPONSE_RECEIVED;
4668 dequeue_mid(mid, false);
4672 data_offset = server->ops->read_data_offset(buf);
4673 #ifdef CONFIG_CIFS_SMB_DIRECT
4674 use_rdma_mr = rdata->mr;
4676 data_len = server->ops->read_data_length(buf, use_rdma_mr);
4678 if (data_offset < server->vals->read_rsp_size) {
4680 * win2k8 sometimes sends an offset of 0 when the read
4681 * is beyond the EOF. Treat it as if the data starts just after
4684 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
4685 __func__, data_offset);
4686 data_offset = server->vals->read_rsp_size;
4687 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
4688 /* data_offset is beyond the end of smallbuf */
4689 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
4690 __func__, data_offset);
4691 rdata->result = -EIO;
4693 mid->mid_state = MID_RESPONSE_MALFORMED;
4695 dequeue_mid(mid, rdata->result);
4699 pad_len = data_offset - server->vals->read_rsp_size;
4701 if (buf_len <= data_offset) {
4702 /* read response payload is in pages */
4703 cur_page_idx = pad_len / PAGE_SIZE;
4704 cur_off = pad_len % PAGE_SIZE;
4706 if (cur_page_idx != 0) {
4707 /* data offset is beyond the 1st page of response */
4708 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
4709 __func__, data_offset);
4710 rdata->result = -EIO;
4712 mid->mid_state = MID_RESPONSE_MALFORMED;
4714 dequeue_mid(mid, rdata->result);
4718 if (data_len > page_data_size - pad_len) {
4719 /* data_len is corrupt -- discard frame */
4720 rdata->result = -EIO;
4722 mid->mid_state = MID_RESPONSE_MALFORMED;
4724 dequeue_mid(mid, rdata->result);
4728 rdata->result = init_read_bvec(pages, npages, page_data_size,
4730 if (rdata->result != 0) {
4732 mid->mid_state = MID_RESPONSE_MALFORMED;
4734 dequeue_mid(mid, rdata->result);
4738 iov_iter_bvec(&iter, WRITE, bvec, npages, data_len);
4739 } else if (buf_len >= data_offset + data_len) {
4740 /* read response payload is in buf */
4741 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
4742 iov.iov_base = buf + data_offset;
4743 iov.iov_len = data_len;
4744 iov_iter_kvec(&iter, WRITE, &iov, 1, data_len);
4746 /* read response payload cannot be in both buf and pages */
4747 WARN_ONCE(1, "buf can not contain only a part of read data");
4748 rdata->result = -EIO;
4750 mid->mid_state = MID_RESPONSE_MALFORMED;
4752 dequeue_mid(mid, rdata->result);
4756 length = rdata->copy_into_pages(server, rdata, &iter);
4764 mid->mid_state = MID_RESPONSE_RECEIVED;
4766 dequeue_mid(mid, false);
4770 struct smb2_decrypt_work {
4771 struct work_struct decrypt;
4772 struct TCP_Server_Info *server;
4773 struct page **ppages;
4775 unsigned int npages;
4780 static void smb2_decrypt_offload(struct work_struct *work)
4782 struct smb2_decrypt_work *dw = container_of(work,
4783 struct smb2_decrypt_work, decrypt);
4785 struct mid_q_entry *mid;
4787 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
4788 dw->ppages, dw->npages, dw->len, true);
4790 cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
4794 dw->server->lstrp = jiffies;
4795 mid = smb2_find_dequeue_mid(dw->server, dw->buf);
4797 cifs_dbg(FYI, "mid not found\n");
4799 mid->decrypted = true;
4800 rc = handle_read_data(dw->server, mid, dw->buf,
4801 dw->server->vals->read_rsp_size,
4802 dw->ppages, dw->npages, dw->len,
4805 #ifdef CONFIG_CIFS_STATS2
4806 mid->when_received = jiffies;
4808 if (dw->server->ops->is_network_name_deleted)
4809 dw->server->ops->is_network_name_deleted(dw->buf,
4814 spin_lock(&dw->server->srv_lock);
4815 if (dw->server->tcpStatus == CifsNeedReconnect) {
4816 spin_lock(&dw->server->mid_lock);
4817 mid->mid_state = MID_RETRY_NEEDED;
4818 spin_unlock(&dw->server->mid_lock);
4819 spin_unlock(&dw->server->srv_lock);
4822 spin_lock(&dw->server->mid_lock);
4823 mid->mid_state = MID_REQUEST_SUBMITTED;
4824 mid->mid_flags &= ~(MID_DELETED);
4825 list_add_tail(&mid->qhead,
4826 &dw->server->pending_mid_q);
4827 spin_unlock(&dw->server->mid_lock);
4828 spin_unlock(&dw->server->srv_lock);
4835 for (i = dw->npages-1; i >= 0; i--)
4836 put_page(dw->ppages[i]);
4839 cifs_small_buf_release(dw->buf);
4845 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
4848 char *buf = server->smallbuf;
4849 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4850 unsigned int npages;
4851 struct page **pages;
4853 unsigned int buflen = server->pdu_size;
4856 struct smb2_decrypt_work *dw;
4859 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
4860 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
4862 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
4865 server->total_read += rc;
4867 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
4868 server->vals->read_rsp_size;
4869 npages = DIV_ROUND_UP(len, PAGE_SIZE);
4871 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
4877 for (; i < npages; i++) {
4878 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4885 /* read read data into pages */
4886 rc = read_data_into_pages(server, pages, npages, len);
4890 rc = cifs_discard_remaining_data(server);
4895 * For large reads, offload to different thread for better performance,
4896 * use more cores decrypting which can be expensive
4899 if ((server->min_offload) && (server->in_flight > 1) &&
4900 (server->pdu_size >= server->min_offload)) {
4901 dw = kmalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL);
4903 goto non_offloaded_decrypt;
4905 dw->buf = server->smallbuf;
4906 server->smallbuf = (char *)cifs_small_buf_get();
4908 INIT_WORK(&dw->decrypt, smb2_decrypt_offload);
4910 dw->npages = npages;
4911 dw->server = server;
4914 queue_work(decrypt_wq, &dw->decrypt);
4915 *num_mids = 0; /* worker thread takes care of finding mid */
4919 non_offloaded_decrypt:
4920 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
4921 pages, npages, len, false);
4925 *mid = smb2_find_mid(server, buf);
4927 cifs_dbg(FYI, "mid not found\n");
4929 cifs_dbg(FYI, "mid found\n");
4930 (*mid)->decrypted = true;
4931 rc = handle_read_data(server, *mid, buf,
4932 server->vals->read_rsp_size,
4933 pages, npages, len, false);
4935 if (server->ops->is_network_name_deleted) {
4936 server->ops->is_network_name_deleted(buf,
4943 for (i = i - 1; i >= 0; i--)
4948 cifs_discard_remaining_data(server);
4953 receive_encrypted_standard(struct TCP_Server_Info *server,
4954 struct mid_q_entry **mids, char **bufs,
4958 char *buf = server->smallbuf;
4959 struct smb2_hdr *shdr;
4960 unsigned int pdu_length = server->pdu_size;
4961 unsigned int buf_size;
4962 struct mid_q_entry *mid_entry;
4964 char *next_buffer = NULL;
4968 /* switch to large buffer if too big for a small one */
4969 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
4970 server->large_buf = true;
4971 memcpy(server->bigbuf, buf, server->total_read);
4972 buf = server->bigbuf;
4975 /* now read the rest */
4976 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
4977 pdu_length - HEADER_SIZE(server) + 1);
4980 server->total_read += length;
4982 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
4983 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0, false);
4987 next_is_large = server->large_buf;
4989 shdr = (struct smb2_hdr *)buf;
4990 if (shdr->NextCommand) {
4992 next_buffer = (char *)cifs_buf_get();
4994 next_buffer = (char *)cifs_small_buf_get();
4996 buf + le32_to_cpu(shdr->NextCommand),
4997 pdu_length - le32_to_cpu(shdr->NextCommand));
5000 mid_entry = smb2_find_mid(server, buf);
5001 if (mid_entry == NULL)
5002 cifs_dbg(FYI, "mid not found\n");
5004 cifs_dbg(FYI, "mid found\n");
5005 mid_entry->decrypted = true;
5006 mid_entry->resp_buf_size = server->pdu_size;
5009 if (*num_mids >= MAX_COMPOUND) {
5010 cifs_server_dbg(VFS, "too many PDUs in compound\n");
5013 bufs[*num_mids] = buf;
5014 mids[(*num_mids)++] = mid_entry;
5016 if (mid_entry && mid_entry->handle)
5017 ret = mid_entry->handle(server, mid_entry);
5019 ret = cifs_handle_standard(server, mid_entry);
5021 if (ret == 0 && shdr->NextCommand) {
5022 pdu_length -= le32_to_cpu(shdr->NextCommand);
5023 server->large_buf = next_is_large;
5025 server->bigbuf = buf = next_buffer;
5027 server->smallbuf = buf = next_buffer;
5029 } else if (ret != 0) {
5031 * ret != 0 here means that we didn't get to handle_mid() thus
5032 * server->smallbuf and server->bigbuf are still valid. We need
5033 * to free next_buffer because it is not going to be used
5037 free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer);
5039 free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer);
5046 smb3_receive_transform(struct TCP_Server_Info *server,
5047 struct mid_q_entry **mids, char **bufs, int *num_mids)
5049 char *buf = server->smallbuf;
5050 unsigned int pdu_length = server->pdu_size;
5051 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
5052 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
5054 if (pdu_length < sizeof(struct smb2_transform_hdr) +
5055 sizeof(struct smb2_hdr)) {
5056 cifs_server_dbg(VFS, "Transform message is too small (%u)\n",
5058 cifs_reconnect(server, true);
5059 return -ECONNABORTED;
5062 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
5063 cifs_server_dbg(VFS, "Transform message is broken\n");
5064 cifs_reconnect(server, true);
5065 return -ECONNABORTED;
5068 /* TODO: add support for compounds containing READ. */
5069 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
5070 return receive_encrypted_read(server, &mids[0], num_mids);
5073 return receive_encrypted_standard(server, mids, bufs, num_mids);
5077 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
5079 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
5081 return handle_read_data(server, mid, buf, server->pdu_size,
5086 smb2_next_header(char *buf)
5088 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
5089 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
5091 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
5092 return sizeof(struct smb2_transform_hdr) +
5093 le32_to_cpu(t_hdr->OriginalMessageSize);
5095 return le32_to_cpu(hdr->NextCommand);
5099 smb2_make_node(unsigned int xid, struct inode *inode,
5100 struct dentry *dentry, struct cifs_tcon *tcon,
5101 const char *full_path, umode_t mode, dev_t dev)
5103 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
5105 FILE_ALL_INFO *buf = NULL;
5106 struct cifs_io_parms io_parms = {0};
5108 struct cifs_fid fid;
5109 struct cifs_open_parms oparms;
5110 unsigned int bytes_written;
5111 struct win_dev *pdev;
5115 * Check if mounted with mount parm 'sfu' mount parm.
5116 * SFU emulation should work with all servers, but only
5117 * supports block and char device (no socket & fifo),
5118 * and was used by default in earlier versions of Windows
5120 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
5124 * TODO: Add ability to create instead via reparse point. Windows (e.g.
5125 * their current NFS server) uses this approach to expose special files
5126 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
5129 if (!S_ISCHR(mode) && !S_ISBLK(mode))
5132 cifs_dbg(FYI, "sfu compat create special file\n");
5134 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
5141 oparms.cifs_sb = cifs_sb;
5142 oparms.desired_access = GENERIC_WRITE;
5143 oparms.create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR |
5144 CREATE_OPTION_SPECIAL);
5145 oparms.disposition = FILE_CREATE;
5146 oparms.path = full_path;
5148 oparms.reconnect = false;
5150 if (tcon->ses->server->oplocks)
5151 oplock = REQ_OPLOCK;
5154 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf);
5159 * BB Do not bother to decode buf since no local inode yet to put
5160 * timestamps in, but we can reuse it safely.
5163 pdev = (struct win_dev *)buf;
5164 io_parms.pid = current->tgid;
5165 io_parms.tcon = tcon;
5166 io_parms.offset = 0;
5167 io_parms.length = sizeof(struct win_dev);
5168 iov[1].iov_base = buf;
5169 iov[1].iov_len = sizeof(struct win_dev);
5170 if (S_ISCHR(mode)) {
5171 memcpy(pdev->type, "IntxCHR", 8);
5172 pdev->major = cpu_to_le64(MAJOR(dev));
5173 pdev->minor = cpu_to_le64(MINOR(dev));
5174 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5175 &bytes_written, iov, 1);
5176 } else if (S_ISBLK(mode)) {
5177 memcpy(pdev->type, "IntxBLK", 8);
5178 pdev->major = cpu_to_le64(MAJOR(dev));
5179 pdev->minor = cpu_to_le64(MINOR(dev));
5180 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5181 &bytes_written, iov, 1);
5183 tcon->ses->server->ops->close(xid, tcon, &fid);
5186 /* FIXME: add code here to set EAs */
5192 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5193 struct smb_version_operations smb20_operations = {
5194 .compare_fids = smb2_compare_fids,
5195 .setup_request = smb2_setup_request,
5196 .setup_async_request = smb2_setup_async_request,
5197 .check_receive = smb2_check_receive,
5198 .add_credits = smb2_add_credits,
5199 .set_credits = smb2_set_credits,
5200 .get_credits_field = smb2_get_credits_field,
5201 .get_credits = smb2_get_credits,
5202 .wait_mtu_credits = cifs_wait_mtu_credits,
5203 .get_next_mid = smb2_get_next_mid,
5204 .revert_current_mid = smb2_revert_current_mid,
5205 .read_data_offset = smb2_read_data_offset,
5206 .read_data_length = smb2_read_data_length,
5207 .map_error = map_smb2_to_linux_error,
5208 .find_mid = smb2_find_mid,
5209 .check_message = smb2_check_message,
5210 .dump_detail = smb2_dump_detail,
5211 .clear_stats = smb2_clear_stats,
5212 .print_stats = smb2_print_stats,
5213 .is_oplock_break = smb2_is_valid_oplock_break,
5214 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5215 .downgrade_oplock = smb2_downgrade_oplock,
5216 .need_neg = smb2_need_neg,
5217 .negotiate = smb2_negotiate,
5218 .negotiate_wsize = smb2_negotiate_wsize,
5219 .negotiate_rsize = smb2_negotiate_rsize,
5220 .sess_setup = SMB2_sess_setup,
5221 .logoff = SMB2_logoff,
5222 .tree_connect = SMB2_tcon,
5223 .tree_disconnect = SMB2_tdis,
5224 .qfs_tcon = smb2_qfs_tcon,
5225 .is_path_accessible = smb2_is_path_accessible,
5226 .can_echo = smb2_can_echo,
5228 .query_path_info = smb2_query_path_info,
5229 .get_srv_inum = smb2_get_srv_inum,
5230 .query_file_info = smb2_query_file_info,
5231 .set_path_size = smb2_set_path_size,
5232 .set_file_size = smb2_set_file_size,
5233 .set_file_info = smb2_set_file_info,
5234 .set_compression = smb2_set_compression,
5235 .mkdir = smb2_mkdir,
5236 .mkdir_setinfo = smb2_mkdir_setinfo,
5237 .rmdir = smb2_rmdir,
5238 .unlink = smb2_unlink,
5239 .rename = smb2_rename_path,
5240 .create_hardlink = smb2_create_hardlink,
5241 .query_symlink = smb2_query_symlink,
5242 .query_mf_symlink = smb3_query_mf_symlink,
5243 .create_mf_symlink = smb3_create_mf_symlink,
5244 .open = smb2_open_file,
5245 .set_fid = smb2_set_fid,
5246 .close = smb2_close_file,
5247 .flush = smb2_flush_file,
5248 .async_readv = smb2_async_readv,
5249 .async_writev = smb2_async_writev,
5250 .sync_read = smb2_sync_read,
5251 .sync_write = smb2_sync_write,
5252 .query_dir_first = smb2_query_dir_first,
5253 .query_dir_next = smb2_query_dir_next,
5254 .close_dir = smb2_close_dir,
5255 .calc_smb_size = smb2_calc_size,
5256 .is_status_pending = smb2_is_status_pending,
5257 .is_session_expired = smb2_is_session_expired,
5258 .oplock_response = smb2_oplock_response,
5259 .queryfs = smb2_queryfs,
5260 .mand_lock = smb2_mand_lock,
5261 .mand_unlock_range = smb2_unlock_range,
5262 .push_mand_locks = smb2_push_mandatory_locks,
5263 .get_lease_key = smb2_get_lease_key,
5264 .set_lease_key = smb2_set_lease_key,
5265 .new_lease_key = smb2_new_lease_key,
5266 .calc_signature = smb2_calc_signature,
5267 .is_read_op = smb2_is_read_op,
5268 .set_oplock_level = smb2_set_oplock_level,
5269 .create_lease_buf = smb2_create_lease_buf,
5270 .parse_lease_buf = smb2_parse_lease_buf,
5271 .copychunk_range = smb2_copychunk_range,
5272 .wp_retry_size = smb2_wp_retry_size,
5273 .dir_needs_close = smb2_dir_needs_close,
5274 .get_dfs_refer = smb2_get_dfs_refer,
5275 .select_sectype = smb2_select_sectype,
5276 #ifdef CONFIG_CIFS_XATTR
5277 .query_all_EAs = smb2_query_eas,
5278 .set_EA = smb2_set_ea,
5279 #endif /* CIFS_XATTR */
5280 .get_acl = get_smb2_acl,
5281 .get_acl_by_fid = get_smb2_acl_by_fid,
5282 .set_acl = set_smb2_acl,
5283 .next_header = smb2_next_header,
5284 .ioctl_query_info = smb2_ioctl_query_info,
5285 .make_node = smb2_make_node,
5286 .fiemap = smb3_fiemap,
5287 .llseek = smb3_llseek,
5288 .is_status_io_timeout = smb2_is_status_io_timeout,
5289 .is_network_name_deleted = smb2_is_network_name_deleted,
5291 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
5293 struct smb_version_operations smb21_operations = {
5294 .compare_fids = smb2_compare_fids,
5295 .setup_request = smb2_setup_request,
5296 .setup_async_request = smb2_setup_async_request,
5297 .check_receive = smb2_check_receive,
5298 .add_credits = smb2_add_credits,
5299 .set_credits = smb2_set_credits,
5300 .get_credits_field = smb2_get_credits_field,
5301 .get_credits = smb2_get_credits,
5302 .wait_mtu_credits = smb2_wait_mtu_credits,
5303 .adjust_credits = smb2_adjust_credits,
5304 .get_next_mid = smb2_get_next_mid,
5305 .revert_current_mid = smb2_revert_current_mid,
5306 .read_data_offset = smb2_read_data_offset,
5307 .read_data_length = smb2_read_data_length,
5308 .map_error = map_smb2_to_linux_error,
5309 .find_mid = smb2_find_mid,
5310 .check_message = smb2_check_message,
5311 .dump_detail = smb2_dump_detail,
5312 .clear_stats = smb2_clear_stats,
5313 .print_stats = smb2_print_stats,
5314 .is_oplock_break = smb2_is_valid_oplock_break,
5315 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5316 .downgrade_oplock = smb2_downgrade_oplock,
5317 .need_neg = smb2_need_neg,
5318 .negotiate = smb2_negotiate,
5319 .negotiate_wsize = smb2_negotiate_wsize,
5320 .negotiate_rsize = smb2_negotiate_rsize,
5321 .sess_setup = SMB2_sess_setup,
5322 .logoff = SMB2_logoff,
5323 .tree_connect = SMB2_tcon,
5324 .tree_disconnect = SMB2_tdis,
5325 .qfs_tcon = smb2_qfs_tcon,
5326 .is_path_accessible = smb2_is_path_accessible,
5327 .can_echo = smb2_can_echo,
5329 .query_path_info = smb2_query_path_info,
5330 .get_srv_inum = smb2_get_srv_inum,
5331 .query_file_info = smb2_query_file_info,
5332 .set_path_size = smb2_set_path_size,
5333 .set_file_size = smb2_set_file_size,
5334 .set_file_info = smb2_set_file_info,
5335 .set_compression = smb2_set_compression,
5336 .mkdir = smb2_mkdir,
5337 .mkdir_setinfo = smb2_mkdir_setinfo,
5338 .rmdir = smb2_rmdir,
5339 .unlink = smb2_unlink,
5340 .rename = smb2_rename_path,
5341 .create_hardlink = smb2_create_hardlink,
5342 .query_symlink = smb2_query_symlink,
5343 .query_mf_symlink = smb3_query_mf_symlink,
5344 .create_mf_symlink = smb3_create_mf_symlink,
5345 .open = smb2_open_file,
5346 .set_fid = smb2_set_fid,
5347 .close = smb2_close_file,
5348 .flush = smb2_flush_file,
5349 .async_readv = smb2_async_readv,
5350 .async_writev = smb2_async_writev,
5351 .sync_read = smb2_sync_read,
5352 .sync_write = smb2_sync_write,
5353 .query_dir_first = smb2_query_dir_first,
5354 .query_dir_next = smb2_query_dir_next,
5355 .close_dir = smb2_close_dir,
5356 .calc_smb_size = smb2_calc_size,
5357 .is_status_pending = smb2_is_status_pending,
5358 .is_session_expired = smb2_is_session_expired,
5359 .oplock_response = smb2_oplock_response,
5360 .queryfs = smb2_queryfs,
5361 .mand_lock = smb2_mand_lock,
5362 .mand_unlock_range = smb2_unlock_range,
5363 .push_mand_locks = smb2_push_mandatory_locks,
5364 .get_lease_key = smb2_get_lease_key,
5365 .set_lease_key = smb2_set_lease_key,
5366 .new_lease_key = smb2_new_lease_key,
5367 .calc_signature = smb2_calc_signature,
5368 .is_read_op = smb21_is_read_op,
5369 .set_oplock_level = smb21_set_oplock_level,
5370 .create_lease_buf = smb2_create_lease_buf,
5371 .parse_lease_buf = smb2_parse_lease_buf,
5372 .copychunk_range = smb2_copychunk_range,
5373 .wp_retry_size = smb2_wp_retry_size,
5374 .dir_needs_close = smb2_dir_needs_close,
5375 .enum_snapshots = smb3_enum_snapshots,
5376 .notify = smb3_notify,
5377 .get_dfs_refer = smb2_get_dfs_refer,
5378 .select_sectype = smb2_select_sectype,
5379 #ifdef CONFIG_CIFS_XATTR
5380 .query_all_EAs = smb2_query_eas,
5381 .set_EA = smb2_set_ea,
5382 #endif /* CIFS_XATTR */
5383 .get_acl = get_smb2_acl,
5384 .get_acl_by_fid = get_smb2_acl_by_fid,
5385 .set_acl = set_smb2_acl,
5386 .next_header = smb2_next_header,
5387 .ioctl_query_info = smb2_ioctl_query_info,
5388 .make_node = smb2_make_node,
5389 .fiemap = smb3_fiemap,
5390 .llseek = smb3_llseek,
5391 .is_status_io_timeout = smb2_is_status_io_timeout,
5392 .is_network_name_deleted = smb2_is_network_name_deleted,
5395 struct smb_version_operations smb30_operations = {
5396 .compare_fids = smb2_compare_fids,
5397 .setup_request = smb2_setup_request,
5398 .setup_async_request = smb2_setup_async_request,
5399 .check_receive = smb2_check_receive,
5400 .add_credits = smb2_add_credits,
5401 .set_credits = smb2_set_credits,
5402 .get_credits_field = smb2_get_credits_field,
5403 .get_credits = smb2_get_credits,
5404 .wait_mtu_credits = smb2_wait_mtu_credits,
5405 .adjust_credits = smb2_adjust_credits,
5406 .get_next_mid = smb2_get_next_mid,
5407 .revert_current_mid = smb2_revert_current_mid,
5408 .read_data_offset = smb2_read_data_offset,
5409 .read_data_length = smb2_read_data_length,
5410 .map_error = map_smb2_to_linux_error,
5411 .find_mid = smb2_find_mid,
5412 .check_message = smb2_check_message,
5413 .dump_detail = smb2_dump_detail,
5414 .clear_stats = smb2_clear_stats,
5415 .print_stats = smb2_print_stats,
5416 .dump_share_caps = smb2_dump_share_caps,
5417 .is_oplock_break = smb2_is_valid_oplock_break,
5418 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5419 .downgrade_oplock = smb3_downgrade_oplock,
5420 .need_neg = smb2_need_neg,
5421 .negotiate = smb2_negotiate,
5422 .negotiate_wsize = smb3_negotiate_wsize,
5423 .negotiate_rsize = smb3_negotiate_rsize,
5424 .sess_setup = SMB2_sess_setup,
5425 .logoff = SMB2_logoff,
5426 .tree_connect = SMB2_tcon,
5427 .tree_disconnect = SMB2_tdis,
5428 .qfs_tcon = smb3_qfs_tcon,
5429 .is_path_accessible = smb2_is_path_accessible,
5430 .can_echo = smb2_can_echo,
5432 .query_path_info = smb2_query_path_info,
5433 /* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */
5434 .query_reparse_tag = smb2_query_reparse_tag,
5435 .get_srv_inum = smb2_get_srv_inum,
5436 .query_file_info = smb2_query_file_info,
5437 .set_path_size = smb2_set_path_size,
5438 .set_file_size = smb2_set_file_size,
5439 .set_file_info = smb2_set_file_info,
5440 .set_compression = smb2_set_compression,
5441 .mkdir = smb2_mkdir,
5442 .mkdir_setinfo = smb2_mkdir_setinfo,
5443 .rmdir = smb2_rmdir,
5444 .unlink = smb2_unlink,
5445 .rename = smb2_rename_path,
5446 .create_hardlink = smb2_create_hardlink,
5447 .query_symlink = smb2_query_symlink,
5448 .query_mf_symlink = smb3_query_mf_symlink,
5449 .create_mf_symlink = smb3_create_mf_symlink,
5450 .open = smb2_open_file,
5451 .set_fid = smb2_set_fid,
5452 .close = smb2_close_file,
5453 .close_getattr = smb2_close_getattr,
5454 .flush = smb2_flush_file,
5455 .async_readv = smb2_async_readv,
5456 .async_writev = smb2_async_writev,
5457 .sync_read = smb2_sync_read,
5458 .sync_write = smb2_sync_write,
5459 .query_dir_first = smb2_query_dir_first,
5460 .query_dir_next = smb2_query_dir_next,
5461 .close_dir = smb2_close_dir,
5462 .calc_smb_size = smb2_calc_size,
5463 .is_status_pending = smb2_is_status_pending,
5464 .is_session_expired = smb2_is_session_expired,
5465 .oplock_response = smb2_oplock_response,
5466 .queryfs = smb2_queryfs,
5467 .mand_lock = smb2_mand_lock,
5468 .mand_unlock_range = smb2_unlock_range,
5469 .push_mand_locks = smb2_push_mandatory_locks,
5470 .get_lease_key = smb2_get_lease_key,
5471 .set_lease_key = smb2_set_lease_key,
5472 .new_lease_key = smb2_new_lease_key,
5473 .generate_signingkey = generate_smb30signingkey,
5474 .calc_signature = smb3_calc_signature,
5475 .set_integrity = smb3_set_integrity,
5476 .is_read_op = smb21_is_read_op,
5477 .set_oplock_level = smb3_set_oplock_level,
5478 .create_lease_buf = smb3_create_lease_buf,
5479 .parse_lease_buf = smb3_parse_lease_buf,
5480 .copychunk_range = smb2_copychunk_range,
5481 .duplicate_extents = smb2_duplicate_extents,
5482 .validate_negotiate = smb3_validate_negotiate,
5483 .wp_retry_size = smb2_wp_retry_size,
5484 .dir_needs_close = smb2_dir_needs_close,
5485 .fallocate = smb3_fallocate,
5486 .enum_snapshots = smb3_enum_snapshots,
5487 .notify = smb3_notify,
5488 .init_transform_rq = smb3_init_transform_rq,
5489 .is_transform_hdr = smb3_is_transform_hdr,
5490 .receive_transform = smb3_receive_transform,
5491 .get_dfs_refer = smb2_get_dfs_refer,
5492 .select_sectype = smb2_select_sectype,
5493 #ifdef CONFIG_CIFS_XATTR
5494 .query_all_EAs = smb2_query_eas,
5495 .set_EA = smb2_set_ea,
5496 #endif /* CIFS_XATTR */
5497 .get_acl = get_smb2_acl,
5498 .get_acl_by_fid = get_smb2_acl_by_fid,
5499 .set_acl = set_smb2_acl,
5500 .next_header = smb2_next_header,
5501 .ioctl_query_info = smb2_ioctl_query_info,
5502 .make_node = smb2_make_node,
5503 .fiemap = smb3_fiemap,
5504 .llseek = smb3_llseek,
5505 .is_status_io_timeout = smb2_is_status_io_timeout,
5506 .is_network_name_deleted = smb2_is_network_name_deleted,
5509 struct smb_version_operations smb311_operations = {
5510 .compare_fids = smb2_compare_fids,
5511 .setup_request = smb2_setup_request,
5512 .setup_async_request = smb2_setup_async_request,
5513 .check_receive = smb2_check_receive,
5514 .add_credits = smb2_add_credits,
5515 .set_credits = smb2_set_credits,
5516 .get_credits_field = smb2_get_credits_field,
5517 .get_credits = smb2_get_credits,
5518 .wait_mtu_credits = smb2_wait_mtu_credits,
5519 .adjust_credits = smb2_adjust_credits,
5520 .get_next_mid = smb2_get_next_mid,
5521 .revert_current_mid = smb2_revert_current_mid,
5522 .read_data_offset = smb2_read_data_offset,
5523 .read_data_length = smb2_read_data_length,
5524 .map_error = map_smb2_to_linux_error,
5525 .find_mid = smb2_find_mid,
5526 .check_message = smb2_check_message,
5527 .dump_detail = smb2_dump_detail,
5528 .clear_stats = smb2_clear_stats,
5529 .print_stats = smb2_print_stats,
5530 .dump_share_caps = smb2_dump_share_caps,
5531 .is_oplock_break = smb2_is_valid_oplock_break,
5532 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5533 .downgrade_oplock = smb3_downgrade_oplock,
5534 .need_neg = smb2_need_neg,
5535 .negotiate = smb2_negotiate,
5536 .negotiate_wsize = smb3_negotiate_wsize,
5537 .negotiate_rsize = smb3_negotiate_rsize,
5538 .sess_setup = SMB2_sess_setup,
5539 .logoff = SMB2_logoff,
5540 .tree_connect = SMB2_tcon,
5541 .tree_disconnect = SMB2_tdis,
5542 .qfs_tcon = smb3_qfs_tcon,
5543 .is_path_accessible = smb2_is_path_accessible,
5544 .can_echo = smb2_can_echo,
5546 .query_path_info = smb2_query_path_info,
5547 .query_reparse_tag = smb2_query_reparse_tag,
5548 .get_srv_inum = smb2_get_srv_inum,
5549 .query_file_info = smb2_query_file_info,
5550 .set_path_size = smb2_set_path_size,
5551 .set_file_size = smb2_set_file_size,
5552 .set_file_info = smb2_set_file_info,
5553 .set_compression = smb2_set_compression,
5554 .mkdir = smb2_mkdir,
5555 .mkdir_setinfo = smb2_mkdir_setinfo,
5556 .posix_mkdir = smb311_posix_mkdir,
5557 .rmdir = smb2_rmdir,
5558 .unlink = smb2_unlink,
5559 .rename = smb2_rename_path,
5560 .create_hardlink = smb2_create_hardlink,
5561 .query_symlink = smb2_query_symlink,
5562 .query_mf_symlink = smb3_query_mf_symlink,
5563 .create_mf_symlink = smb3_create_mf_symlink,
5564 .open = smb2_open_file,
5565 .set_fid = smb2_set_fid,
5566 .close = smb2_close_file,
5567 .close_getattr = smb2_close_getattr,
5568 .flush = smb2_flush_file,
5569 .async_readv = smb2_async_readv,
5570 .async_writev = smb2_async_writev,
5571 .sync_read = smb2_sync_read,
5572 .sync_write = smb2_sync_write,
5573 .query_dir_first = smb2_query_dir_first,
5574 .query_dir_next = smb2_query_dir_next,
5575 .close_dir = smb2_close_dir,
5576 .calc_smb_size = smb2_calc_size,
5577 .is_status_pending = smb2_is_status_pending,
5578 .is_session_expired = smb2_is_session_expired,
5579 .oplock_response = smb2_oplock_response,
5580 .queryfs = smb311_queryfs,
5581 .mand_lock = smb2_mand_lock,
5582 .mand_unlock_range = smb2_unlock_range,
5583 .push_mand_locks = smb2_push_mandatory_locks,
5584 .get_lease_key = smb2_get_lease_key,
5585 .set_lease_key = smb2_set_lease_key,
5586 .new_lease_key = smb2_new_lease_key,
5587 .generate_signingkey = generate_smb311signingkey,
5588 .calc_signature = smb3_calc_signature,
5589 .set_integrity = smb3_set_integrity,
5590 .is_read_op = smb21_is_read_op,
5591 .set_oplock_level = smb3_set_oplock_level,
5592 .create_lease_buf = smb3_create_lease_buf,
5593 .parse_lease_buf = smb3_parse_lease_buf,
5594 .copychunk_range = smb2_copychunk_range,
5595 .duplicate_extents = smb2_duplicate_extents,
5596 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
5597 .wp_retry_size = smb2_wp_retry_size,
5598 .dir_needs_close = smb2_dir_needs_close,
5599 .fallocate = smb3_fallocate,
5600 .enum_snapshots = smb3_enum_snapshots,
5601 .notify = smb3_notify,
5602 .init_transform_rq = smb3_init_transform_rq,
5603 .is_transform_hdr = smb3_is_transform_hdr,
5604 .receive_transform = smb3_receive_transform,
5605 .get_dfs_refer = smb2_get_dfs_refer,
5606 .select_sectype = smb2_select_sectype,
5607 #ifdef CONFIG_CIFS_XATTR
5608 .query_all_EAs = smb2_query_eas,
5609 .set_EA = smb2_set_ea,
5610 #endif /* CIFS_XATTR */
5611 .get_acl = get_smb2_acl,
5612 .get_acl_by_fid = get_smb2_acl_by_fid,
5613 .set_acl = set_smb2_acl,
5614 .next_header = smb2_next_header,
5615 .ioctl_query_info = smb2_ioctl_query_info,
5616 .make_node = smb2_make_node,
5617 .fiemap = smb3_fiemap,
5618 .llseek = smb3_llseek,
5619 .is_status_io_timeout = smb2_is_status_io_timeout,
5620 .is_network_name_deleted = smb2_is_network_name_deleted,
5623 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5624 struct smb_version_values smb20_values = {
5625 .version_string = SMB20_VERSION_STRING,
5626 .protocol_id = SMB20_PROT_ID,
5627 .req_capabilities = 0, /* MBZ */
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),
5644 #endif /* ALLOW_INSECURE_LEGACY */
5646 struct smb_version_values smb21_values = {
5647 .version_string = SMB21_VERSION_STRING,
5648 .protocol_id = SMB21_PROT_ID,
5649 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
5650 .large_lock_type = 0,
5651 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5652 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5653 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5654 .header_size = sizeof(struct smb2_hdr),
5655 .header_preamble_size = 0,
5656 .max_header_size = MAX_SMB2_HDR_SIZE,
5657 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5658 .lock_cmd = SMB2_LOCK,
5660 .cap_nt_find = SMB2_NT_FIND,
5661 .cap_large_files = SMB2_LARGE_FILES,
5662 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5663 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5664 .create_lease_size = sizeof(struct create_lease),
5667 struct smb_version_values smb3any_values = {
5668 .version_string = SMB3ANY_VERSION_STRING,
5669 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5670 .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,
5671 .large_lock_type = 0,
5672 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5673 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5674 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5675 .header_size = sizeof(struct smb2_hdr),
5676 .header_preamble_size = 0,
5677 .max_header_size = MAX_SMB2_HDR_SIZE,
5678 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5679 .lock_cmd = SMB2_LOCK,
5681 .cap_nt_find = SMB2_NT_FIND,
5682 .cap_large_files = SMB2_LARGE_FILES,
5683 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5684 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5685 .create_lease_size = sizeof(struct create_lease_v2),
5688 struct smb_version_values smbdefault_values = {
5689 .version_string = SMBDEFAULT_VERSION_STRING,
5690 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5691 .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,
5692 .large_lock_type = 0,
5693 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5694 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5695 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5696 .header_size = sizeof(struct smb2_hdr),
5697 .header_preamble_size = 0,
5698 .max_header_size = MAX_SMB2_HDR_SIZE,
5699 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5700 .lock_cmd = SMB2_LOCK,
5702 .cap_nt_find = SMB2_NT_FIND,
5703 .cap_large_files = SMB2_LARGE_FILES,
5704 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5705 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5706 .create_lease_size = sizeof(struct create_lease_v2),
5709 struct smb_version_values smb30_values = {
5710 .version_string = SMB30_VERSION_STRING,
5711 .protocol_id = SMB30_PROT_ID,
5712 .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,
5713 .large_lock_type = 0,
5714 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5715 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5716 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5717 .header_size = sizeof(struct smb2_hdr),
5718 .header_preamble_size = 0,
5719 .max_header_size = MAX_SMB2_HDR_SIZE,
5720 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5721 .lock_cmd = SMB2_LOCK,
5723 .cap_nt_find = SMB2_NT_FIND,
5724 .cap_large_files = SMB2_LARGE_FILES,
5725 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5726 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5727 .create_lease_size = sizeof(struct create_lease_v2),
5730 struct smb_version_values smb302_values = {
5731 .version_string = SMB302_VERSION_STRING,
5732 .protocol_id = SMB302_PROT_ID,
5733 .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,
5734 .large_lock_type = 0,
5735 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5736 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5737 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5738 .header_size = sizeof(struct smb2_hdr),
5739 .header_preamble_size = 0,
5740 .max_header_size = MAX_SMB2_HDR_SIZE,
5741 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5742 .lock_cmd = SMB2_LOCK,
5744 .cap_nt_find = SMB2_NT_FIND,
5745 .cap_large_files = SMB2_LARGE_FILES,
5746 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5747 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5748 .create_lease_size = sizeof(struct create_lease_v2),
5751 struct smb_version_values smb311_values = {
5752 .version_string = SMB311_VERSION_STRING,
5753 .protocol_id = SMB311_PROT_ID,
5754 .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,
5755 .large_lock_type = 0,
5756 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5757 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5758 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5759 .header_size = sizeof(struct smb2_hdr),
5760 .header_preamble_size = 0,
5761 .max_header_size = MAX_SMB2_HDR_SIZE,
5762 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5763 .lock_cmd = SMB2_LOCK,
5765 .cap_nt_find = SMB2_NT_FIND,
5766 .cap_large_files = SMB2_LARGE_FILES,
5767 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5768 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5769 .create_lease_size = sizeof(struct create_lease_v2),