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 <crypto/aead.h>
16 #include "smb2proto.h"
17 #include "cifsproto.h"
18 #include "cifs_debug.h"
19 #include "cifs_unicode.h"
20 #include "smb2status.h"
22 #include "cifs_ioctl.h"
23 #include "smbdirect.h"
25 /* Change credits for different ops and return the total number of credits */
27 change_conf(struct TCP_Server_Info *server)
29 server->credits += server->echo_credits + server->oplock_credits;
30 server->oplock_credits = server->echo_credits = 0;
31 switch (server->credits) {
35 server->echoes = false;
36 server->oplocks = false;
39 server->echoes = true;
40 server->oplocks = false;
41 server->echo_credits = 1;
44 server->echoes = true;
46 server->oplocks = true;
47 server->oplock_credits = 1;
49 server->oplocks = false;
51 server->echo_credits = 1;
53 server->credits -= server->echo_credits + server->oplock_credits;
54 return server->credits + server->echo_credits + server->oplock_credits;
58 smb2_add_credits(struct TCP_Server_Info *server,
59 const struct cifs_credits *credits, const int optype)
62 unsigned int add = credits->value;
63 unsigned int instance = credits->instance;
64 bool reconnect_detected = false;
66 spin_lock(&server->req_lock);
67 val = server->ops->get_credits_field(server, optype);
69 /* eg found case where write overlapping reconnect messed up credits */
70 if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0))
71 trace_smb3_reconnect_with_invalid_credits(server->CurrentMid,
72 server->hostname, *val);
73 if ((instance == 0) || (instance == server->reconnect_instance))
76 reconnect_detected = true;
79 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
80 printk_once(KERN_WARNING "server overflowed SMB3 credits\n");
83 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
84 rc = change_conf(server);
86 * Sometimes server returns 0 credits on oplock break ack - we need to
87 * rebalance credits in this case.
89 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
91 if (server->credits > 1) {
93 server->oplock_credits++;
96 spin_unlock(&server->req_lock);
97 wake_up(&server->request_q);
99 if (reconnect_detected)
100 cifs_dbg(FYI, "trying to put %d credits from the old server instance %d\n",
103 if (server->tcpStatus == CifsNeedReconnect
104 || server->tcpStatus == CifsExiting)
109 /* change_conf hasn't been executed */
112 cifs_dbg(VFS, "Possible client or server bug - zero credits\n");
115 cifs_dbg(VFS, "disabling echoes and oplocks\n");
118 cifs_dbg(FYI, "disabling oplocks\n");
121 cifs_dbg(FYI, "add %u credits total=%d\n", add, rc);
126 smb2_set_credits(struct TCP_Server_Info *server, const int val)
128 spin_lock(&server->req_lock);
129 server->credits = val;
131 server->reconnect_instance++;
132 spin_unlock(&server->req_lock);
133 /* don't log while holding the lock */
135 cifs_dbg(FYI, "set credits to 1 due to smb2 reconnect\n");
139 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
143 return &server->echo_credits;
145 return &server->oplock_credits;
147 return &server->credits;
152 smb2_get_credits(struct mid_q_entry *mid)
154 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)mid->resp_buf;
156 if (mid->mid_state == MID_RESPONSE_RECEIVED
157 || mid->mid_state == MID_RESPONSE_MALFORMED)
158 return le16_to_cpu(shdr->CreditRequest);
164 smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
165 unsigned int *num, struct cifs_credits *credits)
168 unsigned int scredits;
170 spin_lock(&server->req_lock);
172 if (server->credits <= 0) {
173 spin_unlock(&server->req_lock);
174 cifs_num_waiters_inc(server);
175 rc = wait_event_killable(server->request_q,
176 has_credits(server, &server->credits, 1));
177 cifs_num_waiters_dec(server);
180 spin_lock(&server->req_lock);
182 if (server->tcpStatus == CifsExiting) {
183 spin_unlock(&server->req_lock);
187 scredits = server->credits;
188 /* can deadlock with reopen */
190 *num = SMB2_MAX_BUFFER_SIZE;
192 credits->instance = 0;
196 /* leave some credits for reopen and other ops */
198 *num = min_t(unsigned int, size,
199 scredits * SMB2_MAX_BUFFER_SIZE);
202 DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
203 credits->instance = server->reconnect_instance;
204 server->credits -= credits->value;
209 spin_unlock(&server->req_lock);
214 smb2_adjust_credits(struct TCP_Server_Info *server,
215 struct cifs_credits *credits,
216 const unsigned int payload_size)
218 int new_val = DIV_ROUND_UP(payload_size, SMB2_MAX_BUFFER_SIZE);
220 if (!credits->value || credits->value == new_val)
223 if (credits->value < new_val) {
224 WARN_ONCE(1, "request has less credits (%d) than required (%d)",
225 credits->value, new_val);
229 spin_lock(&server->req_lock);
231 if (server->reconnect_instance != credits->instance) {
232 spin_unlock(&server->req_lock);
233 cifs_dbg(VFS, "trying to return %d credits to old session\n",
234 credits->value - new_val);
238 server->credits += credits->value - new_val;
239 spin_unlock(&server->req_lock);
240 wake_up(&server->request_q);
241 credits->value = new_val;
246 smb2_get_next_mid(struct TCP_Server_Info *server)
249 /* for SMB2 we need the current value */
250 spin_lock(&GlobalMid_Lock);
251 mid = server->CurrentMid++;
252 spin_unlock(&GlobalMid_Lock);
257 smb2_revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
259 spin_lock(&GlobalMid_Lock);
260 if (server->CurrentMid >= val)
261 server->CurrentMid -= val;
262 spin_unlock(&GlobalMid_Lock);
265 static struct mid_q_entry *
266 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
268 struct mid_q_entry *mid;
269 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
270 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
272 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
273 cifs_dbg(VFS, "Encrypted frame parsing not supported yet\n");
277 spin_lock(&GlobalMid_Lock);
278 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
279 if ((mid->mid == wire_mid) &&
280 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
281 (mid->command == shdr->Command)) {
282 kref_get(&mid->refcount);
283 spin_unlock(&GlobalMid_Lock);
287 spin_unlock(&GlobalMid_Lock);
292 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
294 #ifdef CONFIG_CIFS_DEBUG2
295 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
297 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
298 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
300 cifs_dbg(VFS, "smb buf %p len %u\n", buf,
301 server->ops->calc_smb_size(buf, server));
306 smb2_need_neg(struct TCP_Server_Info *server)
308 return server->max_read == 0;
312 smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
316 ses->server->CurrentMid = 0;
317 rc = SMB2_negotiate(xid, ses);
318 /* BB we probably don't need to retry with modern servers */
325 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
327 struct TCP_Server_Info *server = tcon->ses->server;
330 /* start with specified wsize, or default */
331 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
332 wsize = min_t(unsigned int, wsize, server->max_write);
333 #ifdef CONFIG_CIFS_SMB_DIRECT
336 wsize = min_t(unsigned int,
337 wsize, server->smbd_conn->max_fragmented_send_size);
339 wsize = min_t(unsigned int,
340 wsize, server->smbd_conn->max_readwrite_size);
343 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
344 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
350 smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
352 struct TCP_Server_Info *server = tcon->ses->server;
355 /* start with specified wsize, or default */
356 wsize = volume_info->wsize ? volume_info->wsize : SMB3_DEFAULT_IOSIZE;
357 wsize = min_t(unsigned int, wsize, server->max_write);
358 #ifdef CONFIG_CIFS_SMB_DIRECT
361 wsize = min_t(unsigned int,
362 wsize, server->smbd_conn->max_fragmented_send_size);
364 wsize = min_t(unsigned int,
365 wsize, server->smbd_conn->max_readwrite_size);
368 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
369 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
375 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
377 struct TCP_Server_Info *server = tcon->ses->server;
380 /* start with specified rsize, or default */
381 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
382 rsize = min_t(unsigned int, rsize, server->max_read);
383 #ifdef CONFIG_CIFS_SMB_DIRECT
386 rsize = min_t(unsigned int,
387 rsize, server->smbd_conn->max_fragmented_recv_size);
389 rsize = min_t(unsigned int,
390 rsize, server->smbd_conn->max_readwrite_size);
394 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
395 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
401 smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
403 struct TCP_Server_Info *server = tcon->ses->server;
406 /* start with specified rsize, or default */
407 rsize = volume_info->rsize ? volume_info->rsize : SMB3_DEFAULT_IOSIZE;
408 rsize = min_t(unsigned int, rsize, server->max_read);
409 #ifdef CONFIG_CIFS_SMB_DIRECT
412 rsize = min_t(unsigned int,
413 rsize, server->smbd_conn->max_fragmented_recv_size);
415 rsize = min_t(unsigned int,
416 rsize, server->smbd_conn->max_readwrite_size);
420 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
421 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
427 parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
429 struct cifs_server_iface **iface_list,
432 struct network_interface_info_ioctl_rsp *p;
433 struct sockaddr_in *addr4;
434 struct sockaddr_in6 *addr6;
435 struct iface_info_ipv4 *p4;
436 struct iface_info_ipv6 *p6;
437 struct cifs_server_iface *info;
447 * Fist pass: count and sanity check
450 bytes_left = buf_len;
452 while (bytes_left >= sizeof(*p)) {
454 next = le32_to_cpu(p->Next);
456 bytes_left -= sizeof(*p);
459 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
464 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
469 if (bytes_left || p->Next)
470 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
474 * Second pass: extract info to internal structure
477 *iface_list = kcalloc(nb_iface, sizeof(**iface_list), GFP_KERNEL);
484 bytes_left = buf_len;
486 while (bytes_left >= sizeof(*p)) {
487 info->speed = le64_to_cpu(p->LinkSpeed);
488 info->rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE);
489 info->rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE);
491 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, *iface_count);
492 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
493 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
494 le32_to_cpu(p->Capability));
498 * The kernel and wire socket structures have the same
499 * layout and use network byte order but make the
500 * conversion explicit in case either one changes.
503 addr4 = (struct sockaddr_in *)&info->sockaddr;
504 p4 = (struct iface_info_ipv4 *)p->Buffer;
505 addr4->sin_family = AF_INET;
506 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
508 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
509 addr4->sin_port = cpu_to_be16(CIFS_PORT);
511 cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
515 addr6 = (struct sockaddr_in6 *)&info->sockaddr;
516 p6 = (struct iface_info_ipv6 *)p->Buffer;
517 addr6->sin6_family = AF_INET6;
518 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
520 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
521 addr6->sin6_flowinfo = 0;
522 addr6->sin6_scope_id = 0;
523 addr6->sin6_port = cpu_to_be16(CIFS_PORT);
525 cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
530 "%s: skipping unsupported socket family\n",
538 next = le32_to_cpu(p->Next);
541 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
561 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
564 unsigned int ret_data_len = 0;
565 struct network_interface_info_ioctl_rsp *out_buf = NULL;
566 struct cifs_server_iface *iface_list;
568 struct cifs_ses *ses = tcon->ses;
570 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
571 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
572 NULL /* no data input */, 0 /* no data input */,
573 CIFSMaxBufSize, (char **)&out_buf, &ret_data_len);
574 if (rc == -EOPNOTSUPP) {
576 "server does not support query network interfaces\n");
578 } else if (rc != 0) {
579 cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
583 rc = parse_server_interfaces(out_buf, ret_data_len,
584 &iface_list, &iface_count);
588 spin_lock(&ses->iface_lock);
589 kfree(ses->iface_list);
590 ses->iface_list = iface_list;
591 ses->iface_count = iface_count;
592 ses->iface_last_update = jiffies;
593 spin_unlock(&ses->iface_lock);
601 smb2_close_cached_fid(struct kref *ref)
603 struct cached_fid *cfid = container_of(ref, struct cached_fid,
606 if (cfid->is_valid) {
607 cifs_dbg(FYI, "clear cached root file handle\n");
608 SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid,
609 cfid->fid->volatile_fid);
610 cfid->is_valid = false;
611 cfid->file_all_info_is_valid = false;
615 void close_shroot(struct cached_fid *cfid)
617 mutex_lock(&cfid->fid_mutex);
618 kref_put(&cfid->refcount, smb2_close_cached_fid);
619 mutex_unlock(&cfid->fid_mutex);
623 smb2_cached_lease_break(struct work_struct *work)
625 struct cached_fid *cfid = container_of(work,
626 struct cached_fid, lease_break);
632 * Open the directory at the root of a share
634 int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid)
636 struct cifs_ses *ses = tcon->ses;
637 struct TCP_Server_Info *server = ses->server;
638 struct cifs_open_parms oparms;
639 struct smb2_create_rsp *o_rsp = NULL;
640 struct smb2_query_info_rsp *qi_rsp = NULL;
642 struct smb_rqst rqst[2];
643 struct kvec rsp_iov[2];
644 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
645 struct kvec qi_iov[1];
647 __le16 utf16_path = 0; /* Null - since an open of top of share */
648 u8 oplock = SMB2_OPLOCK_LEVEL_II;
650 mutex_lock(&tcon->crfid.fid_mutex);
651 if (tcon->crfid.is_valid) {
652 cifs_dbg(FYI, "found a cached root file handle\n");
653 memcpy(pfid, tcon->crfid.fid, sizeof(struct cifs_fid));
654 kref_get(&tcon->crfid.refcount);
655 mutex_unlock(&tcon->crfid.fid_mutex);
659 if (smb3_encryption_required(tcon))
660 flags |= CIFS_TRANSFORM_REQ;
662 memset(rqst, 0, sizeof(rqst));
663 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
664 memset(rsp_iov, 0, sizeof(rsp_iov));
667 memset(&open_iov, 0, sizeof(open_iov));
668 rqst[0].rq_iov = open_iov;
669 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
672 oparms.create_options = 0;
673 oparms.desired_access = FILE_READ_ATTRIBUTES;
674 oparms.disposition = FILE_OPEN;
676 oparms.reconnect = false;
678 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, &utf16_path);
681 smb2_set_next_command(tcon, &rqst[0]);
683 memset(&qi_iov, 0, sizeof(qi_iov));
684 rqst[1].rq_iov = qi_iov;
687 rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID,
688 COMPOUND_FID, FILE_ALL_INFORMATION,
690 sizeof(struct smb2_file_all_info) +
691 PATH_MAX * 2, 0, NULL);
695 smb2_set_related(&rqst[1]);
698 * We do not hold the lock for the open because in case
699 * SMB2_open needs to reconnect, it will end up calling
700 * cifs_mark_open_files_invalid() which takes the lock again
701 * thus causing a deadlock
704 mutex_unlock(&tcon->crfid.fid_mutex);
705 rc = compound_send_recv(xid, ses, flags, 2, rqst,
706 resp_buftype, rsp_iov);
707 mutex_lock(&tcon->crfid.fid_mutex);
710 * Now we need to check again as the cached root might have
711 * been successfully re-opened from a concurrent process
714 if (tcon->crfid.is_valid) {
715 /* work was already done */
717 /* stash fids for close() later */
718 struct cifs_fid fid = {
719 .persistent_fid = pfid->persistent_fid,
720 .volatile_fid = pfid->volatile_fid,
724 * caller expects this func to set pfid to a valid
725 * cached root, so we copy the existing one and get a
728 memcpy(pfid, tcon->crfid.fid, sizeof(*pfid));
729 kref_get(&tcon->crfid.refcount);
731 mutex_unlock(&tcon->crfid.fid_mutex);
734 /* close extra handle outside of crit sec */
735 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
740 /* Cached root is still invalid, continue normaly */
745 o_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
746 oparms.fid->persistent_fid = o_rsp->PersistentFileId;
747 oparms.fid->volatile_fid = o_rsp->VolatileFileId;
748 #ifdef CONFIG_CIFS_DEBUG2
749 oparms.fid->mid = le64_to_cpu(o_rsp->sync_hdr.MessageId);
750 #endif /* CIFS_DEBUG2 */
752 memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid));
753 tcon->crfid.tcon = tcon;
754 tcon->crfid.is_valid = true;
755 kref_init(&tcon->crfid.refcount);
757 /* BB TBD check to see if oplock level check can be removed below */
758 if (o_rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE) {
759 kref_get(&tcon->crfid.refcount);
760 smb2_parse_contexts(server, o_rsp,
762 oparms.fid->lease_key, &oplock, NULL);
766 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
767 if (le32_to_cpu(qi_rsp->OutputBufferLength) < sizeof(struct smb2_file_all_info))
769 if (!smb2_validate_and_copy_iov(
770 le16_to_cpu(qi_rsp->OutputBufferOffset),
771 sizeof(struct smb2_file_all_info),
772 &rsp_iov[1], sizeof(struct smb2_file_all_info),
773 (char *)&tcon->crfid.file_all_info))
774 tcon->crfid.file_all_info_is_valid = 1;
777 mutex_unlock(&tcon->crfid.fid_mutex);
779 SMB2_open_free(&rqst[0]);
780 SMB2_query_info_free(&rqst[1]);
781 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
782 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
787 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
790 __le16 srch_path = 0; /* Null - open root of share */
791 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
792 struct cifs_open_parms oparms;
794 bool no_cached_open = tcon->nohandlecache;
797 oparms.desired_access = FILE_READ_ATTRIBUTES;
798 oparms.disposition = FILE_OPEN;
799 oparms.create_options = 0;
801 oparms.reconnect = false;
804 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
807 rc = open_shroot(xid, tcon, &fid);
812 SMB3_request_interfaces(xid, tcon);
814 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
815 FS_ATTRIBUTE_INFORMATION);
816 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
817 FS_DEVICE_INFORMATION);
818 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
819 FS_VOLUME_INFORMATION);
820 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
821 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
823 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
825 close_shroot(&tcon->crfid);
829 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
832 __le16 srch_path = 0; /* Null - open root of share */
833 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
834 struct cifs_open_parms oparms;
838 oparms.desired_access = FILE_READ_ATTRIBUTES;
839 oparms.disposition = FILE_OPEN;
840 oparms.create_options = 0;
842 oparms.reconnect = false;
844 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
848 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
849 FS_ATTRIBUTE_INFORMATION);
850 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
851 FS_DEVICE_INFORMATION);
852 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
856 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
857 struct cifs_sb_info *cifs_sb, const char *full_path)
861 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
862 struct cifs_open_parms oparms;
865 if ((*full_path == 0) && tcon->crfid.is_valid)
868 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
873 oparms.desired_access = FILE_READ_ATTRIBUTES;
874 oparms.disposition = FILE_OPEN;
875 if (backup_cred(cifs_sb))
876 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
878 oparms.create_options = 0;
880 oparms.reconnect = false;
882 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
888 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
894 smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
895 struct cifs_sb_info *cifs_sb, const char *full_path,
896 u64 *uniqueid, FILE_ALL_INFO *data)
898 *uniqueid = le64_to_cpu(data->IndexNumber);
903 smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
904 struct cifs_fid *fid, FILE_ALL_INFO *data)
907 struct smb2_file_all_info *smb2_data;
909 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
911 if (smb2_data == NULL)
914 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
917 move_smb2_info_to_cifs(data, smb2_data);
922 #ifdef CONFIG_CIFS_XATTR
924 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
925 struct smb2_file_full_ea_info *src, size_t src_size,
926 const unsigned char *ea_name)
929 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
931 size_t buf_size = dst_size;
932 size_t name_len, value_len, user_name_len;
934 while (src_size > 0) {
935 name = &src->ea_data[0];
936 name_len = (size_t)src->ea_name_length;
937 value = &src->ea_data[src->ea_name_length + 1];
938 value_len = (size_t)le16_to_cpu(src->ea_value_length);
943 if (src_size < 8 + name_len + 1 + value_len) {
944 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
950 if (ea_name_len == name_len &&
951 memcmp(ea_name, name, name_len) == 0) {
955 if (dst_size < value_len) {
959 memcpy(dst, value, value_len);
963 /* 'user.' plus a terminating null */
964 user_name_len = 5 + 1 + name_len;
967 /* skip copy - calc size only */
969 } else if (dst_size >= user_name_len) {
970 dst_size -= user_name_len;
971 memcpy(dst, "user.", 5);
973 memcpy(dst, src->ea_data, name_len);
979 /* stop before overrun buffer */
985 if (!src->next_entry_offset)
988 if (src_size < le32_to_cpu(src->next_entry_offset)) {
989 /* stop before overrun buffer */
993 src_size -= le32_to_cpu(src->next_entry_offset);
994 src = (void *)((char *)src +
995 le32_to_cpu(src->next_entry_offset));
998 /* didn't find the named attribute */
1007 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
1008 const unsigned char *path, const unsigned char *ea_name,
1009 char *ea_data, size_t buf_size,
1010 struct cifs_sb_info *cifs_sb)
1014 struct kvec rsp_iov = {NULL, 0};
1015 int buftype = CIFS_NO_BUFFER;
1016 struct smb2_query_info_rsp *rsp;
1017 struct smb2_file_full_ea_info *info = NULL;
1019 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1023 rc = smb2_query_info_compound(xid, tcon, utf16_path,
1025 FILE_FULL_EA_INFORMATION,
1028 MAX_SMB2_CREATE_RESPONSE_SIZE -
1029 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1030 &rsp_iov, &buftype, cifs_sb);
1033 * If ea_name is NULL (listxattr) and there are no EAs,
1034 * return 0 as it's not an error. Otherwise, the specified
1035 * ea_name was not found.
1037 if (!ea_name && rc == -ENODATA)
1042 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
1043 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1044 le32_to_cpu(rsp->OutputBufferLength),
1046 sizeof(struct smb2_file_full_ea_info));
1050 info = (struct smb2_file_full_ea_info *)(
1051 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1052 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
1053 le32_to_cpu(rsp->OutputBufferLength), ea_name);
1057 free_rsp_buf(buftype, rsp_iov.iov_base);
1063 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
1064 const char *path, const char *ea_name, const void *ea_value,
1065 const __u16 ea_value_len, const struct nls_table *nls_codepage,
1066 struct cifs_sb_info *cifs_sb)
1068 struct cifs_ses *ses = tcon->ses;
1069 __le16 *utf16_path = NULL;
1070 int ea_name_len = strlen(ea_name);
1073 struct smb_rqst rqst[3];
1074 int resp_buftype[3];
1075 struct kvec rsp_iov[3];
1076 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1077 struct cifs_open_parms oparms;
1078 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1079 struct cifs_fid fid;
1080 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1081 unsigned int size[1];
1083 struct smb2_file_full_ea_info *ea = NULL;
1084 struct kvec close_iov[1];
1087 if (smb3_encryption_required(tcon))
1088 flags |= CIFS_TRANSFORM_REQ;
1090 if (ea_name_len > 255)
1093 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1097 memset(rqst, 0, sizeof(rqst));
1098 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1099 memset(rsp_iov, 0, sizeof(rsp_iov));
1101 if (ses->server->ops->query_all_EAs) {
1103 rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1112 memset(&open_iov, 0, sizeof(open_iov));
1113 rqst[0].rq_iov = open_iov;
1114 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1116 memset(&oparms, 0, sizeof(oparms));
1118 oparms.desired_access = FILE_WRITE_EA;
1119 oparms.disposition = FILE_OPEN;
1120 if (backup_cred(cifs_sb))
1121 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1123 oparms.create_options = 0;
1125 oparms.reconnect = false;
1127 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, utf16_path);
1130 smb2_set_next_command(tcon, &rqst[0]);
1134 memset(&si_iov, 0, sizeof(si_iov));
1135 rqst[1].rq_iov = si_iov;
1136 rqst[1].rq_nvec = 1;
1138 len = sizeof(ea) + ea_name_len + ea_value_len + 1;
1139 ea = kzalloc(len, GFP_KERNEL);
1145 ea->ea_name_length = ea_name_len;
1146 ea->ea_value_length = cpu_to_le16(ea_value_len);
1147 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
1148 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
1153 rc = SMB2_set_info_init(tcon, &rqst[1], COMPOUND_FID,
1154 COMPOUND_FID, current->tgid,
1155 FILE_FULL_EA_INFORMATION,
1156 SMB2_O_INFO_FILE, 0, data, size);
1157 smb2_set_next_command(tcon, &rqst[1]);
1158 smb2_set_related(&rqst[1]);
1162 memset(&close_iov, 0, sizeof(close_iov));
1163 rqst[2].rq_iov = close_iov;
1164 rqst[2].rq_nvec = 1;
1165 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
1166 smb2_set_related(&rqst[2]);
1168 rc = compound_send_recv(xid, ses, flags, 3, rqst,
1169 resp_buftype, rsp_iov);
1174 SMB2_open_free(&rqst[0]);
1175 SMB2_set_info_free(&rqst[1]);
1176 SMB2_close_free(&rqst[2]);
1177 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1178 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1179 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1185 smb2_can_echo(struct TCP_Server_Info *server)
1187 return server->echoes;
1191 smb2_clear_stats(struct cifs_tcon *tcon)
1195 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1196 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1197 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1202 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1204 seq_puts(m, "\n\tShare Capabilities:");
1205 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1206 seq_puts(m, " DFS,");
1207 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1208 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1209 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1210 seq_puts(m, " SCALEOUT,");
1211 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1212 seq_puts(m, " CLUSTER,");
1213 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1214 seq_puts(m, " ASYMMETRIC,");
1215 if (tcon->capabilities == 0)
1216 seq_puts(m, " None");
1217 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1218 seq_puts(m, " Aligned,");
1219 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1220 seq_puts(m, " Partition Aligned,");
1221 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1222 seq_puts(m, " SSD,");
1223 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1224 seq_puts(m, " TRIM-support,");
1226 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1227 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1228 if (tcon->perf_sector_size)
1229 seq_printf(m, "\tOptimal sector size: 0x%x",
1230 tcon->perf_sector_size);
1231 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1235 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1237 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1238 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1241 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1242 * totals (requests sent) since those SMBs are per-session not per tcon
1244 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1245 (long long)(tcon->bytes_read),
1246 (long long)(tcon->bytes_written));
1247 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1248 atomic_read(&tcon->num_local_opens),
1249 atomic_read(&tcon->num_remote_opens));
1250 seq_printf(m, "\nTreeConnects: %d total %d failed",
1251 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1252 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1253 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1254 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1255 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1256 seq_printf(m, "\nCreates: %d total %d failed",
1257 atomic_read(&sent[SMB2_CREATE_HE]),
1258 atomic_read(&failed[SMB2_CREATE_HE]));
1259 seq_printf(m, "\nCloses: %d total %d failed",
1260 atomic_read(&sent[SMB2_CLOSE_HE]),
1261 atomic_read(&failed[SMB2_CLOSE_HE]));
1262 seq_printf(m, "\nFlushes: %d total %d failed",
1263 atomic_read(&sent[SMB2_FLUSH_HE]),
1264 atomic_read(&failed[SMB2_FLUSH_HE]));
1265 seq_printf(m, "\nReads: %d total %d failed",
1266 atomic_read(&sent[SMB2_READ_HE]),
1267 atomic_read(&failed[SMB2_READ_HE]));
1268 seq_printf(m, "\nWrites: %d total %d failed",
1269 atomic_read(&sent[SMB2_WRITE_HE]),
1270 atomic_read(&failed[SMB2_WRITE_HE]));
1271 seq_printf(m, "\nLocks: %d total %d failed",
1272 atomic_read(&sent[SMB2_LOCK_HE]),
1273 atomic_read(&failed[SMB2_LOCK_HE]));
1274 seq_printf(m, "\nIOCTLs: %d total %d failed",
1275 atomic_read(&sent[SMB2_IOCTL_HE]),
1276 atomic_read(&failed[SMB2_IOCTL_HE]));
1277 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1278 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1279 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1280 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1281 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1282 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1283 seq_printf(m, "\nQueryInfos: %d total %d failed",
1284 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1285 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1286 seq_printf(m, "\nSetInfos: %d total %d failed",
1287 atomic_read(&sent[SMB2_SET_INFO_HE]),
1288 atomic_read(&failed[SMB2_SET_INFO_HE]));
1289 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1290 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1291 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1295 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1297 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1298 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1300 cfile->fid.persistent_fid = fid->persistent_fid;
1301 cfile->fid.volatile_fid = fid->volatile_fid;
1302 #ifdef CONFIG_CIFS_DEBUG2
1303 cfile->fid.mid = fid->mid;
1304 #endif /* CIFS_DEBUG2 */
1305 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1307 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1308 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1312 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1313 struct cifs_fid *fid)
1315 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1319 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1320 u64 persistent_fid, u64 volatile_fid,
1321 struct copychunk_ioctl *pcchunk)
1324 unsigned int ret_data_len;
1325 struct resume_key_req *res_key;
1327 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1328 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
1329 NULL, 0 /* no input */, CIFSMaxBufSize,
1330 (char **)&res_key, &ret_data_len);
1333 cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1334 goto req_res_key_exit;
1336 if (ret_data_len < sizeof(struct resume_key_req)) {
1337 cifs_dbg(VFS, "Invalid refcopy resume key length\n");
1339 goto req_res_key_exit;
1341 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1349 smb2_ioctl_query_info(const unsigned int xid,
1350 struct cifs_tcon *tcon,
1351 __le16 *path, int is_dir,
1354 struct cifs_ses *ses = tcon->ses;
1355 char __user *arg = (char __user *)p;
1356 struct smb_query_info qi;
1357 struct smb_query_info __user *pqi;
1360 struct smb2_query_info_rsp *qi_rsp = NULL;
1361 struct smb2_ioctl_rsp *io_rsp = NULL;
1362 void *buffer = NULL;
1363 struct smb_rqst rqst[3];
1364 int resp_buftype[3];
1365 struct kvec rsp_iov[3];
1366 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1367 struct cifs_open_parms oparms;
1368 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1369 struct cifs_fid fid;
1370 struct kvec qi_iov[1];
1371 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
1372 struct kvec close_iov[1];
1374 memset(rqst, 0, sizeof(rqst));
1375 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1376 memset(rsp_iov, 0, sizeof(rsp_iov));
1378 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info)))
1381 if (qi.output_buffer_length > 1024)
1384 if (!ses || !(ses->server))
1387 if (smb3_encryption_required(tcon))
1388 flags |= CIFS_TRANSFORM_REQ;
1390 buffer = kmalloc(qi.output_buffer_length, GFP_KERNEL);
1394 if (copy_from_user(buffer, arg + sizeof(struct smb_query_info),
1395 qi.output_buffer_length)) {
1401 memset(&open_iov, 0, sizeof(open_iov));
1402 rqst[0].rq_iov = open_iov;
1403 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1405 memset(&oparms, 0, sizeof(oparms));
1407 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1408 oparms.disposition = FILE_OPEN;
1410 oparms.create_options = CREATE_NOT_FILE;
1412 oparms.create_options = CREATE_NOT_DIR;
1414 oparms.reconnect = false;
1417 * FSCTL codes encode the special access they need in the fsctl code.
1419 if (qi.flags & PASSTHRU_FSCTL) {
1420 switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1421 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1422 oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1424 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1425 oparms.desired_access = GENERIC_ALL;
1427 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1428 oparms.desired_access = GENERIC_READ;
1430 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1431 oparms.desired_access = GENERIC_WRITE;
1436 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, path);
1439 smb2_set_next_command(tcon, &rqst[0]);
1442 if (qi.flags & PASSTHRU_FSCTL) {
1443 /* Can eventually relax perm check since server enforces too */
1444 if (!capable(CAP_SYS_ADMIN))
1447 memset(&io_iov, 0, sizeof(io_iov));
1448 rqst[1].rq_iov = io_iov;
1449 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1451 rc = SMB2_ioctl_init(tcon, &rqst[1],
1452 COMPOUND_FID, COMPOUND_FID,
1453 qi.info_type, true, buffer,
1454 qi.output_buffer_length,
1457 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1458 memset(&qi_iov, 0, sizeof(qi_iov));
1459 rqst[1].rq_iov = qi_iov;
1460 rqst[1].rq_nvec = 1;
1462 rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID,
1463 COMPOUND_FID, qi.file_info_class,
1464 qi.info_type, qi.additional_information,
1465 qi.input_buffer_length,
1466 qi.output_buffer_length, buffer);
1467 } else { /* unknown flags */
1468 cifs_dbg(VFS, "invalid passthru query flags: 0x%x\n", qi.flags);
1474 smb2_set_next_command(tcon, &rqst[1]);
1475 smb2_set_related(&rqst[1]);
1478 memset(&close_iov, 0, sizeof(close_iov));
1479 rqst[2].rq_iov = close_iov;
1480 rqst[2].rq_nvec = 1;
1482 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
1485 smb2_set_related(&rqst[2]);
1487 rc = compound_send_recv(xid, ses, flags, 3, rqst,
1488 resp_buftype, rsp_iov);
1491 if (qi.flags & PASSTHRU_FSCTL) {
1492 pqi = (struct smb_query_info __user *)arg;
1493 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1494 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1495 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1496 if (qi.input_buffer_length > 0 &&
1497 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length > rsp_iov[1].iov_len) {
1501 if (copy_to_user(&pqi->input_buffer_length, &qi.input_buffer_length,
1502 sizeof(qi.input_buffer_length))) {
1506 if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1507 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1508 qi.input_buffer_length)) {
1513 pqi = (struct smb_query_info __user *)arg;
1514 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1515 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1516 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1517 if (copy_to_user(&pqi->input_buffer_length, &qi.input_buffer_length,
1518 sizeof(qi.input_buffer_length))) {
1522 if (copy_to_user(pqi + 1, qi_rsp->Buffer, qi.input_buffer_length)) {
1530 SMB2_open_free(&rqst[0]);
1531 if (qi.flags & PASSTHRU_FSCTL)
1532 SMB2_ioctl_free(&rqst[1]);
1534 SMB2_query_info_free(&rqst[1]);
1536 SMB2_close_free(&rqst[2]);
1537 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1538 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1539 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1544 smb2_copychunk_range(const unsigned int xid,
1545 struct cifsFileInfo *srcfile,
1546 struct cifsFileInfo *trgtfile, u64 src_off,
1547 u64 len, u64 dest_off)
1550 unsigned int ret_data_len;
1551 struct copychunk_ioctl *pcchunk;
1552 struct copychunk_ioctl_rsp *retbuf = NULL;
1553 struct cifs_tcon *tcon;
1554 int chunks_copied = 0;
1555 bool chunk_sizes_updated = false;
1556 ssize_t bytes_written, total_bytes_written = 0;
1558 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1560 if (pcchunk == NULL)
1563 cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
1564 /* Request a key from the server to identify the source of the copy */
1565 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1566 srcfile->fid.persistent_fid,
1567 srcfile->fid.volatile_fid, pcchunk);
1569 /* Note: request_res_key sets res_key null only if rc !=0 */
1573 /* For now array only one chunk long, will make more flexible later */
1574 pcchunk->ChunkCount = cpu_to_le32(1);
1575 pcchunk->Reserved = 0;
1576 pcchunk->Reserved2 = 0;
1578 tcon = tlink_tcon(trgtfile->tlink);
1581 pcchunk->SourceOffset = cpu_to_le64(src_off);
1582 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1584 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
1586 /* Request server copy to target from src identified by key */
1587 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1588 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1589 true /* is_fsctl */, (char *)pcchunk,
1590 sizeof(struct copychunk_ioctl), CIFSMaxBufSize,
1591 (char **)&retbuf, &ret_data_len);
1594 sizeof(struct copychunk_ioctl_rsp)) {
1595 cifs_dbg(VFS, "invalid cchunk response size\n");
1599 if (retbuf->TotalBytesWritten == 0) {
1600 cifs_dbg(FYI, "no bytes copied\n");
1605 * Check if server claimed to write more than we asked
1607 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1608 le32_to_cpu(pcchunk->Length)) {
1609 cifs_dbg(VFS, "invalid copy chunk response\n");
1613 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1614 cifs_dbg(VFS, "invalid num chunks written\n");
1620 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1621 src_off += bytes_written;
1622 dest_off += bytes_written;
1623 len -= bytes_written;
1624 total_bytes_written += bytes_written;
1626 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1627 le32_to_cpu(retbuf->ChunksWritten),
1628 le32_to_cpu(retbuf->ChunkBytesWritten),
1630 } else if (rc == -EINVAL) {
1631 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1634 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1635 le32_to_cpu(retbuf->ChunksWritten),
1636 le32_to_cpu(retbuf->ChunkBytesWritten),
1637 le32_to_cpu(retbuf->TotalBytesWritten));
1640 * Check if this is the first request using these sizes,
1641 * (ie check if copy succeed once with original sizes
1642 * and check if the server gave us different sizes after
1643 * we already updated max sizes on previous request).
1644 * if not then why is the server returning an error now
1646 if ((chunks_copied != 0) || chunk_sizes_updated)
1649 /* Check that server is not asking us to grow size */
1650 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1651 tcon->max_bytes_chunk)
1652 tcon->max_bytes_chunk =
1653 le32_to_cpu(retbuf->ChunkBytesWritten);
1655 goto cchunk_out; /* server gave us bogus size */
1657 /* No need to change MaxChunks since already set to 1 */
1658 chunk_sizes_updated = true;
1669 return total_bytes_written;
1673 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1674 struct cifs_fid *fid)
1676 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1680 smb2_read_data_offset(char *buf)
1682 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1684 return rsp->DataOffset;
1688 smb2_read_data_length(char *buf, bool in_remaining)
1690 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1693 return le32_to_cpu(rsp->DataRemaining);
1695 return le32_to_cpu(rsp->DataLength);
1700 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1701 struct cifs_io_parms *parms, unsigned int *bytes_read,
1702 char **buf, int *buf_type)
1704 parms->persistent_fid = pfid->persistent_fid;
1705 parms->volatile_fid = pfid->volatile_fid;
1706 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1710 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1711 struct cifs_io_parms *parms, unsigned int *written,
1712 struct kvec *iov, unsigned long nr_segs)
1715 parms->persistent_fid = pfid->persistent_fid;
1716 parms->volatile_fid = pfid->volatile_fid;
1717 return SMB2_write(xid, parms, written, iov, nr_segs);
1720 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1721 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1722 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1724 struct cifsInodeInfo *cifsi;
1727 cifsi = CIFS_I(inode);
1729 /* if file already sparse don't bother setting sparse again */
1730 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1731 return true; /* already sparse */
1733 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1734 return true; /* already not sparse */
1737 * Can't check for sparse support on share the usual way via the
1738 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1739 * since Samba server doesn't set the flag on the share, yet
1740 * supports the set sparse FSCTL and returns sparse correctly
1741 * in the file attributes. If we fail setting sparse though we
1742 * mark that server does not support sparse files for this share
1743 * to avoid repeatedly sending the unsupported fsctl to server
1744 * if the file is repeatedly extended.
1746 if (tcon->broken_sparse_sup)
1749 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1750 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1752 &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
1754 tcon->broken_sparse_sup = true;
1755 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1760 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1762 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1768 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1769 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1771 __le64 eof = cpu_to_le64(size);
1772 struct inode *inode;
1775 * If extending file more than one page make sparse. Many Linux fs
1776 * make files sparse by default when extending via ftruncate
1778 inode = d_inode(cfile->dentry);
1780 if (!set_alloc && (size > inode->i_size + 8192)) {
1781 __u8 set_sparse = 1;
1783 /* whether set sparse succeeds or not, extend the file */
1784 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1787 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1788 cfile->fid.volatile_fid, cfile->pid, &eof);
1792 smb2_duplicate_extents(const unsigned int xid,
1793 struct cifsFileInfo *srcfile,
1794 struct cifsFileInfo *trgtfile, u64 src_off,
1795 u64 len, u64 dest_off)
1798 unsigned int ret_data_len;
1799 struct duplicate_extents_to_file dup_ext_buf;
1800 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1802 /* server fileays advertise duplicate extent support with this flag */
1803 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1804 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1807 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1808 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1809 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1810 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1811 dup_ext_buf.ByteCount = cpu_to_le64(len);
1812 cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
1813 src_off, dest_off, len);
1815 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1817 goto duplicate_extents_out;
1819 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1820 trgtfile->fid.volatile_fid,
1821 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1822 true /* is_fsctl */,
1823 (char *)&dup_ext_buf,
1824 sizeof(struct duplicate_extents_to_file),
1825 CIFSMaxBufSize, NULL,
1828 if (ret_data_len > 0)
1829 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
1831 duplicate_extents_out:
1836 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1837 struct cifsFileInfo *cfile)
1839 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1840 cfile->fid.volatile_fid);
1844 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
1845 struct cifsFileInfo *cfile)
1847 struct fsctl_set_integrity_information_req integr_info;
1848 unsigned int ret_data_len;
1850 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
1851 integr_info.Flags = 0;
1852 integr_info.Reserved = 0;
1854 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1855 cfile->fid.volatile_fid,
1856 FSCTL_SET_INTEGRITY_INFORMATION,
1857 true /* is_fsctl */,
1858 (char *)&integr_info,
1859 sizeof(struct fsctl_set_integrity_information_req),
1860 CIFSMaxBufSize, NULL,
1865 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
1866 #define GMT_TOKEN_SIZE 50
1868 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
1871 * Input buffer contains (empty) struct smb_snapshot array with size filled in
1872 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
1875 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
1876 struct cifsFileInfo *cfile, void __user *ioc_buf)
1878 char *retbuf = NULL;
1879 unsigned int ret_data_len = 0;
1881 u32 max_response_size;
1882 struct smb_snapshot_array snapshot_in;
1885 * On the first query to enumerate the list of snapshots available
1886 * for this volume the buffer begins with 0 (number of snapshots
1887 * which can be returned is zero since at that point we do not know
1888 * how big the buffer needs to be). On the second query,
1889 * it (ret_data_len) is set to number of snapshots so we can
1890 * know to set the maximum response size larger (see below).
1892 if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
1896 * Note that for snapshot queries that servers like Azure expect that
1897 * the first query be minimal size (and just used to get the number/size
1898 * of previous versions) so response size must be specified as EXACTLY
1899 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
1902 if (ret_data_len == 0)
1903 max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
1905 max_response_size = CIFSMaxBufSize;
1907 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1908 cfile->fid.volatile_fid,
1909 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
1910 true /* is_fsctl */,
1911 NULL, 0 /* no input data */, max_response_size,
1914 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
1919 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
1921 if (copy_from_user(&snapshot_in, ioc_buf,
1922 sizeof(struct smb_snapshot_array))) {
1929 * Check for min size, ie not large enough to fit even one GMT
1930 * token (snapshot). On the first ioctl some users may pass in
1931 * smaller size (or zero) to simply get the size of the array
1932 * so the user space caller can allocate sufficient memory
1933 * and retry the ioctl again with larger array size sufficient
1934 * to hold all of the snapshot GMT tokens on the second try.
1936 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
1937 ret_data_len = sizeof(struct smb_snapshot_array);
1940 * We return struct SRV_SNAPSHOT_ARRAY, followed by
1941 * the snapshot array (of 50 byte GMT tokens) each
1942 * representing an available previous version of the data
1944 if (ret_data_len > (snapshot_in.snapshot_array_size +
1945 sizeof(struct smb_snapshot_array)))
1946 ret_data_len = snapshot_in.snapshot_array_size +
1947 sizeof(struct smb_snapshot_array);
1949 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
1958 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
1959 const char *path, struct cifs_sb_info *cifs_sb,
1960 struct cifs_fid *fid, __u16 search_flags,
1961 struct cifs_search_info *srch_inf)
1965 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1966 struct cifs_open_parms oparms;
1968 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1973 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
1974 oparms.disposition = FILE_OPEN;
1975 if (backup_cred(cifs_sb))
1976 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1978 oparms.create_options = 0;
1980 oparms.reconnect = false;
1982 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
1985 cifs_dbg(FYI, "open dir failed rc=%d\n", rc);
1989 srch_inf->entries_in_buffer = 0;
1990 srch_inf->index_of_last_entry = 2;
1992 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
1993 fid->volatile_fid, 0, srch_inf);
1995 cifs_dbg(FYI, "query directory failed rc=%d\n", rc);
1996 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2002 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
2003 struct cifs_fid *fid, __u16 search_flags,
2004 struct cifs_search_info *srch_inf)
2006 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
2007 fid->volatile_fid, 0, srch_inf);
2011 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
2012 struct cifs_fid *fid)
2014 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2018 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2019 * the number of credits and return true. Otherwise - return false.
2022 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
2024 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2026 if (shdr->Status != STATUS_PENDING)
2029 if (shdr->CreditRequest) {
2030 spin_lock(&server->req_lock);
2031 server->credits += le16_to_cpu(shdr->CreditRequest);
2032 spin_unlock(&server->req_lock);
2033 wake_up(&server->request_q);
2040 smb2_is_session_expired(char *buf)
2042 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2044 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
2045 shdr->Status != STATUS_USER_SESSION_DELETED)
2048 trace_smb3_ses_expired(shdr->TreeId, shdr->SessionId,
2049 le16_to_cpu(shdr->Command),
2050 le64_to_cpu(shdr->MessageId));
2051 cifs_dbg(FYI, "Session expired or deleted\n");
2057 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
2058 struct cifsInodeInfo *cinode)
2060 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
2061 return SMB2_lease_break(0, tcon, cinode->lease_key,
2062 smb2_get_lease_state(cinode));
2064 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
2066 CIFS_CACHE_READ(cinode) ? 1 : 0);
2070 smb2_set_related(struct smb_rqst *rqst)
2072 struct smb2_sync_hdr *shdr;
2074 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
2076 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2079 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2082 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
2085 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
2087 struct smb2_sync_hdr *shdr;
2088 struct cifs_ses *ses = tcon->ses;
2089 struct TCP_Server_Info *server = ses->server;
2090 unsigned long len = smb_rqst_len(server, rqst);
2093 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
2095 cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2099 /* SMB headers in a compound are 8 byte aligned. */
2101 /* No padding needed */
2105 num_padding = 8 - (len & 7);
2106 if (!smb3_encryption_required(tcon)) {
2108 * If we do not have encryption then we can just add an extra
2109 * iov for the padding.
2111 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2112 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2117 * We can not add a small padding iov for the encryption case
2118 * because the encryption framework can not handle the padding
2120 * We have to flatten this into a single buffer and add
2121 * the padding to it.
2123 for (i = 1; i < rqst->rq_nvec; i++) {
2124 memcpy(rqst->rq_iov[0].iov_base +
2125 rqst->rq_iov[0].iov_len,
2126 rqst->rq_iov[i].iov_base,
2127 rqst->rq_iov[i].iov_len);
2128 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2130 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2132 rqst->rq_iov[0].iov_len += num_padding;
2138 shdr->NextCommand = cpu_to_le32(len);
2142 * Passes the query info response back to the caller on success.
2143 * Caller need to free this with free_rsp_buf().
2146 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2147 __le16 *utf16_path, u32 desired_access,
2148 u32 class, u32 type, u32 output_len,
2149 struct kvec *rsp, int *buftype,
2150 struct cifs_sb_info *cifs_sb)
2152 struct cifs_ses *ses = tcon->ses;
2154 struct smb_rqst rqst[3];
2155 int resp_buftype[3];
2156 struct kvec rsp_iov[3];
2157 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2158 struct kvec qi_iov[1];
2159 struct kvec close_iov[1];
2160 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2161 struct cifs_open_parms oparms;
2162 struct cifs_fid fid;
2165 if (smb3_encryption_required(tcon))
2166 flags |= CIFS_TRANSFORM_REQ;
2168 memset(rqst, 0, sizeof(rqst));
2169 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2170 memset(rsp_iov, 0, sizeof(rsp_iov));
2172 memset(&open_iov, 0, sizeof(open_iov));
2173 rqst[0].rq_iov = open_iov;
2174 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2177 oparms.desired_access = desired_access;
2178 oparms.disposition = FILE_OPEN;
2179 if (cifs_sb && backup_cred(cifs_sb))
2180 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2182 oparms.create_options = 0;
2184 oparms.reconnect = false;
2186 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, utf16_path);
2189 smb2_set_next_command(tcon, &rqst[0]);
2191 memset(&qi_iov, 0, sizeof(qi_iov));
2192 rqst[1].rq_iov = qi_iov;
2193 rqst[1].rq_nvec = 1;
2195 rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID, COMPOUND_FID,
2201 smb2_set_next_command(tcon, &rqst[1]);
2202 smb2_set_related(&rqst[1]);
2204 memset(&close_iov, 0, sizeof(close_iov));
2205 rqst[2].rq_iov = close_iov;
2206 rqst[2].rq_nvec = 1;
2208 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
2211 smb2_set_related(&rqst[2]);
2213 rc = compound_send_recv(xid, ses, flags, 3, rqst,
2214 resp_buftype, rsp_iov);
2216 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2220 *buftype = resp_buftype[1];
2223 SMB2_open_free(&rqst[0]);
2224 SMB2_query_info_free(&rqst[1]);
2225 SMB2_close_free(&rqst[2]);
2226 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2227 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2232 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2233 struct kstatfs *buf)
2235 struct smb2_query_info_rsp *rsp;
2236 struct smb2_fs_full_size_info *info = NULL;
2237 __le16 utf16_path = 0; /* Null - open root of share */
2238 struct kvec rsp_iov = {NULL, 0};
2239 int buftype = CIFS_NO_BUFFER;
2243 rc = smb2_query_info_compound(xid, tcon, &utf16_path,
2244 FILE_READ_ATTRIBUTES,
2245 FS_FULL_SIZE_INFORMATION,
2246 SMB2_O_INFO_FILESYSTEM,
2247 sizeof(struct smb2_fs_full_size_info),
2248 &rsp_iov, &buftype, NULL);
2252 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2253 buf->f_type = SMB2_MAGIC_NUMBER;
2254 info = (struct smb2_fs_full_size_info *)(
2255 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2256 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2257 le32_to_cpu(rsp->OutputBufferLength),
2259 sizeof(struct smb2_fs_full_size_info));
2261 smb2_copy_fs_info_to_kstatfs(info, buf);
2264 free_rsp_buf(buftype, rsp_iov.iov_base);
2269 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2270 struct kstatfs *buf)
2273 __le16 srch_path = 0; /* Null - open root of share */
2274 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2275 struct cifs_open_parms oparms;
2276 struct cifs_fid fid;
2278 if (!tcon->posix_extensions)
2279 return smb2_queryfs(xid, tcon, buf);
2282 oparms.desired_access = FILE_READ_ATTRIBUTES;
2283 oparms.disposition = FILE_OPEN;
2284 oparms.create_options = 0;
2286 oparms.reconnect = false;
2288 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
2292 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2293 fid.volatile_fid, buf);
2294 buf->f_type = SMB2_MAGIC_NUMBER;
2295 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2300 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2302 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2303 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2307 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2308 __u64 length, __u32 type, int lock, int unlock, bool wait)
2310 if (unlock && !lock)
2311 type = SMB2_LOCKFLAG_UNLOCK;
2312 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2313 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2314 current->tgid, length, offset, type, wait);
2318 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2320 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2324 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2326 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2330 smb2_new_lease_key(struct cifs_fid *fid)
2332 generate_random_uuid(fid->lease_key);
2336 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2337 const char *search_name,
2338 struct dfs_info3_param **target_nodes,
2339 unsigned int *num_of_nodes,
2340 const struct nls_table *nls_codepage, int remap)
2343 __le16 *utf16_path = NULL;
2344 int utf16_path_len = 0;
2345 struct cifs_tcon *tcon;
2346 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2347 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2348 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2350 cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name);
2353 * Try to use the IPC tcon, otherwise just use any
2355 tcon = ses->tcon_ipc;
2357 spin_lock(&cifs_tcp_ses_lock);
2358 tcon = list_first_entry_or_null(&ses->tcon_list,
2363 spin_unlock(&cifs_tcp_ses_lock);
2367 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2373 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2375 nls_codepage, remap);
2381 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2382 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2388 /* Highest DFS referral version understood */
2389 dfs_req->MaxReferralLevel = DFS_VERSION;
2391 /* Path to resolve in an UTF-16 null-terminated string */
2392 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2395 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2396 FSCTL_DFS_GET_REFERRALS,
2397 true /* is_fsctl */,
2398 (char *)dfs_req, dfs_req_size, CIFSMaxBufSize,
2399 (char **)&dfs_rsp, &dfs_rsp_size);
2400 } while (rc == -EAGAIN);
2403 if ((rc != -ENOENT) && (rc != -EOPNOTSUPP))
2404 cifs_dbg(VFS, "ioctl error in %s rc=%d\n", __func__, rc);
2408 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
2409 num_of_nodes, target_nodes,
2410 nls_codepage, remap, search_name,
2411 true /* is_unicode */);
2413 cifs_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc);
2418 if (tcon && !tcon->ipc) {
2419 /* ipc tcons are not refcounted */
2420 spin_lock(&cifs_tcp_ses_lock);
2422 spin_unlock(&cifs_tcp_ses_lock);
2431 parse_reparse_posix(struct reparse_posix_data *symlink_buf,
2432 u32 plen, char **target_path,
2433 struct cifs_sb_info *cifs_sb)
2437 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
2438 len = le16_to_cpu(symlink_buf->ReparseDataLength);
2440 if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
2441 cifs_dbg(VFS, "%lld not a supported symlink type\n",
2442 le64_to_cpu(symlink_buf->InodeType));
2446 *target_path = cifs_strndup_from_utf16(
2447 symlink_buf->PathBuffer,
2448 len, true, cifs_sb->local_nls);
2449 if (!(*target_path))
2452 convert_delimiter(*target_path, '/');
2453 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2459 parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
2460 u32 plen, char **target_path,
2461 struct cifs_sb_info *cifs_sb)
2463 unsigned int sub_len;
2464 unsigned int sub_offset;
2466 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */
2468 sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset);
2469 sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength);
2470 if (sub_offset + 20 > plen ||
2471 sub_offset + sub_len + 20 > plen) {
2472 cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
2476 *target_path = cifs_strndup_from_utf16(
2477 symlink_buf->PathBuffer + sub_offset,
2478 sub_len, true, cifs_sb->local_nls);
2479 if (!(*target_path))
2482 convert_delimiter(*target_path, '/');
2483 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2489 parse_reparse_point(struct reparse_data_buffer *buf,
2490 u32 plen, char **target_path,
2491 struct cifs_sb_info *cifs_sb)
2493 if (plen < sizeof(struct reparse_data_buffer)) {
2494 cifs_dbg(VFS, "reparse buffer is too small. Must be "
2495 "at least 8 bytes but was %d\n", plen);
2499 if (plen < le16_to_cpu(buf->ReparseDataLength) +
2500 sizeof(struct reparse_data_buffer)) {
2501 cifs_dbg(VFS, "srv returned invalid reparse buf "
2502 "length: %d\n", plen);
2506 /* See MS-FSCC 2.1.2 */
2507 switch (le32_to_cpu(buf->ReparseTag)) {
2508 case IO_REPARSE_TAG_NFS:
2509 return parse_reparse_posix(
2510 (struct reparse_posix_data *)buf,
2511 plen, target_path, cifs_sb);
2512 case IO_REPARSE_TAG_SYMLINK:
2513 return parse_reparse_symlink(
2514 (struct reparse_symlink_data_buffer *)buf,
2515 plen, target_path, cifs_sb);
2517 cifs_dbg(VFS, "srv returned unknown symlink buffer "
2518 "tag:0x%08x\n", le32_to_cpu(buf->ReparseTag));
2523 #define SMB2_SYMLINK_STRUCT_SIZE \
2524 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
2527 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
2528 struct cifs_sb_info *cifs_sb, const char *full_path,
2529 char **target_path, bool is_reparse_point)
2532 __le16 *utf16_path = NULL;
2533 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2534 struct cifs_open_parms oparms;
2535 struct cifs_fid fid;
2536 struct kvec err_iov = {NULL, 0};
2537 struct smb2_err_rsp *err_buf = NULL;
2538 struct smb2_symlink_err_rsp *symlink;
2539 unsigned int sub_len;
2540 unsigned int sub_offset;
2541 unsigned int print_len;
2542 unsigned int print_offset;
2544 struct smb_rqst rqst[3];
2545 int resp_buftype[3];
2546 struct kvec rsp_iov[3];
2547 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2548 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2549 struct kvec close_iov[1];
2550 struct smb2_create_rsp *create_rsp;
2551 struct smb2_ioctl_rsp *ioctl_rsp;
2552 struct reparse_data_buffer *reparse_buf;
2555 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2557 *target_path = NULL;
2559 if (smb3_encryption_required(tcon))
2560 flags |= CIFS_TRANSFORM_REQ;
2562 memset(rqst, 0, sizeof(rqst));
2563 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2564 memset(rsp_iov, 0, sizeof(rsp_iov));
2566 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
2571 memset(&open_iov, 0, sizeof(open_iov));
2572 rqst[0].rq_iov = open_iov;
2573 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2575 memset(&oparms, 0, sizeof(oparms));
2577 oparms.desired_access = FILE_READ_ATTRIBUTES;
2578 oparms.disposition = FILE_OPEN;
2580 if (backup_cred(cifs_sb))
2581 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2583 oparms.create_options = 0;
2584 if (is_reparse_point)
2585 oparms.create_options = OPEN_REPARSE_POINT;
2588 oparms.reconnect = false;
2590 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, utf16_path);
2593 smb2_set_next_command(tcon, &rqst[0]);
2597 memset(&io_iov, 0, sizeof(io_iov));
2598 rqst[1].rq_iov = io_iov;
2599 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
2601 rc = SMB2_ioctl_init(tcon, &rqst[1], fid.persistent_fid,
2602 fid.volatile_fid, FSCTL_GET_REPARSE_POINT,
2603 true /* is_fctl */, NULL, 0, CIFSMaxBufSize);
2607 smb2_set_next_command(tcon, &rqst[1]);
2608 smb2_set_related(&rqst[1]);
2612 memset(&close_iov, 0, sizeof(close_iov));
2613 rqst[2].rq_iov = close_iov;
2614 rqst[2].rq_nvec = 1;
2616 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
2620 smb2_set_related(&rqst[2]);
2622 rc = compound_send_recv(xid, tcon->ses, flags, 3, rqst,
2623 resp_buftype, rsp_iov);
2625 create_rsp = rsp_iov[0].iov_base;
2626 if (create_rsp && create_rsp->sync_hdr.Status)
2627 err_iov = rsp_iov[0];
2628 ioctl_rsp = rsp_iov[1].iov_base;
2631 * Open was successful and we got an ioctl response.
2633 if ((rc == 0) && (is_reparse_point)) {
2634 /* See MS-FSCC 2.3.23 */
2636 reparse_buf = (struct reparse_data_buffer *)
2637 ((char *)ioctl_rsp +
2638 le32_to_cpu(ioctl_rsp->OutputOffset));
2639 plen = le32_to_cpu(ioctl_rsp->OutputCount);
2641 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
2642 rsp_iov[1].iov_len) {
2643 cifs_dbg(VFS, "srv returned invalid ioctl len: %d\n",
2649 rc = parse_reparse_point(reparse_buf, plen, target_path,
2654 if (!rc || !err_iov.iov_base) {
2659 err_buf = err_iov.iov_base;
2660 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
2661 err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) {
2666 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
2667 if (le32_to_cpu(symlink->SymLinkErrorTag) != SYMLINK_ERROR_TAG ||
2668 le32_to_cpu(symlink->ReparseTag) != IO_REPARSE_TAG_SYMLINK) {
2673 /* open must fail on symlink - reset rc */
2675 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
2676 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
2677 print_len = le16_to_cpu(symlink->PrintNameLength);
2678 print_offset = le16_to_cpu(symlink->PrintNameOffset);
2680 if (err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
2685 if (err_iov.iov_len <
2686 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
2691 *target_path = cifs_strndup_from_utf16(
2692 (char *)symlink->PathBuffer + sub_offset,
2693 sub_len, true, cifs_sb->local_nls);
2694 if (!(*target_path)) {
2698 convert_delimiter(*target_path, '/');
2699 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2702 cifs_dbg(FYI, "query symlink rc %d\n", rc);
2704 SMB2_open_free(&rqst[0]);
2705 SMB2_ioctl_free(&rqst[1]);
2706 SMB2_close_free(&rqst[2]);
2707 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2708 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2709 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2713 static struct cifs_ntsd *
2714 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
2715 const struct cifs_fid *cifsfid, u32 *pacllen)
2717 struct cifs_ntsd *pntsd = NULL;
2719 int rc = -EOPNOTSUPP;
2720 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
2723 return ERR_CAST(tlink);
2726 cifs_dbg(FYI, "trying to get acl\n");
2728 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
2729 cifsfid->volatile_fid, (void **)&pntsd, pacllen);
2732 cifs_put_tlink(tlink);
2734 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
2741 static struct cifs_ntsd *
2742 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
2743 const char *path, u32 *pacllen)
2745 struct cifs_ntsd *pntsd = NULL;
2746 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2749 struct cifs_tcon *tcon;
2750 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
2751 struct cifs_fid fid;
2752 struct cifs_open_parms oparms;
2755 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
2757 return ERR_CAST(tlink);
2759 tcon = tlink_tcon(tlink);
2762 if (backup_cred(cifs_sb))
2763 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2765 oparms.create_options = 0;
2767 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2775 oparms.desired_access = READ_CONTROL;
2776 oparms.disposition = FILE_OPEN;
2778 oparms.reconnect = false;
2780 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
2783 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
2784 fid.volatile_fid, (void **)&pntsd, pacllen);
2785 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2788 cifs_put_tlink(tlink);
2791 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
2798 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
2799 struct inode *inode, const char *path, int aclflag)
2801 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2803 int rc, access_flags = 0;
2804 struct cifs_tcon *tcon;
2805 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2806 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
2807 struct cifs_fid fid;
2808 struct cifs_open_parms oparms;
2811 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
2813 return PTR_ERR(tlink);
2815 tcon = tlink_tcon(tlink);
2818 if (backup_cred(cifs_sb))
2819 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2821 oparms.create_options = 0;
2823 if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP)
2824 access_flags = WRITE_OWNER;
2826 access_flags = WRITE_DAC;
2828 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2836 oparms.desired_access = access_flags;
2837 oparms.disposition = FILE_OPEN;
2840 oparms.reconnect = false;
2842 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
2845 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
2846 fid.volatile_fid, pnntsd, acllen, aclflag);
2847 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2850 cifs_put_tlink(tlink);
2855 /* Retrieve an ACL from the server */
2856 static struct cifs_ntsd *
2857 get_smb2_acl(struct cifs_sb_info *cifs_sb,
2858 struct inode *inode, const char *path,
2861 struct cifs_ntsd *pntsd = NULL;
2862 struct cifsFileInfo *open_file = NULL;
2865 open_file = find_readable_file(CIFS_I(inode), true);
2867 return get_smb2_acl_by_path(cifs_sb, path, pacllen);
2869 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen);
2870 cifsFileInfo_put(open_file);
2874 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
2875 loff_t offset, loff_t len, bool keep_size)
2877 struct cifs_ses *ses = tcon->ses;
2878 struct inode *inode;
2879 struct cifsInodeInfo *cifsi;
2880 struct cifsFileInfo *cfile = file->private_data;
2881 struct file_zero_data_information fsctl_buf;
2888 inode = d_inode(cfile->dentry);
2889 cifsi = CIFS_I(inode);
2891 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
2892 ses->Suid, offset, len);
2895 /* if file not oplocked can't be sure whether asking to extend size */
2896 if (!CIFS_CACHE_READ(cifsi))
2897 if (keep_size == false) {
2899 trace_smb3_zero_err(xid, cfile->fid.persistent_fid,
2900 tcon->tid, ses->Suid, offset, len, rc);
2905 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
2907 fsctl_buf.FileOffset = cpu_to_le64(offset);
2908 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
2910 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2911 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, true,
2913 sizeof(struct file_zero_data_information),
2916 goto zero_range_exit;
2919 * do we also need to change the size of the file?
2921 if (keep_size == false && i_size_read(inode) < offset + len) {
2922 eof = cpu_to_le64(offset + len);
2923 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
2924 cfile->fid.volatile_fid, cfile->pid, &eof);
2930 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
2931 ses->Suid, offset, len, rc);
2933 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
2934 ses->Suid, offset, len);
2938 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
2939 loff_t offset, loff_t len)
2941 struct inode *inode;
2942 struct cifsInodeInfo *cifsi;
2943 struct cifsFileInfo *cfile = file->private_data;
2944 struct file_zero_data_information fsctl_buf;
2947 __u8 set_sparse = 1;
2951 inode = d_inode(cfile->dentry);
2952 cifsi = CIFS_I(inode);
2954 /* Need to make file sparse, if not already, before freeing range. */
2955 /* Consider adding equivalent for compressed since it could also work */
2956 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
2962 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
2964 fsctl_buf.FileOffset = cpu_to_le64(offset);
2965 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
2967 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2968 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
2969 true /* is_fctl */, (char *)&fsctl_buf,
2970 sizeof(struct file_zero_data_information),
2971 CIFSMaxBufSize, NULL, NULL);
2976 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
2977 loff_t off, loff_t len, bool keep_size)
2979 struct inode *inode;
2980 struct cifsInodeInfo *cifsi;
2981 struct cifsFileInfo *cfile = file->private_data;
2982 long rc = -EOPNOTSUPP;
2988 inode = d_inode(cfile->dentry);
2989 cifsi = CIFS_I(inode);
2991 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
2992 tcon->ses->Suid, off, len);
2993 /* if file not oplocked can't be sure whether asking to extend size */
2994 if (!CIFS_CACHE_READ(cifsi))
2995 if (keep_size == false) {
2996 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
2997 tcon->tid, tcon->ses->Suid, off, len, rc);
3003 * Files are non-sparse by default so falloc may be a no-op
3004 * Must check if file sparse. If not sparse, and not extending
3005 * then no need to do anything since file already allocated
3007 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
3008 if (keep_size == true)
3010 /* check if extending file */
3011 else if (i_size_read(inode) >= off + len)
3012 /* not extending file and already not sparse */
3014 /* BB: in future add else clause to extend file */
3018 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3019 tcon->tid, tcon->ses->Suid, off, len, rc);
3021 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid,
3022 tcon->tid, tcon->ses->Suid, off, len);
3027 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3029 * Check if falloc starts within first few pages of file
3030 * and ends within a few pages of the end of file to
3031 * ensure that most of file is being forced to be
3032 * fallocated now. If so then setting whole file sparse
3033 * ie potentially making a few extra pages at the beginning
3034 * or end of the file non-sparse via set_sparse is harmless.
3036 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
3038 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3039 tcon->tid, tcon->ses->Suid, off, len, rc);
3044 smb2_set_sparse(xid, tcon, cfile, inode, false);
3047 smb2_set_sparse(xid, tcon, cfile, inode, false);
3049 if (i_size_read(inode) < off + len) {
3050 eof = cpu_to_le64(off + len);
3051 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3052 cfile->fid.volatile_fid, cfile->pid,
3058 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3059 tcon->ses->Suid, off, len, rc);
3061 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3062 tcon->ses->Suid, off, len);
3068 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3070 struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3071 struct cifsInodeInfo *cifsi;
3072 struct inode *inode;
3074 struct file_allocated_range_buffer in_data, *out_data = NULL;
3078 if (whence != SEEK_HOLE && whence != SEEK_DATA)
3079 return generic_file_llseek(file, offset, whence);
3081 inode = d_inode(cfile->dentry);
3082 cifsi = CIFS_I(inode);
3084 if (offset < 0 || offset >= i_size_read(inode))
3089 * We need to be sure that all dirty pages are written as they
3090 * might fill holes on the server.
3091 * Note that we also MUST flush any written pages since at least
3092 * some servers (Windows2016) will not reflect recent writes in
3093 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3095 wrcfile = find_writable_file(cifsi, false);
3097 filemap_write_and_wait(inode->i_mapping);
3098 smb2_flush_file(xid, tcon, &wrcfile->fid);
3099 cifsFileInfo_put(wrcfile);
3102 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3103 if (whence == SEEK_HOLE)
3104 offset = i_size_read(inode);
3108 in_data.file_offset = cpu_to_le64(offset);
3109 in_data.length = cpu_to_le64(i_size_read(inode));
3111 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3112 cfile->fid.volatile_fid,
3113 FSCTL_QUERY_ALLOCATED_RANGES, true,
3114 (char *)&in_data, sizeof(in_data),
3115 sizeof(struct file_allocated_range_buffer),
3116 (char **)&out_data, &out_data_len);
3122 if (whence == SEEK_HOLE && out_data_len == 0)
3125 if (whence == SEEK_DATA && out_data_len == 0) {
3130 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3134 if (whence == SEEK_DATA) {
3135 offset = le64_to_cpu(out_data->file_offset);
3138 if (offset < le64_to_cpu(out_data->file_offset))
3141 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3147 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3152 static int smb3_fiemap(struct cifs_tcon *tcon,
3153 struct cifsFileInfo *cfile,
3154 struct fiemap_extent_info *fei, u64 start, u64 len)
3157 struct file_allocated_range_buffer in_data, *out_data;
3159 int i, num, rc, flags, last_blob;
3162 if (fiemap_check_flags(fei, FIEMAP_FLAG_SYNC))
3167 in_data.file_offset = cpu_to_le64(start);
3168 in_data.length = cpu_to_le64(len);
3170 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3171 cfile->fid.volatile_fid,
3172 FSCTL_QUERY_ALLOCATED_RANGES, true,
3173 (char *)&in_data, sizeof(in_data),
3174 1024 * sizeof(struct file_allocated_range_buffer),
3175 (char **)&out_data, &out_data_len);
3184 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3188 if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3193 num = out_data_len / sizeof(struct file_allocated_range_buffer);
3194 for (i = 0; i < num; i++) {
3196 if (i == num - 1 && last_blob)
3197 flags |= FIEMAP_EXTENT_LAST;
3199 rc = fiemap_fill_next_extent(fei,
3200 le64_to_cpu(out_data[i].file_offset),
3201 le64_to_cpu(out_data[i].file_offset),
3202 le64_to_cpu(out_data[i].length),
3213 next = le64_to_cpu(out_data[num - 1].file_offset) +
3214 le64_to_cpu(out_data[num - 1].length);
3215 len = len - (next - start);
3226 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
3227 loff_t off, loff_t len)
3229 /* KEEP_SIZE already checked for by do_fallocate */
3230 if (mode & FALLOC_FL_PUNCH_HOLE)
3231 return smb3_punch_hole(file, tcon, off, len);
3232 else if (mode & FALLOC_FL_ZERO_RANGE) {
3233 if (mode & FALLOC_FL_KEEP_SIZE)
3234 return smb3_zero_range(file, tcon, off, len, true);
3235 return smb3_zero_range(file, tcon, off, len, false);
3236 } else if (mode == FALLOC_FL_KEEP_SIZE)
3237 return smb3_simple_falloc(file, tcon, off, len, true);
3239 return smb3_simple_falloc(file, tcon, off, len, false);
3245 smb2_downgrade_oplock(struct TCP_Server_Info *server,
3246 struct cifsInodeInfo *cinode, bool set_level2)
3249 server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
3252 server->ops->set_oplock_level(cinode, 0, 0, NULL);
3256 smb21_downgrade_oplock(struct TCP_Server_Info *server,
3257 struct cifsInodeInfo *cinode, bool set_level2)
3259 server->ops->set_oplock_level(cinode,
3260 set_level2 ? SMB2_LEASE_READ_CACHING_HE :
3265 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3266 unsigned int epoch, bool *purge_cache)
3269 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3271 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
3272 cinode->oplock = CIFS_CACHE_RHW_FLG;
3273 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
3274 &cinode->vfs_inode);
3275 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
3276 cinode->oplock = CIFS_CACHE_RW_FLG;
3277 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
3278 &cinode->vfs_inode);
3279 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
3280 cinode->oplock = CIFS_CACHE_READ_FLG;
3281 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
3282 &cinode->vfs_inode);
3288 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3289 unsigned int epoch, bool *purge_cache)
3291 char message[5] = {0};
3292 unsigned int new_oplock = 0;
3295 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3298 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
3299 new_oplock |= CIFS_CACHE_READ_FLG;
3300 strcat(message, "R");
3302 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
3303 new_oplock |= CIFS_CACHE_HANDLE_FLG;
3304 strcat(message, "H");
3306 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
3307 new_oplock |= CIFS_CACHE_WRITE_FLG;
3308 strcat(message, "W");
3311 strncpy(message, "None", sizeof(message));
3313 cinode->oplock = new_oplock;
3314 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
3315 &cinode->vfs_inode);
3319 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3320 unsigned int epoch, bool *purge_cache)
3322 unsigned int old_oplock = cinode->oplock;
3324 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
3327 *purge_cache = false;
3328 if (old_oplock == CIFS_CACHE_READ_FLG) {
3329 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
3330 (epoch - cinode->epoch > 0))
3331 *purge_cache = true;
3332 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
3333 (epoch - cinode->epoch > 1))
3334 *purge_cache = true;
3335 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
3336 (epoch - cinode->epoch > 1))
3337 *purge_cache = true;
3338 else if (cinode->oplock == 0 &&
3339 (epoch - cinode->epoch > 0))
3340 *purge_cache = true;
3341 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
3342 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
3343 (epoch - cinode->epoch > 0))
3344 *purge_cache = true;
3345 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
3346 (epoch - cinode->epoch > 1))
3347 *purge_cache = true;
3349 cinode->epoch = epoch;
3354 smb2_is_read_op(__u32 oplock)
3356 return oplock == SMB2_OPLOCK_LEVEL_II;
3360 smb21_is_read_op(__u32 oplock)
3362 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
3363 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
3367 map_oplock_to_lease(u8 oplock)
3369 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
3370 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
3371 else if (oplock == SMB2_OPLOCK_LEVEL_II)
3372 return SMB2_LEASE_READ_CACHING;
3373 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
3374 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
3375 SMB2_LEASE_WRITE_CACHING;
3380 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
3382 struct create_lease *buf;
3384 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
3388 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
3389 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
3391 buf->ccontext.DataOffset = cpu_to_le16(offsetof
3392 (struct create_lease, lcontext));
3393 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
3394 buf->ccontext.NameOffset = cpu_to_le16(offsetof
3395 (struct create_lease, Name));
3396 buf->ccontext.NameLength = cpu_to_le16(4);
3397 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
3406 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
3408 struct create_lease_v2 *buf;
3410 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
3414 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
3415 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
3417 buf->ccontext.DataOffset = cpu_to_le16(offsetof
3418 (struct create_lease_v2, lcontext));
3419 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
3420 buf->ccontext.NameOffset = cpu_to_le16(offsetof
3421 (struct create_lease_v2, Name));
3422 buf->ccontext.NameLength = cpu_to_le16(4);
3423 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
3432 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
3434 struct create_lease *lc = (struct create_lease *)buf;
3436 *epoch = 0; /* not used */
3437 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
3438 return SMB2_OPLOCK_LEVEL_NOCHANGE;
3439 return le32_to_cpu(lc->lcontext.LeaseState);
3443 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
3445 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
3447 *epoch = le16_to_cpu(lc->lcontext.Epoch);
3448 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
3449 return SMB2_OPLOCK_LEVEL_NOCHANGE;
3451 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
3452 return le32_to_cpu(lc->lcontext.LeaseState);
3456 smb2_wp_retry_size(struct inode *inode)
3458 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
3459 SMB2_MAX_BUFFER_SIZE);
3463 smb2_dir_needs_close(struct cifsFileInfo *cfile)
3465 return !cfile->invalidHandle;
3469 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
3470 struct smb_rqst *old_rq, __le16 cipher_type)
3472 struct smb2_sync_hdr *shdr =
3473 (struct smb2_sync_hdr *)old_rq->rq_iov[0].iov_base;
3475 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
3476 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
3477 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
3478 tr_hdr->Flags = cpu_to_le16(0x01);
3479 if (cipher_type == SMB2_ENCRYPTION_AES128_GCM)
3480 get_random_bytes(&tr_hdr->Nonce, SMB3_AES128GCM_NONCE);
3482 get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CCM_NONCE);
3483 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
3486 /* We can not use the normal sg_set_buf() as we will sometimes pass a
3487 * stack object as buf.
3489 static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
3490 unsigned int buflen)
3494 * VMAP_STACK (at least) puts stack into the vmalloc address space
3496 if (is_vmalloc_addr(buf))
3497 addr = vmalloc_to_page(buf);
3499 addr = virt_to_page(buf);
3500 sg_set_page(sg, addr, buflen, offset_in_page(buf));
3503 /* Assumes the first rqst has a transform header as the first iov.
3505 * rqst[0].rq_iov[0] is transform header
3506 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
3507 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
3509 static struct scatterlist *
3510 init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign)
3512 unsigned int sg_len;
3513 struct scatterlist *sg;
3516 unsigned int idx = 0;
3520 for (i = 0; i < num_rqst; i++)
3521 sg_len += rqst[i].rq_nvec + rqst[i].rq_npages;
3523 sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
3527 sg_init_table(sg, sg_len);
3528 for (i = 0; i < num_rqst; i++) {
3529 for (j = 0; j < rqst[i].rq_nvec; j++) {
3531 * The first rqst has a transform header where the
3532 * first 20 bytes are not part of the encrypted blob
3534 skip = (i == 0) && (j == 0) ? 20 : 0;
3535 smb2_sg_set_buf(&sg[idx++],
3536 rqst[i].rq_iov[j].iov_base + skip,
3537 rqst[i].rq_iov[j].iov_len - skip);
3540 for (j = 0; j < rqst[i].rq_npages; j++) {
3541 unsigned int len, offset;
3543 rqst_page_get_length(&rqst[i], j, &len, &offset);
3544 sg_set_page(&sg[idx++], rqst[i].rq_pages[j], len, offset);
3547 smb2_sg_set_buf(&sg[idx], sign, SMB2_SIGNATURE_SIZE);
3552 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
3554 struct cifs_ses *ses;
3557 spin_lock(&cifs_tcp_ses_lock);
3558 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
3559 if (ses->Suid != ses_id)
3561 ses_enc_key = enc ? ses->smb3encryptionkey :
3562 ses->smb3decryptionkey;
3563 memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE);
3564 spin_unlock(&cifs_tcp_ses_lock);
3567 spin_unlock(&cifs_tcp_ses_lock);
3572 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
3573 * iov[0] - transform header (associate data),
3574 * iov[1-N] - SMB2 header and pages - data to encrypt.
3575 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
3579 crypt_message(struct TCP_Server_Info *server, int num_rqst,
3580 struct smb_rqst *rqst, int enc)
3582 struct smb2_transform_hdr *tr_hdr =
3583 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
3584 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
3586 struct scatterlist *sg;
3587 u8 sign[SMB2_SIGNATURE_SIZE] = {};
3588 u8 key[SMB3_SIGN_KEY_SIZE];
3589 struct aead_request *req;
3591 unsigned int iv_len;
3592 DECLARE_CRYPTO_WAIT(wait);
3593 struct crypto_aead *tfm;
3594 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
3596 rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key);
3598 cifs_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
3603 rc = smb3_crypto_aead_allocate(server);
3605 cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__);
3609 tfm = enc ? server->secmech.ccmaesencrypt :
3610 server->secmech.ccmaesdecrypt;
3611 rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
3613 cifs_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
3617 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
3619 cifs_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
3623 req = aead_request_alloc(tfm, GFP_KERNEL);
3625 cifs_dbg(VFS, "%s: Failed to alloc aead request\n", __func__);
3630 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
3631 crypt_len += SMB2_SIGNATURE_SIZE;
3634 sg = init_sg(num_rqst, rqst, sign);
3636 cifs_dbg(VFS, "%s: Failed to init sg\n", __func__);
3641 iv_len = crypto_aead_ivsize(tfm);
3642 iv = kzalloc(iv_len, GFP_KERNEL);
3644 cifs_dbg(VFS, "%s: Failed to alloc iv\n", __func__);
3649 if (server->cipher_type == SMB2_ENCRYPTION_AES128_GCM)
3650 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES128GCM_NONCE);
3653 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CCM_NONCE);
3656 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
3657 aead_request_set_ad(req, assoc_data_len);
3659 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
3660 crypto_req_done, &wait);
3662 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
3663 : crypto_aead_decrypt(req), &wait);
3666 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
3677 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
3681 for (i = 0; i < num_rqst; i++) {
3682 if (rqst[i].rq_pages) {
3683 for (j = rqst[i].rq_npages - 1; j >= 0; j--)
3684 put_page(rqst[i].rq_pages[j]);
3685 kfree(rqst[i].rq_pages);
3691 * This function will initialize new_rq and encrypt the content.
3692 * The first entry, new_rq[0], only contains a single iov which contains
3693 * a smb2_transform_hdr and is pre-allocated by the caller.
3694 * This function then populates new_rq[1+] with the content from olq_rq[0+].
3696 * The end result is an array of smb_rqst structures where the first structure
3697 * only contains a single iov for the transform header which we then can pass
3698 * to crypt_message().
3700 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
3701 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
3704 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
3705 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
3707 struct page **pages;
3708 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
3709 unsigned int npages;
3710 unsigned int orig_len = 0;
3714 for (i = 1; i < num_rqst; i++) {
3715 npages = old_rq[i - 1].rq_npages;
3716 pages = kmalloc_array(npages, sizeof(struct page *),
3721 new_rq[i].rq_pages = pages;
3722 new_rq[i].rq_npages = npages;
3723 new_rq[i].rq_offset = old_rq[i - 1].rq_offset;
3724 new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz;
3725 new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz;
3726 new_rq[i].rq_iov = old_rq[i - 1].rq_iov;
3727 new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec;
3729 orig_len += smb_rqst_len(server, &old_rq[i - 1]);
3731 for (j = 0; j < npages; j++) {
3732 pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
3737 /* copy pages form the old */
3738 for (j = 0; j < npages; j++) {
3740 unsigned int offset, len;
3742 rqst_page_get_length(&new_rq[i], j, &len, &offset);
3744 dst = (char *) kmap(new_rq[i].rq_pages[j]) + offset;
3745 src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset;
3747 memcpy(dst, src, len);
3748 kunmap(new_rq[i].rq_pages[j]);
3749 kunmap(old_rq[i - 1].rq_pages[j]);
3753 /* fill the 1st iov with a transform header */
3754 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
3756 rc = crypt_message(server, num_rqst, new_rq, 1);
3757 cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
3764 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
3769 smb3_is_transform_hdr(void *buf)
3771 struct smb2_transform_hdr *trhdr = buf;
3773 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
3777 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
3778 unsigned int buf_data_size, struct page **pages,
3779 unsigned int npages, unsigned int page_data_size)
3782 struct smb_rqst rqst = {NULL};
3785 iov[0].iov_base = buf;
3786 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
3787 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
3788 iov[1].iov_len = buf_data_size;
3792 rqst.rq_pages = pages;
3793 rqst.rq_npages = npages;
3794 rqst.rq_pagesz = PAGE_SIZE;
3795 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
3797 rc = crypt_message(server, 1, &rqst, 0);
3798 cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
3803 memmove(buf, iov[1].iov_base, buf_data_size);
3805 server->total_read = buf_data_size + page_data_size;
3811 read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
3812 unsigned int npages, unsigned int len)
3817 for (i = 0; i < npages; i++) {
3818 struct page *page = pages[i];
3822 if (len >= PAGE_SIZE) {
3823 /* enough data to fill the page */
3827 zero_user(page, len, PAGE_SIZE - len);
3830 length = cifs_read_page_from_socket(server, page, 0, n);
3833 server->total_read += length;
3840 init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
3841 unsigned int cur_off, struct bio_vec **page_vec)
3843 struct bio_vec *bvec;
3846 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
3850 for (i = 0; i < npages; i++) {
3851 bvec[i].bv_page = pages[i];
3852 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
3853 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
3854 data_size -= bvec[i].bv_len;
3857 if (data_size != 0) {
3858 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
3868 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
3869 char *buf, unsigned int buf_len, struct page **pages,
3870 unsigned int npages, unsigned int page_data_size)
3872 unsigned int data_offset;
3873 unsigned int data_len;
3874 unsigned int cur_off;
3875 unsigned int cur_page_idx;
3876 unsigned int pad_len;
3877 struct cifs_readdata *rdata = mid->callback_data;
3878 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
3879 struct bio_vec *bvec = NULL;
3880 struct iov_iter iter;
3883 bool use_rdma_mr = false;
3885 if (shdr->Command != SMB2_READ) {
3886 cifs_dbg(VFS, "only big read responses are supported\n");
3890 if (server->ops->is_session_expired &&
3891 server->ops->is_session_expired(buf)) {
3892 cifs_reconnect(server);
3893 wake_up(&server->response_q);
3897 if (server->ops->is_status_pending &&
3898 server->ops->is_status_pending(buf, server))
3901 /* set up first two iov to get credits */
3902 rdata->iov[0].iov_base = buf;
3903 rdata->iov[0].iov_len = 0;
3904 rdata->iov[1].iov_base = buf;
3905 rdata->iov[1].iov_len =
3906 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
3907 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
3908 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
3909 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
3910 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
3912 rdata->result = server->ops->map_error(buf, true);
3913 if (rdata->result != 0) {
3914 cifs_dbg(FYI, "%s: server returned error %d\n",
3915 __func__, rdata->result);
3916 /* normal error on read response */
3917 dequeue_mid(mid, false);
3921 data_offset = server->ops->read_data_offset(buf);
3922 #ifdef CONFIG_CIFS_SMB_DIRECT
3923 use_rdma_mr = rdata->mr;
3925 data_len = server->ops->read_data_length(buf, use_rdma_mr);
3927 if (data_offset < server->vals->read_rsp_size) {
3929 * win2k8 sometimes sends an offset of 0 when the read
3930 * is beyond the EOF. Treat it as if the data starts just after
3933 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
3934 __func__, data_offset);
3935 data_offset = server->vals->read_rsp_size;
3936 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
3937 /* data_offset is beyond the end of smallbuf */
3938 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
3939 __func__, data_offset);
3940 rdata->result = -EIO;
3941 dequeue_mid(mid, rdata->result);
3945 pad_len = data_offset - server->vals->read_rsp_size;
3947 if (buf_len <= data_offset) {
3948 /* read response payload is in pages */
3949 cur_page_idx = pad_len / PAGE_SIZE;
3950 cur_off = pad_len % PAGE_SIZE;
3952 if (cur_page_idx != 0) {
3953 /* data offset is beyond the 1st page of response */
3954 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
3955 __func__, data_offset);
3956 rdata->result = -EIO;
3957 dequeue_mid(mid, rdata->result);
3961 if (data_len > page_data_size - pad_len) {
3962 /* data_len is corrupt -- discard frame */
3963 rdata->result = -EIO;
3964 dequeue_mid(mid, rdata->result);
3968 rdata->result = init_read_bvec(pages, npages, page_data_size,
3970 if (rdata->result != 0) {
3971 dequeue_mid(mid, rdata->result);
3975 iov_iter_bvec(&iter, WRITE, bvec, npages, data_len);
3976 } else if (buf_len >= data_offset + data_len) {
3977 /* read response payload is in buf */
3978 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
3979 iov.iov_base = buf + data_offset;
3980 iov.iov_len = data_len;
3981 iov_iter_kvec(&iter, WRITE, &iov, 1, data_len);
3983 /* read response payload cannot be in both buf and pages */
3984 WARN_ONCE(1, "buf can not contain only a part of read data");
3985 rdata->result = -EIO;
3986 dequeue_mid(mid, rdata->result);
3990 length = rdata->copy_into_pages(server, rdata, &iter);
3997 dequeue_mid(mid, false);
4002 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid)
4004 char *buf = server->smallbuf;
4005 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4006 unsigned int npages;
4007 struct page **pages;
4009 unsigned int buflen = server->pdu_size;
4013 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
4014 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
4016 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
4019 server->total_read += rc;
4021 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
4022 server->vals->read_rsp_size;
4023 npages = DIV_ROUND_UP(len, PAGE_SIZE);
4025 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
4031 for (; i < npages; i++) {
4032 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4039 /* read read data into pages */
4040 rc = read_data_into_pages(server, pages, npages, len);
4044 rc = cifs_discard_remaining_data(server);
4048 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
4049 pages, npages, len);
4053 *mid = smb2_find_mid(server, buf);
4055 cifs_dbg(FYI, "mid not found\n");
4057 cifs_dbg(FYI, "mid found\n");
4058 (*mid)->decrypted = true;
4059 rc = handle_read_data(server, *mid, buf,
4060 server->vals->read_rsp_size,
4061 pages, npages, len);
4065 for (i = i - 1; i >= 0; i--)
4070 cifs_discard_remaining_data(server);
4075 receive_encrypted_standard(struct TCP_Server_Info *server,
4076 struct mid_q_entry **mids, char **bufs,
4080 char *buf = server->smallbuf;
4081 struct smb2_sync_hdr *shdr;
4082 unsigned int pdu_length = server->pdu_size;
4083 unsigned int buf_size;
4084 struct mid_q_entry *mid_entry;
4086 char *next_buffer = NULL;
4090 /* switch to large buffer if too big for a small one */
4091 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
4092 server->large_buf = true;
4093 memcpy(server->bigbuf, buf, server->total_read);
4094 buf = server->bigbuf;
4097 /* now read the rest */
4098 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
4099 pdu_length - HEADER_SIZE(server) + 1);
4102 server->total_read += length;
4104 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
4105 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0);
4109 next_is_large = server->large_buf;
4111 shdr = (struct smb2_sync_hdr *)buf;
4112 if (shdr->NextCommand) {
4114 next_buffer = (char *)cifs_buf_get();
4116 next_buffer = (char *)cifs_small_buf_get();
4118 buf + le32_to_cpu(shdr->NextCommand),
4119 pdu_length - le32_to_cpu(shdr->NextCommand));
4122 mid_entry = smb2_find_mid(server, buf);
4123 if (mid_entry == NULL)
4124 cifs_dbg(FYI, "mid not found\n");
4126 cifs_dbg(FYI, "mid found\n");
4127 mid_entry->decrypted = true;
4128 mid_entry->resp_buf_size = server->pdu_size;
4131 if (*num_mids >= MAX_COMPOUND) {
4132 cifs_dbg(VFS, "too many PDUs in compound\n");
4135 bufs[*num_mids] = buf;
4136 mids[(*num_mids)++] = mid_entry;
4138 if (mid_entry && mid_entry->handle)
4139 ret = mid_entry->handle(server, mid_entry);
4141 ret = cifs_handle_standard(server, mid_entry);
4143 if (ret == 0 && shdr->NextCommand) {
4144 pdu_length -= le32_to_cpu(shdr->NextCommand);
4145 server->large_buf = next_is_large;
4147 server->bigbuf = buf = next_buffer;
4149 server->smallbuf = buf = next_buffer;
4151 } else if (ret != 0) {
4153 * ret != 0 here means that we didn't get to handle_mid() thus
4154 * server->smallbuf and server->bigbuf are still valid. We need
4155 * to free next_buffer because it is not going to be used
4159 free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer);
4161 free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer);
4168 smb3_receive_transform(struct TCP_Server_Info *server,
4169 struct mid_q_entry **mids, char **bufs, int *num_mids)
4171 char *buf = server->smallbuf;
4172 unsigned int pdu_length = server->pdu_size;
4173 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4174 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4176 if (pdu_length < sizeof(struct smb2_transform_hdr) +
4177 sizeof(struct smb2_sync_hdr)) {
4178 cifs_dbg(VFS, "Transform message is too small (%u)\n",
4180 cifs_reconnect(server);
4181 wake_up(&server->response_q);
4182 return -ECONNABORTED;
4185 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
4186 cifs_dbg(VFS, "Transform message is broken\n");
4187 cifs_reconnect(server);
4188 wake_up(&server->response_q);
4189 return -ECONNABORTED;
4192 /* TODO: add support for compounds containing READ. */
4193 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
4195 return receive_encrypted_read(server, &mids[0]);
4198 return receive_encrypted_standard(server, mids, bufs, num_mids);
4202 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
4204 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
4206 return handle_read_data(server, mid, buf, server->pdu_size,
4211 smb2_next_header(char *buf)
4213 struct smb2_sync_hdr *hdr = (struct smb2_sync_hdr *)buf;
4214 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
4216 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
4217 return sizeof(struct smb2_transform_hdr) +
4218 le32_to_cpu(t_hdr->OriginalMessageSize);
4220 return le32_to_cpu(hdr->NextCommand);
4224 smb2_make_node(unsigned int xid, struct inode *inode,
4225 struct dentry *dentry, struct cifs_tcon *tcon,
4226 char *full_path, umode_t mode, dev_t dev)
4228 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
4230 int create_options = CREATE_NOT_DIR | CREATE_OPTION_SPECIAL;
4231 FILE_ALL_INFO *buf = NULL;
4232 struct cifs_io_parms io_parms;
4234 struct cifs_fid fid;
4235 struct cifs_open_parms oparms;
4236 unsigned int bytes_written;
4237 struct win_dev *pdev;
4241 * Check if mounted with mount parm 'sfu' mount parm.
4242 * SFU emulation should work with all servers, but only
4243 * supports block and char device (no socket & fifo),
4244 * and was used by default in earlier versions of Windows
4246 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
4250 * TODO: Add ability to create instead via reparse point. Windows (e.g.
4251 * their current NFS server) uses this approach to expose special files
4252 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
4255 if (!S_ISCHR(mode) && !S_ISBLK(mode))
4258 cifs_dbg(FYI, "sfu compat create special file\n");
4260 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
4266 if (backup_cred(cifs_sb))
4267 create_options |= CREATE_OPEN_BACKUP_INTENT;
4270 oparms.cifs_sb = cifs_sb;
4271 oparms.desired_access = GENERIC_WRITE;
4272 oparms.create_options = create_options;
4273 oparms.disposition = FILE_CREATE;
4274 oparms.path = full_path;
4276 oparms.reconnect = false;
4278 if (tcon->ses->server->oplocks)
4279 oplock = REQ_OPLOCK;
4282 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf);
4287 * BB Do not bother to decode buf since no local inode yet to put
4288 * timestamps in, but we can reuse it safely.
4291 pdev = (struct win_dev *)buf;
4292 io_parms.pid = current->tgid;
4293 io_parms.tcon = tcon;
4294 io_parms.offset = 0;
4295 io_parms.length = sizeof(struct win_dev);
4296 iov[1].iov_base = buf;
4297 iov[1].iov_len = sizeof(struct win_dev);
4298 if (S_ISCHR(mode)) {
4299 memcpy(pdev->type, "IntxCHR", 8);
4300 pdev->major = cpu_to_le64(MAJOR(dev));
4301 pdev->minor = cpu_to_le64(MINOR(dev));
4302 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
4303 &bytes_written, iov, 1);
4304 } else if (S_ISBLK(mode)) {
4305 memcpy(pdev->type, "IntxBLK", 8);
4306 pdev->major = cpu_to_le64(MAJOR(dev));
4307 pdev->minor = cpu_to_le64(MINOR(dev));
4308 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
4309 &bytes_written, iov, 1);
4311 tcon->ses->server->ops->close(xid, tcon, &fid);
4314 /* FIXME: add code here to set EAs */
4321 struct smb_version_operations smb20_operations = {
4322 .compare_fids = smb2_compare_fids,
4323 .setup_request = smb2_setup_request,
4324 .setup_async_request = smb2_setup_async_request,
4325 .check_receive = smb2_check_receive,
4326 .add_credits = smb2_add_credits,
4327 .set_credits = smb2_set_credits,
4328 .get_credits_field = smb2_get_credits_field,
4329 .get_credits = smb2_get_credits,
4330 .wait_mtu_credits = cifs_wait_mtu_credits,
4331 .get_next_mid = smb2_get_next_mid,
4332 .revert_current_mid = smb2_revert_current_mid,
4333 .read_data_offset = smb2_read_data_offset,
4334 .read_data_length = smb2_read_data_length,
4335 .map_error = map_smb2_to_linux_error,
4336 .find_mid = smb2_find_mid,
4337 .check_message = smb2_check_message,
4338 .dump_detail = smb2_dump_detail,
4339 .clear_stats = smb2_clear_stats,
4340 .print_stats = smb2_print_stats,
4341 .is_oplock_break = smb2_is_valid_oplock_break,
4342 .handle_cancelled_mid = smb2_handle_cancelled_mid,
4343 .downgrade_oplock = smb2_downgrade_oplock,
4344 .need_neg = smb2_need_neg,
4345 .negotiate = smb2_negotiate,
4346 .negotiate_wsize = smb2_negotiate_wsize,
4347 .negotiate_rsize = smb2_negotiate_rsize,
4348 .sess_setup = SMB2_sess_setup,
4349 .logoff = SMB2_logoff,
4350 .tree_connect = SMB2_tcon,
4351 .tree_disconnect = SMB2_tdis,
4352 .qfs_tcon = smb2_qfs_tcon,
4353 .is_path_accessible = smb2_is_path_accessible,
4354 .can_echo = smb2_can_echo,
4356 .query_path_info = smb2_query_path_info,
4357 .get_srv_inum = smb2_get_srv_inum,
4358 .query_file_info = smb2_query_file_info,
4359 .set_path_size = smb2_set_path_size,
4360 .set_file_size = smb2_set_file_size,
4361 .set_file_info = smb2_set_file_info,
4362 .set_compression = smb2_set_compression,
4363 .mkdir = smb2_mkdir,
4364 .mkdir_setinfo = smb2_mkdir_setinfo,
4365 .rmdir = smb2_rmdir,
4366 .unlink = smb2_unlink,
4367 .rename = smb2_rename_path,
4368 .create_hardlink = smb2_create_hardlink,
4369 .query_symlink = smb2_query_symlink,
4370 .query_mf_symlink = smb3_query_mf_symlink,
4371 .create_mf_symlink = smb3_create_mf_symlink,
4372 .open = smb2_open_file,
4373 .set_fid = smb2_set_fid,
4374 .close = smb2_close_file,
4375 .flush = smb2_flush_file,
4376 .async_readv = smb2_async_readv,
4377 .async_writev = smb2_async_writev,
4378 .sync_read = smb2_sync_read,
4379 .sync_write = smb2_sync_write,
4380 .query_dir_first = smb2_query_dir_first,
4381 .query_dir_next = smb2_query_dir_next,
4382 .close_dir = smb2_close_dir,
4383 .calc_smb_size = smb2_calc_size,
4384 .is_status_pending = smb2_is_status_pending,
4385 .is_session_expired = smb2_is_session_expired,
4386 .oplock_response = smb2_oplock_response,
4387 .queryfs = smb2_queryfs,
4388 .mand_lock = smb2_mand_lock,
4389 .mand_unlock_range = smb2_unlock_range,
4390 .push_mand_locks = smb2_push_mandatory_locks,
4391 .get_lease_key = smb2_get_lease_key,
4392 .set_lease_key = smb2_set_lease_key,
4393 .new_lease_key = smb2_new_lease_key,
4394 .calc_signature = smb2_calc_signature,
4395 .is_read_op = smb2_is_read_op,
4396 .set_oplock_level = smb2_set_oplock_level,
4397 .create_lease_buf = smb2_create_lease_buf,
4398 .parse_lease_buf = smb2_parse_lease_buf,
4399 .copychunk_range = smb2_copychunk_range,
4400 .wp_retry_size = smb2_wp_retry_size,
4401 .dir_needs_close = smb2_dir_needs_close,
4402 .get_dfs_refer = smb2_get_dfs_refer,
4403 .select_sectype = smb2_select_sectype,
4404 #ifdef CONFIG_CIFS_XATTR
4405 .query_all_EAs = smb2_query_eas,
4406 .set_EA = smb2_set_ea,
4407 #endif /* CIFS_XATTR */
4408 .get_acl = get_smb2_acl,
4409 .get_acl_by_fid = get_smb2_acl_by_fid,
4410 .set_acl = set_smb2_acl,
4411 .next_header = smb2_next_header,
4412 .ioctl_query_info = smb2_ioctl_query_info,
4413 .make_node = smb2_make_node,
4414 .fiemap = smb3_fiemap,
4415 .llseek = smb3_llseek,
4418 struct smb_version_operations smb21_operations = {
4419 .compare_fids = smb2_compare_fids,
4420 .setup_request = smb2_setup_request,
4421 .setup_async_request = smb2_setup_async_request,
4422 .check_receive = smb2_check_receive,
4423 .add_credits = smb2_add_credits,
4424 .set_credits = smb2_set_credits,
4425 .get_credits_field = smb2_get_credits_field,
4426 .get_credits = smb2_get_credits,
4427 .wait_mtu_credits = smb2_wait_mtu_credits,
4428 .adjust_credits = smb2_adjust_credits,
4429 .get_next_mid = smb2_get_next_mid,
4430 .revert_current_mid = smb2_revert_current_mid,
4431 .read_data_offset = smb2_read_data_offset,
4432 .read_data_length = smb2_read_data_length,
4433 .map_error = map_smb2_to_linux_error,
4434 .find_mid = smb2_find_mid,
4435 .check_message = smb2_check_message,
4436 .dump_detail = smb2_dump_detail,
4437 .clear_stats = smb2_clear_stats,
4438 .print_stats = smb2_print_stats,
4439 .is_oplock_break = smb2_is_valid_oplock_break,
4440 .handle_cancelled_mid = smb2_handle_cancelled_mid,
4441 .downgrade_oplock = smb21_downgrade_oplock,
4442 .need_neg = smb2_need_neg,
4443 .negotiate = smb2_negotiate,
4444 .negotiate_wsize = smb2_negotiate_wsize,
4445 .negotiate_rsize = smb2_negotiate_rsize,
4446 .sess_setup = SMB2_sess_setup,
4447 .logoff = SMB2_logoff,
4448 .tree_connect = SMB2_tcon,
4449 .tree_disconnect = SMB2_tdis,
4450 .qfs_tcon = smb2_qfs_tcon,
4451 .is_path_accessible = smb2_is_path_accessible,
4452 .can_echo = smb2_can_echo,
4454 .query_path_info = smb2_query_path_info,
4455 .get_srv_inum = smb2_get_srv_inum,
4456 .query_file_info = smb2_query_file_info,
4457 .set_path_size = smb2_set_path_size,
4458 .set_file_size = smb2_set_file_size,
4459 .set_file_info = smb2_set_file_info,
4460 .set_compression = smb2_set_compression,
4461 .mkdir = smb2_mkdir,
4462 .mkdir_setinfo = smb2_mkdir_setinfo,
4463 .rmdir = smb2_rmdir,
4464 .unlink = smb2_unlink,
4465 .rename = smb2_rename_path,
4466 .create_hardlink = smb2_create_hardlink,
4467 .query_symlink = smb2_query_symlink,
4468 .query_mf_symlink = smb3_query_mf_symlink,
4469 .create_mf_symlink = smb3_create_mf_symlink,
4470 .open = smb2_open_file,
4471 .set_fid = smb2_set_fid,
4472 .close = smb2_close_file,
4473 .flush = smb2_flush_file,
4474 .async_readv = smb2_async_readv,
4475 .async_writev = smb2_async_writev,
4476 .sync_read = smb2_sync_read,
4477 .sync_write = smb2_sync_write,
4478 .query_dir_first = smb2_query_dir_first,
4479 .query_dir_next = smb2_query_dir_next,
4480 .close_dir = smb2_close_dir,
4481 .calc_smb_size = smb2_calc_size,
4482 .is_status_pending = smb2_is_status_pending,
4483 .is_session_expired = smb2_is_session_expired,
4484 .oplock_response = smb2_oplock_response,
4485 .queryfs = smb2_queryfs,
4486 .mand_lock = smb2_mand_lock,
4487 .mand_unlock_range = smb2_unlock_range,
4488 .push_mand_locks = smb2_push_mandatory_locks,
4489 .get_lease_key = smb2_get_lease_key,
4490 .set_lease_key = smb2_set_lease_key,
4491 .new_lease_key = smb2_new_lease_key,
4492 .calc_signature = smb2_calc_signature,
4493 .is_read_op = smb21_is_read_op,
4494 .set_oplock_level = smb21_set_oplock_level,
4495 .create_lease_buf = smb2_create_lease_buf,
4496 .parse_lease_buf = smb2_parse_lease_buf,
4497 .copychunk_range = smb2_copychunk_range,
4498 .wp_retry_size = smb2_wp_retry_size,
4499 .dir_needs_close = smb2_dir_needs_close,
4500 .enum_snapshots = smb3_enum_snapshots,
4501 .get_dfs_refer = smb2_get_dfs_refer,
4502 .select_sectype = smb2_select_sectype,
4503 #ifdef CONFIG_CIFS_XATTR
4504 .query_all_EAs = smb2_query_eas,
4505 .set_EA = smb2_set_ea,
4506 #endif /* CIFS_XATTR */
4507 .get_acl = get_smb2_acl,
4508 .get_acl_by_fid = get_smb2_acl_by_fid,
4509 .set_acl = set_smb2_acl,
4510 .next_header = smb2_next_header,
4511 .ioctl_query_info = smb2_ioctl_query_info,
4512 .make_node = smb2_make_node,
4513 .fiemap = smb3_fiemap,
4514 .llseek = smb3_llseek,
4517 struct smb_version_operations smb30_operations = {
4518 .compare_fids = smb2_compare_fids,
4519 .setup_request = smb2_setup_request,
4520 .setup_async_request = smb2_setup_async_request,
4521 .check_receive = smb2_check_receive,
4522 .add_credits = smb2_add_credits,
4523 .set_credits = smb2_set_credits,
4524 .get_credits_field = smb2_get_credits_field,
4525 .get_credits = smb2_get_credits,
4526 .wait_mtu_credits = smb2_wait_mtu_credits,
4527 .adjust_credits = smb2_adjust_credits,
4528 .get_next_mid = smb2_get_next_mid,
4529 .revert_current_mid = smb2_revert_current_mid,
4530 .read_data_offset = smb2_read_data_offset,
4531 .read_data_length = smb2_read_data_length,
4532 .map_error = map_smb2_to_linux_error,
4533 .find_mid = smb2_find_mid,
4534 .check_message = smb2_check_message,
4535 .dump_detail = smb2_dump_detail,
4536 .clear_stats = smb2_clear_stats,
4537 .print_stats = smb2_print_stats,
4538 .dump_share_caps = smb2_dump_share_caps,
4539 .is_oplock_break = smb2_is_valid_oplock_break,
4540 .handle_cancelled_mid = smb2_handle_cancelled_mid,
4541 .downgrade_oplock = smb21_downgrade_oplock,
4542 .need_neg = smb2_need_neg,
4543 .negotiate = smb2_negotiate,
4544 .negotiate_wsize = smb3_negotiate_wsize,
4545 .negotiate_rsize = smb3_negotiate_rsize,
4546 .sess_setup = SMB2_sess_setup,
4547 .logoff = SMB2_logoff,
4548 .tree_connect = SMB2_tcon,
4549 .tree_disconnect = SMB2_tdis,
4550 .qfs_tcon = smb3_qfs_tcon,
4551 .is_path_accessible = smb2_is_path_accessible,
4552 .can_echo = smb2_can_echo,
4554 .query_path_info = smb2_query_path_info,
4555 .get_srv_inum = smb2_get_srv_inum,
4556 .query_file_info = smb2_query_file_info,
4557 .set_path_size = smb2_set_path_size,
4558 .set_file_size = smb2_set_file_size,
4559 .set_file_info = smb2_set_file_info,
4560 .set_compression = smb2_set_compression,
4561 .mkdir = smb2_mkdir,
4562 .mkdir_setinfo = smb2_mkdir_setinfo,
4563 .rmdir = smb2_rmdir,
4564 .unlink = smb2_unlink,
4565 .rename = smb2_rename_path,
4566 .create_hardlink = smb2_create_hardlink,
4567 .query_symlink = smb2_query_symlink,
4568 .query_mf_symlink = smb3_query_mf_symlink,
4569 .create_mf_symlink = smb3_create_mf_symlink,
4570 .open = smb2_open_file,
4571 .set_fid = smb2_set_fid,
4572 .close = smb2_close_file,
4573 .flush = smb2_flush_file,
4574 .async_readv = smb2_async_readv,
4575 .async_writev = smb2_async_writev,
4576 .sync_read = smb2_sync_read,
4577 .sync_write = smb2_sync_write,
4578 .query_dir_first = smb2_query_dir_first,
4579 .query_dir_next = smb2_query_dir_next,
4580 .close_dir = smb2_close_dir,
4581 .calc_smb_size = smb2_calc_size,
4582 .is_status_pending = smb2_is_status_pending,
4583 .is_session_expired = smb2_is_session_expired,
4584 .oplock_response = smb2_oplock_response,
4585 .queryfs = smb2_queryfs,
4586 .mand_lock = smb2_mand_lock,
4587 .mand_unlock_range = smb2_unlock_range,
4588 .push_mand_locks = smb2_push_mandatory_locks,
4589 .get_lease_key = smb2_get_lease_key,
4590 .set_lease_key = smb2_set_lease_key,
4591 .new_lease_key = smb2_new_lease_key,
4592 .generate_signingkey = generate_smb30signingkey,
4593 .calc_signature = smb3_calc_signature,
4594 .set_integrity = smb3_set_integrity,
4595 .is_read_op = smb21_is_read_op,
4596 .set_oplock_level = smb3_set_oplock_level,
4597 .create_lease_buf = smb3_create_lease_buf,
4598 .parse_lease_buf = smb3_parse_lease_buf,
4599 .copychunk_range = smb2_copychunk_range,
4600 .duplicate_extents = smb2_duplicate_extents,
4601 .validate_negotiate = smb3_validate_negotiate,
4602 .wp_retry_size = smb2_wp_retry_size,
4603 .dir_needs_close = smb2_dir_needs_close,
4604 .fallocate = smb3_fallocate,
4605 .enum_snapshots = smb3_enum_snapshots,
4606 .init_transform_rq = smb3_init_transform_rq,
4607 .is_transform_hdr = smb3_is_transform_hdr,
4608 .receive_transform = smb3_receive_transform,
4609 .get_dfs_refer = smb2_get_dfs_refer,
4610 .select_sectype = smb2_select_sectype,
4611 #ifdef CONFIG_CIFS_XATTR
4612 .query_all_EAs = smb2_query_eas,
4613 .set_EA = smb2_set_ea,
4614 #endif /* CIFS_XATTR */
4615 .get_acl = get_smb2_acl,
4616 .get_acl_by_fid = get_smb2_acl_by_fid,
4617 .set_acl = set_smb2_acl,
4618 .next_header = smb2_next_header,
4619 .ioctl_query_info = smb2_ioctl_query_info,
4620 .make_node = smb2_make_node,
4621 .fiemap = smb3_fiemap,
4622 .llseek = smb3_llseek,
4625 struct smb_version_operations smb311_operations = {
4626 .compare_fids = smb2_compare_fids,
4627 .setup_request = smb2_setup_request,
4628 .setup_async_request = smb2_setup_async_request,
4629 .check_receive = smb2_check_receive,
4630 .add_credits = smb2_add_credits,
4631 .set_credits = smb2_set_credits,
4632 .get_credits_field = smb2_get_credits_field,
4633 .get_credits = smb2_get_credits,
4634 .wait_mtu_credits = smb2_wait_mtu_credits,
4635 .adjust_credits = smb2_adjust_credits,
4636 .get_next_mid = smb2_get_next_mid,
4637 .revert_current_mid = smb2_revert_current_mid,
4638 .read_data_offset = smb2_read_data_offset,
4639 .read_data_length = smb2_read_data_length,
4640 .map_error = map_smb2_to_linux_error,
4641 .find_mid = smb2_find_mid,
4642 .check_message = smb2_check_message,
4643 .dump_detail = smb2_dump_detail,
4644 .clear_stats = smb2_clear_stats,
4645 .print_stats = smb2_print_stats,
4646 .dump_share_caps = smb2_dump_share_caps,
4647 .is_oplock_break = smb2_is_valid_oplock_break,
4648 .handle_cancelled_mid = smb2_handle_cancelled_mid,
4649 .downgrade_oplock = smb21_downgrade_oplock,
4650 .need_neg = smb2_need_neg,
4651 .negotiate = smb2_negotiate,
4652 .negotiate_wsize = smb3_negotiate_wsize,
4653 .negotiate_rsize = smb3_negotiate_rsize,
4654 .sess_setup = SMB2_sess_setup,
4655 .logoff = SMB2_logoff,
4656 .tree_connect = SMB2_tcon,
4657 .tree_disconnect = SMB2_tdis,
4658 .qfs_tcon = smb3_qfs_tcon,
4659 .is_path_accessible = smb2_is_path_accessible,
4660 .can_echo = smb2_can_echo,
4662 .query_path_info = smb2_query_path_info,
4663 .get_srv_inum = smb2_get_srv_inum,
4664 .query_file_info = smb2_query_file_info,
4665 .set_path_size = smb2_set_path_size,
4666 .set_file_size = smb2_set_file_size,
4667 .set_file_info = smb2_set_file_info,
4668 .set_compression = smb2_set_compression,
4669 .mkdir = smb2_mkdir,
4670 .mkdir_setinfo = smb2_mkdir_setinfo,
4671 .posix_mkdir = smb311_posix_mkdir,
4672 .rmdir = smb2_rmdir,
4673 .unlink = smb2_unlink,
4674 .rename = smb2_rename_path,
4675 .create_hardlink = smb2_create_hardlink,
4676 .query_symlink = smb2_query_symlink,
4677 .query_mf_symlink = smb3_query_mf_symlink,
4678 .create_mf_symlink = smb3_create_mf_symlink,
4679 .open = smb2_open_file,
4680 .set_fid = smb2_set_fid,
4681 .close = smb2_close_file,
4682 .flush = smb2_flush_file,
4683 .async_readv = smb2_async_readv,
4684 .async_writev = smb2_async_writev,
4685 .sync_read = smb2_sync_read,
4686 .sync_write = smb2_sync_write,
4687 .query_dir_first = smb2_query_dir_first,
4688 .query_dir_next = smb2_query_dir_next,
4689 .close_dir = smb2_close_dir,
4690 .calc_smb_size = smb2_calc_size,
4691 .is_status_pending = smb2_is_status_pending,
4692 .is_session_expired = smb2_is_session_expired,
4693 .oplock_response = smb2_oplock_response,
4694 .queryfs = smb311_queryfs,
4695 .mand_lock = smb2_mand_lock,
4696 .mand_unlock_range = smb2_unlock_range,
4697 .push_mand_locks = smb2_push_mandatory_locks,
4698 .get_lease_key = smb2_get_lease_key,
4699 .set_lease_key = smb2_set_lease_key,
4700 .new_lease_key = smb2_new_lease_key,
4701 .generate_signingkey = generate_smb311signingkey,
4702 .calc_signature = smb3_calc_signature,
4703 .set_integrity = smb3_set_integrity,
4704 .is_read_op = smb21_is_read_op,
4705 .set_oplock_level = smb3_set_oplock_level,
4706 .create_lease_buf = smb3_create_lease_buf,
4707 .parse_lease_buf = smb3_parse_lease_buf,
4708 .copychunk_range = smb2_copychunk_range,
4709 .duplicate_extents = smb2_duplicate_extents,
4710 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
4711 .wp_retry_size = smb2_wp_retry_size,
4712 .dir_needs_close = smb2_dir_needs_close,
4713 .fallocate = smb3_fallocate,
4714 .enum_snapshots = smb3_enum_snapshots,
4715 .init_transform_rq = smb3_init_transform_rq,
4716 .is_transform_hdr = smb3_is_transform_hdr,
4717 .receive_transform = smb3_receive_transform,
4718 .get_dfs_refer = smb2_get_dfs_refer,
4719 .select_sectype = smb2_select_sectype,
4720 #ifdef CONFIG_CIFS_XATTR
4721 .query_all_EAs = smb2_query_eas,
4722 .set_EA = smb2_set_ea,
4723 #endif /* CIFS_XATTR */
4724 .get_acl = get_smb2_acl,
4725 .get_acl_by_fid = get_smb2_acl_by_fid,
4726 .set_acl = set_smb2_acl,
4727 .next_header = smb2_next_header,
4728 .ioctl_query_info = smb2_ioctl_query_info,
4729 .make_node = smb2_make_node,
4730 .fiemap = smb3_fiemap,
4731 .llseek = smb3_llseek,
4734 struct smb_version_values smb20_values = {
4735 .version_string = SMB20_VERSION_STRING,
4736 .protocol_id = SMB20_PROT_ID,
4737 .req_capabilities = 0, /* MBZ */
4738 .large_lock_type = 0,
4739 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4740 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4741 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4742 .header_size = sizeof(struct smb2_sync_hdr),
4743 .header_preamble_size = 0,
4744 .max_header_size = MAX_SMB2_HDR_SIZE,
4745 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4746 .lock_cmd = SMB2_LOCK,
4748 .cap_nt_find = SMB2_NT_FIND,
4749 .cap_large_files = SMB2_LARGE_FILES,
4750 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4751 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4752 .create_lease_size = sizeof(struct create_lease),
4755 struct smb_version_values smb21_values = {
4756 .version_string = SMB21_VERSION_STRING,
4757 .protocol_id = SMB21_PROT_ID,
4758 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
4759 .large_lock_type = 0,
4760 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4761 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4762 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4763 .header_size = sizeof(struct smb2_sync_hdr),
4764 .header_preamble_size = 0,
4765 .max_header_size = MAX_SMB2_HDR_SIZE,
4766 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4767 .lock_cmd = SMB2_LOCK,
4769 .cap_nt_find = SMB2_NT_FIND,
4770 .cap_large_files = SMB2_LARGE_FILES,
4771 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4772 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4773 .create_lease_size = sizeof(struct create_lease),
4776 struct smb_version_values smb3any_values = {
4777 .version_string = SMB3ANY_VERSION_STRING,
4778 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
4779 .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,
4780 .large_lock_type = 0,
4781 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4782 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4783 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4784 .header_size = sizeof(struct smb2_sync_hdr),
4785 .header_preamble_size = 0,
4786 .max_header_size = MAX_SMB2_HDR_SIZE,
4787 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4788 .lock_cmd = SMB2_LOCK,
4790 .cap_nt_find = SMB2_NT_FIND,
4791 .cap_large_files = SMB2_LARGE_FILES,
4792 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4793 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4794 .create_lease_size = sizeof(struct create_lease_v2),
4797 struct smb_version_values smbdefault_values = {
4798 .version_string = SMBDEFAULT_VERSION_STRING,
4799 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
4800 .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,
4801 .large_lock_type = 0,
4802 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4803 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4804 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4805 .header_size = sizeof(struct smb2_sync_hdr),
4806 .header_preamble_size = 0,
4807 .max_header_size = MAX_SMB2_HDR_SIZE,
4808 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4809 .lock_cmd = SMB2_LOCK,
4811 .cap_nt_find = SMB2_NT_FIND,
4812 .cap_large_files = SMB2_LARGE_FILES,
4813 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4814 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4815 .create_lease_size = sizeof(struct create_lease_v2),
4818 struct smb_version_values smb30_values = {
4819 .version_string = SMB30_VERSION_STRING,
4820 .protocol_id = SMB30_PROT_ID,
4821 .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,
4822 .large_lock_type = 0,
4823 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4824 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4825 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4826 .header_size = sizeof(struct smb2_sync_hdr),
4827 .header_preamble_size = 0,
4828 .max_header_size = MAX_SMB2_HDR_SIZE,
4829 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4830 .lock_cmd = SMB2_LOCK,
4832 .cap_nt_find = SMB2_NT_FIND,
4833 .cap_large_files = SMB2_LARGE_FILES,
4834 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4835 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4836 .create_lease_size = sizeof(struct create_lease_v2),
4839 struct smb_version_values smb302_values = {
4840 .version_string = SMB302_VERSION_STRING,
4841 .protocol_id = SMB302_PROT_ID,
4842 .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,
4843 .large_lock_type = 0,
4844 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4845 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4846 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4847 .header_size = sizeof(struct smb2_sync_hdr),
4848 .header_preamble_size = 0,
4849 .max_header_size = MAX_SMB2_HDR_SIZE,
4850 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4851 .lock_cmd = SMB2_LOCK,
4853 .cap_nt_find = SMB2_NT_FIND,
4854 .cap_large_files = SMB2_LARGE_FILES,
4855 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4856 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4857 .create_lease_size = sizeof(struct create_lease_v2),
4860 struct smb_version_values smb311_values = {
4861 .version_string = SMB311_VERSION_STRING,
4862 .protocol_id = SMB311_PROT_ID,
4863 .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,
4864 .large_lock_type = 0,
4865 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4866 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4867 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4868 .header_size = sizeof(struct smb2_sync_hdr),
4869 .header_preamble_size = 0,
4870 .max_header_size = MAX_SMB2_HDR_SIZE,
4871 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4872 .lock_cmd = SMB2_LOCK,
4874 .cap_nt_find = SMB2_NT_FIND,
4875 .cap_large_files = SMB2_LARGE_FILES,
4876 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4877 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4878 .create_lease_size = sizeof(struct create_lease_v2),