1 // SPDX-License-Identifier: GPL-2.0
3 * SMB2 version specific operations
5 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
8 #include <linux/pagemap.h>
10 #include <linux/falloc.h>
11 #include <linux/scatterlist.h>
12 #include <linux/uuid.h>
13 #include <linux/sort.h>
14 #include <crypto/aead.h>
15 #include <linux/fiemap.h>
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_cached_dir(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_cached_dir_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_cached_dir_lease(struct cached_fid *cfid)
713 mutex_lock(&cfid->fid_mutex);
714 close_cached_dir_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_cached_dir_lease(cfid);
728 * Open the and cache a directory handle.
729 * Only supported for the root handle.
731 int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
733 struct cifs_sb_info *cifs_sb,
734 struct cached_fid **cfid)
736 struct cifs_ses *ses = tcon->ses;
737 struct TCP_Server_Info *server = ses->server;
738 struct cifs_open_parms oparms;
739 struct smb2_create_rsp *o_rsp = NULL;
740 struct smb2_query_info_rsp *qi_rsp = NULL;
742 struct smb_rqst rqst[2];
743 struct kvec rsp_iov[2];
744 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
745 struct kvec qi_iov[1];
747 __le16 utf16_path = 0; /* Null - since an open of top of share */
748 u8 oplock = SMB2_OPLOCK_LEVEL_II;
749 struct cifs_fid *pfid;
751 if (tcon->nohandlecache)
757 mutex_lock(&tcon->crfid.fid_mutex);
758 if (tcon->crfid.is_valid) {
759 cifs_dbg(FYI, "found a cached root file handle\n");
760 *cfid = &tcon->crfid;
761 kref_get(&tcon->crfid.refcount);
762 mutex_unlock(&tcon->crfid.fid_mutex);
767 * We do not hold the lock for the open because in case
768 * SMB2_open needs to reconnect, it will end up calling
769 * cifs_mark_open_files_invalid() which takes the lock again
770 * thus causing a deadlock
773 mutex_unlock(&tcon->crfid.fid_mutex);
775 if (smb3_encryption_required(tcon))
776 flags |= CIFS_TRANSFORM_REQ;
778 if (!server->ops->new_lease_key)
781 pfid = tcon->crfid.fid;
782 server->ops->new_lease_key(pfid);
784 memset(rqst, 0, sizeof(rqst));
785 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
786 memset(rsp_iov, 0, sizeof(rsp_iov));
789 memset(&open_iov, 0, sizeof(open_iov));
790 rqst[0].rq_iov = open_iov;
791 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
794 oparms.create_options = cifs_create_options(cifs_sb, 0);
795 oparms.desired_access = FILE_READ_ATTRIBUTES;
796 oparms.disposition = FILE_OPEN;
798 oparms.reconnect = false;
800 rc = SMB2_open_init(tcon, server,
801 &rqst[0], &oplock, &oparms, &utf16_path);
804 smb2_set_next_command(tcon, &rqst[0]);
806 memset(&qi_iov, 0, sizeof(qi_iov));
807 rqst[1].rq_iov = qi_iov;
810 rc = SMB2_query_info_init(tcon, server,
811 &rqst[1], COMPOUND_FID,
812 COMPOUND_FID, FILE_ALL_INFORMATION,
814 sizeof(struct smb2_file_all_info) +
815 PATH_MAX * 2, 0, NULL);
819 smb2_set_related(&rqst[1]);
821 rc = compound_send_recv(xid, ses, server,
823 resp_buftype, rsp_iov);
824 mutex_lock(&tcon->crfid.fid_mutex);
827 * Now we need to check again as the cached root might have
828 * been successfully re-opened from a concurrent process
831 if (tcon->crfid.is_valid) {
832 /* work was already done */
834 /* stash fids for close() later */
835 struct cifs_fid fid = {
836 .persistent_fid = pfid->persistent_fid,
837 .volatile_fid = pfid->volatile_fid,
841 * caller expects this func to set pfid to a valid
842 * cached root, so we copy the existing one and get a
845 memcpy(pfid, tcon->crfid.fid, sizeof(*pfid));
846 kref_get(&tcon->crfid.refcount);
848 mutex_unlock(&tcon->crfid.fid_mutex);
851 /* close extra handle outside of crit sec */
852 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
858 /* Cached root is still invalid, continue normaly */
861 if (rc == -EREMCHG) {
862 tcon->need_reconnect = true;
863 pr_warn_once("server share %s deleted\n",
869 atomic_inc(&tcon->num_remote_opens);
871 o_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
872 oparms.fid->persistent_fid = o_rsp->PersistentFileId;
873 oparms.fid->volatile_fid = o_rsp->VolatileFileId;
874 #ifdef CONFIG_CIFS_DEBUG2
875 oparms.fid->mid = le64_to_cpu(o_rsp->sync_hdr.MessageId);
876 #endif /* CIFS_DEBUG2 */
878 memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid));
879 tcon->crfid.tcon = tcon;
880 tcon->crfid.is_valid = true;
881 kref_init(&tcon->crfid.refcount);
883 /* BB TBD check to see if oplock level check can be removed below */
884 if (o_rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE) {
885 kref_get(&tcon->crfid.refcount);
886 tcon->crfid.has_lease = true;
887 smb2_parse_contexts(server, o_rsp,
889 oparms.fid->lease_key, &oplock,
894 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
895 if (le32_to_cpu(qi_rsp->OutputBufferLength) < sizeof(struct smb2_file_all_info))
897 if (!smb2_validate_and_copy_iov(
898 le16_to_cpu(qi_rsp->OutputBufferOffset),
899 sizeof(struct smb2_file_all_info),
900 &rsp_iov[1], sizeof(struct smb2_file_all_info),
901 (char *)&tcon->crfid.file_all_info))
902 tcon->crfid.file_all_info_is_valid = true;
905 mutex_unlock(&tcon->crfid.fid_mutex);
907 SMB2_open_free(&rqst[0]);
908 SMB2_query_info_free(&rqst[1]);
909 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
910 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
912 *cfid = &tcon->crfid;
917 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
918 struct cifs_sb_info *cifs_sb)
921 __le16 srch_path = 0; /* Null - open root of share */
922 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
923 struct cifs_open_parms oparms;
925 struct cached_fid *cfid = NULL;
928 oparms.desired_access = FILE_READ_ATTRIBUTES;
929 oparms.disposition = FILE_OPEN;
930 oparms.create_options = cifs_create_options(cifs_sb, 0);
932 oparms.reconnect = false;
934 rc = open_cached_dir(xid, tcon, "", cifs_sb, &cfid);
936 memcpy(&fid, cfid->fid, sizeof(struct cifs_fid));
938 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
943 SMB3_request_interfaces(xid, tcon);
945 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
946 FS_ATTRIBUTE_INFORMATION);
947 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
948 FS_DEVICE_INFORMATION);
949 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
950 FS_VOLUME_INFORMATION);
951 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
952 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
954 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
956 close_cached_dir(cfid);
960 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
961 struct cifs_sb_info *cifs_sb)
964 __le16 srch_path = 0; /* Null - open root of share */
965 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
966 struct cifs_open_parms oparms;
970 oparms.desired_access = FILE_READ_ATTRIBUTES;
971 oparms.disposition = FILE_OPEN;
972 oparms.create_options = cifs_create_options(cifs_sb, 0);
974 oparms.reconnect = false;
976 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
981 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
982 FS_ATTRIBUTE_INFORMATION);
983 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
984 FS_DEVICE_INFORMATION);
985 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
989 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
990 struct cifs_sb_info *cifs_sb, const char *full_path)
994 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
995 struct cifs_open_parms oparms;
998 if ((*full_path == 0) && tcon->crfid.is_valid)
1001 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
1006 oparms.desired_access = FILE_READ_ATTRIBUTES;
1007 oparms.disposition = FILE_OPEN;
1008 oparms.create_options = cifs_create_options(cifs_sb, 0);
1010 oparms.reconnect = false;
1012 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
1019 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
1025 smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
1026 struct cifs_sb_info *cifs_sb, const char *full_path,
1027 u64 *uniqueid, FILE_ALL_INFO *data)
1029 *uniqueid = le64_to_cpu(data->IndexNumber);
1034 smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
1035 struct cifs_fid *fid, FILE_ALL_INFO *data)
1038 struct smb2_file_all_info *smb2_data;
1040 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
1042 if (smb2_data == NULL)
1045 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
1048 move_smb2_info_to_cifs(data, smb2_data);
1053 #ifdef CONFIG_CIFS_XATTR
1055 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
1056 struct smb2_file_full_ea_info *src, size_t src_size,
1057 const unsigned char *ea_name)
1060 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
1062 size_t buf_size = dst_size;
1063 size_t name_len, value_len, user_name_len;
1065 while (src_size > 0) {
1066 name = &src->ea_data[0];
1067 name_len = (size_t)src->ea_name_length;
1068 value = &src->ea_data[src->ea_name_length + 1];
1069 value_len = (size_t)le16_to_cpu(src->ea_value_length);
1074 if (src_size < 8 + name_len + 1 + value_len) {
1075 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
1081 if (ea_name_len == name_len &&
1082 memcmp(ea_name, name, name_len) == 0) {
1086 if (dst_size < value_len) {
1090 memcpy(dst, value, value_len);
1094 /* 'user.' plus a terminating null */
1095 user_name_len = 5 + 1 + name_len;
1097 if (buf_size == 0) {
1098 /* skip copy - calc size only */
1099 rc += user_name_len;
1100 } else if (dst_size >= user_name_len) {
1101 dst_size -= user_name_len;
1102 memcpy(dst, "user.", 5);
1104 memcpy(dst, src->ea_data, name_len);
1108 rc += user_name_len;
1110 /* stop before overrun buffer */
1116 if (!src->next_entry_offset)
1119 if (src_size < le32_to_cpu(src->next_entry_offset)) {
1120 /* stop before overrun buffer */
1124 src_size -= le32_to_cpu(src->next_entry_offset);
1125 src = (void *)((char *)src +
1126 le32_to_cpu(src->next_entry_offset));
1129 /* didn't find the named attribute */
1138 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
1139 const unsigned char *path, const unsigned char *ea_name,
1140 char *ea_data, size_t buf_size,
1141 struct cifs_sb_info *cifs_sb)
1145 struct kvec rsp_iov = {NULL, 0};
1146 int buftype = CIFS_NO_BUFFER;
1147 struct smb2_query_info_rsp *rsp;
1148 struct smb2_file_full_ea_info *info = NULL;
1150 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1154 rc = smb2_query_info_compound(xid, tcon, utf16_path,
1156 FILE_FULL_EA_INFORMATION,
1159 MAX_SMB2_CREATE_RESPONSE_SIZE -
1160 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1161 &rsp_iov, &buftype, cifs_sb);
1164 * If ea_name is NULL (listxattr) and there are no EAs,
1165 * return 0 as it's not an error. Otherwise, the specified
1166 * ea_name was not found.
1168 if (!ea_name && rc == -ENODATA)
1173 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
1174 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1175 le32_to_cpu(rsp->OutputBufferLength),
1177 sizeof(struct smb2_file_full_ea_info));
1181 info = (struct smb2_file_full_ea_info *)(
1182 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1183 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
1184 le32_to_cpu(rsp->OutputBufferLength), ea_name);
1188 free_rsp_buf(buftype, rsp_iov.iov_base);
1194 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
1195 const char *path, const char *ea_name, const void *ea_value,
1196 const __u16 ea_value_len, const struct nls_table *nls_codepage,
1197 struct cifs_sb_info *cifs_sb)
1199 struct cifs_ses *ses = tcon->ses;
1200 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1201 __le16 *utf16_path = NULL;
1202 int ea_name_len = strlen(ea_name);
1203 int flags = CIFS_CP_CREATE_CLOSE_OP;
1205 struct smb_rqst rqst[3];
1206 int resp_buftype[3];
1207 struct kvec rsp_iov[3];
1208 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1209 struct cifs_open_parms oparms;
1210 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1211 struct cifs_fid fid;
1212 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1213 unsigned int size[1];
1215 struct smb2_file_full_ea_info *ea = NULL;
1216 struct kvec close_iov[1];
1217 struct smb2_query_info_rsp *rsp;
1218 int rc, used_len = 0;
1220 if (smb3_encryption_required(tcon))
1221 flags |= CIFS_TRANSFORM_REQ;
1223 if (ea_name_len > 255)
1226 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1230 memset(rqst, 0, sizeof(rqst));
1231 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1232 memset(rsp_iov, 0, sizeof(rsp_iov));
1234 if (ses->server->ops->query_all_EAs) {
1236 rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1242 /* If we are adding a attribute we should first check
1243 * if there will be enough space available to store
1244 * the new EA. If not we should not add it since we
1245 * would not be able to even read the EAs back.
1247 rc = smb2_query_info_compound(xid, tcon, utf16_path,
1249 FILE_FULL_EA_INFORMATION,
1252 MAX_SMB2_CREATE_RESPONSE_SIZE -
1253 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1254 &rsp_iov[1], &resp_buftype[1], cifs_sb);
1256 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1257 used_len = le32_to_cpu(rsp->OutputBufferLength);
1259 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1260 resp_buftype[1] = CIFS_NO_BUFFER;
1261 memset(&rsp_iov[1], 0, sizeof(rsp_iov[1]));
1264 /* Use a fudge factor of 256 bytes in case we collide
1265 * with a different set_EAs command.
1267 if(CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
1268 MAX_SMB2_CLOSE_RESPONSE_SIZE - 256 <
1269 used_len + ea_name_len + ea_value_len + 1) {
1277 memset(&open_iov, 0, sizeof(open_iov));
1278 rqst[0].rq_iov = open_iov;
1279 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1281 memset(&oparms, 0, sizeof(oparms));
1283 oparms.desired_access = FILE_WRITE_EA;
1284 oparms.disposition = FILE_OPEN;
1285 oparms.create_options = cifs_create_options(cifs_sb, 0);
1287 oparms.reconnect = false;
1289 rc = SMB2_open_init(tcon, server,
1290 &rqst[0], &oplock, &oparms, utf16_path);
1293 smb2_set_next_command(tcon, &rqst[0]);
1297 memset(&si_iov, 0, sizeof(si_iov));
1298 rqst[1].rq_iov = si_iov;
1299 rqst[1].rq_nvec = 1;
1301 len = sizeof(*ea) + ea_name_len + ea_value_len + 1;
1302 ea = kzalloc(len, GFP_KERNEL);
1308 ea->ea_name_length = ea_name_len;
1309 ea->ea_value_length = cpu_to_le16(ea_value_len);
1310 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
1311 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
1316 rc = SMB2_set_info_init(tcon, server,
1317 &rqst[1], COMPOUND_FID,
1318 COMPOUND_FID, current->tgid,
1319 FILE_FULL_EA_INFORMATION,
1320 SMB2_O_INFO_FILE, 0, data, size);
1321 smb2_set_next_command(tcon, &rqst[1]);
1322 smb2_set_related(&rqst[1]);
1326 memset(&close_iov, 0, sizeof(close_iov));
1327 rqst[2].rq_iov = close_iov;
1328 rqst[2].rq_nvec = 1;
1329 rc = SMB2_close_init(tcon, server,
1330 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1331 smb2_set_related(&rqst[2]);
1333 rc = compound_send_recv(xid, ses, server,
1335 resp_buftype, rsp_iov);
1336 /* no need to bump num_remote_opens because handle immediately closed */
1341 SMB2_open_free(&rqst[0]);
1342 SMB2_set_info_free(&rqst[1]);
1343 SMB2_close_free(&rqst[2]);
1344 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1345 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1346 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1352 smb2_can_echo(struct TCP_Server_Info *server)
1354 return server->echoes;
1358 smb2_clear_stats(struct cifs_tcon *tcon)
1362 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1363 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1364 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1369 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1371 seq_puts(m, "\n\tShare Capabilities:");
1372 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1373 seq_puts(m, " DFS,");
1374 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1375 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1376 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1377 seq_puts(m, " SCALEOUT,");
1378 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1379 seq_puts(m, " CLUSTER,");
1380 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1381 seq_puts(m, " ASYMMETRIC,");
1382 if (tcon->capabilities == 0)
1383 seq_puts(m, " None");
1384 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1385 seq_puts(m, " Aligned,");
1386 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1387 seq_puts(m, " Partition Aligned,");
1388 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1389 seq_puts(m, " SSD,");
1390 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1391 seq_puts(m, " TRIM-support,");
1393 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1394 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1395 if (tcon->perf_sector_size)
1396 seq_printf(m, "\tOptimal sector size: 0x%x",
1397 tcon->perf_sector_size);
1398 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1402 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1404 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1405 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1408 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1409 * totals (requests sent) since those SMBs are per-session not per tcon
1411 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1412 (long long)(tcon->bytes_read),
1413 (long long)(tcon->bytes_written));
1414 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1415 atomic_read(&tcon->num_local_opens),
1416 atomic_read(&tcon->num_remote_opens));
1417 seq_printf(m, "\nTreeConnects: %d total %d failed",
1418 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1419 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1420 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1421 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1422 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1423 seq_printf(m, "\nCreates: %d total %d failed",
1424 atomic_read(&sent[SMB2_CREATE_HE]),
1425 atomic_read(&failed[SMB2_CREATE_HE]));
1426 seq_printf(m, "\nCloses: %d total %d failed",
1427 atomic_read(&sent[SMB2_CLOSE_HE]),
1428 atomic_read(&failed[SMB2_CLOSE_HE]));
1429 seq_printf(m, "\nFlushes: %d total %d failed",
1430 atomic_read(&sent[SMB2_FLUSH_HE]),
1431 atomic_read(&failed[SMB2_FLUSH_HE]));
1432 seq_printf(m, "\nReads: %d total %d failed",
1433 atomic_read(&sent[SMB2_READ_HE]),
1434 atomic_read(&failed[SMB2_READ_HE]));
1435 seq_printf(m, "\nWrites: %d total %d failed",
1436 atomic_read(&sent[SMB2_WRITE_HE]),
1437 atomic_read(&failed[SMB2_WRITE_HE]));
1438 seq_printf(m, "\nLocks: %d total %d failed",
1439 atomic_read(&sent[SMB2_LOCK_HE]),
1440 atomic_read(&failed[SMB2_LOCK_HE]));
1441 seq_printf(m, "\nIOCTLs: %d total %d failed",
1442 atomic_read(&sent[SMB2_IOCTL_HE]),
1443 atomic_read(&failed[SMB2_IOCTL_HE]));
1444 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1445 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1446 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1447 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1448 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1449 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1450 seq_printf(m, "\nQueryInfos: %d total %d failed",
1451 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1452 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1453 seq_printf(m, "\nSetInfos: %d total %d failed",
1454 atomic_read(&sent[SMB2_SET_INFO_HE]),
1455 atomic_read(&failed[SMB2_SET_INFO_HE]));
1456 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1457 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1458 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1462 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1464 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1465 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1467 cfile->fid.persistent_fid = fid->persistent_fid;
1468 cfile->fid.volatile_fid = fid->volatile_fid;
1469 cfile->fid.access = fid->access;
1470 #ifdef CONFIG_CIFS_DEBUG2
1471 cfile->fid.mid = fid->mid;
1472 #endif /* CIFS_DEBUG2 */
1473 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1475 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1476 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1480 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1481 struct cifs_fid *fid)
1483 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1487 smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon,
1488 struct cifsFileInfo *cfile)
1490 struct smb2_file_network_open_info file_inf;
1491 struct inode *inode;
1494 rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid,
1495 cfile->fid.volatile_fid, &file_inf);
1499 inode = d_inode(cfile->dentry);
1501 spin_lock(&inode->i_lock);
1502 CIFS_I(inode)->time = jiffies;
1504 /* Creation time should not need to be updated on close */
1505 if (file_inf.LastWriteTime)
1506 inode->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime);
1507 if (file_inf.ChangeTime)
1508 inode->i_ctime = cifs_NTtimeToUnix(file_inf.ChangeTime);
1509 if (file_inf.LastAccessTime)
1510 inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime);
1513 * i_blocks is not related to (i_size / i_blksize),
1514 * but instead 512 byte (2**9) size is required for
1515 * calculating num blocks.
1517 if (le64_to_cpu(file_inf.AllocationSize) > 4096)
1519 (512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9;
1521 /* End of file and Attributes should not have to be updated on close */
1522 spin_unlock(&inode->i_lock);
1526 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1527 u64 persistent_fid, u64 volatile_fid,
1528 struct copychunk_ioctl *pcchunk)
1531 unsigned int ret_data_len;
1532 struct resume_key_req *res_key;
1534 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1535 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
1536 NULL, 0 /* no input */, CIFSMaxBufSize,
1537 (char **)&res_key, &ret_data_len);
1540 cifs_tcon_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1541 goto req_res_key_exit;
1543 if (ret_data_len < sizeof(struct resume_key_req)) {
1544 cifs_tcon_dbg(VFS, "Invalid refcopy resume key length\n");
1546 goto req_res_key_exit;
1548 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1556 struct smb_rqst rqst[3];
1557 struct kvec rsp_iov[3];
1558 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1559 struct kvec qi_iov[1];
1560 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
1561 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1562 struct kvec close_iov[1];
1566 smb2_ioctl_query_info(const unsigned int xid,
1567 struct cifs_tcon *tcon,
1568 struct cifs_sb_info *cifs_sb,
1569 __le16 *path, int is_dir,
1572 struct iqi_vars *vars;
1573 struct smb_rqst *rqst;
1574 struct kvec *rsp_iov;
1575 struct cifs_ses *ses = tcon->ses;
1576 struct TCP_Server_Info *server = cifs_pick_channel(ses);
1577 char __user *arg = (char __user *)p;
1578 struct smb_query_info qi;
1579 struct smb_query_info __user *pqi;
1581 int flags = CIFS_CP_CREATE_CLOSE_OP;
1582 struct smb2_query_info_rsp *qi_rsp = NULL;
1583 struct smb2_ioctl_rsp *io_rsp = NULL;
1584 void *buffer = NULL;
1585 int resp_buftype[3];
1586 struct cifs_open_parms oparms;
1587 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1588 struct cifs_fid fid;
1589 unsigned int size[2];
1591 int create_options = is_dir ? CREATE_NOT_FILE : CREATE_NOT_DIR;
1593 vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
1596 rqst = &vars->rqst[0];
1597 rsp_iov = &vars->rsp_iov[0];
1599 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1601 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info)))
1604 if (qi.output_buffer_length > 1024) {
1609 if (!ses || !server) {
1614 if (smb3_encryption_required(tcon))
1615 flags |= CIFS_TRANSFORM_REQ;
1617 buffer = memdup_user(arg + sizeof(struct smb_query_info),
1618 qi.output_buffer_length);
1619 if (IS_ERR(buffer)) {
1621 return PTR_ERR(buffer);
1625 rqst[0].rq_iov = &vars->open_iov[0];
1626 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1628 memset(&oparms, 0, sizeof(oparms));
1630 oparms.disposition = FILE_OPEN;
1631 oparms.create_options = cifs_create_options(cifs_sb, create_options);
1633 oparms.reconnect = false;
1635 if (qi.flags & PASSTHRU_FSCTL) {
1636 switch (qi.info_type & FSCTL_DEVICE_ACCESS_MASK) {
1637 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS:
1638 oparms.desired_access = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE;
1640 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS:
1641 oparms.desired_access = GENERIC_ALL;
1643 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS:
1644 oparms.desired_access = GENERIC_READ;
1646 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS:
1647 oparms.desired_access = GENERIC_WRITE;
1650 } else if (qi.flags & PASSTHRU_SET_INFO) {
1651 oparms.desired_access = GENERIC_WRITE;
1653 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1656 rc = SMB2_open_init(tcon, server,
1657 &rqst[0], &oplock, &oparms, path);
1660 smb2_set_next_command(tcon, &rqst[0]);
1663 if (qi.flags & PASSTHRU_FSCTL) {
1664 /* Can eventually relax perm check since server enforces too */
1665 if (!capable(CAP_SYS_ADMIN))
1668 rqst[1].rq_iov = &vars->io_iov[0];
1669 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
1671 rc = SMB2_ioctl_init(tcon, server,
1673 COMPOUND_FID, COMPOUND_FID,
1674 qi.info_type, true, buffer,
1675 qi.output_buffer_length,
1677 MAX_SMB2_CREATE_RESPONSE_SIZE -
1678 MAX_SMB2_CLOSE_RESPONSE_SIZE);
1680 } else if (qi.flags == PASSTHRU_SET_INFO) {
1681 /* Can eventually relax perm check since server enforces too */
1682 if (!capable(CAP_SYS_ADMIN))
1685 rqst[1].rq_iov = &vars->si_iov[0];
1686 rqst[1].rq_nvec = 1;
1691 rc = SMB2_set_info_init(tcon, server,
1693 COMPOUND_FID, COMPOUND_FID,
1695 FILE_END_OF_FILE_INFORMATION,
1696 SMB2_O_INFO_FILE, 0, data, size);
1698 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1699 rqst[1].rq_iov = &vars->qi_iov[0];
1700 rqst[1].rq_nvec = 1;
1702 rc = SMB2_query_info_init(tcon, server,
1703 &rqst[1], COMPOUND_FID,
1704 COMPOUND_FID, qi.file_info_class,
1705 qi.info_type, qi.additional_information,
1706 qi.input_buffer_length,
1707 qi.output_buffer_length, buffer);
1708 } else { /* unknown flags */
1709 cifs_tcon_dbg(VFS, "Invalid passthru query flags: 0x%x\n",
1716 smb2_set_next_command(tcon, &rqst[1]);
1717 smb2_set_related(&rqst[1]);
1720 rqst[2].rq_iov = &vars->close_iov[0];
1721 rqst[2].rq_nvec = 1;
1723 rc = SMB2_close_init(tcon, server,
1724 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
1727 smb2_set_related(&rqst[2]);
1729 rc = compound_send_recv(xid, ses, server,
1731 resp_buftype, rsp_iov);
1735 /* No need to bump num_remote_opens since handle immediately closed */
1736 if (qi.flags & PASSTHRU_FSCTL) {
1737 pqi = (struct smb_query_info __user *)arg;
1738 io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base;
1739 if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length)
1740 qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount);
1741 if (qi.input_buffer_length > 0 &&
1742 le32_to_cpu(io_rsp->OutputOffset) + qi.input_buffer_length
1743 > rsp_iov[1].iov_len)
1746 if (copy_to_user(&pqi->input_buffer_length,
1747 &qi.input_buffer_length,
1748 sizeof(qi.input_buffer_length)))
1751 if (copy_to_user((void __user *)pqi + sizeof(struct smb_query_info),
1752 (const void *)io_rsp + le32_to_cpu(io_rsp->OutputOffset),
1753 qi.input_buffer_length))
1756 pqi = (struct smb_query_info __user *)arg;
1757 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1758 if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length)
1759 qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength);
1760 if (copy_to_user(&pqi->input_buffer_length,
1761 &qi.input_buffer_length,
1762 sizeof(qi.input_buffer_length)))
1765 if (copy_to_user(pqi + 1, qi_rsp->Buffer,
1766 qi.input_buffer_length))
1773 SMB2_open_free(&rqst[0]);
1774 if (qi.flags & PASSTHRU_FSCTL)
1775 SMB2_ioctl_free(&rqst[1]);
1777 SMB2_query_info_free(&rqst[1]);
1779 SMB2_close_free(&rqst[2]);
1780 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1781 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1782 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1791 smb2_copychunk_range(const unsigned int xid,
1792 struct cifsFileInfo *srcfile,
1793 struct cifsFileInfo *trgtfile, u64 src_off,
1794 u64 len, u64 dest_off)
1797 unsigned int ret_data_len;
1798 struct copychunk_ioctl *pcchunk;
1799 struct copychunk_ioctl_rsp *retbuf = NULL;
1800 struct cifs_tcon *tcon;
1801 int chunks_copied = 0;
1802 bool chunk_sizes_updated = false;
1803 ssize_t bytes_written, total_bytes_written = 0;
1805 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1807 if (pcchunk == NULL)
1810 cifs_dbg(FYI, "%s: about to call request res key\n", __func__);
1811 /* Request a key from the server to identify the source of the copy */
1812 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1813 srcfile->fid.persistent_fid,
1814 srcfile->fid.volatile_fid, pcchunk);
1816 /* Note: request_res_key sets res_key null only if rc !=0 */
1820 /* For now array only one chunk long, will make more flexible later */
1821 pcchunk->ChunkCount = cpu_to_le32(1);
1822 pcchunk->Reserved = 0;
1823 pcchunk->Reserved2 = 0;
1825 tcon = tlink_tcon(trgtfile->tlink);
1828 pcchunk->SourceOffset = cpu_to_le64(src_off);
1829 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1831 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
1833 /* Request server copy to target from src identified by key */
1834 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1835 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1836 true /* is_fsctl */, (char *)pcchunk,
1837 sizeof(struct copychunk_ioctl), CIFSMaxBufSize,
1838 (char **)&retbuf, &ret_data_len);
1841 sizeof(struct copychunk_ioctl_rsp)) {
1842 cifs_tcon_dbg(VFS, "Invalid cchunk response size\n");
1846 if (retbuf->TotalBytesWritten == 0) {
1847 cifs_dbg(FYI, "no bytes copied\n");
1852 * Check if server claimed to write more than we asked
1854 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1855 le32_to_cpu(pcchunk->Length)) {
1856 cifs_tcon_dbg(VFS, "Invalid copy chunk response\n");
1860 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1861 cifs_tcon_dbg(VFS, "Invalid num chunks written\n");
1867 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1868 src_off += bytes_written;
1869 dest_off += bytes_written;
1870 len -= bytes_written;
1871 total_bytes_written += bytes_written;
1873 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1874 le32_to_cpu(retbuf->ChunksWritten),
1875 le32_to_cpu(retbuf->ChunkBytesWritten),
1877 } else if (rc == -EINVAL) {
1878 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1881 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1882 le32_to_cpu(retbuf->ChunksWritten),
1883 le32_to_cpu(retbuf->ChunkBytesWritten),
1884 le32_to_cpu(retbuf->TotalBytesWritten));
1887 * Check if this is the first request using these sizes,
1888 * (ie check if copy succeed once with original sizes
1889 * and check if the server gave us different sizes after
1890 * we already updated max sizes on previous request).
1891 * if not then why is the server returning an error now
1893 if ((chunks_copied != 0) || chunk_sizes_updated)
1896 /* Check that server is not asking us to grow size */
1897 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1898 tcon->max_bytes_chunk)
1899 tcon->max_bytes_chunk =
1900 le32_to_cpu(retbuf->ChunkBytesWritten);
1902 goto cchunk_out; /* server gave us bogus size */
1904 /* No need to change MaxChunks since already set to 1 */
1905 chunk_sizes_updated = true;
1916 return total_bytes_written;
1920 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1921 struct cifs_fid *fid)
1923 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1927 smb2_read_data_offset(char *buf)
1929 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1931 return rsp->DataOffset;
1935 smb2_read_data_length(char *buf, bool in_remaining)
1937 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1940 return le32_to_cpu(rsp->DataRemaining);
1942 return le32_to_cpu(rsp->DataLength);
1947 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1948 struct cifs_io_parms *parms, unsigned int *bytes_read,
1949 char **buf, int *buf_type)
1951 parms->persistent_fid = pfid->persistent_fid;
1952 parms->volatile_fid = pfid->volatile_fid;
1953 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1957 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1958 struct cifs_io_parms *parms, unsigned int *written,
1959 struct kvec *iov, unsigned long nr_segs)
1962 parms->persistent_fid = pfid->persistent_fid;
1963 parms->volatile_fid = pfid->volatile_fid;
1964 return SMB2_write(xid, parms, written, iov, nr_segs);
1967 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1968 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1969 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1971 struct cifsInodeInfo *cifsi;
1974 cifsi = CIFS_I(inode);
1976 /* if file already sparse don't bother setting sparse again */
1977 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1978 return true; /* already sparse */
1980 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1981 return true; /* already not sparse */
1984 * Can't check for sparse support on share the usual way via the
1985 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1986 * since Samba server doesn't set the flag on the share, yet
1987 * supports the set sparse FSCTL and returns sparse correctly
1988 * in the file attributes. If we fail setting sparse though we
1989 * mark that server does not support sparse files for this share
1990 * to avoid repeatedly sending the unsupported fsctl to server
1991 * if the file is repeatedly extended.
1993 if (tcon->broken_sparse_sup)
1996 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1997 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1999 &setsparse, 1, CIFSMaxBufSize, NULL, NULL);
2001 tcon->broken_sparse_sup = true;
2002 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
2007 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
2009 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
2015 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
2016 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
2018 __le64 eof = cpu_to_le64(size);
2019 struct inode *inode;
2022 * If extending file more than one page make sparse. Many Linux fs
2023 * make files sparse by default when extending via ftruncate
2025 inode = d_inode(cfile->dentry);
2027 if (!set_alloc && (size > inode->i_size + 8192)) {
2028 __u8 set_sparse = 1;
2030 /* whether set sparse succeeds or not, extend the file */
2031 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
2034 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
2035 cfile->fid.volatile_fid, cfile->pid, &eof);
2039 smb2_duplicate_extents(const unsigned int xid,
2040 struct cifsFileInfo *srcfile,
2041 struct cifsFileInfo *trgtfile, u64 src_off,
2042 u64 len, u64 dest_off)
2045 unsigned int ret_data_len;
2046 struct inode *inode;
2047 struct duplicate_extents_to_file dup_ext_buf;
2048 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
2050 /* server fileays advertise duplicate extent support with this flag */
2051 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
2052 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
2055 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
2056 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
2057 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
2058 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
2059 dup_ext_buf.ByteCount = cpu_to_le64(len);
2060 cifs_dbg(FYI, "Duplicate extents: src off %lld dst off %lld len %lld\n",
2061 src_off, dest_off, len);
2063 inode = d_inode(trgtfile->dentry);
2064 if (inode->i_size < dest_off + len) {
2065 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
2067 goto duplicate_extents_out;
2070 * Although also could set plausible allocation size (i_blocks)
2071 * here in addition to setting the file size, in reflink
2072 * it is likely that the target file is sparse. Its allocation
2073 * size will be queried on next revalidate, but it is important
2074 * to make sure that file's cached size is updated immediately
2076 cifs_setsize(inode, dest_off + len);
2078 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
2079 trgtfile->fid.volatile_fid,
2080 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
2081 true /* is_fsctl */,
2082 (char *)&dup_ext_buf,
2083 sizeof(struct duplicate_extents_to_file),
2084 CIFSMaxBufSize, NULL,
2087 if (ret_data_len > 0)
2088 cifs_dbg(FYI, "Non-zero response length in duplicate extents\n");
2090 duplicate_extents_out:
2095 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
2096 struct cifsFileInfo *cfile)
2098 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
2099 cfile->fid.volatile_fid);
2103 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
2104 struct cifsFileInfo *cfile)
2106 struct fsctl_set_integrity_information_req integr_info;
2107 unsigned int ret_data_len;
2109 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
2110 integr_info.Flags = 0;
2111 integr_info.Reserved = 0;
2113 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2114 cfile->fid.volatile_fid,
2115 FSCTL_SET_INTEGRITY_INFORMATION,
2116 true /* is_fsctl */,
2117 (char *)&integr_info,
2118 sizeof(struct fsctl_set_integrity_information_req),
2119 CIFSMaxBufSize, NULL,
2124 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
2125 #define GMT_TOKEN_SIZE 50
2127 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
2130 * Input buffer contains (empty) struct smb_snapshot array with size filled in
2131 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
2134 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
2135 struct cifsFileInfo *cfile, void __user *ioc_buf)
2137 char *retbuf = NULL;
2138 unsigned int ret_data_len = 0;
2140 u32 max_response_size;
2141 struct smb_snapshot_array snapshot_in;
2144 * On the first query to enumerate the list of snapshots available
2145 * for this volume the buffer begins with 0 (number of snapshots
2146 * which can be returned is zero since at that point we do not know
2147 * how big the buffer needs to be). On the second query,
2148 * it (ret_data_len) is set to number of snapshots so we can
2149 * know to set the maximum response size larger (see below).
2151 if (get_user(ret_data_len, (unsigned int __user *)ioc_buf))
2155 * Note that for snapshot queries that servers like Azure expect that
2156 * the first query be minimal size (and just used to get the number/size
2157 * of previous versions) so response size must be specified as EXACTLY
2158 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
2161 if (ret_data_len == 0)
2162 max_response_size = MIN_SNAPSHOT_ARRAY_SIZE;
2164 max_response_size = CIFSMaxBufSize;
2166 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2167 cfile->fid.volatile_fid,
2168 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
2169 true /* is_fsctl */,
2170 NULL, 0 /* no input data */, max_response_size,
2173 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
2178 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
2180 if (copy_from_user(&snapshot_in, ioc_buf,
2181 sizeof(struct smb_snapshot_array))) {
2188 * Check for min size, ie not large enough to fit even one GMT
2189 * token (snapshot). On the first ioctl some users may pass in
2190 * smaller size (or zero) to simply get the size of the array
2191 * so the user space caller can allocate sufficient memory
2192 * and retry the ioctl again with larger array size sufficient
2193 * to hold all of the snapshot GMT tokens on the second try.
2195 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
2196 ret_data_len = sizeof(struct smb_snapshot_array);
2199 * We return struct SRV_SNAPSHOT_ARRAY, followed by
2200 * the snapshot array (of 50 byte GMT tokens) each
2201 * representing an available previous version of the data
2203 if (ret_data_len > (snapshot_in.snapshot_array_size +
2204 sizeof(struct smb_snapshot_array)))
2205 ret_data_len = snapshot_in.snapshot_array_size +
2206 sizeof(struct smb_snapshot_array);
2208 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
2219 smb3_notify(const unsigned int xid, struct file *pfile,
2220 void __user *ioc_buf)
2222 struct smb3_notify notify;
2223 struct dentry *dentry = pfile->f_path.dentry;
2224 struct inode *inode = file_inode(pfile);
2225 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2226 struct cifs_open_parms oparms;
2227 struct cifs_fid fid;
2228 struct cifs_tcon *tcon;
2229 const unsigned char *path;
2230 void *page = alloc_dentry_path();
2231 __le16 *utf16_path = NULL;
2232 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2235 path = build_path_from_dentry(dentry, page);
2241 utf16_path = cifs_convert_path_to_utf16(path + 1, cifs_sb);
2242 if (utf16_path == NULL) {
2247 if (copy_from_user(¬ify, ioc_buf, sizeof(struct smb3_notify))) {
2252 tcon = cifs_sb_master_tcon(cifs_sb);
2254 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
2255 oparms.disposition = FILE_OPEN;
2256 oparms.create_options = cifs_create_options(cifs_sb, 0);
2258 oparms.reconnect = false;
2260 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
2265 rc = SMB2_change_notify(xid, tcon, fid.persistent_fid, fid.volatile_fid,
2266 notify.watch_tree, notify.completion_filter);
2268 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2270 cifs_dbg(FYI, "change notify for path %s rc %d\n", path, rc);
2273 free_dentry_path(page);
2279 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
2280 const char *path, struct cifs_sb_info *cifs_sb,
2281 struct cifs_fid *fid, __u16 search_flags,
2282 struct cifs_search_info *srch_inf)
2285 struct smb_rqst rqst[2];
2286 struct kvec rsp_iov[2];
2287 int resp_buftype[2];
2288 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2289 struct kvec qd_iov[SMB2_QUERY_DIRECTORY_IOV_SIZE];
2291 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2292 struct cifs_open_parms oparms;
2293 struct smb2_query_directory_rsp *qd_rsp = NULL;
2294 struct smb2_create_rsp *op_rsp = NULL;
2295 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2297 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2301 if (smb3_encryption_required(tcon))
2302 flags |= CIFS_TRANSFORM_REQ;
2304 memset(rqst, 0, sizeof(rqst));
2305 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
2306 memset(rsp_iov, 0, sizeof(rsp_iov));
2309 memset(&open_iov, 0, sizeof(open_iov));
2310 rqst[0].rq_iov = open_iov;
2311 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2314 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
2315 oparms.disposition = FILE_OPEN;
2316 oparms.create_options = cifs_create_options(cifs_sb, 0);
2318 oparms.reconnect = false;
2320 rc = SMB2_open_init(tcon, server,
2321 &rqst[0], &oplock, &oparms, utf16_path);
2324 smb2_set_next_command(tcon, &rqst[0]);
2326 /* Query directory */
2327 srch_inf->entries_in_buffer = 0;
2328 srch_inf->index_of_last_entry = 2;
2330 memset(&qd_iov, 0, sizeof(qd_iov));
2331 rqst[1].rq_iov = qd_iov;
2332 rqst[1].rq_nvec = SMB2_QUERY_DIRECTORY_IOV_SIZE;
2334 rc = SMB2_query_directory_init(xid, tcon, server,
2336 COMPOUND_FID, COMPOUND_FID,
2337 0, srch_inf->info_level);
2341 smb2_set_related(&rqst[1]);
2343 rc = compound_send_recv(xid, tcon->ses, server,
2345 resp_buftype, rsp_iov);
2347 /* If the open failed there is nothing to do */
2348 op_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
2349 if (op_rsp == NULL || op_rsp->sync_hdr.Status != STATUS_SUCCESS) {
2350 cifs_dbg(FYI, "query_dir_first: open failed rc=%d\n", rc);
2353 fid->persistent_fid = op_rsp->PersistentFileId;
2354 fid->volatile_fid = op_rsp->VolatileFileId;
2356 /* Anything else than ENODATA means a genuine error */
2357 if (rc && rc != -ENODATA) {
2358 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2359 cifs_dbg(FYI, "query_dir_first: query directory failed rc=%d\n", rc);
2360 trace_smb3_query_dir_err(xid, fid->persistent_fid,
2361 tcon->tid, tcon->ses->Suid, 0, 0, rc);
2365 atomic_inc(&tcon->num_remote_opens);
2367 qd_rsp = (struct smb2_query_directory_rsp *)rsp_iov[1].iov_base;
2368 if (qd_rsp->sync_hdr.Status == STATUS_NO_MORE_FILES) {
2369 trace_smb3_query_dir_done(xid, fid->persistent_fid,
2370 tcon->tid, tcon->ses->Suid, 0, 0);
2371 srch_inf->endOfSearch = true;
2376 rc = smb2_parse_query_directory(tcon, &rsp_iov[1], resp_buftype[1],
2379 trace_smb3_query_dir_err(xid, fid->persistent_fid, tcon->tid,
2380 tcon->ses->Suid, 0, 0, rc);
2383 resp_buftype[1] = CIFS_NO_BUFFER;
2385 trace_smb3_query_dir_done(xid, fid->persistent_fid, tcon->tid,
2386 tcon->ses->Suid, 0, srch_inf->entries_in_buffer);
2390 SMB2_open_free(&rqst[0]);
2391 SMB2_query_directory_free(&rqst[1]);
2392 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2393 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2398 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
2399 struct cifs_fid *fid, __u16 search_flags,
2400 struct cifs_search_info *srch_inf)
2402 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
2403 fid->volatile_fid, 0, srch_inf);
2407 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
2408 struct cifs_fid *fid)
2410 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
2414 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2415 * the number of credits and return true. Otherwise - return false.
2418 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
2420 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2421 int scredits, in_flight;
2423 if (shdr->Status != STATUS_PENDING)
2426 if (shdr->CreditRequest) {
2427 spin_lock(&server->req_lock);
2428 server->credits += le16_to_cpu(shdr->CreditRequest);
2429 scredits = server->credits;
2430 in_flight = server->in_flight;
2431 spin_unlock(&server->req_lock);
2432 wake_up(&server->request_q);
2434 trace_smb3_add_credits(server->CurrentMid,
2435 server->conn_id, server->hostname, scredits,
2436 le16_to_cpu(shdr->CreditRequest), in_flight);
2437 cifs_dbg(FYI, "%s: status pending add %u credits total=%d\n",
2438 __func__, le16_to_cpu(shdr->CreditRequest), scredits);
2445 smb2_is_session_expired(char *buf)
2447 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2449 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
2450 shdr->Status != STATUS_USER_SESSION_DELETED)
2453 trace_smb3_ses_expired(shdr->TreeId, shdr->SessionId,
2454 le16_to_cpu(shdr->Command),
2455 le64_to_cpu(shdr->MessageId));
2456 cifs_dbg(FYI, "Session expired or deleted\n");
2462 smb2_is_status_io_timeout(char *buf)
2464 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2466 if (shdr->Status == STATUS_IO_TIMEOUT)
2473 smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server)
2475 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2476 struct list_head *tmp, *tmp1;
2477 struct cifs_ses *ses;
2478 struct cifs_tcon *tcon;
2480 if (shdr->Status != STATUS_NETWORK_NAME_DELETED)
2483 spin_lock(&cifs_tcp_ses_lock);
2484 list_for_each(tmp, &server->smb_ses_list) {
2485 ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
2486 list_for_each(tmp1, &ses->tcon_list) {
2487 tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
2488 if (tcon->tid == shdr->TreeId) {
2489 tcon->need_reconnect = true;
2490 spin_unlock(&cifs_tcp_ses_lock);
2491 pr_warn_once("Server share %s deleted.\n",
2497 spin_unlock(&cifs_tcp_ses_lock);
2501 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
2502 struct cifsInodeInfo *cinode)
2504 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
2505 return SMB2_lease_break(0, tcon, cinode->lease_key,
2506 smb2_get_lease_state(cinode));
2508 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
2510 CIFS_CACHE_READ(cinode) ? 1 : 0);
2514 smb2_set_related(struct smb_rqst *rqst)
2516 struct smb2_sync_hdr *shdr;
2518 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
2520 cifs_dbg(FYI, "shdr NULL in smb2_set_related\n");
2523 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2526 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
2529 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
2531 struct smb2_sync_hdr *shdr;
2532 struct cifs_ses *ses = tcon->ses;
2533 struct TCP_Server_Info *server = ses->server;
2534 unsigned long len = smb_rqst_len(server, rqst);
2537 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
2539 cifs_dbg(FYI, "shdr NULL in smb2_set_next_command\n");
2543 /* SMB headers in a compound are 8 byte aligned. */
2545 /* No padding needed */
2549 num_padding = 8 - (len & 7);
2550 if (!smb3_encryption_required(tcon)) {
2552 * If we do not have encryption then we can just add an extra
2553 * iov for the padding.
2555 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
2556 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
2561 * We can not add a small padding iov for the encryption case
2562 * because the encryption framework can not handle the padding
2564 * We have to flatten this into a single buffer and add
2565 * the padding to it.
2567 for (i = 1; i < rqst->rq_nvec; i++) {
2568 memcpy(rqst->rq_iov[0].iov_base +
2569 rqst->rq_iov[0].iov_len,
2570 rqst->rq_iov[i].iov_base,
2571 rqst->rq_iov[i].iov_len);
2572 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2574 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2576 rqst->rq_iov[0].iov_len += num_padding;
2582 shdr->NextCommand = cpu_to_le32(len);
2586 * Passes the query info response back to the caller on success.
2587 * Caller need to free this with free_rsp_buf().
2590 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2591 __le16 *utf16_path, u32 desired_access,
2592 u32 class, u32 type, u32 output_len,
2593 struct kvec *rsp, int *buftype,
2594 struct cifs_sb_info *cifs_sb)
2596 struct cifs_ses *ses = tcon->ses;
2597 struct TCP_Server_Info *server = cifs_pick_channel(ses);
2598 int flags = CIFS_CP_CREATE_CLOSE_OP;
2599 struct smb_rqst rqst[3];
2600 int resp_buftype[3];
2601 struct kvec rsp_iov[3];
2602 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2603 struct kvec qi_iov[1];
2604 struct kvec close_iov[1];
2605 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2606 struct cifs_open_parms oparms;
2607 struct cifs_fid fid;
2610 if (smb3_encryption_required(tcon))
2611 flags |= CIFS_TRANSFORM_REQ;
2613 memset(rqst, 0, sizeof(rqst));
2614 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2615 memset(rsp_iov, 0, sizeof(rsp_iov));
2617 memset(&open_iov, 0, sizeof(open_iov));
2618 rqst[0].rq_iov = open_iov;
2619 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2622 oparms.desired_access = desired_access;
2623 oparms.disposition = FILE_OPEN;
2624 oparms.create_options = cifs_create_options(cifs_sb, 0);
2626 oparms.reconnect = false;
2628 rc = SMB2_open_init(tcon, server,
2629 &rqst[0], &oplock, &oparms, utf16_path);
2632 smb2_set_next_command(tcon, &rqst[0]);
2634 memset(&qi_iov, 0, sizeof(qi_iov));
2635 rqst[1].rq_iov = qi_iov;
2636 rqst[1].rq_nvec = 1;
2638 rc = SMB2_query_info_init(tcon, server,
2639 &rqst[1], COMPOUND_FID, COMPOUND_FID,
2645 smb2_set_next_command(tcon, &rqst[1]);
2646 smb2_set_related(&rqst[1]);
2648 memset(&close_iov, 0, sizeof(close_iov));
2649 rqst[2].rq_iov = close_iov;
2650 rqst[2].rq_nvec = 1;
2652 rc = SMB2_close_init(tcon, server,
2653 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
2656 smb2_set_related(&rqst[2]);
2658 rc = compound_send_recv(xid, ses, server,
2660 resp_buftype, rsp_iov);
2662 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2663 if (rc == -EREMCHG) {
2664 tcon->need_reconnect = true;
2665 pr_warn_once("server share %s deleted\n",
2671 *buftype = resp_buftype[1];
2674 SMB2_open_free(&rqst[0]);
2675 SMB2_query_info_free(&rqst[1]);
2676 SMB2_close_free(&rqst[2]);
2677 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2678 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2683 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2684 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2686 struct smb2_query_info_rsp *rsp;
2687 struct smb2_fs_full_size_info *info = NULL;
2688 __le16 utf16_path = 0; /* Null - open root of share */
2689 struct kvec rsp_iov = {NULL, 0};
2690 int buftype = CIFS_NO_BUFFER;
2694 rc = smb2_query_info_compound(xid, tcon, &utf16_path,
2695 FILE_READ_ATTRIBUTES,
2696 FS_FULL_SIZE_INFORMATION,
2697 SMB2_O_INFO_FILESYSTEM,
2698 sizeof(struct smb2_fs_full_size_info),
2699 &rsp_iov, &buftype, cifs_sb);
2703 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2704 buf->f_type = SMB2_MAGIC_NUMBER;
2705 info = (struct smb2_fs_full_size_info *)(
2706 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2707 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2708 le32_to_cpu(rsp->OutputBufferLength),
2710 sizeof(struct smb2_fs_full_size_info));
2712 smb2_copy_fs_info_to_kstatfs(info, buf);
2715 free_rsp_buf(buftype, rsp_iov.iov_base);
2720 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2721 struct cifs_sb_info *cifs_sb, struct kstatfs *buf)
2724 __le16 srch_path = 0; /* Null - open root of share */
2725 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2726 struct cifs_open_parms oparms;
2727 struct cifs_fid fid;
2729 if (!tcon->posix_extensions)
2730 return smb2_queryfs(xid, tcon, cifs_sb, buf);
2733 oparms.desired_access = FILE_READ_ATTRIBUTES;
2734 oparms.disposition = FILE_OPEN;
2735 oparms.create_options = cifs_create_options(cifs_sb, 0);
2737 oparms.reconnect = false;
2739 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
2744 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2745 fid.volatile_fid, buf);
2746 buf->f_type = SMB2_MAGIC_NUMBER;
2747 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2752 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2754 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2755 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2759 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2760 __u64 length, __u32 type, int lock, int unlock, bool wait)
2762 if (unlock && !lock)
2763 type = SMB2_LOCKFLAG_UNLOCK;
2764 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2765 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2766 current->tgid, length, offset, type, wait);
2770 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2772 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2776 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2778 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2782 smb2_new_lease_key(struct cifs_fid *fid)
2784 generate_random_uuid(fid->lease_key);
2788 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2789 const char *search_name,
2790 struct dfs_info3_param **target_nodes,
2791 unsigned int *num_of_nodes,
2792 const struct nls_table *nls_codepage, int remap)
2795 __le16 *utf16_path = NULL;
2796 int utf16_path_len = 0;
2797 struct cifs_tcon *tcon;
2798 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2799 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2800 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2802 cifs_dbg(FYI, "%s: path: %s\n", __func__, search_name);
2805 * Try to use the IPC tcon, otherwise just use any
2807 tcon = ses->tcon_ipc;
2809 spin_lock(&cifs_tcp_ses_lock);
2810 tcon = list_first_entry_or_null(&ses->tcon_list,
2815 spin_unlock(&cifs_tcp_ses_lock);
2819 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2825 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2827 nls_codepage, remap);
2833 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2834 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2840 /* Highest DFS referral version understood */
2841 dfs_req->MaxReferralLevel = DFS_VERSION;
2843 /* Path to resolve in an UTF-16 null-terminated string */
2844 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2847 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2848 FSCTL_DFS_GET_REFERRALS,
2849 true /* is_fsctl */,
2850 (char *)dfs_req, dfs_req_size, CIFSMaxBufSize,
2851 (char **)&dfs_rsp, &dfs_rsp_size);
2852 } while (rc == -EAGAIN);
2855 if ((rc != -ENOENT) && (rc != -EOPNOTSUPP))
2856 cifs_tcon_dbg(VFS, "ioctl error in %s rc=%d\n", __func__, rc);
2860 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
2861 num_of_nodes, target_nodes,
2862 nls_codepage, remap, search_name,
2863 true /* is_unicode */);
2865 cifs_tcon_dbg(VFS, "parse error in %s rc=%d\n", __func__, rc);
2870 if (tcon && !tcon->ipc) {
2871 /* ipc tcons are not refcounted */
2872 spin_lock(&cifs_tcp_ses_lock);
2874 spin_unlock(&cifs_tcp_ses_lock);
2883 parse_reparse_posix(struct reparse_posix_data *symlink_buf,
2884 u32 plen, char **target_path,
2885 struct cifs_sb_info *cifs_sb)
2889 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
2890 len = le16_to_cpu(symlink_buf->ReparseDataLength);
2892 if (le64_to_cpu(symlink_buf->InodeType) != NFS_SPECFILE_LNK) {
2893 cifs_dbg(VFS, "%lld not a supported symlink type\n",
2894 le64_to_cpu(symlink_buf->InodeType));
2898 *target_path = cifs_strndup_from_utf16(
2899 symlink_buf->PathBuffer,
2900 len, true, cifs_sb->local_nls);
2901 if (!(*target_path))
2904 convert_delimiter(*target_path, '/');
2905 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2911 parse_reparse_symlink(struct reparse_symlink_data_buffer *symlink_buf,
2912 u32 plen, char **target_path,
2913 struct cifs_sb_info *cifs_sb)
2915 unsigned int sub_len;
2916 unsigned int sub_offset;
2918 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */
2920 sub_offset = le16_to_cpu(symlink_buf->SubstituteNameOffset);
2921 sub_len = le16_to_cpu(symlink_buf->SubstituteNameLength);
2922 if (sub_offset + 20 > plen ||
2923 sub_offset + sub_len + 20 > plen) {
2924 cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
2928 *target_path = cifs_strndup_from_utf16(
2929 symlink_buf->PathBuffer + sub_offset,
2930 sub_len, true, cifs_sb->local_nls);
2931 if (!(*target_path))
2934 convert_delimiter(*target_path, '/');
2935 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2941 parse_reparse_point(struct reparse_data_buffer *buf,
2942 u32 plen, char **target_path,
2943 struct cifs_sb_info *cifs_sb)
2945 if (plen < sizeof(struct reparse_data_buffer)) {
2946 cifs_dbg(VFS, "reparse buffer is too small. Must be at least 8 bytes but was %d\n",
2951 if (plen < le16_to_cpu(buf->ReparseDataLength) +
2952 sizeof(struct reparse_data_buffer)) {
2953 cifs_dbg(VFS, "srv returned invalid reparse buf length: %d\n",
2958 /* See MS-FSCC 2.1.2 */
2959 switch (le32_to_cpu(buf->ReparseTag)) {
2960 case IO_REPARSE_TAG_NFS:
2961 return parse_reparse_posix(
2962 (struct reparse_posix_data *)buf,
2963 plen, target_path, cifs_sb);
2964 case IO_REPARSE_TAG_SYMLINK:
2965 return parse_reparse_symlink(
2966 (struct reparse_symlink_data_buffer *)buf,
2967 plen, target_path, cifs_sb);
2969 cifs_dbg(VFS, "srv returned unknown symlink buffer tag:0x%08x\n",
2970 le32_to_cpu(buf->ReparseTag));
2975 #define SMB2_SYMLINK_STRUCT_SIZE \
2976 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
2979 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
2980 struct cifs_sb_info *cifs_sb, const char *full_path,
2981 char **target_path, bool is_reparse_point)
2984 __le16 *utf16_path = NULL;
2985 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2986 struct cifs_open_parms oparms;
2987 struct cifs_fid fid;
2988 struct kvec err_iov = {NULL, 0};
2989 struct smb2_err_rsp *err_buf = NULL;
2990 struct smb2_symlink_err_rsp *symlink;
2991 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
2992 unsigned int sub_len;
2993 unsigned int sub_offset;
2994 unsigned int print_len;
2995 unsigned int print_offset;
2996 int flags = CIFS_CP_CREATE_CLOSE_OP;
2997 struct smb_rqst rqst[3];
2998 int resp_buftype[3];
2999 struct kvec rsp_iov[3];
3000 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
3001 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
3002 struct kvec close_iov[1];
3003 struct smb2_create_rsp *create_rsp;
3004 struct smb2_ioctl_rsp *ioctl_rsp;
3005 struct reparse_data_buffer *reparse_buf;
3006 int create_options = is_reparse_point ? OPEN_REPARSE_POINT : 0;
3009 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
3011 *target_path = NULL;
3013 if (smb3_encryption_required(tcon))
3014 flags |= CIFS_TRANSFORM_REQ;
3016 memset(rqst, 0, sizeof(rqst));
3017 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
3018 memset(rsp_iov, 0, sizeof(rsp_iov));
3020 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
3025 memset(&open_iov, 0, sizeof(open_iov));
3026 rqst[0].rq_iov = open_iov;
3027 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
3029 memset(&oparms, 0, sizeof(oparms));
3031 oparms.desired_access = FILE_READ_ATTRIBUTES;
3032 oparms.disposition = FILE_OPEN;
3033 oparms.create_options = cifs_create_options(cifs_sb, create_options);
3035 oparms.reconnect = false;
3037 rc = SMB2_open_init(tcon, server,
3038 &rqst[0], &oplock, &oparms, utf16_path);
3041 smb2_set_next_command(tcon, &rqst[0]);
3045 memset(&io_iov, 0, sizeof(io_iov));
3046 rqst[1].rq_iov = io_iov;
3047 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3049 rc = SMB2_ioctl_init(tcon, server,
3050 &rqst[1], fid.persistent_fid,
3051 fid.volatile_fid, FSCTL_GET_REPARSE_POINT,
3052 true /* is_fctl */, NULL, 0,
3054 MAX_SMB2_CREATE_RESPONSE_SIZE -
3055 MAX_SMB2_CLOSE_RESPONSE_SIZE);
3059 smb2_set_next_command(tcon, &rqst[1]);
3060 smb2_set_related(&rqst[1]);
3064 memset(&close_iov, 0, sizeof(close_iov));
3065 rqst[2].rq_iov = close_iov;
3066 rqst[2].rq_nvec = 1;
3068 rc = SMB2_close_init(tcon, server,
3069 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3073 smb2_set_related(&rqst[2]);
3075 rc = compound_send_recv(xid, tcon->ses, server,
3077 resp_buftype, rsp_iov);
3079 create_rsp = rsp_iov[0].iov_base;
3080 if (create_rsp && create_rsp->sync_hdr.Status)
3081 err_iov = rsp_iov[0];
3082 ioctl_rsp = rsp_iov[1].iov_base;
3085 * Open was successful and we got an ioctl response.
3087 if ((rc == 0) && (is_reparse_point)) {
3088 /* See MS-FSCC 2.3.23 */
3090 reparse_buf = (struct reparse_data_buffer *)
3091 ((char *)ioctl_rsp +
3092 le32_to_cpu(ioctl_rsp->OutputOffset));
3093 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3095 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3096 rsp_iov[1].iov_len) {
3097 cifs_tcon_dbg(VFS, "srv returned invalid ioctl len: %d\n",
3103 rc = parse_reparse_point(reparse_buf, plen, target_path,
3108 if (!rc || !err_iov.iov_base) {
3113 err_buf = err_iov.iov_base;
3114 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
3115 err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) {
3120 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
3121 if (le32_to_cpu(symlink->SymLinkErrorTag) != SYMLINK_ERROR_TAG ||
3122 le32_to_cpu(symlink->ReparseTag) != IO_REPARSE_TAG_SYMLINK) {
3127 /* open must fail on symlink - reset rc */
3129 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
3130 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
3131 print_len = le16_to_cpu(symlink->PrintNameLength);
3132 print_offset = le16_to_cpu(symlink->PrintNameOffset);
3134 if (err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
3139 if (err_iov.iov_len <
3140 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
3145 *target_path = cifs_strndup_from_utf16(
3146 (char *)symlink->PathBuffer + sub_offset,
3147 sub_len, true, cifs_sb->local_nls);
3148 if (!(*target_path)) {
3152 convert_delimiter(*target_path, '/');
3153 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
3156 cifs_dbg(FYI, "query symlink rc %d\n", rc);
3158 SMB2_open_free(&rqst[0]);
3159 SMB2_ioctl_free(&rqst[1]);
3160 SMB2_close_free(&rqst[2]);
3161 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3162 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3163 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3168 smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
3169 struct cifs_sb_info *cifs_sb, const char *full_path,
3173 __le16 *utf16_path = NULL;
3174 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3175 struct cifs_open_parms oparms;
3176 struct cifs_fid fid;
3177 struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
3178 int flags = CIFS_CP_CREATE_CLOSE_OP;
3179 struct smb_rqst rqst[3];
3180 int resp_buftype[3];
3181 struct kvec rsp_iov[3];
3182 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
3183 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
3184 struct kvec close_iov[1];
3185 struct smb2_ioctl_rsp *ioctl_rsp;
3186 struct reparse_data_buffer *reparse_buf;
3189 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
3191 if (smb3_encryption_required(tcon))
3192 flags |= CIFS_TRANSFORM_REQ;
3194 memset(rqst, 0, sizeof(rqst));
3195 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
3196 memset(rsp_iov, 0, sizeof(rsp_iov));
3198 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
3203 * setup smb2open - TODO add optimization to call cifs_get_readable_path
3204 * to see if there is a handle already open that we can use
3206 memset(&open_iov, 0, sizeof(open_iov));
3207 rqst[0].rq_iov = open_iov;
3208 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
3210 memset(&oparms, 0, sizeof(oparms));
3212 oparms.desired_access = FILE_READ_ATTRIBUTES;
3213 oparms.disposition = FILE_OPEN;
3214 oparms.create_options = cifs_create_options(cifs_sb, OPEN_REPARSE_POINT);
3216 oparms.reconnect = false;
3218 rc = SMB2_open_init(tcon, server,
3219 &rqst[0], &oplock, &oparms, utf16_path);
3222 smb2_set_next_command(tcon, &rqst[0]);
3226 memset(&io_iov, 0, sizeof(io_iov));
3227 rqst[1].rq_iov = io_iov;
3228 rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
3230 rc = SMB2_ioctl_init(tcon, server,
3231 &rqst[1], COMPOUND_FID,
3232 COMPOUND_FID, FSCTL_GET_REPARSE_POINT,
3233 true /* is_fctl */, NULL, 0,
3235 MAX_SMB2_CREATE_RESPONSE_SIZE -
3236 MAX_SMB2_CLOSE_RESPONSE_SIZE);
3240 smb2_set_next_command(tcon, &rqst[1]);
3241 smb2_set_related(&rqst[1]);
3245 memset(&close_iov, 0, sizeof(close_iov));
3246 rqst[2].rq_iov = close_iov;
3247 rqst[2].rq_nvec = 1;
3249 rc = SMB2_close_init(tcon, server,
3250 &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
3254 smb2_set_related(&rqst[2]);
3256 rc = compound_send_recv(xid, tcon->ses, server,
3258 resp_buftype, rsp_iov);
3260 ioctl_rsp = rsp_iov[1].iov_base;
3263 * Open was successful and we got an ioctl response.
3266 /* See MS-FSCC 2.3.23 */
3268 reparse_buf = (struct reparse_data_buffer *)
3269 ((char *)ioctl_rsp +
3270 le32_to_cpu(ioctl_rsp->OutputOffset));
3271 plen = le32_to_cpu(ioctl_rsp->OutputCount);
3273 if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
3274 rsp_iov[1].iov_len) {
3275 cifs_tcon_dbg(FYI, "srv returned invalid ioctl len: %d\n",
3280 *tag = le32_to_cpu(reparse_buf->ReparseTag);
3285 SMB2_open_free(&rqst[0]);
3286 SMB2_ioctl_free(&rqst[1]);
3287 SMB2_close_free(&rqst[2]);
3288 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
3289 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
3290 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
3294 static struct cifs_ntsd *
3295 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
3296 const struct cifs_fid *cifsfid, u32 *pacllen, u32 info)
3298 struct cifs_ntsd *pntsd = NULL;
3300 int rc = -EOPNOTSUPP;
3301 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3304 return ERR_CAST(tlink);
3307 cifs_dbg(FYI, "trying to get acl\n");
3309 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
3310 cifsfid->volatile_fid, (void **)&pntsd, pacllen,
3314 cifs_put_tlink(tlink);
3316 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3323 static struct cifs_ntsd *
3324 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
3325 const char *path, u32 *pacllen, u32 info)
3327 struct cifs_ntsd *pntsd = NULL;
3328 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3331 struct cifs_tcon *tcon;
3332 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3333 struct cifs_fid fid;
3334 struct cifs_open_parms oparms;
3337 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
3339 return ERR_CAST(tlink);
3341 tcon = tlink_tcon(tlink);
3344 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3352 oparms.desired_access = READ_CONTROL;
3353 oparms.disposition = FILE_OPEN;
3355 * When querying an ACL, even if the file is a symlink we want to open
3356 * the source not the target, and so the protocol requires that the
3357 * client specify this flag when opening a reparse point
3359 oparms.create_options = cifs_create_options(cifs_sb, 0) | OPEN_REPARSE_POINT;
3361 oparms.reconnect = false;
3363 if (info & SACL_SECINFO)
3364 oparms.desired_access |= SYSTEM_SECURITY;
3366 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL,
3370 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3371 fid.volatile_fid, (void **)&pntsd, pacllen,
3373 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3376 cifs_put_tlink(tlink);
3379 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
3386 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
3387 struct inode *inode, const char *path, int aclflag)
3389 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
3391 int rc, access_flags = 0;
3392 struct cifs_tcon *tcon;
3393 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
3394 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
3395 struct cifs_fid fid;
3396 struct cifs_open_parms oparms;
3399 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
3401 return PTR_ERR(tlink);
3403 tcon = tlink_tcon(tlink);
3406 if (aclflag & CIFS_ACL_OWNER || aclflag & CIFS_ACL_GROUP)
3407 access_flags |= WRITE_OWNER;
3408 if (aclflag & CIFS_ACL_SACL)
3409 access_flags |= SYSTEM_SECURITY;
3410 if (aclflag & CIFS_ACL_DACL)
3411 access_flags |= WRITE_DAC;
3413 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
3421 oparms.desired_access = access_flags;
3422 oparms.create_options = cifs_create_options(cifs_sb, 0);
3423 oparms.disposition = FILE_OPEN;
3426 oparms.reconnect = false;
3428 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
3432 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
3433 fid.volatile_fid, pnntsd, acllen, aclflag);
3434 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
3437 cifs_put_tlink(tlink);
3442 /* Retrieve an ACL from the server */
3443 static struct cifs_ntsd *
3444 get_smb2_acl(struct cifs_sb_info *cifs_sb,
3445 struct inode *inode, const char *path,
3446 u32 *pacllen, u32 info)
3448 struct cifs_ntsd *pntsd = NULL;
3449 struct cifsFileInfo *open_file = NULL;
3451 if (inode && !(info & SACL_SECINFO))
3452 open_file = find_readable_file(CIFS_I(inode), true);
3453 if (!open_file || (info & SACL_SECINFO))
3454 return get_smb2_acl_by_path(cifs_sb, path, pacllen, info);
3456 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen, info);
3457 cifsFileInfo_put(open_file);
3461 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
3462 loff_t offset, loff_t len, bool keep_size)
3464 struct cifs_ses *ses = tcon->ses;
3465 struct inode *inode;
3466 struct cifsInodeInfo *cifsi;
3467 struct cifsFileInfo *cfile = file->private_data;
3468 struct file_zero_data_information fsctl_buf;
3475 inode = d_inode(cfile->dentry);
3476 cifsi = CIFS_I(inode);
3478 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3479 ses->Suid, offset, len);
3482 * We zero the range through ioctl, so we need remove the page caches
3483 * first, otherwise the data may be inconsistent with the server.
3485 truncate_pagecache_range(inode, offset, offset + len - 1);
3487 /* if file not oplocked can't be sure whether asking to extend size */
3488 if (!CIFS_CACHE_READ(cifsi))
3489 if (keep_size == false) {
3491 trace_smb3_zero_err(xid, cfile->fid.persistent_fid,
3492 tcon->tid, ses->Suid, offset, len, rc);
3497 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3499 fsctl_buf.FileOffset = cpu_to_le64(offset);
3500 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3502 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3503 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA, true,
3505 sizeof(struct file_zero_data_information),
3508 goto zero_range_exit;
3511 * do we also need to change the size of the file?
3513 if (keep_size == false && i_size_read(inode) < offset + len) {
3514 eof = cpu_to_le64(offset + len);
3515 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3516 cfile->fid.volatile_fid, cfile->pid, &eof);
3522 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
3523 ses->Suid, offset, len, rc);
3525 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
3526 ses->Suid, offset, len);
3530 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
3531 loff_t offset, loff_t len)
3533 struct inode *inode;
3534 struct cifsFileInfo *cfile = file->private_data;
3535 struct file_zero_data_information fsctl_buf;
3538 __u8 set_sparse = 1;
3542 inode = d_inode(cfile->dentry);
3544 /* Need to make file sparse, if not already, before freeing range. */
3545 /* Consider adding equivalent for compressed since it could also work */
3546 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
3553 * We implement the punch hole through ioctl, so we need remove the page
3554 * caches first, otherwise the data may be inconsistent with the server.
3556 truncate_pagecache_range(inode, offset, offset + len - 1);
3558 cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
3560 fsctl_buf.FileOffset = cpu_to_le64(offset);
3561 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
3563 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3564 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
3565 true /* is_fctl */, (char *)&fsctl_buf,
3566 sizeof(struct file_zero_data_information),
3567 CIFSMaxBufSize, NULL, NULL);
3572 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
3573 loff_t off, loff_t len, bool keep_size)
3575 struct inode *inode;
3576 struct cifsInodeInfo *cifsi;
3577 struct cifsFileInfo *cfile = file->private_data;
3578 long rc = -EOPNOTSUPP;
3584 inode = d_inode(cfile->dentry);
3585 cifsi = CIFS_I(inode);
3587 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
3588 tcon->ses->Suid, off, len);
3589 /* if file not oplocked can't be sure whether asking to extend size */
3590 if (!CIFS_CACHE_READ(cifsi))
3591 if (keep_size == false) {
3592 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
3593 tcon->tid, tcon->ses->Suid, off, len, rc);
3599 * Extending the file
3601 if ((keep_size == false) && i_size_read(inode) < off + len) {
3602 rc = inode_newsize_ok(inode, off + len);
3606 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0)
3607 smb2_set_sparse(xid, tcon, cfile, inode, false);
3609 eof = cpu_to_le64(off + len);
3610 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3611 cfile->fid.volatile_fid, cfile->pid, &eof);
3613 cifsi->server_eof = off + len;
3614 cifs_setsize(inode, off + len);
3615 cifs_truncate_page(inode->i_mapping, inode->i_size);
3616 truncate_setsize(inode, off + len);
3622 * Files are non-sparse by default so falloc may be a no-op
3623 * Must check if file sparse. If not sparse, and since we are not
3624 * extending then no need to do anything since file already allocated
3626 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
3631 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
3633 * Check if falloc starts within first few pages of file
3634 * and ends within a few pages of the end of file to
3635 * ensure that most of file is being forced to be
3636 * fallocated now. If so then setting whole file sparse
3637 * ie potentially making a few extra pages at the beginning
3638 * or end of the file non-sparse via set_sparse is harmless.
3640 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
3646 smb2_set_sparse(xid, tcon, cfile, inode, false);
3651 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
3652 tcon->ses->Suid, off, len, rc);
3654 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
3655 tcon->ses->Suid, off, len);
3661 static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
3663 struct cifsFileInfo *wrcfile, *cfile = file->private_data;
3664 struct cifsInodeInfo *cifsi;
3665 struct inode *inode;
3667 struct file_allocated_range_buffer in_data, *out_data = NULL;
3671 if (whence != SEEK_HOLE && whence != SEEK_DATA)
3672 return generic_file_llseek(file, offset, whence);
3674 inode = d_inode(cfile->dentry);
3675 cifsi = CIFS_I(inode);
3677 if (offset < 0 || offset >= i_size_read(inode))
3682 * We need to be sure that all dirty pages are written as they
3683 * might fill holes on the server.
3684 * Note that we also MUST flush any written pages since at least
3685 * some servers (Windows2016) will not reflect recent writes in
3686 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3688 wrcfile = find_writable_file(cifsi, FIND_WR_ANY);
3690 filemap_write_and_wait(inode->i_mapping);
3691 smb2_flush_file(xid, tcon, &wrcfile->fid);
3692 cifsFileInfo_put(wrcfile);
3695 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
3696 if (whence == SEEK_HOLE)
3697 offset = i_size_read(inode);
3701 in_data.file_offset = cpu_to_le64(offset);
3702 in_data.length = cpu_to_le64(i_size_read(inode));
3704 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3705 cfile->fid.volatile_fid,
3706 FSCTL_QUERY_ALLOCATED_RANGES, true,
3707 (char *)&in_data, sizeof(in_data),
3708 sizeof(struct file_allocated_range_buffer),
3709 (char **)&out_data, &out_data_len);
3715 if (whence == SEEK_HOLE && out_data_len == 0)
3718 if (whence == SEEK_DATA && out_data_len == 0) {
3723 if (out_data_len < sizeof(struct file_allocated_range_buffer)) {
3727 if (whence == SEEK_DATA) {
3728 offset = le64_to_cpu(out_data->file_offset);
3731 if (offset < le64_to_cpu(out_data->file_offset))
3734 offset = le64_to_cpu(out_data->file_offset) + le64_to_cpu(out_data->length);
3740 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3745 static int smb3_fiemap(struct cifs_tcon *tcon,
3746 struct cifsFileInfo *cfile,
3747 struct fiemap_extent_info *fei, u64 start, u64 len)
3750 struct file_allocated_range_buffer in_data, *out_data;
3752 int i, num, rc, flags, last_blob;
3755 rc = fiemap_prep(d_inode(cfile->dentry), fei, start, &len, 0);
3761 in_data.file_offset = cpu_to_le64(start);
3762 in_data.length = cpu_to_le64(len);
3764 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
3765 cfile->fid.volatile_fid,
3766 FSCTL_QUERY_ALLOCATED_RANGES, true,
3767 (char *)&in_data, sizeof(in_data),
3768 1024 * sizeof(struct file_allocated_range_buffer),
3769 (char **)&out_data, &out_data_len);
3778 if (out_data_len && out_data_len < sizeof(struct file_allocated_range_buffer)) {
3782 if (out_data_len % sizeof(struct file_allocated_range_buffer)) {
3787 num = out_data_len / sizeof(struct file_allocated_range_buffer);
3788 for (i = 0; i < num; i++) {
3790 if (i == num - 1 && last_blob)
3791 flags |= FIEMAP_EXTENT_LAST;
3793 rc = fiemap_fill_next_extent(fei,
3794 le64_to_cpu(out_data[i].file_offset),
3795 le64_to_cpu(out_data[i].file_offset),
3796 le64_to_cpu(out_data[i].length),
3807 next = le64_to_cpu(out_data[num - 1].file_offset) +
3808 le64_to_cpu(out_data[num - 1].length);
3809 len = len - (next - start);
3820 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
3821 loff_t off, loff_t len)
3823 /* KEEP_SIZE already checked for by do_fallocate */
3824 if (mode & FALLOC_FL_PUNCH_HOLE)
3825 return smb3_punch_hole(file, tcon, off, len);
3826 else if (mode & FALLOC_FL_ZERO_RANGE) {
3827 if (mode & FALLOC_FL_KEEP_SIZE)
3828 return smb3_zero_range(file, tcon, off, len, true);
3829 return smb3_zero_range(file, tcon, off, len, false);
3830 } else if (mode == FALLOC_FL_KEEP_SIZE)
3831 return smb3_simple_falloc(file, tcon, off, len, true);
3833 return smb3_simple_falloc(file, tcon, off, len, false);
3839 smb2_downgrade_oplock(struct TCP_Server_Info *server,
3840 struct cifsInodeInfo *cinode, __u32 oplock,
3841 unsigned int epoch, bool *purge_cache)
3843 server->ops->set_oplock_level(cinode, oplock, 0, NULL);
3847 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3848 unsigned int epoch, bool *purge_cache);
3851 smb3_downgrade_oplock(struct TCP_Server_Info *server,
3852 struct cifsInodeInfo *cinode, __u32 oplock,
3853 unsigned int epoch, bool *purge_cache)
3855 unsigned int old_state = cinode->oplock;
3856 unsigned int old_epoch = cinode->epoch;
3857 unsigned int new_state;
3859 if (epoch > old_epoch) {
3860 smb21_set_oplock_level(cinode, oplock, 0, NULL);
3861 cinode->epoch = epoch;
3864 new_state = cinode->oplock;
3865 *purge_cache = false;
3867 if ((old_state & CIFS_CACHE_READ_FLG) != 0 &&
3868 (new_state & CIFS_CACHE_READ_FLG) == 0)
3869 *purge_cache = true;
3870 else if (old_state == new_state && (epoch - old_epoch > 1))
3871 *purge_cache = true;
3875 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3876 unsigned int epoch, bool *purge_cache)
3879 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3881 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
3882 cinode->oplock = CIFS_CACHE_RHW_FLG;
3883 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
3884 &cinode->vfs_inode);
3885 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
3886 cinode->oplock = CIFS_CACHE_RW_FLG;
3887 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
3888 &cinode->vfs_inode);
3889 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
3890 cinode->oplock = CIFS_CACHE_READ_FLG;
3891 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
3892 &cinode->vfs_inode);
3898 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3899 unsigned int epoch, bool *purge_cache)
3901 char message[5] = {0};
3902 unsigned int new_oplock = 0;
3905 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
3908 /* Check if the server granted an oplock rather than a lease */
3909 if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE)
3910 return smb2_set_oplock_level(cinode, oplock, epoch,
3913 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
3914 new_oplock |= CIFS_CACHE_READ_FLG;
3915 strcat(message, "R");
3917 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
3918 new_oplock |= CIFS_CACHE_HANDLE_FLG;
3919 strcat(message, "H");
3921 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
3922 new_oplock |= CIFS_CACHE_WRITE_FLG;
3923 strcat(message, "W");
3926 strncpy(message, "None", sizeof(message));
3928 cinode->oplock = new_oplock;
3929 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
3930 &cinode->vfs_inode);
3934 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
3935 unsigned int epoch, bool *purge_cache)
3937 unsigned int old_oplock = cinode->oplock;
3939 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
3942 *purge_cache = false;
3943 if (old_oplock == CIFS_CACHE_READ_FLG) {
3944 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
3945 (epoch - cinode->epoch > 0))
3946 *purge_cache = true;
3947 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
3948 (epoch - cinode->epoch > 1))
3949 *purge_cache = true;
3950 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
3951 (epoch - cinode->epoch > 1))
3952 *purge_cache = true;
3953 else if (cinode->oplock == 0 &&
3954 (epoch - cinode->epoch > 0))
3955 *purge_cache = true;
3956 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
3957 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
3958 (epoch - cinode->epoch > 0))
3959 *purge_cache = true;
3960 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
3961 (epoch - cinode->epoch > 1))
3962 *purge_cache = true;
3964 cinode->epoch = epoch;
3969 smb2_is_read_op(__u32 oplock)
3971 return oplock == SMB2_OPLOCK_LEVEL_II;
3975 smb21_is_read_op(__u32 oplock)
3977 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
3978 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
3982 map_oplock_to_lease(u8 oplock)
3984 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
3985 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
3986 else if (oplock == SMB2_OPLOCK_LEVEL_II)
3987 return SMB2_LEASE_READ_CACHING;
3988 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
3989 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
3990 SMB2_LEASE_WRITE_CACHING;
3995 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
3997 struct create_lease *buf;
3999 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
4003 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4004 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4006 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4007 (struct create_lease, lcontext));
4008 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
4009 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4010 (struct create_lease, Name));
4011 buf->ccontext.NameLength = cpu_to_le16(4);
4012 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4021 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
4023 struct create_lease_v2 *buf;
4025 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
4029 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
4030 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
4032 buf->ccontext.DataOffset = cpu_to_le16(offsetof
4033 (struct create_lease_v2, lcontext));
4034 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
4035 buf->ccontext.NameOffset = cpu_to_le16(offsetof
4036 (struct create_lease_v2, Name));
4037 buf->ccontext.NameLength = cpu_to_le16(4);
4038 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4047 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4049 struct create_lease *lc = (struct create_lease *)buf;
4051 *epoch = 0; /* not used */
4052 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
4053 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4054 return le32_to_cpu(lc->lcontext.LeaseState);
4058 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
4060 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
4062 *epoch = le16_to_cpu(lc->lcontext.Epoch);
4063 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
4064 return SMB2_OPLOCK_LEVEL_NOCHANGE;
4066 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
4067 return le32_to_cpu(lc->lcontext.LeaseState);
4071 smb2_wp_retry_size(struct inode *inode)
4073 return min_t(unsigned int, CIFS_SB(inode->i_sb)->ctx->wsize,
4074 SMB2_MAX_BUFFER_SIZE);
4078 smb2_dir_needs_close(struct cifsFileInfo *cfile)
4080 return !cfile->invalidHandle;
4084 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
4085 struct smb_rqst *old_rq, __le16 cipher_type)
4087 struct smb2_sync_hdr *shdr =
4088 (struct smb2_sync_hdr *)old_rq->rq_iov[0].iov_base;
4090 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
4091 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
4092 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
4093 tr_hdr->Flags = cpu_to_le16(0x01);
4094 if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4095 (cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4096 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4098 get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4099 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
4102 /* We can not use the normal sg_set_buf() as we will sometimes pass a
4103 * stack object as buf.
4105 static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
4106 unsigned int buflen)
4110 * VMAP_STACK (at least) puts stack into the vmalloc address space
4112 if (is_vmalloc_addr(buf))
4113 addr = vmalloc_to_page(buf);
4115 addr = virt_to_page(buf);
4116 sg_set_page(sg, addr, buflen, offset_in_page(buf));
4119 /* Assumes the first rqst has a transform header as the first iov.
4121 * rqst[0].rq_iov[0] is transform header
4122 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
4123 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
4125 static struct scatterlist *
4126 init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign)
4128 unsigned int sg_len;
4129 struct scatterlist *sg;
4132 unsigned int idx = 0;
4136 for (i = 0; i < num_rqst; i++)
4137 sg_len += rqst[i].rq_nvec + rqst[i].rq_npages;
4139 sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
4143 sg_init_table(sg, sg_len);
4144 for (i = 0; i < num_rqst; i++) {
4145 for (j = 0; j < rqst[i].rq_nvec; j++) {
4147 * The first rqst has a transform header where the
4148 * first 20 bytes are not part of the encrypted blob
4150 skip = (i == 0) && (j == 0) ? 20 : 0;
4151 smb2_sg_set_buf(&sg[idx++],
4152 rqst[i].rq_iov[j].iov_base + skip,
4153 rqst[i].rq_iov[j].iov_len - skip);
4156 for (j = 0; j < rqst[i].rq_npages; j++) {
4157 unsigned int len, offset;
4159 rqst_page_get_length(&rqst[i], j, &len, &offset);
4160 sg_set_page(&sg[idx++], rqst[i].rq_pages[j], len, offset);
4163 smb2_sg_set_buf(&sg[idx], sign, SMB2_SIGNATURE_SIZE);
4168 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
4170 struct cifs_ses *ses;
4173 spin_lock(&cifs_tcp_ses_lock);
4174 list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
4175 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
4176 if (ses->Suid == ses_id) {
4177 ses_enc_key = enc ? ses->smb3encryptionkey :
4178 ses->smb3decryptionkey;
4179 memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE);
4180 spin_unlock(&cifs_tcp_ses_lock);
4185 spin_unlock(&cifs_tcp_ses_lock);
4190 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
4191 * iov[0] - transform header (associate data),
4192 * iov[1-N] - SMB2 header and pages - data to encrypt.
4193 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4197 crypt_message(struct TCP_Server_Info *server, int num_rqst,
4198 struct smb_rqst *rqst, int enc)
4200 struct smb2_transform_hdr *tr_hdr =
4201 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
4202 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
4204 struct scatterlist *sg;
4205 u8 sign[SMB2_SIGNATURE_SIZE] = {};
4206 u8 key[SMB3_ENC_DEC_KEY_SIZE];
4207 struct aead_request *req;
4209 unsigned int iv_len;
4210 DECLARE_CRYPTO_WAIT(wait);
4211 struct crypto_aead *tfm;
4212 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4214 rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key);
4216 cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
4221 rc = smb3_crypto_aead_allocate(server);
4223 cifs_server_dbg(VFS, "%s: crypto alloc failed\n", __func__);
4227 tfm = enc ? server->secmech.ccmaesencrypt :
4228 server->secmech.ccmaesdecrypt;
4230 if ((server->cipher_type == SMB2_ENCRYPTION_AES256_CCM) ||
4231 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4232 rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
4234 rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE);
4237 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
4241 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
4243 cifs_server_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
4247 req = aead_request_alloc(tfm, GFP_KERNEL);
4249 cifs_server_dbg(VFS, "%s: Failed to alloc aead request\n", __func__);
4254 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
4255 crypt_len += SMB2_SIGNATURE_SIZE;
4258 sg = init_sg(num_rqst, rqst, sign);
4260 cifs_server_dbg(VFS, "%s: Failed to init sg\n", __func__);
4265 iv_len = crypto_aead_ivsize(tfm);
4266 iv = kzalloc(iv_len, GFP_KERNEL);
4268 cifs_server_dbg(VFS, "%s: Failed to alloc iv\n", __func__);
4273 if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
4274 (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
4275 memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
4278 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
4281 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
4282 aead_request_set_ad(req, assoc_data_len);
4284 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
4285 crypto_req_done, &wait);
4287 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
4288 : crypto_aead_decrypt(req), &wait);
4291 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
4302 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
4306 for (i = 0; i < num_rqst; i++) {
4307 if (rqst[i].rq_pages) {
4308 for (j = rqst[i].rq_npages - 1; j >= 0; j--)
4309 put_page(rqst[i].rq_pages[j]);
4310 kfree(rqst[i].rq_pages);
4316 * This function will initialize new_rq and encrypt the content.
4317 * The first entry, new_rq[0], only contains a single iov which contains
4318 * a smb2_transform_hdr and is pre-allocated by the caller.
4319 * This function then populates new_rq[1+] with the content from olq_rq[0+].
4321 * The end result is an array of smb_rqst structures where the first structure
4322 * only contains a single iov for the transform header which we then can pass
4323 * to crypt_message().
4325 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4326 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
4329 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
4330 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
4332 struct page **pages;
4333 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
4334 unsigned int npages;
4335 unsigned int orig_len = 0;
4339 for (i = 1; i < num_rqst; i++) {
4340 npages = old_rq[i - 1].rq_npages;
4341 pages = kmalloc_array(npages, sizeof(struct page *),
4346 new_rq[i].rq_pages = pages;
4347 new_rq[i].rq_npages = npages;
4348 new_rq[i].rq_offset = old_rq[i - 1].rq_offset;
4349 new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz;
4350 new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz;
4351 new_rq[i].rq_iov = old_rq[i - 1].rq_iov;
4352 new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec;
4354 orig_len += smb_rqst_len(server, &old_rq[i - 1]);
4356 for (j = 0; j < npages; j++) {
4357 pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4362 /* copy pages form the old */
4363 for (j = 0; j < npages; j++) {
4365 unsigned int offset, len;
4367 rqst_page_get_length(&new_rq[i], j, &len, &offset);
4369 dst = (char *) kmap(new_rq[i].rq_pages[j]) + offset;
4370 src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset;
4372 memcpy(dst, src, len);
4373 kunmap(new_rq[i].rq_pages[j]);
4374 kunmap(old_rq[i - 1].rq_pages[j]);
4378 /* fill the 1st iov with a transform header */
4379 fill_transform_hdr(tr_hdr, orig_len, old_rq, server->cipher_type);
4381 rc = crypt_message(server, num_rqst, new_rq, 1);
4382 cifs_dbg(FYI, "Encrypt message returned %d\n", rc);
4389 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
4394 smb3_is_transform_hdr(void *buf)
4396 struct smb2_transform_hdr *trhdr = buf;
4398 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
4402 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
4403 unsigned int buf_data_size, struct page **pages,
4404 unsigned int npages, unsigned int page_data_size,
4408 struct smb_rqst rqst = {NULL};
4411 iov[0].iov_base = buf;
4412 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
4413 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
4414 iov[1].iov_len = buf_data_size;
4418 rqst.rq_pages = pages;
4419 rqst.rq_npages = npages;
4420 rqst.rq_pagesz = PAGE_SIZE;
4421 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
4423 rc = crypt_message(server, 1, &rqst, 0);
4424 cifs_dbg(FYI, "Decrypt message returned %d\n", rc);
4429 memmove(buf, iov[1].iov_base, buf_data_size);
4432 server->total_read = buf_data_size + page_data_size;
4438 read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
4439 unsigned int npages, unsigned int len)
4444 for (i = 0; i < npages; i++) {
4445 struct page *page = pages[i];
4449 if (len >= PAGE_SIZE) {
4450 /* enough data to fill the page */
4454 zero_user(page, len, PAGE_SIZE - len);
4457 length = cifs_read_page_from_socket(server, page, 0, n);
4460 server->total_read += length;
4467 init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
4468 unsigned int cur_off, struct bio_vec **page_vec)
4470 struct bio_vec *bvec;
4473 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
4477 for (i = 0; i < npages; i++) {
4478 bvec[i].bv_page = pages[i];
4479 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
4480 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
4481 data_size -= bvec[i].bv_len;
4484 if (data_size != 0) {
4485 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
4495 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
4496 char *buf, unsigned int buf_len, struct page **pages,
4497 unsigned int npages, unsigned int page_data_size,
4500 unsigned int data_offset;
4501 unsigned int data_len;
4502 unsigned int cur_off;
4503 unsigned int cur_page_idx;
4504 unsigned int pad_len;
4505 struct cifs_readdata *rdata = mid->callback_data;
4506 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
4507 struct bio_vec *bvec = NULL;
4508 struct iov_iter iter;
4511 bool use_rdma_mr = false;
4513 if (shdr->Command != SMB2_READ) {
4514 cifs_server_dbg(VFS, "only big read responses are supported\n");
4518 if (server->ops->is_session_expired &&
4519 server->ops->is_session_expired(buf)) {
4521 cifs_reconnect(server);
4525 if (server->ops->is_status_pending &&
4526 server->ops->is_status_pending(buf, server))
4529 /* set up first two iov to get credits */
4530 rdata->iov[0].iov_base = buf;
4531 rdata->iov[0].iov_len = 0;
4532 rdata->iov[1].iov_base = buf;
4533 rdata->iov[1].iov_len =
4534 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
4535 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
4536 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
4537 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
4538 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
4540 rdata->result = server->ops->map_error(buf, true);
4541 if (rdata->result != 0) {
4542 cifs_dbg(FYI, "%s: server returned error %d\n",
4543 __func__, rdata->result);
4544 /* normal error on read response */
4546 mid->mid_state = MID_RESPONSE_RECEIVED;
4548 dequeue_mid(mid, false);
4552 data_offset = server->ops->read_data_offset(buf);
4553 #ifdef CONFIG_CIFS_SMB_DIRECT
4554 use_rdma_mr = rdata->mr;
4556 data_len = server->ops->read_data_length(buf, use_rdma_mr);
4558 if (data_offset < server->vals->read_rsp_size) {
4560 * win2k8 sometimes sends an offset of 0 when the read
4561 * is beyond the EOF. Treat it as if the data starts just after
4564 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
4565 __func__, data_offset);
4566 data_offset = server->vals->read_rsp_size;
4567 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
4568 /* data_offset is beyond the end of smallbuf */
4569 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
4570 __func__, data_offset);
4571 rdata->result = -EIO;
4573 mid->mid_state = MID_RESPONSE_MALFORMED;
4575 dequeue_mid(mid, rdata->result);
4579 pad_len = data_offset - server->vals->read_rsp_size;
4581 if (buf_len <= data_offset) {
4582 /* read response payload is in pages */
4583 cur_page_idx = pad_len / PAGE_SIZE;
4584 cur_off = pad_len % PAGE_SIZE;
4586 if (cur_page_idx != 0) {
4587 /* data offset is beyond the 1st page of response */
4588 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
4589 __func__, data_offset);
4590 rdata->result = -EIO;
4592 mid->mid_state = MID_RESPONSE_MALFORMED;
4594 dequeue_mid(mid, rdata->result);
4598 if (data_len > page_data_size - pad_len) {
4599 /* data_len is corrupt -- discard frame */
4600 rdata->result = -EIO;
4602 mid->mid_state = MID_RESPONSE_MALFORMED;
4604 dequeue_mid(mid, rdata->result);
4608 rdata->result = init_read_bvec(pages, npages, page_data_size,
4610 if (rdata->result != 0) {
4612 mid->mid_state = MID_RESPONSE_MALFORMED;
4614 dequeue_mid(mid, rdata->result);
4618 iov_iter_bvec(&iter, WRITE, bvec, npages, data_len);
4619 } else if (buf_len >= data_offset + data_len) {
4620 /* read response payload is in buf */
4621 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
4622 iov.iov_base = buf + data_offset;
4623 iov.iov_len = data_len;
4624 iov_iter_kvec(&iter, WRITE, &iov, 1, data_len);
4626 /* read response payload cannot be in both buf and pages */
4627 WARN_ONCE(1, "buf can not contain only a part of read data");
4628 rdata->result = -EIO;
4630 mid->mid_state = MID_RESPONSE_MALFORMED;
4632 dequeue_mid(mid, rdata->result);
4636 length = rdata->copy_into_pages(server, rdata, &iter);
4644 mid->mid_state = MID_RESPONSE_RECEIVED;
4646 dequeue_mid(mid, false);
4650 struct smb2_decrypt_work {
4651 struct work_struct decrypt;
4652 struct TCP_Server_Info *server;
4653 struct page **ppages;
4655 unsigned int npages;
4660 static void smb2_decrypt_offload(struct work_struct *work)
4662 struct smb2_decrypt_work *dw = container_of(work,
4663 struct smb2_decrypt_work, decrypt);
4665 struct mid_q_entry *mid;
4667 rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
4668 dw->ppages, dw->npages, dw->len, true);
4670 cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
4674 dw->server->lstrp = jiffies;
4675 mid = smb2_find_dequeue_mid(dw->server, dw->buf);
4677 cifs_dbg(FYI, "mid not found\n");
4679 mid->decrypted = true;
4680 rc = handle_read_data(dw->server, mid, dw->buf,
4681 dw->server->vals->read_rsp_size,
4682 dw->ppages, dw->npages, dw->len,
4685 #ifdef CONFIG_CIFS_STATS2
4686 mid->when_received = jiffies;
4688 if (dw->server->ops->is_network_name_deleted)
4689 dw->server->ops->is_network_name_deleted(dw->buf,
4694 spin_lock(&GlobalMid_Lock);
4695 if (dw->server->tcpStatus == CifsNeedReconnect) {
4696 mid->mid_state = MID_RETRY_NEEDED;
4697 spin_unlock(&GlobalMid_Lock);
4700 mid->mid_state = MID_REQUEST_SUBMITTED;
4701 mid->mid_flags &= ~(MID_DELETED);
4702 list_add_tail(&mid->qhead,
4703 &dw->server->pending_mid_q);
4704 spin_unlock(&GlobalMid_Lock);
4707 cifs_mid_q_entry_release(mid);
4711 for (i = dw->npages-1; i >= 0; i--)
4712 put_page(dw->ppages[i]);
4715 cifs_small_buf_release(dw->buf);
4721 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
4724 char *buf = server->smallbuf;
4725 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4726 unsigned int npages;
4727 struct page **pages;
4729 unsigned int buflen = server->pdu_size;
4732 struct smb2_decrypt_work *dw;
4735 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
4736 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
4738 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
4741 server->total_read += rc;
4743 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
4744 server->vals->read_rsp_size;
4745 npages = DIV_ROUND_UP(len, PAGE_SIZE);
4747 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
4753 for (; i < npages; i++) {
4754 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
4761 /* read read data into pages */
4762 rc = read_data_into_pages(server, pages, npages, len);
4766 rc = cifs_discard_remaining_data(server);
4771 * For large reads, offload to different thread for better performance,
4772 * use more cores decrypting which can be expensive
4775 if ((server->min_offload) && (server->in_flight > 1) &&
4776 (server->pdu_size >= server->min_offload)) {
4777 dw = kmalloc(sizeof(struct smb2_decrypt_work), GFP_KERNEL);
4779 goto non_offloaded_decrypt;
4781 dw->buf = server->smallbuf;
4782 server->smallbuf = (char *)cifs_small_buf_get();
4784 INIT_WORK(&dw->decrypt, smb2_decrypt_offload);
4786 dw->npages = npages;
4787 dw->server = server;
4790 queue_work(decrypt_wq, &dw->decrypt);
4791 *num_mids = 0; /* worker thread takes care of finding mid */
4795 non_offloaded_decrypt:
4796 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
4797 pages, npages, len, false);
4801 *mid = smb2_find_mid(server, buf);
4803 cifs_dbg(FYI, "mid not found\n");
4805 cifs_dbg(FYI, "mid found\n");
4806 (*mid)->decrypted = true;
4807 rc = handle_read_data(server, *mid, buf,
4808 server->vals->read_rsp_size,
4809 pages, npages, len, false);
4811 if (server->ops->is_network_name_deleted) {
4812 server->ops->is_network_name_deleted(buf,
4819 for (i = i - 1; i >= 0; i--)
4824 cifs_discard_remaining_data(server);
4829 receive_encrypted_standard(struct TCP_Server_Info *server,
4830 struct mid_q_entry **mids, char **bufs,
4834 char *buf = server->smallbuf;
4835 struct smb2_sync_hdr *shdr;
4836 unsigned int pdu_length = server->pdu_size;
4837 unsigned int buf_size;
4838 struct mid_q_entry *mid_entry;
4840 char *next_buffer = NULL;
4844 /* switch to large buffer if too big for a small one */
4845 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
4846 server->large_buf = true;
4847 memcpy(server->bigbuf, buf, server->total_read);
4848 buf = server->bigbuf;
4851 /* now read the rest */
4852 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
4853 pdu_length - HEADER_SIZE(server) + 1);
4856 server->total_read += length;
4858 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
4859 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0, false);
4863 next_is_large = server->large_buf;
4865 shdr = (struct smb2_sync_hdr *)buf;
4866 if (shdr->NextCommand) {
4868 next_buffer = (char *)cifs_buf_get();
4870 next_buffer = (char *)cifs_small_buf_get();
4872 buf + le32_to_cpu(shdr->NextCommand),
4873 pdu_length - le32_to_cpu(shdr->NextCommand));
4876 mid_entry = smb2_find_mid(server, buf);
4877 if (mid_entry == NULL)
4878 cifs_dbg(FYI, "mid not found\n");
4880 cifs_dbg(FYI, "mid found\n");
4881 mid_entry->decrypted = true;
4882 mid_entry->resp_buf_size = server->pdu_size;
4885 if (*num_mids >= MAX_COMPOUND) {
4886 cifs_server_dbg(VFS, "too many PDUs in compound\n");
4889 bufs[*num_mids] = buf;
4890 mids[(*num_mids)++] = mid_entry;
4892 if (mid_entry && mid_entry->handle)
4893 ret = mid_entry->handle(server, mid_entry);
4895 ret = cifs_handle_standard(server, mid_entry);
4897 if (ret == 0 && shdr->NextCommand) {
4898 pdu_length -= le32_to_cpu(shdr->NextCommand);
4899 server->large_buf = next_is_large;
4901 server->bigbuf = buf = next_buffer;
4903 server->smallbuf = buf = next_buffer;
4905 } else if (ret != 0) {
4907 * ret != 0 here means that we didn't get to handle_mid() thus
4908 * server->smallbuf and server->bigbuf are still valid. We need
4909 * to free next_buffer because it is not going to be used
4913 free_rsp_buf(CIFS_LARGE_BUFFER, next_buffer);
4915 free_rsp_buf(CIFS_SMALL_BUFFER, next_buffer);
4922 smb3_receive_transform(struct TCP_Server_Info *server,
4923 struct mid_q_entry **mids, char **bufs, int *num_mids)
4925 char *buf = server->smallbuf;
4926 unsigned int pdu_length = server->pdu_size;
4927 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
4928 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
4930 if (pdu_length < sizeof(struct smb2_transform_hdr) +
4931 sizeof(struct smb2_sync_hdr)) {
4932 cifs_server_dbg(VFS, "Transform message is too small (%u)\n",
4934 cifs_reconnect(server);
4935 return -ECONNABORTED;
4938 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
4939 cifs_server_dbg(VFS, "Transform message is broken\n");
4940 cifs_reconnect(server);
4941 return -ECONNABORTED;
4944 /* TODO: add support for compounds containing READ. */
4945 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
4946 return receive_encrypted_read(server, &mids[0], num_mids);
4949 return receive_encrypted_standard(server, mids, bufs, num_mids);
4953 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
4955 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
4957 return handle_read_data(server, mid, buf, server->pdu_size,
4962 smb2_next_header(char *buf)
4964 struct smb2_sync_hdr *hdr = (struct smb2_sync_hdr *)buf;
4965 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
4967 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
4968 return sizeof(struct smb2_transform_hdr) +
4969 le32_to_cpu(t_hdr->OriginalMessageSize);
4971 return le32_to_cpu(hdr->NextCommand);
4975 smb2_make_node(unsigned int xid, struct inode *inode,
4976 struct dentry *dentry, struct cifs_tcon *tcon,
4977 const char *full_path, umode_t mode, dev_t dev)
4979 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
4981 FILE_ALL_INFO *buf = NULL;
4982 struct cifs_io_parms io_parms = {0};
4984 struct cifs_fid fid;
4985 struct cifs_open_parms oparms;
4986 unsigned int bytes_written;
4987 struct win_dev *pdev;
4991 * Check if mounted with mount parm 'sfu' mount parm.
4992 * SFU emulation should work with all servers, but only
4993 * supports block and char device (no socket & fifo),
4994 * and was used by default in earlier versions of Windows
4996 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
5000 * TODO: Add ability to create instead via reparse point. Windows (e.g.
5001 * their current NFS server) uses this approach to expose special files
5002 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
5005 if (!S_ISCHR(mode) && !S_ISBLK(mode))
5008 cifs_dbg(FYI, "sfu compat create special file\n");
5010 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
5017 oparms.cifs_sb = cifs_sb;
5018 oparms.desired_access = GENERIC_WRITE;
5019 oparms.create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR |
5020 CREATE_OPTION_SPECIAL);
5021 oparms.disposition = FILE_CREATE;
5022 oparms.path = full_path;
5024 oparms.reconnect = false;
5026 if (tcon->ses->server->oplocks)
5027 oplock = REQ_OPLOCK;
5030 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf);
5035 * BB Do not bother to decode buf since no local inode yet to put
5036 * timestamps in, but we can reuse it safely.
5039 pdev = (struct win_dev *)buf;
5040 io_parms.pid = current->tgid;
5041 io_parms.tcon = tcon;
5042 io_parms.offset = 0;
5043 io_parms.length = sizeof(struct win_dev);
5044 iov[1].iov_base = buf;
5045 iov[1].iov_len = sizeof(struct win_dev);
5046 if (S_ISCHR(mode)) {
5047 memcpy(pdev->type, "IntxCHR", 8);
5048 pdev->major = cpu_to_le64(MAJOR(dev));
5049 pdev->minor = cpu_to_le64(MINOR(dev));
5050 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5051 &bytes_written, iov, 1);
5052 } else if (S_ISBLK(mode)) {
5053 memcpy(pdev->type, "IntxBLK", 8);
5054 pdev->major = cpu_to_le64(MAJOR(dev));
5055 pdev->minor = cpu_to_le64(MINOR(dev));
5056 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
5057 &bytes_written, iov, 1);
5059 tcon->ses->server->ops->close(xid, tcon, &fid);
5062 /* FIXME: add code here to set EAs */
5069 struct smb_version_operations smb20_operations = {
5070 .compare_fids = smb2_compare_fids,
5071 .setup_request = smb2_setup_request,
5072 .setup_async_request = smb2_setup_async_request,
5073 .check_receive = smb2_check_receive,
5074 .add_credits = smb2_add_credits,
5075 .set_credits = smb2_set_credits,
5076 .get_credits_field = smb2_get_credits_field,
5077 .get_credits = smb2_get_credits,
5078 .wait_mtu_credits = cifs_wait_mtu_credits,
5079 .get_next_mid = smb2_get_next_mid,
5080 .revert_current_mid = smb2_revert_current_mid,
5081 .read_data_offset = smb2_read_data_offset,
5082 .read_data_length = smb2_read_data_length,
5083 .map_error = map_smb2_to_linux_error,
5084 .find_mid = smb2_find_mid,
5085 .check_message = smb2_check_message,
5086 .dump_detail = smb2_dump_detail,
5087 .clear_stats = smb2_clear_stats,
5088 .print_stats = smb2_print_stats,
5089 .is_oplock_break = smb2_is_valid_oplock_break,
5090 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5091 .downgrade_oplock = smb2_downgrade_oplock,
5092 .need_neg = smb2_need_neg,
5093 .negotiate = smb2_negotiate,
5094 .negotiate_wsize = smb2_negotiate_wsize,
5095 .negotiate_rsize = smb2_negotiate_rsize,
5096 .sess_setup = SMB2_sess_setup,
5097 .logoff = SMB2_logoff,
5098 .tree_connect = SMB2_tcon,
5099 .tree_disconnect = SMB2_tdis,
5100 .qfs_tcon = smb2_qfs_tcon,
5101 .is_path_accessible = smb2_is_path_accessible,
5102 .can_echo = smb2_can_echo,
5104 .query_path_info = smb2_query_path_info,
5105 .get_srv_inum = smb2_get_srv_inum,
5106 .query_file_info = smb2_query_file_info,
5107 .set_path_size = smb2_set_path_size,
5108 .set_file_size = smb2_set_file_size,
5109 .set_file_info = smb2_set_file_info,
5110 .set_compression = smb2_set_compression,
5111 .mkdir = smb2_mkdir,
5112 .mkdir_setinfo = smb2_mkdir_setinfo,
5113 .rmdir = smb2_rmdir,
5114 .unlink = smb2_unlink,
5115 .rename = smb2_rename_path,
5116 .create_hardlink = smb2_create_hardlink,
5117 .query_symlink = smb2_query_symlink,
5118 .query_mf_symlink = smb3_query_mf_symlink,
5119 .create_mf_symlink = smb3_create_mf_symlink,
5120 .open = smb2_open_file,
5121 .set_fid = smb2_set_fid,
5122 .close = smb2_close_file,
5123 .flush = smb2_flush_file,
5124 .async_readv = smb2_async_readv,
5125 .async_writev = smb2_async_writev,
5126 .sync_read = smb2_sync_read,
5127 .sync_write = smb2_sync_write,
5128 .query_dir_first = smb2_query_dir_first,
5129 .query_dir_next = smb2_query_dir_next,
5130 .close_dir = smb2_close_dir,
5131 .calc_smb_size = smb2_calc_size,
5132 .is_status_pending = smb2_is_status_pending,
5133 .is_session_expired = smb2_is_session_expired,
5134 .oplock_response = smb2_oplock_response,
5135 .queryfs = smb2_queryfs,
5136 .mand_lock = smb2_mand_lock,
5137 .mand_unlock_range = smb2_unlock_range,
5138 .push_mand_locks = smb2_push_mandatory_locks,
5139 .get_lease_key = smb2_get_lease_key,
5140 .set_lease_key = smb2_set_lease_key,
5141 .new_lease_key = smb2_new_lease_key,
5142 .calc_signature = smb2_calc_signature,
5143 .is_read_op = smb2_is_read_op,
5144 .set_oplock_level = smb2_set_oplock_level,
5145 .create_lease_buf = smb2_create_lease_buf,
5146 .parse_lease_buf = smb2_parse_lease_buf,
5147 .copychunk_range = smb2_copychunk_range,
5148 .wp_retry_size = smb2_wp_retry_size,
5149 .dir_needs_close = smb2_dir_needs_close,
5150 .get_dfs_refer = smb2_get_dfs_refer,
5151 .select_sectype = smb2_select_sectype,
5152 #ifdef CONFIG_CIFS_XATTR
5153 .query_all_EAs = smb2_query_eas,
5154 .set_EA = smb2_set_ea,
5155 #endif /* CIFS_XATTR */
5156 .get_acl = get_smb2_acl,
5157 .get_acl_by_fid = get_smb2_acl_by_fid,
5158 .set_acl = set_smb2_acl,
5159 .next_header = smb2_next_header,
5160 .ioctl_query_info = smb2_ioctl_query_info,
5161 .make_node = smb2_make_node,
5162 .fiemap = smb3_fiemap,
5163 .llseek = smb3_llseek,
5164 .is_status_io_timeout = smb2_is_status_io_timeout,
5165 .is_network_name_deleted = smb2_is_network_name_deleted,
5168 struct smb_version_operations smb21_operations = {
5169 .compare_fids = smb2_compare_fids,
5170 .setup_request = smb2_setup_request,
5171 .setup_async_request = smb2_setup_async_request,
5172 .check_receive = smb2_check_receive,
5173 .add_credits = smb2_add_credits,
5174 .set_credits = smb2_set_credits,
5175 .get_credits_field = smb2_get_credits_field,
5176 .get_credits = smb2_get_credits,
5177 .wait_mtu_credits = smb2_wait_mtu_credits,
5178 .adjust_credits = smb2_adjust_credits,
5179 .get_next_mid = smb2_get_next_mid,
5180 .revert_current_mid = smb2_revert_current_mid,
5181 .read_data_offset = smb2_read_data_offset,
5182 .read_data_length = smb2_read_data_length,
5183 .map_error = map_smb2_to_linux_error,
5184 .find_mid = smb2_find_mid,
5185 .check_message = smb2_check_message,
5186 .dump_detail = smb2_dump_detail,
5187 .clear_stats = smb2_clear_stats,
5188 .print_stats = smb2_print_stats,
5189 .is_oplock_break = smb2_is_valid_oplock_break,
5190 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5191 .downgrade_oplock = smb2_downgrade_oplock,
5192 .need_neg = smb2_need_neg,
5193 .negotiate = smb2_negotiate,
5194 .negotiate_wsize = smb2_negotiate_wsize,
5195 .negotiate_rsize = smb2_negotiate_rsize,
5196 .sess_setup = SMB2_sess_setup,
5197 .logoff = SMB2_logoff,
5198 .tree_connect = SMB2_tcon,
5199 .tree_disconnect = SMB2_tdis,
5200 .qfs_tcon = smb2_qfs_tcon,
5201 .is_path_accessible = smb2_is_path_accessible,
5202 .can_echo = smb2_can_echo,
5204 .query_path_info = smb2_query_path_info,
5205 .get_srv_inum = smb2_get_srv_inum,
5206 .query_file_info = smb2_query_file_info,
5207 .set_path_size = smb2_set_path_size,
5208 .set_file_size = smb2_set_file_size,
5209 .set_file_info = smb2_set_file_info,
5210 .set_compression = smb2_set_compression,
5211 .mkdir = smb2_mkdir,
5212 .mkdir_setinfo = smb2_mkdir_setinfo,
5213 .rmdir = smb2_rmdir,
5214 .unlink = smb2_unlink,
5215 .rename = smb2_rename_path,
5216 .create_hardlink = smb2_create_hardlink,
5217 .query_symlink = smb2_query_symlink,
5218 .query_mf_symlink = smb3_query_mf_symlink,
5219 .create_mf_symlink = smb3_create_mf_symlink,
5220 .open = smb2_open_file,
5221 .set_fid = smb2_set_fid,
5222 .close = smb2_close_file,
5223 .flush = smb2_flush_file,
5224 .async_readv = smb2_async_readv,
5225 .async_writev = smb2_async_writev,
5226 .sync_read = smb2_sync_read,
5227 .sync_write = smb2_sync_write,
5228 .query_dir_first = smb2_query_dir_first,
5229 .query_dir_next = smb2_query_dir_next,
5230 .close_dir = smb2_close_dir,
5231 .calc_smb_size = smb2_calc_size,
5232 .is_status_pending = smb2_is_status_pending,
5233 .is_session_expired = smb2_is_session_expired,
5234 .oplock_response = smb2_oplock_response,
5235 .queryfs = smb2_queryfs,
5236 .mand_lock = smb2_mand_lock,
5237 .mand_unlock_range = smb2_unlock_range,
5238 .push_mand_locks = smb2_push_mandatory_locks,
5239 .get_lease_key = smb2_get_lease_key,
5240 .set_lease_key = smb2_set_lease_key,
5241 .new_lease_key = smb2_new_lease_key,
5242 .calc_signature = smb2_calc_signature,
5243 .is_read_op = smb21_is_read_op,
5244 .set_oplock_level = smb21_set_oplock_level,
5245 .create_lease_buf = smb2_create_lease_buf,
5246 .parse_lease_buf = smb2_parse_lease_buf,
5247 .copychunk_range = smb2_copychunk_range,
5248 .wp_retry_size = smb2_wp_retry_size,
5249 .dir_needs_close = smb2_dir_needs_close,
5250 .enum_snapshots = smb3_enum_snapshots,
5251 .notify = smb3_notify,
5252 .get_dfs_refer = smb2_get_dfs_refer,
5253 .select_sectype = smb2_select_sectype,
5254 #ifdef CONFIG_CIFS_XATTR
5255 .query_all_EAs = smb2_query_eas,
5256 .set_EA = smb2_set_ea,
5257 #endif /* CIFS_XATTR */
5258 .get_acl = get_smb2_acl,
5259 .get_acl_by_fid = get_smb2_acl_by_fid,
5260 .set_acl = set_smb2_acl,
5261 .next_header = smb2_next_header,
5262 .ioctl_query_info = smb2_ioctl_query_info,
5263 .make_node = smb2_make_node,
5264 .fiemap = smb3_fiemap,
5265 .llseek = smb3_llseek,
5266 .is_status_io_timeout = smb2_is_status_io_timeout,
5267 .is_network_name_deleted = smb2_is_network_name_deleted,
5270 struct smb_version_operations smb30_operations = {
5271 .compare_fids = smb2_compare_fids,
5272 .setup_request = smb2_setup_request,
5273 .setup_async_request = smb2_setup_async_request,
5274 .check_receive = smb2_check_receive,
5275 .add_credits = smb2_add_credits,
5276 .set_credits = smb2_set_credits,
5277 .get_credits_field = smb2_get_credits_field,
5278 .get_credits = smb2_get_credits,
5279 .wait_mtu_credits = smb2_wait_mtu_credits,
5280 .adjust_credits = smb2_adjust_credits,
5281 .get_next_mid = smb2_get_next_mid,
5282 .revert_current_mid = smb2_revert_current_mid,
5283 .read_data_offset = smb2_read_data_offset,
5284 .read_data_length = smb2_read_data_length,
5285 .map_error = map_smb2_to_linux_error,
5286 .find_mid = smb2_find_mid,
5287 .check_message = smb2_check_message,
5288 .dump_detail = smb2_dump_detail,
5289 .clear_stats = smb2_clear_stats,
5290 .print_stats = smb2_print_stats,
5291 .dump_share_caps = smb2_dump_share_caps,
5292 .is_oplock_break = smb2_is_valid_oplock_break,
5293 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5294 .downgrade_oplock = smb3_downgrade_oplock,
5295 .need_neg = smb2_need_neg,
5296 .negotiate = smb2_negotiate,
5297 .negotiate_wsize = smb3_negotiate_wsize,
5298 .negotiate_rsize = smb3_negotiate_rsize,
5299 .sess_setup = SMB2_sess_setup,
5300 .logoff = SMB2_logoff,
5301 .tree_connect = SMB2_tcon,
5302 .tree_disconnect = SMB2_tdis,
5303 .qfs_tcon = smb3_qfs_tcon,
5304 .is_path_accessible = smb2_is_path_accessible,
5305 .can_echo = smb2_can_echo,
5307 .query_path_info = smb2_query_path_info,
5308 /* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */
5309 .query_reparse_tag = smb2_query_reparse_tag,
5310 .get_srv_inum = smb2_get_srv_inum,
5311 .query_file_info = smb2_query_file_info,
5312 .set_path_size = smb2_set_path_size,
5313 .set_file_size = smb2_set_file_size,
5314 .set_file_info = smb2_set_file_info,
5315 .set_compression = smb2_set_compression,
5316 .mkdir = smb2_mkdir,
5317 .mkdir_setinfo = smb2_mkdir_setinfo,
5318 .rmdir = smb2_rmdir,
5319 .unlink = smb2_unlink,
5320 .rename = smb2_rename_path,
5321 .create_hardlink = smb2_create_hardlink,
5322 .query_symlink = smb2_query_symlink,
5323 .query_mf_symlink = smb3_query_mf_symlink,
5324 .create_mf_symlink = smb3_create_mf_symlink,
5325 .open = smb2_open_file,
5326 .set_fid = smb2_set_fid,
5327 .close = smb2_close_file,
5328 .close_getattr = smb2_close_getattr,
5329 .flush = smb2_flush_file,
5330 .async_readv = smb2_async_readv,
5331 .async_writev = smb2_async_writev,
5332 .sync_read = smb2_sync_read,
5333 .sync_write = smb2_sync_write,
5334 .query_dir_first = smb2_query_dir_first,
5335 .query_dir_next = smb2_query_dir_next,
5336 .close_dir = smb2_close_dir,
5337 .calc_smb_size = smb2_calc_size,
5338 .is_status_pending = smb2_is_status_pending,
5339 .is_session_expired = smb2_is_session_expired,
5340 .oplock_response = smb2_oplock_response,
5341 .queryfs = smb2_queryfs,
5342 .mand_lock = smb2_mand_lock,
5343 .mand_unlock_range = smb2_unlock_range,
5344 .push_mand_locks = smb2_push_mandatory_locks,
5345 .get_lease_key = smb2_get_lease_key,
5346 .set_lease_key = smb2_set_lease_key,
5347 .new_lease_key = smb2_new_lease_key,
5348 .generate_signingkey = generate_smb30signingkey,
5349 .calc_signature = smb3_calc_signature,
5350 .set_integrity = smb3_set_integrity,
5351 .is_read_op = smb21_is_read_op,
5352 .set_oplock_level = smb3_set_oplock_level,
5353 .create_lease_buf = smb3_create_lease_buf,
5354 .parse_lease_buf = smb3_parse_lease_buf,
5355 .copychunk_range = smb2_copychunk_range,
5356 .duplicate_extents = smb2_duplicate_extents,
5357 .validate_negotiate = smb3_validate_negotiate,
5358 .wp_retry_size = smb2_wp_retry_size,
5359 .dir_needs_close = smb2_dir_needs_close,
5360 .fallocate = smb3_fallocate,
5361 .enum_snapshots = smb3_enum_snapshots,
5362 .notify = smb3_notify,
5363 .init_transform_rq = smb3_init_transform_rq,
5364 .is_transform_hdr = smb3_is_transform_hdr,
5365 .receive_transform = smb3_receive_transform,
5366 .get_dfs_refer = smb2_get_dfs_refer,
5367 .select_sectype = smb2_select_sectype,
5368 #ifdef CONFIG_CIFS_XATTR
5369 .query_all_EAs = smb2_query_eas,
5370 .set_EA = smb2_set_ea,
5371 #endif /* CIFS_XATTR */
5372 .get_acl = get_smb2_acl,
5373 .get_acl_by_fid = get_smb2_acl_by_fid,
5374 .set_acl = set_smb2_acl,
5375 .next_header = smb2_next_header,
5376 .ioctl_query_info = smb2_ioctl_query_info,
5377 .make_node = smb2_make_node,
5378 .fiemap = smb3_fiemap,
5379 .llseek = smb3_llseek,
5380 .is_status_io_timeout = smb2_is_status_io_timeout,
5381 .is_network_name_deleted = smb2_is_network_name_deleted,
5384 struct smb_version_operations smb311_operations = {
5385 .compare_fids = smb2_compare_fids,
5386 .setup_request = smb2_setup_request,
5387 .setup_async_request = smb2_setup_async_request,
5388 .check_receive = smb2_check_receive,
5389 .add_credits = smb2_add_credits,
5390 .set_credits = smb2_set_credits,
5391 .get_credits_field = smb2_get_credits_field,
5392 .get_credits = smb2_get_credits,
5393 .wait_mtu_credits = smb2_wait_mtu_credits,
5394 .adjust_credits = smb2_adjust_credits,
5395 .get_next_mid = smb2_get_next_mid,
5396 .revert_current_mid = smb2_revert_current_mid,
5397 .read_data_offset = smb2_read_data_offset,
5398 .read_data_length = smb2_read_data_length,
5399 .map_error = map_smb2_to_linux_error,
5400 .find_mid = smb2_find_mid,
5401 .check_message = smb2_check_message,
5402 .dump_detail = smb2_dump_detail,
5403 .clear_stats = smb2_clear_stats,
5404 .print_stats = smb2_print_stats,
5405 .dump_share_caps = smb2_dump_share_caps,
5406 .is_oplock_break = smb2_is_valid_oplock_break,
5407 .handle_cancelled_mid = smb2_handle_cancelled_mid,
5408 .downgrade_oplock = smb3_downgrade_oplock,
5409 .need_neg = smb2_need_neg,
5410 .negotiate = smb2_negotiate,
5411 .negotiate_wsize = smb3_negotiate_wsize,
5412 .negotiate_rsize = smb3_negotiate_rsize,
5413 .sess_setup = SMB2_sess_setup,
5414 .logoff = SMB2_logoff,
5415 .tree_connect = SMB2_tcon,
5416 .tree_disconnect = SMB2_tdis,
5417 .qfs_tcon = smb3_qfs_tcon,
5418 .is_path_accessible = smb2_is_path_accessible,
5419 .can_echo = smb2_can_echo,
5421 .query_path_info = smb2_query_path_info,
5422 .query_reparse_tag = smb2_query_reparse_tag,
5423 .get_srv_inum = smb2_get_srv_inum,
5424 .query_file_info = smb2_query_file_info,
5425 .set_path_size = smb2_set_path_size,
5426 .set_file_size = smb2_set_file_size,
5427 .set_file_info = smb2_set_file_info,
5428 .set_compression = smb2_set_compression,
5429 .mkdir = smb2_mkdir,
5430 .mkdir_setinfo = smb2_mkdir_setinfo,
5431 .posix_mkdir = smb311_posix_mkdir,
5432 .rmdir = smb2_rmdir,
5433 .unlink = smb2_unlink,
5434 .rename = smb2_rename_path,
5435 .create_hardlink = smb2_create_hardlink,
5436 .query_symlink = smb2_query_symlink,
5437 .query_mf_symlink = smb3_query_mf_symlink,
5438 .create_mf_symlink = smb3_create_mf_symlink,
5439 .open = smb2_open_file,
5440 .set_fid = smb2_set_fid,
5441 .close = smb2_close_file,
5442 .close_getattr = smb2_close_getattr,
5443 .flush = smb2_flush_file,
5444 .async_readv = smb2_async_readv,
5445 .async_writev = smb2_async_writev,
5446 .sync_read = smb2_sync_read,
5447 .sync_write = smb2_sync_write,
5448 .query_dir_first = smb2_query_dir_first,
5449 .query_dir_next = smb2_query_dir_next,
5450 .close_dir = smb2_close_dir,
5451 .calc_smb_size = smb2_calc_size,
5452 .is_status_pending = smb2_is_status_pending,
5453 .is_session_expired = smb2_is_session_expired,
5454 .oplock_response = smb2_oplock_response,
5455 .queryfs = smb311_queryfs,
5456 .mand_lock = smb2_mand_lock,
5457 .mand_unlock_range = smb2_unlock_range,
5458 .push_mand_locks = smb2_push_mandatory_locks,
5459 .get_lease_key = smb2_get_lease_key,
5460 .set_lease_key = smb2_set_lease_key,
5461 .new_lease_key = smb2_new_lease_key,
5462 .generate_signingkey = generate_smb311signingkey,
5463 .calc_signature = smb3_calc_signature,
5464 .set_integrity = smb3_set_integrity,
5465 .is_read_op = smb21_is_read_op,
5466 .set_oplock_level = smb3_set_oplock_level,
5467 .create_lease_buf = smb3_create_lease_buf,
5468 .parse_lease_buf = smb3_parse_lease_buf,
5469 .copychunk_range = smb2_copychunk_range,
5470 .duplicate_extents = smb2_duplicate_extents,
5471 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
5472 .wp_retry_size = smb2_wp_retry_size,
5473 .dir_needs_close = smb2_dir_needs_close,
5474 .fallocate = smb3_fallocate,
5475 .enum_snapshots = smb3_enum_snapshots,
5476 .notify = smb3_notify,
5477 .init_transform_rq = smb3_init_transform_rq,
5478 .is_transform_hdr = smb3_is_transform_hdr,
5479 .receive_transform = smb3_receive_transform,
5480 .get_dfs_refer = smb2_get_dfs_refer,
5481 .select_sectype = smb2_select_sectype,
5482 #ifdef CONFIG_CIFS_XATTR
5483 .query_all_EAs = smb2_query_eas,
5484 .set_EA = smb2_set_ea,
5485 #endif /* CIFS_XATTR */
5486 .get_acl = get_smb2_acl,
5487 .get_acl_by_fid = get_smb2_acl_by_fid,
5488 .set_acl = set_smb2_acl,
5489 .next_header = smb2_next_header,
5490 .ioctl_query_info = smb2_ioctl_query_info,
5491 .make_node = smb2_make_node,
5492 .fiemap = smb3_fiemap,
5493 .llseek = smb3_llseek,
5494 .is_status_io_timeout = smb2_is_status_io_timeout,
5495 .is_network_name_deleted = smb2_is_network_name_deleted,
5498 struct smb_version_values smb20_values = {
5499 .version_string = SMB20_VERSION_STRING,
5500 .protocol_id = SMB20_PROT_ID,
5501 .req_capabilities = 0, /* MBZ */
5502 .large_lock_type = 0,
5503 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5504 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5505 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5506 .header_size = sizeof(struct smb2_sync_hdr),
5507 .header_preamble_size = 0,
5508 .max_header_size = MAX_SMB2_HDR_SIZE,
5509 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5510 .lock_cmd = SMB2_LOCK,
5512 .cap_nt_find = SMB2_NT_FIND,
5513 .cap_large_files = SMB2_LARGE_FILES,
5514 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5515 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5516 .create_lease_size = sizeof(struct create_lease),
5519 struct smb_version_values smb21_values = {
5520 .version_string = SMB21_VERSION_STRING,
5521 .protocol_id = SMB21_PROT_ID,
5522 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
5523 .large_lock_type = 0,
5524 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5525 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5526 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5527 .header_size = sizeof(struct smb2_sync_hdr),
5528 .header_preamble_size = 0,
5529 .max_header_size = MAX_SMB2_HDR_SIZE,
5530 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5531 .lock_cmd = SMB2_LOCK,
5533 .cap_nt_find = SMB2_NT_FIND,
5534 .cap_large_files = SMB2_LARGE_FILES,
5535 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5536 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5537 .create_lease_size = sizeof(struct create_lease),
5540 struct smb_version_values smb3any_values = {
5541 .version_string = SMB3ANY_VERSION_STRING,
5542 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5543 .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,
5544 .large_lock_type = 0,
5545 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5546 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5547 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5548 .header_size = sizeof(struct smb2_sync_hdr),
5549 .header_preamble_size = 0,
5550 .max_header_size = MAX_SMB2_HDR_SIZE,
5551 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5552 .lock_cmd = SMB2_LOCK,
5554 .cap_nt_find = SMB2_NT_FIND,
5555 .cap_large_files = SMB2_LARGE_FILES,
5556 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5557 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5558 .create_lease_size = sizeof(struct create_lease_v2),
5561 struct smb_version_values smbdefault_values = {
5562 .version_string = SMBDEFAULT_VERSION_STRING,
5563 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
5564 .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,
5565 .large_lock_type = 0,
5566 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5567 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5568 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5569 .header_size = sizeof(struct smb2_sync_hdr),
5570 .header_preamble_size = 0,
5571 .max_header_size = MAX_SMB2_HDR_SIZE,
5572 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5573 .lock_cmd = SMB2_LOCK,
5575 .cap_nt_find = SMB2_NT_FIND,
5576 .cap_large_files = SMB2_LARGE_FILES,
5577 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5578 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5579 .create_lease_size = sizeof(struct create_lease_v2),
5582 struct smb_version_values smb30_values = {
5583 .version_string = SMB30_VERSION_STRING,
5584 .protocol_id = SMB30_PROT_ID,
5585 .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,
5586 .large_lock_type = 0,
5587 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5588 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5589 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5590 .header_size = sizeof(struct smb2_sync_hdr),
5591 .header_preamble_size = 0,
5592 .max_header_size = MAX_SMB2_HDR_SIZE,
5593 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5594 .lock_cmd = SMB2_LOCK,
5596 .cap_nt_find = SMB2_NT_FIND,
5597 .cap_large_files = SMB2_LARGE_FILES,
5598 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5599 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5600 .create_lease_size = sizeof(struct create_lease_v2),
5603 struct smb_version_values smb302_values = {
5604 .version_string = SMB302_VERSION_STRING,
5605 .protocol_id = SMB302_PROT_ID,
5606 .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,
5607 .large_lock_type = 0,
5608 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5609 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5610 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5611 .header_size = sizeof(struct smb2_sync_hdr),
5612 .header_preamble_size = 0,
5613 .max_header_size = MAX_SMB2_HDR_SIZE,
5614 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5615 .lock_cmd = SMB2_LOCK,
5617 .cap_nt_find = SMB2_NT_FIND,
5618 .cap_large_files = SMB2_LARGE_FILES,
5619 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5620 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5621 .create_lease_size = sizeof(struct create_lease_v2),
5624 struct smb_version_values smb311_values = {
5625 .version_string = SMB311_VERSION_STRING,
5626 .protocol_id = SMB311_PROT_ID,
5627 .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,
5628 .large_lock_type = 0,
5629 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
5630 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
5631 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
5632 .header_size = sizeof(struct smb2_sync_hdr),
5633 .header_preamble_size = 0,
5634 .max_header_size = MAX_SMB2_HDR_SIZE,
5635 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
5636 .lock_cmd = SMB2_LOCK,
5638 .cap_nt_find = SMB2_NT_FIND,
5639 .cap_large_files = SMB2_LARGE_FILES,
5640 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
5641 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
5642 .create_lease_size = sizeof(struct create_lease_v2),