1 // SPDX-License-Identifier: GPL-2.0
3 * SMB2 version specific operations
5 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
8 #include <linux/pagemap.h>
10 #include <linux/falloc.h>
11 #include <linux/scatterlist.h>
12 #include <linux/uuid.h>
13 #include <linux/sort.h>
14 #include <crypto/aead.h>
15 #include <linux/fiemap.h>
16 #include <uapi/linux/magic.h>
20 #include "smb2proto.h"
21 #include "cifsproto.h"
22 #include "cifs_debug.h"
23 #include "cifs_unicode.h"
24 #include "smb2status.h"
26 #include "cifs_ioctl.h"
27 #include "smbdirect.h"
29 #include "fs_context.h"
30 #include "cached_dir.h"
32 /* Change credits for different ops and return the total number of credits */
34 change_conf(struct TCP_Server_Info *server)
36 server->credits += server->echo_credits + server->oplock_credits;
37 server->oplock_credits = server->echo_credits = 0;
38 switch (server->credits) {
42 server->echoes = false;
43 server->oplocks = false;
46 server->echoes = true;
47 server->oplocks = false;
48 server->echo_credits = 1;
51 server->echoes = true;
53 server->oplocks = true;
54 server->oplock_credits = 1;
56 server->oplocks = false;
58 server->echo_credits = 1;
60 server->credits -= server->echo_credits + server->oplock_credits;
61 return server->credits + server->echo_credits + server->oplock_credits;
65 smb2_add_credits(struct TCP_Server_Info *server,
66 const struct cifs_credits *credits, const int optype)
69 int scredits, in_flight;
70 unsigned int add = credits->value;
71 unsigned int instance = credits->instance;
72 bool reconnect_detected = false;
73 bool reconnect_with_invalid_credits = false;
75 spin_lock(&server->req_lock);
76 val = server->ops->get_credits_field(server, optype);
78 /* eg found case where write overlapping reconnect messed up credits */
79 if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0))
80 reconnect_with_invalid_credits = true;
82 if ((instance == 0) || (instance == server->reconnect_instance))
85 reconnect_detected = true;
88 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
89 pr_warn_once("server overflowed SMB3 credits\n");
90 trace_smb3_overflow_credits(server->CurrentMid,
91 server->conn_id, server->hostname, *val,
92 add, server->in_flight);
95 if (server->in_flight == 0 &&
96 ((optype & CIFS_OP_MASK) != CIFS_NEG_OP) &&
97 ((optype & CIFS_OP_MASK) != CIFS_SESS_OP))
98 rc = change_conf(server);
100 * Sometimes server returns 0 credits on oplock break ack - we need to
101 * rebalance credits in this case.
103 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
105 if (server->credits > 1) {
107 server->oplock_credits++;
111 in_flight = server->in_flight;
112 spin_unlock(&server->req_lock);
113 wake_up(&server->request_q);
115 if (reconnect_detected) {
116 trace_smb3_reconnect_detected(server->CurrentMid,
117 server->conn_id, server->hostname, scredits, add, in_flight);
119 cifs_dbg(FYI, "trying to put %d credits from the old server instance %d\n",
123 if (reconnect_with_invalid_credits) {
124 trace_smb3_reconnect_with_invalid_credits(server->CurrentMid,
125 server->conn_id, server->hostname, scredits, add, in_flight);
126 cifs_dbg(FYI, "Negotiate operation when server credits is non-zero. Optype: %d, server credits: %d, credits added: %d\n",
127 optype, scredits, add);
130 spin_lock(&server->srv_lock);
131 if (server->tcpStatus == CifsNeedReconnect
132 || server->tcpStatus == CifsExiting) {
133 spin_unlock(&server->srv_lock);
136 spin_unlock(&server->srv_lock);
140 /* change_conf hasn't been executed */
143 cifs_server_dbg(VFS, "Possible client or server bug - zero credits\n");
146 cifs_server_dbg(VFS, "disabling echoes and oplocks\n");
149 cifs_dbg(FYI, "disabling oplocks\n");
152 /* change_conf rebalanced credits for different types */
156 trace_smb3_add_credits(server->CurrentMid,
157 server->conn_id, server->hostname, scredits, add, in_flight);
158 cifs_dbg(FYI, "%s: added %u credits total=%d\n", __func__, add, scredits);
162 smb2_set_credits(struct TCP_Server_Info *server, const int val)
164 int scredits, in_flight;
166 spin_lock(&server->req_lock);
167 server->credits = val;
169 server->reconnect_instance++;
170 scredits = server->credits;
171 in_flight = server->in_flight;
172 spin_unlock(&server->req_lock);
174 trace_smb3_set_credits(server->CurrentMid,
175 server->conn_id, server->hostname, scredits, val, in_flight);
176 cifs_dbg(FYI, "%s: set %u credits\n", __func__, val);
178 /* don't log while holding the lock */
180 cifs_dbg(FYI, "set credits to 1 due to smb2 reconnect\n");
184 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
188 return &server->echo_credits;
190 return &server->oplock_credits;
192 return &server->credits;
197 smb2_get_credits(struct mid_q_entry *mid)
199 return mid->credits_received;
203 smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
204 unsigned int *num, struct cifs_credits *credits)
207 unsigned int scredits, in_flight;
209 spin_lock(&server->req_lock);
211 if (server->credits <= 0) {
212 spin_unlock(&server->req_lock);
213 cifs_num_waiters_inc(server);
214 rc = wait_event_killable(server->request_q,
215 has_credits(server, &server->credits, 1));
216 cifs_num_waiters_dec(server);
219 spin_lock(&server->req_lock);
221 spin_unlock(&server->req_lock);
222 spin_lock(&server->srv_lock);
223 if (server->tcpStatus == CifsExiting) {
224 spin_unlock(&server->srv_lock);
227 spin_unlock(&server->srv_lock);
229 spin_lock(&server->req_lock);
230 scredits = server->credits;
231 /* can deadlock with reopen */
233 *num = SMB2_MAX_BUFFER_SIZE;
235 credits->instance = 0;
239 /* leave some credits for reopen and other ops */
241 *num = min_t(unsigned int, size,
242 scredits * SMB2_MAX_BUFFER_SIZE);
245 DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
246 credits->instance = server->reconnect_instance;
247 server->credits -= credits->value;
249 if (server->in_flight > server->max_in_flight)
250 server->max_in_flight = server->in_flight;
254 scredits = server->credits;
255 in_flight = server->in_flight;
256 spin_unlock(&server->req_lock);
258 trace_smb3_wait_credits(server->CurrentMid,
259 server->conn_id, server->hostname, scredits, -(credits->value), in_flight);
260 cifs_dbg(FYI, "%s: removed %u credits total=%d\n",
261 __func__, credits->value, scredits);
267 smb2_adjust_credits(struct TCP_Server_Info *server,
268 struct cifs_credits *credits,
269 const unsigned int payload_size)
271 int new_val = DIV_ROUND_UP(payload_size, SMB2_MAX_BUFFER_SIZE);
272 int scredits, in_flight;
274 if (!credits->value || credits->value == new_val)
277 if (credits->value < new_val) {
278 trace_smb3_too_many_credits(server->CurrentMid,
279 server->conn_id, server->hostname, 0, credits->value - new_val, 0);
280 cifs_server_dbg(VFS, "request has less credits (%d) than required (%d)",
281 credits->value, new_val);
286 spin_lock(&server->req_lock);
288 if (server->reconnect_instance != credits->instance) {
289 scredits = server->credits;
290 in_flight = server->in_flight;
291 spin_unlock(&server->req_lock);
293 trace_smb3_reconnect_detected(server->CurrentMid,
294 server->conn_id, server->hostname, scredits,
295 credits->value - new_val, in_flight);
296 cifs_server_dbg(VFS, "trying to return %d credits to old session\n",
297 credits->value - new_val);
301 server->credits += credits->value - new_val;
302 scredits = server->credits;
303 in_flight = server->in_flight;
304 spin_unlock(&server->req_lock);
305 wake_up(&server->request_q);
307 trace_smb3_adj_credits(server->CurrentMid,
308 server->conn_id, server->hostname, scredits,
309 credits->value - new_val, in_flight);
310 cifs_dbg(FYI, "%s: adjust added %u credits total=%d\n",
311 __func__, credits->value - new_val, scredits);
313 credits->value = new_val;
319 smb2_get_next_mid(struct TCP_Server_Info *server)
322 /* for SMB2 we need the current value */
323 spin_lock(&server->mid_lock);
324 mid = server->CurrentMid++;
325 spin_unlock(&server->mid_lock);
330 smb2_revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
332 spin_lock(&server->mid_lock);
333 if (server->CurrentMid >= val)
334 server->CurrentMid -= val;
335 spin_unlock(&server->mid_lock);
338 static struct mid_q_entry *
339 __smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue)
341 struct mid_q_entry *mid;
342 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
343 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
345 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
346 cifs_server_dbg(VFS, "Encrypted frame parsing not supported yet\n");
350 spin_lock(&server->mid_lock);
351 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
352 if ((mid->mid == wire_mid) &&
353 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
354 (mid->command == shdr->Command)) {
355 kref_get(&mid->refcount);
357 list_del_init(&mid->qhead);
358 mid->mid_flags |= MID_DELETED;
360 spin_unlock(&server->mid_lock);
364 spin_unlock(&server->mid_lock);
368 static struct mid_q_entry *
369 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
371 return __smb2_find_mid(server, buf, false);
374 static struct mid_q_entry *
375 smb2_find_dequeue_mid(struct TCP_Server_Info *server, char *buf)
377 return __smb2_find_mid(server, buf, true);
381 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
383 #ifdef CONFIG_CIFS_DEBUG2
384 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
386 cifs_server_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
387 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
388 shdr->Id.SyncId.ProcessId);
389 cifs_server_dbg(VFS, "smb buf %p len %u\n", buf,
390 server->ops->calc_smb_size(buf));
395 smb2_need_neg(struct TCP_Server_Info *server)
397 return server->max_read == 0;
401 smb2_negotiate(const unsigned int xid,
402 struct cifs_ses *ses,
403 struct TCP_Server_Info *server)
407 spin_lock(&server->mid_lock);
408 server->CurrentMid = 0;
409 spin_unlock(&server->mid_lock);
410 rc = SMB2_negotiate(xid, ses, server);
411 /* BB we probably don't need to retry with modern servers */
418 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
420 struct TCP_Server_Info *server = tcon->ses->server;
423 /* start with specified wsize, or default */
424 wsize = ctx->wsize ? ctx->wsize : CIFS_DEFAULT_IOSIZE;
425 wsize = min_t(unsigned int, wsize, server->max_write);
426 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
427 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
433 smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
435 struct TCP_Server_Info *server = tcon->ses->server;
438 /* start with specified wsize, or default */
439 wsize = ctx->wsize ? ctx->wsize : SMB3_DEFAULT_IOSIZE;
440 wsize = min_t(unsigned int, wsize, server->max_write);
441 #ifdef CONFIG_CIFS_SMB_DIRECT
445 * Account for SMB2 data transfer packet header and
446 * possible encryption header
448 wsize = min_t(unsigned int,
450 server->smbd_conn->max_fragmented_send_size -
451 SMB2_READWRITE_PDU_HEADER_SIZE -
452 sizeof(struct smb2_transform_hdr));
454 wsize = min_t(unsigned int,
455 wsize, server->smbd_conn->max_readwrite_size);
458 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
459 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
465 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
467 struct TCP_Server_Info *server = tcon->ses->server;
470 /* start with specified rsize, or default */
471 rsize = ctx->rsize ? ctx->rsize : CIFS_DEFAULT_IOSIZE;
472 rsize = min_t(unsigned int, rsize, server->max_read);
474 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
475 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
481 smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
483 struct TCP_Server_Info *server = tcon->ses->server;
486 /* start with specified rsize, or default */
487 rsize = ctx->rsize ? ctx->rsize : SMB3_DEFAULT_IOSIZE;
488 rsize = min_t(unsigned int, rsize, server->max_read);
489 #ifdef CONFIG_CIFS_SMB_DIRECT
493 * Account for SMB2 data transfer packet header and
494 * possible encryption header
496 rsize = min_t(unsigned int,
498 server->smbd_conn->max_fragmented_recv_size -
499 SMB2_READWRITE_PDU_HEADER_SIZE -
500 sizeof(struct smb2_transform_hdr));
502 rsize = min_t(unsigned int,
503 rsize, server->smbd_conn->max_readwrite_size);
507 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
508 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
514 parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
515 size_t buf_len, struct cifs_ses *ses, bool in_mount)
517 struct network_interface_info_ioctl_rsp *p;
518 struct sockaddr_in *addr4;
519 struct sockaddr_in6 *addr6;
520 struct iface_info_ipv4 *p4;
521 struct iface_info_ipv6 *p6;
522 struct cifs_server_iface *info = NULL, *iface = NULL, *niface = NULL;
523 struct cifs_server_iface tmp_iface;
529 bytes_left = buf_len;
532 spin_lock(&ses->iface_lock);
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)
801 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
802 int err_buftype = CIFS_NO_BUFFER;
803 struct cifs_open_parms oparms;
804 struct kvec err_iov = {};
806 struct cached_fid *cfid;
808 rc = open_cached_dir(xid, tcon, full_path, cifs_sb, true, &cfid);
810 if (cfid->has_lease) {
811 close_cached_dir(cfid);
814 close_cached_dir(cfid);
817 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
821 oparms = (struct cifs_open_parms) {
823 .desired_access = FILE_READ_ATTRIBUTES,
824 .disposition = FILE_OPEN,
825 .create_options = cifs_create_options(cifs_sb, 0),
829 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
830 &err_iov, &err_buftype);
832 struct smb2_hdr *hdr = err_iov.iov_base;
834 if (unlikely(!hdr || err_buftype == CIFS_NO_BUFFER))
837 * Handle weird Windows SMB server behaviour. It responds with
838 * STATUS_OBJECT_NAME_INVALID code to SMB2 QUERY_INFO request
839 * for "\<server>\<dfsname>\<linkpath>" DFS reference,
840 * where <dfsname> contains non-ASCII unicode symbols.
842 if (rc != -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) &&
843 hdr->Status == STATUS_OBJECT_NAME_INVALID)
845 if (rc == -EREMOTE && IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) && cifs_sb &&
846 (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_DFS))
851 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
854 free_rsp_buf(err_buftype, err_iov.iov_base);
859 static int smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
860 struct cifs_sb_info *cifs_sb, const char *full_path,
861 u64 *uniqueid, struct cifs_open_info_data *data)
863 *uniqueid = le64_to_cpu(data->fi.IndexNumber);
867 static int smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
868 struct cifsFileInfo *cfile, struct cifs_open_info_data *data)
870 struct cifs_fid *fid = &cfile->fid;
872 if (cfile->symlink_target) {
873 data->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
874 if (!data->symlink_target)
877 return SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, &data->fi);
880 #ifdef CONFIG_CIFS_XATTR
882 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
883 struct smb2_file_full_ea_info *src, size_t src_size,
884 const unsigned char *ea_name)
887 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
889 size_t buf_size = dst_size;
890 size_t name_len, value_len, user_name_len;
892 while (src_size > 0) {
893 name_len = (size_t)src->ea_name_length;
894 value_len = (size_t)le16_to_cpu(src->ea_value_length);
899 if (src_size < 8 + name_len + 1 + value_len) {
900 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
905 name = &src->ea_data[0];
906 value = &src->ea_data[src->ea_name_length + 1];
909 if (ea_name_len == name_len &&
910 memcmp(ea_name, name, name_len) == 0) {
914 if (dst_size < value_len) {
918 memcpy(dst, value, value_len);
922 /* 'user.' plus a terminating null */
923 user_name_len = 5 + 1 + name_len;
926 /* skip copy - calc size only */
928 } else if (dst_size >= user_name_len) {
929 dst_size -= user_name_len;
930 memcpy(dst, "user.", 5);
932 memcpy(dst, src->ea_data, name_len);
938 /* stop before overrun buffer */
944 if (!src->next_entry_offset)
947 if (src_size < le32_to_cpu(src->next_entry_offset)) {
948 /* stop before overrun buffer */
952 src_size -= le32_to_cpu(src->next_entry_offset);
953 src = (void *)((char *)src +
954 le32_to_cpu(src->next_entry_offset));
957 /* didn't find the named attribute */
966 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
967 const unsigned char *path, const unsigned char *ea_name,
968 char *ea_data, size_t buf_size,
969 struct cifs_sb_info *cifs_sb)
972 struct kvec rsp_iov = {NULL, 0};
973 int buftype = CIFS_NO_BUFFER;
974 struct smb2_query_info_rsp *rsp;
975 struct smb2_file_full_ea_info *info = NULL;
977 rc = smb2_query_info_compound(xid, tcon, path,
979 FILE_FULL_EA_INFORMATION,
982 MAX_SMB2_CREATE_RESPONSE_SIZE -
983 MAX_SMB2_CLOSE_RESPONSE_SIZE,
984 &rsp_iov, &buftype, cifs_sb);
987 * If ea_name is NULL (listxattr) and there are no EAs,
988 * return 0 as it's not an error. Otherwise, the specified
989 * ea_name was not found.
991 if (!ea_name && rc == -ENODATA)
996 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
997 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
998 le32_to_cpu(rsp->OutputBufferLength),
1000 sizeof(struct smb2_file_full_ea_info));
1004 info = (struct smb2_file_full_ea_info *)(
1005 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1006 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
1007 le32_to_cpu(rsp->OutputBufferLength), ea_name);
1010 free_rsp_buf(buftype, rsp_iov.iov_base);
1016 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
1017 const char *path, const char *ea_name, const void *ea_value,
1018 const __u16 ea_value_len, const struct nls_table *nls_codepage,
1019 struct cifs_sb_info *cifs_sb)
1021 struct cifs_ses *ses = tcon->ses;
1022 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1023 __le16 *utf16_path = NULL;
1024 int ea_name_len = strlen(ea_name);
1025 int flags = CIFS_CP_CREATE_CLOSE_OP;
1027 struct smb_rqst rqst[3];
1028 int resp_buftype[3];
1029 struct kvec rsp_iov[3];
1030 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1031 struct cifs_open_parms oparms;
1032 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1033 struct cifs_fid fid;
1034 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1035 unsigned int size[1];
1037 struct smb2_file_full_ea_info *ea = NULL;
1038 struct kvec close_iov[1];
1039 struct smb2_query_info_rsp *rsp;
1040 int rc, used_len = 0;
1042 if (smb3_encryption_required(tcon))
1043 flags |= CIFS_TRANSFORM_REQ;
1045 if (ea_name_len > 255)
1048 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1052 memset(rqst, 0, sizeof(rqst));
1053 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1054 memset(rsp_iov, 0, sizeof(rsp_iov));
1056 if (ses->server->ops->query_all_EAs) {
1058 rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1064 /* If we are adding a attribute we should first check
1065 * if there will be enough space available to store
1066 * the new EA. If not we should not add it since we
1067 * would not be able to even read the EAs back.
1069 rc = smb2_query_info_compound(xid, tcon, path,
1071 FILE_FULL_EA_INFORMATION,
1074 MAX_SMB2_CREATE_RESPONSE_SIZE -
1075 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1076 &rsp_iov[1], &resp_buftype[1], cifs_sb);
1078 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1079 used_len = le32_to_cpu(rsp->OutputBufferLength);
1081 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1082 resp_buftype[1] = CIFS_NO_BUFFER;
1083 memset(&rsp_iov[1], 0, sizeof(rsp_iov[1]));
1086 /* Use a fudge factor of 256 bytes in case we collide
1087 * with a different set_EAs command.
1089 if(CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1090 MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 <
1091 used_len + ea_name_len + ea_value_len + 1) {
1099 memset(&open_iov, 0, sizeof(open_iov));
1100 rqst[0].rq_iov = open_iov;
1101 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1103 oparms = (struct cifs_open_parms) {
1105 .desired_access = FILE_WRITE_EA,
1106 .disposition = FILE_OPEN,
1107 .create_options = cifs_create_options(cifs_sb, 0),
1111 rc = SMB2_open_init(tcon, server,
1112 &rqst[0], &oplock, &oparms, utf16_path);
1115 smb2_set_next_command(tcon, &rqst[0]);
1119 memset(&si_iov, 0, sizeof(si_iov));
1120 rqst[1].rq_iov = si_iov;
1121 rqst[1].rq_nvec = 1;
1123 len = sizeof(*ea) + ea_name_len + ea_value_len + 1;
1124 ea = kzalloc(len, GFP_KERNEL);
1130 ea->ea_name_length = ea_name_len;
1131 ea->ea_value_length = cpu_to_le16(ea_value_len);
1132 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
1133 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
1138 rc = SMB2_set_info_init(tcon, server,
1139 &rqst[1], COMPOUND_FID,
1140 COMPOUND_FID, current->tgid,
1141 FILE_FULL_EA_INFORMATION,
1142 SMB2_O_INFO_FILE, 0, data, size);
1145 smb2_set_next_command(tcon, &rqst[1]);
1146 smb2_set_related(&rqst[1]);
1150 memset(&close_iov, 0, sizeof(close_iov));
1151 rqst[2].rq_iov = close_iov;
1152 rqst[2].rq_nvec = 1;
1153 rc = SMB2_close_init(tcon, server,
1154 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1157 smb2_set_related(&rqst[2]);
1159 rc = compound_send_recv(xid, ses, server,
1161 resp_buftype, rsp_iov);
1162 /* no need to bump num_remote_opens because handle immediately closed */
1167 SMB2_open_free(&rqst[0]);
1168 SMB2_set_info_free(&rqst[1]);
1169 SMB2_close_free(&rqst[2]);
1170 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1171 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1172 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1178 smb2_can_echo(struct TCP_Server_Info *server)
1180 return server->echoes;
1184 smb2_clear_stats(struct cifs_tcon *tcon)
1188 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1189 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1190 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1195 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1197 seq_puts(m, "\n\tShare Capabilities:");
1198 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1199 seq_puts(m, " DFS,");
1200 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1201 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1202 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1203 seq_puts(m, " SCALEOUT,");
1204 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1205 seq_puts(m, " CLUSTER,");
1206 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1207 seq_puts(m, " ASYMMETRIC,");
1208 if (tcon->capabilities == 0)
1209 seq_puts(m, " None");
1210 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1211 seq_puts(m, " Aligned,");
1212 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1213 seq_puts(m, " Partition Aligned,");
1214 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1215 seq_puts(m, " SSD,");
1216 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1217 seq_puts(m, " TRIM-support,");
1219 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1220 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1221 if (tcon->perf_sector_size)
1222 seq_printf(m, "\tOptimal sector size: 0x%x",
1223 tcon->perf_sector_size);
1224 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1228 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1230 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1231 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1234 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1235 * totals (requests sent) since those SMBs are per-session not per tcon
1237 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1238 (long long)(tcon->bytes_read),
1239 (long long)(tcon->bytes_written));
1240 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1241 atomic_read(&tcon->num_local_opens),
1242 atomic_read(&tcon->num_remote_opens));
1243 seq_printf(m, "\nTreeConnects: %d total %d failed",
1244 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1245 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1246 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1247 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1248 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1249 seq_printf(m, "\nCreates: %d total %d failed",
1250 atomic_read(&sent[SMB2_CREATE_HE]),
1251 atomic_read(&failed[SMB2_CREATE_HE]));
1252 seq_printf(m, "\nCloses: %d total %d failed",
1253 atomic_read(&sent[SMB2_CLOSE_HE]),
1254 atomic_read(&failed[SMB2_CLOSE_HE]));
1255 seq_printf(m, "\nFlushes: %d total %d failed",
1256 atomic_read(&sent[SMB2_FLUSH_HE]),
1257 atomic_read(&failed[SMB2_FLUSH_HE]));
1258 seq_printf(m, "\nReads: %d total %d failed",
1259 atomic_read(&sent[SMB2_READ_HE]),
1260 atomic_read(&failed[SMB2_READ_HE]));
1261 seq_printf(m, "\nWrites: %d total %d failed",
1262 atomic_read(&sent[SMB2_WRITE_HE]),
1263 atomic_read(&failed[SMB2_WRITE_HE]));
1264 seq_printf(m, "\nLocks: %d total %d failed",
1265 atomic_read(&sent[SMB2_LOCK_HE]),
1266 atomic_read(&failed[SMB2_LOCK_HE]));
1267 seq_printf(m, "\nIOCTLs: %d total %d failed",
1268 atomic_read(&sent[SMB2_IOCTL_HE]),
1269 atomic_read(&failed[SMB2_IOCTL_HE]));
1270 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1271 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1272 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1273 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1274 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1275 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1276 seq_printf(m, "\nQueryInfos: %d total %d failed",
1277 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1278 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1279 seq_printf(m, "\nSetInfos: %d total %d failed",
1280 atomic_read(&sent[SMB2_SET_INFO_HE]),
1281 atomic_read(&failed[SMB2_SET_INFO_HE]));
1282 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1283 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1284 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1288 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1290 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1291 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1293 cfile->fid.persistent_fid = fid->persistent_fid;
1294 cfile->fid.volatile_fid = fid->volatile_fid;
1295 cfile->fid.access = fid->access;
1296 #ifdef CONFIG_CIFS_DEBUG2
1297 cfile->fid.mid = fid->mid;
1298 #endif /* CIFS_DEBUG2 */
1299 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1301 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1302 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1306 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1307 struct cifs_fid *fid)
1309 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1313 smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon,
1314 struct cifsFileInfo *cfile)
1316 struct smb2_file_network_open_info file_inf;
1317 struct inode *inode;
1320 rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid,
1321 cfile->fid.volatile_fid, &file_inf);
1325 inode = d_inode(cfile->dentry);
1327 spin_lock(&inode->i_lock);
1328 CIFS_I(inode)->time = jiffies;
1330 /* Creation time should not need to be updated on close */
1331 if (file_inf.LastWriteTime)
1332 inode->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime);
1333 if (file_inf.ChangeTime)
1334 inode->i_ctime = cifs_NTtimeToUnix(file_inf.ChangeTime);
1335 if (file_inf.LastAccessTime)
1336 inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime);
1339 * i_blocks is not related to (i_size / i_blksize),
1340 * but instead 512 byte (2**9) size is required for
1341 * calculating num blocks.
1343 if (le64_to_cpu(file_inf.AllocationSize) > 4096)
1345 (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9;
1347 /* End of file and Attributes should not have to be updated on close */
1348 spin_unlock(&inode->i_lock);
1352 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1353 u64 persistent_fid, u64 volatile_fid,
1354 struct copychunk_ioctl *pcchunk)
1357 unsigned int ret_data_len;
1358 struct resume_key_req *res_key;
1360 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1361 FSCTL_SRV_REQUEST_RESUME_KEY, NULL, 0 /* no input */,
1362 CIFSMaxBufSize, (char **)&res_key, &ret_data_len);
1364 if (rc == -EOPNOTSUPP) {
1365 pr_warn_once("Server share %s does not support copy range\n", tcon->tree_name);
1366 goto req_res_key_exit;
1368 cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1369 goto req_res_key_exit;
1371 if (ret_data_len < sizeof(struct resume_key_req)) {
1372 cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n");
1374 goto req_res_key_exit;
1376 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1384 struct smb_rqst rqst[3];
1385 struct kvec rsp_iov[3];
1386 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1387 struct kvec qi_iov[1];
1388 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
1389 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1390 struct kvec close_iov[1];
1394 smb2_ioctl_query_info(const unsigned int xid,
1395 struct cifs_tcon *tcon,
1396 struct cifs_sb_info *cifs_sb,
1397 __le16 *path, int is_dir,
1400 struct iqi_vars *vars;
1401 struct smb_rqst *rqst;
1402 struct kvec *rsp_iov;
1403 struct cifs_ses *ses = tcon->ses;
1404 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1405 char __user *arg = (char __user *)p;
1406 struct smb_query_info qi;
1407 struct smb_query_info __user *pqi;
1409 int flags = CIFS_CP_CREATE_CLOSE_OP;
1410 struct smb2_query_info_rsp *qi_rsp = NULL;
1411 struct smb2_ioctl_rsp *io_rsp = NULL;
1412 void *buffer = NULL;
1413 int resp_buftype[3];
1414 struct cifs_open_parms oparms;
1415 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1416 struct cifs_fid fid;
1417 unsigned int size[2];
1419 int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR;
1420 void (*free_req1_func)(struct smb_rqst *r);
1422 vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
1425 rqst = &vars->rqst[0];
1426 rsp_iov = &vars->rsp_iov[0];
1428 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1430 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info))) {
1434 if (qi.output_buffer_length > 1024) {
1439 if (!ses || !server) {
1444 if (smb3_encryption_required(tcon))
1445 flags |= CIFS_TRANSFORM_REQ;
1447 if (qi.output_buffer_length) {
1448 buffer = memdup_user(arg + sizeof(struct smb_query_info), qi.output_buffer_length);
1449 if (IS_ERR(buffer)) {
1450 rc = PTR_ERR(buffer);
1456 rqst[0].rq_iov = &vars->open_iov[0];
1457 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1459 oparms = (struct cifs_open_parms) {
1461 .disposition = FILE_OPEN,
1462 .create_options = cifs_create_options(cifs_sb, create_options),
1466 if (qi.flags & PASSTHRU_FSCTL) {
1467 switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1468 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1469 oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1471 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1472 oparms.desired_access = GENERIC_ALL;
1474 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1475 oparms.desired_access = GENERIC_READ;
1477 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1478 oparms.desired_access = GENERIC_WRITE;
1481 } else if (qi.flags & PASSTHRU_SET_INFO) {
1482 oparms.desired_access = GENERIC_WRITE;
1484 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1487 rc = SMB2_open_init(tcon, server,
1488 &rqst[0], &oplock, &oparms, path);
1490 goto free_output_buffer;
1491 smb2_set_next_command(tcon, &rqst[0]);
1494 if (qi.flags & PASSTHRU_FSCTL) {
1495 /* Can eventually relax perm check since server enforces too */
1496 if (!capable(CAP_SYS_ADMIN)) {
1500 rqst[1].rq_iov = &vars->io_iov[0];
1501 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1503 rc = SMB2_ioctl_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1504 qi.info_type, buffer, qi.output_buffer_length,
1505 CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1506 MAX_SMB2_CLOSE_RESPONSE_SIZE);
1507 free_req1_func = SMB2_ioctl_free;
1508 } else if (qi.flags == PASSTHRU_SET_INFO) {
1509 /* Can eventually relax perm check since server enforces too */
1510 if (!capable(CAP_SYS_ADMIN)) {
1514 if (qi.output_buffer_length < 8) {
1518 rqst[1].rq_iov = &vars->si_iov[0];
1519 rqst[1].rq_nvec = 1;
1521 /* MS-FSCC 2.4.13 FileEndOfFileInformation */
1525 rc = SMB2_set_info_init(tcon, server, &rqst[1], COMPOUND_FID, COMPOUND_FID,
1526 current->tgid, FILE_END_OF_FILE_INFORMATION,
1527 SMB2_O_INFO_FILE, 0, data, size);
1528 free_req1_func = SMB2_set_info_free;
1529 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1530 rqst[1].rq_iov = &vars->qi_iov[0];
1531 rqst[1].rq_nvec = 1;
1533 rc = SMB2_query_info_init(tcon, server,
1534 &rqst[1], COMPOUND_FID,
1535 COMPOUND_FID, qi.file_info_class,
1536 qi.info_type, qi.additional_information,
1537 qi.input_buffer_length,
1538 qi.output_buffer_length, buffer);
1539 free_req1_func = SMB2_query_info_free;
1540 } else { /* unknown flags */
1541 cifs_tcon_dbg(VFS, "Invalid passthru query flags: 0x%x\n",
1548 smb2_set_next_command(tcon, &rqst[1]);
1549 smb2_set_related(&rqst[1]);
1552 rqst[2].rq_iov = &vars->close_iov[0];
1553 rqst[2].rq_nvec = 1;
1555 rc = SMB2_close_init(tcon, server,
1556 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1559 smb2_set_related(&rqst[2]);
1561 rc = compound_send_recv(xid, ses, server,
1563 resp_buftype, rsp_iov);
1567 /* No need to bump num_remote_opens since handle immediately closed */
1568 if (qi.flags & PASSTHRU_FSCTL) {
1569 pqi = (struct smb_query_info __user *)arg;
1570 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1571 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1572 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1573 if (qi.input_buffer_length > 0 &&
1574 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length
1575 > rsp_iov[1].iov_len) {
1580 if (copy_to_user(&pqi->input_buffer_length,
1581 &qi.input_buffer_length,
1582 sizeof(qi.input_buffer_length))) {
1587 if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1588 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1589 qi.input_buffer_length))
1592 pqi = (struct smb_query_info __user *)arg;
1593 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1594 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1595 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1596 if (copy_to_user(&pqi->input_buffer_length,
1597 &qi.input_buffer_length,
1598 sizeof(qi.input_buffer_length))) {
1603 if (copy_to_user(pqi + 1, qi_rsp->Buffer,
1604 qi.input_buffer_length))
1609 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1610 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1611 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1612 SMB2_close_free(&rqst[2]);
1614 free_req1_func(&rqst[1]);
1616 SMB2_open_free(&rqst[0]);
1625 smb2_copychunk_range(const unsigned int xid,
1626 struct cifsFileInfo *srcfile,
1627 struct cifsFileInfo *trgtfile, u64 src_off,
1628 u64 len, u64 dest_off)
1631 unsigned int ret_data_len;
1632 struct copychunk_ioctl *pcchunk;
1633 struct copychunk_ioctl_rsp *retbuf = NULL;
1634 struct cifs_tcon *tcon;
1635 int chunks_copied = 0;
1636 bool chunk_sizes_updated = false;
1637 ssize_t bytes_written, total_bytes_written = 0;
1639 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1640 if (pcchunk == NULL)
1643 cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
1644 /* Request a key from the server to identify the source of the copy */
1645 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1646 srcfile->fid.persistent_fid,
1647 srcfile->fid.volatile_fid, pcchunk);
1649 /* Note: request_res_key sets res_key null only if rc !=0 */
1653 /* For now array only one chunk long, will make more flexible later */
1654 pcchunk->ChunkCount = cpu_to_le32(1);
1655 pcchunk->Reserved = 0;
1656 pcchunk->Reserved2 = 0;
1658 tcon = tlink_tcon(trgtfile->tlink);
1661 pcchunk->SourceOffset = cpu_to_le64(src_off);
1662 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1664 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
1666 /* Request server copy to target from src identified by key */
1669 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1670 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1671 (char *)pcchunk, sizeof(struct copychunk_ioctl),
1672 CIFSMaxBufSize, (char **)&retbuf, &ret_data_len);
1675 sizeof(struct copychunk_ioctl_rsp)) {
1676 cifs_tcon_dbg(VFS, "Invalid cchunk response size\n");
1680 if (retbuf->TotalBytesWritten == 0) {
1681 cifs_dbg(FYI, "no bytes copied\n");
1686 * Check if server claimed to write more than we asked
1688 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1689 le32_to_cpu(pcchunk->Length)) {
1690 cifs_tcon_dbg(VFS, "Invalid copy chunk response\n");
1694 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1695 cifs_tcon_dbg(VFS, "Invalid num chunks written\n");
1701 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1702 src_off += bytes_written;
1703 dest_off += bytes_written;
1704 len -= bytes_written;
1705 total_bytes_written += bytes_written;
1707 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1708 le32_to_cpu(retbuf->ChunksWritten),
1709 le32_to_cpu(retbuf->ChunkBytesWritten),
1711 } else if (rc == -EINVAL) {
1712 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1715 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1716 le32_to_cpu(retbuf->ChunksWritten),
1717 le32_to_cpu(retbuf->ChunkBytesWritten),
1718 le32_to_cpu(retbuf->TotalBytesWritten));
1721 * Check if this is the first request using these sizes,
1722 * (ie check if copy succeed once with original sizes
1723 * and check if the server gave us different sizes after
1724 * we already updated max sizes on previous request).
1725 * if not then why is the server returning an error now
1727 if ((chunks_copied != 0) || chunk_sizes_updated)
1730 /* Check that server is not asking us to grow size */
1731 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1732 tcon->max_bytes_chunk)
1733 tcon->max_bytes_chunk =
1734 le32_to_cpu(retbuf->ChunkBytesWritten);
1736 goto cchunk_out; /* server gave us bogus size */
1738 /* No need to change MaxChunks since already set to 1 */
1739 chunk_sizes_updated = true;
1750 return total_bytes_written;
1754 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1755 struct cifs_fid *fid)
1757 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1761 smb2_read_data_offset(char *buf)
1763 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1765 return rsp->DataOffset;
1769 smb2_read_data_length(char *buf, bool in_remaining)
1771 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1774 return le32_to_cpu(rsp->DataRemaining);
1776 return le32_to_cpu(rsp->DataLength);
1781 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1782 struct cifs_io_parms *parms, unsigned int *bytes_read,
1783 char **buf, int *buf_type)
1785 parms->persistent_fid = pfid->persistent_fid;
1786 parms->volatile_fid = pfid->volatile_fid;
1787 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1791 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1792 struct cifs_io_parms *parms, unsigned int *written,
1793 struct kvec *iov, unsigned long nr_segs)
1796 parms->persistent_fid = pfid->persistent_fid;
1797 parms->volatile_fid = pfid->volatile_fid;
1798 return SMB2_write(xid, parms, written, iov, nr_segs);
1801 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1802 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1803 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1805 struct cifsInodeInfo *cifsi;
1808 cifsi = CIFS_I(inode);
1810 /* if file already sparse don't bother setting sparse again */
1811 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1812 return true; /* already sparse */
1814 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1815 return true; /* already not sparse */
1818 * Can't check for sparse support on share the usual way via the
1819 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1820 * since Samba server doesn't set the flag on the share, yet
1821 * supports the set sparse FSCTL and returns sparse correctly
1822 * in the file attributes. If we fail setting sparse though we
1823 * mark that server does not support sparse files for this share
1824 * to avoid repeatedly sending the unsupported fsctl to server
1825 * if the file is repeatedly extended.
1827 if (tcon->broken_sparse_sup)
1830 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1831 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1832 &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
1834 tcon->broken_sparse_sup = true;
1835 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1840 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1842 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1848 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1849 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1851 __le64 eof = cpu_to_le64(size);
1852 struct inode *inode;
1855 * If extending file more than one page make sparse. Many Linux fs
1856 * make files sparse by default when extending via ftruncate
1858 inode = d_inode(cfile->dentry);
1860 if (!set_alloc && (size > inode->i_size + 8192)) {
1861 __u8 set_sparse = 1;
1863 /* whether set sparse succeeds or not, extend the file */
1864 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1867 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1868 cfile->fid.volatile_fid, cfile->pid, &eof);
1872 smb2_duplicate_extents(const unsigned int xid,
1873 struct cifsFileInfo *srcfile,
1874 struct cifsFileInfo *trgtfile, u64 src_off,
1875 u64 len, u64 dest_off)
1878 unsigned int ret_data_len;
1879 struct inode *inode;
1880 struct duplicate_extents_to_file dup_ext_buf;
1881 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1883 /* server fileays advertise duplicate extent support with this flag */
1884 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1885 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1888 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1889 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1890 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1891 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1892 dup_ext_buf.ByteCount = cpu_to_le64(len);
1893 cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
1894 src_off, dest_off, len);
1896 inode = d_inode(trgtfile->dentry);
1897 if (inode->i_size < dest_off + len) {
1898 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1900 goto duplicate_extents_out;
1903 * Although also could set plausible allocation size (i_blocks)
1904 * here in addition to setting the file size, in reflink
1905 * it is likely that the target file is sparse. Its allocation
1906 * size will be queried on next revalidate, but it is important
1907 * to make sure that file's cached size is updated immediately
1909 cifs_setsize(inode, dest_off + len);
1911 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1912 trgtfile->fid.volatile_fid,
1913 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1914 (char *)&dup_ext_buf,
1915 sizeof(struct duplicate_extents_to_file),
1916 CIFSMaxBufSize, NULL,
1919 if (ret_data_len > 0)
1920 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
1922 duplicate_extents_out:
1927 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1928 struct cifsFileInfo *cfile)
1930 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1931 cfile->fid.volatile_fid);
1935 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
1936 struct cifsFileInfo *cfile)
1938 struct fsctl_set_integrity_information_req integr_info;
1939 unsigned int ret_data_len;
1941 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
1942 integr_info.Flags = 0;
1943 integr_info.Reserved = 0;
1945 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1946 cfile->fid.volatile_fid,
1947 FSCTL_SET_INTEGRITY_INFORMATION,
1948 (char *)&integr_info,
1949 sizeof(struct fsctl_set_integrity_information_req),
1950 CIFSMaxBufSize, NULL,
1955 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
1956 #define GMT_TOKEN_SIZE 50
1958 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
1961 * Input buffer contains (empty) struct smb_snapshot array with size filled in
1962 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
1965 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
1966 struct cifsFileInfo *cfile, void __user *ioc_buf)
1968 char *retbuf = NULL;
1969 unsigned int ret_data_len = 0;
1971 u32 max_response_size;
1972 struct smb_snapshot_array snapshot_in;
1975 * On the first query to enumerate the list of snapshots available
1976 * for this volume the buffer begins with 0 (number of snapshots
1977 * which can be returned is zero since at that point we do not know
1978 * how big the buffer needs to be). On the second query,
1979 * it (ret_data_len) is set to number of snapshots so we can
1980 * know to set the maximum response size larger (see below).
1982 if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
1986 * Note that for snapshot queries that servers like Azure expect that
1987 * the first query be minimal size (and just used to get the number/size
1988 * of previous versions) so response size must be specified as EXACTLY
1989 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
1992 if (ret_data_len == 0)
1993 max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
1995 max_response_size = CIFSMaxBufSize;
1997 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1998 cfile->fid.volatile_fid,
1999 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
2000 NULL, 0 /* no input data */, max_response_size,
2003 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
2008 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
2010 if (copy_from_user(&snapshot_in, ioc_buf,
2011 sizeof(struct smb_snapshot_array))) {
2018 * Check for min size, ie not large enough to fit even one GMT
2019 * token (snapshot). On the first ioctl some users may pass in
2020 * smaller size (or zero) to simply get the size of the array
2021 * so the user space caller can allocate sufficient memory
2022 * and retry the ioctl again with larger array size sufficient
2023 * to hold all of the snapshot GMT tokens on the second try.
2025 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
2026 ret_data_len = sizeof(struct smb_snapshot_array);
2029 * We return struct SRV_SNAPSHOT_ARRAY, followed by
2030 * the snapshot array (of 50 byte GMT tokens) each
2031 * representing an available previous version of the data
2033 if (ret_data_len > (snapshot_in.snapshot_array_size +
2034 sizeof(struct smb_snapshot_array)))
2035 ret_data_len = snapshot_in.snapshot_array_size +
2036 sizeof(struct smb_snapshot_array);
2038 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
2049 smb3_notify(const unsigned int xid, struct file *pfile,
2050 void __user *ioc_buf, bool return_changes)
2052 struct smb3_notify_info notify;
2053 struct smb3_notify_info __user *pnotify_buf;
2054 struct dentry *dentry = pfile->f_path.dentry;
2055 struct inode *inode = file_inode(pfile);
2056 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2057 struct cifs_open_parms oparms;
2058 struct cifs_fid fid;
2059 struct cifs_tcon *tcon;
2060 const unsigned char *path;
2061 char *returned_ioctl_info = NULL;
2062 void *page = alloc_dentry_path();
2063 __le16 *utf16_path = NULL;
2064 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2068 path = build_path_from_dentry(dentry, page);
2074 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2075 if (utf16_path == NULL) {
2080 if (return_changes) {
2081 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify_info))) {
2086 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify))) {
2090 notify.data_len = 0;
2093 tcon = cifs_sb_master_tcon(cifs_sb);
2094 oparms = (struct cifs_open_parms) {
2096 .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
2097 .disposition = FILE_OPEN,
2098 .create_options = cifs_create_options(cifs_sb, 0),
2102 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
2107 rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid,
2108 notify.watch_tree, notify.completion_filter,
2109 notify.data_len, &returned_ioctl_info, &ret_len);
2111 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2113 cifs_dbg(FYI, "change notify for path %s rc %d\n", path, rc);
2114 if (return_changes && (ret_len > 0) && (notify.data_len > 0)) {
2115 if (ret_len > notify.data_len)
2116 ret_len = notify.data_len;
2117 pnotify_buf = (struct smb3_notify_info __user *)ioc_buf;
2118 if (copy_to_user(pnotify_buf->notify_data, returned_ioctl_info, ret_len))
2120 else if (copy_to_user(&pnotify_buf->data_len, &ret_len, sizeof(ret_len)))
2123 kfree(returned_ioctl_info);
2125 free_dentry_path(page);
2131 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
2132 const char *path, struct cifs_sb_info *cifs_sb,
2133 struct cifs_fid *fid, __u16 search_flags,
2134 struct cifs_search_info *srch_inf)
2137 struct smb_rqst rqst[2];
2138 struct kvec rsp_iov[2];
2139 int resp_buftype[2];
2140 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2141 struct kvec qd_iov[SMB2_QUERY_DIRECTORY_IOV_SIZE];
2143 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2144 struct cifs_open_parms oparms;
2145 struct smb2_query_directory_rsp *qd_rsp = NULL;
2146 struct smb2_create_rsp *op_rsp = NULL;
2147 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2148 int retry_count = 0;
2150 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2154 if (smb3_encryption_required(tcon))
2155 flags |= CIFS_TRANSFORM_REQ;
2157 memset(rqst, 0, sizeof(rqst));
2158 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
2159 memset(rsp_iov, 0, sizeof(rsp_iov));
2162 memset(&open_iov, 0, sizeof(open_iov));
2163 rqst[0].rq_iov = open_iov;
2164 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2166 oparms = (struct cifs_open_parms) {
2168 .desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA,
2169 .disposition = FILE_OPEN,
2170 .create_options = cifs_create_options(cifs_sb, 0),
2174 rc = SMB2_open_init(tcon, server,
2175 &rqst[0], &oplock, &oparms, utf16_path);
2178 smb2_set_next_command(tcon, &rqst[0]);
2180 /* Query directory */
2181 srch_inf->entries_in_buffer = 0;
2182 srch_inf->index_of_last_entry = 2;
2184 memset(&qd_iov, 0, sizeof(qd_iov));
2185 rqst[1].rq_iov = qd_iov;
2186 rqst[1].rq_nvec = SMB2_QUERY_DIRECTORY_IOV_SIZE;
2188 rc = SMB2_query_directory_init(xid, tcon, server,
2190 COMPOUND_FID, COMPOUND_FID,
2191 0, srch_inf->info_level);
2195 smb2_set_related(&rqst[1]);
2198 rc = compound_send_recv(xid, tcon->ses, server,
2200 resp_buftype, rsp_iov);
2202 if (rc == -EAGAIN && retry_count++ < 10)
2205 /* If the open failed there is nothing to do */
2206 op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
2207 if (op_rsp == NULL || op_rsp->hdr.Status != STATUS_SUCCESS) {
2208 cifs_dbg(FYI, "query_dir_first: open failed rc=%d\n", rc);
2211 fid->persistent_fid = op_rsp->PersistentFileId;
2212 fid->volatile_fid = op_rsp->VolatileFileId;
2214 /* Anything else than ENODATA means a genuine error */
2215 if (rc && rc != -ENODATA) {
2216 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2217 cifs_dbg(FYI, "query_dir_first: query directory failed rc=%d\n", rc);
2218 trace_smb3_query_dir_err(xid, fid->persistent_fid,
2219 tcon->tid, tcon->ses->Suid, 0, 0, rc);
2223 atomic_inc(&tcon->num_remote_opens);
2225 qd_rsp = (struct smb2_query_directory_rsp *)rsp_iov[1].iov_base;
2226 if (qd_rsp->hdr.Status == STATUS_NO_MORE_FILES) {
2227 trace_smb3_query_dir_done(xid, fid->persistent_fid,
2228 tcon->tid, tcon->ses->Suid, 0, 0);
2229 srch_inf->endOfSearch = true;
2234 rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1],
2237 trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid,
2238 tcon->ses->Suid, 0, 0, rc);
2241 resp_buftype[1] = CIFS_NO_BUFFER;
2243 trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid,
2244 tcon->ses->Suid, 0, srch_inf->entries_in_buffer);
2248 SMB2_open_free(&rqst[0]);
2249 SMB2_query_directory_free(&rqst[1]);
2250 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2251 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2256 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
2257 struct cifs_fid *fid, __u16 search_flags,
2258 struct cifs_search_info *srch_inf)
2260 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
2261 fid->volatile_fid, 0, srch_inf);
2265 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
2266 struct cifs_fid *fid)
2268 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2272 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2273 * the number of credits and return true. Otherwise - return false.
2276 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
2278 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2279 int scredits, in_flight;
2281 if (shdr->Status != STATUS_PENDING)
2284 if (shdr->CreditRequest) {
2285 spin_lock(&server->req_lock);
2286 server->credits += le16_to_cpu(shdr->CreditRequest);
2287 scredits = server->credits;
2288 in_flight = server->in_flight;
2289 spin_unlock(&server->req_lock);
2290 wake_up(&server->request_q);
2292 trace_smb3_pend_credits(server->CurrentMid,
2293 server->conn_id, server->hostname, scredits,
2294 le16_to_cpu(shdr->CreditRequest), in_flight);
2295 cifs_dbg(FYI, "%s: status pending add %u credits total=%d\n",
2296 __func__, le16_to_cpu(shdr->CreditRequest), scredits);
2303 smb2_is_session_expired(char *buf)
2305 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2307 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
2308 shdr->Status != STATUS_USER_SESSION_DELETED)
2311 trace_smb3_ses_expired(le32_to_cpu(shdr->Id.SyncId.TreeId),
2312 le64_to_cpu(shdr->SessionId),
2313 le16_to_cpu(shdr->Command),
2314 le64_to_cpu(shdr->MessageId));
2315 cifs_dbg(FYI, "Session expired or deleted\n");
2321 smb2_is_status_io_timeout(char *buf)
2323 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2325 if (shdr->Status == STATUS_IO_TIMEOUT)
2332 smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server)
2334 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
2335 struct TCP_Server_Info *pserver;
2336 struct cifs_ses *ses;
2337 struct cifs_tcon *tcon;
2339 if (shdr->Status != STATUS_NETWORK_NAME_DELETED)
2342 /* If server is a channel, select the primary channel */
2343 pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
2345 spin_lock(&cifs_tcp_ses_lock);
2346 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
2347 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
2348 if (tcon->tid == le32_to_cpu(shdr->Id.SyncId.TreeId)) {
2349 spin_lock(&tcon->tc_lock);
2350 tcon->need_reconnect = true;
2351 spin_unlock(&tcon->tc_lock);
2352 spin_unlock(&cifs_tcp_ses_lock);
2353 pr_warn_once("Server share %s deleted.\n",
2359 spin_unlock(&cifs_tcp_ses_lock);
2363 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
2364 struct cifsInodeInfo *cinode)
2366 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
2367 return SMB2_lease_break(0, tcon, cinode->lease_key,
2368 smb2_get_lease_state(cinode));
2370 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
2372 CIFS_CACHE_READ(cinode) ? 1 : 0);
2376 smb2_set_related(struct smb_rqst *rqst)
2378 struct smb2_hdr *shdr;
2380 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2382 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2385 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2388 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
2391 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
2393 struct smb2_hdr *shdr;
2394 struct cifs_ses *ses = tcon->ses;
2395 struct TCP_Server_Info *server = ses->server;
2396 unsigned long len = smb_rqst_len(server, rqst);
2399 shdr = (struct smb2_hdr *)(rqst->rq_iov[0].iov_base);
2401 cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2405 /* SMB headers in a compound are 8 byte aligned. */
2407 /* No padding needed */
2411 num_padding = 8 - (len & 7);
2412 if (!smb3_encryption_required(tcon)) {
2414 * If we do not have encryption then we can just add an extra
2415 * iov for the padding.
2417 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2418 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2423 * We can not add a small padding iov for the encryption case
2424 * because the encryption framework can not handle the padding
2426 * We have to flatten this into a single buffer and add
2427 * the padding to it.
2429 for (i = 1; i < rqst->rq_nvec; i++) {
2430 memcpy(rqst->rq_iov[0].iov_base +
2431 rqst->rq_iov[0].iov_len,
2432 rqst->rq_iov[i].iov_base,
2433 rqst->rq_iov[i].iov_len);
2434 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2436 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2438 rqst->rq_iov[0].iov_len += num_padding;
2444 shdr->NextCommand = cpu_to_le32(len);
2448 * Passes the query info response back to the caller on success.
2449 * Caller need to free this with free_rsp_buf().
2452 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2453 const char *path, u32 desired_access,
2454 u32 class, u32 type, u32 output_len,
2455 struct kvec *rsp, int *buftype,
2456 struct cifs_sb_info *cifs_sb)
2458 struct cifs_ses *ses = tcon->ses;
2459 struct TCP_Server_Info *server = cifs_pick_channel(ses);
2460 int flags = CIFS_CP_CREATE_CLOSE_OP;
2461 struct smb_rqst rqst[3];
2462 int resp_buftype[3];
2463 struct kvec rsp_iov[3];
2464 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2465 struct kvec qi_iov[1];
2466 struct kvec close_iov[1];
2467 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2468 struct cifs_open_parms oparms;
2469 struct cifs_fid fid;
2472 struct cached_fid *cfid = NULL;
2476 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2480 if (smb3_encryption_required(tcon))
2481 flags |= CIFS_TRANSFORM_REQ;
2483 memset(rqst, 0, sizeof(rqst));
2484 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2485 memset(rsp_iov, 0, sizeof(rsp_iov));
2488 * We can only call this for things we know are directories.
2490 if (!strcmp(path, ""))
2491 open_cached_dir(xid, tcon, path, cifs_sb, false,
2492 &cfid); /* cfid null if open dir failed */
2494 memset(&open_iov, 0, sizeof(open_iov));
2495 rqst[0].rq_iov = open_iov;
2496 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2498 oparms = (struct cifs_open_parms) {
2500 .desired_access = desired_access,
2501 .disposition = FILE_OPEN,
2502 .create_options = cifs_create_options(cifs_sb, 0),
2506 rc = SMB2_open_init(tcon, server,
2507 &rqst[0], &oplock, &oparms, utf16_path);
2510 smb2_set_next_command(tcon, &rqst[0]);
2512 memset(&qi_iov, 0, sizeof(qi_iov));
2513 rqst[1].rq_iov = qi_iov;
2514 rqst[1].rq_nvec = 1;
2517 rc = SMB2_query_info_init(tcon, server,
2519 cfid->fid.persistent_fid,
2520 cfid->fid.volatile_fid,
2525 rc = SMB2_query_info_init(tcon, server,
2536 smb2_set_next_command(tcon, &rqst[1]);
2537 smb2_set_related(&rqst[1]);
2540 memset(&close_iov, 0, sizeof(close_iov));
2541 rqst[2].rq_iov = close_iov;
2542 rqst[2].rq_nvec = 1;
2544 rc = SMB2_close_init(tcon, server,
2545 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2548 smb2_set_related(&rqst[2]);
2551 rc = compound_send_recv(xid, ses, server,
2553 &resp_buftype[1], &rsp_iov[1]);
2555 rc = compound_send_recv(xid, ses, server,
2557 resp_buftype, rsp_iov);
2560 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2561 if (rc == -EREMCHG) {
2562 tcon->need_reconnect = true;
2563 pr_warn_once("server share %s deleted\n",
2569 *buftype = resp_buftype[1];
2573 SMB2_open_free(&rqst[0]);
2574 SMB2_query_info_free(&rqst[1]);
2575 SMB2_close_free(&rqst[2]);
2576 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2577 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2579 close_cached_dir(cfid);
2584 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2585 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2587 struct smb2_query_info_rsp *rsp;
2588 struct smb2_fs_full_size_info *info = NULL;
2589 struct kvec rsp_iov = {NULL, 0};
2590 int buftype = CIFS_NO_BUFFER;
2594 rc = smb2_query_info_compound(xid, tcon, "",
2595 FILE_READ_ATTRIBUTES,
2596 FS_FULL_SIZE_INFORMATION,
2597 SMB2_O_INFO_FILESYSTEM,
2598 sizeof(struct smb2_fs_full_size_info),
2599 &rsp_iov, &buftype, cifs_sb);
2603 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2604 buf->f_type = SMB2_SUPER_MAGIC;
2605 info = (struct smb2_fs_full_size_info *)(
2606 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2607 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2608 le32_to_cpu(rsp->OutputBufferLength),
2610 sizeof(struct smb2_fs_full_size_info));
2612 smb2_copy_fs_info_to_kstatfs(info, buf);
2615 free_rsp_buf(buftype, rsp_iov.iov_base);
2620 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2621 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2624 __le16 srch_path = 0; /* Null - open root of share */
2625 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2626 struct cifs_open_parms oparms;
2627 struct cifs_fid fid;
2629 if (!tcon->posix_extensions)
2630 return smb2_queryfs(xid, tcon, cifs_sb, buf);
2632 oparms = (struct cifs_open_parms) {
2634 .desired_access = FILE_READ_ATTRIBUTES,
2635 .disposition = FILE_OPEN,
2636 .create_options = cifs_create_options(cifs_sb, 0),
2640 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
2645 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2646 fid.volatile_fid, buf);
2647 buf->f_type = SMB2_SUPER_MAGIC;
2648 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2653 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2655 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2656 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2660 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2661 __u64 length, __u32 type, int lock, int unlock, bool wait)
2663 if (unlock && !lock)
2664 type = SMB2_LOCKFLAG_UNLOCK;
2665 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2666 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2667 current->tgid, length, offset, type, wait);
2671 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2673 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2677 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2679 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2683 smb2_new_lease_key(struct cifs_fid *fid)
2685 generate_random_uuid(fid->lease_key);
2689 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2690 const char *search_name,
2691 struct dfs_info3_param **target_nodes,
2692 unsigned int *num_of_nodes,
2693 const struct nls_table *nls_codepage, int remap)
2696 __le16 *utf16_path = NULL;
2697 int utf16_path_len = 0;
2698 struct cifs_tcon *tcon;
2699 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2700 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2701 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2702 int retry_count = 0;
2704 cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name);
2707 * Try to use the IPC tcon, otherwise just use any
2709 tcon = ses->tcon_ipc;
2711 spin_lock(&cifs_tcp_ses_lock);
2712 tcon = list_first_entry_or_null(&ses->tcon_list,
2717 spin_unlock(&cifs_tcp_ses_lock);
2721 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2727 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2729 nls_codepage, remap);
2735 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2736 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2742 /* Highest DFS referral version understood */
2743 dfs_req->MaxReferralLevel = DFS_VERSION;
2745 /* Path to resolve in an UTF-16 null-terminated string */
2746 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2749 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2750 FSCTL_DFS_GET_REFERRALS,
2751 (char *)dfs_req, dfs_req_size, CIFSMaxBufSize,
2752 (char **)&dfs_rsp, &dfs_rsp_size);
2753 if (!is_retryable_error(rc))
2755 usleep_range(512, 2048);
2756 } while (++retry_count < 5);
2759 if (!is_retryable_error(rc) && rc != -ENOENT && rc != -EOPNOTSUPP)
2760 cifs_tcon_dbg(VFS, "%s: ioctl error: rc=%d\n", __func__, rc);
2764 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
2765 num_of_nodes, target_nodes,
2766 nls_codepage, remap, search_name,
2767 true /* is_unicode */);
2769 cifs_tcon_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc);
2774 if (tcon && !tcon->ipc) {
2775 /* ipc tcons are not refcounted */
2776 spin_lock(&cifs_tcp_ses_lock);
2778 /* tc_count can never go negative */
2779 WARN_ON(tcon->tc_count < 0);
2780 spin_unlock(&cifs_tcp_ses_lock);
2789 parse_reparse_posix(struct reparse_posix_data *symlink_buf,
2790 u32 plen, char **target_path,
2791 struct cifs_sb_info *cifs_sb)
2795 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
2796 len = le16_to_cpu(symlink_buf->ReparseDataLength);
2798 if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
2799 cifs_dbg(VFS, "%lld not a supported symlink type\n",
2800 le64_to_cpu(symlink_buf->InodeType));
2804 *target_path = cifs_strndup_from_utf16(
2805 symlink_buf->PathBuffer,
2806 len, true, cifs_sb->local_nls);
2807 if (!(*target_path))
2810 convert_delimiter(*target_path, '/');
2811 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2817 parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
2818 u32 plen, char **target_path,
2819 struct cifs_sb_info *cifs_sb)
2821 unsigned int sub_len;
2822 unsigned int sub_offset;
2824 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */
2826 sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset);
2827 sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength);
2828 if (sub_offset + 20 > plen ||
2829 sub_offset + sub_len + 20 > plen) {
2830 cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
2834 *target_path = cifs_strndup_from_utf16(
2835 symlink_buf->PathBuffer + sub_offset,
2836 sub_len, true, cifs_sb->local_nls);
2837 if (!(*target_path))
2840 convert_delimiter(*target_path, '/');
2841 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2847 parse_reparse_point(struct reparse_data_buffer *buf,
2848 u32 plen, char **target_path,
2849 struct cifs_sb_info *cifs_sb)
2851 if (plen < sizeof(struct reparse_data_buffer)) {
2852 cifs_dbg(VFS, "reparse buffer is too small. Must be at least 8 bytes but was %d\n",
2857 if (plen < le16_to_cpu(buf->ReparseDataLength) +
2858 sizeof(struct reparse_data_buffer)) {
2859 cifs_dbg(VFS, "srv returned invalid reparse buf length: %d\n",
2864 /* See MS-FSCC 2.1.2 */
2865 switch (le32_to_cpu(buf->ReparseTag)) {
2866 case IO_REPARSE_TAG_NFS:
2867 return parse_reparse_posix(
2868 (struct reparse_posix_data *)buf,
2869 plen, target_path, cifs_sb);
2870 case IO_REPARSE_TAG_SYMLINK:
2871 return parse_reparse_symlink(
2872 (struct reparse_symlink_data_buffer *)buf,
2873 plen, target_path, cifs_sb);
2875 cifs_dbg(VFS, "srv returned unknown symlink buffer tag:0x%08x\n",
2876 le32_to_cpu(buf->ReparseTag));
2882 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
2883 struct cifs_sb_info *cifs_sb, const char *full_path,
2884 char **target_path, bool is_reparse_point)
2887 __le16 *utf16_path = NULL;
2888 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2889 struct cifs_open_parms oparms;
2890 struct cifs_fid fid;
2891 struct kvec err_iov = {NULL, 0};
2892 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2893 int flags = CIFS_CP_CREATE_CLOSE_OP;
2894 struct smb_rqst rqst[3];
2895 int resp_buftype[3];
2896 struct kvec rsp_iov[3];
2897 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2898 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2899 struct kvec close_iov[1];
2900 struct smb2_create_rsp *create_rsp;
2901 struct smb2_ioctl_rsp *ioctl_rsp;
2902 struct reparse_data_buffer *reparse_buf;
2903 int create_options = is_reparse_point ? OPEN_REPARSE_POINT : 0;
2906 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2908 *target_path = NULL;
2910 if (smb3_encryption_required(tcon))
2911 flags |= CIFS_TRANSFORM_REQ;
2913 memset(rqst, 0, sizeof(rqst));
2914 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2915 memset(rsp_iov, 0, sizeof(rsp_iov));
2917 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
2922 memset(&open_iov, 0, sizeof(open_iov));
2923 rqst[0].rq_iov = open_iov;
2924 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2926 oparms = (struct cifs_open_parms) {
2928 .desired_access = FILE_READ_ATTRIBUTES,
2929 .disposition = FILE_OPEN,
2930 .create_options = cifs_create_options(cifs_sb, create_options),
2934 rc = SMB2_open_init(tcon, server,
2935 &rqst[0], &oplock, &oparms, utf16_path);
2938 smb2_set_next_command(tcon, &rqst[0]);
2942 memset(&io_iov, 0, sizeof(io_iov));
2943 rqst[1].rq_iov = io_iov;
2944 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
2946 rc = SMB2_ioctl_init(tcon, server,
2947 &rqst[1], fid.persistent_fid,
2948 fid.volatile_fid, FSCTL_GET_REPARSE_POINT, NULL, 0,
2950 MAX_SMB2_CREATE_RESPONSE_SIZE -
2951 MAX_SMB2_CLOSE_RESPONSE_SIZE);
2955 smb2_set_next_command(tcon, &rqst[1]);
2956 smb2_set_related(&rqst[1]);
2960 memset(&close_iov, 0, sizeof(close_iov));
2961 rqst[2].rq_iov = close_iov;
2962 rqst[2].rq_nvec = 1;
2964 rc = SMB2_close_init(tcon, server,
2965 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2969 smb2_set_related(&rqst[2]);
2971 rc = compound_send_recv(xid, tcon->ses, server,
2973 resp_buftype, rsp_iov);
2975 create_rsp = rsp_iov[0].iov_base;
2976 if (create_rsp && create_rsp->hdr.Status)
2977 err_iov = rsp_iov[0];
2978 ioctl_rsp = rsp_iov[1].iov_base;
2981 * Open was successful and we got an ioctl response.
2983 if ((rc == 0) && (is_reparse_point)) {
2984 /* See MS-FSCC 2.3.23 */
2986 reparse_buf = (struct reparse_data_buffer *)
2987 ((char *)ioctl_rsp +
2988 le32_to_cpu(ioctl_rsp->OutputOffset));
2989 plen = le32_to_cpu(ioctl_rsp->OutputCount);
2991 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
2992 rsp_iov[1].iov_len) {
2993 cifs_tcon_dbg(VFS, "srv returned invalid ioctl len: %d\n",
2999 rc = parse_reparse_point(reparse_buf, plen, target_path,
3004 if (!rc || !err_iov.iov_base) {
3009 rc = smb2_parse_symlink_response(cifs_sb, &err_iov, target_path);
3012 cifs_dbg(FYI, "query symlink rc %d\n", rc);
3014 SMB2_open_free(&rqst[0]);
3015 SMB2_ioctl_free(&rqst[1]);
3016 SMB2_close_free(&rqst[2]);
3017 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3018 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3019 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3024 smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
3025 struct cifs_sb_info *cifs_sb, const char *full_path,
3029 __le16 *utf16_path = NULL;
3030 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3031 struct cifs_open_parms oparms;
3032 struct cifs_fid fid;
3033 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
3034 int flags = CIFS_CP_CREATE_CLOSE_OP;
3035 struct smb_rqst rqst[3];
3036 int resp_buftype[3];
3037 struct kvec rsp_iov[3];
3038 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
3039 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
3040 struct kvec close_iov[1];
3041 struct smb2_ioctl_rsp *ioctl_rsp;
3042 struct reparse_data_buffer *reparse_buf;
3045 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
3047 if (smb3_encryption_required(tcon))
3048 flags |= CIFS_TRANSFORM_REQ;
3050 memset(rqst, 0, sizeof(rqst));
3051 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
3052 memset(rsp_iov, 0, sizeof(rsp_iov));
3054 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
3059 * setup smb2open - TODO add optimization to call cifs_get_readable_path
3060 * to see if there is a handle already open that we can use
3062 memset(&open_iov, 0, sizeof(open_iov));
3063 rqst[0].rq_iov = open_iov;
3064 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
3066 oparms = (struct cifs_open_parms) {
3068 .desired_access = FILE_READ_ATTRIBUTES,
3069 .disposition = FILE_OPEN,
3070 .create_options = cifs_create_options(cifs_sb, OPEN_REPARSE_POINT),
3074 rc = SMB2_open_init(tcon, server,
3075 &rqst[0], &oplock, &oparms, utf16_path);
3078 smb2_set_next_command(tcon, &rqst[0]);
3082 memset(&io_iov, 0, sizeof(io_iov));
3083 rqst[1].rq_iov = io_iov;
3084 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3086 rc = SMB2_ioctl_init(tcon, server,
3087 &rqst[1], COMPOUND_FID,
3088 COMPOUND_FID, FSCTL_GET_REPARSE_POINT, NULL, 0,
3090 MAX_SMB2_CREATE_RESPONSE_SIZE -
3091 MAX_SMB2_CLOSE_RESPONSE_SIZE);
3095 smb2_set_next_command(tcon, &rqst[1]);
3096 smb2_set_related(&rqst[1]);
3100 memset(&close_iov, 0, sizeof(close_iov));
3101 rqst[2].rq_iov = close_iov;
3102 rqst[2].rq_nvec = 1;
3104 rc = SMB2_close_init(tcon, server,
3105 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3109 smb2_set_related(&rqst[2]);
3111 rc = compound_send_recv(xid, tcon->ses, server,
3113 resp_buftype, rsp_iov);
3115 ioctl_rsp = rsp_iov[1].iov_base;
3118 * Open was successful and we got an ioctl response.
3121 /* See MS-FSCC 2.3.23 */
3123 reparse_buf = (struct reparse_data_buffer *)
3124 ((char *)ioctl_rsp +
3125 le32_to_cpu(ioctl_rsp->OutputOffset));
3126 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3128 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3129 rsp_iov[1].iov_len) {
3130 cifs_tcon_dbg(FYI, "srv returned invalid ioctl len: %d\n",
3135 *tag = le32_to_cpu(reparse_buf->ReparseTag);
3140 SMB2_open_free(&rqst[0]);
3141 SMB2_ioctl_free(&rqst[1]);
3142 SMB2_close_free(&rqst[2]);
3143 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3144 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3145 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3149 static struct cifs_ntsd *
3150 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
3151 const struct cifs_fid *cifsfid, u32 *pacllen, u32 info)
3153 struct cifs_ntsd *pntsd = NULL;
3155 int rc = -EOPNOTSUPP;
3156 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3159 return ERR_CAST(tlink);
3162 cifs_dbg(FYI, "trying to get acl\n");
3164 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
3165 cifsfid->volatile_fid, (void **)&pntsd, pacllen,
3169 cifs_put_tlink(tlink);
3171 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3178 static struct cifs_ntsd *
3179 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
3180 const char *path, u32 *pacllen, u32 info)
3182 struct cifs_ntsd *pntsd = NULL;
3183 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3186 struct cifs_tcon *tcon;
3187 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3188 struct cifs_fid fid;
3189 struct cifs_open_parms oparms;
3192 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
3194 return ERR_CAST(tlink);
3196 tcon = tlink_tcon(tlink);
3199 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3206 oparms = (struct cifs_open_parms) {
3208 .desired_access = READ_CONTROL,
3209 .disposition = FILE_OPEN,
3211 * When querying an ACL, even if the file is a symlink
3212 * we want to open the source not the target, and so
3213 * the protocol requires that the client specify this
3214 * flag when opening a reparse point
3216 .create_options = cifs_create_options(cifs_sb, 0) |
3221 if (info & SACL_SECINFO)
3222 oparms.desired_access |= SYSTEM_SECURITY;
3224 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
3228 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3229 fid.volatile_fid, (void **)&pntsd, pacllen,
3231 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3234 cifs_put_tlink(tlink);
3237 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3244 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
3245 struct inode *inode, const char *path, int aclflag)
3247 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3249 int rc, access_flags = 0;
3250 struct cifs_tcon *tcon;
3251 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
3252 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3253 struct cifs_fid fid;
3254 struct cifs_open_parms oparms;
3257 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
3259 return PTR_ERR(tlink);
3261 tcon = tlink_tcon(tlink);
3264 if (aclflag & CIFS_ACL_OWNER || aclflag & CIFS_ACL_GROUP)
3265 access_flags |= WRITE_OWNER;
3266 if (aclflag & CIFS_ACL_SACL)
3267 access_flags |= SYSTEM_SECURITY;
3268 if (aclflag & CIFS_ACL_DACL)
3269 access_flags |= WRITE_DAC;
3271 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3278 oparms = (struct cifs_open_parms) {
3280 .desired_access = access_flags,
3281 .create_options = cifs_create_options(cifs_sb, 0),
3282 .disposition = FILE_OPEN,
3287 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
3291 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3292 fid.volatile_fid, pnntsd, acllen, aclflag);
3293 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3296 cifs_put_tlink(tlink);
3301 /* Retrieve an ACL from the server */
3302 static struct cifs_ntsd *
3303 get_smb2_acl(struct cifs_sb_info *cifs_sb,
3304 struct inode *inode, const char *path,
3305 u32 *pacllen, u32 info)
3307 struct cifs_ntsd *pntsd = NULL;
3308 struct cifsFileInfo *open_file = NULL;
3310 if (inode && !(info & SACL_SECINFO))
3311 open_file = find_readable_file(CIFS_I(inode), true);
3312 if (!open_file || (info & SACL_SECINFO))
3313 return get_smb2_acl_by_path(cifs_sb, path, pacllen, info);
3315 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen, info);
3316 cifsFileInfo_put(open_file);
3320 static long smb3_zero_data(struct file *file, struct cifs_tcon *tcon,
3321 loff_t offset, loff_t len, unsigned int xid)
3323 struct cifsFileInfo *cfile = file->private_data;
3324 struct file_zero_data_information fsctl_buf;
3326 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3328 fsctl_buf.FileOffset = cpu_to_le64(offset);
3329 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3331 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3332 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3334 sizeof(struct file_zero_data_information),
3338 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3339 loff_t offset, loff_t len, bool keep_size)
3341 struct cifs_ses *ses = tcon->ses;
3342 struct inode *inode = file_inode(file);
3343 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3344 struct cifsFileInfo *cfile = file->private_data;
3351 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3352 ses->Suid, offset, len);
3355 filemap_invalidate_lock(inode->i_mapping);
3358 * We zero the range through ioctl, so we need remove the page caches
3359 * first, otherwise the data may be inconsistent with the server.
3361 truncate_pagecache_range(inode, offset, offset + len - 1);
3363 /* if file not oplocked can't be sure whether asking to extend size */
3365 if (keep_size == false && !CIFS_CACHE_READ(cifsi))
3366 goto zero_range_exit;
3368 rc = smb3_zero_data(file, tcon, offset, len, xid);
3370 goto zero_range_exit;
3373 * do we also need to change the size of the file?
3375 if (keep_size == false && i_size_read(inode) < offset + len) {
3376 eof = cpu_to_le64(offset + len);
3377 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3378 cfile->fid.volatile_fid, cfile->pid, &eof);
3382 filemap_invalidate_unlock(inode->i_mapping);
3383 inode_unlock(inode);
3386 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
3387 ses->Suid, offset, len, rc);
3389 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
3390 ses->Suid, offset, len);
3394 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
3395 loff_t offset, loff_t len)
3397 struct inode *inode = file_inode(file);
3398 struct cifsFileInfo *cfile = file->private_data;
3399 struct file_zero_data_information fsctl_buf;
3402 __u8 set_sparse = 1;
3407 /* Need to make file sparse, if not already, before freeing range. */
3408 /* Consider adding equivalent for compressed since it could also work */
3409 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
3414 filemap_invalidate_lock(inode->i_mapping);
3416 * We implement the punch hole through ioctl, so we need remove the page
3417 * caches first, otherwise the data may be inconsistent with the server.
3419 truncate_pagecache_range(inode, offset, offset + len - 1);
3421 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3423 fsctl_buf.FileOffset = cpu_to_le64(offset);
3424 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3426 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3427 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3429 sizeof(struct file_zero_data_information),
3430 CIFSMaxBufSize, NULL, NULL);
3431 filemap_invalidate_unlock(inode->i_mapping);
3433 inode_unlock(inode);
3438 static int smb3_simple_fallocate_write_range(unsigned int xid,
3439 struct cifs_tcon *tcon,
3440 struct cifsFileInfo *cfile,
3441 loff_t off, loff_t len,
3444 struct cifs_io_parms io_parms = {0};
3449 io_parms.netfid = cfile->fid.netfid;
3450 io_parms.pid = current->tgid;
3451 io_parms.tcon = tcon;
3452 io_parms.persistent_fid = cfile->fid.persistent_fid;
3453 io_parms.volatile_fid = cfile->fid.volatile_fid;
3456 io_parms.offset = off;
3457 io_parms.length = len;
3458 if (io_parms.length > SMB2_MAX_BUFFER_SIZE)
3459 io_parms.length = SMB2_MAX_BUFFER_SIZE;
3460 /* iov[0] is reserved for smb header */
3461 iov[1].iov_base = buf;
3462 iov[1].iov_len = io_parms.length;
3463 rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
3475 static int smb3_simple_fallocate_range(unsigned int xid,
3476 struct cifs_tcon *tcon,
3477 struct cifsFileInfo *cfile,
3478 loff_t off, loff_t len)
3480 struct file_allocated_range_buffer in_data, *out_data = NULL, *tmp_data;
3486 in_data.file_offset = cpu_to_le64(off);
3487 in_data.length = cpu_to_le64(len);
3488 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3489 cfile->fid.volatile_fid,
3490 FSCTL_QUERY_ALLOCATED_RANGES,
3491 (char *)&in_data, sizeof(in_data),
3492 1024 * sizeof(struct file_allocated_range_buffer),
3493 (char **)&out_data, &out_data_len);
3497 buf = kzalloc(1024 * 1024, GFP_KERNEL);
3503 tmp_data = out_data;
3506 * The rest of the region is unmapped so write it all.
3508 if (out_data_len == 0) {
3509 rc = smb3_simple_fallocate_write_range(xid, tcon,
3510 cfile, off, len, buf);
3514 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3519 if (off < le64_to_cpu(tmp_data->file_offset)) {
3521 * We are at a hole. Write until the end of the region
3522 * or until the next allocated data,
3523 * whichever comes next.
3525 l = le64_to_cpu(tmp_data->file_offset) - off;
3528 rc = smb3_simple_fallocate_write_range(xid, tcon,
3529 cfile, off, l, buf);
3538 * We are at a section of allocated data, just skip forward
3539 * until the end of the data or the end of the region
3540 * we are supposed to fallocate, whichever comes first.
3542 l = le64_to_cpu(tmp_data->length);
3548 tmp_data = &tmp_data[1];
3549 out_data_len -= sizeof(struct file_allocated_range_buffer);
3559 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3560 loff_t off, loff_t len, bool keep_size)
3562 struct inode *inode;
3563 struct cifsInodeInfo *cifsi;
3564 struct cifsFileInfo *cfile = file->private_data;
3565 long rc = -EOPNOTSUPP;
3571 inode = d_inode(cfile->dentry);
3572 cifsi = CIFS_I(inode);
3574 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3575 tcon->ses->Suid, off, len);
3576 /* if file not oplocked can't be sure whether asking to extend size */
3577 if (!CIFS_CACHE_READ(cifsi))
3578 if (keep_size == false) {
3579 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3580 tcon->tid, tcon->ses->Suid, off, len, rc);
3586 * Extending the file
3588 if ((keep_size == false) && i_size_read(inode) < off + len) {
3589 rc = inode_newsize_ok(inode, off + len);
3593 if (cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)
3594 smb2_set_sparse(xid, tcon, cfile, inode, false);
3596 eof = cpu_to_le64(off + len);
3597 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3598 cfile->fid.volatile_fid, cfile->pid, &eof);
3600 cifsi->server_eof = off + len;
3601 cifs_setsize(inode, off + len);
3602 cifs_truncate_page(inode->i_mapping, inode->i_size);
3603 truncate_setsize(inode, off + len);
3609 * Files are non-sparse by default so falloc may be a no-op
3610 * Must check if file sparse. If not sparse, and since we are not
3611 * extending then no need to do anything since file already allocated
3613 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
3618 if (keep_size == true) {
3620 * We can not preallocate pages beyond the end of the file
3623 if (off >= i_size_read(inode)) {
3628 * For fallocates that are partially beyond the end of file,
3629 * clamp len so we only fallocate up to the end of file.
3631 if (off + len > i_size_read(inode)) {
3632 len = i_size_read(inode) - off;
3636 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3638 * At this point, we are trying to fallocate an internal
3639 * regions of a sparse file. Since smb2 does not have a
3640 * fallocate command we have two otions on how to emulate this.
3641 * We can either turn the entire file to become non-sparse
3642 * which we only do if the fallocate is for virtually
3643 * the whole file, or we can overwrite the region with zeroes
3644 * using SMB2_write, which could be prohibitevly expensive
3648 * We are only trying to fallocate a small region so
3649 * just write it with zero.
3651 if (len <= 1024 * 1024) {
3652 rc = smb3_simple_fallocate_range(xid, tcon, cfile,
3658 * Check if falloc starts within first few pages of file
3659 * and ends within a few pages of the end of file to
3660 * ensure that most of file is being forced to be
3661 * fallocated now. If so then setting whole file sparse
3662 * ie potentially making a few extra pages at the beginning
3663 * or end of the file non-sparse via set_sparse is harmless.
3665 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
3671 smb2_set_sparse(xid, tcon, cfile, inode, false);
3676 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3677 tcon->ses->Suid, off, len, rc);
3679 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3680 tcon->ses->Suid, off, len);
3686 static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
3687 loff_t off, loff_t len)
3691 struct inode *inode = file_inode(file);
3692 struct cifsFileInfo *cfile = file->private_data;
3693 struct cifsInodeInfo *cifsi = CIFS_I(inode);
3701 old_eof = i_size_read(inode);
3702 if ((off >= old_eof) ||
3703 off + len >= old_eof) {
3708 filemap_invalidate_lock(inode->i_mapping);
3709 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof - 1);
3713 truncate_pagecache_range(inode, off, old_eof);
3715 rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
3716 old_eof - off - len, off);
3720 eof = cpu_to_le64(old_eof - len);
3721 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3722 cfile->fid.volatile_fid, cfile->pid, &eof);
3728 cifsi->server_eof = i_size_read(inode) - len;
3729 truncate_setsize(inode, cifsi->server_eof);
3730 fscache_resize_cookie(cifs_inode_cookie(inode), cifsi->server_eof);
3732 filemap_invalidate_unlock(inode->i_mapping);
3734 inode_unlock(inode);
3739 static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
3740 loff_t off, loff_t len)
3744 struct cifsFileInfo *cfile = file->private_data;
3745 struct inode *inode = file_inode(file);
3747 __u64 count, old_eof;
3753 old_eof = i_size_read(inode);
3754 if (off >= old_eof) {
3759 count = old_eof - off;
3760 eof = cpu_to_le64(old_eof + len);
3762 filemap_invalidate_lock(inode->i_mapping);
3763 rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof + len - 1);
3766 truncate_pagecache_range(inode, off, old_eof);
3768 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3769 cfile->fid.volatile_fid, cfile->pid, &eof);
3773 rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len);
3777 rc = smb3_zero_data(file, tcon, off, len, xid);
3783 filemap_invalidate_unlock(inode->i_mapping);
3785 inode_unlock(inode);
3790 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3792 struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3793 struct cifsInodeInfo *cifsi;
3794 struct inode *inode;
3796 struct file_allocated_range_buffer in_data, *out_data = NULL;
3800 if (whence != SEEK_HOLE && whence != SEEK_DATA)
3801 return generic_file_llseek(file, offset, whence);
3803 inode = d_inode(cfile->dentry);
3804 cifsi = CIFS_I(inode);
3806 if (offset < 0 || offset >= i_size_read(inode))
3811 * We need to be sure that all dirty pages are written as they
3812 * might fill holes on the server.
3813 * Note that we also MUST flush any written pages since at least
3814 * some servers (Windows2016) will not reflect recent writes in
3815 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3817 wrcfile = find_writable_file(cifsi, FIND_WR_ANY);
3819 filemap_write_and_wait(inode->i_mapping);
3820 smb2_flush_file(xid, tcon, &wrcfile->fid);
3821 cifsFileInfo_put(wrcfile);
3824 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3825 if (whence == SEEK_HOLE)
3826 offset = i_size_read(inode);
3830 in_data.file_offset = cpu_to_le64(offset);
3831 in_data.length = cpu_to_le64(i_size_read(inode));
3833 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3834 cfile->fid.volatile_fid,
3835 FSCTL_QUERY_ALLOCATED_RANGES,
3836 (char *)&in_data, sizeof(in_data),
3837 sizeof(struct file_allocated_range_buffer),
3838 (char **)&out_data, &out_data_len);
3844 if (whence == SEEK_HOLE && out_data_len == 0)
3847 if (whence == SEEK_DATA && out_data_len == 0) {
3852 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3856 if (whence == SEEK_DATA) {
3857 offset = le64_to_cpu(out_data->file_offset);
3860 if (offset < le64_to_cpu(out_data->file_offset))
3863 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3869 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3874 static int smb3_fiemap(struct cifs_tcon *tcon,
3875 struct cifsFileInfo *cfile,
3876 struct fiemap_extent_info *fei, u64 start, u64 len)
3879 struct file_allocated_range_buffer in_data, *out_data;
3881 int i, num, rc, flags, last_blob;
3884 rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0);
3890 in_data.file_offset = cpu_to_le64(start);
3891 in_data.length = cpu_to_le64(len);
3893 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3894 cfile->fid.volatile_fid,
3895 FSCTL_QUERY_ALLOCATED_RANGES,
3896 (char *)&in_data, sizeof(in_data),
3897 1024 * sizeof(struct file_allocated_range_buffer),
3898 (char **)&out_data, &out_data_len);
3907 if (out_data_len && out_data_len < sizeof(struct file_allocated_range_buffer)) {
3911 if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3916 num = out_data_len / sizeof(struct file_allocated_range_buffer);
3917 for (i = 0; i < num; i++) {
3919 if (i == num - 1 && last_blob)
3920 flags |= FIEMAP_EXTENT_LAST;
3922 rc = fiemap_fill_next_extent(fei,
3923 le64_to_cpu(out_data[i].file_offset),
3924 le64_to_cpu(out_data[i].file_offset),
3925 le64_to_cpu(out_data[i].length),
3936 next = le64_to_cpu(out_data[num - 1].file_offset) +
3937 le64_to_cpu(out_data[num - 1].length);
3938 len = len - (next - start);
3949 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
3950 loff_t off, loff_t len)
3952 /* KEEP_SIZE already checked for by do_fallocate */
3953 if (mode & FALLOC_FL_PUNCH_HOLE)
3954 return smb3_punch_hole(file, tcon, off, len);
3955 else if (mode & FALLOC_FL_ZERO_RANGE) {
3956 if (mode & FALLOC_FL_KEEP_SIZE)
3957 return smb3_zero_range(file, tcon, off, len, true);
3958 return smb3_zero_range(file, tcon, off, len, false);
3959 } else if (mode == FALLOC_FL_KEEP_SIZE)
3960 return smb3_simple_falloc(file, tcon, off, len, true);
3961 else if (mode == FALLOC_FL_COLLAPSE_RANGE)
3962 return smb3_collapse_range(file, tcon, off, len);
3963 else if (mode == FALLOC_FL_INSERT_RANGE)
3964 return smb3_insert_range(file, tcon, off, len);
3966 return smb3_simple_falloc(file, tcon, off, len, false);
3972 smb2_downgrade_oplock(struct TCP_Server_Info *server,
3973 struct cifsInodeInfo *cinode, __u32 oplock,
3974 unsigned int epoch, bool *purge_cache)
3976 server->ops->set_oplock_level(cinode, oplock, 0, NULL);
3980 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3981 unsigned int epoch, bool *purge_cache);
3984 smb3_downgrade_oplock(struct TCP_Server_Info *server,
3985 struct cifsInodeInfo *cinode, __u32 oplock,
3986 unsigned int epoch, bool *purge_cache)
3988 unsigned int old_state = cinode->oplock;
3989 unsigned int old_epoch = cinode->epoch;
3990 unsigned int new_state;
3992 if (epoch > old_epoch) {
3993 smb21_set_oplock_level(cinode, oplock, 0, NULL);
3994 cinode->epoch = epoch;
3997 new_state = cinode->oplock;
3998 *purge_cache = false;
4000 if ((old_state & CIFS_CACHE_READ_FLG) != 0 &&
4001 (new_state & CIFS_CACHE_READ_FLG) == 0)
4002 *purge_cache = true;
4003 else if (old_state == new_state && (epoch - old_epoch > 1))
4004 *purge_cache = true;
4008 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4009 unsigned int epoch, bool *purge_cache)
4012 cinode->lease_granted = false;
4013 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
4015 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
4016 cinode->oplock = CIFS_CACHE_RHW_FLG;
4017 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
4018 &cinode->netfs.inode);
4019 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
4020 cinode->oplock = CIFS_CACHE_RW_FLG;
4021 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
4022 &cinode->netfs.inode);
4023 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
4024 cinode->oplock = CIFS_CACHE_READ_FLG;
4025 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
4026 &cinode->netfs.inode);
4032 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4033 unsigned int epoch, bool *purge_cache)
4035 char message[5] = {0};
4036 unsigned int new_oplock = 0;
4039 cinode->lease_granted = true;
4040 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
4043 /* Check if the server granted an oplock rather than a lease */
4044 if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4045 return smb2_set_oplock_level(cinode, oplock, epoch,
4048 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
4049 new_oplock |= CIFS_CACHE_READ_FLG;
4050 strcat(message, "R");
4052 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
4053 new_oplock |= CIFS_CACHE_HANDLE_FLG;
4054 strcat(message, "H");
4056 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
4057 new_oplock |= CIFS_CACHE_WRITE_FLG;
4058 strcat(message, "W");
4061 strncpy(message, "None", sizeof(message));
4063 cinode->oplock = new_oplock;
4064 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
4065 &cinode->netfs.inode);
4069 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
4070 unsigned int epoch, bool *purge_cache)
4072 unsigned int old_oplock = cinode->oplock;
4074 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
4077 *purge_cache = false;
4078 if (old_oplock == CIFS_CACHE_READ_FLG) {
4079 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
4080 (epoch - cinode->epoch > 0))
4081 *purge_cache = true;
4082 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4083 (epoch - cinode->epoch > 1))
4084 *purge_cache = true;
4085 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4086 (epoch - cinode->epoch > 1))
4087 *purge_cache = true;
4088 else if (cinode->oplock == 0 &&
4089 (epoch - cinode->epoch > 0))
4090 *purge_cache = true;
4091 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
4092 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
4093 (epoch - cinode->epoch > 0))
4094 *purge_cache = true;
4095 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
4096 (epoch - cinode->epoch > 1))
4097 *purge_cache = true;
4099 cinode->epoch = epoch;
4103 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
4105 smb2_is_read_op(__u32 oplock)
4107 return oplock == SMB2_OPLOCK_LEVEL_II;
4109 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
4112 smb21_is_read_op(__u32 oplock)
4114 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
4115 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
4119 map_oplock_to_lease(u8 oplock)
4121 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
4122 return SMB2_LEASE_WRITE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE;
4123 else if (oplock == SMB2_OPLOCK_LEVEL_II)
4124 return SMB2_LEASE_READ_CACHING_LE;
4125 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
4126 return SMB2_LEASE_HANDLE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE |
4127 SMB2_LEASE_WRITE_CACHING_LE;
4132 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
4134 struct create_lease *buf;
4136 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
4140 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4141 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4143 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4144 (struct create_lease, lcontext));
4145 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
4146 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4147 (struct create_lease, Name));
4148 buf->ccontext.NameLength = cpu_to_le16(4);
4149 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4158 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
4160 struct create_lease_v2 *buf;
4162 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
4166 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4167 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4169 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4170 (struct create_lease_v2, lcontext));
4171 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
4172 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4173 (struct create_lease_v2, Name));
4174 buf->ccontext.NameLength = cpu_to_le16(4);
4175 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4184 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4186 struct create_lease *lc = (struct create_lease *)buf;
4188 *epoch = 0; /* not used */
4189 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4190 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4191 return le32_to_cpu(lc->lcontext.LeaseState);
4195 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4197 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
4199 *epoch = le16_to_cpu(lc->lcontext.Epoch);
4200 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE)
4201 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4203 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
4204 return le32_to_cpu(lc->lcontext.LeaseState);
4208 smb2_wp_retry_size(struct inode *inode)
4210 return min_t(unsigned int, CIFS_SB(inode->i_sb)->ctx->wsize,
4211 SMB2_MAX_BUFFER_SIZE);
4215 smb2_dir_needs_close(struct cifsFileInfo *cfile)
4217 return !cfile->invalidHandle;
4221 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
4222 struct smb_rqst *old_rq, __le16 cipher_type)
4224 struct smb2_hdr *shdr =
4225 (struct smb2_hdr *)old_rq->rq_iov[0].iov_base;
4227 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
4228 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
4229 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
4230 tr_hdr->Flags = cpu_to_le16(0x01);
4231 if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4232 (cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4233 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4235 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4236 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
4239 static void *smb2_aead_req_alloc(struct crypto_aead *tfm, const struct smb_rqst *rqst,
4240 int num_rqst, const u8 *sig, u8 **iv,
4241 struct aead_request **req, struct scatterlist **sgl,
4242 unsigned int *num_sgs)
4244 unsigned int req_size = sizeof(**req) + crypto_aead_reqsize(tfm);
4245 unsigned int iv_size = crypto_aead_ivsize(tfm);
4249 *num_sgs = cifs_get_num_sgs(rqst, num_rqst, sig);
4252 len += crypto_aead_alignmask(tfm) & ~(crypto_tfm_ctx_alignment() - 1);
4253 len = ALIGN(len, crypto_tfm_ctx_alignment());
4255 len = ALIGN(len, __alignof__(struct scatterlist));
4256 len += *num_sgs * sizeof(**sgl);
4258 p = kmalloc(len, GFP_ATOMIC);
4262 *iv = (u8 *)PTR_ALIGN(p, crypto_aead_alignmask(tfm) + 1);
4263 *req = (struct aead_request *)PTR_ALIGN(*iv + iv_size,
4264 crypto_tfm_ctx_alignment());
4265 *sgl = (struct scatterlist *)PTR_ALIGN((u8 *)*req + req_size,
4266 __alignof__(struct scatterlist));
4270 static void *smb2_get_aead_req(struct crypto_aead *tfm, const struct smb_rqst *rqst,
4271 int num_rqst, const u8 *sig, u8 **iv,
4272 struct aead_request **req, struct scatterlist **sgl)
4274 unsigned int off, len, skip;
4275 struct scatterlist *sg;
4276 unsigned int num_sgs;
4281 p = smb2_aead_req_alloc(tfm, rqst, num_rqst, sig, iv, req, sgl, &num_sgs);
4285 sg_init_table(*sgl, num_sgs);
4289 * The first rqst has a transform header where the
4290 * first 20 bytes are not part of the encrypted blob.
4294 /* Assumes the first rqst has a transform header as the first iov.
4296 * rqst[0].rq_iov[0] is transform header
4297 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
4298 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
4300 for (i = 0; i < num_rqst; i++) {
4301 for (j = 0; j < rqst[i].rq_nvec; j++) {
4302 struct kvec *iov = &rqst[i].rq_iov[j];
4304 addr = (unsigned long)iov->iov_base + skip;
4305 len = iov->iov_len - skip;
4306 sg = cifs_sg_set_buf(sg, (void *)addr, len);
4308 /* See the above comment on the 'skip' assignment */
4311 for (j = 0; j < rqst[i].rq_npages; j++) {
4312 rqst_page_get_length(&rqst[i], j, &len, &off);
4313 sg_set_page(sg++, rqst[i].rq_pages[j], len, off);
4316 cifs_sg_set_buf(sg, sig, SMB2_SIGNATURE_SIZE);
4322 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
4324 struct TCP_Server_Info *pserver;
4325 struct cifs_ses *ses;
4328 /* If server is a channel, select the primary channel */
4329 pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
4331 spin_lock(&cifs_tcp_ses_lock);
4332 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
4333 if (ses->Suid == ses_id) {
4334 spin_lock(&ses->ses_lock);
4335 ses_enc_key = enc ? ses->smb3encryptionkey :
4336 ses->smb3decryptionkey;
4337 memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE);
4338 spin_unlock(&ses->ses_lock);
4339 spin_unlock(&cifs_tcp_ses_lock);
4343 spin_unlock(&cifs_tcp_ses_lock);
4348 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
4349 * iov[0] - transform header (associate data),
4350 * iov[1-N] - SMB2 header and pages - data to encrypt.
4351 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4355 crypt_message(struct TCP_Server_Info *server, int num_rqst,
4356 struct smb_rqst *rqst, int enc)
4358 struct smb2_transform_hdr *tr_hdr =
4359 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
4360 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
4362 struct scatterlist *sg;
4363 u8 sign[SMB2_SIGNATURE_SIZE] = {};
4364 u8 key[SMB3_ENC_DEC_KEY_SIZE];
4365 struct aead_request *req;
4367 DECLARE_CRYPTO_WAIT(wait);
4368 struct crypto_aead *tfm;
4369 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4372 rc = smb2_get_enc_key(server, le64_to_cpu(tr_hdr->SessionId), enc, key);
4374 cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
4379 rc = smb3_crypto_aead_allocate(server);
4381 cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
4385 tfm = enc ? server->secmech.enc : server->secmech.dec;
4387 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
4388 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4389 rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
4391 rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE);
4394 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
4398 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
4400 cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
4404 creq = smb2_get_aead_req(tfm, rqst, num_rqst, sign, &iv, &req, &sg);
4405 if (unlikely(!creq))
4409 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
4410 crypt_len += SMB2_SIGNATURE_SIZE;
4413 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4414 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4415 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4418 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4421 aead_request_set_tfm(req, tfm);
4422 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
4423 aead_request_set_ad(req, assoc_data_len);
4425 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
4426 crypto_req_done, &wait);
4428 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
4429 : crypto_aead_decrypt(req), &wait);
4432 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
4434 kfree_sensitive(creq);
4439 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
4443 for (i = 0; i < num_rqst; i++) {
4444 if (rqst[i].rq_pages) {
4445 for (j = rqst[i].rq_npages - 1; j >= 0; j--)
4446 put_page(rqst[i].rq_pages[j]);
4447 kfree(rqst[i].rq_pages);
4453 * This function will initialize new_rq and encrypt the content.
4454 * The first entry, new_rq[0], only contains a single iov which contains
4455 * a smb2_transform_hdr and is pre-allocated by the caller.
4456 * This function then populates new_rq[1+] with the content from olq_rq[0+].
4458 * The end result is an array of smb_rqst structures where the first structure
4459 * only contains a single iov for the transform header which we then can pass
4460 * to crypt_message().
4462 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4463 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
4466 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
4467 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
4469 struct page **pages;
4470 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
4471 unsigned int npages;
4472 unsigned int orig_len = 0;
4476 for (i = 1; i < num_rqst; i++) {
4477 struct smb_rqst *old = &old_rq[i - 1];
4478 struct smb_rqst *new = &new_rq[i];
4480 orig_len += smb_rqst_len(server, old);
4481 new->rq_iov = old->rq_iov;
4482 new->rq_nvec = old->rq_nvec;
4484 npages = old->rq_npages;
4488 pages = kmalloc_array(npages, sizeof(struct page *),
4493 new->rq_pages = pages;
4494 new->rq_npages = npages;
4495 new->rq_offset = old->rq_offset;
4496 new->rq_pagesz = old->rq_pagesz;
4497 new->rq_tailsz = old->rq_tailsz;
4499 for (j = 0; j < npages; j++) {
4500 pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4505 /* copy pages form the old */
4506 for (j = 0; j < npages; j++) {
4507 unsigned int offset, len;
4509 rqst_page_get_length(new, j, &len, &offset);
4511 memcpy_page(new->rq_pages[j], offset,
4512 old->rq_pages[j], offset, len);
4516 /* fill the 1st iov with a transform header */
4517 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
4519 rc = crypt_message(server, num_rqst, new_rq, 1);
4520 cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
4527 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
4532 smb3_is_transform_hdr(void *buf)
4534 struct smb2_transform_hdr *trhdr = buf;
4536 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
4540 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
4541 unsigned int buf_data_size, struct page **pages,
4542 unsigned int npages, unsigned int page_data_size,
4546 struct smb_rqst rqst = {NULL};
4549 iov[0].iov_base = buf;
4550 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
4551 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
4552 iov[1].iov_len = buf_data_size;
4556 rqst.rq_pages = pages;
4557 rqst.rq_npages = npages;
4558 rqst.rq_pagesz = PAGE_SIZE;
4559 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
4561 rc = crypt_message(server, 1, &rqst, 0);
4562 cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
4567 memmove(buf, iov[1].iov_base, buf_data_size);
4570 server->total_read = buf_data_size + page_data_size;
4576 read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
4577 unsigned int npages, unsigned int len)
4582 for (i = 0; i < npages; i++) {
4583 struct page *page = pages[i];
4587 if (len >= PAGE_SIZE) {
4588 /* enough data to fill the page */
4592 zero_user(page, len, PAGE_SIZE - len);
4595 length = cifs_read_page_from_socket(server, page, 0, n);
4598 server->total_read += length;
4605 init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
4606 unsigned int cur_off, struct bio_vec **page_vec)
4608 struct bio_vec *bvec;
4611 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
4615 for (i = 0; i < npages; i++) {
4616 bvec[i].bv_page = pages[i];
4617 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
4618 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
4619 data_size -= bvec[i].bv_len;
4622 if (data_size != 0) {
4623 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
4633 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
4634 char *buf, unsigned int buf_len, struct page **pages,
4635 unsigned int npages, unsigned int page_data_size,
4638 unsigned int data_offset;
4639 unsigned int data_len;
4640 unsigned int cur_off;
4641 unsigned int cur_page_idx;
4642 unsigned int pad_len;
4643 struct cifs_readdata *rdata = mid->callback_data;
4644 struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
4645 struct bio_vec *bvec = NULL;
4646 struct iov_iter iter;
4649 bool use_rdma_mr = false;
4651 if (shdr->Command != SMB2_READ) {
4652 cifs_server_dbg(VFS, "only big read responses are supported\n");
4656 if (server->ops->is_session_expired &&
4657 server->ops->is_session_expired(buf)) {
4659 cifs_reconnect(server, true);
4663 if (server->ops->is_status_pending &&
4664 server->ops->is_status_pending(buf, server))
4667 /* set up first two iov to get credits */
4668 rdata->iov[0].iov_base = buf;
4669 rdata->iov[0].iov_len = 0;
4670 rdata->iov[1].iov_base = buf;
4671 rdata->iov[1].iov_len =
4672 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
4673 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
4674 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
4675 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
4676 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
4678 rdata->result = server->ops->map_error(buf, true);
4679 if (rdata->result != 0) {
4680 cifs_dbg(FYI, "%s: server returned error %d\n",
4681 __func__, rdata->result);
4682 /* normal error on read response */
4684 mid->mid_state = MID_RESPONSE_RECEIVED;
4686 dequeue_mid(mid, false);
4690 data_offset = server->ops->read_data_offset(buf);
4691 #ifdef CONFIG_CIFS_SMB_DIRECT
4692 use_rdma_mr = rdata->mr;
4694 data_len = server->ops->read_data_length(buf, use_rdma_mr);
4696 if (data_offset < server->vals->read_rsp_size) {
4698 * win2k8 sometimes sends an offset of 0 when the read
4699 * is beyond the EOF. Treat it as if the data starts just after
4702 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
4703 __func__, data_offset);
4704 data_offset = server->vals->read_rsp_size;
4705 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
4706 /* data_offset is beyond the end of smallbuf */
4707 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
4708 __func__, data_offset);
4709 rdata->result = -EIO;
4711 mid->mid_state = MID_RESPONSE_MALFORMED;
4713 dequeue_mid(mid, rdata->result);
4717 pad_len = data_offset - server->vals->read_rsp_size;
4719 if (buf_len <= data_offset) {
4720 /* read response payload is in pages */
4721 cur_page_idx = pad_len / PAGE_SIZE;
4722 cur_off = pad_len % PAGE_SIZE;
4724 if (cur_page_idx != 0) {
4725 /* data offset is beyond the 1st page of response */
4726 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
4727 __func__, data_offset);
4728 rdata->result = -EIO;
4730 mid->mid_state = MID_RESPONSE_MALFORMED;
4732 dequeue_mid(mid, rdata->result);
4736 if (data_len > page_data_size - pad_len) {
4737 /* data_len is corrupt -- discard frame */
4738 rdata->result = -EIO;
4740 mid->mid_state = MID_RESPONSE_MALFORMED;
4742 dequeue_mid(mid, rdata->result);
4746 rdata->result = init_read_bvec(pages, npages, page_data_size,
4748 if (rdata->result != 0) {
4750 mid->mid_state = MID_RESPONSE_MALFORMED;
4752 dequeue_mid(mid, rdata->result);
4756 iov_iter_bvec(&iter, ITER_SOURCE, bvec, npages, data_len);
4757 } else if (buf_len >= data_offset + data_len) {
4758 /* read response payload is in buf */
4759 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
4760 iov.iov_base = buf + data_offset;
4761 iov.iov_len = data_len;
4762 iov_iter_kvec(&iter, ITER_SOURCE, &iov, 1, data_len);
4764 /* read response payload cannot be in both buf and pages */
4765 WARN_ONCE(1, "buf can not contain only a part of read data");
4766 rdata->result = -EIO;
4768 mid->mid_state = MID_RESPONSE_MALFORMED;
4770 dequeue_mid(mid, rdata->result);
4774 length = rdata->copy_into_pages(server, rdata, &iter);
4782 mid->mid_state = MID_RESPONSE_RECEIVED;
4784 dequeue_mid(mid, false);
4788 struct smb2_decrypt_work {
4789 struct work_struct decrypt;
4790 struct TCP_Server_Info *server;
4791 struct page **ppages;
4793 unsigned int npages;
4798 static void smb2_decrypt_offload(struct work_struct *work)
4800 struct smb2_decrypt_work *dw = container_of(work,
4801 struct smb2_decrypt_work, decrypt);
4803 struct mid_q_entry *mid;
4805 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
4806 dw->ppages, dw->npages, dw->len, true);
4808 cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
4812 dw->server->lstrp = jiffies;
4813 mid = smb2_find_dequeue_mid(dw->server, dw->buf);
4815 cifs_dbg(FYI, "mid not found\n");
4817 mid->decrypted = true;
4818 rc = handle_read_data(dw->server, mid, dw->buf,
4819 dw->server->vals->read_rsp_size,
4820 dw->ppages, dw->npages, dw->len,
4823 #ifdef CONFIG_CIFS_STATS2
4824 mid->when_received = jiffies;
4826 if (dw->server->ops->is_network_name_deleted)
4827 dw->server->ops->is_network_name_deleted(dw->buf,
4832 spin_lock(&dw->server->srv_lock);
4833 if (dw->server->tcpStatus == CifsNeedReconnect) {
4834 spin_lock(&dw->server->mid_lock);
4835 mid->mid_state = MID_RETRY_NEEDED;
4836 spin_unlock(&dw->server->mid_lock);
4837 spin_unlock(&dw->server->srv_lock);
4840 spin_lock(&dw->server->mid_lock);
4841 mid->mid_state = MID_REQUEST_SUBMITTED;
4842 mid->mid_flags &= ~(MID_DELETED);
4843 list_add_tail(&mid->qhead,
4844 &dw->server->pending_mid_q);
4845 spin_unlock(&dw->server->mid_lock);
4846 spin_unlock(&dw->server->srv_lock);
4853 for (i = dw->npages-1; i >= 0; i--)
4854 put_page(dw->ppages[i]);
4857 cifs_small_buf_release(dw->buf);
4863 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
4866 char *buf = server->smallbuf;
4867 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4868 unsigned int npages;
4869 struct page **pages;
4871 unsigned int buflen = server->pdu_size;
4874 struct smb2_decrypt_work *dw;
4877 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
4878 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
4880 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
4883 server->total_read += rc;
4885 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
4886 server->vals->read_rsp_size;
4887 npages = DIV_ROUND_UP(len, PAGE_SIZE);
4889 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
4895 for (; i < npages; i++) {
4896 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4903 /* read read data into pages */
4904 rc = read_data_into_pages(server, pages, npages, len);
4908 rc = cifs_discard_remaining_data(server);
4913 * For large reads, offload to different thread for better performance,
4914 * use more cores decrypting which can be expensive
4917 if ((server->min_offload) && (server->in_flight > 1) &&
4918 (server->pdu_size >= server->min_offload)) {
4919 dw = kmalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL);
4921 goto non_offloaded_decrypt;
4923 dw->buf = server->smallbuf;
4924 server->smallbuf = (char *)cifs_small_buf_get();
4926 INIT_WORK(&dw->decrypt, smb2_decrypt_offload);
4928 dw->npages = npages;
4929 dw->server = server;
4932 queue_work(decrypt_wq, &dw->decrypt);
4933 *num_mids = 0; /* worker thread takes care of finding mid */
4937 non_offloaded_decrypt:
4938 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
4939 pages, npages, len, false);
4943 *mid = smb2_find_mid(server, buf);
4945 cifs_dbg(FYI, "mid not found\n");
4947 cifs_dbg(FYI, "mid found\n");
4948 (*mid)->decrypted = true;
4949 rc = handle_read_data(server, *mid, buf,
4950 server->vals->read_rsp_size,
4951 pages, npages, len, false);
4953 if (server->ops->is_network_name_deleted) {
4954 server->ops->is_network_name_deleted(buf,
4961 for (i = i - 1; i >= 0; i--)
4966 cifs_discard_remaining_data(server);
4971 receive_encrypted_standard(struct TCP_Server_Info *server,
4972 struct mid_q_entry **mids, char **bufs,
4976 char *buf = server->smallbuf;
4977 struct smb2_hdr *shdr;
4978 unsigned int pdu_length = server->pdu_size;
4979 unsigned int buf_size;
4980 struct mid_q_entry *mid_entry;
4982 char *next_buffer = NULL;
4986 /* switch to large buffer if too big for a small one */
4987 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
4988 server->large_buf = true;
4989 memcpy(server->bigbuf, buf, server->total_read);
4990 buf = server->bigbuf;
4993 /* now read the rest */
4994 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
4995 pdu_length - HEADER_SIZE(server) + 1);
4998 server->total_read += length;
5000 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
5001 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0, false);
5005 next_is_large = server->large_buf;
5007 shdr = (struct smb2_hdr *)buf;
5008 if (shdr->NextCommand) {
5010 next_buffer = (char *)cifs_buf_get();
5012 next_buffer = (char *)cifs_small_buf_get();
5014 buf + le32_to_cpu(shdr->NextCommand),
5015 pdu_length - le32_to_cpu(shdr->NextCommand));
5018 mid_entry = smb2_find_mid(server, buf);
5019 if (mid_entry == NULL)
5020 cifs_dbg(FYI, "mid not found\n");
5022 cifs_dbg(FYI, "mid found\n");
5023 mid_entry->decrypted = true;
5024 mid_entry->resp_buf_size = server->pdu_size;
5027 if (*num_mids >= MAX_COMPOUND) {
5028 cifs_server_dbg(VFS, "too many PDUs in compound\n");
5031 bufs[*num_mids] = buf;
5032 mids[(*num_mids)++] = mid_entry;
5034 if (mid_entry && mid_entry->handle)
5035 ret = mid_entry->handle(server, mid_entry);
5037 ret = cifs_handle_standard(server, mid_entry);
5039 if (ret == 0 && shdr->NextCommand) {
5040 pdu_length -= le32_to_cpu(shdr->NextCommand);
5041 server->large_buf = next_is_large;
5043 server->bigbuf = buf = next_buffer;
5045 server->smallbuf = buf = next_buffer;
5047 } else if (ret != 0) {
5049 * ret != 0 here means that we didn't get to handle_mid() thus
5050 * server->smallbuf and server->bigbuf are still valid. We need
5051 * to free next_buffer because it is not going to be used
5055 free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer);
5057 free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer);
5064 smb3_receive_transform(struct TCP_Server_Info *server,
5065 struct mid_q_entry **mids, char **bufs, int *num_mids)
5067 char *buf = server->smallbuf;
5068 unsigned int pdu_length = server->pdu_size;
5069 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
5070 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
5072 if (pdu_length < sizeof(struct smb2_transform_hdr) +
5073 sizeof(struct smb2_hdr)) {
5074 cifs_server_dbg(VFS, "Transform message is too small (%u)\n",
5076 cifs_reconnect(server, true);
5077 return -ECONNABORTED;
5080 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
5081 cifs_server_dbg(VFS, "Transform message is broken\n");
5082 cifs_reconnect(server, true);
5083 return -ECONNABORTED;
5086 /* TODO: add support for compounds containing READ. */
5087 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
5088 return receive_encrypted_read(server, &mids[0], num_mids);
5091 return receive_encrypted_standard(server, mids, bufs, num_mids);
5095 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
5097 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
5099 return handle_read_data(server, mid, buf, server->pdu_size,
5104 smb2_next_header(char *buf)
5106 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
5107 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
5109 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
5110 return sizeof(struct smb2_transform_hdr) +
5111 le32_to_cpu(t_hdr->OriginalMessageSize);
5113 return le32_to_cpu(hdr->NextCommand);
5117 smb2_make_node(unsigned int xid, struct inode *inode,
5118 struct dentry *dentry, struct cifs_tcon *tcon,
5119 const char *full_path, umode_t mode, dev_t dev)
5121 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
5123 struct cifs_open_info_data buf = {};
5124 struct cifs_io_parms io_parms = {0};
5126 struct cifs_fid fid;
5127 struct cifs_open_parms oparms;
5128 unsigned int bytes_written;
5129 struct win_dev *pdev;
5133 * Check if mounted with mount parm 'sfu' mount parm.
5134 * SFU emulation should work with all servers, but only
5135 * supports block and char device (no socket & fifo),
5136 * and was used by default in earlier versions of Windows
5138 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
5142 * TODO: Add ability to create instead via reparse point. Windows (e.g.
5143 * their current NFS server) uses this approach to expose special files
5144 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
5147 if (!S_ISCHR(mode) && !S_ISBLK(mode))
5150 cifs_dbg(FYI, "sfu compat create special file\n");
5152 oparms = (struct cifs_open_parms) {
5155 .desired_access = GENERIC_WRITE,
5156 .create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR |
5157 CREATE_OPTION_SPECIAL),
5158 .disposition = FILE_CREATE,
5163 if (tcon->ses->server->oplocks)
5164 oplock = REQ_OPLOCK;
5167 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, &buf);
5172 * BB Do not bother to decode buf since no local inode yet to put
5173 * timestamps in, but we can reuse it safely.
5176 pdev = (struct win_dev *)&buf.fi;
5177 io_parms.pid = current->tgid;
5178 io_parms.tcon = tcon;
5179 io_parms.offset = 0;
5180 io_parms.length = sizeof(struct win_dev);
5181 iov[1].iov_base = &buf.fi;
5182 iov[1].iov_len = sizeof(struct win_dev);
5183 if (S_ISCHR(mode)) {
5184 memcpy(pdev->type, "IntxCHR", 8);
5185 pdev->major = cpu_to_le64(MAJOR(dev));
5186 pdev->minor = cpu_to_le64(MINOR(dev));
5187 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5188 &bytes_written, iov, 1);
5189 } else if (S_ISBLK(mode)) {
5190 memcpy(pdev->type, "IntxBLK", 8);
5191 pdev->major = cpu_to_le64(MAJOR(dev));
5192 pdev->minor = cpu_to_le64(MINOR(dev));
5193 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5194 &bytes_written, iov, 1);
5196 tcon->ses->server->ops->close(xid, tcon, &fid);
5199 /* FIXME: add code here to set EAs */
5201 cifs_free_open_info(&buf);
5205 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5206 struct smb_version_operations smb20_operations = {
5207 .compare_fids = smb2_compare_fids,
5208 .setup_request = smb2_setup_request,
5209 .setup_async_request = smb2_setup_async_request,
5210 .check_receive = smb2_check_receive,
5211 .add_credits = smb2_add_credits,
5212 .set_credits = smb2_set_credits,
5213 .get_credits_field = smb2_get_credits_field,
5214 .get_credits = smb2_get_credits,
5215 .wait_mtu_credits = cifs_wait_mtu_credits,
5216 .get_next_mid = smb2_get_next_mid,
5217 .revert_current_mid = smb2_revert_current_mid,
5218 .read_data_offset = smb2_read_data_offset,
5219 .read_data_length = smb2_read_data_length,
5220 .map_error = map_smb2_to_linux_error,
5221 .find_mid = smb2_find_mid,
5222 .check_message = smb2_check_message,
5223 .dump_detail = smb2_dump_detail,
5224 .clear_stats = smb2_clear_stats,
5225 .print_stats = smb2_print_stats,
5226 .is_oplock_break = smb2_is_valid_oplock_break,
5227 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5228 .downgrade_oplock = smb2_downgrade_oplock,
5229 .need_neg = smb2_need_neg,
5230 .negotiate = smb2_negotiate,
5231 .negotiate_wsize = smb2_negotiate_wsize,
5232 .negotiate_rsize = smb2_negotiate_rsize,
5233 .sess_setup = SMB2_sess_setup,
5234 .logoff = SMB2_logoff,
5235 .tree_connect = SMB2_tcon,
5236 .tree_disconnect = SMB2_tdis,
5237 .qfs_tcon = smb2_qfs_tcon,
5238 .is_path_accessible = smb2_is_path_accessible,
5239 .can_echo = smb2_can_echo,
5241 .query_path_info = smb2_query_path_info,
5242 .get_srv_inum = smb2_get_srv_inum,
5243 .query_file_info = smb2_query_file_info,
5244 .set_path_size = smb2_set_path_size,
5245 .set_file_size = smb2_set_file_size,
5246 .set_file_info = smb2_set_file_info,
5247 .set_compression = smb2_set_compression,
5248 .mkdir = smb2_mkdir,
5249 .mkdir_setinfo = smb2_mkdir_setinfo,
5250 .rmdir = smb2_rmdir,
5251 .unlink = smb2_unlink,
5252 .rename = smb2_rename_path,
5253 .create_hardlink = smb2_create_hardlink,
5254 .query_symlink = smb2_query_symlink,
5255 .query_mf_symlink = smb3_query_mf_symlink,
5256 .create_mf_symlink = smb3_create_mf_symlink,
5257 .open = smb2_open_file,
5258 .set_fid = smb2_set_fid,
5259 .close = smb2_close_file,
5260 .flush = smb2_flush_file,
5261 .async_readv = smb2_async_readv,
5262 .async_writev = smb2_async_writev,
5263 .sync_read = smb2_sync_read,
5264 .sync_write = smb2_sync_write,
5265 .query_dir_first = smb2_query_dir_first,
5266 .query_dir_next = smb2_query_dir_next,
5267 .close_dir = smb2_close_dir,
5268 .calc_smb_size = smb2_calc_size,
5269 .is_status_pending = smb2_is_status_pending,
5270 .is_session_expired = smb2_is_session_expired,
5271 .oplock_response = smb2_oplock_response,
5272 .queryfs = smb2_queryfs,
5273 .mand_lock = smb2_mand_lock,
5274 .mand_unlock_range = smb2_unlock_range,
5275 .push_mand_locks = smb2_push_mandatory_locks,
5276 .get_lease_key = smb2_get_lease_key,
5277 .set_lease_key = smb2_set_lease_key,
5278 .new_lease_key = smb2_new_lease_key,
5279 .calc_signature = smb2_calc_signature,
5280 .is_read_op = smb2_is_read_op,
5281 .set_oplock_level = smb2_set_oplock_level,
5282 .create_lease_buf = smb2_create_lease_buf,
5283 .parse_lease_buf = smb2_parse_lease_buf,
5284 .copychunk_range = smb2_copychunk_range,
5285 .wp_retry_size = smb2_wp_retry_size,
5286 .dir_needs_close = smb2_dir_needs_close,
5287 .get_dfs_refer = smb2_get_dfs_refer,
5288 .select_sectype = smb2_select_sectype,
5289 #ifdef CONFIG_CIFS_XATTR
5290 .query_all_EAs = smb2_query_eas,
5291 .set_EA = smb2_set_ea,
5292 #endif /* CIFS_XATTR */
5293 .get_acl = get_smb2_acl,
5294 .get_acl_by_fid = get_smb2_acl_by_fid,
5295 .set_acl = set_smb2_acl,
5296 .next_header = smb2_next_header,
5297 .ioctl_query_info = smb2_ioctl_query_info,
5298 .make_node = smb2_make_node,
5299 .fiemap = smb3_fiemap,
5300 .llseek = smb3_llseek,
5301 .is_status_io_timeout = smb2_is_status_io_timeout,
5302 .is_network_name_deleted = smb2_is_network_name_deleted,
5304 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
5306 struct smb_version_operations smb21_operations = {
5307 .compare_fids = smb2_compare_fids,
5308 .setup_request = smb2_setup_request,
5309 .setup_async_request = smb2_setup_async_request,
5310 .check_receive = smb2_check_receive,
5311 .add_credits = smb2_add_credits,
5312 .set_credits = smb2_set_credits,
5313 .get_credits_field = smb2_get_credits_field,
5314 .get_credits = smb2_get_credits,
5315 .wait_mtu_credits = smb2_wait_mtu_credits,
5316 .adjust_credits = smb2_adjust_credits,
5317 .get_next_mid = smb2_get_next_mid,
5318 .revert_current_mid = smb2_revert_current_mid,
5319 .read_data_offset = smb2_read_data_offset,
5320 .read_data_length = smb2_read_data_length,
5321 .map_error = map_smb2_to_linux_error,
5322 .find_mid = smb2_find_mid,
5323 .check_message = smb2_check_message,
5324 .dump_detail = smb2_dump_detail,
5325 .clear_stats = smb2_clear_stats,
5326 .print_stats = smb2_print_stats,
5327 .is_oplock_break = smb2_is_valid_oplock_break,
5328 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5329 .downgrade_oplock = smb2_downgrade_oplock,
5330 .need_neg = smb2_need_neg,
5331 .negotiate = smb2_negotiate,
5332 .negotiate_wsize = smb2_negotiate_wsize,
5333 .negotiate_rsize = smb2_negotiate_rsize,
5334 .sess_setup = SMB2_sess_setup,
5335 .logoff = SMB2_logoff,
5336 .tree_connect = SMB2_tcon,
5337 .tree_disconnect = SMB2_tdis,
5338 .qfs_tcon = smb2_qfs_tcon,
5339 .is_path_accessible = smb2_is_path_accessible,
5340 .can_echo = smb2_can_echo,
5342 .query_path_info = smb2_query_path_info,
5343 .get_srv_inum = smb2_get_srv_inum,
5344 .query_file_info = smb2_query_file_info,
5345 .set_path_size = smb2_set_path_size,
5346 .set_file_size = smb2_set_file_size,
5347 .set_file_info = smb2_set_file_info,
5348 .set_compression = smb2_set_compression,
5349 .mkdir = smb2_mkdir,
5350 .mkdir_setinfo = smb2_mkdir_setinfo,
5351 .rmdir = smb2_rmdir,
5352 .unlink = smb2_unlink,
5353 .rename = smb2_rename_path,
5354 .create_hardlink = smb2_create_hardlink,
5355 .query_symlink = smb2_query_symlink,
5356 .query_mf_symlink = smb3_query_mf_symlink,
5357 .create_mf_symlink = smb3_create_mf_symlink,
5358 .open = smb2_open_file,
5359 .set_fid = smb2_set_fid,
5360 .close = smb2_close_file,
5361 .flush = smb2_flush_file,
5362 .async_readv = smb2_async_readv,
5363 .async_writev = smb2_async_writev,
5364 .sync_read = smb2_sync_read,
5365 .sync_write = smb2_sync_write,
5366 .query_dir_first = smb2_query_dir_first,
5367 .query_dir_next = smb2_query_dir_next,
5368 .close_dir = smb2_close_dir,
5369 .calc_smb_size = smb2_calc_size,
5370 .is_status_pending = smb2_is_status_pending,
5371 .is_session_expired = smb2_is_session_expired,
5372 .oplock_response = smb2_oplock_response,
5373 .queryfs = smb2_queryfs,
5374 .mand_lock = smb2_mand_lock,
5375 .mand_unlock_range = smb2_unlock_range,
5376 .push_mand_locks = smb2_push_mandatory_locks,
5377 .get_lease_key = smb2_get_lease_key,
5378 .set_lease_key = smb2_set_lease_key,
5379 .new_lease_key = smb2_new_lease_key,
5380 .calc_signature = smb2_calc_signature,
5381 .is_read_op = smb21_is_read_op,
5382 .set_oplock_level = smb21_set_oplock_level,
5383 .create_lease_buf = smb2_create_lease_buf,
5384 .parse_lease_buf = smb2_parse_lease_buf,
5385 .copychunk_range = smb2_copychunk_range,
5386 .wp_retry_size = smb2_wp_retry_size,
5387 .dir_needs_close = smb2_dir_needs_close,
5388 .enum_snapshots = smb3_enum_snapshots,
5389 .notify = smb3_notify,
5390 .get_dfs_refer = smb2_get_dfs_refer,
5391 .select_sectype = smb2_select_sectype,
5392 #ifdef CONFIG_CIFS_XATTR
5393 .query_all_EAs = smb2_query_eas,
5394 .set_EA = smb2_set_ea,
5395 #endif /* CIFS_XATTR */
5396 .get_acl = get_smb2_acl,
5397 .get_acl_by_fid = get_smb2_acl_by_fid,
5398 .set_acl = set_smb2_acl,
5399 .next_header = smb2_next_header,
5400 .ioctl_query_info = smb2_ioctl_query_info,
5401 .make_node = smb2_make_node,
5402 .fiemap = smb3_fiemap,
5403 .llseek = smb3_llseek,
5404 .is_status_io_timeout = smb2_is_status_io_timeout,
5405 .is_network_name_deleted = smb2_is_network_name_deleted,
5408 struct smb_version_operations smb30_operations = {
5409 .compare_fids = smb2_compare_fids,
5410 .setup_request = smb2_setup_request,
5411 .setup_async_request = smb2_setup_async_request,
5412 .check_receive = smb2_check_receive,
5413 .add_credits = smb2_add_credits,
5414 .set_credits = smb2_set_credits,
5415 .get_credits_field = smb2_get_credits_field,
5416 .get_credits = smb2_get_credits,
5417 .wait_mtu_credits = smb2_wait_mtu_credits,
5418 .adjust_credits = smb2_adjust_credits,
5419 .get_next_mid = smb2_get_next_mid,
5420 .revert_current_mid = smb2_revert_current_mid,
5421 .read_data_offset = smb2_read_data_offset,
5422 .read_data_length = smb2_read_data_length,
5423 .map_error = map_smb2_to_linux_error,
5424 .find_mid = smb2_find_mid,
5425 .check_message = smb2_check_message,
5426 .dump_detail = smb2_dump_detail,
5427 .clear_stats = smb2_clear_stats,
5428 .print_stats = smb2_print_stats,
5429 .dump_share_caps = smb2_dump_share_caps,
5430 .is_oplock_break = smb2_is_valid_oplock_break,
5431 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5432 .downgrade_oplock = smb3_downgrade_oplock,
5433 .need_neg = smb2_need_neg,
5434 .negotiate = smb2_negotiate,
5435 .negotiate_wsize = smb3_negotiate_wsize,
5436 .negotiate_rsize = smb3_negotiate_rsize,
5437 .sess_setup = SMB2_sess_setup,
5438 .logoff = SMB2_logoff,
5439 .tree_connect = SMB2_tcon,
5440 .tree_disconnect = SMB2_tdis,
5441 .qfs_tcon = smb3_qfs_tcon,
5442 .is_path_accessible = smb2_is_path_accessible,
5443 .can_echo = smb2_can_echo,
5445 .query_path_info = smb2_query_path_info,
5446 /* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */
5447 .query_reparse_tag = smb2_query_reparse_tag,
5448 .get_srv_inum = smb2_get_srv_inum,
5449 .query_file_info = smb2_query_file_info,
5450 .set_path_size = smb2_set_path_size,
5451 .set_file_size = smb2_set_file_size,
5452 .set_file_info = smb2_set_file_info,
5453 .set_compression = smb2_set_compression,
5454 .mkdir = smb2_mkdir,
5455 .mkdir_setinfo = smb2_mkdir_setinfo,
5456 .rmdir = smb2_rmdir,
5457 .unlink = smb2_unlink,
5458 .rename = smb2_rename_path,
5459 .create_hardlink = smb2_create_hardlink,
5460 .query_symlink = smb2_query_symlink,
5461 .query_mf_symlink = smb3_query_mf_symlink,
5462 .create_mf_symlink = smb3_create_mf_symlink,
5463 .open = smb2_open_file,
5464 .set_fid = smb2_set_fid,
5465 .close = smb2_close_file,
5466 .close_getattr = smb2_close_getattr,
5467 .flush = smb2_flush_file,
5468 .async_readv = smb2_async_readv,
5469 .async_writev = smb2_async_writev,
5470 .sync_read = smb2_sync_read,
5471 .sync_write = smb2_sync_write,
5472 .query_dir_first = smb2_query_dir_first,
5473 .query_dir_next = smb2_query_dir_next,
5474 .close_dir = smb2_close_dir,
5475 .calc_smb_size = smb2_calc_size,
5476 .is_status_pending = smb2_is_status_pending,
5477 .is_session_expired = smb2_is_session_expired,
5478 .oplock_response = smb2_oplock_response,
5479 .queryfs = smb2_queryfs,
5480 .mand_lock = smb2_mand_lock,
5481 .mand_unlock_range = smb2_unlock_range,
5482 .push_mand_locks = smb2_push_mandatory_locks,
5483 .get_lease_key = smb2_get_lease_key,
5484 .set_lease_key = smb2_set_lease_key,
5485 .new_lease_key = smb2_new_lease_key,
5486 .generate_signingkey = generate_smb30signingkey,
5487 .calc_signature = smb3_calc_signature,
5488 .set_integrity = smb3_set_integrity,
5489 .is_read_op = smb21_is_read_op,
5490 .set_oplock_level = smb3_set_oplock_level,
5491 .create_lease_buf = smb3_create_lease_buf,
5492 .parse_lease_buf = smb3_parse_lease_buf,
5493 .copychunk_range = smb2_copychunk_range,
5494 .duplicate_extents = smb2_duplicate_extents,
5495 .validate_negotiate = smb3_validate_negotiate,
5496 .wp_retry_size = smb2_wp_retry_size,
5497 .dir_needs_close = smb2_dir_needs_close,
5498 .fallocate = smb3_fallocate,
5499 .enum_snapshots = smb3_enum_snapshots,
5500 .notify = smb3_notify,
5501 .init_transform_rq = smb3_init_transform_rq,
5502 .is_transform_hdr = smb3_is_transform_hdr,
5503 .receive_transform = smb3_receive_transform,
5504 .get_dfs_refer = smb2_get_dfs_refer,
5505 .select_sectype = smb2_select_sectype,
5506 #ifdef CONFIG_CIFS_XATTR
5507 .query_all_EAs = smb2_query_eas,
5508 .set_EA = smb2_set_ea,
5509 #endif /* CIFS_XATTR */
5510 .get_acl = get_smb2_acl,
5511 .get_acl_by_fid = get_smb2_acl_by_fid,
5512 .set_acl = set_smb2_acl,
5513 .next_header = smb2_next_header,
5514 .ioctl_query_info = smb2_ioctl_query_info,
5515 .make_node = smb2_make_node,
5516 .fiemap = smb3_fiemap,
5517 .llseek = smb3_llseek,
5518 .is_status_io_timeout = smb2_is_status_io_timeout,
5519 .is_network_name_deleted = smb2_is_network_name_deleted,
5522 struct smb_version_operations smb311_operations = {
5523 .compare_fids = smb2_compare_fids,
5524 .setup_request = smb2_setup_request,
5525 .setup_async_request = smb2_setup_async_request,
5526 .check_receive = smb2_check_receive,
5527 .add_credits = smb2_add_credits,
5528 .set_credits = smb2_set_credits,
5529 .get_credits_field = smb2_get_credits_field,
5530 .get_credits = smb2_get_credits,
5531 .wait_mtu_credits = smb2_wait_mtu_credits,
5532 .adjust_credits = smb2_adjust_credits,
5533 .get_next_mid = smb2_get_next_mid,
5534 .revert_current_mid = smb2_revert_current_mid,
5535 .read_data_offset = smb2_read_data_offset,
5536 .read_data_length = smb2_read_data_length,
5537 .map_error = map_smb2_to_linux_error,
5538 .find_mid = smb2_find_mid,
5539 .check_message = smb2_check_message,
5540 .dump_detail = smb2_dump_detail,
5541 .clear_stats = smb2_clear_stats,
5542 .print_stats = smb2_print_stats,
5543 .dump_share_caps = smb2_dump_share_caps,
5544 .is_oplock_break = smb2_is_valid_oplock_break,
5545 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5546 .downgrade_oplock = smb3_downgrade_oplock,
5547 .need_neg = smb2_need_neg,
5548 .negotiate = smb2_negotiate,
5549 .negotiate_wsize = smb3_negotiate_wsize,
5550 .negotiate_rsize = smb3_negotiate_rsize,
5551 .sess_setup = SMB2_sess_setup,
5552 .logoff = SMB2_logoff,
5553 .tree_connect = SMB2_tcon,
5554 .tree_disconnect = SMB2_tdis,
5555 .qfs_tcon = smb3_qfs_tcon,
5556 .is_path_accessible = smb2_is_path_accessible,
5557 .can_echo = smb2_can_echo,
5559 .query_path_info = smb2_query_path_info,
5560 .query_reparse_tag = smb2_query_reparse_tag,
5561 .get_srv_inum = smb2_get_srv_inum,
5562 .query_file_info = smb2_query_file_info,
5563 .set_path_size = smb2_set_path_size,
5564 .set_file_size = smb2_set_file_size,
5565 .set_file_info = smb2_set_file_info,
5566 .set_compression = smb2_set_compression,
5567 .mkdir = smb2_mkdir,
5568 .mkdir_setinfo = smb2_mkdir_setinfo,
5569 .posix_mkdir = smb311_posix_mkdir,
5570 .rmdir = smb2_rmdir,
5571 .unlink = smb2_unlink,
5572 .rename = smb2_rename_path,
5573 .create_hardlink = smb2_create_hardlink,
5574 .query_symlink = smb2_query_symlink,
5575 .query_mf_symlink = smb3_query_mf_symlink,
5576 .create_mf_symlink = smb3_create_mf_symlink,
5577 .open = smb2_open_file,
5578 .set_fid = smb2_set_fid,
5579 .close = smb2_close_file,
5580 .close_getattr = smb2_close_getattr,
5581 .flush = smb2_flush_file,
5582 .async_readv = smb2_async_readv,
5583 .async_writev = smb2_async_writev,
5584 .sync_read = smb2_sync_read,
5585 .sync_write = smb2_sync_write,
5586 .query_dir_first = smb2_query_dir_first,
5587 .query_dir_next = smb2_query_dir_next,
5588 .close_dir = smb2_close_dir,
5589 .calc_smb_size = smb2_calc_size,
5590 .is_status_pending = smb2_is_status_pending,
5591 .is_session_expired = smb2_is_session_expired,
5592 .oplock_response = smb2_oplock_response,
5593 .queryfs = smb311_queryfs,
5594 .mand_lock = smb2_mand_lock,
5595 .mand_unlock_range = smb2_unlock_range,
5596 .push_mand_locks = smb2_push_mandatory_locks,
5597 .get_lease_key = smb2_get_lease_key,
5598 .set_lease_key = smb2_set_lease_key,
5599 .new_lease_key = smb2_new_lease_key,
5600 .generate_signingkey = generate_smb311signingkey,
5601 .calc_signature = smb3_calc_signature,
5602 .set_integrity = smb3_set_integrity,
5603 .is_read_op = smb21_is_read_op,
5604 .set_oplock_level = smb3_set_oplock_level,
5605 .create_lease_buf = smb3_create_lease_buf,
5606 .parse_lease_buf = smb3_parse_lease_buf,
5607 .copychunk_range = smb2_copychunk_range,
5608 .duplicate_extents = smb2_duplicate_extents,
5609 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
5610 .wp_retry_size = smb2_wp_retry_size,
5611 .dir_needs_close = smb2_dir_needs_close,
5612 .fallocate = smb3_fallocate,
5613 .enum_snapshots = smb3_enum_snapshots,
5614 .notify = smb3_notify,
5615 .init_transform_rq = smb3_init_transform_rq,
5616 .is_transform_hdr = smb3_is_transform_hdr,
5617 .receive_transform = smb3_receive_transform,
5618 .get_dfs_refer = smb2_get_dfs_refer,
5619 .select_sectype = smb2_select_sectype,
5620 #ifdef CONFIG_CIFS_XATTR
5621 .query_all_EAs = smb2_query_eas,
5622 .set_EA = smb2_set_ea,
5623 #endif /* CIFS_XATTR */
5624 .get_acl = get_smb2_acl,
5625 .get_acl_by_fid = get_smb2_acl_by_fid,
5626 .set_acl = set_smb2_acl,
5627 .next_header = smb2_next_header,
5628 .ioctl_query_info = smb2_ioctl_query_info,
5629 .make_node = smb2_make_node,
5630 .fiemap = smb3_fiemap,
5631 .llseek = smb3_llseek,
5632 .is_status_io_timeout = smb2_is_status_io_timeout,
5633 .is_network_name_deleted = smb2_is_network_name_deleted,
5636 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5637 struct smb_version_values smb20_values = {
5638 .version_string = SMB20_VERSION_STRING,
5639 .protocol_id = SMB20_PROT_ID,
5640 .req_capabilities = 0, /* MBZ */
5641 .large_lock_type = 0,
5642 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5643 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5644 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5645 .header_size = sizeof(struct smb2_hdr),
5646 .header_preamble_size = 0,
5647 .max_header_size = MAX_SMB2_HDR_SIZE,
5648 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5649 .lock_cmd = SMB2_LOCK,
5651 .cap_nt_find = SMB2_NT_FIND,
5652 .cap_large_files = SMB2_LARGE_FILES,
5653 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5654 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5655 .create_lease_size = sizeof(struct create_lease),
5657 #endif /* ALLOW_INSECURE_LEGACY */
5659 struct smb_version_values smb21_values = {
5660 .version_string = SMB21_VERSION_STRING,
5661 .protocol_id = SMB21_PROT_ID,
5662 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
5663 .large_lock_type = 0,
5664 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5665 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5666 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5667 .header_size = sizeof(struct smb2_hdr),
5668 .header_preamble_size = 0,
5669 .max_header_size = MAX_SMB2_HDR_SIZE,
5670 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5671 .lock_cmd = SMB2_LOCK,
5673 .cap_nt_find = SMB2_NT_FIND,
5674 .cap_large_files = SMB2_LARGE_FILES,
5675 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5676 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5677 .create_lease_size = sizeof(struct create_lease),
5680 struct smb_version_values smb3any_values = {
5681 .version_string = SMB3ANY_VERSION_STRING,
5682 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5683 .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,
5684 .large_lock_type = 0,
5685 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5686 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5687 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5688 .header_size = sizeof(struct smb2_hdr),
5689 .header_preamble_size = 0,
5690 .max_header_size = MAX_SMB2_HDR_SIZE,
5691 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5692 .lock_cmd = SMB2_LOCK,
5694 .cap_nt_find = SMB2_NT_FIND,
5695 .cap_large_files = SMB2_LARGE_FILES,
5696 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5697 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5698 .create_lease_size = sizeof(struct create_lease_v2),
5701 struct smb_version_values smbdefault_values = {
5702 .version_string = SMBDEFAULT_VERSION_STRING,
5703 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5704 .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,
5705 .large_lock_type = 0,
5706 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5707 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5708 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5709 .header_size = sizeof(struct smb2_hdr),
5710 .header_preamble_size = 0,
5711 .max_header_size = MAX_SMB2_HDR_SIZE,
5712 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5713 .lock_cmd = SMB2_LOCK,
5715 .cap_nt_find = SMB2_NT_FIND,
5716 .cap_large_files = SMB2_LARGE_FILES,
5717 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5718 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5719 .create_lease_size = sizeof(struct create_lease_v2),
5722 struct smb_version_values smb30_values = {
5723 .version_string = SMB30_VERSION_STRING,
5724 .protocol_id = SMB30_PROT_ID,
5725 .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,
5726 .large_lock_type = 0,
5727 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5728 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5729 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5730 .header_size = sizeof(struct smb2_hdr),
5731 .header_preamble_size = 0,
5732 .max_header_size = MAX_SMB2_HDR_SIZE,
5733 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5734 .lock_cmd = SMB2_LOCK,
5736 .cap_nt_find = SMB2_NT_FIND,
5737 .cap_large_files = SMB2_LARGE_FILES,
5738 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5739 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5740 .create_lease_size = sizeof(struct create_lease_v2),
5743 struct smb_version_values smb302_values = {
5744 .version_string = SMB302_VERSION_STRING,
5745 .protocol_id = SMB302_PROT_ID,
5746 .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,
5747 .large_lock_type = 0,
5748 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5749 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5750 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5751 .header_size = sizeof(struct smb2_hdr),
5752 .header_preamble_size = 0,
5753 .max_header_size = MAX_SMB2_HDR_SIZE,
5754 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5755 .lock_cmd = SMB2_LOCK,
5757 .cap_nt_find = SMB2_NT_FIND,
5758 .cap_large_files = SMB2_LARGE_FILES,
5759 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5760 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5761 .create_lease_size = sizeof(struct create_lease_v2),
5764 struct smb_version_values smb311_values = {
5765 .version_string = SMB311_VERSION_STRING,
5766 .protocol_id = SMB311_PROT_ID,
5767 .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,
5768 .large_lock_type = 0,
5769 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
5770 .shared_lock_type = SMB2_LOCKFLAG_SHARED,
5771 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5772 .header_size = sizeof(struct smb2_hdr),
5773 .header_preamble_size = 0,
5774 .max_header_size = MAX_SMB2_HDR_SIZE,
5775 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5776 .lock_cmd = SMB2_LOCK,
5778 .cap_nt_find = SMB2_NT_FIND,
5779 .cap_large_files = SMB2_LARGE_FILES,
5780 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5781 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5782 .create_lease_size = sizeof(struct create_lease_v2),