1 // SPDX-License-Identifier: GPL-2.0
3 * SMB2 version specific operations
8 #include <linux/pagemap.h>
10 #include <linux/falloc.h>
11 #include <linux/scatterlist.h>
12 #include <linux/uuid.h>
13 #include <linux/sort.h>
14 #include <crypto/aead.h>
15 #include <linux/fiemap.h>
16 #include <uapi/linux/magic.h>
20 #include "smb2proto.h"
21 #include "cifsproto.h"
22 #include "cifs_debug.h"
23 #include "cifs_unicode.h"
24 #include "smb2status.h"
26 #include "cifs_ioctl.h"
27 #include "smbdirect.h"
29 #include "fs_context.h"
30 #include "cached_dir.h"
32 /* Change credits for different ops and return the total number of credits */
34 change_conf(struct TCP_Server_Info *server)
36 server->credits += server->echo_credits + server->oplock_credits;
37 server->oplock_credits = server->echo_credits = 0;
38 switch (server->credits) {
42 server->echoes = false;
43 server->oplocks = false;
46 server->echoes = true;
47 server->oplocks = false;
48 server->echo_credits = 1;
51 server->echoes = true;
53 server->oplocks = true;
54 server->oplock_credits = 1;
56 server->oplocks = false;
58 server->echo_credits = 1;
60 server->credits -= server->echo_credits + server->oplock_credits;
61 return server->credits + server->echo_credits + server->oplock_credits;
65 smb2_add_credits(struct TCP_Server_Info *server,
66 const struct cifs_credits *credits, const int optype)
69 int scredits, in_flight;
70 unsigned int add = credits->value;
71 unsigned int instance = credits->instance;
72 bool reconnect_detected = false;
73 bool reconnect_with_invalid_credits = false;
75 spin_lock(&server->req_lock);
76 val = server->ops->get_credits_field(server, optype);
78 /* eg found case where write overlapping reconnect messed up credits */
79 if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0))
80 reconnect_with_invalid_credits = true;
82 if ((instance == 0) || (instance == server->reconnect_instance))
85 reconnect_detected = true;
88 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
89 pr_warn_once("server overflowed SMB3 credits\n");
90 trace_smb3_overflow_credits(server->CurrentMid,
91 server->conn_id, server->hostname, *val,
92 add, server->in_flight);
95 if (server->in_flight == 0 &&
96 ((optype & CIFS_OP_MASK) != CIFS_NEG_OP) &&
97 ((optype & CIFS_OP_MASK) != CIFS_SESS_OP))
98 rc = change_conf(server);
100 * Sometimes server returns 0 credits on oplock break ack - we need to
101 * rebalance credits in this case.
103 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
105 if (server->credits > 1) {
107 server->oplock_credits++;
111 in_flight = server->in_flight;
112 spin_unlock(&server->req_lock);
113 wake_up(&server->request_q);
115 if (reconnect_detected) {
116 trace_smb3_reconnect_detected(server->CurrentMid,
117 server->conn_id, server->hostname, scredits, add, in_flight);
119 cifs_dbg(FYI, "trying to put %d credits from the old server instance %d\n",
123 if (reconnect_with_invalid_credits) {
124 trace_smb3_reconnect_with_invalid_credits(server->CurrentMid,
125 server->conn_id, server->hostname, scredits, add, in_flight);
126 cifs_dbg(FYI, "Negotiate operation when server credits is non-zero. Optype: %d, server credits: %d, credits added: %d\n",
127 optype, scredits, add);
130 spin_lock(&server->srv_lock);
131 if (server->tcpStatus == CifsNeedReconnect
132 || server->tcpStatus == CifsExiting) {
133 spin_unlock(&server->srv_lock);
136 spin_unlock(&server->srv_lock);
140 /* change_conf hasn't been executed */
143 cifs_server_dbg(VFS, "Possible client or server bug - zero credits\n");
146 cifs_server_dbg(VFS, "disabling echoes and oplocks\n");
149 cifs_dbg(FYI, "disabling oplocks\n");
152 /* change_conf rebalanced credits for different types */
156 trace_smb3_add_credits(server->CurrentMid,
157 server->conn_id, server->hostname, scredits, add, in_flight);
158 cifs_dbg(FYI, "%s: added %u credits total=%d\n", __func__, add, scredits);
162 smb2_set_credits(struct TCP_Server_Info *server, const int val)
164 int scredits, in_flight;
166 spin_lock(&server->req_lock);
167 server->credits = val;
169 server->reconnect_instance++;
170 scredits = server->credits;
171 in_flight = server->in_flight;
172 spin_unlock(&server->req_lock);
174 trace_smb3_set_credits(server->CurrentMid,
175 server->conn_id, server->hostname, scredits, val, in_flight);
176 cifs_dbg(FYI, "%s: set %u credits\n", __func__, val);
178 /* don't log while holding the lock */
180 cifs_dbg(FYI, "set credits to 1 due to smb2 reconnect\n");
184 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
188 return &server->echo_credits;
190 return &server->oplock_credits;
192 return &server->credits;
197 smb2_get_credits(struct mid_q_entry *mid)
199 return mid->credits_received;
203 smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
204 unsigned int *num, struct cifs_credits *credits)
207 unsigned int scredits, in_flight;
209 spin_lock(&server->req_lock);
211 if (server->credits <= 0) {
212 spin_unlock(&server->req_lock);
213 cifs_num_waiters_inc(server);
214 rc = wait_event_killable(server->request_q,
215 has_credits(server, &server->credits, 1));
216 cifs_num_waiters_dec(server);
219 spin_lock(&server->req_lock);
221 spin_unlock(&server->req_lock);
222 spin_lock(&server->srv_lock);
223 if (server->tcpStatus == CifsExiting) {
224 spin_unlock(&server->srv_lock);
227 spin_unlock(&server->srv_lock);
229 spin_lock(&server->req_lock);
230 scredits = server->credits;
231 /* can deadlock with reopen */
233 *num = SMB2_MAX_BUFFER_SIZE;
235 credits->instance = 0;
239 /* leave some credits for reopen and other ops */
241 *num = min_t(unsigned int, size,
242 scredits * SMB2_MAX_BUFFER_SIZE);
245 DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
246 credits->instance = server->reconnect_instance;
247 server->credits -= credits->value;
249 if (server->in_flight > server->max_in_flight)
250 server->max_in_flight = server->in_flight;
254 scredits = server->credits;
255 in_flight = server->in_flight;
256 spin_unlock(&server->req_lock);
258 trace_smb3_wait_credits(server->CurrentMid,
259 server->conn_id, server->hostname, scredits, -(credits->value), in_flight);
260 cifs_dbg(FYI, "%s: removed %u credits total=%d\n",
261 __func__, credits->value, scredits);
267 smb2_adjust_credits(struct TCP_Server_Info *server,
268 struct cifs_credits *credits,
269 const unsigned int payload_size)
271 int new_val = DIV_ROUND_UP(payload_size, SMB2_MAX_BUFFER_SIZE);
272 int scredits, in_flight;
274 if (!credits->value || credits->value == new_val)
277 if (credits->value < new_val) {
278 trace_smb3_too_many_credits(server->CurrentMid,
279 server->conn_id, server->hostname, 0, credits->value - new_val, 0);
280 cifs_server_dbg(VFS, "request has less credits (%d) than required (%d)",
281 credits->value, new_val);
286 spin_lock(&server->req_lock);
288 if (server->reconnect_instance != credits->instance) {
289 scredits = server->credits;
290 in_flight = server->in_flight;
291 spin_unlock(&server->req_lock);
293 trace_smb3_reconnect_detected(server->CurrentMid,
294 server->conn_id, server->hostname, scredits,
295 credits->value - new_val, in_flight);
296 cifs_server_dbg(VFS, "trying to return %d credits to old session\n",
297 credits->value - new_val);
301 server->credits += credits->value - new_val;
302 scredits = server->credits;
303 in_flight = server->in_flight;
304 spin_unlock(&server->req_lock);
305 wake_up(&server->request_q);
307 trace_smb3_adj_credits(server->CurrentMid,
308 server->conn_id, server->hostname, scredits,
309 credits->value - new_val, in_flight);
310 cifs_dbg(FYI, "%s: adjust added %u credits total=%d\n",
311 __func__, credits->value - new_val, scredits);
313 credits->value = new_val;
319 smb2_get_next_mid(struct TCP_Server_Info *server)
322 /* for SMB2 we need the current value */
323 spin_lock(&server->mid_lock);
324 mid = server->CurrentMid++;
325 spin_unlock(&server->mid_lock);
330 smb2_revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
332 spin_lock(&server->mid_lock);
333 if (server->CurrentMid >= val)
334 server->CurrentMid -= val;
335 spin_unlock(&server->mid_lock);
338 static struct mid_q_entry *
339 __smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue)
341 struct mid_q_entry *mid;
342 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
343 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
345 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
346 cifs_server_dbg(VFS, "Encrypted frame parsing not supported yet\n");
350 spin_lock(&server->mid_lock);
351 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
352 if ((mid->mid == wire_mid) &&
353 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
354 (mid->command == shdr->Command)) {
355 kref_get(&mid->refcount);
357 list_del_init(&mid->qhead);
358 mid->mid_flags |= MID_DELETED;
360 spin_unlock(&server->mid_lock);
364 spin_unlock(&server->mid_lock);
368 static struct mid_q_entry *
369 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
371 return __smb2_find_mid(server, buf, false);
374 static struct mid_q_entry *
375 smb2_find_dequeue_mid(struct TCP_Server_Info *server, char *buf)
377 return __smb2_find_mid(server, buf, true);
381 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
383 #ifdef CONFIG_CIFS_DEBUG2
384 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
386 cifs_server_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
387 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
388 shdr->Id.SyncId.ProcessId);
389 cifs_server_dbg(VFS, "smb buf %p len %u\n", buf,
390 server->ops->calc_smb_size(buf));
395 smb2_need_neg(struct TCP_Server_Info *server)
397 return server->max_read == 0;
401 smb2_negotiate(const unsigned int xid,
402 struct cifs_ses *ses,
403 struct TCP_Server_Info *server)
407 spin_lock(&server->mid_lock);
408 server->CurrentMid = 0;
409 spin_unlock(&server->mid_lock);
410 rc = SMB2_negotiate(xid, ses, server);
411 /* BB we probably don't need to retry with modern servers */
418 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
420 struct TCP_Server_Info *server = tcon->ses->server;
423 /* start with specified wsize, or default */
424 wsize = ctx->wsize ? ctx->wsize : CIFS_DEFAULT_IOSIZE;
425 wsize = min_t(unsigned int, wsize, server->max_write);
426 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
427 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
433 smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
435 struct TCP_Server_Info *server = tcon->ses->server;
438 /* start with specified wsize, or default */
439 wsize = ctx->wsize ? ctx->wsize : SMB3_DEFAULT_IOSIZE;
440 wsize = min_t(unsigned int, wsize, server->max_write);
441 #ifdef CONFIG_CIFS_SMB_DIRECT
445 * Account for SMB2 data transfer packet header and
446 * possible encryption header
448 wsize = min_t(unsigned int,
450 server->smbd_conn->max_fragmented_send_size -
451 SMB2_READWRITE_PDU_HEADER_SIZE -
452 sizeof(struct smb2_transform_hdr));
454 wsize = min_t(unsigned int,
455 wsize, server->smbd_conn->max_readwrite_size);
458 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
459 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
465 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
467 struct TCP_Server_Info *server = tcon->ses->server;
470 /* start with specified rsize, or default */
471 rsize = ctx->rsize ? ctx->rsize : CIFS_DEFAULT_IOSIZE;
472 rsize = min_t(unsigned int, rsize, server->max_read);
474 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
475 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
481 smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
483 struct TCP_Server_Info *server = tcon->ses->server;
486 /* start with specified rsize, or default */
487 rsize = ctx->rsize ? ctx->rsize : SMB3_DEFAULT_IOSIZE;
488 rsize = min_t(unsigned int, rsize, server->max_read);
489 #ifdef CONFIG_CIFS_SMB_DIRECT
493 * Account for SMB2 data transfer packet header and
494 * possible encryption header
496 rsize = min_t(unsigned int,
498 server->smbd_conn->max_fragmented_recv_size -
499 SMB2_READWRITE_PDU_HEADER_SIZE -
500 sizeof(struct smb2_transform_hdr));
502 rsize = min_t(unsigned int,
503 rsize, server->smbd_conn->max_readwrite_size);
507 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
508 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
514 parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
515 size_t buf_len, struct cifs_ses *ses, bool in_mount)
517 struct network_interface_info_ioctl_rsp *p;
518 struct sockaddr_in *addr4;
519 struct sockaddr_in6 *addr6;
520 struct iface_info_ipv4 *p4;
521 struct iface_info_ipv6 *p6;
522 struct cifs_server_iface *info = NULL, *iface = NULL, *niface = NULL;
523 struct cifs_server_iface tmp_iface;
529 bytes_left = buf_len;
532 spin_lock(&ses->iface_lock);
534 * Go through iface_list and do kref_put to remove
535 * any unused ifaces. ifaces in use will be removed
536 * when the last user calls a kref_put on it
538 list_for_each_entry_safe(iface, niface, &ses->iface_list,
540 iface->is_active = 0;
541 kref_put(&iface->refcount, release_iface);
544 spin_unlock(&ses->iface_lock);
547 * Samba server e.g. can return an empty interface list in some cases,
548 * which would only be a problem if we were requesting multichannel
550 if (bytes_left == 0) {
551 /* avoid spamming logs every 10 minutes, so log only in mount */
552 if ((ses->chan_max > 1) && in_mount)
554 "multichannel not available\n"
555 "Empty network interface list returned by server %s\n",
556 ses->server->hostname);
561 while (bytes_left >= sizeof(*p)) {
562 memset(&tmp_iface, 0, sizeof(tmp_iface));
563 tmp_iface.speed = le64_to_cpu(p->LinkSpeed);
564 tmp_iface.rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE) ? 1 : 0;
565 tmp_iface.rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE) ? 1 : 0;
569 * The kernel and wire socket structures have the same
570 * layout and use network byte order but make the
571 * conversion explicit in case either one changes.
574 addr4 = (struct sockaddr_in *)&tmp_iface.sockaddr;
575 p4 = (struct iface_info_ipv4 *)p->Buffer;
576 addr4->sin_family = AF_INET;
577 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
579 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
580 addr4->sin_port = cpu_to_be16(CIFS_PORT);
582 cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
586 addr6 = (struct sockaddr_in6 *)&tmp_iface.sockaddr;
587 p6 = (struct iface_info_ipv6 *)p->Buffer;
588 addr6->sin6_family = AF_INET6;
589 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
591 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
592 addr6->sin6_flowinfo = 0;
593 addr6->sin6_scope_id = 0;
594 addr6->sin6_port = cpu_to_be16(CIFS_PORT);
596 cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
601 "%s: skipping unsupported socket family\n",
607 * The iface_list is assumed to be sorted by speed.
608 * Check if the new interface exists in that list.
609 * NEVER change iface. it could be in use.
610 * Add a new one instead
612 spin_lock(&ses->iface_lock);
613 iface = niface = NULL;
614 list_for_each_entry_safe(iface, niface, &ses->iface_list,
616 ret = iface_cmp(iface, &tmp_iface);
618 /* just get a ref so that it doesn't get picked/freed */
619 iface->is_active = 1;
620 kref_get(&iface->refcount);
622 spin_unlock(&ses->iface_lock);
624 } else if (ret < 0) {
625 /* all remaining ifaces are slower */
626 kref_get(&iface->refcount);
630 spin_unlock(&ses->iface_lock);
632 /* no match. insert the entry in the list */
633 info = kmalloc(sizeof(struct cifs_server_iface),
639 memcpy(info, &tmp_iface, sizeof(tmp_iface));
641 /* add this new entry to the list */
642 kref_init(&info->refcount);
645 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, ses->iface_count);
646 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
647 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
648 le32_to_cpu(p->Capability));
650 spin_lock(&ses->iface_lock);
651 if (!list_entry_is_head(iface, &ses->iface_list, iface_head)) {
652 list_add_tail(&info->iface_head, &iface->iface_head);
653 kref_put(&iface->refcount, release_iface);
655 list_add_tail(&info->iface_head, &ses->iface_list);
658 spin_unlock(&ses->iface_lock);
659 ses->iface_last_update = jiffies;
662 next = le32_to_cpu(p->Next);
664 bytes_left -= sizeof(*p);
667 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
672 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
677 /* Azure rounds the buffer size up 8, to a 16 byte boundary */
678 if ((bytes_left > 8) || p->Next)
679 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
682 if (!ses->iface_count) {
692 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon, bool in_mount)
695 unsigned int ret_data_len = 0;
696 struct network_interface_info_ioctl_rsp *out_buf = NULL;
697 struct cifs_ses *ses = tcon->ses;
699 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
700 FSCTL_QUERY_NETWORK_INTERFACE_INFO,
701 NULL /* no data input */, 0 /* no data input */,
702 CIFSMaxBufSize, (char **)&out_buf, &ret_data_len);
703 if (rc == -EOPNOTSUPP) {
705 "server does not support query network interfaces\n");
707 } else if (rc != 0) {
708 cifs_tcon_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
712 rc = parse_server_interfaces(out_buf, ret_data_len, ses, in_mount);
722 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
723 struct cifs_sb_info *cifs_sb)
726 __le16 srch_path = 0; /* Null - open root of share */
727 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
728 struct cifs_open_parms oparms;
730 struct cached_fid *cfid = NULL;
732 oparms = (struct cifs_open_parms) {
734 .desired_access = FILE_READ_ATTRIBUTES,
735 .disposition = FILE_OPEN,
736 .create_options = cifs_create_options(cifs_sb, 0),
740 rc = open_cached_dir(xid, tcon, "", cifs_sb, false, &cfid);
742 memcpy(&fid, &cfid->fid, sizeof(struct cifs_fid));
744 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
749 SMB3_request_interfaces(xid, tcon, true /* called during mount */);
751 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
752 FS_ATTRIBUTE_INFORMATION);
753 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
754 FS_DEVICE_INFORMATION);
755 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
756 FS_VOLUME_INFORMATION);
757 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
758 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
760 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
762 close_cached_dir(cfid);
766 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
767 struct cifs_sb_info *cifs_sb)
770 __le16 srch_path = 0; /* Null - open root of share */
771 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
772 struct cifs_open_parms oparms;
775 oparms = (struct cifs_open_parms) {
777 .desired_access = FILE_READ_ATTRIBUTES,
778 .disposition = FILE_OPEN,
779 .create_options = cifs_create_options(cifs_sb, 0),
783 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
788 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
789 FS_ATTRIBUTE_INFORMATION);
790 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
791 FS_DEVICE_INFORMATION);
792 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
796 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
797 struct cifs_sb_info *cifs_sb, const char *full_path)
800 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
801 int err_buftype = CIFS_NO_BUFFER;
802 struct cifs_open_parms oparms;
803 struct kvec err_iov = {};
805 struct cached_fid *cfid;
809 rc = open_cached_dir(xid, tcon, full_path, cifs_sb, true, &cfid);
811 if (cfid->has_lease) {
812 close_cached_dir(cfid);
815 close_cached_dir(cfid);
818 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
822 oparms = (struct cifs_open_parms) {
824 .desired_access = FILE_READ_ATTRIBUTES,
825 .disposition = FILE_OPEN,
826 .create_options = cifs_create_options(cifs_sb, 0),
830 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
831 &err_iov, &err_buftype);
833 struct smb2_hdr *hdr = err_iov.iov_base;
835 if (unlikely(!hdr || err_buftype == CIFS_NO_BUFFER))
838 if (rc != -EREMOTE && hdr->Status == STATUS_OBJECT_NAME_INVALID) {
839 rc2 = cifs_inval_name_dfs_link_error(xid, tcon, cifs_sb,
848 if (rc == -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) && cifs_sb &&
849 (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS))
854 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
857 free_rsp_buf(err_buftype, err_iov.iov_base);
862 static int smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
863 struct cifs_sb_info *cifs_sb, const char *full_path,
864 u64 *uniqueid, struct cifs_open_info_data *data)
866 *uniqueid = le64_to_cpu(data->fi.IndexNumber);
870 static int smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
871 struct cifsFileInfo *cfile, struct cifs_open_info_data *data)
873 struct cifs_fid *fid = &cfile->fid;
875 if (cfile->symlink_target) {
876 data->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
877 if (!data->symlink_target)
880 return SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, &data->fi);
883 #ifdef CONFIG_CIFS_XATTR
885 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
886 struct smb2_file_full_ea_info *src, size_t src_size,
887 const unsigned char *ea_name)
890 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
892 size_t buf_size = dst_size;
893 size_t name_len, value_len, user_name_len;
895 while (src_size > 0) {
896 name_len = (size_t)src->ea_name_length;
897 value_len = (size_t)le16_to_cpu(src->ea_value_length);
902 if (src_size < 8 + name_len + 1 + value_len) {
903 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
908 name = &src->ea_data[0];
909 value = &src->ea_data[src->ea_name_length + 1];
912 if (ea_name_len == name_len &&
913 memcmp(ea_name, name, name_len) == 0) {
917 if (dst_size < value_len) {
921 memcpy(dst, value, value_len);
925 /* 'user.' plus a terminating null */
926 user_name_len = 5 + 1 + name_len;
929 /* skip copy - calc size only */
931 } else if (dst_size >= user_name_len) {
932 dst_size -= user_name_len;
933 memcpy(dst, "user.", 5);
935 memcpy(dst, src->ea_data, name_len);
941 /* stop before overrun buffer */
947 if (!src->next_entry_offset)
950 if (src_size < le32_to_cpu(src->next_entry_offset)) {
951 /* stop before overrun buffer */
955 src_size -= le32_to_cpu(src->next_entry_offset);
956 src = (void *)((char *)src +
957 le32_to_cpu(src->next_entry_offset));
960 /* didn't find the named attribute */
969 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
970 const unsigned char *path, const unsigned char *ea_name,
971 char *ea_data, size_t buf_size,
972 struct cifs_sb_info *cifs_sb)
975 struct kvec rsp_iov = {NULL, 0};
976 int buftype = CIFS_NO_BUFFER;
977 struct smb2_query_info_rsp *rsp;
978 struct smb2_file_full_ea_info *info = NULL;
980 rc = smb2_query_info_compound(xid, tcon, path,
982 FILE_FULL_EA_INFORMATION,
985 MAX_SMB2_CREATE_RESPONSE_SIZE -
986 MAX_SMB2_CLOSE_RESPONSE_SIZE,
987 &rsp_iov, &buftype, cifs_sb);
990 * If ea_name is NULL (listxattr) and there are no EAs,
991 * return 0 as it's not an error. Otherwise, the specified
992 * ea_name was not found.
994 if (!ea_name && rc == -ENODATA)
999 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
1000 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1001 le32_to_cpu(rsp->OutputBufferLength),
1003 sizeof(struct smb2_file_full_ea_info));
1007 info = (struct smb2_file_full_ea_info *)(
1008 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1009 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
1010 le32_to_cpu(rsp->OutputBufferLength), ea_name);
1013 free_rsp_buf(buftype, rsp_iov.iov_base);
1019 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
1020 const char *path, const char *ea_name, const void *ea_value,
1021 const __u16 ea_value_len, const struct nls_table *nls_codepage,
1022 struct cifs_sb_info *cifs_sb)
1024 struct cifs_ses *ses = tcon->ses;
1025 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1026 __le16 *utf16_path = NULL;
1027 int ea_name_len = strlen(ea_name);
1028 int flags = CIFS_CP_CREATE_CLOSE_OP;
1030 struct smb_rqst rqst[3];
1031 int resp_buftype[3];
1032 struct kvec rsp_iov[3];
1033 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1034 struct cifs_open_parms oparms;
1035 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1036 struct cifs_fid fid;
1037 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1038 unsigned int size[1];
1040 struct smb2_file_full_ea_info *ea = NULL;
1041 struct kvec close_iov[1];
1042 struct smb2_query_info_rsp *rsp;
1043 int rc, used_len = 0;
1045 if (smb3_encryption_required(tcon))
1046 flags |= CIFS_TRANSFORM_REQ;
1048 if (ea_name_len > 255)
1051 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1055 memset(rqst, 0, sizeof(rqst));
1056 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1057 memset(rsp_iov, 0, sizeof(rsp_iov));
1059 if (ses->server->ops->query_all_EAs) {
1061 rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1067 /* If we are adding a attribute we should first check
1068 * if there will be enough space available to store
1069 * the new EA. If not we should not add it since we
1070 * would not be able to even read the EAs back.
1072 rc = smb2_query_info_compound(xid, tcon, path,
1074 FILE_FULL_EA_INFORMATION,
1077 MAX_SMB2_CREATE_RESPONSE_SIZE -
1078 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1079 &rsp_iov[1], &resp_buftype[1], cifs_sb);
1081 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1082 used_len = le32_to_cpu(rsp->OutputBufferLength);
1084 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1085 resp_buftype[1] = CIFS_NO_BUFFER;
1086 memset(&rsp_iov[1], 0, sizeof(rsp_iov[1]));
1089 /* Use a fudge factor of 256 bytes in case we collide
1090 * with a different set_EAs command.
1092 if(CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1093 MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 <
1094 used_len + ea_name_len + ea_value_len + 1) {
1102 memset(&open_iov, 0, sizeof(open_iov));
1103 rqst[0].rq_iov = open_iov;
1104 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1106 oparms = (struct cifs_open_parms) {
1108 .desired_access = FILE_WRITE_EA,
1109 .disposition = FILE_OPEN,
1110 .create_options = cifs_create_options(cifs_sb, 0),
1114 rc = SMB2_open_init(tcon, server,
1115 &rqst[0], &oplock, &oparms, utf16_path);
1118 smb2_set_next_command(tcon, &rqst[0]);
1122 memset(&si_iov, 0, sizeof(si_iov));
1123 rqst[1].rq_iov = si_iov;
1124 rqst[1].rq_nvec = 1;
1126 len = sizeof(*ea) + ea_name_len + ea_value_len + 1;
1127 ea = kzalloc(len, GFP_KERNEL);
1133 ea->ea_name_length = ea_name_len;
1134 ea->ea_value_length = cpu_to_le16(ea_value_len);
1135 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
1136 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
1141 rc = SMB2_set_info_init(tcon, server,
1142 &rqst[1], COMPOUND_FID,
1143 COMPOUND_FID, current->tgid,
1144 FILE_FULL_EA_INFORMATION,
1145 SMB2_O_INFO_FILE, 0, data, size);
1148 smb2_set_next_command(tcon, &rqst[1]);
1149 smb2_set_related(&rqst[1]);
1153 memset(&close_iov, 0, sizeof(close_iov));
1154 rqst[2].rq_iov = close_iov;
1155 rqst[2].rq_nvec = 1;
1156 rc = SMB2_close_init(tcon, server,
1157 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1160 smb2_set_related(&rqst[2]);
1162 rc = compound_send_recv(xid, ses, server,
1164 resp_buftype, rsp_iov);
1165 /* no need to bump num_remote_opens because handle immediately closed */
1170 SMB2_open_free(&rqst[0]);
1171 SMB2_set_info_free(&rqst[1]);
1172 SMB2_close_free(&rqst[2]);
1173 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1174 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1175 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1181 smb2_can_echo(struct TCP_Server_Info *server)
1183 return server->echoes;
1187 smb2_clear_stats(struct cifs_tcon *tcon)
1191 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1192 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1193 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1198 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1200 seq_puts(m, "\n\tShare Capabilities:");
1201 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1202 seq_puts(m, " DFS,");
1203 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1204 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1205 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1206 seq_puts(m, " SCALEOUT,");
1207 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1208 seq_puts(m, " CLUSTER,");
1209 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1210 seq_puts(m, " ASYMMETRIC,");
1211 if (tcon->capabilities == 0)
1212 seq_puts(m, " None");
1213 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1214 seq_puts(m, " Aligned,");
1215 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1216 seq_puts(m, " Partition Aligned,");
1217 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1218 seq_puts(m, " SSD,");
1219 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1220 seq_puts(m, " TRIM-support,");
1222 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1223 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1224 if (tcon->perf_sector_size)
1225 seq_printf(m, "\tOptimal sector size: 0x%x",
1226 tcon->perf_sector_size);
1227 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1231 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1233 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1234 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1237 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1238 * totals (requests sent) since those SMBs are per-session not per tcon
1240 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1241 (long long)(tcon->bytes_read),
1242 (long long)(tcon->bytes_written));
1243 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1244 atomic_read(&tcon->num_local_opens),
1245 atomic_read(&tcon->num_remote_opens));
1246 seq_printf(m, "\nTreeConnects: %d total %d failed",
1247 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1248 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1249 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1250 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1251 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1252 seq_printf(m, "\nCreates: %d total %d failed",
1253 atomic_read(&sent[SMB2_CREATE_HE]),
1254 atomic_read(&failed[SMB2_CREATE_HE]));
1255 seq_printf(m, "\nCloses: %d total %d failed",
1256 atomic_read(&sent[SMB2_CLOSE_HE]),
1257 atomic_read(&failed[SMB2_CLOSE_HE]));
1258 seq_printf(m, "\nFlushes: %d total %d failed",
1259 atomic_read(&sent[SMB2_FLUSH_HE]),
1260 atomic_read(&failed[SMB2_FLUSH_HE]));
1261 seq_printf(m, "\nReads: %d total %d failed",
1262 atomic_read(&sent[SMB2_READ_HE]),
1263 atomic_read(&failed[SMB2_READ_HE]));
1264 seq_printf(m, "\nWrites: %d total %d failed",
1265 atomic_read(&sent[SMB2_WRITE_HE]),
1266 atomic_read(&failed[SMB2_WRITE_HE]));
1267 seq_printf(m, "\nLocks: %d total %d failed",
1268 atomic_read(&sent[SMB2_LOCK_HE]),
1269 atomic_read(&failed[SMB2_LOCK_HE]));
1270 seq_printf(m, "\nIOCTLs: %d total %d failed",
1271 atomic_read(&sent[SMB2_IOCTL_HE]),
1272 atomic_read(&failed[SMB2_IOCTL_HE]));
1273 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1274 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1275 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1276 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1277 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1278 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1279 seq_printf(m, "\nQueryInfos: %d total %d failed",
1280 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1281 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1282 seq_printf(m, "\nSetInfos: %d total %d failed",
1283 atomic_read(&sent[SMB2_SET_INFO_HE]),
1284 atomic_read(&failed[SMB2_SET_INFO_HE]));
1285 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1286 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1287 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1291 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1293 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1294 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1296 cfile->fid.persistent_fid = fid->persistent_fid;
1297 cfile->fid.volatile_fid = fid->volatile_fid;
1298 cfile->fid.access = fid->access;
1299 #ifdef CONFIG_CIFS_DEBUG2
1300 cfile->fid.mid = fid->mid;
1301 #endif /* CIFS_DEBUG2 */
1302 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1304 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1305 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1309 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1310 struct cifs_fid *fid)
1312 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1316 smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon,
1317 struct cifsFileInfo *cfile)
1319 struct smb2_file_network_open_info file_inf;
1320 struct inode *inode;
1323 rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid,
1324 cfile->fid.volatile_fid, &file_inf);
1328 inode = d_inode(cfile->dentry);
1330 spin_lock(&inode->i_lock);
1331 CIFS_I(inode)->time = jiffies;
1333 /* Creation time should not need to be updated on close */
1334 if (file_inf.LastWriteTime)
1335 inode->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime);
1336 if (file_inf.ChangeTime)
1337 inode->i_ctime = cifs_NTtimeToUnix(file_inf.ChangeTime);
1338 if (file_inf.LastAccessTime)
1339 inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime);
1342 * i_blocks is not related to (i_size / i_blksize),
1343 * but instead 512 byte (2**9) size is required for
1344 * calculating num blocks.
1346 if (le64_to_cpu(file_inf.AllocationSize) > 4096)
1348 (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9;
1350 /* End of file and Attributes should not have to be updated on close */
1351 spin_unlock(&inode->i_lock);
1355 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1356 u64 persistent_fid, u64 volatile_fid,
1357 struct copychunk_ioctl *pcchunk)
1360 unsigned int ret_data_len;
1361 struct resume_key_req *res_key;
1363 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1364 FSCTL_SRV_REQUEST_RESUME_KEY, NULL, 0 /* no input */,
1365 CIFSMaxBufSize, (char **)&res_key, &ret_data_len);
1367 if (rc == -EOPNOTSUPP) {
1368 pr_warn_once("Server share %s does not support copy range\n", tcon->tree_name);
1369 goto req_res_key_exit;
1371 cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1372 goto req_res_key_exit;
1374 if (ret_data_len < sizeof(struct resume_key_req)) {
1375 cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n");
1377 goto req_res_key_exit;
1379 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1387 struct smb_rqst rqst[3];
1388 struct kvec rsp_iov[3];
1389 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1390 struct kvec qi_iov[1];
1391 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
1392 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1393 struct kvec close_iov[1];
1397 smb2_ioctl_query_info(const unsigned int xid,
1398 struct cifs_tcon *tcon,
1399 struct cifs_sb_info *cifs_sb,
1400 __le16 *path, int is_dir,
1403 struct iqi_vars *vars;
1404 struct smb_rqst *rqst;
1405 struct kvec *rsp_iov;
1406 struct cifs_ses *ses = tcon->ses;
1407 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1408 char __user *arg = (char __user *)p;
1409 struct smb_query_info qi;
1410 struct smb_query_info __user *pqi;
1412 int flags = CIFS_CP_CREATE_CLOSE_OP;
1413 struct smb2_query_info_rsp *qi_rsp = NULL;
1414 struct smb2_ioctl_rsp *io_rsp = NULL;
1415 void *buffer = NULL;
1416 int resp_buftype[3];
1417 struct cifs_open_parms oparms;
1418 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1419 struct cifs_fid fid;
1420 unsigned int size[2];
1422 int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR;
1423 void (*free_req1_func)(struct smb_rqst *r);
1425 vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
1428 rqst = &vars->rqst[0];
1429 rsp_iov = &vars->rsp_iov[0];
1431 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1433 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info))) {
1437 if (qi.output_buffer_length > 1024) {
1442 if (!ses || !server) {
1447 if (smb3_encryption_required(tcon))
1448 flags |= CIFS_TRANSFORM_REQ;
1450 if (qi.output_buffer_length) {
1451 buffer = memdup_user(arg + sizeof(struct smb_query_info), qi.output_buffer_length);
1452 if (IS_ERR(buffer)) {
1453 rc = PTR_ERR(buffer);
1459 rqst[0].rq_iov = &vars->open_iov[0];
1460 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1462 oparms = (struct cifs_open_parms) {
1464 .disposition = FILE_OPEN,
1465 .create_options = cifs_create_options(cifs_sb, create_options),
1469 if (qi.flags & PASSTHRU_FSCTL) {
1470 switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1471 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1472 oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1474 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1475 oparms.desired_access = GENERIC_ALL;
1477 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1478 oparms.desired_access = GENERIC_READ;
1480 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1481 oparms.desired_access = GENERIC_WRITE;
1484 } else if (qi.flags & PASSTHRU_SET_INFO) {
1485 oparms.desired_access = GENERIC_WRITE;
1487 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1490 rc = SMB2_open_init(tcon, server,
1491 &rqst[0], &oplock, &oparms, path);
1493 goto free_output_buffer;
1494 smb2_set_next_command(tcon, &rqst[0]);
1497 if (qi.flags & PASSTHRU_FSCTL) {
1498 /* Can eventually relax perm check since server enforces too */
1499 if (!capable(CAP_SYS_ADMIN)) {
1503 rqst[1].rq_iov = &vars->io_iov[0];
1504 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1506 rc = SMB2_ioctl_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1507 qi.info_type, buffer, qi.output_buffer_length,
1508 CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1509 MAX_SMB2_CLOSE_RESPONSE_SIZE);
1510 free_req1_func = SMB2_ioctl_free;
1511 } else if (qi.flags == PASSTHRU_SET_INFO) {
1512 /* Can eventually relax perm check since server enforces too */
1513 if (!capable(CAP_SYS_ADMIN)) {
1517 if (qi.output_buffer_length < 8) {
1521 rqst[1].rq_iov = &vars->si_iov[0];
1522 rqst[1].rq_nvec = 1;
1524 /* MS-FSCC 2.4.13 FileEndOfFileInformation */
1528 rc = SMB2_set_info_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1529 current->tgid, FILE_END_OF_FILE_INFORMATION,
1530 SMB2_O_INFO_FILE, 0, data, size);
1531 free_req1_func = SMB2_set_info_free;
1532 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1533 rqst[1].rq_iov = &vars->qi_iov[0];
1534 rqst[1].rq_nvec = 1;
1536 rc = SMB2_query_info_init(tcon, server,
1537 &rqst[1], COMPOUND_FID,
1538 COMPOUND_FID, qi.file_info_class,
1539 qi.info_type, qi.additional_information,
1540 qi.input_buffer_length,
1541 qi.output_buffer_length, buffer);
1542 free_req1_func = SMB2_query_info_free;
1543 } else { /* unknown flags */
1544 cifs_tcon_dbg(VFS, "Invalid passthru query flags: 0x%x\n",
1551 smb2_set_next_command(tcon, &rqst[1]);
1552 smb2_set_related(&rqst[1]);
1555 rqst[2].rq_iov = &vars->close_iov[0];
1556 rqst[2].rq_nvec = 1;
1558 rc = SMB2_close_init(tcon, server,
1559 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1562 smb2_set_related(&rqst[2]);
1564 rc = compound_send_recv(xid, ses, server,
1566 resp_buftype, rsp_iov);
1570 /* No need to bump num_remote_opens since handle immediately closed */
1571 if (qi.flags & PASSTHRU_FSCTL) {
1572 pqi = (struct smb_query_info __user *)arg;
1573 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1574 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1575 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1576 if (qi.input_buffer_length > 0 &&
1577 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length
1578 > rsp_iov[1].iov_len) {
1583 if (copy_to_user(&pqi->input_buffer_length,
1584 &qi.input_buffer_length,
1585 sizeof(qi.input_buffer_length))) {
1590 if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1591 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1592 qi.input_buffer_length))
1595 pqi = (struct smb_query_info __user *)arg;
1596 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1597 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1598 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1599 if (copy_to_user(&pqi->input_buffer_length,
1600 &qi.input_buffer_length,
1601 sizeof(qi.input_buffer_length))) {
1606 if (copy_to_user(pqi + 1, qi_rsp->Buffer,
1607 qi.input_buffer_length))
1612 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1613 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1614 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1615 SMB2_close_free(&rqst[2]);
1617 free_req1_func(&rqst[1]);
1619 SMB2_open_free(&rqst[0]);
1628 smb2_copychunk_range(const unsigned int xid,
1629 struct cifsFileInfo *srcfile,
1630 struct cifsFileInfo *trgtfile, u64 src_off,
1631 u64 len, u64 dest_off)
1634 unsigned int ret_data_len;
1635 struct copychunk_ioctl *pcchunk;
1636 struct copychunk_ioctl_rsp *retbuf = NULL;
1637 struct cifs_tcon *tcon;
1638 int chunks_copied = 0;
1639 bool chunk_sizes_updated = false;
1640 ssize_t bytes_written, total_bytes_written = 0;
1642 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1643 if (pcchunk == NULL)
1646 cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
1647 /* Request a key from the server to identify the source of the copy */
1648 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1649 srcfile->fid.persistent_fid,
1650 srcfile->fid.volatile_fid, pcchunk);
1652 /* Note: request_res_key sets res_key null only if rc !=0 */
1656 /* For now array only one chunk long, will make more flexible later */
1657 pcchunk->ChunkCount = cpu_to_le32(1);
1658 pcchunk->Reserved = 0;
1659 pcchunk->Reserved2 = 0;
1661 tcon = tlink_tcon(trgtfile->tlink);
1664 pcchunk->SourceOffset = cpu_to_le64(src_off);
1665 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1667 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
1669 /* Request server copy to target from src identified by key */
1672 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1673 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1674 (char *)pcchunk, sizeof(struct copychunk_ioctl),
1675 CIFSMaxBufSize, (char **)&retbuf, &ret_data_len);
1678 sizeof(struct copychunk_ioctl_rsp)) {
1679 cifs_tcon_dbg(VFS, "Invalid cchunk response size\n");
1683 if (retbuf->TotalBytesWritten == 0) {
1684 cifs_dbg(FYI, "no bytes copied\n");
1689 * Check if server claimed to write more than we asked
1691 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1692 le32_to_cpu(pcchunk->Length)) {
1693 cifs_tcon_dbg(VFS, "Invalid copy chunk response\n");
1697 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1698 cifs_tcon_dbg(VFS, "Invalid num chunks written\n");
1704 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1705 src_off += bytes_written;
1706 dest_off += bytes_written;
1707 len -= bytes_written;
1708 total_bytes_written += bytes_written;
1710 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1711 le32_to_cpu(retbuf->ChunksWritten),
1712 le32_to_cpu(retbuf->ChunkBytesWritten),
1714 } else if (rc == -EINVAL) {
1715 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1718 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1719 le32_to_cpu(retbuf->ChunksWritten),
1720 le32_to_cpu(retbuf->ChunkBytesWritten),
1721 le32_to_cpu(retbuf->TotalBytesWritten));
1724 * Check if this is the first request using these sizes,
1725 * (ie check if copy succeed once with original sizes
1726 * and check if the server gave us different sizes after
1727 * we already updated max sizes on previous request).
1728 * if not then why is the server returning an error now
1730 if ((chunks_copied != 0) || chunk_sizes_updated)
1733 /* Check that server is not asking us to grow size */
1734 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1735 tcon->max_bytes_chunk)
1736 tcon->max_bytes_chunk =
1737 le32_to_cpu(retbuf->ChunkBytesWritten);
1739 goto cchunk_out; /* server gave us bogus size */
1741 /* No need to change MaxChunks since already set to 1 */
1742 chunk_sizes_updated = true;
1753 return total_bytes_written;
1757 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1758 struct cifs_fid *fid)
1760 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1764 smb2_read_data_offset(char *buf)
1766 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1768 return rsp->DataOffset;
1772 smb2_read_data_length(char *buf, bool in_remaining)
1774 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1777 return le32_to_cpu(rsp->DataRemaining);
1779 return le32_to_cpu(rsp->DataLength);
1784 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1785 struct cifs_io_parms *parms, unsigned int *bytes_read,
1786 char **buf, int *buf_type)
1788 parms->persistent_fid = pfid->persistent_fid;
1789 parms->volatile_fid = pfid->volatile_fid;
1790 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1794 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1795 struct cifs_io_parms *parms, unsigned int *written,
1796 struct kvec *iov, unsigned long nr_segs)
1799 parms->persistent_fid = pfid->persistent_fid;
1800 parms->volatile_fid = pfid->volatile_fid;
1801 return SMB2_write(xid, parms, written, iov, nr_segs);
1804 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1805 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1806 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1808 struct cifsInodeInfo *cifsi;
1811 cifsi = CIFS_I(inode);
1813 /* if file already sparse don't bother setting sparse again */
1814 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1815 return true; /* already sparse */
1817 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1818 return true; /* already not sparse */
1821 * Can't check for sparse support on share the usual way via the
1822 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1823 * since Samba server doesn't set the flag on the share, yet
1824 * supports the set sparse FSCTL and returns sparse correctly
1825 * in the file attributes. If we fail setting sparse though we
1826 * mark that server does not support sparse files for this share
1827 * to avoid repeatedly sending the unsupported fsctl to server
1828 * if the file is repeatedly extended.
1830 if (tcon->broken_sparse_sup)
1833 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1834 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1835 &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
1837 tcon->broken_sparse_sup = true;
1838 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1843 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1845 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1851 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1852 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1854 __le64 eof = cpu_to_le64(size);
1855 struct inode *inode;
1858 * If extending file more than one page make sparse. Many Linux fs
1859 * make files sparse by default when extending via ftruncate
1861 inode = d_inode(cfile->dentry);
1863 if (!set_alloc && (size > inode->i_size + 8192)) {
1864 __u8 set_sparse = 1;
1866 /* whether set sparse succeeds or not, extend the file */
1867 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1870 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1871 cfile->fid.volatile_fid, cfile->pid, &eof);
1875 smb2_duplicate_extents(const unsigned int xid,
1876 struct cifsFileInfo *srcfile,
1877 struct cifsFileInfo *trgtfile, u64 src_off,
1878 u64 len, u64 dest_off)
1881 unsigned int ret_data_len;
1882 struct inode *inode;
1883 struct duplicate_extents_to_file dup_ext_buf;
1884 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1886 /* server fileays advertise duplicate extent support with this flag */
1887 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1888 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1891 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1892 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1893 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1894 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1895 dup_ext_buf.ByteCount = cpu_to_le64(len);
1896 cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
1897 src_off, dest_off, len);
1899 inode = d_inode(trgtfile->dentry);
1900 if (inode->i_size < dest_off + len) {
1901 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1903 goto duplicate_extents_out;
1906 * Although also could set plausible allocation size (i_blocks)
1907 * here in addition to setting the file size, in reflink
1908 * it is likely that the target file is sparse. Its allocation
1909 * size will be queried on next revalidate, but it is important
1910 * to make sure that file's cached size is updated immediately
1912 cifs_setsize(inode, dest_off + len);
1914 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1915 trgtfile->fid.volatile_fid,
1916 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1917 (char *)&dup_ext_buf,
1918 sizeof(struct duplicate_extents_to_file),
1919 CIFSMaxBufSize, NULL,
1922 if (ret_data_len > 0)
1923 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
1925 duplicate_extents_out:
1930 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1931 struct cifsFileInfo *cfile)
1933 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1934 cfile->fid.volatile_fid);
1938 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
1939 struct cifsFileInfo *cfile)
1941 struct fsctl_set_integrity_information_req integr_info;
1942 unsigned int ret_data_len;
1944 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
1945 integr_info.Flags = 0;
1946 integr_info.Reserved = 0;
1948 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1949 cfile->fid.volatile_fid,
1950 FSCTL_SET_INTEGRITY_INFORMATION,
1951 (char *)&integr_info,
1952 sizeof(struct fsctl_set_integrity_information_req),
1953 CIFSMaxBufSize, NULL,
1958 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
1959 #define GMT_TOKEN_SIZE 50
1961 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
1964 * Input buffer contains (empty) struct smb_snapshot array with size filled in
1965 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
1968 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
1969 struct cifsFileInfo *cfile, void __user *ioc_buf)
1971 char *retbuf = NULL;
1972 unsigned int ret_data_len = 0;
1974 u32 max_response_size;
1975 struct smb_snapshot_array snapshot_in;
1978 * On the first query to enumerate the list of snapshots available
1979 * for this volume the buffer begins with 0 (number of snapshots
1980 * which can be returned is zero since at that point we do not know
1981 * how big the buffer needs to be). On the second query,
1982 * it (ret_data_len) is set to number of snapshots so we can
1983 * know to set the maximum response size larger (see below).
1985 if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
1989 * Note that for snapshot queries that servers like Azure expect that
1990 * the first query be minimal size (and just used to get the number/size
1991 * of previous versions) so response size must be specified as EXACTLY
1992 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
1995 if (ret_data_len == 0)
1996 max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
1998 max_response_size = CIFSMaxBufSize;
2000 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2001 cfile->fid.volatile_fid,
2002 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
2003 NULL, 0 /* no input data */, max_response_size,
2006 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
2011 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
2013 if (copy_from_user(&snapshot_in, ioc_buf,
2014 sizeof(struct smb_snapshot_array))) {
2021 * Check for min size, ie not large enough to fit even one GMT
2022 * token (snapshot). On the first ioctl some users may pass in
2023 * smaller size (or zero) to simply get the size of the array
2024 * so the user space caller can allocate sufficient memory
2025 * and retry the ioctl again with larger array size sufficient
2026 * to hold all of the snapshot GMT tokens on the second try.
2028 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
2029 ret_data_len = sizeof(struct smb_snapshot_array);
2032 * We return struct SRV_SNAPSHOT_ARRAY, followed by
2033 * the snapshot array (of 50 byte GMT tokens) each
2034 * representing an available previous version of the data
2036 if (ret_data_len > (snapshot_in.snapshot_array_size +
2037 sizeof(struct smb_snapshot_array)))
2038 ret_data_len = snapshot_in.snapshot_array_size +
2039 sizeof(struct smb_snapshot_array);
2041 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
2052 smb3_notify(const unsigned int xid, struct file *pfile,
2053 void __user *ioc_buf, bool return_changes)
2055 struct smb3_notify_info notify;
2056 struct smb3_notify_info __user *pnotify_buf;
2057 struct dentry *dentry = pfile->f_path.dentry;
2058 struct inode *inode = file_inode(pfile);
2059 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2060 struct cifs_open_parms oparms;
2061 struct cifs_fid fid;
2062 struct cifs_tcon *tcon;
2063 const unsigned char *path;
2064 char *returned_ioctl_info = NULL;
2065 void *page = alloc_dentry_path();
2066 __le16 *utf16_path = NULL;
2067 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2071 path = build_path_from_dentry(dentry, page);
2077 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2078 if (utf16_path == NULL) {
2083 if (return_changes) {
2084 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify_info))) {
2089 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify))) {
2093 notify.data_len = 0;
2096 tcon = cifs_sb_master_tcon(cifs_sb);
2097 oparms = (struct cifs_open_parms) {
2099 .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
2100 .disposition = FILE_OPEN,
2101 .create_options = cifs_create_options(cifs_sb, 0),
2105 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
2110 rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid,
2111 notify.watch_tree, notify.completion_filter,
2112 notify.data_len, &returned_ioctl_info, &ret_len);
2114 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2116 cifs_dbg(FYI, "change notify for path %s rc %d\n", path, rc);
2117 if (return_changes && (ret_len > 0) && (notify.data_len > 0)) {
2118 if (ret_len > notify.data_len)
2119 ret_len = notify.data_len;
2120 pnotify_buf = (struct smb3_notify_info __user *)ioc_buf;
2121 if (copy_to_user(pnotify_buf->notify_data, returned_ioctl_info, ret_len))
2123 else if (copy_to_user(&pnotify_buf->data_len, &ret_len, sizeof(ret_len)))
2126 kfree(returned_ioctl_info);
2128 free_dentry_path(page);
2134 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
2135 const char *path, struct cifs_sb_info *cifs_sb,
2136 struct cifs_fid *fid, __u16 search_flags,
2137 struct cifs_search_info *srch_inf)
2140 struct smb_rqst rqst[2];
2141 struct kvec rsp_iov[2];
2142 int resp_buftype[2];
2143 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2144 struct kvec qd_iov[SMB2_QUERY_DIRECTORY_IOV_SIZE];
2146 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2147 struct cifs_open_parms oparms;
2148 struct smb2_query_directory_rsp *qd_rsp = NULL;
2149 struct smb2_create_rsp *op_rsp = NULL;
2150 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2151 int retry_count = 0;
2153 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2157 if (smb3_encryption_required(tcon))
2158 flags |= CIFS_TRANSFORM_REQ;
2160 memset(rqst, 0, sizeof(rqst));
2161 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
2162 memset(rsp_iov, 0, sizeof(rsp_iov));
2165 memset(&open_iov, 0, sizeof(open_iov));
2166 rqst[0].rq_iov = open_iov;
2167 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2169 oparms = (struct cifs_open_parms) {
2171 .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
2172 .disposition = FILE_OPEN,
2173 .create_options = cifs_create_options(cifs_sb, 0),
2177 rc = SMB2_open_init(tcon, server,
2178 &rqst[0], &oplock, &oparms, utf16_path);
2181 smb2_set_next_command(tcon, &rqst[0]);
2183 /* Query directory */
2184 srch_inf->entries_in_buffer = 0;
2185 srch_inf->index_of_last_entry = 2;
2187 memset(&qd_iov, 0, sizeof(qd_iov));
2188 rqst[1].rq_iov = qd_iov;
2189 rqst[1].rq_nvec = SMB2_QUERY_DIRECTORY_IOV_SIZE;
2191 rc = SMB2_query_directory_init(xid, tcon, server,
2193 COMPOUND_FID, COMPOUND_FID,
2194 0, srch_inf->info_level);
2198 smb2_set_related(&rqst[1]);
2201 rc = compound_send_recv(xid, tcon->ses, server,
2203 resp_buftype, rsp_iov);
2205 if (rc == -EAGAIN && retry_count++ < 10)
2208 /* If the open failed there is nothing to do */
2209 op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
2210 if (op_rsp == NULL || op_rsp->hdr.Status != STATUS_SUCCESS) {
2211 cifs_dbg(FYI, "query_dir_first: open failed rc=%d\n", rc);
2214 fid->persistent_fid = op_rsp->PersistentFileId;
2215 fid->volatile_fid = op_rsp->VolatileFileId;
2217 /* Anything else than ENODATA means a genuine error */
2218 if (rc && rc != -ENODATA) {
2219 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2220 cifs_dbg(FYI, "query_dir_first: query directory failed rc=%d\n", rc);
2221 trace_smb3_query_dir_err(xid, fid->persistent_fid,
2222 tcon->tid, tcon->ses->Suid, 0, 0, rc);
2226 atomic_inc(&tcon->num_remote_opens);
2228 qd_rsp = (struct smb2_query_directory_rsp *)rsp_iov[1].iov_base;
2229 if (qd_rsp->hdr.Status == STATUS_NO_MORE_FILES) {
2230 trace_smb3_query_dir_done(xid, fid->persistent_fid,
2231 tcon->tid, tcon->ses->Suid, 0, 0);
2232 srch_inf->endOfSearch = true;
2237 rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1],
2240 trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid,
2241 tcon->ses->Suid, 0, 0, rc);
2244 resp_buftype[1] = CIFS_NO_BUFFER;
2246 trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid,
2247 tcon->ses->Suid, 0, srch_inf->entries_in_buffer);
2251 SMB2_open_free(&rqst[0]);
2252 SMB2_query_directory_free(&rqst[1]);
2253 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2254 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2259 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
2260 struct cifs_fid *fid, __u16 search_flags,
2261 struct cifs_search_info *srch_inf)
2263 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
2264 fid->volatile_fid, 0, srch_inf);
2268 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
2269 struct cifs_fid *fid)
2271 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2275 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2276 * the number of credits and return true. Otherwise - return false.
2279 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
2281 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2282 int scredits, in_flight;
2284 if (shdr->Status != STATUS_PENDING)
2287 if (shdr->CreditRequest) {
2288 spin_lock(&server->req_lock);
2289 server->credits += le16_to_cpu(shdr->CreditRequest);
2290 scredits = server->credits;
2291 in_flight = server->in_flight;
2292 spin_unlock(&server->req_lock);
2293 wake_up(&server->request_q);
2295 trace_smb3_pend_credits(server->CurrentMid,
2296 server->conn_id, server->hostname, scredits,
2297 le16_to_cpu(shdr->CreditRequest), in_flight);
2298 cifs_dbg(FYI, "%s: status pending add %u credits total=%d\n",
2299 __func__, le16_to_cpu(shdr->CreditRequest), scredits);
2306 smb2_is_session_expired(char *buf)
2308 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2310 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
2311 shdr->Status != STATUS_USER_SESSION_DELETED)
2314 trace_smb3_ses_expired(le32_to_cpu(shdr->Id.SyncId.TreeId),
2315 le64_to_cpu(shdr->SessionId),
2316 le16_to_cpu(shdr->Command),
2317 le64_to_cpu(shdr->MessageId));
2318 cifs_dbg(FYI, "Session expired or deleted\n");
2324 smb2_is_status_io_timeout(char *buf)
2326 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2328 if (shdr->Status == STATUS_IO_TIMEOUT)
2335 smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server)
2337 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2338 struct TCP_Server_Info *pserver;
2339 struct cifs_ses *ses;
2340 struct cifs_tcon *tcon;
2342 if (shdr->Status != STATUS_NETWORK_NAME_DELETED)
2345 /* If server is a channel, select the primary channel */
2346 pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
2348 spin_lock(&cifs_tcp_ses_lock);
2349 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
2350 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
2351 if (tcon->tid == le32_to_cpu(shdr->Id.SyncId.TreeId)) {
2352 spin_lock(&tcon->tc_lock);
2353 tcon->need_reconnect = true;
2354 spin_unlock(&tcon->tc_lock);
2355 spin_unlock(&cifs_tcp_ses_lock);
2356 pr_warn_once("Server share %s deleted.\n",
2362 spin_unlock(&cifs_tcp_ses_lock);
2366 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
2367 struct cifsInodeInfo *cinode)
2369 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
2370 return SMB2_lease_break(0, tcon, cinode->lease_key,
2371 smb2_get_lease_state(cinode));
2373 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
2375 CIFS_CACHE_READ(cinode) ? 1 : 0);
2379 smb2_set_related(struct smb_rqst *rqst)
2381 struct smb2_hdr *shdr;
2383 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2385 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2388 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2391 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
2394 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
2396 struct smb2_hdr *shdr;
2397 struct cifs_ses *ses = tcon->ses;
2398 struct TCP_Server_Info *server = ses->server;
2399 unsigned long len = smb_rqst_len(server, rqst);
2402 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2404 cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2408 /* SMB headers in a compound are 8 byte aligned. */
2410 /* No padding needed */
2414 num_padding = 8 - (len & 7);
2415 if (!smb3_encryption_required(tcon)) {
2417 * If we do not have encryption then we can just add an extra
2418 * iov for the padding.
2420 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2421 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2426 * We can not add a small padding iov for the encryption case
2427 * because the encryption framework can not handle the padding
2429 * We have to flatten this into a single buffer and add
2430 * the padding to it.
2432 for (i = 1; i < rqst->rq_nvec; i++) {
2433 memcpy(rqst->rq_iov[0].iov_base +
2434 rqst->rq_iov[0].iov_len,
2435 rqst->rq_iov[i].iov_base,
2436 rqst->rq_iov[i].iov_len);
2437 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2439 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2441 rqst->rq_iov[0].iov_len += num_padding;
2447 shdr->NextCommand = cpu_to_le32(len);
2451 * Passes the query info response back to the caller on success.
2452 * Caller need to free this with free_rsp_buf().
2455 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2456 const char *path, u32 desired_access,
2457 u32 class, u32 type, u32 output_len,
2458 struct kvec *rsp, int *buftype,
2459 struct cifs_sb_info *cifs_sb)
2461 struct cifs_ses *ses = tcon->ses;
2462 struct TCP_Server_Info *server = cifs_pick_channel(ses);
2463 int flags = CIFS_CP_CREATE_CLOSE_OP;
2464 struct smb_rqst rqst[3];
2465 int resp_buftype[3];
2466 struct kvec rsp_iov[3];
2467 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2468 struct kvec qi_iov[1];
2469 struct kvec close_iov[1];
2470 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2471 struct cifs_open_parms oparms;
2472 struct cifs_fid fid;
2475 struct cached_fid *cfid = NULL;
2479 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2483 if (smb3_encryption_required(tcon))
2484 flags |= CIFS_TRANSFORM_REQ;
2486 memset(rqst, 0, sizeof(rqst));
2487 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2488 memset(rsp_iov, 0, sizeof(rsp_iov));
2491 * We can only call this for things we know are directories.
2493 if (!strcmp(path, ""))
2494 open_cached_dir(xid, tcon, path, cifs_sb, false,
2495 &cfid); /* cfid null if open dir failed */
2497 memset(&open_iov, 0, sizeof(open_iov));
2498 rqst[0].rq_iov = open_iov;
2499 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2501 oparms = (struct cifs_open_parms) {
2503 .desired_access = desired_access,
2504 .disposition = FILE_OPEN,
2505 .create_options = cifs_create_options(cifs_sb, 0),
2509 rc = SMB2_open_init(tcon, server,
2510 &rqst[0], &oplock, &oparms, utf16_path);
2513 smb2_set_next_command(tcon, &rqst[0]);
2515 memset(&qi_iov, 0, sizeof(qi_iov));
2516 rqst[1].rq_iov = qi_iov;
2517 rqst[1].rq_nvec = 1;
2520 rc = SMB2_query_info_init(tcon, server,
2522 cfid->fid.persistent_fid,
2523 cfid->fid.volatile_fid,
2528 rc = SMB2_query_info_init(tcon, server,
2539 smb2_set_next_command(tcon, &rqst[1]);
2540 smb2_set_related(&rqst[1]);
2543 memset(&close_iov, 0, sizeof(close_iov));
2544 rqst[2].rq_iov = close_iov;
2545 rqst[2].rq_nvec = 1;
2547 rc = SMB2_close_init(tcon, server,
2548 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2551 smb2_set_related(&rqst[2]);
2554 rc = compound_send_recv(xid, ses, server,
2556 &resp_buftype[1], &rsp_iov[1]);
2558 rc = compound_send_recv(xid, ses, server,
2560 resp_buftype, rsp_iov);
2563 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2564 if (rc == -EREMCHG) {
2565 tcon->need_reconnect = true;
2566 pr_warn_once("server share %s deleted\n",
2572 *buftype = resp_buftype[1];
2576 SMB2_open_free(&rqst[0]);
2577 SMB2_query_info_free(&rqst[1]);
2578 SMB2_close_free(&rqst[2]);
2579 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2580 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2582 close_cached_dir(cfid);
2587 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2588 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2590 struct smb2_query_info_rsp *rsp;
2591 struct smb2_fs_full_size_info *info = NULL;
2592 struct kvec rsp_iov = {NULL, 0};
2593 int buftype = CIFS_NO_BUFFER;
2597 rc = smb2_query_info_compound(xid, tcon, "",
2598 FILE_READ_ATTRIBUTES,
2599 FS_FULL_SIZE_INFORMATION,
2600 SMB2_O_INFO_FILESYSTEM,
2601 sizeof(struct smb2_fs_full_size_info),
2602 &rsp_iov, &buftype, cifs_sb);
2606 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2607 buf->f_type = SMB2_SUPER_MAGIC;
2608 info = (struct smb2_fs_full_size_info *)(
2609 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2610 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2611 le32_to_cpu(rsp->OutputBufferLength),
2613 sizeof(struct smb2_fs_full_size_info));
2615 smb2_copy_fs_info_to_kstatfs(info, buf);
2618 free_rsp_buf(buftype, rsp_iov.iov_base);
2623 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2624 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2627 __le16 srch_path = 0; /* Null - open root of share */
2628 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2629 struct cifs_open_parms oparms;
2630 struct cifs_fid fid;
2632 if (!tcon->posix_extensions)
2633 return smb2_queryfs(xid, tcon, cifs_sb, buf);
2635 oparms = (struct cifs_open_parms) {
2637 .desired_access = FILE_READ_ATTRIBUTES,
2638 .disposition = FILE_OPEN,
2639 .create_options = cifs_create_options(cifs_sb, 0),
2643 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
2648 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2649 fid.volatile_fid, buf);
2650 buf->f_type = SMB2_SUPER_MAGIC;
2651 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2656 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2658 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2659 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2663 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2664 __u64 length, __u32 type, int lock, int unlock, bool wait)
2666 if (unlock && !lock)
2667 type = SMB2_LOCKFLAG_UNLOCK;
2668 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2669 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2670 current->tgid, length, offset, type, wait);
2674 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2676 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2680 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2682 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2686 smb2_new_lease_key(struct cifs_fid *fid)
2688 generate_random_uuid(fid->lease_key);
2692 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2693 const char *search_name,
2694 struct dfs_info3_param **target_nodes,
2695 unsigned int *num_of_nodes,
2696 const struct nls_table *nls_codepage, int remap)
2699 __le16 *utf16_path = NULL;
2700 int utf16_path_len = 0;
2701 struct cifs_tcon *tcon;
2702 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2703 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2704 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2705 int retry_count = 0;
2707 cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name);
2710 * Try to use the IPC tcon, otherwise just use any
2712 tcon = ses->tcon_ipc;
2714 spin_lock(&cifs_tcp_ses_lock);
2715 tcon = list_first_entry_or_null(&ses->tcon_list,
2720 spin_unlock(&cifs_tcp_ses_lock);
2724 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2730 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2732 nls_codepage, remap);
2738 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2739 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2745 /* Highest DFS referral version understood */
2746 dfs_req->MaxReferralLevel = DFS_VERSION;
2748 /* Path to resolve in an UTF-16 null-terminated string */
2749 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2752 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2753 FSCTL_DFS_GET_REFERRALS,
2754 (char *)dfs_req, dfs_req_size, CIFSMaxBufSize,
2755 (char **)&dfs_rsp, &dfs_rsp_size);
2756 if (!is_retryable_error(rc))
2758 usleep_range(512, 2048);
2759 } while (++retry_count < 5);
2762 if (!is_retryable_error(rc) && rc != -ENOENT && rc != -EOPNOTSUPP)
2763 cifs_tcon_dbg(VFS, "%s: ioctl error: rc=%d\n", __func__, rc);
2767 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
2768 num_of_nodes, target_nodes,
2769 nls_codepage, remap, search_name,
2770 true /* is_unicode */);
2772 cifs_tcon_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc);
2777 if (tcon && !tcon->ipc) {
2778 /* ipc tcons are not refcounted */
2779 spin_lock(&cifs_tcp_ses_lock);
2781 /* tc_count can never go negative */
2782 WARN_ON(tcon->tc_count < 0);
2783 spin_unlock(&cifs_tcp_ses_lock);
2792 parse_reparse_posix(struct reparse_posix_data *symlink_buf,
2793 u32 plen, char **target_path,
2794 struct cifs_sb_info *cifs_sb)
2798 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
2799 len = le16_to_cpu(symlink_buf->ReparseDataLength);
2801 if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
2802 cifs_dbg(VFS, "%lld not a supported symlink type\n",
2803 le64_to_cpu(symlink_buf->InodeType));
2807 *target_path = cifs_strndup_from_utf16(
2808 symlink_buf->PathBuffer,
2809 len, true, cifs_sb->local_nls);
2810 if (!(*target_path))
2813 convert_delimiter(*target_path, '/');
2814 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2820 parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
2821 u32 plen, char **target_path,
2822 struct cifs_sb_info *cifs_sb)
2824 unsigned int sub_len;
2825 unsigned int sub_offset;
2827 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */
2829 sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset);
2830 sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength);
2831 if (sub_offset + 20 > plen ||
2832 sub_offset + sub_len + 20 > plen) {
2833 cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
2837 *target_path = cifs_strndup_from_utf16(
2838 symlink_buf->PathBuffer + sub_offset,
2839 sub_len, true, cifs_sb->local_nls);
2840 if (!(*target_path))
2843 convert_delimiter(*target_path, '/');
2844 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2850 parse_reparse_point(struct reparse_data_buffer *buf,
2851 u32 plen, char **target_path,
2852 struct cifs_sb_info *cifs_sb)
2854 if (plen < sizeof(struct reparse_data_buffer)) {
2855 cifs_dbg(VFS, "reparse buffer is too small. Must be at least 8 bytes but was %d\n",
2860 if (plen < le16_to_cpu(buf->ReparseDataLength) +
2861 sizeof(struct reparse_data_buffer)) {
2862 cifs_dbg(VFS, "srv returned invalid reparse buf length: %d\n",
2867 /* See MS-FSCC 2.1.2 */
2868 switch (le32_to_cpu(buf->ReparseTag)) {
2869 case IO_REPARSE_TAG_NFS:
2870 return parse_reparse_posix(
2871 (struct reparse_posix_data *)buf,
2872 plen, target_path, cifs_sb);
2873 case IO_REPARSE_TAG_SYMLINK:
2874 return parse_reparse_symlink(
2875 (struct reparse_symlink_data_buffer *)buf,
2876 plen, target_path, cifs_sb);
2878 cifs_dbg(VFS, "srv returned unknown symlink buffer tag:0x%08x\n",
2879 le32_to_cpu(buf->ReparseTag));
2885 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
2886 struct cifs_sb_info *cifs_sb, const char *full_path,
2887 char **target_path, bool is_reparse_point)
2890 __le16 *utf16_path = NULL;
2891 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2892 struct cifs_open_parms oparms;
2893 struct cifs_fid fid;
2894 struct kvec err_iov = {NULL, 0};
2895 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2896 int flags = CIFS_CP_CREATE_CLOSE_OP;
2897 struct smb_rqst rqst[3];
2898 int resp_buftype[3];
2899 struct kvec rsp_iov[3];
2900 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2901 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2902 struct kvec close_iov[1];
2903 struct smb2_create_rsp *create_rsp;
2904 struct smb2_ioctl_rsp *ioctl_rsp;
2905 struct reparse_data_buffer *reparse_buf;
2906 int create_options = is_reparse_point ? OPEN_REPARSE_POINT : 0;
2909 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2911 *target_path = NULL;
2913 if (smb3_encryption_required(tcon))
2914 flags |= CIFS_TRANSFORM_REQ;
2916 memset(rqst, 0, sizeof(rqst));
2917 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2918 memset(rsp_iov, 0, sizeof(rsp_iov));
2920 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
2925 memset(&open_iov, 0, sizeof(open_iov));
2926 rqst[0].rq_iov = open_iov;
2927 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2929 oparms = (struct cifs_open_parms) {
2931 .desired_access = FILE_READ_ATTRIBUTES,
2932 .disposition = FILE_OPEN,
2933 .create_options = cifs_create_options(cifs_sb, create_options),
2937 rc = SMB2_open_init(tcon, server,
2938 &rqst[0], &oplock, &oparms, utf16_path);
2941 smb2_set_next_command(tcon, &rqst[0]);
2945 memset(&io_iov, 0, sizeof(io_iov));
2946 rqst[1].rq_iov = io_iov;
2947 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
2949 rc = SMB2_ioctl_init(tcon, server,
2950 &rqst[1], fid.persistent_fid,
2951 fid.volatile_fid, FSCTL_GET_REPARSE_POINT, NULL, 0,
2953 MAX_SMB2_CREATE_RESPONSE_SIZE -
2954 MAX_SMB2_CLOSE_RESPONSE_SIZE);
2958 smb2_set_next_command(tcon, &rqst[1]);
2959 smb2_set_related(&rqst[1]);
2963 memset(&close_iov, 0, sizeof(close_iov));
2964 rqst[2].rq_iov = close_iov;
2965 rqst[2].rq_nvec = 1;
2967 rc = SMB2_close_init(tcon, server,
2968 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2972 smb2_set_related(&rqst[2]);
2974 rc = compound_send_recv(xid, tcon->ses, server,
2976 resp_buftype, rsp_iov);
2978 create_rsp = rsp_iov[0].iov_base;
2979 if (create_rsp && create_rsp->hdr.Status)
2980 err_iov = rsp_iov[0];
2981 ioctl_rsp = rsp_iov[1].iov_base;
2984 * Open was successful and we got an ioctl response.
2986 if ((rc == 0) && (is_reparse_point)) {
2987 /* See MS-FSCC 2.3.23 */
2989 reparse_buf = (struct reparse_data_buffer *)
2990 ((char *)ioctl_rsp +
2991 le32_to_cpu(ioctl_rsp->OutputOffset));
2992 plen = le32_to_cpu(ioctl_rsp->OutputCount);
2994 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
2995 rsp_iov[1].iov_len) {
2996 cifs_tcon_dbg(VFS, "srv returned invalid ioctl len: %d\n",
3002 rc = parse_reparse_point(reparse_buf, plen, target_path,
3007 if (!rc || !err_iov.iov_base) {
3012 rc = smb2_parse_symlink_response(cifs_sb, &err_iov, target_path);
3015 cifs_dbg(FYI, "query symlink rc %d\n", rc);
3017 SMB2_open_free(&rqst[0]);
3018 SMB2_ioctl_free(&rqst[1]);
3019 SMB2_close_free(&rqst[2]);
3020 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3021 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3022 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3027 smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
3028 struct cifs_sb_info *cifs_sb, const char *full_path,
3032 __le16 *utf16_path = NULL;
3033 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3034 struct cifs_open_parms oparms;
3035 struct cifs_fid fid;
3036 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
3037 int flags = CIFS_CP_CREATE_CLOSE_OP;
3038 struct smb_rqst rqst[3];
3039 int resp_buftype[3];
3040 struct kvec rsp_iov[3];
3041 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
3042 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
3043 struct kvec close_iov[1];
3044 struct smb2_ioctl_rsp *ioctl_rsp;
3045 struct reparse_data_buffer *reparse_buf;
3048 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
3050 if (smb3_encryption_required(tcon))
3051 flags |= CIFS_TRANSFORM_REQ;
3053 memset(rqst, 0, sizeof(rqst));
3054 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
3055 memset(rsp_iov, 0, sizeof(rsp_iov));
3057 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
3062 * setup smb2open - TODO add optimization to call cifs_get_readable_path
3063 * to see if there is a handle already open that we can use
3065 memset(&open_iov, 0, sizeof(open_iov));
3066 rqst[0].rq_iov = open_iov;
3067 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
3069 oparms = (struct cifs_open_parms) {
3071 .desired_access = FILE_READ_ATTRIBUTES,
3072 .disposition = FILE_OPEN,
3073 .create_options = cifs_create_options(cifs_sb, OPEN_REPARSE_POINT),
3077 rc = SMB2_open_init(tcon, server,
3078 &rqst[0], &oplock, &oparms, utf16_path);
3081 smb2_set_next_command(tcon, &rqst[0]);
3085 memset(&io_iov, 0, sizeof(io_iov));
3086 rqst[1].rq_iov = io_iov;
3087 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3089 rc = SMB2_ioctl_init(tcon, server,
3090 &rqst[1], COMPOUND_FID,
3091 COMPOUND_FID, FSCTL_GET_REPARSE_POINT, NULL, 0,
3093 MAX_SMB2_CREATE_RESPONSE_SIZE -
3094 MAX_SMB2_CLOSE_RESPONSE_SIZE);
3098 smb2_set_next_command(tcon, &rqst[1]);
3099 smb2_set_related(&rqst[1]);
3103 memset(&close_iov, 0, sizeof(close_iov));
3104 rqst[2].rq_iov = close_iov;
3105 rqst[2].rq_nvec = 1;
3107 rc = SMB2_close_init(tcon, server,
3108 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3112 smb2_set_related(&rqst[2]);
3114 rc = compound_send_recv(xid, tcon->ses, server,
3116 resp_buftype, rsp_iov);
3118 ioctl_rsp = rsp_iov[1].iov_base;
3121 * Open was successful and we got an ioctl response.
3124 /* See MS-FSCC 2.3.23 */
3126 reparse_buf = (struct reparse_data_buffer *)
3127 ((char *)ioctl_rsp +
3128 le32_to_cpu(ioctl_rsp->OutputOffset));
3129 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3131 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3132 rsp_iov[1].iov_len) {
3133 cifs_tcon_dbg(FYI, "srv returned invalid ioctl len: %d\n",
3138 *tag = le32_to_cpu(reparse_buf->ReparseTag);
3143 SMB2_open_free(&rqst[0]);
3144 SMB2_ioctl_free(&rqst[1]);
3145 SMB2_close_free(&rqst[2]);
3146 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3147 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3148 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3152 static struct cifs_ntsd *
3153 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
3154 const struct cifs_fid *cifsfid, u32 *pacllen, u32 info)
3156 struct cifs_ntsd *pntsd = NULL;
3158 int rc = -EOPNOTSUPP;
3159 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3162 return ERR_CAST(tlink);
3165 cifs_dbg(FYI, "trying to get acl\n");
3167 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
3168 cifsfid->volatile_fid, (void **)&pntsd, pacllen,
3172 cifs_put_tlink(tlink);
3174 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3181 static struct cifs_ntsd *
3182 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
3183 const char *path, u32 *pacllen, u32 info)
3185 struct cifs_ntsd *pntsd = NULL;
3186 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3189 struct cifs_tcon *tcon;
3190 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3191 struct cifs_fid fid;
3192 struct cifs_open_parms oparms;
3195 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
3197 return ERR_CAST(tlink);
3199 tcon = tlink_tcon(tlink);
3202 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3209 oparms = (struct cifs_open_parms) {
3211 .desired_access = READ_CONTROL,
3212 .disposition = FILE_OPEN,
3214 * When querying an ACL, even if the file is a symlink
3215 * we want to open the source not the target, and so
3216 * the protocol requires that the client specify this
3217 * flag when opening a reparse point
3219 .create_options = cifs_create_options(cifs_sb, 0) |
3224 if (info & SACL_SECINFO)
3225 oparms.desired_access |= SYSTEM_SECURITY;
3227 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
3231 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3232 fid.volatile_fid, (void **)&pntsd, pacllen,
3234 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3237 cifs_put_tlink(tlink);
3240 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3247 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
3248 struct inode *inode, const char *path, int aclflag)
3250 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3252 int rc, access_flags = 0;
3253 struct cifs_tcon *tcon;
3254 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
3255 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3256 struct cifs_fid fid;
3257 struct cifs_open_parms oparms;
3260 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
3262 return PTR_ERR(tlink);
3264 tcon = tlink_tcon(tlink);
3267 if (aclflag & CIFS_ACL_OWNER || aclflag & CIFS_ACL_GROUP)
3268 access_flags |= WRITE_OWNER;
3269 if (aclflag & CIFS_ACL_SACL)
3270 access_flags |= SYSTEM_SECURITY;
3271 if (aclflag & CIFS_ACL_DACL)
3272 access_flags |= WRITE_DAC;
3274 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3281 oparms = (struct cifs_open_parms) {
3283 .desired_access = access_flags,
3284 .create_options = cifs_create_options(cifs_sb, 0),
3285 .disposition = FILE_OPEN,
3290 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
3294 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3295 fid.volatile_fid, pnntsd, acllen, aclflag);
3296 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3299 cifs_put_tlink(tlink);
3304 /* Retrieve an ACL from the server */
3305 static struct cifs_ntsd *
3306 get_smb2_acl(struct cifs_sb_info *cifs_sb,
3307 struct inode *inode, const char *path,
3308 u32 *pacllen, u32 info)
3310 struct cifs_ntsd *pntsd = NULL;
3311 struct cifsFileInfo *open_file = NULL;
3313 if (inode && !(info & SACL_SECINFO))
3314 open_file = find_readable_file(CIFS_I(inode), true);
3315 if (!open_file || (info & SACL_SECINFO))
3316 return get_smb2_acl_by_path(cifs_sb, path, pacllen, info);
3318 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen, info);
3319 cifsFileInfo_put(open_file);
3323 static long smb3_zero_data(struct file *file, struct cifs_tcon *tcon,
3324 loff_t offset, loff_t len, unsigned int xid)
3326 struct cifsFileInfo *cfile = file->private_data;
3327 struct file_zero_data_information fsctl_buf;
3329 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3331 fsctl_buf.FileOffset = cpu_to_le64(offset);
3332 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3334 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3335 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3337 sizeof(struct file_zero_data_information),
3341 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3342 loff_t offset, loff_t len, bool keep_size)
3344 struct cifs_ses *ses = tcon->ses;
3345 struct inode *inode = file_inode(file);
3346 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3347 struct cifsFileInfo *cfile = file->private_data;
3354 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3355 ses->Suid, offset, len);
3358 filemap_invalidate_lock(inode->i_mapping);
3361 * We zero the range through ioctl, so we need remove the page caches
3362 * first, otherwise the data may be inconsistent with the server.
3364 truncate_pagecache_range(inode, offset, offset + len - 1);
3366 /* if file not oplocked can't be sure whether asking to extend size */
3368 if (keep_size == false && !CIFS_CACHE_READ(cifsi))
3369 goto zero_range_exit;
3371 rc = smb3_zero_data(file, tcon, offset, len, xid);
3373 goto zero_range_exit;
3376 * do we also need to change the size of the file?
3378 if (keep_size == false && i_size_read(inode) < offset + len) {
3379 eof = cpu_to_le64(offset + len);
3380 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3381 cfile->fid.volatile_fid, cfile->pid, &eof);
3385 filemap_invalidate_unlock(inode->i_mapping);
3386 inode_unlock(inode);
3389 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
3390 ses->Suid, offset, len, rc);
3392 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
3393 ses->Suid, offset, len);
3397 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
3398 loff_t offset, loff_t len)
3400 struct inode *inode = file_inode(file);
3401 struct cifsFileInfo *cfile = file->private_data;
3402 struct file_zero_data_information fsctl_buf;
3405 __u8 set_sparse = 1;
3410 /* Need to make file sparse, if not already, before freeing range. */
3411 /* Consider adding equivalent for compressed since it could also work */
3412 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
3417 filemap_invalidate_lock(inode->i_mapping);
3419 * We implement the punch hole through ioctl, so we need remove the page
3420 * caches first, otherwise the data may be inconsistent with the server.
3422 truncate_pagecache_range(inode, offset, offset + len - 1);
3424 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3426 fsctl_buf.FileOffset = cpu_to_le64(offset);
3427 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3429 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3430 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3432 sizeof(struct file_zero_data_information),
3433 CIFSMaxBufSize, NULL, NULL);
3434 filemap_invalidate_unlock(inode->i_mapping);
3436 inode_unlock(inode);
3441 static int smb3_simple_fallocate_write_range(unsigned int xid,
3442 struct cifs_tcon *tcon,
3443 struct cifsFileInfo *cfile,
3444 loff_t off, loff_t len,
3447 struct cifs_io_parms io_parms = {0};
3452 io_parms.netfid = cfile->fid.netfid;
3453 io_parms.pid = current->tgid;
3454 io_parms.tcon = tcon;
3455 io_parms.persistent_fid = cfile->fid.persistent_fid;
3456 io_parms.volatile_fid = cfile->fid.volatile_fid;
3459 io_parms.offset = off;
3460 io_parms.length = len;
3461 if (io_parms.length > SMB2_MAX_BUFFER_SIZE)
3462 io_parms.length = SMB2_MAX_BUFFER_SIZE;
3463 /* iov[0] is reserved for smb header */
3464 iov[1].iov_base = buf;
3465 iov[1].iov_len = io_parms.length;
3466 rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
3478 static int smb3_simple_fallocate_range(unsigned int xid,
3479 struct cifs_tcon *tcon,
3480 struct cifsFileInfo *cfile,
3481 loff_t off, loff_t len)
3483 struct file_allocated_range_buffer in_data, *out_data = NULL, *tmp_data;
3489 in_data.file_offset = cpu_to_le64(off);
3490 in_data.length = cpu_to_le64(len);
3491 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3492 cfile->fid.volatile_fid,
3493 FSCTL_QUERY_ALLOCATED_RANGES,
3494 (char *)&in_data, sizeof(in_data),
3495 1024 * sizeof(struct file_allocated_range_buffer),
3496 (char **)&out_data, &out_data_len);
3500 buf = kzalloc(1024 * 1024, GFP_KERNEL);
3506 tmp_data = out_data;
3509 * The rest of the region is unmapped so write it all.
3511 if (out_data_len == 0) {
3512 rc = smb3_simple_fallocate_write_range(xid, tcon,
3513 cfile, off, len, buf);
3517 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3522 if (off < le64_to_cpu(tmp_data->file_offset)) {
3524 * We are at a hole. Write until the end of the region
3525 * or until the next allocated data,
3526 * whichever comes next.
3528 l = le64_to_cpu(tmp_data->file_offset) - off;
3531 rc = smb3_simple_fallocate_write_range(xid, tcon,
3532 cfile, off, l, buf);
3541 * We are at a section of allocated data, just skip forward
3542 * until the end of the data or the end of the region
3543 * we are supposed to fallocate, whichever comes first.
3545 l = le64_to_cpu(tmp_data->length);
3551 tmp_data = &tmp_data[1];
3552 out_data_len -= sizeof(struct file_allocated_range_buffer);
3562 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3563 loff_t off, loff_t len, bool keep_size)
3565 struct inode *inode;
3566 struct cifsInodeInfo *cifsi;
3567 struct cifsFileInfo *cfile = file->private_data;
3568 long rc = -EOPNOTSUPP;
3574 inode = d_inode(cfile->dentry);
3575 cifsi = CIFS_I(inode);
3577 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3578 tcon->ses->Suid, off, len);
3579 /* if file not oplocked can't be sure whether asking to extend size */
3580 if (!CIFS_CACHE_READ(cifsi))
3581 if (keep_size == false) {
3582 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3583 tcon->tid, tcon->ses->Suid, off, len, rc);
3589 * Extending the file
3591 if ((keep_size == false) && i_size_read(inode) < off + len) {
3592 rc = inode_newsize_ok(inode, off + len);
3596 if (cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)
3597 smb2_set_sparse(xid, tcon, cfile, inode, false);
3599 eof = cpu_to_le64(off + len);
3600 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3601 cfile->fid.volatile_fid, cfile->pid, &eof);
3603 cifsi->server_eof = off + len;
3604 cifs_setsize(inode, off + len);
3605 cifs_truncate_page(inode->i_mapping, inode->i_size);
3606 truncate_setsize(inode, off + len);
3612 * Files are non-sparse by default so falloc may be a no-op
3613 * Must check if file sparse. If not sparse, and since we are not
3614 * extending then no need to do anything since file already allocated
3616 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
3621 if (keep_size == true) {
3623 * We can not preallocate pages beyond the end of the file
3626 if (off >= i_size_read(inode)) {
3631 * For fallocates that are partially beyond the end of file,
3632 * clamp len so we only fallocate up to the end of file.
3634 if (off + len > i_size_read(inode)) {
3635 len = i_size_read(inode) - off;
3639 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3641 * At this point, we are trying to fallocate an internal
3642 * regions of a sparse file. Since smb2 does not have a
3643 * fallocate command we have two otions on how to emulate this.
3644 * We can either turn the entire file to become non-sparse
3645 * which we only do if the fallocate is for virtually
3646 * the whole file, or we can overwrite the region with zeroes
3647 * using SMB2_write, which could be prohibitevly expensive
3651 * We are only trying to fallocate a small region so
3652 * just write it with zero.
3654 if (len <= 1024 * 1024) {
3655 rc = smb3_simple_fallocate_range(xid, tcon, cfile,
3661 * Check if falloc starts within first few pages of file
3662 * and ends within a few pages of the end of file to
3663 * ensure that most of file is being forced to be
3664 * fallocated now. If so then setting whole file sparse
3665 * ie potentially making a few extra pages at the beginning
3666 * or end of the file non-sparse via set_sparse is harmless.
3668 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
3674 smb2_set_sparse(xid, tcon, cfile, inode, false);
3679 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3680 tcon->ses->Suid, off, len, rc);
3682 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3683 tcon->ses->Suid, off, len);
3689 static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
3690 loff_t off, loff_t len)
3694 struct inode *inode = file_inode(file);
3695 struct cifsFileInfo *cfile = file->private_data;
3696 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3704 old_eof = i_size_read(inode);
3705 if ((off >= old_eof) ||
3706 off + len >= old_eof) {
3711 filemap_invalidate_lock(inode->i_mapping);
3712 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof - 1);
3716 truncate_pagecache_range(inode, off, old_eof);
3718 rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
3719 old_eof - off - len, off);
3723 eof = cpu_to_le64(old_eof - len);
3724 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3725 cfile->fid.volatile_fid, cfile->pid, &eof);
3731 cifsi->server_eof = i_size_read(inode) - len;
3732 truncate_setsize(inode, cifsi->server_eof);
3733 fscache_resize_cookie(cifs_inode_cookie(inode), cifsi->server_eof);
3735 filemap_invalidate_unlock(inode->i_mapping);
3737 inode_unlock(inode);
3742 static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
3743 loff_t off, loff_t len)
3747 struct cifsFileInfo *cfile = file->private_data;
3748 struct inode *inode = file_inode(file);
3750 __u64 count, old_eof;
3756 old_eof = i_size_read(inode);
3757 if (off >= old_eof) {
3762 count = old_eof - off;
3763 eof = cpu_to_le64(old_eof + len);
3765 filemap_invalidate_lock(inode->i_mapping);
3766 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof + len - 1);
3769 truncate_pagecache_range(inode, off, old_eof);
3771 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3772 cfile->fid.volatile_fid, cfile->pid, &eof);
3776 rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len);
3780 rc = smb3_zero_data(file, tcon, off, len, xid);
3786 filemap_invalidate_unlock(inode->i_mapping);
3788 inode_unlock(inode);
3793 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3795 struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3796 struct cifsInodeInfo *cifsi;
3797 struct inode *inode;
3799 struct file_allocated_range_buffer in_data, *out_data = NULL;
3803 if (whence != SEEK_HOLE && whence != SEEK_DATA)
3804 return generic_file_llseek(file, offset, whence);
3806 inode = d_inode(cfile->dentry);
3807 cifsi = CIFS_I(inode);
3809 if (offset < 0 || offset >= i_size_read(inode))
3814 * We need to be sure that all dirty pages are written as they
3815 * might fill holes on the server.
3816 * Note that we also MUST flush any written pages since at least
3817 * some servers (Windows2016) will not reflect recent writes in
3818 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3820 wrcfile = find_writable_file(cifsi, FIND_WR_ANY);
3822 filemap_write_and_wait(inode->i_mapping);
3823 smb2_flush_file(xid, tcon, &wrcfile->fid);
3824 cifsFileInfo_put(wrcfile);
3827 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3828 if (whence == SEEK_HOLE)
3829 offset = i_size_read(inode);
3833 in_data.file_offset = cpu_to_le64(offset);
3834 in_data.length = cpu_to_le64(i_size_read(inode));
3836 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3837 cfile->fid.volatile_fid,
3838 FSCTL_QUERY_ALLOCATED_RANGES,
3839 (char *)&in_data, sizeof(in_data),
3840 sizeof(struct file_allocated_range_buffer),
3841 (char **)&out_data, &out_data_len);
3847 if (whence == SEEK_HOLE && out_data_len == 0)
3850 if (whence == SEEK_DATA && out_data_len == 0) {
3855 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3859 if (whence == SEEK_DATA) {
3860 offset = le64_to_cpu(out_data->file_offset);
3863 if (offset < le64_to_cpu(out_data->file_offset))
3866 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3872 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3877 static int smb3_fiemap(struct cifs_tcon *tcon,
3878 struct cifsFileInfo *cfile,
3879 struct fiemap_extent_info *fei, u64 start, u64 len)
3882 struct file_allocated_range_buffer in_data, *out_data;
3884 int i, num, rc, flags, last_blob;
3887 rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0);
3893 in_data.file_offset = cpu_to_le64(start);
3894 in_data.length = cpu_to_le64(len);
3896 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3897 cfile->fid.volatile_fid,
3898 FSCTL_QUERY_ALLOCATED_RANGES,
3899 (char *)&in_data, sizeof(in_data),
3900 1024 * sizeof(struct file_allocated_range_buffer),
3901 (char **)&out_data, &out_data_len);
3910 if (out_data_len && out_data_len < sizeof(struct file_allocated_range_buffer)) {
3914 if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3919 num = out_data_len / sizeof(struct file_allocated_range_buffer);
3920 for (i = 0; i < num; i++) {
3922 if (i == num - 1 && last_blob)
3923 flags |= FIEMAP_EXTENT_LAST;
3925 rc = fiemap_fill_next_extent(fei,
3926 le64_to_cpu(out_data[i].file_offset),
3927 le64_to_cpu(out_data[i].file_offset),
3928 le64_to_cpu(out_data[i].length),
3939 next = le64_to_cpu(out_data[num - 1].file_offset) +
3940 le64_to_cpu(out_data[num - 1].length);
3941 len = len - (next - start);
3952 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
3953 loff_t off, loff_t len)
3955 /* KEEP_SIZE already checked for by do_fallocate */
3956 if (mode & FALLOC_FL_PUNCH_HOLE)
3957 return smb3_punch_hole(file, tcon, off, len);
3958 else if (mode & FALLOC_FL_ZERO_RANGE) {
3959 if (mode & FALLOC_FL_KEEP_SIZE)
3960 return smb3_zero_range(file, tcon, off, len, true);
3961 return smb3_zero_range(file, tcon, off, len, false);
3962 } else if (mode == FALLOC_FL_KEEP_SIZE)
3963 return smb3_simple_falloc(file, tcon, off, len, true);
3964 else if (mode == FALLOC_FL_COLLAPSE_RANGE)
3965 return smb3_collapse_range(file, tcon, off, len);
3966 else if (mode == FALLOC_FL_INSERT_RANGE)
3967 return smb3_insert_range(file, tcon, off, len);
3969 return smb3_simple_falloc(file, tcon, off, len, false);
3975 smb2_downgrade_oplock(struct TCP_Server_Info *server,
3976 struct cifsInodeInfo *cinode, __u32 oplock,
3977 unsigned int epoch, bool *purge_cache)
3979 server->ops->set_oplock_level(cinode, oplock, 0, NULL);
3983 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3984 unsigned int epoch, bool *purge_cache);
3987 smb3_downgrade_oplock(struct TCP_Server_Info *server,
3988 struct cifsInodeInfo *cinode, __u32 oplock,
3989 unsigned int epoch, bool *purge_cache)
3991 unsigned int old_state = cinode->oplock;
3992 unsigned int old_epoch = cinode->epoch;
3993 unsigned int new_state;
3995 if (epoch > old_epoch) {
3996 smb21_set_oplock_level(cinode, oplock, 0, NULL);
3997 cinode->epoch = epoch;
4000 new_state = cinode->oplock;
4001 *purge_cache = false;
4003 if ((old_state & CIFS_CACHE_READ_FLG) != 0 &&
4004 (new_state & CIFS_CACHE_READ_FLG) == 0)
4005 *purge_cache = true;
4006 else if (old_state == new_state && (epoch - old_epoch > 1))
4007 *purge_cache = true;
4011 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4012 unsigned int epoch, bool *purge_cache)
4015 cinode->lease_granted = false;
4016 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
4018 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
4019 cinode->oplock = CIFS_CACHE_RHW_FLG;
4020 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
4021 &cinode->netfs.inode);
4022 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
4023 cinode->oplock = CIFS_CACHE_RW_FLG;
4024 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
4025 &cinode->netfs.inode);
4026 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
4027 cinode->oplock = CIFS_CACHE_READ_FLG;
4028 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
4029 &cinode->netfs.inode);
4035 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4036 unsigned int epoch, bool *purge_cache)
4038 char message[5] = {0};
4039 unsigned int new_oplock = 0;
4042 cinode->lease_granted = true;
4043 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
4046 /* Check if the server granted an oplock rather than a lease */
4047 if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4048 return smb2_set_oplock_level(cinode, oplock, epoch,
4051 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
4052 new_oplock |= CIFS_CACHE_READ_FLG;
4053 strcat(message, "R");
4055 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
4056 new_oplock |= CIFS_CACHE_HANDLE_FLG;
4057 strcat(message, "H");
4059 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
4060 new_oplock |= CIFS_CACHE_WRITE_FLG;
4061 strcat(message, "W");
4064 strncpy(message, "None", sizeof(message));
4066 cinode->oplock = new_oplock;
4067 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
4068 &cinode->netfs.inode);
4072 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4073 unsigned int epoch, bool *purge_cache)
4075 unsigned int old_oplock = cinode->oplock;
4077 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
4080 *purge_cache = false;
4081 if (old_oplock == CIFS_CACHE_READ_FLG) {
4082 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
4083 (epoch - cinode->epoch > 0))
4084 *purge_cache = true;
4085 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4086 (epoch - cinode->epoch > 1))
4087 *purge_cache = true;
4088 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4089 (epoch - cinode->epoch > 1))
4090 *purge_cache = true;
4091 else if (cinode->oplock == 0 &&
4092 (epoch - cinode->epoch > 0))
4093 *purge_cache = true;
4094 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
4095 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4096 (epoch - cinode->epoch > 0))
4097 *purge_cache = true;
4098 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4099 (epoch - cinode->epoch > 1))
4100 *purge_cache = true;
4102 cinode->epoch = epoch;
4106 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
4108 smb2_is_read_op(__u32 oplock)
4110 return oplock == SMB2_OPLOCK_LEVEL_II;
4112 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
4115 smb21_is_read_op(__u32 oplock)
4117 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
4118 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
4122 map_oplock_to_lease(u8 oplock)
4124 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4125 return SMB2_LEASE_WRITE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE;
4126 else if (oplock == SMB2_OPLOCK_LEVEL_II)
4127 return SMB2_LEASE_READ_CACHING_LE;
4128 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
4129 return SMB2_LEASE_HANDLE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE |
4130 SMB2_LEASE_WRITE_CACHING_LE;
4135 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
4137 struct create_lease *buf;
4139 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
4143 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4144 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4146 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4147 (struct create_lease, lcontext));
4148 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
4149 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4150 (struct create_lease, Name));
4151 buf->ccontext.NameLength = cpu_to_le16(4);
4152 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4161 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
4163 struct create_lease_v2 *buf;
4165 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
4169 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4170 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4172 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4173 (struct create_lease_v2, lcontext));
4174 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
4175 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4176 (struct create_lease_v2, Name));
4177 buf->ccontext.NameLength = cpu_to_le16(4);
4178 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4187 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4189 struct create_lease *lc = (struct create_lease *)buf;
4191 *epoch = 0; /* not used */
4192 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4193 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4194 return le32_to_cpu(lc->lcontext.LeaseState);
4198 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4200 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
4202 *epoch = le16_to_cpu(lc->lcontext.Epoch);
4203 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4204 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4206 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
4207 return le32_to_cpu(lc->lcontext.LeaseState);
4211 smb2_wp_retry_size(struct inode *inode)
4213 return min_t(unsigned int, CIFS_SB(inode->i_sb)->ctx->wsize,
4214 SMB2_MAX_BUFFER_SIZE);
4218 smb2_dir_needs_close(struct cifsFileInfo *cfile)
4220 return !cfile->invalidHandle;
4224 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
4225 struct smb_rqst *old_rq, __le16 cipher_type)
4227 struct smb2_hdr *shdr =
4228 (struct smb2_hdr *)old_rq->rq_iov[0].iov_base;
4230 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
4231 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
4232 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
4233 tr_hdr->Flags = cpu_to_le16(0x01);
4234 if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4235 (cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4236 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4238 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4239 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
4242 static void *smb2_aead_req_alloc(struct crypto_aead *tfm, const struct smb_rqst *rqst,
4243 int num_rqst, const u8 *sig, u8 **iv,
4244 struct aead_request **req, struct sg_table *sgt,
4245 unsigned int *num_sgs, size_t *sensitive_size)
4247 unsigned int req_size = sizeof(**req) + crypto_aead_reqsize(tfm);
4248 unsigned int iv_size = crypto_aead_ivsize(tfm);
4252 *num_sgs = cifs_get_num_sgs(rqst, num_rqst, sig);
4253 if (IS_ERR_VALUE((long)(int)*num_sgs))
4254 return ERR_PTR(*num_sgs);
4257 len += crypto_aead_alignmask(tfm) & ~(crypto_tfm_ctx_alignment() - 1);
4258 len = ALIGN(len, crypto_tfm_ctx_alignment());
4260 len = ALIGN(len, __alignof__(struct scatterlist));
4261 len += array_size(*num_sgs, sizeof(struct scatterlist));
4262 *sensitive_size = len;
4264 p = kvzalloc(len, GFP_NOFS);
4266 return ERR_PTR(-ENOMEM);
4268 *iv = (u8 *)PTR_ALIGN(p, crypto_aead_alignmask(tfm) + 1);
4269 *req = (struct aead_request *)PTR_ALIGN(*iv + iv_size,
4270 crypto_tfm_ctx_alignment());
4271 sgt->sgl = (struct scatterlist *)PTR_ALIGN((u8 *)*req + req_size,
4272 __alignof__(struct scatterlist));
4276 static void *smb2_get_aead_req(struct crypto_aead *tfm, struct smb_rqst *rqst,
4277 int num_rqst, const u8 *sig, u8 **iv,
4278 struct aead_request **req, struct scatterlist **sgl,
4279 size_t *sensitive_size)
4281 struct sg_table sgtable = {};
4282 unsigned int skip, num_sgs, i, j;
4286 p = smb2_aead_req_alloc(tfm, rqst, num_rqst, sig, iv, req, &sgtable,
4287 &num_sgs, sensitive_size);
4291 sg_init_marker(sgtable.sgl, num_sgs);
4294 * The first rqst has a transform header where the
4295 * first 20 bytes are not part of the encrypted blob.
4299 for (i = 0; i < num_rqst; i++) {
4300 struct iov_iter *iter = &rqst[i].rq_iter;
4301 size_t count = iov_iter_count(iter);
4303 for (j = 0; j < rqst[i].rq_nvec; j++) {
4304 cifs_sg_set_buf(&sgtable,
4305 rqst[i].rq_iov[j].iov_base + skip,
4306 rqst[i].rq_iov[j].iov_len - skip);
4308 /* See the above comment on the 'skip' assignment */
4311 sgtable.orig_nents = sgtable.nents;
4313 rc = netfs_extract_iter_to_sg(iter, count, &sgtable,
4314 num_sgs - sgtable.nents, 0);
4315 iov_iter_revert(iter, rc);
4316 sgtable.orig_nents = sgtable.nents;
4319 cifs_sg_set_buf(&sgtable, sig, SMB2_SIGNATURE_SIZE);
4320 sg_mark_end(&sgtable.sgl[sgtable.nents - 1]);
4326 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
4328 struct TCP_Server_Info *pserver;
4329 struct cifs_ses *ses;
4332 /* If server is a channel, select the primary channel */
4333 pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
4335 spin_lock(&cifs_tcp_ses_lock);
4336 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
4337 if (ses->Suid == ses_id) {
4338 spin_lock(&ses->ses_lock);
4339 ses_enc_key = enc ? ses->smb3encryptionkey :
4340 ses->smb3decryptionkey;
4341 memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE);
4342 spin_unlock(&ses->ses_lock);
4343 spin_unlock(&cifs_tcp_ses_lock);
4347 spin_unlock(&cifs_tcp_ses_lock);
4352 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
4353 * iov[0] - transform header (associate data),
4354 * iov[1-N] - SMB2 header and pages - data to encrypt.
4355 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4359 crypt_message(struct TCP_Server_Info *server, int num_rqst,
4360 struct smb_rqst *rqst, int enc)
4362 struct smb2_transform_hdr *tr_hdr =
4363 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
4364 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
4366 struct scatterlist *sg;
4367 u8 sign[SMB2_SIGNATURE_SIZE] = {};
4368 u8 key[SMB3_ENC_DEC_KEY_SIZE];
4369 struct aead_request *req;
4371 DECLARE_CRYPTO_WAIT(wait);
4372 struct crypto_aead *tfm;
4373 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4375 size_t sensitive_size;
4377 rc = smb2_get_enc_key(server, le64_to_cpu(tr_hdr->SessionId), enc, key);
4379 cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
4384 rc = smb3_crypto_aead_allocate(server);
4386 cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
4390 tfm = enc ? server->secmech.enc : server->secmech.dec;
4392 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
4393 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4394 rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
4396 rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE);
4399 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
4403 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
4405 cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
4409 creq = smb2_get_aead_req(tfm, rqst, num_rqst, sign, &iv, &req, &sg,
4412 return PTR_ERR(creq);
4415 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
4416 crypt_len += SMB2_SIGNATURE_SIZE;
4419 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4420 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4421 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4424 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4427 aead_request_set_tfm(req, tfm);
4428 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
4429 aead_request_set_ad(req, assoc_data_len);
4431 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
4432 crypto_req_done, &wait);
4434 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
4435 : crypto_aead_decrypt(req), &wait);
4438 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
4440 kvfree_sensitive(creq, sensitive_size);
4445 * Clear a read buffer, discarding the folios which have XA_MARK_0 set.
4447 static void cifs_clear_xarray_buffer(struct xarray *buffer)
4449 struct folio *folio;
4451 XA_STATE(xas, buffer, 0);
4454 xas_for_each_marked(&xas, folio, ULONG_MAX, XA_MARK_0) {
4462 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
4466 for (i = 0; i < num_rqst; i++)
4467 if (!xa_empty(&rqst[i].rq_buffer))
4468 cifs_clear_xarray_buffer(&rqst[i].rq_buffer);
4472 * This function will initialize new_rq and encrypt the content.
4473 * The first entry, new_rq[0], only contains a single iov which contains
4474 * a smb2_transform_hdr and is pre-allocated by the caller.
4475 * This function then populates new_rq[1+] with the content from olq_rq[0+].
4477 * The end result is an array of smb_rqst structures where the first structure
4478 * only contains a single iov for the transform header which we then can pass
4479 * to crypt_message().
4481 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4482 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
4485 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
4486 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
4488 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
4490 unsigned int orig_len = 0;
4494 for (i = 1; i < num_rqst; i++) {
4495 struct smb_rqst *old = &old_rq[i - 1];
4496 struct smb_rqst *new = &new_rq[i];
4497 struct xarray *buffer = &new->rq_buffer;
4498 size_t size = iov_iter_count(&old->rq_iter), seg, copied = 0;
4500 orig_len += smb_rqst_len(server, old);
4501 new->rq_iov = old->rq_iov;
4502 new->rq_nvec = old->rq_nvec;
4507 unsigned int npages = DIV_ROUND_UP(size, PAGE_SIZE);
4509 for (j = 0; j < npages; j++) {
4513 page = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4517 o = xa_store(buffer, j, page, GFP_KERNEL);
4524 xa_set_mark(buffer, j, XA_MARK_0);
4526 seg = min_t(size_t, size - copied, PAGE_SIZE);
4527 if (copy_page_from_iter(page, 0, seg, &old->rq_iter) != seg) {
4533 iov_iter_xarray(&new->rq_iter, ITER_SOURCE,
4535 new->rq_iter_size = size;
4539 /* fill the 1st iov with a transform header */
4540 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
4542 rc = crypt_message(server, num_rqst, new_rq, 1);
4543 cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
4550 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
4555 smb3_is_transform_hdr(void *buf)
4557 struct smb2_transform_hdr *trhdr = buf;
4559 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
4563 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
4564 unsigned int buf_data_size, struct iov_iter *iter,
4568 struct smb_rqst rqst = {NULL};
4569 size_t iter_size = 0;
4572 iov[0].iov_base = buf;
4573 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
4574 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
4575 iov[1].iov_len = buf_data_size;
4580 rqst.rq_iter = *iter;
4581 rqst.rq_iter_size = iov_iter_count(iter);
4582 iter_size = iov_iter_count(iter);
4585 rc = crypt_message(server, 1, &rqst, 0);
4586 cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
4591 memmove(buf, iov[1].iov_base, buf_data_size);
4594 server->total_read = buf_data_size + iter_size;
4600 cifs_copy_pages_to_iter(struct xarray *pages, unsigned int data_size,
4601 unsigned int skip, struct iov_iter *iter)
4604 unsigned long index;
4606 xa_for_each(pages, index, page) {
4607 size_t n, len = min_t(unsigned int, PAGE_SIZE - skip, data_size);
4609 n = copy_page_to_iter(page, skip, len, iter);
4611 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
4622 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
4623 char *buf, unsigned int buf_len, struct xarray *pages,
4624 unsigned int pages_len, bool is_offloaded)
4626 unsigned int data_offset;
4627 unsigned int data_len;
4628 unsigned int cur_off;
4629 unsigned int cur_page_idx;
4630 unsigned int pad_len;
4631 struct cifs_readdata *rdata = mid->callback_data;
4632 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
4634 bool use_rdma_mr = false;
4636 if (shdr->Command != SMB2_READ) {
4637 cifs_server_dbg(VFS, "only big read responses are supported\n");
4641 if (server->ops->is_session_expired &&
4642 server->ops->is_session_expired(buf)) {
4644 cifs_reconnect(server, true);
4648 if (server->ops->is_status_pending &&
4649 server->ops->is_status_pending(buf, server))
4652 /* set up first two iov to get credits */
4653 rdata->iov[0].iov_base = buf;
4654 rdata->iov[0].iov_len = 0;
4655 rdata->iov[1].iov_base = buf;
4656 rdata->iov[1].iov_len =
4657 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
4658 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
4659 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
4660 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
4661 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
4663 rdata->result = server->ops->map_error(buf, true);
4664 if (rdata->result != 0) {
4665 cifs_dbg(FYI, "%s: server returned error %d\n",
4666 __func__, rdata->result);
4667 /* normal error on read response */
4669 mid->mid_state = MID_RESPONSE_RECEIVED;
4671 dequeue_mid(mid, false);
4675 data_offset = server->ops->read_data_offset(buf);
4676 #ifdef CONFIG_CIFS_SMB_DIRECT
4677 use_rdma_mr = rdata->mr;
4679 data_len = server->ops->read_data_length(buf, use_rdma_mr);
4681 if (data_offset < server->vals->read_rsp_size) {
4683 * win2k8 sometimes sends an offset of 0 when the read
4684 * is beyond the EOF. Treat it as if the data starts just after
4687 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
4688 __func__, data_offset);
4689 data_offset = server->vals->read_rsp_size;
4690 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
4691 /* data_offset is beyond the end of smallbuf */
4692 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
4693 __func__, data_offset);
4694 rdata->result = -EIO;
4696 mid->mid_state = MID_RESPONSE_MALFORMED;
4698 dequeue_mid(mid, rdata->result);
4702 pad_len = data_offset - server->vals->read_rsp_size;
4704 if (buf_len <= data_offset) {
4705 /* read response payload is in pages */
4706 cur_page_idx = pad_len / PAGE_SIZE;
4707 cur_off = pad_len % PAGE_SIZE;
4709 if (cur_page_idx != 0) {
4710 /* data offset is beyond the 1st page of response */
4711 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
4712 __func__, data_offset);
4713 rdata->result = -EIO;
4715 mid->mid_state = MID_RESPONSE_MALFORMED;
4717 dequeue_mid(mid, rdata->result);
4721 if (data_len > pages_len - pad_len) {
4722 /* data_len is corrupt -- discard frame */
4723 rdata->result = -EIO;
4725 mid->mid_state = MID_RESPONSE_MALFORMED;
4727 dequeue_mid(mid, rdata->result);
4731 /* Copy the data to the output I/O iterator. */
4732 rdata->result = cifs_copy_pages_to_iter(pages, pages_len,
4733 cur_off, &rdata->iter);
4734 if (rdata->result != 0) {
4736 mid->mid_state = MID_RESPONSE_MALFORMED;
4738 dequeue_mid(mid, rdata->result);
4741 rdata->got_bytes = pages_len;
4743 } else if (buf_len >= data_offset + data_len) {
4744 /* read response payload is in buf */
4745 WARN_ONCE(pages && !xa_empty(pages),
4746 "read data can be either in buf or in pages");
4747 length = copy_to_iter(buf + data_offset, data_len, &rdata->iter);
4750 rdata->got_bytes = data_len;
4752 /* read response payload cannot be in both buf and pages */
4753 WARN_ONCE(1, "buf can not contain only a part of read data");
4754 rdata->result = -EIO;
4756 mid->mid_state = MID_RESPONSE_MALFORMED;
4758 dequeue_mid(mid, rdata->result);
4763 mid->mid_state = MID_RESPONSE_RECEIVED;
4765 dequeue_mid(mid, false);
4769 struct smb2_decrypt_work {
4770 struct work_struct decrypt;
4771 struct TCP_Server_Info *server;
4772 struct xarray buffer;
4778 static void smb2_decrypt_offload(struct work_struct *work)
4780 struct smb2_decrypt_work *dw = container_of(work,
4781 struct smb2_decrypt_work, decrypt);
4783 struct mid_q_entry *mid;
4784 struct iov_iter iter;
4786 iov_iter_xarray(&iter, ITER_DEST, &dw->buffer, 0, dw->len);
4787 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
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->buffer, 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 cifs_clear_xarray_buffer(&dw->buffer);
4836 cifs_small_buf_release(dw->buf);
4842 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
4846 char *buf = server->smallbuf;
4847 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4848 struct iov_iter iter;
4849 unsigned int len, npages;
4850 unsigned int buflen = server->pdu_size;
4853 struct smb2_decrypt_work *dw;
4855 dw = kzalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL);
4858 xa_init(&dw->buffer);
4859 INIT_WORK(&dw->decrypt, smb2_decrypt_offload);
4860 dw->server = server;
4863 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
4864 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
4866 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
4869 server->total_read += rc;
4871 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
4872 server->vals->read_rsp_size;
4874 npages = DIV_ROUND_UP(len, PAGE_SIZE);
4877 for (; i < npages; i++) {
4880 page = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4884 old = xa_store(&dw->buffer, i, page, GFP_KERNEL);
4885 if (xa_is_err(old)) {
4890 xa_set_mark(&dw->buffer, i, XA_MARK_0);
4893 iov_iter_xarray(&iter, ITER_DEST, &dw->buffer, 0, npages * PAGE_SIZE);
4895 /* Read the data into the buffer and clear excess bufferage. */
4896 rc = cifs_read_iter_from_socket(server, &iter, dw->len);
4900 server->total_read += rc;
4901 if (rc < npages * PAGE_SIZE)
4902 iov_iter_zero(npages * PAGE_SIZE - rc, &iter);
4903 iov_iter_revert(&iter, npages * PAGE_SIZE);
4904 iov_iter_truncate(&iter, dw->len);
4906 rc = cifs_discard_remaining_data(server);
4911 * For large reads, offload to different thread for better performance,
4912 * use more cores decrypting which can be expensive
4915 if ((server->min_offload) && (server->in_flight > 1) &&
4916 (server->pdu_size >= server->min_offload)) {
4917 dw->buf = server->smallbuf;
4918 server->smallbuf = (char *)cifs_small_buf_get();
4920 queue_work(decrypt_wq, &dw->decrypt);
4921 *num_mids = 0; /* worker thread takes care of finding mid */
4925 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
4930 *mid = smb2_find_mid(server, buf);
4932 cifs_dbg(FYI, "mid not found\n");
4934 cifs_dbg(FYI, "mid found\n");
4935 (*mid)->decrypted = true;
4936 rc = handle_read_data(server, *mid, buf,
4937 server->vals->read_rsp_size,
4938 &dw->buffer, dw->len, false);
4940 if (server->ops->is_network_name_deleted) {
4941 server->ops->is_network_name_deleted(buf,
4948 cifs_clear_xarray_buffer(&dw->buffer);
4953 cifs_discard_remaining_data(server);
4958 receive_encrypted_standard(struct TCP_Server_Info *server,
4959 struct mid_q_entry **mids, char **bufs,
4963 char *buf = server->smallbuf;
4964 struct smb2_hdr *shdr;
4965 unsigned int pdu_length = server->pdu_size;
4966 unsigned int buf_size;
4967 struct mid_q_entry *mid_entry;
4969 char *next_buffer = NULL;
4973 /* switch to large buffer if too big for a small one */
4974 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
4975 server->large_buf = true;
4976 memcpy(server->bigbuf, buf, server->total_read);
4977 buf = server->bigbuf;
4980 /* now read the rest */
4981 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
4982 pdu_length - HEADER_SIZE(server) + 1);
4985 server->total_read += length;
4987 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
4988 length = decrypt_raw_data(server, buf, buf_size, NULL, false);
4992 next_is_large = server->large_buf;
4994 shdr = (struct smb2_hdr *)buf;
4995 if (shdr->NextCommand) {
4997 next_buffer = (char *)cifs_buf_get();
4999 next_buffer = (char *)cifs_small_buf_get();
5001 buf + le32_to_cpu(shdr->NextCommand),
5002 pdu_length - le32_to_cpu(shdr->NextCommand));
5005 mid_entry = smb2_find_mid(server, buf);
5006 if (mid_entry == NULL)
5007 cifs_dbg(FYI, "mid not found\n");
5009 cifs_dbg(FYI, "mid found\n");
5010 mid_entry->decrypted = true;
5011 mid_entry->resp_buf_size = server->pdu_size;
5014 if (*num_mids >= MAX_COMPOUND) {
5015 cifs_server_dbg(VFS, "too many PDUs in compound\n");
5018 bufs[*num_mids] = buf;
5019 mids[(*num_mids)++] = mid_entry;
5021 if (mid_entry && mid_entry->handle)
5022 ret = mid_entry->handle(server, mid_entry);
5024 ret = cifs_handle_standard(server, mid_entry);
5026 if (ret == 0 && shdr->NextCommand) {
5027 pdu_length -= le32_to_cpu(shdr->NextCommand);
5028 server->large_buf = next_is_large;
5030 server->bigbuf = buf = next_buffer;
5032 server->smallbuf = buf = next_buffer;
5034 } else if (ret != 0) {
5036 * ret != 0 here means that we didn't get to handle_mid() thus
5037 * server->smallbuf and server->bigbuf are still valid. We need
5038 * to free next_buffer because it is not going to be used
5042 free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer);
5044 free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer);
5051 smb3_receive_transform(struct TCP_Server_Info *server,
5052 struct mid_q_entry **mids, char **bufs, int *num_mids)
5054 char *buf = server->smallbuf;
5055 unsigned int pdu_length = server->pdu_size;
5056 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
5057 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
5059 if (pdu_length < sizeof(struct smb2_transform_hdr) +
5060 sizeof(struct smb2_hdr)) {
5061 cifs_server_dbg(VFS, "Transform message is too small (%u)\n",
5063 cifs_reconnect(server, true);
5064 return -ECONNABORTED;
5067 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
5068 cifs_server_dbg(VFS, "Transform message is broken\n");
5069 cifs_reconnect(server, true);
5070 return -ECONNABORTED;
5073 /* TODO: add support for compounds containing READ. */
5074 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
5075 return receive_encrypted_read(server, &mids[0], num_mids);
5078 return receive_encrypted_standard(server, mids, bufs, num_mids);
5082 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
5084 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
5086 return handle_read_data(server, mid, buf, server->pdu_size,
5091 smb2_next_header(char *buf)
5093 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
5094 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
5096 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
5097 return sizeof(struct smb2_transform_hdr) +
5098 le32_to_cpu(t_hdr->OriginalMessageSize);
5100 return le32_to_cpu(hdr->NextCommand);
5104 smb2_make_node(unsigned int xid, struct inode *inode,
5105 struct dentry *dentry, struct cifs_tcon *tcon,
5106 const char *full_path, umode_t mode, dev_t dev)
5108 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
5110 struct cifs_open_info_data buf = {};
5111 struct cifs_io_parms io_parms = {0};
5113 struct cifs_fid fid;
5114 struct cifs_open_parms oparms;
5115 unsigned int bytes_written;
5116 struct win_dev *pdev;
5120 * Check if mounted with mount parm 'sfu' mount parm.
5121 * SFU emulation should work with all servers, but only
5122 * supports block and char device (no socket & fifo),
5123 * and was used by default in earlier versions of Windows
5125 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
5129 * TODO: Add ability to create instead via reparse point. Windows (e.g.
5130 * their current NFS server) uses this approach to expose special files
5131 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
5134 if (!S_ISCHR(mode) && !S_ISBLK(mode))
5137 cifs_dbg(FYI, "sfu compat create special file\n");
5139 oparms = (struct cifs_open_parms) {
5142 .desired_access = GENERIC_WRITE,
5143 .create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR |
5144 CREATE_OPTION_SPECIAL),
5145 .disposition = FILE_CREATE,
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.fi;
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.fi;
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 */
5188 cifs_free_open_info(&buf);
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),
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),
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),
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),
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),
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),
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),
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),