1 // SPDX-License-Identifier: GPL-2.0
3 * SMB2 version specific operations
8 #include <linux/pagemap.h>
10 #include <linux/falloc.h>
11 #include <linux/scatterlist.h>
12 #include <linux/uuid.h>
13 #include <linux/sort.h>
14 #include <crypto/aead.h>
15 #include <linux/fiemap.h>
19 #include "smb2proto.h"
20 #include "cifsproto.h"
21 #include "cifs_debug.h"
22 #include "cifs_unicode.h"
23 #include "smb2status.h"
25 #include "cifs_ioctl.h"
26 #include "smbdirect.h"
27 #include "fs_context.h"
29 /* Change credits for different ops and return the total number of credits */
31 change_conf(struct TCP_Server_Info *server)
33 server->credits += server->echo_credits + server->oplock_credits;
34 server->oplock_credits = server->echo_credits = 0;
35 switch (server->credits) {
39 server->echoes = false;
40 server->oplocks = false;
43 server->echoes = true;
44 server->oplocks = false;
45 server->echo_credits = 1;
48 server->echoes = true;
50 server->oplocks = true;
51 server->oplock_credits = 1;
53 server->oplocks = false;
55 server->echo_credits = 1;
57 server->credits -= server->echo_credits + server->oplock_credits;
58 return server->credits + server->echo_credits + server->oplock_credits;
62 smb2_add_credits(struct TCP_Server_Info *server,
63 const struct cifs_credits *credits, const int optype)
66 int scredits, in_flight;
67 unsigned int add = credits->value;
68 unsigned int instance = credits->instance;
69 bool reconnect_detected = false;
70 bool reconnect_with_invalid_credits = false;
72 spin_lock(&server->req_lock);
73 val = server->ops->get_credits_field(server, optype);
75 /* eg found case where write overlapping reconnect messed up credits */
76 if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0))
77 reconnect_with_invalid_credits = true;
79 if ((instance == 0) || (instance == server->reconnect_instance))
82 reconnect_detected = true;
85 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
86 pr_warn_once("server overflowed SMB3 credits\n");
89 if (server->in_flight == 0 &&
90 ((optype & CIFS_OP_MASK) != CIFS_NEG_OP) &&
91 ((optype & CIFS_OP_MASK) != CIFS_SESS_OP))
92 rc = change_conf(server);
94 * Sometimes server returns 0 credits on oplock break ack - we need to
95 * rebalance credits in this case.
97 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
99 if (server->credits > 1) {
101 server->oplock_credits++;
105 in_flight = server->in_flight;
106 spin_unlock(&server->req_lock);
107 wake_up(&server->request_q);
109 if (reconnect_detected) {
110 trace_smb3_reconnect_detected(server->CurrentMid,
111 server->conn_id, server->hostname, scredits, add, in_flight);
113 cifs_dbg(FYI, "trying to put %d credits from the old server instance %d\n",
117 if (reconnect_with_invalid_credits) {
118 trace_smb3_reconnect_with_invalid_credits(server->CurrentMid,
119 server->conn_id, server->hostname, scredits, add, in_flight);
120 cifs_dbg(FYI, "Negotiate operation when server credits is non-zero. Optype: %d, server credits: %d, credits added: %d\n",
121 optype, scredits, add);
124 if (server->tcpStatus == CifsNeedReconnect
125 || server->tcpStatus == CifsExiting)
130 /* change_conf hasn't been executed */
133 cifs_server_dbg(VFS, "Possible client or server bug - zero credits\n");
136 cifs_server_dbg(VFS, "disabling echoes and oplocks\n");
139 cifs_dbg(FYI, "disabling oplocks\n");
142 /* change_conf rebalanced credits for different types */
146 trace_smb3_add_credits(server->CurrentMid,
147 server->conn_id, server->hostname, scredits, add, in_flight);
148 cifs_dbg(FYI, "%s: added %u credits total=%d\n", __func__, add, scredits);
152 smb2_set_credits(struct TCP_Server_Info *server, const int val)
154 int scredits, in_flight;
156 spin_lock(&server->req_lock);
157 server->credits = val;
159 server->reconnect_instance++;
160 scredits = server->credits;
161 in_flight = server->in_flight;
162 spin_unlock(&server->req_lock);
164 trace_smb3_set_credits(server->CurrentMid,
165 server->conn_id, server->hostname, scredits, val, in_flight);
166 cifs_dbg(FYI, "%s: set %u credits\n", __func__, val);
168 /* don't log while holding the lock */
170 cifs_dbg(FYI, "set credits to 1 due to smb2 reconnect\n");
174 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
178 return &server->echo_credits;
180 return &server->oplock_credits;
182 return &server->credits;
187 smb2_get_credits(struct mid_q_entry *mid)
189 return mid->credits_received;
193 smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
194 unsigned int *num, struct cifs_credits *credits)
197 unsigned int scredits, in_flight;
199 spin_lock(&server->req_lock);
201 if (server->credits <= 0) {
202 spin_unlock(&server->req_lock);
203 cifs_num_waiters_inc(server);
204 rc = wait_event_killable(server->request_q,
205 has_credits(server, &server->credits, 1));
206 cifs_num_waiters_dec(server);
209 spin_lock(&server->req_lock);
211 if (server->tcpStatus == CifsExiting) {
212 spin_unlock(&server->req_lock);
216 scredits = server->credits;
217 /* can deadlock with reopen */
219 *num = SMB2_MAX_BUFFER_SIZE;
221 credits->instance = 0;
225 /* leave some credits for reopen and other ops */
227 *num = min_t(unsigned int, size,
228 scredits * SMB2_MAX_BUFFER_SIZE);
231 DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
232 credits->instance = server->reconnect_instance;
233 server->credits -= credits->value;
235 if (server->in_flight > server->max_in_flight)
236 server->max_in_flight = server->in_flight;
240 scredits = server->credits;
241 in_flight = server->in_flight;
242 spin_unlock(&server->req_lock);
244 trace_smb3_add_credits(server->CurrentMid,
245 server->conn_id, server->hostname, scredits, -(credits->value), in_flight);
246 cifs_dbg(FYI, "%s: removed %u credits total=%d\n",
247 __func__, credits->value, scredits);
253 smb2_adjust_credits(struct TCP_Server_Info *server,
254 struct cifs_credits *credits,
255 const unsigned int payload_size)
257 int new_val = DIV_ROUND_UP(payload_size, SMB2_MAX_BUFFER_SIZE);
258 int scredits, in_flight;
260 if (!credits->value || credits->value == new_val)
263 if (credits->value < new_val) {
264 trace_smb3_too_many_credits(server->CurrentMid,
265 server->conn_id, server->hostname, 0, credits->value - new_val, 0);
266 cifs_server_dbg(VFS, "request has less credits (%d) than required (%d)",
267 credits->value, new_val);
272 spin_lock(&server->req_lock);
274 if (server->reconnect_instance != credits->instance) {
275 scredits = server->credits;
276 in_flight = server->in_flight;
277 spin_unlock(&server->req_lock);
279 trace_smb3_reconnect_detected(server->CurrentMid,
280 server->conn_id, server->hostname, scredits,
281 credits->value - new_val, in_flight);
282 cifs_server_dbg(VFS, "trying to return %d credits to old session\n",
283 credits->value - new_val);
287 server->credits += credits->value - new_val;
288 scredits = server->credits;
289 in_flight = server->in_flight;
290 spin_unlock(&server->req_lock);
291 wake_up(&server->request_q);
293 trace_smb3_add_credits(server->CurrentMid,
294 server->conn_id, server->hostname, scredits,
295 credits->value - new_val, in_flight);
296 cifs_dbg(FYI, "%s: adjust added %u credits total=%d\n",
297 __func__, credits->value - new_val, scredits);
299 credits->value = new_val;
305 smb2_get_next_mid(struct TCP_Server_Info *server)
308 /* for SMB2 we need the current value */
309 spin_lock(&GlobalMid_Lock);
310 mid = server->CurrentMid++;
311 spin_unlock(&GlobalMid_Lock);
316 smb2_revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
318 spin_lock(&GlobalMid_Lock);
319 if (server->CurrentMid >= val)
320 server->CurrentMid -= val;
321 spin_unlock(&GlobalMid_Lock);
324 static struct mid_q_entry *
325 __smb2_find_mid(struct TCP_Server_Info *server, char *buf, bool dequeue)
327 struct mid_q_entry *mid;
328 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
329 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
331 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
332 cifs_server_dbg(VFS, "Encrypted frame parsing not supported yet\n");
336 spin_lock(&GlobalMid_Lock);
337 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
338 if ((mid->mid == wire_mid) &&
339 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
340 (mid->command == shdr->Command)) {
341 kref_get(&mid->refcount);
343 list_del_init(&mid->qhead);
344 mid->mid_flags |= MID_DELETED;
346 spin_unlock(&GlobalMid_Lock);
350 spin_unlock(&GlobalMid_Lock);
354 static struct mid_q_entry *
355 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
357 return __smb2_find_mid(server, buf, false);
360 static struct mid_q_entry *
361 smb2_find_dequeue_mid(struct TCP_Server_Info *server, char *buf)
363 return __smb2_find_mid(server, buf, true);
367 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
369 #ifdef CONFIG_CIFS_DEBUG2
370 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
372 cifs_server_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
373 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
375 cifs_server_dbg(VFS, "smb buf %p len %u\n", buf,
376 server->ops->calc_smb_size(buf, server));
381 smb2_need_neg(struct TCP_Server_Info *server)
383 return server->max_read == 0;
387 smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
391 cifs_ses_server(ses)->CurrentMid = 0;
392 rc = SMB2_negotiate(xid, ses);
393 /* BB we probably don't need to retry with modern servers */
400 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
402 struct TCP_Server_Info *server = tcon->ses->server;
405 /* start with specified wsize, or default */
406 wsize = ctx->wsize ? ctx->wsize : CIFS_DEFAULT_IOSIZE;
407 wsize = min_t(unsigned int, wsize, server->max_write);
408 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
409 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
415 smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
417 struct TCP_Server_Info *server = tcon->ses->server;
420 /* start with specified wsize, or default */
421 wsize = ctx->wsize ? ctx->wsize : SMB3_DEFAULT_IOSIZE;
422 wsize = min_t(unsigned int, wsize, server->max_write);
423 #ifdef CONFIG_CIFS_SMB_DIRECT
427 * Account for SMB2 data transfer packet header and
428 * possible encryption header
430 wsize = min_t(unsigned int,
432 server->smbd_conn->max_fragmented_send_size -
433 SMB2_READWRITE_PDU_HEADER_SIZE -
434 sizeof(struct smb2_transform_hdr));
436 wsize = min_t(unsigned int,
437 wsize, server->smbd_conn->max_readwrite_size);
440 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
441 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
447 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
449 struct TCP_Server_Info *server = tcon->ses->server;
452 /* start with specified rsize, or default */
453 rsize = ctx->rsize ? ctx->rsize : CIFS_DEFAULT_IOSIZE;
454 rsize = min_t(unsigned int, rsize, server->max_read);
456 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
457 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
463 smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
465 struct TCP_Server_Info *server = tcon->ses->server;
468 /* start with specified rsize, or default */
469 rsize = ctx->rsize ? ctx->rsize : SMB3_DEFAULT_IOSIZE;
470 rsize = min_t(unsigned int, rsize, server->max_read);
471 #ifdef CONFIG_CIFS_SMB_DIRECT
475 * Account for SMB2 data transfer packet header and
476 * possible encryption header
478 rsize = min_t(unsigned int,
480 server->smbd_conn->max_fragmented_recv_size -
481 SMB2_READWRITE_PDU_HEADER_SIZE -
482 sizeof(struct smb2_transform_hdr));
484 rsize = min_t(unsigned int,
485 rsize, server->smbd_conn->max_readwrite_size);
489 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
490 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
496 parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
498 struct cifs_server_iface **iface_list,
501 struct network_interface_info_ioctl_rsp *p;
502 struct sockaddr_in *addr4;
503 struct sockaddr_in6 *addr6;
504 struct iface_info_ipv4 *p4;
505 struct iface_info_ipv6 *p6;
506 struct cifs_server_iface *info;
516 * Fist pass: count and sanity check
519 bytes_left = buf_len;
521 while (bytes_left >= sizeof(*p)) {
523 next = le32_to_cpu(p->Next);
525 bytes_left -= sizeof(*p);
528 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
533 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
538 /* Azure rounds the buffer size up 8, to a 16 byte boundary */
539 if ((bytes_left > 8) || p->Next)
540 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
544 * Second pass: extract info to internal structure
547 *iface_list = kcalloc(nb_iface, sizeof(**iface_list), GFP_KERNEL);
554 bytes_left = buf_len;
556 while (bytes_left >= sizeof(*p)) {
557 info->speed = le64_to_cpu(p->LinkSpeed);
558 info->rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE);
559 info->rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE);
561 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, *iface_count);
562 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
563 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
564 le32_to_cpu(p->Capability));
568 * The kernel and wire socket structures have the same
569 * layout and use network byte order but make the
570 * conversion explicit in case either one changes.
573 addr4 = (struct sockaddr_in *)&info->sockaddr;
574 p4 = (struct iface_info_ipv4 *)p->Buffer;
575 addr4->sin_family = AF_INET;
576 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
578 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
579 addr4->sin_port = cpu_to_be16(CIFS_PORT);
581 cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
585 addr6 = (struct sockaddr_in6 *)&info->sockaddr;
586 p6 = (struct iface_info_ipv6 *)p->Buffer;
587 addr6->sin6_family = AF_INET6;
588 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
590 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
591 addr6->sin6_flowinfo = 0;
592 addr6->sin6_scope_id = 0;
593 addr6->sin6_port = cpu_to_be16(CIFS_PORT);
595 cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
600 "%s: skipping unsupported socket family\n",
608 next = le32_to_cpu(p->Next);
611 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
629 static int compare_iface(const void *ia, const void *ib)
631 const struct cifs_server_iface *a = (struct cifs_server_iface *)ia;
632 const struct cifs_server_iface *b = (struct cifs_server_iface *)ib;
634 return a->speed == b->speed ? 0 : (a->speed > b->speed ? -1 : 1);
638 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
641 unsigned int ret_data_len = 0;
642 struct network_interface_info_ioctl_rsp *out_buf = NULL;
643 struct cifs_server_iface *iface_list;
645 struct cifs_ses *ses = tcon->ses;
647 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
648 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
649 NULL /* no data input */, 0 /* no data input */,
650 CIFSMaxBufSize, (char **)&out_buf, &ret_data_len);
651 if (rc == -EOPNOTSUPP) {
653 "server does not support query network interfaces\n");
655 } else if (rc != 0) {
656 cifs_tcon_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
660 rc = parse_server_interfaces(out_buf, ret_data_len,
661 &iface_list, &iface_count);
665 /* sort interfaces from fastest to slowest */
666 sort(iface_list, iface_count, sizeof(*iface_list), compare_iface, NULL);
668 spin_lock(&ses->iface_lock);
669 kfree(ses->iface_list);
670 ses->iface_list = iface_list;
671 ses->iface_count = iface_count;
672 ses->iface_last_update = jiffies;
673 spin_unlock(&ses->iface_lock);
681 smb2_close_cached_fid(struct kref *ref)
683 struct cached_fid *cfid = container_of(ref, struct cached_fid,
686 if (cfid->is_valid) {
687 cifs_dbg(FYI, "clear cached root file handle\n");
688 SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid,
689 cfid->fid->volatile_fid);
690 cfid->is_valid = false;
691 cfid->file_all_info_is_valid = false;
692 cfid->has_lease = false;
696 void close_shroot(struct cached_fid *cfid)
698 mutex_lock(&cfid->fid_mutex);
699 kref_put(&cfid->refcount, smb2_close_cached_fid);
700 mutex_unlock(&cfid->fid_mutex);
703 void close_shroot_lease_locked(struct cached_fid *cfid)
705 if (cfid->has_lease) {
706 cfid->has_lease = false;
707 kref_put(&cfid->refcount, smb2_close_cached_fid);
711 void close_shroot_lease(struct cached_fid *cfid)
713 mutex_lock(&cfid->fid_mutex);
714 close_shroot_lease_locked(cfid);
715 mutex_unlock(&cfid->fid_mutex);
719 smb2_cached_lease_break(struct work_struct *work)
721 struct cached_fid *cfid = container_of(work,
722 struct cached_fid, lease_break);
724 close_shroot_lease(cfid);
728 * Open the directory at the root of a share
730 int open_shroot(unsigned int xid, struct cifs_tcon *tcon,
731 struct cifs_sb_info *cifs_sb,
732 struct cached_fid **cfid)
734 struct cifs_ses *ses = tcon->ses;
735 struct TCP_Server_Info *server = ses->server;
736 struct cifs_open_parms oparms;
737 struct smb2_create_rsp *o_rsp = NULL;
738 struct smb2_query_info_rsp *qi_rsp = NULL;
740 struct smb_rqst rqst[2];
741 struct kvec rsp_iov[2];
742 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
743 struct kvec qi_iov[1];
745 __le16 utf16_path = 0; /* Null - since an open of top of share */
746 u8 oplock = SMB2_OPLOCK_LEVEL_II;
747 struct cifs_fid *pfid;
749 mutex_lock(&tcon->crfid.fid_mutex);
750 if (tcon->crfid.is_valid) {
751 cifs_dbg(FYI, "found a cached root file handle\n");
752 *cfid = &tcon->crfid;
753 kref_get(&tcon->crfid.refcount);
754 mutex_unlock(&tcon->crfid.fid_mutex);
759 * We do not hold the lock for the open because in case
760 * SMB2_open needs to reconnect, it will end up calling
761 * cifs_mark_open_files_invalid() which takes the lock again
762 * thus causing a deadlock
765 mutex_unlock(&tcon->crfid.fid_mutex);
767 if (smb3_encryption_required(tcon))
768 flags |= CIFS_TRANSFORM_REQ;
770 if (!server->ops->new_lease_key)
773 pfid = tcon->crfid.fid;
774 server->ops->new_lease_key(pfid);
776 memset(rqst, 0, sizeof(rqst));
777 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
778 memset(rsp_iov, 0, sizeof(rsp_iov));
781 memset(&open_iov, 0, sizeof(open_iov));
782 rqst[0].rq_iov = open_iov;
783 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
786 oparms.create_options = cifs_create_options(cifs_sb, 0);
787 oparms.desired_access = FILE_READ_ATTRIBUTES;
788 oparms.disposition = FILE_OPEN;
790 oparms.reconnect = false;
792 rc = SMB2_open_init(tcon, server,
793 &rqst[0], &oplock, &oparms, &utf16_path);
796 smb2_set_next_command(tcon, &rqst[0]);
798 memset(&qi_iov, 0, sizeof(qi_iov));
799 rqst[1].rq_iov = qi_iov;
802 rc = SMB2_query_info_init(tcon, server,
803 &rqst[1], COMPOUND_FID,
804 COMPOUND_FID, FILE_ALL_INFORMATION,
806 sizeof(struct smb2_file_all_info) +
807 PATH_MAX * 2, 0, NULL);
811 smb2_set_related(&rqst[1]);
813 rc = compound_send_recv(xid, ses, server,
815 resp_buftype, rsp_iov);
816 mutex_lock(&tcon->crfid.fid_mutex);
819 * Now we need to check again as the cached root might have
820 * been successfully re-opened from a concurrent process
823 if (tcon->crfid.is_valid) {
824 /* work was already done */
826 /* stash fids for close() later */
827 struct cifs_fid fid = {
828 .persistent_fid = pfid->persistent_fid,
829 .volatile_fid = pfid->volatile_fid,
833 * caller expects this func to set pfid to a valid
834 * cached root, so we copy the existing one and get a
837 memcpy(pfid, tcon->crfid.fid, sizeof(*pfid));
838 kref_get(&tcon->crfid.refcount);
840 mutex_unlock(&tcon->crfid.fid_mutex);
843 /* close extra handle outside of crit sec */
844 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
850 /* Cached root is still invalid, continue normaly */
853 if (rc == -EREMCHG) {
854 tcon->need_reconnect = true;
855 pr_warn_once("server share %s deleted\n",
861 atomic_inc(&tcon->num_remote_opens);
863 o_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
864 oparms.fid->persistent_fid = o_rsp->PersistentFileId;
865 oparms.fid->volatile_fid = o_rsp->VolatileFileId;
866 #ifdef CONFIG_CIFS_DEBUG2
867 oparms.fid->mid = le64_to_cpu(o_rsp->sync_hdr.MessageId);
868 #endif /* CIFS_DEBUG2 */
870 memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid));
871 tcon->crfid.tcon = tcon;
872 tcon->crfid.is_valid = true;
873 kref_init(&tcon->crfid.refcount);
875 /* BB TBD check to see if oplock level check can be removed below */
876 if (o_rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE) {
877 kref_get(&tcon->crfid.refcount);
878 tcon->crfid.has_lease = true;
879 smb2_parse_contexts(server, o_rsp,
881 oparms.fid->lease_key, &oplock,
886 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
887 if (le32_to_cpu(qi_rsp->OutputBufferLength) < sizeof(struct smb2_file_all_info))
889 if (!smb2_validate_and_copy_iov(
890 le16_to_cpu(qi_rsp->OutputBufferOffset),
891 sizeof(struct smb2_file_all_info),
892 &rsp_iov[1], sizeof(struct smb2_file_all_info),
893 (char *)&tcon->crfid.file_all_info))
894 tcon->crfid.file_all_info_is_valid = true;
897 mutex_unlock(&tcon->crfid.fid_mutex);
899 SMB2_open_free(&rqst[0]);
900 SMB2_query_info_free(&rqst[1]);
901 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
902 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
904 *cfid = &tcon->crfid;
909 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
910 struct cifs_sb_info *cifs_sb)
913 __le16 srch_path = 0; /* Null - open root of share */
914 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
915 struct cifs_open_parms oparms;
917 bool no_cached_open = tcon->nohandlecache;
918 struct cached_fid *cfid = NULL;
921 oparms.desired_access = FILE_READ_ATTRIBUTES;
922 oparms.disposition = FILE_OPEN;
923 oparms.create_options = cifs_create_options(cifs_sb, 0);
925 oparms.reconnect = false;
927 if (no_cached_open) {
928 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
931 rc = open_shroot(xid, tcon, cifs_sb, &cfid);
933 memcpy(&fid, cfid->fid, sizeof(struct cifs_fid));
938 SMB3_request_interfaces(xid, tcon);
940 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
941 FS_ATTRIBUTE_INFORMATION);
942 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
943 FS_DEVICE_INFORMATION);
944 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
945 FS_VOLUME_INFORMATION);
946 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
947 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
949 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
955 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
956 struct cifs_sb_info *cifs_sb)
959 __le16 srch_path = 0; /* Null - open root of share */
960 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
961 struct cifs_open_parms oparms;
965 oparms.desired_access = FILE_READ_ATTRIBUTES;
966 oparms.disposition = FILE_OPEN;
967 oparms.create_options = cifs_create_options(cifs_sb, 0);
969 oparms.reconnect = false;
971 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
976 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
977 FS_ATTRIBUTE_INFORMATION);
978 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
979 FS_DEVICE_INFORMATION);
980 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
984 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
985 struct cifs_sb_info *cifs_sb, const char *full_path)
989 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
990 struct cifs_open_parms oparms;
993 if ((*full_path == 0) && tcon->crfid.is_valid)
996 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
1001 oparms.desired_access = FILE_READ_ATTRIBUTES;
1002 oparms.disposition = FILE_OPEN;
1003 oparms.create_options = cifs_create_options(cifs_sb, 0);
1005 oparms.reconnect = false;
1007 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
1014 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
1020 smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
1021 struct cifs_sb_info *cifs_sb, const char *full_path,
1022 u64 *uniqueid, FILE_ALL_INFO *data)
1024 *uniqueid = le64_to_cpu(data->IndexNumber);
1029 smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
1030 struct cifs_fid *fid, FILE_ALL_INFO *data)
1033 struct smb2_file_all_info *smb2_data;
1035 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
1037 if (smb2_data == NULL)
1040 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
1043 move_smb2_info_to_cifs(data, smb2_data);
1048 #ifdef CONFIG_CIFS_XATTR
1050 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
1051 struct smb2_file_full_ea_info *src, size_t src_size,
1052 const unsigned char *ea_name)
1055 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
1057 size_t buf_size = dst_size;
1058 size_t name_len, value_len, user_name_len;
1060 while (src_size > 0) {
1061 name = &src->ea_data[0];
1062 name_len = (size_t)src->ea_name_length;
1063 value = &src->ea_data[src->ea_name_length + 1];
1064 value_len = (size_t)le16_to_cpu(src->ea_value_length);
1069 if (src_size < 8 + name_len + 1 + value_len) {
1070 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
1076 if (ea_name_len == name_len &&
1077 memcmp(ea_name, name, name_len) == 0) {
1081 if (dst_size < value_len) {
1085 memcpy(dst, value, value_len);
1089 /* 'user.' plus a terminating null */
1090 user_name_len = 5 + 1 + name_len;
1092 if (buf_size == 0) {
1093 /* skip copy - calc size only */
1094 rc += user_name_len;
1095 } else if (dst_size >= user_name_len) {
1096 dst_size -= user_name_len;
1097 memcpy(dst, "user.", 5);
1099 memcpy(dst, src->ea_data, name_len);
1103 rc += user_name_len;
1105 /* stop before overrun buffer */
1111 if (!src->next_entry_offset)
1114 if (src_size < le32_to_cpu(src->next_entry_offset)) {
1115 /* stop before overrun buffer */
1119 src_size -= le32_to_cpu(src->next_entry_offset);
1120 src = (void *)((char *)src +
1121 le32_to_cpu(src->next_entry_offset));
1124 /* didn't find the named attribute */
1133 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
1134 const unsigned char *path, const unsigned char *ea_name,
1135 char *ea_data, size_t buf_size,
1136 struct cifs_sb_info *cifs_sb)
1140 struct kvec rsp_iov = {NULL, 0};
1141 int buftype = CIFS_NO_BUFFER;
1142 struct smb2_query_info_rsp *rsp;
1143 struct smb2_file_full_ea_info *info = NULL;
1145 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1149 rc = smb2_query_info_compound(xid, tcon, utf16_path,
1151 FILE_FULL_EA_INFORMATION,
1154 MAX_SMB2_CREATE_RESPONSE_SIZE -
1155 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1156 &rsp_iov, &buftype, cifs_sb);
1159 * If ea_name is NULL (listxattr) and there are no EAs,
1160 * return 0 as it's not an error. Otherwise, the specified
1161 * ea_name was not found.
1163 if (!ea_name && rc == -ENODATA)
1168 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
1169 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1170 le32_to_cpu(rsp->OutputBufferLength),
1172 sizeof(struct smb2_file_full_ea_info));
1176 info = (struct smb2_file_full_ea_info *)(
1177 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1178 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
1179 le32_to_cpu(rsp->OutputBufferLength), ea_name);
1183 free_rsp_buf(buftype, rsp_iov.iov_base);
1189 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
1190 const char *path, const char *ea_name, const void *ea_value,
1191 const __u16 ea_value_len, const struct nls_table *nls_codepage,
1192 struct cifs_sb_info *cifs_sb)
1194 struct cifs_ses *ses = tcon->ses;
1195 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1196 __le16 *utf16_path = NULL;
1197 int ea_name_len = strlen(ea_name);
1200 struct smb_rqst rqst[3];
1201 int resp_buftype[3];
1202 struct kvec rsp_iov[3];
1203 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1204 struct cifs_open_parms oparms;
1205 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1206 struct cifs_fid fid;
1207 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1208 unsigned int size[1];
1210 struct smb2_file_full_ea_info *ea = NULL;
1211 struct kvec close_iov[1];
1212 struct smb2_query_info_rsp *rsp;
1213 int rc, used_len = 0;
1215 if (smb3_encryption_required(tcon))
1216 flags |= CIFS_TRANSFORM_REQ;
1218 if (ea_name_len > 255)
1221 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1225 memset(rqst, 0, sizeof(rqst));
1226 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1227 memset(rsp_iov, 0, sizeof(rsp_iov));
1229 if (ses->server->ops->query_all_EAs) {
1231 rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1237 /* If we are adding a attribute we should first check
1238 * if there will be enough space available to store
1239 * the new EA. If not we should not add it since we
1240 * would not be able to even read the EAs back.
1242 rc = smb2_query_info_compound(xid, tcon, utf16_path,
1244 FILE_FULL_EA_INFORMATION,
1247 MAX_SMB2_CREATE_RESPONSE_SIZE -
1248 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1249 &rsp_iov[1], &resp_buftype[1], cifs_sb);
1251 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1252 used_len = le32_to_cpu(rsp->OutputBufferLength);
1254 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1255 resp_buftype[1] = CIFS_NO_BUFFER;
1256 memset(&rsp_iov[1], 0, sizeof(rsp_iov[1]));
1259 /* Use a fudge factor of 256 bytes in case we collide
1260 * with a different set_EAs command.
1262 if(CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1263 MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 <
1264 used_len + ea_name_len + ea_value_len + 1) {
1272 memset(&open_iov, 0, sizeof(open_iov));
1273 rqst[0].rq_iov = open_iov;
1274 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1276 memset(&oparms, 0, sizeof(oparms));
1278 oparms.desired_access = FILE_WRITE_EA;
1279 oparms.disposition = FILE_OPEN;
1280 oparms.create_options = cifs_create_options(cifs_sb, 0);
1282 oparms.reconnect = false;
1284 rc = SMB2_open_init(tcon, server,
1285 &rqst[0], &oplock, &oparms, utf16_path);
1288 smb2_set_next_command(tcon, &rqst[0]);
1292 memset(&si_iov, 0, sizeof(si_iov));
1293 rqst[1].rq_iov = si_iov;
1294 rqst[1].rq_nvec = 1;
1296 len = sizeof(*ea) + ea_name_len + ea_value_len + 1;
1297 ea = kzalloc(len, GFP_KERNEL);
1303 ea->ea_name_length = ea_name_len;
1304 ea->ea_value_length = cpu_to_le16(ea_value_len);
1305 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
1306 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
1311 rc = SMB2_set_info_init(tcon, server,
1312 &rqst[1], COMPOUND_FID,
1313 COMPOUND_FID, current->tgid,
1314 FILE_FULL_EA_INFORMATION,
1315 SMB2_O_INFO_FILE, 0, data, size);
1316 smb2_set_next_command(tcon, &rqst[1]);
1317 smb2_set_related(&rqst[1]);
1321 memset(&close_iov, 0, sizeof(close_iov));
1322 rqst[2].rq_iov = close_iov;
1323 rqst[2].rq_nvec = 1;
1324 rc = SMB2_close_init(tcon, server,
1325 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1326 smb2_set_related(&rqst[2]);
1328 rc = compound_send_recv(xid, ses, server,
1330 resp_buftype, rsp_iov);
1331 /* no need to bump num_remote_opens because handle immediately closed */
1336 SMB2_open_free(&rqst[0]);
1337 SMB2_set_info_free(&rqst[1]);
1338 SMB2_close_free(&rqst[2]);
1339 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1340 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1341 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1347 smb2_can_echo(struct TCP_Server_Info *server)
1349 return server->echoes;
1353 smb2_clear_stats(struct cifs_tcon *tcon)
1357 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1358 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1359 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1364 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1366 seq_puts(m, "\n\tShare Capabilities:");
1367 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1368 seq_puts(m, " DFS,");
1369 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1370 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1371 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1372 seq_puts(m, " SCALEOUT,");
1373 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1374 seq_puts(m, " CLUSTER,");
1375 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1376 seq_puts(m, " ASYMMETRIC,");
1377 if (tcon->capabilities == 0)
1378 seq_puts(m, " None");
1379 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1380 seq_puts(m, " Aligned,");
1381 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1382 seq_puts(m, " Partition Aligned,");
1383 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1384 seq_puts(m, " SSD,");
1385 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1386 seq_puts(m, " TRIM-support,");
1388 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1389 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1390 if (tcon->perf_sector_size)
1391 seq_printf(m, "\tOptimal sector size: 0x%x",
1392 tcon->perf_sector_size);
1393 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1397 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1399 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1400 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1403 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1404 * totals (requests sent) since those SMBs are per-session not per tcon
1406 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1407 (long long)(tcon->bytes_read),
1408 (long long)(tcon->bytes_written));
1409 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1410 atomic_read(&tcon->num_local_opens),
1411 atomic_read(&tcon->num_remote_opens));
1412 seq_printf(m, "\nTreeConnects: %d total %d failed",
1413 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1414 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1415 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1416 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1417 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1418 seq_printf(m, "\nCreates: %d total %d failed",
1419 atomic_read(&sent[SMB2_CREATE_HE]),
1420 atomic_read(&failed[SMB2_CREATE_HE]));
1421 seq_printf(m, "\nCloses: %d total %d failed",
1422 atomic_read(&sent[SMB2_CLOSE_HE]),
1423 atomic_read(&failed[SMB2_CLOSE_HE]));
1424 seq_printf(m, "\nFlushes: %d total %d failed",
1425 atomic_read(&sent[SMB2_FLUSH_HE]),
1426 atomic_read(&failed[SMB2_FLUSH_HE]));
1427 seq_printf(m, "\nReads: %d total %d failed",
1428 atomic_read(&sent[SMB2_READ_HE]),
1429 atomic_read(&failed[SMB2_READ_HE]));
1430 seq_printf(m, "\nWrites: %d total %d failed",
1431 atomic_read(&sent[SMB2_WRITE_HE]),
1432 atomic_read(&failed[SMB2_WRITE_HE]));
1433 seq_printf(m, "\nLocks: %d total %d failed",
1434 atomic_read(&sent[SMB2_LOCK_HE]),
1435 atomic_read(&failed[SMB2_LOCK_HE]));
1436 seq_printf(m, "\nIOCTLs: %d total %d failed",
1437 atomic_read(&sent[SMB2_IOCTL_HE]),
1438 atomic_read(&failed[SMB2_IOCTL_HE]));
1439 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1440 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1441 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1442 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1443 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1444 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1445 seq_printf(m, "\nQueryInfos: %d total %d failed",
1446 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1447 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1448 seq_printf(m, "\nSetInfos: %d total %d failed",
1449 atomic_read(&sent[SMB2_SET_INFO_HE]),
1450 atomic_read(&failed[SMB2_SET_INFO_HE]));
1451 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1452 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1453 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1457 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1459 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1460 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1462 cfile->fid.persistent_fid = fid->persistent_fid;
1463 cfile->fid.volatile_fid = fid->volatile_fid;
1464 cfile->fid.access = fid->access;
1465 #ifdef CONFIG_CIFS_DEBUG2
1466 cfile->fid.mid = fid->mid;
1467 #endif /* CIFS_DEBUG2 */
1468 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1470 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1471 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1475 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1476 struct cifs_fid *fid)
1478 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1482 smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon,
1483 struct cifsFileInfo *cfile)
1485 struct smb2_file_network_open_info file_inf;
1486 struct inode *inode;
1489 rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid,
1490 cfile->fid.volatile_fid, &file_inf);
1494 inode = d_inode(cfile->dentry);
1496 spin_lock(&inode->i_lock);
1497 CIFS_I(inode)->time = jiffies;
1499 /* Creation time should not need to be updated on close */
1500 if (file_inf.LastWriteTime)
1501 inode->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime);
1502 if (file_inf.ChangeTime)
1503 inode->i_ctime = cifs_NTtimeToUnix(file_inf.ChangeTime);
1504 if (file_inf.LastAccessTime)
1505 inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime);
1508 * i_blocks is not related to (i_size / i_blksize),
1509 * but instead 512 byte (2**9) size is required for
1510 * calculating num blocks.
1512 if (le64_to_cpu(file_inf.AllocationSize) > 4096)
1514 (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9;
1516 /* End of file and Attributes should not have to be updated on close */
1517 spin_unlock(&inode->i_lock);
1521 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1522 u64 persistent_fid, u64 volatile_fid,
1523 struct copychunk_ioctl *pcchunk)
1526 unsigned int ret_data_len;
1527 struct resume_key_req *res_key;
1529 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1530 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
1531 NULL, 0 /* no input */, CIFSMaxBufSize,
1532 (char **)&res_key, &ret_data_len);
1535 cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1536 goto req_res_key_exit;
1538 if (ret_data_len < sizeof(struct resume_key_req)) {
1539 cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n");
1541 goto req_res_key_exit;
1543 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1551 struct smb_rqst rqst[3];
1552 struct kvec rsp_iov[3];
1553 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1554 struct kvec qi_iov[1];
1555 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
1556 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1557 struct kvec close_iov[1];
1561 smb2_ioctl_query_info(const unsigned int xid,
1562 struct cifs_tcon *tcon,
1563 struct cifs_sb_info *cifs_sb,
1564 __le16 *path, int is_dir,
1567 struct iqi_vars *vars;
1568 struct smb_rqst *rqst;
1569 struct kvec *rsp_iov;
1570 struct cifs_ses *ses = tcon->ses;
1571 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1572 char __user *arg = (char __user *)p;
1573 struct smb_query_info qi;
1574 struct smb_query_info __user *pqi;
1577 struct smb2_query_info_rsp *qi_rsp = NULL;
1578 struct smb2_ioctl_rsp *io_rsp = NULL;
1579 void *buffer = NULL;
1580 int resp_buftype[3];
1581 struct cifs_open_parms oparms;
1582 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1583 struct cifs_fid fid;
1584 unsigned int size[2];
1586 int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR;
1588 vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
1591 rqst = &vars->rqst[0];
1592 rsp_iov = &vars->rsp_iov[0];
1594 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1596 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info)))
1599 if (qi.output_buffer_length > 1024) {
1604 if (!ses || !server) {
1609 if (smb3_encryption_required(tcon))
1610 flags |= CIFS_TRANSFORM_REQ;
1612 buffer = memdup_user(arg + sizeof(struct smb_query_info),
1613 qi.output_buffer_length);
1614 if (IS_ERR(buffer)) {
1616 return PTR_ERR(buffer);
1620 rqst[0].rq_iov = &vars->open_iov[0];
1621 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1623 memset(&oparms, 0, sizeof(oparms));
1625 oparms.disposition = FILE_OPEN;
1626 oparms.create_options = cifs_create_options(cifs_sb, create_options);
1628 oparms.reconnect = false;
1630 if (qi.flags & PASSTHRU_FSCTL) {
1631 switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1632 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1633 oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1635 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1636 oparms.desired_access = GENERIC_ALL;
1638 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1639 oparms.desired_access = GENERIC_READ;
1641 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1642 oparms.desired_access = GENERIC_WRITE;
1645 } else if (qi.flags & PASSTHRU_SET_INFO) {
1646 oparms.desired_access = GENERIC_WRITE;
1648 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1651 rc = SMB2_open_init(tcon, server,
1652 &rqst[0], &oplock, &oparms, path);
1655 smb2_set_next_command(tcon, &rqst[0]);
1658 if (qi.flags & PASSTHRU_FSCTL) {
1659 /* Can eventually relax perm check since server enforces too */
1660 if (!capable(CAP_SYS_ADMIN))
1663 rqst[1].rq_iov = &vars->io_iov[0];
1664 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1666 rc = SMB2_ioctl_init(tcon, server,
1668 COMPOUND_FID, COMPOUND_FID,
1669 qi.info_type, true, buffer,
1670 qi.output_buffer_length,
1672 MAX_SMB2_CREATE_RESPONSE_SIZE -
1673 MAX_SMB2_CLOSE_RESPONSE_SIZE);
1675 } else if (qi.flags == PASSTHRU_SET_INFO) {
1676 /* Can eventually relax perm check since server enforces too */
1677 if (!capable(CAP_SYS_ADMIN))
1680 rqst[1].rq_iov = &vars->si_iov[0];
1681 rqst[1].rq_nvec = 1;
1686 rc = SMB2_set_info_init(tcon, server,
1688 COMPOUND_FID, COMPOUND_FID,
1690 FILE_END_OF_FILE_INFORMATION,
1691 SMB2_O_INFO_FILE, 0, data, size);
1693 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1694 rqst[1].rq_iov = &vars->qi_iov[0];
1695 rqst[1].rq_nvec = 1;
1697 rc = SMB2_query_info_init(tcon, server,
1698 &rqst[1], COMPOUND_FID,
1699 COMPOUND_FID, qi.file_info_class,
1700 qi.info_type, qi.additional_information,
1701 qi.input_buffer_length,
1702 qi.output_buffer_length, buffer);
1703 } else { /* unknown flags */
1704 cifs_tcon_dbg(VFS, "Invalid passthru query flags: 0x%x\n",
1711 smb2_set_next_command(tcon, &rqst[1]);
1712 smb2_set_related(&rqst[1]);
1715 rqst[2].rq_iov = &vars->close_iov[0];
1716 rqst[2].rq_nvec = 1;
1718 rc = SMB2_close_init(tcon, server,
1719 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1722 smb2_set_related(&rqst[2]);
1724 rc = compound_send_recv(xid, ses, server,
1726 resp_buftype, rsp_iov);
1730 /* No need to bump num_remote_opens since handle immediately closed */
1731 if (qi.flags & PASSTHRU_FSCTL) {
1732 pqi = (struct smb_query_info __user *)arg;
1733 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1734 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1735 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1736 if (qi.input_buffer_length > 0 &&
1737 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length
1738 > rsp_iov[1].iov_len)
1741 if (copy_to_user(&pqi->input_buffer_length,
1742 &qi.input_buffer_length,
1743 sizeof(qi.input_buffer_length)))
1746 if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1747 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1748 qi.input_buffer_length))
1751 pqi = (struct smb_query_info __user *)arg;
1752 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1753 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1754 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1755 if (copy_to_user(&pqi->input_buffer_length,
1756 &qi.input_buffer_length,
1757 sizeof(qi.input_buffer_length)))
1760 if (copy_to_user(pqi + 1, qi_rsp->Buffer,
1761 qi.input_buffer_length))
1768 SMB2_open_free(&rqst[0]);
1769 if (qi.flags & PASSTHRU_FSCTL)
1770 SMB2_ioctl_free(&rqst[1]);
1772 SMB2_query_info_free(&rqst[1]);
1774 SMB2_close_free(&rqst[2]);
1775 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1776 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1777 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1786 smb2_copychunk_range(const unsigned int xid,
1787 struct cifsFileInfo *srcfile,
1788 struct cifsFileInfo *trgtfile, u64 src_off,
1789 u64 len, u64 dest_off)
1792 unsigned int ret_data_len;
1793 struct copychunk_ioctl *pcchunk;
1794 struct copychunk_ioctl_rsp *retbuf = NULL;
1795 struct cifs_tcon *tcon;
1796 int chunks_copied = 0;
1797 bool chunk_sizes_updated = false;
1798 ssize_t bytes_written, total_bytes_written = 0;
1800 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1802 if (pcchunk == NULL)
1805 cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
1806 /* Request a key from the server to identify the source of the copy */
1807 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1808 srcfile->fid.persistent_fid,
1809 srcfile->fid.volatile_fid, pcchunk);
1811 /* Note: request_res_key sets res_key null only if rc !=0 */
1815 /* For now array only one chunk long, will make more flexible later */
1816 pcchunk->ChunkCount = cpu_to_le32(1);
1817 pcchunk->Reserved = 0;
1818 pcchunk->Reserved2 = 0;
1820 tcon = tlink_tcon(trgtfile->tlink);
1823 pcchunk->SourceOffset = cpu_to_le64(src_off);
1824 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1826 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
1828 /* Request server copy to target from src identified by key */
1829 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1830 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1831 true /* is_fsctl */, (char *)pcchunk,
1832 sizeof(struct copychunk_ioctl), CIFSMaxBufSize,
1833 (char **)&retbuf, &ret_data_len);
1836 sizeof(struct copychunk_ioctl_rsp)) {
1837 cifs_tcon_dbg(VFS, "Invalid cchunk response size\n");
1841 if (retbuf->TotalBytesWritten == 0) {
1842 cifs_dbg(FYI, "no bytes copied\n");
1847 * Check if server claimed to write more than we asked
1849 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1850 le32_to_cpu(pcchunk->Length)) {
1851 cifs_tcon_dbg(VFS, "Invalid copy chunk response\n");
1855 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1856 cifs_tcon_dbg(VFS, "Invalid num chunks written\n");
1862 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1863 src_off += bytes_written;
1864 dest_off += bytes_written;
1865 len -= bytes_written;
1866 total_bytes_written += bytes_written;
1868 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1869 le32_to_cpu(retbuf->ChunksWritten),
1870 le32_to_cpu(retbuf->ChunkBytesWritten),
1872 } else if (rc == -EINVAL) {
1873 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1876 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1877 le32_to_cpu(retbuf->ChunksWritten),
1878 le32_to_cpu(retbuf->ChunkBytesWritten),
1879 le32_to_cpu(retbuf->TotalBytesWritten));
1882 * Check if this is the first request using these sizes,
1883 * (ie check if copy succeed once with original sizes
1884 * and check if the server gave us different sizes after
1885 * we already updated max sizes on previous request).
1886 * if not then why is the server returning an error now
1888 if ((chunks_copied != 0) || chunk_sizes_updated)
1891 /* Check that server is not asking us to grow size */
1892 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1893 tcon->max_bytes_chunk)
1894 tcon->max_bytes_chunk =
1895 le32_to_cpu(retbuf->ChunkBytesWritten);
1897 goto cchunk_out; /* server gave us bogus size */
1899 /* No need to change MaxChunks since already set to 1 */
1900 chunk_sizes_updated = true;
1911 return total_bytes_written;
1915 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1916 struct cifs_fid *fid)
1918 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1922 smb2_read_data_offset(char *buf)
1924 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1926 return rsp->DataOffset;
1930 smb2_read_data_length(char *buf, bool in_remaining)
1932 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1935 return le32_to_cpu(rsp->DataRemaining);
1937 return le32_to_cpu(rsp->DataLength);
1942 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1943 struct cifs_io_parms *parms, unsigned int *bytes_read,
1944 char **buf, int *buf_type)
1946 parms->persistent_fid = pfid->persistent_fid;
1947 parms->volatile_fid = pfid->volatile_fid;
1948 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1952 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1953 struct cifs_io_parms *parms, unsigned int *written,
1954 struct kvec *iov, unsigned long nr_segs)
1957 parms->persistent_fid = pfid->persistent_fid;
1958 parms->volatile_fid = pfid->volatile_fid;
1959 return SMB2_write(xid, parms, written, iov, nr_segs);
1962 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1963 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1964 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1966 struct cifsInodeInfo *cifsi;
1969 cifsi = CIFS_I(inode);
1971 /* if file already sparse don't bother setting sparse again */
1972 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1973 return true; /* already sparse */
1975 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1976 return true; /* already not sparse */
1979 * Can't check for sparse support on share the usual way via the
1980 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1981 * since Samba server doesn't set the flag on the share, yet
1982 * supports the set sparse FSCTL and returns sparse correctly
1983 * in the file attributes. If we fail setting sparse though we
1984 * mark that server does not support sparse files for this share
1985 * to avoid repeatedly sending the unsupported fsctl to server
1986 * if the file is repeatedly extended.
1988 if (tcon->broken_sparse_sup)
1991 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1992 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1994 &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
1996 tcon->broken_sparse_sup = true;
1997 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
2002 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
2004 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
2010 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
2011 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
2013 __le64 eof = cpu_to_le64(size);
2014 struct inode *inode;
2017 * If extending file more than one page make sparse. Many Linux fs
2018 * make files sparse by default when extending via ftruncate
2020 inode = d_inode(cfile->dentry);
2022 if (!set_alloc && (size > inode->i_size + 8192)) {
2023 __u8 set_sparse = 1;
2025 /* whether set sparse succeeds or not, extend the file */
2026 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
2029 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
2030 cfile->fid.volatile_fid, cfile->pid, &eof);
2034 smb2_duplicate_extents(const unsigned int xid,
2035 struct cifsFileInfo *srcfile,
2036 struct cifsFileInfo *trgtfile, u64 src_off,
2037 u64 len, u64 dest_off)
2040 unsigned int ret_data_len;
2041 struct duplicate_extents_to_file dup_ext_buf;
2042 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
2044 /* server fileays advertise duplicate extent support with this flag */
2045 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
2046 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
2049 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
2050 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
2051 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
2052 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
2053 dup_ext_buf.ByteCount = cpu_to_le64(len);
2054 cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
2055 src_off, dest_off, len);
2057 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
2059 goto duplicate_extents_out;
2061 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
2062 trgtfile->fid.volatile_fid,
2063 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
2064 true /* is_fsctl */,
2065 (char *)&dup_ext_buf,
2066 sizeof(struct duplicate_extents_to_file),
2067 CIFSMaxBufSize, NULL,
2070 if (ret_data_len > 0)
2071 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
2073 duplicate_extents_out:
2078 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
2079 struct cifsFileInfo *cfile)
2081 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
2082 cfile->fid.volatile_fid);
2086 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
2087 struct cifsFileInfo *cfile)
2089 struct fsctl_set_integrity_information_req integr_info;
2090 unsigned int ret_data_len;
2092 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
2093 integr_info.Flags = 0;
2094 integr_info.Reserved = 0;
2096 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2097 cfile->fid.volatile_fid,
2098 FSCTL_SET_INTEGRITY_INFORMATION,
2099 true /* is_fsctl */,
2100 (char *)&integr_info,
2101 sizeof(struct fsctl_set_integrity_information_req),
2102 CIFSMaxBufSize, NULL,
2107 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
2108 #define GMT_TOKEN_SIZE 50
2110 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
2113 * Input buffer contains (empty) struct smb_snapshot array with size filled in
2114 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
2117 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
2118 struct cifsFileInfo *cfile, void __user *ioc_buf)
2120 char *retbuf = NULL;
2121 unsigned int ret_data_len = 0;
2123 u32 max_response_size;
2124 struct smb_snapshot_array snapshot_in;
2127 * On the first query to enumerate the list of snapshots available
2128 * for this volume the buffer begins with 0 (number of snapshots
2129 * which can be returned is zero since at that point we do not know
2130 * how big the buffer needs to be). On the second query,
2131 * it (ret_data_len) is set to number of snapshots so we can
2132 * know to set the maximum response size larger (see below).
2134 if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
2138 * Note that for snapshot queries that servers like Azure expect that
2139 * the first query be minimal size (and just used to get the number/size
2140 * of previous versions) so response size must be specified as EXACTLY
2141 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
2144 if (ret_data_len == 0)
2145 max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
2147 max_response_size = CIFSMaxBufSize;
2149 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2150 cfile->fid.volatile_fid,
2151 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
2152 true /* is_fsctl */,
2153 NULL, 0 /* no input data */, max_response_size,
2156 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
2161 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
2163 if (copy_from_user(&snapshot_in, ioc_buf,
2164 sizeof(struct smb_snapshot_array))) {
2171 * Check for min size, ie not large enough to fit even one GMT
2172 * token (snapshot). On the first ioctl some users may pass in
2173 * smaller size (or zero) to simply get the size of the array
2174 * so the user space caller can allocate sufficient memory
2175 * and retry the ioctl again with larger array size sufficient
2176 * to hold all of the snapshot GMT tokens on the second try.
2178 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
2179 ret_data_len = sizeof(struct smb_snapshot_array);
2182 * We return struct SRV_SNAPSHOT_ARRAY, followed by
2183 * the snapshot array (of 50 byte GMT tokens) each
2184 * representing an available previous version of the data
2186 if (ret_data_len > (snapshot_in.snapshot_array_size +
2187 sizeof(struct smb_snapshot_array)))
2188 ret_data_len = snapshot_in.snapshot_array_size +
2189 sizeof(struct smb_snapshot_array);
2191 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
2202 smb3_notify(const unsigned int xid, struct file *pfile,
2203 void __user *ioc_buf)
2205 struct smb3_notify notify;
2206 struct dentry *dentry = pfile->f_path.dentry;
2207 struct inode *inode = file_inode(pfile);
2208 struct cifs_sb_info *cifs_sb;
2209 struct cifs_open_parms oparms;
2210 struct cifs_fid fid;
2211 struct cifs_tcon *tcon;
2212 unsigned char *path = NULL;
2213 __le16 *utf16_path = NULL;
2214 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2217 path = build_path_from_dentry(dentry);
2221 cifs_sb = CIFS_SB(inode->i_sb);
2223 utf16_path = cifs_convert_path_to_utf16(path + 1, cifs_sb);
2224 if (utf16_path == NULL) {
2229 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify))) {
2234 tcon = cifs_sb_master_tcon(cifs_sb);
2236 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
2237 oparms.disposition = FILE_OPEN;
2238 oparms.create_options = cifs_create_options(cifs_sb, 0);
2240 oparms.reconnect = false;
2242 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
2247 rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid,
2248 notify.watch_tree, notify.completion_filter);
2250 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2252 cifs_dbg(FYI, "change notify for path %s rc %d\n", path, rc);
2261 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
2262 const char *path, struct cifs_sb_info *cifs_sb,
2263 struct cifs_fid *fid, __u16 search_flags,
2264 struct cifs_search_info *srch_inf)
2267 struct smb_rqst rqst[2];
2268 struct kvec rsp_iov[2];
2269 int resp_buftype[2];
2270 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2271 struct kvec qd_iov[SMB2_QUERY_DIRECTORY_IOV_SIZE];
2273 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2274 struct cifs_open_parms oparms;
2275 struct smb2_query_directory_rsp *qd_rsp = NULL;
2276 struct smb2_create_rsp *op_rsp = NULL;
2277 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2279 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2283 if (smb3_encryption_required(tcon))
2284 flags |= CIFS_TRANSFORM_REQ;
2286 memset(rqst, 0, sizeof(rqst));
2287 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
2288 memset(rsp_iov, 0, sizeof(rsp_iov));
2291 memset(&open_iov, 0, sizeof(open_iov));
2292 rqst[0].rq_iov = open_iov;
2293 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2296 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
2297 oparms.disposition = FILE_OPEN;
2298 oparms.create_options = cifs_create_options(cifs_sb, 0);
2300 oparms.reconnect = false;
2302 rc = SMB2_open_init(tcon, server,
2303 &rqst[0], &oplock, &oparms, utf16_path);
2306 smb2_set_next_command(tcon, &rqst[0]);
2308 /* Query directory */
2309 srch_inf->entries_in_buffer = 0;
2310 srch_inf->index_of_last_entry = 2;
2312 memset(&qd_iov, 0, sizeof(qd_iov));
2313 rqst[1].rq_iov = qd_iov;
2314 rqst[1].rq_nvec = SMB2_QUERY_DIRECTORY_IOV_SIZE;
2316 rc = SMB2_query_directory_init(xid, tcon, server,
2318 COMPOUND_FID, COMPOUND_FID,
2319 0, srch_inf->info_level);
2323 smb2_set_related(&rqst[1]);
2325 rc = compound_send_recv(xid, tcon->ses, server,
2327 resp_buftype, rsp_iov);
2329 /* If the open failed there is nothing to do */
2330 op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
2331 if (op_rsp == NULL || op_rsp->sync_hdr.Status != STATUS_SUCCESS) {
2332 cifs_dbg(FYI, "query_dir_first: open failed rc=%d\n", rc);
2335 fid->persistent_fid = op_rsp->PersistentFileId;
2336 fid->volatile_fid = op_rsp->VolatileFileId;
2338 /* Anything else than ENODATA means a genuine error */
2339 if (rc && rc != -ENODATA) {
2340 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2341 cifs_dbg(FYI, "query_dir_first: query directory failed rc=%d\n", rc);
2342 trace_smb3_query_dir_err(xid, fid->persistent_fid,
2343 tcon->tid, tcon->ses->Suid, 0, 0, rc);
2347 atomic_inc(&tcon->num_remote_opens);
2349 qd_rsp = (struct smb2_query_directory_rsp *)rsp_iov[1].iov_base;
2350 if (qd_rsp->sync_hdr.Status == STATUS_NO_MORE_FILES) {
2351 trace_smb3_query_dir_done(xid, fid->persistent_fid,
2352 tcon->tid, tcon->ses->Suid, 0, 0);
2353 srch_inf->endOfSearch = true;
2358 rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1],
2361 trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid,
2362 tcon->ses->Suid, 0, 0, rc);
2365 resp_buftype[1] = CIFS_NO_BUFFER;
2367 trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid,
2368 tcon->ses->Suid, 0, srch_inf->entries_in_buffer);
2372 SMB2_open_free(&rqst[0]);
2373 SMB2_query_directory_free(&rqst[1]);
2374 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2375 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2380 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
2381 struct cifs_fid *fid, __u16 search_flags,
2382 struct cifs_search_info *srch_inf)
2384 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
2385 fid->volatile_fid, 0, srch_inf);
2389 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
2390 struct cifs_fid *fid)
2392 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2396 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2397 * the number of credits and return true. Otherwise - return false.
2400 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
2402 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2403 int scredits, in_flight;
2405 if (shdr->Status != STATUS_PENDING)
2408 if (shdr->CreditRequest) {
2409 spin_lock(&server->req_lock);
2410 server->credits += le16_to_cpu(shdr->CreditRequest);
2411 scredits = server->credits;
2412 in_flight = server->in_flight;
2413 spin_unlock(&server->req_lock);
2414 wake_up(&server->request_q);
2416 trace_smb3_add_credits(server->CurrentMid,
2417 server->conn_id, server->hostname, scredits,
2418 le16_to_cpu(shdr->CreditRequest), in_flight);
2419 cifs_dbg(FYI, "%s: status pending add %u credits total=%d\n",
2420 __func__, le16_to_cpu(shdr->CreditRequest), scredits);
2427 smb2_is_session_expired(char *buf)
2429 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2431 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
2432 shdr->Status != STATUS_USER_SESSION_DELETED)
2435 trace_smb3_ses_expired(shdr->TreeId, shdr->SessionId,
2436 le16_to_cpu(shdr->Command),
2437 le64_to_cpu(shdr->MessageId));
2438 cifs_dbg(FYI, "Session expired or deleted\n");
2444 smb2_is_status_io_timeout(char *buf)
2446 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2448 if (shdr->Status == STATUS_IO_TIMEOUT)
2455 smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server)
2457 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2458 struct list_head *tmp, *tmp1;
2459 struct cifs_ses *ses;
2460 struct cifs_tcon *tcon;
2462 if (shdr->Status != STATUS_NETWORK_NAME_DELETED)
2465 spin_lock(&cifs_tcp_ses_lock);
2466 list_for_each(tmp, &server->smb_ses_list) {
2467 ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
2468 list_for_each(tmp1, &ses->tcon_list) {
2469 tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
2470 if (tcon->tid == shdr->TreeId) {
2471 tcon->need_reconnect = true;
2472 spin_unlock(&cifs_tcp_ses_lock);
2473 pr_warn_once("Server share %s deleted.\n",
2479 spin_unlock(&cifs_tcp_ses_lock);
2483 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
2484 struct cifsInodeInfo *cinode)
2486 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
2487 return SMB2_lease_break(0, tcon, cinode->lease_key,
2488 smb2_get_lease_state(cinode));
2490 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
2492 CIFS_CACHE_READ(cinode) ? 1 : 0);
2496 smb2_set_related(struct smb_rqst *rqst)
2498 struct smb2_sync_hdr *shdr;
2500 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
2502 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2505 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2508 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
2511 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
2513 struct smb2_sync_hdr *shdr;
2514 struct cifs_ses *ses = tcon->ses;
2515 struct TCP_Server_Info *server = ses->server;
2516 unsigned long len = smb_rqst_len(server, rqst);
2519 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
2521 cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2525 /* SMB headers in a compound are 8 byte aligned. */
2527 /* No padding needed */
2531 num_padding = 8 - (len & 7);
2532 if (!smb3_encryption_required(tcon)) {
2534 * If we do not have encryption then we can just add an extra
2535 * iov for the padding.
2537 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2538 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2543 * We can not add a small padding iov for the encryption case
2544 * because the encryption framework can not handle the padding
2546 * We have to flatten this into a single buffer and add
2547 * the padding to it.
2549 for (i = 1; i < rqst->rq_nvec; i++) {
2550 memcpy(rqst->rq_iov[0].iov_base +
2551 rqst->rq_iov[0].iov_len,
2552 rqst->rq_iov[i].iov_base,
2553 rqst->rq_iov[i].iov_len);
2554 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2556 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2558 rqst->rq_iov[0].iov_len += num_padding;
2564 shdr->NextCommand = cpu_to_le32(len);
2568 * Passes the query info response back to the caller on success.
2569 * Caller need to free this with free_rsp_buf().
2572 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2573 __le16 *utf16_path, u32 desired_access,
2574 u32 class, u32 type, u32 output_len,
2575 struct kvec *rsp, int *buftype,
2576 struct cifs_sb_info *cifs_sb)
2578 struct cifs_ses *ses = tcon->ses;
2579 struct TCP_Server_Info *server = cifs_pick_channel(ses);
2581 struct smb_rqst rqst[3];
2582 int resp_buftype[3];
2583 struct kvec rsp_iov[3];
2584 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2585 struct kvec qi_iov[1];
2586 struct kvec close_iov[1];
2587 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2588 struct cifs_open_parms oparms;
2589 struct cifs_fid fid;
2592 if (smb3_encryption_required(tcon))
2593 flags |= CIFS_TRANSFORM_REQ;
2595 memset(rqst, 0, sizeof(rqst));
2596 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2597 memset(rsp_iov, 0, sizeof(rsp_iov));
2599 memset(&open_iov, 0, sizeof(open_iov));
2600 rqst[0].rq_iov = open_iov;
2601 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2604 oparms.desired_access = desired_access;
2605 oparms.disposition = FILE_OPEN;
2606 oparms.create_options = cifs_create_options(cifs_sb, 0);
2608 oparms.reconnect = false;
2610 rc = SMB2_open_init(tcon, server,
2611 &rqst[0], &oplock, &oparms, utf16_path);
2614 smb2_set_next_command(tcon, &rqst[0]);
2616 memset(&qi_iov, 0, sizeof(qi_iov));
2617 rqst[1].rq_iov = qi_iov;
2618 rqst[1].rq_nvec = 1;
2620 rc = SMB2_query_info_init(tcon, server,
2621 &rqst[1], COMPOUND_FID, COMPOUND_FID,
2627 smb2_set_next_command(tcon, &rqst[1]);
2628 smb2_set_related(&rqst[1]);
2630 memset(&close_iov, 0, sizeof(close_iov));
2631 rqst[2].rq_iov = close_iov;
2632 rqst[2].rq_nvec = 1;
2634 rc = SMB2_close_init(tcon, server,
2635 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2638 smb2_set_related(&rqst[2]);
2640 rc = compound_send_recv(xid, ses, server,
2642 resp_buftype, rsp_iov);
2644 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2645 if (rc == -EREMCHG) {
2646 tcon->need_reconnect = true;
2647 pr_warn_once("server share %s deleted\n",
2653 *buftype = resp_buftype[1];
2656 SMB2_open_free(&rqst[0]);
2657 SMB2_query_info_free(&rqst[1]);
2658 SMB2_close_free(&rqst[2]);
2659 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2660 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2665 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2666 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2668 struct smb2_query_info_rsp *rsp;
2669 struct smb2_fs_full_size_info *info = NULL;
2670 __le16 utf16_path = 0; /* Null - open root of share */
2671 struct kvec rsp_iov = {NULL, 0};
2672 int buftype = CIFS_NO_BUFFER;
2676 rc = smb2_query_info_compound(xid, tcon, &utf16_path,
2677 FILE_READ_ATTRIBUTES,
2678 FS_FULL_SIZE_INFORMATION,
2679 SMB2_O_INFO_FILESYSTEM,
2680 sizeof(struct smb2_fs_full_size_info),
2681 &rsp_iov, &buftype, cifs_sb);
2685 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2686 buf->f_type = SMB2_MAGIC_NUMBER;
2687 info = (struct smb2_fs_full_size_info *)(
2688 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2689 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2690 le32_to_cpu(rsp->OutputBufferLength),
2692 sizeof(struct smb2_fs_full_size_info));
2694 smb2_copy_fs_info_to_kstatfs(info, buf);
2697 free_rsp_buf(buftype, rsp_iov.iov_base);
2702 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2703 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2706 __le16 srch_path = 0; /* Null - open root of share */
2707 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2708 struct cifs_open_parms oparms;
2709 struct cifs_fid fid;
2711 if (!tcon->posix_extensions)
2712 return smb2_queryfs(xid, tcon, cifs_sb, buf);
2715 oparms.desired_access = FILE_READ_ATTRIBUTES;
2716 oparms.disposition = FILE_OPEN;
2717 oparms.create_options = cifs_create_options(cifs_sb, 0);
2719 oparms.reconnect = false;
2721 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
2726 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2727 fid.volatile_fid, buf);
2728 buf->f_type = SMB2_MAGIC_NUMBER;
2729 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2734 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2736 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2737 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2741 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2742 __u64 length, __u32 type, int lock, int unlock, bool wait)
2744 if (unlock && !lock)
2745 type = SMB2_LOCKFLAG_UNLOCK;
2746 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2747 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2748 current->tgid, length, offset, type, wait);
2752 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2754 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2758 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2760 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2764 smb2_new_lease_key(struct cifs_fid *fid)
2766 generate_random_uuid(fid->lease_key);
2770 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2771 const char *search_name,
2772 struct dfs_info3_param **target_nodes,
2773 unsigned int *num_of_nodes,
2774 const struct nls_table *nls_codepage, int remap)
2777 __le16 *utf16_path = NULL;
2778 int utf16_path_len = 0;
2779 struct cifs_tcon *tcon;
2780 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2781 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2782 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2784 cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name);
2787 * Try to use the IPC tcon, otherwise just use any
2789 tcon = ses->tcon_ipc;
2791 spin_lock(&cifs_tcp_ses_lock);
2792 tcon = list_first_entry_or_null(&ses->tcon_list,
2797 spin_unlock(&cifs_tcp_ses_lock);
2801 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2807 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2809 nls_codepage, remap);
2815 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2816 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2822 /* Highest DFS referral version understood */
2823 dfs_req->MaxReferralLevel = DFS_VERSION;
2825 /* Path to resolve in an UTF-16 null-terminated string */
2826 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2829 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2830 FSCTL_DFS_GET_REFERRALS,
2831 true /* is_fsctl */,
2832 (char *)dfs_req, dfs_req_size, CIFSMaxBufSize,
2833 (char **)&dfs_rsp, &dfs_rsp_size);
2834 } while (rc == -EAGAIN);
2837 if ((rc != -ENOENT) && (rc != -EOPNOTSUPP))
2838 cifs_tcon_dbg(VFS, "ioctl error in %s rc=%d\n", __func__, rc);
2842 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
2843 num_of_nodes, target_nodes,
2844 nls_codepage, remap, search_name,
2845 true /* is_unicode */);
2847 cifs_tcon_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc);
2852 if (tcon && !tcon->ipc) {
2853 /* ipc tcons are not refcounted */
2854 spin_lock(&cifs_tcp_ses_lock);
2856 spin_unlock(&cifs_tcp_ses_lock);
2865 parse_reparse_posix(struct reparse_posix_data *symlink_buf,
2866 u32 plen, char **target_path,
2867 struct cifs_sb_info *cifs_sb)
2871 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
2872 len = le16_to_cpu(symlink_buf->ReparseDataLength);
2874 if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
2875 cifs_dbg(VFS, "%lld not a supported symlink type\n",
2876 le64_to_cpu(symlink_buf->InodeType));
2880 *target_path = cifs_strndup_from_utf16(
2881 symlink_buf->PathBuffer,
2882 len, true, cifs_sb->local_nls);
2883 if (!(*target_path))
2886 convert_delimiter(*target_path, '/');
2887 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2893 parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
2894 u32 plen, char **target_path,
2895 struct cifs_sb_info *cifs_sb)
2897 unsigned int sub_len;
2898 unsigned int sub_offset;
2900 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */
2902 sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset);
2903 sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength);
2904 if (sub_offset + 20 > plen ||
2905 sub_offset + sub_len + 20 > plen) {
2906 cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
2910 *target_path = cifs_strndup_from_utf16(
2911 symlink_buf->PathBuffer + sub_offset,
2912 sub_len, true, cifs_sb->local_nls);
2913 if (!(*target_path))
2916 convert_delimiter(*target_path, '/');
2917 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2923 parse_reparse_point(struct reparse_data_buffer *buf,
2924 u32 plen, char **target_path,
2925 struct cifs_sb_info *cifs_sb)
2927 if (plen < sizeof(struct reparse_data_buffer)) {
2928 cifs_dbg(VFS, "reparse buffer is too small. Must be at least 8 bytes but was %d\n",
2933 if (plen < le16_to_cpu(buf->ReparseDataLength) +
2934 sizeof(struct reparse_data_buffer)) {
2935 cifs_dbg(VFS, "srv returned invalid reparse buf length: %d\n",
2940 /* See MS-FSCC 2.1.2 */
2941 switch (le32_to_cpu(buf->ReparseTag)) {
2942 case IO_REPARSE_TAG_NFS:
2943 return parse_reparse_posix(
2944 (struct reparse_posix_data *)buf,
2945 plen, target_path, cifs_sb);
2946 case IO_REPARSE_TAG_SYMLINK:
2947 return parse_reparse_symlink(
2948 (struct reparse_symlink_data_buffer *)buf,
2949 plen, target_path, cifs_sb);
2951 cifs_dbg(VFS, "srv returned unknown symlink buffer tag:0x%08x\n",
2952 le32_to_cpu(buf->ReparseTag));
2957 #define SMB2_SYMLINK_STRUCT_SIZE \
2958 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
2961 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
2962 struct cifs_sb_info *cifs_sb, const char *full_path,
2963 char **target_path, bool is_reparse_point)
2966 __le16 *utf16_path = NULL;
2967 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2968 struct cifs_open_parms oparms;
2969 struct cifs_fid fid;
2970 struct kvec err_iov = {NULL, 0};
2971 struct smb2_err_rsp *err_buf = NULL;
2972 struct smb2_symlink_err_rsp *symlink;
2973 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2974 unsigned int sub_len;
2975 unsigned int sub_offset;
2976 unsigned int print_len;
2977 unsigned int print_offset;
2979 struct smb_rqst rqst[3];
2980 int resp_buftype[3];
2981 struct kvec rsp_iov[3];
2982 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2983 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2984 struct kvec close_iov[1];
2985 struct smb2_create_rsp *create_rsp;
2986 struct smb2_ioctl_rsp *ioctl_rsp;
2987 struct reparse_data_buffer *reparse_buf;
2988 int create_options = is_reparse_point ? OPEN_REPARSE_POINT : 0;
2991 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2993 *target_path = NULL;
2995 if (smb3_encryption_required(tcon))
2996 flags |= CIFS_TRANSFORM_REQ;
2998 memset(rqst, 0, sizeof(rqst));
2999 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
3000 memset(rsp_iov, 0, sizeof(rsp_iov));
3002 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
3007 memset(&open_iov, 0, sizeof(open_iov));
3008 rqst[0].rq_iov = open_iov;
3009 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
3011 memset(&oparms, 0, sizeof(oparms));
3013 oparms.desired_access = FILE_READ_ATTRIBUTES;
3014 oparms.disposition = FILE_OPEN;
3015 oparms.create_options = cifs_create_options(cifs_sb, create_options);
3017 oparms.reconnect = false;
3019 rc = SMB2_open_init(tcon, server,
3020 &rqst[0], &oplock, &oparms, utf16_path);
3023 smb2_set_next_command(tcon, &rqst[0]);
3027 memset(&io_iov, 0, sizeof(io_iov));
3028 rqst[1].rq_iov = io_iov;
3029 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3031 rc = SMB2_ioctl_init(tcon, server,
3032 &rqst[1], fid.persistent_fid,
3033 fid.volatile_fid, FSCTL_GET_REPARSE_POINT,
3034 true /* is_fctl */, NULL, 0,
3036 MAX_SMB2_CREATE_RESPONSE_SIZE -
3037 MAX_SMB2_CLOSE_RESPONSE_SIZE);
3041 smb2_set_next_command(tcon, &rqst[1]);
3042 smb2_set_related(&rqst[1]);
3046 memset(&close_iov, 0, sizeof(close_iov));
3047 rqst[2].rq_iov = close_iov;
3048 rqst[2].rq_nvec = 1;
3050 rc = SMB2_close_init(tcon, server,
3051 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3055 smb2_set_related(&rqst[2]);
3057 rc = compound_send_recv(xid, tcon->ses, server,
3059 resp_buftype, rsp_iov);
3061 create_rsp = rsp_iov[0].iov_base;
3062 if (create_rsp && create_rsp->sync_hdr.Status)
3063 err_iov = rsp_iov[0];
3064 ioctl_rsp = rsp_iov[1].iov_base;
3067 * Open was successful and we got an ioctl response.
3069 if ((rc == 0) && (is_reparse_point)) {
3070 /* See MS-FSCC 2.3.23 */
3072 reparse_buf = (struct reparse_data_buffer *)
3073 ((char *)ioctl_rsp +
3074 le32_to_cpu(ioctl_rsp->OutputOffset));
3075 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3077 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3078 rsp_iov[1].iov_len) {
3079 cifs_tcon_dbg(VFS, "srv returned invalid ioctl len: %d\n",
3085 rc = parse_reparse_point(reparse_buf, plen, target_path,
3090 if (!rc || !err_iov.iov_base) {
3095 err_buf = err_iov.iov_base;
3096 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
3097 err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) {
3102 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
3103 if (le32_to_cpu(symlink->SymLinkErrorTag) != SYMLINK_ERROR_TAG ||
3104 le32_to_cpu(symlink->ReparseTag) != IO_REPARSE_TAG_SYMLINK) {
3109 /* open must fail on symlink - reset rc */
3111 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
3112 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
3113 print_len = le16_to_cpu(symlink->PrintNameLength);
3114 print_offset = le16_to_cpu(symlink->PrintNameOffset);
3116 if (err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
3121 if (err_iov.iov_len <
3122 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
3127 *target_path = cifs_strndup_from_utf16(
3128 (char *)symlink->PathBuffer + sub_offset,
3129 sub_len, true, cifs_sb->local_nls);
3130 if (!(*target_path)) {
3134 convert_delimiter(*target_path, '/');
3135 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
3138 cifs_dbg(FYI, "query symlink rc %d\n", rc);
3140 SMB2_open_free(&rqst[0]);
3141 SMB2_ioctl_free(&rqst[1]);
3142 SMB2_close_free(&rqst[2]);
3143 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3144 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3145 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3150 smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
3151 struct cifs_sb_info *cifs_sb, const char *full_path,
3155 __le16 *utf16_path = NULL;
3156 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3157 struct cifs_open_parms oparms;
3158 struct cifs_fid fid;
3159 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
3161 struct smb_rqst rqst[3];
3162 int resp_buftype[3];
3163 struct kvec rsp_iov[3];
3164 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
3165 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
3166 struct kvec close_iov[1];
3167 struct smb2_ioctl_rsp *ioctl_rsp;
3168 struct reparse_data_buffer *reparse_buf;
3171 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
3173 if (smb3_encryption_required(tcon))
3174 flags |= CIFS_TRANSFORM_REQ;
3176 memset(rqst, 0, sizeof(rqst));
3177 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
3178 memset(rsp_iov, 0, sizeof(rsp_iov));
3180 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
3185 * setup smb2open - TODO add optimization to call cifs_get_readable_path
3186 * to see if there is a handle already open that we can use
3188 memset(&open_iov, 0, sizeof(open_iov));
3189 rqst[0].rq_iov = open_iov;
3190 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
3192 memset(&oparms, 0, sizeof(oparms));
3194 oparms.desired_access = FILE_READ_ATTRIBUTES;
3195 oparms.disposition = FILE_OPEN;
3196 oparms.create_options = cifs_create_options(cifs_sb, OPEN_REPARSE_POINT);
3198 oparms.reconnect = false;
3200 rc = SMB2_open_init(tcon, server,
3201 &rqst[0], &oplock, &oparms, utf16_path);
3204 smb2_set_next_command(tcon, &rqst[0]);
3208 memset(&io_iov, 0, sizeof(io_iov));
3209 rqst[1].rq_iov = io_iov;
3210 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3212 rc = SMB2_ioctl_init(tcon, server,
3213 &rqst[1], COMPOUND_FID,
3214 COMPOUND_FID, FSCTL_GET_REPARSE_POINT,
3215 true /* is_fctl */, NULL, 0,
3217 MAX_SMB2_CREATE_RESPONSE_SIZE -
3218 MAX_SMB2_CLOSE_RESPONSE_SIZE);
3222 smb2_set_next_command(tcon, &rqst[1]);
3223 smb2_set_related(&rqst[1]);
3227 memset(&close_iov, 0, sizeof(close_iov));
3228 rqst[2].rq_iov = close_iov;
3229 rqst[2].rq_nvec = 1;
3231 rc = SMB2_close_init(tcon, server,
3232 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3236 smb2_set_related(&rqst[2]);
3238 rc = compound_send_recv(xid, tcon->ses, server,
3240 resp_buftype, rsp_iov);
3242 ioctl_rsp = rsp_iov[1].iov_base;
3245 * Open was successful and we got an ioctl response.
3248 /* See MS-FSCC 2.3.23 */
3250 reparse_buf = (struct reparse_data_buffer *)
3251 ((char *)ioctl_rsp +
3252 le32_to_cpu(ioctl_rsp->OutputOffset));
3253 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3255 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3256 rsp_iov[1].iov_len) {
3257 cifs_tcon_dbg(FYI, "srv returned invalid ioctl len: %d\n",
3262 *tag = le32_to_cpu(reparse_buf->ReparseTag);
3267 SMB2_open_free(&rqst[0]);
3268 SMB2_ioctl_free(&rqst[1]);
3269 SMB2_close_free(&rqst[2]);
3270 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3271 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3272 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3276 static struct cifs_ntsd *
3277 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
3278 const struct cifs_fid *cifsfid, u32 *pacllen, u32 info)
3280 struct cifs_ntsd *pntsd = NULL;
3282 int rc = -EOPNOTSUPP;
3283 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3286 return ERR_CAST(tlink);
3289 cifs_dbg(FYI, "trying to get acl\n");
3291 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
3292 cifsfid->volatile_fid, (void **)&pntsd, pacllen,
3296 cifs_put_tlink(tlink);
3298 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3305 static struct cifs_ntsd *
3306 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
3307 const char *path, u32 *pacllen, u32 info)
3309 struct cifs_ntsd *pntsd = NULL;
3310 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3313 struct cifs_tcon *tcon;
3314 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3315 struct cifs_fid fid;
3316 struct cifs_open_parms oparms;
3319 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
3321 return ERR_CAST(tlink);
3323 tcon = tlink_tcon(tlink);
3326 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3334 oparms.desired_access = READ_CONTROL;
3335 oparms.disposition = FILE_OPEN;
3337 * When querying an ACL, even if the file is a symlink we want to open
3338 * the source not the target, and so the protocol requires that the
3339 * client specify this flag when opening a reparse point
3341 oparms.create_options = cifs_create_options(cifs_sb, 0) | OPEN_REPARSE_POINT;
3343 oparms.reconnect = false;
3345 if (info & SACL_SECINFO)
3346 oparms.desired_access |= SYSTEM_SECURITY;
3348 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
3352 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3353 fid.volatile_fid, (void **)&pntsd, pacllen,
3355 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3358 cifs_put_tlink(tlink);
3361 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3368 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
3369 struct inode *inode, const char *path, int aclflag)
3371 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3373 int rc, access_flags = 0;
3374 struct cifs_tcon *tcon;
3375 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
3376 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3377 struct cifs_fid fid;
3378 struct cifs_open_parms oparms;
3381 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
3383 return PTR_ERR(tlink);
3385 tcon = tlink_tcon(tlink);
3388 if (aclflag & CIFS_ACL_OWNER || aclflag & CIFS_ACL_GROUP)
3389 access_flags |= WRITE_OWNER;
3390 if (aclflag & CIFS_ACL_SACL)
3391 access_flags |= SYSTEM_SECURITY;
3392 if (aclflag & CIFS_ACL_DACL)
3393 access_flags |= WRITE_DAC;
3395 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3403 oparms.desired_access = access_flags;
3404 oparms.create_options = cifs_create_options(cifs_sb, 0);
3405 oparms.disposition = FILE_OPEN;
3408 oparms.reconnect = false;
3410 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
3414 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3415 fid.volatile_fid, pnntsd, acllen, aclflag);
3416 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3419 cifs_put_tlink(tlink);
3424 /* Retrieve an ACL from the server */
3425 static struct cifs_ntsd *
3426 get_smb2_acl(struct cifs_sb_info *cifs_sb,
3427 struct inode *inode, const char *path,
3428 u32 *pacllen, u32 info)
3430 struct cifs_ntsd *pntsd = NULL;
3431 struct cifsFileInfo *open_file = NULL;
3433 if (inode && !(info & SACL_SECINFO))
3434 open_file = find_readable_file(CIFS_I(inode), true);
3435 if (!open_file || (info & SACL_SECINFO))
3436 return get_smb2_acl_by_path(cifs_sb, path, pacllen, info);
3438 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen, info);
3439 cifsFileInfo_put(open_file);
3443 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3444 loff_t offset, loff_t len, bool keep_size)
3446 struct cifs_ses *ses = tcon->ses;
3447 struct inode *inode;
3448 struct cifsInodeInfo *cifsi;
3449 struct cifsFileInfo *cfile = file->private_data;
3450 struct file_zero_data_information fsctl_buf;
3457 inode = d_inode(cfile->dentry);
3458 cifsi = CIFS_I(inode);
3460 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3461 ses->Suid, offset, len);
3464 * We zero the range through ioctl, so we need remove the page caches
3465 * first, otherwise the data may be inconsistent with the server.
3467 truncate_pagecache_range(inode, offset, offset + len - 1);
3469 /* if file not oplocked can't be sure whether asking to extend size */
3470 if (!CIFS_CACHE_READ(cifsi))
3471 if (keep_size == false) {
3473 trace_smb3_zero_err(xid, cfile->fid.persistent_fid,
3474 tcon->tid, ses->Suid, offset, len, rc);
3479 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3481 fsctl_buf.FileOffset = cpu_to_le64(offset);
3482 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3484 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3485 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, true,
3487 sizeof(struct file_zero_data_information),
3490 goto zero_range_exit;
3493 * do we also need to change the size of the file?
3495 if (keep_size == false && i_size_read(inode) < offset + len) {
3496 eof = cpu_to_le64(offset + len);
3497 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3498 cfile->fid.volatile_fid, cfile->pid, &eof);
3504 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
3505 ses->Suid, offset, len, rc);
3507 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
3508 ses->Suid, offset, len);
3512 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
3513 loff_t offset, loff_t len)
3515 struct inode *inode;
3516 struct cifsFileInfo *cfile = file->private_data;
3517 struct file_zero_data_information fsctl_buf;
3520 __u8 set_sparse = 1;
3524 inode = d_inode(cfile->dentry);
3526 /* Need to make file sparse, if not already, before freeing range. */
3527 /* Consider adding equivalent for compressed since it could also work */
3528 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
3535 * We implement the punch hole through ioctl, so we need remove the page
3536 * caches first, otherwise the data may be inconsistent with the server.
3538 truncate_pagecache_range(inode, offset, offset + len - 1);
3540 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3542 fsctl_buf.FileOffset = cpu_to_le64(offset);
3543 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3545 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3546 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3547 true /* is_fctl */, (char *)&fsctl_buf,
3548 sizeof(struct file_zero_data_information),
3549 CIFSMaxBufSize, NULL, NULL);
3554 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3555 loff_t off, loff_t len, bool keep_size)
3557 struct inode *inode;
3558 struct cifsInodeInfo *cifsi;
3559 struct cifsFileInfo *cfile = file->private_data;
3560 long rc = -EOPNOTSUPP;
3566 inode = d_inode(cfile->dentry);
3567 cifsi = CIFS_I(inode);
3569 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3570 tcon->ses->Suid, off, len);
3571 /* if file not oplocked can't be sure whether asking to extend size */
3572 if (!CIFS_CACHE_READ(cifsi))
3573 if (keep_size == false) {
3574 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3575 tcon->tid, tcon->ses->Suid, off, len, rc);
3581 * Extending the file
3583 if ((keep_size == false) && i_size_read(inode) < off + len) {
3584 rc = inode_newsize_ok(inode, off + len);
3588 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0)
3589 smb2_set_sparse(xid, tcon, cfile, inode, false);
3591 eof = cpu_to_le64(off + len);
3592 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3593 cfile->fid.volatile_fid, cfile->pid, &eof);
3595 cifsi->server_eof = off + len;
3596 cifs_setsize(inode, off + len);
3597 cifs_truncate_page(inode->i_mapping, inode->i_size);
3598 truncate_setsize(inode, off + len);
3604 * Files are non-sparse by default so falloc may be a no-op
3605 * Must check if file sparse. If not sparse, and since we are not
3606 * extending then no need to do anything since file already allocated
3608 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
3613 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3615 * Check if falloc starts within first few pages of file
3616 * and ends within a few pages of the end of file to
3617 * ensure that most of file is being forced to be
3618 * fallocated now. If so then setting whole file sparse
3619 * ie potentially making a few extra pages at the beginning
3620 * or end of the file non-sparse via set_sparse is harmless.
3622 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
3628 smb2_set_sparse(xid, tcon, cfile, inode, false);
3633 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3634 tcon->ses->Suid, off, len, rc);
3636 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3637 tcon->ses->Suid, off, len);
3643 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3645 struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3646 struct cifsInodeInfo *cifsi;
3647 struct inode *inode;
3649 struct file_allocated_range_buffer in_data, *out_data = NULL;
3653 if (whence != SEEK_HOLE && whence != SEEK_DATA)
3654 return generic_file_llseek(file, offset, whence);
3656 inode = d_inode(cfile->dentry);
3657 cifsi = CIFS_I(inode);
3659 if (offset < 0 || offset >= i_size_read(inode))
3664 * We need to be sure that all dirty pages are written as they
3665 * might fill holes on the server.
3666 * Note that we also MUST flush any written pages since at least
3667 * some servers (Windows2016) will not reflect recent writes in
3668 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3670 wrcfile = find_writable_file(cifsi, FIND_WR_ANY);
3672 filemap_write_and_wait(inode->i_mapping);
3673 smb2_flush_file(xid, tcon, &wrcfile->fid);
3674 cifsFileInfo_put(wrcfile);
3677 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3678 if (whence == SEEK_HOLE)
3679 offset = i_size_read(inode);
3683 in_data.file_offset = cpu_to_le64(offset);
3684 in_data.length = cpu_to_le64(i_size_read(inode));
3686 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3687 cfile->fid.volatile_fid,
3688 FSCTL_QUERY_ALLOCATED_RANGES, true,
3689 (char *)&in_data, sizeof(in_data),
3690 sizeof(struct file_allocated_range_buffer),
3691 (char **)&out_data, &out_data_len);
3697 if (whence == SEEK_HOLE && out_data_len == 0)
3700 if (whence == SEEK_DATA && out_data_len == 0) {
3705 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3709 if (whence == SEEK_DATA) {
3710 offset = le64_to_cpu(out_data->file_offset);
3713 if (offset < le64_to_cpu(out_data->file_offset))
3716 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3722 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3727 static int smb3_fiemap(struct cifs_tcon *tcon,
3728 struct cifsFileInfo *cfile,
3729 struct fiemap_extent_info *fei, u64 start, u64 len)
3732 struct file_allocated_range_buffer in_data, *out_data;
3734 int i, num, rc, flags, last_blob;
3737 rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0);
3743 in_data.file_offset = cpu_to_le64(start);
3744 in_data.length = cpu_to_le64(len);
3746 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3747 cfile->fid.volatile_fid,
3748 FSCTL_QUERY_ALLOCATED_RANGES, true,
3749 (char *)&in_data, sizeof(in_data),
3750 1024 * sizeof(struct file_allocated_range_buffer),
3751 (char **)&out_data, &out_data_len);
3760 if (out_data_len && out_data_len < sizeof(struct file_allocated_range_buffer)) {
3764 if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3769 num = out_data_len / sizeof(struct file_allocated_range_buffer);
3770 for (i = 0; i < num; i++) {
3772 if (i == num - 1 && last_blob)
3773 flags |= FIEMAP_EXTENT_LAST;
3775 rc = fiemap_fill_next_extent(fei,
3776 le64_to_cpu(out_data[i].file_offset),
3777 le64_to_cpu(out_data[i].file_offset),
3778 le64_to_cpu(out_data[i].length),
3789 next = le64_to_cpu(out_data[num - 1].file_offset) +
3790 le64_to_cpu(out_data[num - 1].length);
3791 len = len - (next - start);
3802 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
3803 loff_t off, loff_t len)
3805 /* KEEP_SIZE already checked for by do_fallocate */
3806 if (mode & FALLOC_FL_PUNCH_HOLE)
3807 return smb3_punch_hole(file, tcon, off, len);
3808 else if (mode & FALLOC_FL_ZERO_RANGE) {
3809 if (mode & FALLOC_FL_KEEP_SIZE)
3810 return smb3_zero_range(file, tcon, off, len, true);
3811 return smb3_zero_range(file, tcon, off, len, false);
3812 } else if (mode == FALLOC_FL_KEEP_SIZE)
3813 return smb3_simple_falloc(file, tcon, off, len, true);
3815 return smb3_simple_falloc(file, tcon, off, len, false);
3821 smb2_downgrade_oplock(struct TCP_Server_Info *server,
3822 struct cifsInodeInfo *cinode, __u32 oplock,
3823 unsigned int epoch, bool *purge_cache)
3825 server->ops->set_oplock_level(cinode, oplock, 0, NULL);
3829 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3830 unsigned int epoch, bool *purge_cache);
3833 smb3_downgrade_oplock(struct TCP_Server_Info *server,
3834 struct cifsInodeInfo *cinode, __u32 oplock,
3835 unsigned int epoch, bool *purge_cache)
3837 unsigned int old_state = cinode->oplock;
3838 unsigned int old_epoch = cinode->epoch;
3839 unsigned int new_state;
3841 if (epoch > old_epoch) {
3842 smb21_set_oplock_level(cinode, oplock, 0, NULL);
3843 cinode->epoch = epoch;
3846 new_state = cinode->oplock;
3847 *purge_cache = false;
3849 if ((old_state & CIFS_CACHE_READ_FLG) != 0 &&
3850 (new_state & CIFS_CACHE_READ_FLG) == 0)
3851 *purge_cache = true;
3852 else if (old_state == new_state && (epoch - old_epoch > 1))
3853 *purge_cache = true;
3857 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3858 unsigned int epoch, bool *purge_cache)
3861 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3863 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
3864 cinode->oplock = CIFS_CACHE_RHW_FLG;
3865 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
3866 &cinode->vfs_inode);
3867 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
3868 cinode->oplock = CIFS_CACHE_RW_FLG;
3869 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
3870 &cinode->vfs_inode);
3871 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
3872 cinode->oplock = CIFS_CACHE_READ_FLG;
3873 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
3874 &cinode->vfs_inode);
3880 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3881 unsigned int epoch, bool *purge_cache)
3883 char message[5] = {0};
3884 unsigned int new_oplock = 0;
3887 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3890 /* Check if the server granted an oplock rather than a lease */
3891 if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE)
3892 return smb2_set_oplock_level(cinode, oplock, epoch,
3895 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
3896 new_oplock |= CIFS_CACHE_READ_FLG;
3897 strcat(message, "R");
3899 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
3900 new_oplock |= CIFS_CACHE_HANDLE_FLG;
3901 strcat(message, "H");
3903 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
3904 new_oplock |= CIFS_CACHE_WRITE_FLG;
3905 strcat(message, "W");
3908 strncpy(message, "None", sizeof(message));
3910 cinode->oplock = new_oplock;
3911 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
3912 &cinode->vfs_inode);
3916 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3917 unsigned int epoch, bool *purge_cache)
3919 unsigned int old_oplock = cinode->oplock;
3921 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
3924 *purge_cache = false;
3925 if (old_oplock == CIFS_CACHE_READ_FLG) {
3926 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
3927 (epoch - cinode->epoch > 0))
3928 *purge_cache = true;
3929 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
3930 (epoch - cinode->epoch > 1))
3931 *purge_cache = true;
3932 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
3933 (epoch - cinode->epoch > 1))
3934 *purge_cache = true;
3935 else if (cinode->oplock == 0 &&
3936 (epoch - cinode->epoch > 0))
3937 *purge_cache = true;
3938 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
3939 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
3940 (epoch - cinode->epoch > 0))
3941 *purge_cache = true;
3942 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
3943 (epoch - cinode->epoch > 1))
3944 *purge_cache = true;
3946 cinode->epoch = epoch;
3951 smb2_is_read_op(__u32 oplock)
3953 return oplock == SMB2_OPLOCK_LEVEL_II;
3957 smb21_is_read_op(__u32 oplock)
3959 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
3960 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
3964 map_oplock_to_lease(u8 oplock)
3966 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
3967 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
3968 else if (oplock == SMB2_OPLOCK_LEVEL_II)
3969 return SMB2_LEASE_READ_CACHING;
3970 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
3971 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
3972 SMB2_LEASE_WRITE_CACHING;
3977 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
3979 struct create_lease *buf;
3981 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
3985 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
3986 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
3988 buf->ccontext.DataOffset = cpu_to_le16(offsetof
3989 (struct create_lease, lcontext));
3990 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
3991 buf->ccontext.NameOffset = cpu_to_le16(offsetof
3992 (struct create_lease, Name));
3993 buf->ccontext.NameLength = cpu_to_le16(4);
3994 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4003 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
4005 struct create_lease_v2 *buf;
4007 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
4011 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4012 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4014 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4015 (struct create_lease_v2, lcontext));
4016 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
4017 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4018 (struct create_lease_v2, Name));
4019 buf->ccontext.NameLength = cpu_to_le16(4);
4020 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4029 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4031 struct create_lease *lc = (struct create_lease *)buf;
4033 *epoch = 0; /* not used */
4034 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
4035 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4036 return le32_to_cpu(lc->lcontext.LeaseState);
4040 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4042 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
4044 *epoch = le16_to_cpu(lc->lcontext.Epoch);
4045 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
4046 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4048 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
4049 return le32_to_cpu(lc->lcontext.LeaseState);
4053 smb2_wp_retry_size(struct inode *inode)
4055 return min_t(unsigned int, CIFS_SB(inode->i_sb)->ctx->wsize,
4056 SMB2_MAX_BUFFER_SIZE);
4060 smb2_dir_needs_close(struct cifsFileInfo *cfile)
4062 return !cfile->invalidHandle;
4066 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
4067 struct smb_rqst *old_rq, __le16 cipher_type)
4069 struct smb2_sync_hdr *shdr =
4070 (struct smb2_sync_hdr *)old_rq->rq_iov[0].iov_base;
4072 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
4073 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
4074 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
4075 tr_hdr->Flags = cpu_to_le16(0x01);
4076 if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4077 (cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4078 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4080 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4081 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
4084 /* We can not use the normal sg_set_buf() as we will sometimes pass a
4085 * stack object as buf.
4087 static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
4088 unsigned int buflen)
4092 * VMAP_STACK (at least) puts stack into the vmalloc address space
4094 if (is_vmalloc_addr(buf))
4095 addr = vmalloc_to_page(buf);
4097 addr = virt_to_page(buf);
4098 sg_set_page(sg, addr, buflen, offset_in_page(buf));
4101 /* Assumes the first rqst has a transform header as the first iov.
4103 * rqst[0].rq_iov[0] is transform header
4104 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
4105 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
4107 static struct scatterlist *
4108 init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign)
4110 unsigned int sg_len;
4111 struct scatterlist *sg;
4114 unsigned int idx = 0;
4118 for (i = 0; i < num_rqst; i++)
4119 sg_len += rqst[i].rq_nvec + rqst[i].rq_npages;
4121 sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
4125 sg_init_table(sg, sg_len);
4126 for (i = 0; i < num_rqst; i++) {
4127 for (j = 0; j < rqst[i].rq_nvec; j++) {
4129 * The first rqst has a transform header where the
4130 * first 20 bytes are not part of the encrypted blob
4132 skip = (i == 0) && (j == 0) ? 20 : 0;
4133 smb2_sg_set_buf(&sg[idx++],
4134 rqst[i].rq_iov[j].iov_base + skip,
4135 rqst[i].rq_iov[j].iov_len - skip);
4138 for (j = 0; j < rqst[i].rq_npages; j++) {
4139 unsigned int len, offset;
4141 rqst_page_get_length(&rqst[i], j, &len, &offset);
4142 sg_set_page(&sg[idx++], rqst[i].rq_pages[j], len, offset);
4145 smb2_sg_set_buf(&sg[idx], sign, SMB2_SIGNATURE_SIZE);
4150 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
4152 struct cifs_ses *ses;
4155 spin_lock(&cifs_tcp_ses_lock);
4156 list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
4157 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
4158 if (ses->Suid == ses_id) {
4159 ses_enc_key = enc ? ses->smb3encryptionkey :
4160 ses->smb3decryptionkey;
4161 memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE);
4162 spin_unlock(&cifs_tcp_ses_lock);
4167 spin_unlock(&cifs_tcp_ses_lock);
4172 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
4173 * iov[0] - transform header (associate data),
4174 * iov[1-N] - SMB2 header and pages - data to encrypt.
4175 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4179 crypt_message(struct TCP_Server_Info *server, int num_rqst,
4180 struct smb_rqst *rqst, int enc)
4182 struct smb2_transform_hdr *tr_hdr =
4183 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
4184 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
4186 struct scatterlist *sg;
4187 u8 sign[SMB2_SIGNATURE_SIZE] = {};
4188 u8 key[SMB3_SIGN_KEY_SIZE];
4189 struct aead_request *req;
4191 unsigned int iv_len;
4192 DECLARE_CRYPTO_WAIT(wait);
4193 struct crypto_aead *tfm;
4194 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4196 rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key);
4198 cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
4203 rc = smb3_crypto_aead_allocate(server);
4205 cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
4209 tfm = enc ? server->secmech.ccmaesencrypt :
4210 server->secmech.ccmaesdecrypt;
4212 if (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)
4213 rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
4215 rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
4218 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
4222 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
4224 cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
4228 req = aead_request_alloc(tfm, GFP_KERNEL);
4230 cifs_server_dbg(VFS, "%s: Failed to alloc aead request\n", __func__);
4235 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
4236 crypt_len += SMB2_SIGNATURE_SIZE;
4239 sg = init_sg(num_rqst, rqst, sign);
4241 cifs_server_dbg(VFS, "%s: Failed to init sg\n", __func__);
4246 iv_len = crypto_aead_ivsize(tfm);
4247 iv = kzalloc(iv_len, GFP_KERNEL);
4249 cifs_server_dbg(VFS, "%s: Failed to alloc iv\n", __func__);
4254 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4255 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4256 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4259 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4262 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
4263 aead_request_set_ad(req, assoc_data_len);
4265 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
4266 crypto_req_done, &wait);
4268 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
4269 : crypto_aead_decrypt(req), &wait);
4272 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
4283 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
4287 for (i = 0; i < num_rqst; i++) {
4288 if (rqst[i].rq_pages) {
4289 for (j = rqst[i].rq_npages - 1; j >= 0; j--)
4290 put_page(rqst[i].rq_pages[j]);
4291 kfree(rqst[i].rq_pages);
4297 * This function will initialize new_rq and encrypt the content.
4298 * The first entry, new_rq[0], only contains a single iov which contains
4299 * a smb2_transform_hdr and is pre-allocated by the caller.
4300 * This function then populates new_rq[1+] with the content from olq_rq[0+].
4302 * The end result is an array of smb_rqst structures where the first structure
4303 * only contains a single iov for the transform header which we then can pass
4304 * to crypt_message().
4306 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4307 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
4310 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
4311 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
4313 struct page **pages;
4314 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
4315 unsigned int npages;
4316 unsigned int orig_len = 0;
4320 for (i = 1; i < num_rqst; i++) {
4321 npages = old_rq[i - 1].rq_npages;
4322 pages = kmalloc_array(npages, sizeof(struct page *),
4327 new_rq[i].rq_pages = pages;
4328 new_rq[i].rq_npages = npages;
4329 new_rq[i].rq_offset = old_rq[i - 1].rq_offset;
4330 new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz;
4331 new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz;
4332 new_rq[i].rq_iov = old_rq[i - 1].rq_iov;
4333 new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec;
4335 orig_len += smb_rqst_len(server, &old_rq[i - 1]);
4337 for (j = 0; j < npages; j++) {
4338 pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4343 /* copy pages form the old */
4344 for (j = 0; j < npages; j++) {
4346 unsigned int offset, len;
4348 rqst_page_get_length(&new_rq[i], j, &len, &offset);
4350 dst = (char *) kmap(new_rq[i].rq_pages[j]) + offset;
4351 src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset;
4353 memcpy(dst, src, len);
4354 kunmap(new_rq[i].rq_pages[j]);
4355 kunmap(old_rq[i - 1].rq_pages[j]);
4359 /* fill the 1st iov with a transform header */
4360 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
4362 rc = crypt_message(server, num_rqst, new_rq, 1);
4363 cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
4370 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
4375 smb3_is_transform_hdr(void *buf)
4377 struct smb2_transform_hdr *trhdr = buf;
4379 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
4383 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
4384 unsigned int buf_data_size, struct page **pages,
4385 unsigned int npages, unsigned int page_data_size,
4389 struct smb_rqst rqst = {NULL};
4392 iov[0].iov_base = buf;
4393 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
4394 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
4395 iov[1].iov_len = buf_data_size;
4399 rqst.rq_pages = pages;
4400 rqst.rq_npages = npages;
4401 rqst.rq_pagesz = PAGE_SIZE;
4402 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
4404 rc = crypt_message(server, 1, &rqst, 0);
4405 cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
4410 memmove(buf, iov[1].iov_base, buf_data_size);
4413 server->total_read = buf_data_size + page_data_size;
4419 read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
4420 unsigned int npages, unsigned int len)
4425 for (i = 0; i < npages; i++) {
4426 struct page *page = pages[i];
4430 if (len >= PAGE_SIZE) {
4431 /* enough data to fill the page */
4435 zero_user(page, len, PAGE_SIZE - len);
4438 length = cifs_read_page_from_socket(server, page, 0, n);
4441 server->total_read += length;
4448 init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
4449 unsigned int cur_off, struct bio_vec **page_vec)
4451 struct bio_vec *bvec;
4454 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
4458 for (i = 0; i < npages; i++) {
4459 bvec[i].bv_page = pages[i];
4460 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
4461 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
4462 data_size -= bvec[i].bv_len;
4465 if (data_size != 0) {
4466 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
4476 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
4477 char *buf, unsigned int buf_len, struct page **pages,
4478 unsigned int npages, unsigned int page_data_size,
4481 unsigned int data_offset;
4482 unsigned int data_len;
4483 unsigned int cur_off;
4484 unsigned int cur_page_idx;
4485 unsigned int pad_len;
4486 struct cifs_readdata *rdata = mid->callback_data;
4487 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
4488 struct bio_vec *bvec = NULL;
4489 struct iov_iter iter;
4492 bool use_rdma_mr = false;
4494 if (shdr->Command != SMB2_READ) {
4495 cifs_server_dbg(VFS, "only big read responses are supported\n");
4499 if (server->ops->is_session_expired &&
4500 server->ops->is_session_expired(buf)) {
4502 cifs_reconnect(server);
4506 if (server->ops->is_status_pending &&
4507 server->ops->is_status_pending(buf, server))
4510 /* set up first two iov to get credits */
4511 rdata->iov[0].iov_base = buf;
4512 rdata->iov[0].iov_len = 0;
4513 rdata->iov[1].iov_base = buf;
4514 rdata->iov[1].iov_len =
4515 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
4516 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
4517 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
4518 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
4519 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
4521 rdata->result = server->ops->map_error(buf, true);
4522 if (rdata->result != 0) {
4523 cifs_dbg(FYI, "%s: server returned error %d\n",
4524 __func__, rdata->result);
4525 /* normal error on read response */
4527 mid->mid_state = MID_RESPONSE_RECEIVED;
4529 dequeue_mid(mid, false);
4533 data_offset = server->ops->read_data_offset(buf);
4534 #ifdef CONFIG_CIFS_SMB_DIRECT
4535 use_rdma_mr = rdata->mr;
4537 data_len = server->ops->read_data_length(buf, use_rdma_mr);
4539 if (data_offset < server->vals->read_rsp_size) {
4541 * win2k8 sometimes sends an offset of 0 when the read
4542 * is beyond the EOF. Treat it as if the data starts just after
4545 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
4546 __func__, data_offset);
4547 data_offset = server->vals->read_rsp_size;
4548 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
4549 /* data_offset is beyond the end of smallbuf */
4550 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
4551 __func__, data_offset);
4552 rdata->result = -EIO;
4554 mid->mid_state = MID_RESPONSE_MALFORMED;
4556 dequeue_mid(mid, rdata->result);
4560 pad_len = data_offset - server->vals->read_rsp_size;
4562 if (buf_len <= data_offset) {
4563 /* read response payload is in pages */
4564 cur_page_idx = pad_len / PAGE_SIZE;
4565 cur_off = pad_len % PAGE_SIZE;
4567 if (cur_page_idx != 0) {
4568 /* data offset is beyond the 1st page of response */
4569 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
4570 __func__, data_offset);
4571 rdata->result = -EIO;
4573 mid->mid_state = MID_RESPONSE_MALFORMED;
4575 dequeue_mid(mid, rdata->result);
4579 if (data_len > page_data_size - pad_len) {
4580 /* data_len is corrupt -- discard frame */
4581 rdata->result = -EIO;
4583 mid->mid_state = MID_RESPONSE_MALFORMED;
4585 dequeue_mid(mid, rdata->result);
4589 rdata->result = init_read_bvec(pages, npages, page_data_size,
4591 if (rdata->result != 0) {
4593 mid->mid_state = MID_RESPONSE_MALFORMED;
4595 dequeue_mid(mid, rdata->result);
4599 iov_iter_bvec(&iter, WRITE, bvec, npages, data_len);
4600 } else if (buf_len >= data_offset + data_len) {
4601 /* read response payload is in buf */
4602 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
4603 iov.iov_base = buf + data_offset;
4604 iov.iov_len = data_len;
4605 iov_iter_kvec(&iter, WRITE, &iov, 1, data_len);
4607 /* read response payload cannot be in both buf and pages */
4608 WARN_ONCE(1, "buf can not contain only a part of read data");
4609 rdata->result = -EIO;
4611 mid->mid_state = MID_RESPONSE_MALFORMED;
4613 dequeue_mid(mid, rdata->result);
4617 length = rdata->copy_into_pages(server, rdata, &iter);
4625 mid->mid_state = MID_RESPONSE_RECEIVED;
4627 dequeue_mid(mid, false);
4631 struct smb2_decrypt_work {
4632 struct work_struct decrypt;
4633 struct TCP_Server_Info *server;
4634 struct page **ppages;
4636 unsigned int npages;
4641 static void smb2_decrypt_offload(struct work_struct *work)
4643 struct smb2_decrypt_work *dw = container_of(work,
4644 struct smb2_decrypt_work, decrypt);
4646 struct mid_q_entry *mid;
4648 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
4649 dw->ppages, dw->npages, dw->len, true);
4651 cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
4655 dw->server->lstrp = jiffies;
4656 mid = smb2_find_dequeue_mid(dw->server, dw->buf);
4658 cifs_dbg(FYI, "mid not found\n");
4660 mid->decrypted = true;
4661 rc = handle_read_data(dw->server, mid, dw->buf,
4662 dw->server->vals->read_rsp_size,
4663 dw->ppages, dw->npages, dw->len,
4666 #ifdef CONFIG_CIFS_STATS2
4667 mid->when_received = jiffies;
4669 if (dw->server->ops->is_network_name_deleted)
4670 dw->server->ops->is_network_name_deleted(dw->buf,
4675 spin_lock(&GlobalMid_Lock);
4676 if (dw->server->tcpStatus == CifsNeedReconnect) {
4677 mid->mid_state = MID_RETRY_NEEDED;
4678 spin_unlock(&GlobalMid_Lock);
4681 mid->mid_state = MID_REQUEST_SUBMITTED;
4682 mid->mid_flags &= ~(MID_DELETED);
4683 list_add_tail(&mid->qhead,
4684 &dw->server->pending_mid_q);
4685 spin_unlock(&GlobalMid_Lock);
4688 cifs_mid_q_entry_release(mid);
4692 for (i = dw->npages-1; i >= 0; i--)
4693 put_page(dw->ppages[i]);
4696 cifs_small_buf_release(dw->buf);
4702 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
4705 char *buf = server->smallbuf;
4706 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4707 unsigned int npages;
4708 struct page **pages;
4710 unsigned int buflen = server->pdu_size;
4713 struct smb2_decrypt_work *dw;
4716 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
4717 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
4719 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
4722 server->total_read += rc;
4724 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
4725 server->vals->read_rsp_size;
4726 npages = DIV_ROUND_UP(len, PAGE_SIZE);
4728 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
4734 for (; i < npages; i++) {
4735 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4742 /* read read data into pages */
4743 rc = read_data_into_pages(server, pages, npages, len);
4747 rc = cifs_discard_remaining_data(server);
4752 * For large reads, offload to different thread for better performance,
4753 * use more cores decrypting which can be expensive
4756 if ((server->min_offload) && (server->in_flight > 1) &&
4757 (server->pdu_size >= server->min_offload)) {
4758 dw = kmalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL);
4760 goto non_offloaded_decrypt;
4762 dw->buf = server->smallbuf;
4763 server->smallbuf = (char *)cifs_small_buf_get();
4765 INIT_WORK(&dw->decrypt, smb2_decrypt_offload);
4767 dw->npages = npages;
4768 dw->server = server;
4771 queue_work(decrypt_wq, &dw->decrypt);
4772 *num_mids = 0; /* worker thread takes care of finding mid */
4776 non_offloaded_decrypt:
4777 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
4778 pages, npages, len, false);
4782 *mid = smb2_find_mid(server, buf);
4784 cifs_dbg(FYI, "mid not found\n");
4786 cifs_dbg(FYI, "mid found\n");
4787 (*mid)->decrypted = true;
4788 rc = handle_read_data(server, *mid, buf,
4789 server->vals->read_rsp_size,
4790 pages, npages, len, false);
4792 if (server->ops->is_network_name_deleted) {
4793 server->ops->is_network_name_deleted(buf,
4800 for (i = i - 1; i >= 0; i--)
4805 cifs_discard_remaining_data(server);
4810 receive_encrypted_standard(struct TCP_Server_Info *server,
4811 struct mid_q_entry **mids, char **bufs,
4815 char *buf = server->smallbuf;
4816 struct smb2_sync_hdr *shdr;
4817 unsigned int pdu_length = server->pdu_size;
4818 unsigned int buf_size;
4819 struct mid_q_entry *mid_entry;
4821 char *next_buffer = NULL;
4825 /* switch to large buffer if too big for a small one */
4826 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
4827 server->large_buf = true;
4828 memcpy(server->bigbuf, buf, server->total_read);
4829 buf = server->bigbuf;
4832 /* now read the rest */
4833 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
4834 pdu_length - HEADER_SIZE(server) + 1);
4837 server->total_read += length;
4839 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
4840 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0, false);
4844 next_is_large = server->large_buf;
4846 shdr = (struct smb2_sync_hdr *)buf;
4847 if (shdr->NextCommand) {
4849 next_buffer = (char *)cifs_buf_get();
4851 next_buffer = (char *)cifs_small_buf_get();
4853 buf + le32_to_cpu(shdr->NextCommand),
4854 pdu_length - le32_to_cpu(shdr->NextCommand));
4857 mid_entry = smb2_find_mid(server, buf);
4858 if (mid_entry == NULL)
4859 cifs_dbg(FYI, "mid not found\n");
4861 cifs_dbg(FYI, "mid found\n");
4862 mid_entry->decrypted = true;
4863 mid_entry->resp_buf_size = server->pdu_size;
4866 if (*num_mids >= MAX_COMPOUND) {
4867 cifs_server_dbg(VFS, "too many PDUs in compound\n");
4870 bufs[*num_mids] = buf;
4871 mids[(*num_mids)++] = mid_entry;
4873 if (mid_entry && mid_entry->handle)
4874 ret = mid_entry->handle(server, mid_entry);
4876 ret = cifs_handle_standard(server, mid_entry);
4878 if (ret == 0 && shdr->NextCommand) {
4879 pdu_length -= le32_to_cpu(shdr->NextCommand);
4880 server->large_buf = next_is_large;
4882 server->bigbuf = buf = next_buffer;
4884 server->smallbuf = buf = next_buffer;
4886 } else if (ret != 0) {
4888 * ret != 0 here means that we didn't get to handle_mid() thus
4889 * server->smallbuf and server->bigbuf are still valid. We need
4890 * to free next_buffer because it is not going to be used
4894 free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer);
4896 free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer);
4903 smb3_receive_transform(struct TCP_Server_Info *server,
4904 struct mid_q_entry **mids, char **bufs, int *num_mids)
4906 char *buf = server->smallbuf;
4907 unsigned int pdu_length = server->pdu_size;
4908 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4909 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4911 if (pdu_length < sizeof(struct smb2_transform_hdr) +
4912 sizeof(struct smb2_sync_hdr)) {
4913 cifs_server_dbg(VFS, "Transform message is too small (%u)\n",
4915 cifs_reconnect(server);
4916 return -ECONNABORTED;
4919 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
4920 cifs_server_dbg(VFS, "Transform message is broken\n");
4921 cifs_reconnect(server);
4922 return -ECONNABORTED;
4925 /* TODO: add support for compounds containing READ. */
4926 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
4927 return receive_encrypted_read(server, &mids[0], num_mids);
4930 return receive_encrypted_standard(server, mids, bufs, num_mids);
4934 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
4936 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
4938 return handle_read_data(server, mid, buf, server->pdu_size,
4943 smb2_next_header(char *buf)
4945 struct smb2_sync_hdr *hdr = (struct smb2_sync_hdr *)buf;
4946 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
4948 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
4949 return sizeof(struct smb2_transform_hdr) +
4950 le32_to_cpu(t_hdr->OriginalMessageSize);
4952 return le32_to_cpu(hdr->NextCommand);
4956 smb2_make_node(unsigned int xid, struct inode *inode,
4957 struct dentry *dentry, struct cifs_tcon *tcon,
4958 char *full_path, umode_t mode, dev_t dev)
4960 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
4962 FILE_ALL_INFO *buf = NULL;
4963 struct cifs_io_parms io_parms = {0};
4965 struct cifs_fid fid;
4966 struct cifs_open_parms oparms;
4967 unsigned int bytes_written;
4968 struct win_dev *pdev;
4972 * Check if mounted with mount parm 'sfu' mount parm.
4973 * SFU emulation should work with all servers, but only
4974 * supports block and char device (no socket & fifo),
4975 * and was used by default in earlier versions of Windows
4977 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
4981 * TODO: Add ability to create instead via reparse point. Windows (e.g.
4982 * their current NFS server) uses this approach to expose special files
4983 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
4986 if (!S_ISCHR(mode) && !S_ISBLK(mode))
4989 cifs_dbg(FYI, "sfu compat create special file\n");
4991 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
4998 oparms.cifs_sb = cifs_sb;
4999 oparms.desired_access = GENERIC_WRITE;
5000 oparms.create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR |
5001 CREATE_OPTION_SPECIAL);
5002 oparms.disposition = FILE_CREATE;
5003 oparms.path = full_path;
5005 oparms.reconnect = false;
5007 if (tcon->ses->server->oplocks)
5008 oplock = REQ_OPLOCK;
5011 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf);
5016 * BB Do not bother to decode buf since no local inode yet to put
5017 * timestamps in, but we can reuse it safely.
5020 pdev = (struct win_dev *)buf;
5021 io_parms.pid = current->tgid;
5022 io_parms.tcon = tcon;
5023 io_parms.offset = 0;
5024 io_parms.length = sizeof(struct win_dev);
5025 iov[1].iov_base = buf;
5026 iov[1].iov_len = sizeof(struct win_dev);
5027 if (S_ISCHR(mode)) {
5028 memcpy(pdev->type, "IntxCHR", 8);
5029 pdev->major = cpu_to_le64(MAJOR(dev));
5030 pdev->minor = cpu_to_le64(MINOR(dev));
5031 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5032 &bytes_written, iov, 1);
5033 } else if (S_ISBLK(mode)) {
5034 memcpy(pdev->type, "IntxBLK", 8);
5035 pdev->major = cpu_to_le64(MAJOR(dev));
5036 pdev->minor = cpu_to_le64(MINOR(dev));
5037 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5038 &bytes_written, iov, 1);
5040 tcon->ses->server->ops->close(xid, tcon, &fid);
5043 /* FIXME: add code here to set EAs */
5050 struct smb_version_operations smb20_operations = {
5051 .compare_fids = smb2_compare_fids,
5052 .setup_request = smb2_setup_request,
5053 .setup_async_request = smb2_setup_async_request,
5054 .check_receive = smb2_check_receive,
5055 .add_credits = smb2_add_credits,
5056 .set_credits = smb2_set_credits,
5057 .get_credits_field = smb2_get_credits_field,
5058 .get_credits = smb2_get_credits,
5059 .wait_mtu_credits = cifs_wait_mtu_credits,
5060 .get_next_mid = smb2_get_next_mid,
5061 .revert_current_mid = smb2_revert_current_mid,
5062 .read_data_offset = smb2_read_data_offset,
5063 .read_data_length = smb2_read_data_length,
5064 .map_error = map_smb2_to_linux_error,
5065 .find_mid = smb2_find_mid,
5066 .check_message = smb2_check_message,
5067 .dump_detail = smb2_dump_detail,
5068 .clear_stats = smb2_clear_stats,
5069 .print_stats = smb2_print_stats,
5070 .is_oplock_break = smb2_is_valid_oplock_break,
5071 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5072 .downgrade_oplock = smb2_downgrade_oplock,
5073 .need_neg = smb2_need_neg,
5074 .negotiate = smb2_negotiate,
5075 .negotiate_wsize = smb2_negotiate_wsize,
5076 .negotiate_rsize = smb2_negotiate_rsize,
5077 .sess_setup = SMB2_sess_setup,
5078 .logoff = SMB2_logoff,
5079 .tree_connect = SMB2_tcon,
5080 .tree_disconnect = SMB2_tdis,
5081 .qfs_tcon = smb2_qfs_tcon,
5082 .is_path_accessible = smb2_is_path_accessible,
5083 .can_echo = smb2_can_echo,
5085 .query_path_info = smb2_query_path_info,
5086 .get_srv_inum = smb2_get_srv_inum,
5087 .query_file_info = smb2_query_file_info,
5088 .set_path_size = smb2_set_path_size,
5089 .set_file_size = smb2_set_file_size,
5090 .set_file_info = smb2_set_file_info,
5091 .set_compression = smb2_set_compression,
5092 .mkdir = smb2_mkdir,
5093 .mkdir_setinfo = smb2_mkdir_setinfo,
5094 .rmdir = smb2_rmdir,
5095 .unlink = smb2_unlink,
5096 .rename = smb2_rename_path,
5097 .create_hardlink = smb2_create_hardlink,
5098 .query_symlink = smb2_query_symlink,
5099 .query_mf_symlink = smb3_query_mf_symlink,
5100 .create_mf_symlink = smb3_create_mf_symlink,
5101 .open = smb2_open_file,
5102 .set_fid = smb2_set_fid,
5103 .close = smb2_close_file,
5104 .flush = smb2_flush_file,
5105 .async_readv = smb2_async_readv,
5106 .async_writev = smb2_async_writev,
5107 .sync_read = smb2_sync_read,
5108 .sync_write = smb2_sync_write,
5109 .query_dir_first = smb2_query_dir_first,
5110 .query_dir_next = smb2_query_dir_next,
5111 .close_dir = smb2_close_dir,
5112 .calc_smb_size = smb2_calc_size,
5113 .is_status_pending = smb2_is_status_pending,
5114 .is_session_expired = smb2_is_session_expired,
5115 .oplock_response = smb2_oplock_response,
5116 .queryfs = smb2_queryfs,
5117 .mand_lock = smb2_mand_lock,
5118 .mand_unlock_range = smb2_unlock_range,
5119 .push_mand_locks = smb2_push_mandatory_locks,
5120 .get_lease_key = smb2_get_lease_key,
5121 .set_lease_key = smb2_set_lease_key,
5122 .new_lease_key = smb2_new_lease_key,
5123 .calc_signature = smb2_calc_signature,
5124 .is_read_op = smb2_is_read_op,
5125 .set_oplock_level = smb2_set_oplock_level,
5126 .create_lease_buf = smb2_create_lease_buf,
5127 .parse_lease_buf = smb2_parse_lease_buf,
5128 .copychunk_range = smb2_copychunk_range,
5129 .wp_retry_size = smb2_wp_retry_size,
5130 .dir_needs_close = smb2_dir_needs_close,
5131 .get_dfs_refer = smb2_get_dfs_refer,
5132 .select_sectype = smb2_select_sectype,
5133 #ifdef CONFIG_CIFS_XATTR
5134 .query_all_EAs = smb2_query_eas,
5135 .set_EA = smb2_set_ea,
5136 #endif /* CIFS_XATTR */
5137 .get_acl = get_smb2_acl,
5138 .get_acl_by_fid = get_smb2_acl_by_fid,
5139 .set_acl = set_smb2_acl,
5140 .next_header = smb2_next_header,
5141 .ioctl_query_info = smb2_ioctl_query_info,
5142 .make_node = smb2_make_node,
5143 .fiemap = smb3_fiemap,
5144 .llseek = smb3_llseek,
5145 .is_status_io_timeout = smb2_is_status_io_timeout,
5146 .is_network_name_deleted = smb2_is_network_name_deleted,
5149 struct smb_version_operations smb21_operations = {
5150 .compare_fids = smb2_compare_fids,
5151 .setup_request = smb2_setup_request,
5152 .setup_async_request = smb2_setup_async_request,
5153 .check_receive = smb2_check_receive,
5154 .add_credits = smb2_add_credits,
5155 .set_credits = smb2_set_credits,
5156 .get_credits_field = smb2_get_credits_field,
5157 .get_credits = smb2_get_credits,
5158 .wait_mtu_credits = smb2_wait_mtu_credits,
5159 .adjust_credits = smb2_adjust_credits,
5160 .get_next_mid = smb2_get_next_mid,
5161 .revert_current_mid = smb2_revert_current_mid,
5162 .read_data_offset = smb2_read_data_offset,
5163 .read_data_length = smb2_read_data_length,
5164 .map_error = map_smb2_to_linux_error,
5165 .find_mid = smb2_find_mid,
5166 .check_message = smb2_check_message,
5167 .dump_detail = smb2_dump_detail,
5168 .clear_stats = smb2_clear_stats,
5169 .print_stats = smb2_print_stats,
5170 .is_oplock_break = smb2_is_valid_oplock_break,
5171 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5172 .downgrade_oplock = smb2_downgrade_oplock,
5173 .need_neg = smb2_need_neg,
5174 .negotiate = smb2_negotiate,
5175 .negotiate_wsize = smb2_negotiate_wsize,
5176 .negotiate_rsize = smb2_negotiate_rsize,
5177 .sess_setup = SMB2_sess_setup,
5178 .logoff = SMB2_logoff,
5179 .tree_connect = SMB2_tcon,
5180 .tree_disconnect = SMB2_tdis,
5181 .qfs_tcon = smb2_qfs_tcon,
5182 .is_path_accessible = smb2_is_path_accessible,
5183 .can_echo = smb2_can_echo,
5185 .query_path_info = smb2_query_path_info,
5186 .get_srv_inum = smb2_get_srv_inum,
5187 .query_file_info = smb2_query_file_info,
5188 .set_path_size = smb2_set_path_size,
5189 .set_file_size = smb2_set_file_size,
5190 .set_file_info = smb2_set_file_info,
5191 .set_compression = smb2_set_compression,
5192 .mkdir = smb2_mkdir,
5193 .mkdir_setinfo = smb2_mkdir_setinfo,
5194 .rmdir = smb2_rmdir,
5195 .unlink = smb2_unlink,
5196 .rename = smb2_rename_path,
5197 .create_hardlink = smb2_create_hardlink,
5198 .query_symlink = smb2_query_symlink,
5199 .query_mf_symlink = smb3_query_mf_symlink,
5200 .create_mf_symlink = smb3_create_mf_symlink,
5201 .open = smb2_open_file,
5202 .set_fid = smb2_set_fid,
5203 .close = smb2_close_file,
5204 .flush = smb2_flush_file,
5205 .async_readv = smb2_async_readv,
5206 .async_writev = smb2_async_writev,
5207 .sync_read = smb2_sync_read,
5208 .sync_write = smb2_sync_write,
5209 .query_dir_first = smb2_query_dir_first,
5210 .query_dir_next = smb2_query_dir_next,
5211 .close_dir = smb2_close_dir,
5212 .calc_smb_size = smb2_calc_size,
5213 .is_status_pending = smb2_is_status_pending,
5214 .is_session_expired = smb2_is_session_expired,
5215 .oplock_response = smb2_oplock_response,
5216 .queryfs = smb2_queryfs,
5217 .mand_lock = smb2_mand_lock,
5218 .mand_unlock_range = smb2_unlock_range,
5219 .push_mand_locks = smb2_push_mandatory_locks,
5220 .get_lease_key = smb2_get_lease_key,
5221 .set_lease_key = smb2_set_lease_key,
5222 .new_lease_key = smb2_new_lease_key,
5223 .calc_signature = smb2_calc_signature,
5224 .is_read_op = smb21_is_read_op,
5225 .set_oplock_level = smb21_set_oplock_level,
5226 .create_lease_buf = smb2_create_lease_buf,
5227 .parse_lease_buf = smb2_parse_lease_buf,
5228 .copychunk_range = smb2_copychunk_range,
5229 .wp_retry_size = smb2_wp_retry_size,
5230 .dir_needs_close = smb2_dir_needs_close,
5231 .enum_snapshots = smb3_enum_snapshots,
5232 .notify = smb3_notify,
5233 .get_dfs_refer = smb2_get_dfs_refer,
5234 .select_sectype = smb2_select_sectype,
5235 #ifdef CONFIG_CIFS_XATTR
5236 .query_all_EAs = smb2_query_eas,
5237 .set_EA = smb2_set_ea,
5238 #endif /* CIFS_XATTR */
5239 .get_acl = get_smb2_acl,
5240 .get_acl_by_fid = get_smb2_acl_by_fid,
5241 .set_acl = set_smb2_acl,
5242 .next_header = smb2_next_header,
5243 .ioctl_query_info = smb2_ioctl_query_info,
5244 .make_node = smb2_make_node,
5245 .fiemap = smb3_fiemap,
5246 .llseek = smb3_llseek,
5247 .is_status_io_timeout = smb2_is_status_io_timeout,
5248 .is_network_name_deleted = smb2_is_network_name_deleted,
5251 struct smb_version_operations smb30_operations = {
5252 .compare_fids = smb2_compare_fids,
5253 .setup_request = smb2_setup_request,
5254 .setup_async_request = smb2_setup_async_request,
5255 .check_receive = smb2_check_receive,
5256 .add_credits = smb2_add_credits,
5257 .set_credits = smb2_set_credits,
5258 .get_credits_field = smb2_get_credits_field,
5259 .get_credits = smb2_get_credits,
5260 .wait_mtu_credits = smb2_wait_mtu_credits,
5261 .adjust_credits = smb2_adjust_credits,
5262 .get_next_mid = smb2_get_next_mid,
5263 .revert_current_mid = smb2_revert_current_mid,
5264 .read_data_offset = smb2_read_data_offset,
5265 .read_data_length = smb2_read_data_length,
5266 .map_error = map_smb2_to_linux_error,
5267 .find_mid = smb2_find_mid,
5268 .check_message = smb2_check_message,
5269 .dump_detail = smb2_dump_detail,
5270 .clear_stats = smb2_clear_stats,
5271 .print_stats = smb2_print_stats,
5272 .dump_share_caps = smb2_dump_share_caps,
5273 .is_oplock_break = smb2_is_valid_oplock_break,
5274 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5275 .downgrade_oplock = smb3_downgrade_oplock,
5276 .need_neg = smb2_need_neg,
5277 .negotiate = smb2_negotiate,
5278 .negotiate_wsize = smb3_negotiate_wsize,
5279 .negotiate_rsize = smb3_negotiate_rsize,
5280 .sess_setup = SMB2_sess_setup,
5281 .logoff = SMB2_logoff,
5282 .tree_connect = SMB2_tcon,
5283 .tree_disconnect = SMB2_tdis,
5284 .qfs_tcon = smb3_qfs_tcon,
5285 .is_path_accessible = smb2_is_path_accessible,
5286 .can_echo = smb2_can_echo,
5288 .query_path_info = smb2_query_path_info,
5289 /* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */
5290 .query_reparse_tag = smb2_query_reparse_tag,
5291 .get_srv_inum = smb2_get_srv_inum,
5292 .query_file_info = smb2_query_file_info,
5293 .set_path_size = smb2_set_path_size,
5294 .set_file_size = smb2_set_file_size,
5295 .set_file_info = smb2_set_file_info,
5296 .set_compression = smb2_set_compression,
5297 .mkdir = smb2_mkdir,
5298 .mkdir_setinfo = smb2_mkdir_setinfo,
5299 .rmdir = smb2_rmdir,
5300 .unlink = smb2_unlink,
5301 .rename = smb2_rename_path,
5302 .create_hardlink = smb2_create_hardlink,
5303 .query_symlink = smb2_query_symlink,
5304 .query_mf_symlink = smb3_query_mf_symlink,
5305 .create_mf_symlink = smb3_create_mf_symlink,
5306 .open = smb2_open_file,
5307 .set_fid = smb2_set_fid,
5308 .close = smb2_close_file,
5309 .close_getattr = smb2_close_getattr,
5310 .flush = smb2_flush_file,
5311 .async_readv = smb2_async_readv,
5312 .async_writev = smb2_async_writev,
5313 .sync_read = smb2_sync_read,
5314 .sync_write = smb2_sync_write,
5315 .query_dir_first = smb2_query_dir_first,
5316 .query_dir_next = smb2_query_dir_next,
5317 .close_dir = smb2_close_dir,
5318 .calc_smb_size = smb2_calc_size,
5319 .is_status_pending = smb2_is_status_pending,
5320 .is_session_expired = smb2_is_session_expired,
5321 .oplock_response = smb2_oplock_response,
5322 .queryfs = smb2_queryfs,
5323 .mand_lock = smb2_mand_lock,
5324 .mand_unlock_range = smb2_unlock_range,
5325 .push_mand_locks = smb2_push_mandatory_locks,
5326 .get_lease_key = smb2_get_lease_key,
5327 .set_lease_key = smb2_set_lease_key,
5328 .new_lease_key = smb2_new_lease_key,
5329 .generate_signingkey = generate_smb30signingkey,
5330 .calc_signature = smb3_calc_signature,
5331 .set_integrity = smb3_set_integrity,
5332 .is_read_op = smb21_is_read_op,
5333 .set_oplock_level = smb3_set_oplock_level,
5334 .create_lease_buf = smb3_create_lease_buf,
5335 .parse_lease_buf = smb3_parse_lease_buf,
5336 .copychunk_range = smb2_copychunk_range,
5337 .duplicate_extents = smb2_duplicate_extents,
5338 .validate_negotiate = smb3_validate_negotiate,
5339 .wp_retry_size = smb2_wp_retry_size,
5340 .dir_needs_close = smb2_dir_needs_close,
5341 .fallocate = smb3_fallocate,
5342 .enum_snapshots = smb3_enum_snapshots,
5343 .notify = smb3_notify,
5344 .init_transform_rq = smb3_init_transform_rq,
5345 .is_transform_hdr = smb3_is_transform_hdr,
5346 .receive_transform = smb3_receive_transform,
5347 .get_dfs_refer = smb2_get_dfs_refer,
5348 .select_sectype = smb2_select_sectype,
5349 #ifdef CONFIG_CIFS_XATTR
5350 .query_all_EAs = smb2_query_eas,
5351 .set_EA = smb2_set_ea,
5352 #endif /* CIFS_XATTR */
5353 .get_acl = get_smb2_acl,
5354 .get_acl_by_fid = get_smb2_acl_by_fid,
5355 .set_acl = set_smb2_acl,
5356 .next_header = smb2_next_header,
5357 .ioctl_query_info = smb2_ioctl_query_info,
5358 .make_node = smb2_make_node,
5359 .fiemap = smb3_fiemap,
5360 .llseek = smb3_llseek,
5361 .is_status_io_timeout = smb2_is_status_io_timeout,
5362 .is_network_name_deleted = smb2_is_network_name_deleted,
5365 struct smb_version_operations smb311_operations = {
5366 .compare_fids = smb2_compare_fids,
5367 .setup_request = smb2_setup_request,
5368 .setup_async_request = smb2_setup_async_request,
5369 .check_receive = smb2_check_receive,
5370 .add_credits = smb2_add_credits,
5371 .set_credits = smb2_set_credits,
5372 .get_credits_field = smb2_get_credits_field,
5373 .get_credits = smb2_get_credits,
5374 .wait_mtu_credits = smb2_wait_mtu_credits,
5375 .adjust_credits = smb2_adjust_credits,
5376 .get_next_mid = smb2_get_next_mid,
5377 .revert_current_mid = smb2_revert_current_mid,
5378 .read_data_offset = smb2_read_data_offset,
5379 .read_data_length = smb2_read_data_length,
5380 .map_error = map_smb2_to_linux_error,
5381 .find_mid = smb2_find_mid,
5382 .check_message = smb2_check_message,
5383 .dump_detail = smb2_dump_detail,
5384 .clear_stats = smb2_clear_stats,
5385 .print_stats = smb2_print_stats,
5386 .dump_share_caps = smb2_dump_share_caps,
5387 .is_oplock_break = smb2_is_valid_oplock_break,
5388 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5389 .downgrade_oplock = smb3_downgrade_oplock,
5390 .need_neg = smb2_need_neg,
5391 .negotiate = smb2_negotiate,
5392 .negotiate_wsize = smb3_negotiate_wsize,
5393 .negotiate_rsize = smb3_negotiate_rsize,
5394 .sess_setup = SMB2_sess_setup,
5395 .logoff = SMB2_logoff,
5396 .tree_connect = SMB2_tcon,
5397 .tree_disconnect = SMB2_tdis,
5398 .qfs_tcon = smb3_qfs_tcon,
5399 .is_path_accessible = smb2_is_path_accessible,
5400 .can_echo = smb2_can_echo,
5402 .query_path_info = smb2_query_path_info,
5403 .query_reparse_tag = smb2_query_reparse_tag,
5404 .get_srv_inum = smb2_get_srv_inum,
5405 .query_file_info = smb2_query_file_info,
5406 .set_path_size = smb2_set_path_size,
5407 .set_file_size = smb2_set_file_size,
5408 .set_file_info = smb2_set_file_info,
5409 .set_compression = smb2_set_compression,
5410 .mkdir = smb2_mkdir,
5411 .mkdir_setinfo = smb2_mkdir_setinfo,
5412 .posix_mkdir = smb311_posix_mkdir,
5413 .rmdir = smb2_rmdir,
5414 .unlink = smb2_unlink,
5415 .rename = smb2_rename_path,
5416 .create_hardlink = smb2_create_hardlink,
5417 .query_symlink = smb2_query_symlink,
5418 .query_mf_symlink = smb3_query_mf_symlink,
5419 .create_mf_symlink = smb3_create_mf_symlink,
5420 .open = smb2_open_file,
5421 .set_fid = smb2_set_fid,
5422 .close = smb2_close_file,
5423 .close_getattr = smb2_close_getattr,
5424 .flush = smb2_flush_file,
5425 .async_readv = smb2_async_readv,
5426 .async_writev = smb2_async_writev,
5427 .sync_read = smb2_sync_read,
5428 .sync_write = smb2_sync_write,
5429 .query_dir_first = smb2_query_dir_first,
5430 .query_dir_next = smb2_query_dir_next,
5431 .close_dir = smb2_close_dir,
5432 .calc_smb_size = smb2_calc_size,
5433 .is_status_pending = smb2_is_status_pending,
5434 .is_session_expired = smb2_is_session_expired,
5435 .oplock_response = smb2_oplock_response,
5436 .queryfs = smb311_queryfs,
5437 .mand_lock = smb2_mand_lock,
5438 .mand_unlock_range = smb2_unlock_range,
5439 .push_mand_locks = smb2_push_mandatory_locks,
5440 .get_lease_key = smb2_get_lease_key,
5441 .set_lease_key = smb2_set_lease_key,
5442 .new_lease_key = smb2_new_lease_key,
5443 .generate_signingkey = generate_smb311signingkey,
5444 .calc_signature = smb3_calc_signature,
5445 .set_integrity = smb3_set_integrity,
5446 .is_read_op = smb21_is_read_op,
5447 .set_oplock_level = smb3_set_oplock_level,
5448 .create_lease_buf = smb3_create_lease_buf,
5449 .parse_lease_buf = smb3_parse_lease_buf,
5450 .copychunk_range = smb2_copychunk_range,
5451 .duplicate_extents = smb2_duplicate_extents,
5452 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
5453 .wp_retry_size = smb2_wp_retry_size,
5454 .dir_needs_close = smb2_dir_needs_close,
5455 .fallocate = smb3_fallocate,
5456 .enum_snapshots = smb3_enum_snapshots,
5457 .notify = smb3_notify,
5458 .init_transform_rq = smb3_init_transform_rq,
5459 .is_transform_hdr = smb3_is_transform_hdr,
5460 .receive_transform = smb3_receive_transform,
5461 .get_dfs_refer = smb2_get_dfs_refer,
5462 .select_sectype = smb2_select_sectype,
5463 #ifdef CONFIG_CIFS_XATTR
5464 .query_all_EAs = smb2_query_eas,
5465 .set_EA = smb2_set_ea,
5466 #endif /* CIFS_XATTR */
5467 .get_acl = get_smb2_acl,
5468 .get_acl_by_fid = get_smb2_acl_by_fid,
5469 .set_acl = set_smb2_acl,
5470 .next_header = smb2_next_header,
5471 .ioctl_query_info = smb2_ioctl_query_info,
5472 .make_node = smb2_make_node,
5473 .fiemap = smb3_fiemap,
5474 .llseek = smb3_llseek,
5475 .is_status_io_timeout = smb2_is_status_io_timeout,
5476 .is_network_name_deleted = smb2_is_network_name_deleted,
5479 struct smb_version_values smb20_values = {
5480 .version_string = SMB20_VERSION_STRING,
5481 .protocol_id = SMB20_PROT_ID,
5482 .req_capabilities = 0, /* MBZ */
5483 .large_lock_type = 0,
5484 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5485 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5486 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5487 .header_size = sizeof(struct smb2_sync_hdr),
5488 .header_preamble_size = 0,
5489 .max_header_size = MAX_SMB2_HDR_SIZE,
5490 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5491 .lock_cmd = SMB2_LOCK,
5493 .cap_nt_find = SMB2_NT_FIND,
5494 .cap_large_files = SMB2_LARGE_FILES,
5495 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5496 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5497 .create_lease_size = sizeof(struct create_lease),
5500 struct smb_version_values smb21_values = {
5501 .version_string = SMB21_VERSION_STRING,
5502 .protocol_id = SMB21_PROT_ID,
5503 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
5504 .large_lock_type = 0,
5505 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5506 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5507 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5508 .header_size = sizeof(struct smb2_sync_hdr),
5509 .header_preamble_size = 0,
5510 .max_header_size = MAX_SMB2_HDR_SIZE,
5511 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5512 .lock_cmd = SMB2_LOCK,
5514 .cap_nt_find = SMB2_NT_FIND,
5515 .cap_large_files = SMB2_LARGE_FILES,
5516 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5517 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5518 .create_lease_size = sizeof(struct create_lease),
5521 struct smb_version_values smb3any_values = {
5522 .version_string = SMB3ANY_VERSION_STRING,
5523 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5524 .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,
5525 .large_lock_type = 0,
5526 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5527 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5528 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5529 .header_size = sizeof(struct smb2_sync_hdr),
5530 .header_preamble_size = 0,
5531 .max_header_size = MAX_SMB2_HDR_SIZE,
5532 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5533 .lock_cmd = SMB2_LOCK,
5535 .cap_nt_find = SMB2_NT_FIND,
5536 .cap_large_files = SMB2_LARGE_FILES,
5537 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5538 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5539 .create_lease_size = sizeof(struct create_lease_v2),
5542 struct smb_version_values smbdefault_values = {
5543 .version_string = SMBDEFAULT_VERSION_STRING,
5544 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5545 .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,
5546 .large_lock_type = 0,
5547 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5548 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5549 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5550 .header_size = sizeof(struct smb2_sync_hdr),
5551 .header_preamble_size = 0,
5552 .max_header_size = MAX_SMB2_HDR_SIZE,
5553 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5554 .lock_cmd = SMB2_LOCK,
5556 .cap_nt_find = SMB2_NT_FIND,
5557 .cap_large_files = SMB2_LARGE_FILES,
5558 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5559 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5560 .create_lease_size = sizeof(struct create_lease_v2),
5563 struct smb_version_values smb30_values = {
5564 .version_string = SMB30_VERSION_STRING,
5565 .protocol_id = SMB30_PROT_ID,
5566 .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,
5567 .large_lock_type = 0,
5568 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5569 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5570 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5571 .header_size = sizeof(struct smb2_sync_hdr),
5572 .header_preamble_size = 0,
5573 .max_header_size = MAX_SMB2_HDR_SIZE,
5574 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5575 .lock_cmd = SMB2_LOCK,
5577 .cap_nt_find = SMB2_NT_FIND,
5578 .cap_large_files = SMB2_LARGE_FILES,
5579 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5580 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5581 .create_lease_size = sizeof(struct create_lease_v2),
5584 struct smb_version_values smb302_values = {
5585 .version_string = SMB302_VERSION_STRING,
5586 .protocol_id = SMB302_PROT_ID,
5587 .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,
5588 .large_lock_type = 0,
5589 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5590 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5591 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5592 .header_size = sizeof(struct smb2_sync_hdr),
5593 .header_preamble_size = 0,
5594 .max_header_size = MAX_SMB2_HDR_SIZE,
5595 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5596 .lock_cmd = SMB2_LOCK,
5598 .cap_nt_find = SMB2_NT_FIND,
5599 .cap_large_files = SMB2_LARGE_FILES,
5600 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5601 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5602 .create_lease_size = sizeof(struct create_lease_v2),
5605 struct smb_version_values smb311_values = {
5606 .version_string = SMB311_VERSION_STRING,
5607 .protocol_id = SMB311_PROT_ID,
5608 .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,
5609 .large_lock_type = 0,
5610 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5611 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5612 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5613 .header_size = sizeof(struct smb2_sync_hdr),
5614 .header_preamble_size = 0,
5615 .max_header_size = MAX_SMB2_HDR_SIZE,
5616 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5617 .lock_cmd = SMB2_LOCK,
5619 .cap_nt_find = SMB2_NT_FIND,
5620 .cap_large_files = SMB2_LARGE_FILES,
5621 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5622 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5623 .create_lease_size = sizeof(struct create_lease_v2),