2 * SMB2 version specific operations
4 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
6 * This library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License v2 as published
8 * by the Free Software Foundation.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/pagemap.h>
21 #include <linux/vfs.h>
22 #include <linux/falloc.h>
23 #include <linux/scatterlist.h>
24 #include <linux/uuid.h>
25 #include <crypto/aead.h>
28 #include "smb2proto.h"
29 #include "cifsproto.h"
30 #include "cifs_debug.h"
31 #include "cifs_unicode.h"
32 #include "smb2status.h"
34 #include "cifs_ioctl.h"
35 #include "smbdirect.h"
37 /* Change credits for different ops and return the total number of credits */
39 change_conf(struct TCP_Server_Info *server)
41 server->credits += server->echo_credits + server->oplock_credits;
42 server->oplock_credits = server->echo_credits = 0;
43 switch (server->credits) {
47 server->echoes = false;
48 server->oplocks = false;
51 server->echoes = true;
52 server->oplocks = false;
53 server->echo_credits = 1;
56 server->echoes = true;
58 server->oplocks = true;
59 server->oplock_credits = 1;
61 server->oplocks = false;
63 server->echo_credits = 1;
65 server->credits -= server->echo_credits + server->oplock_credits;
66 return server->credits + server->echo_credits + server->oplock_credits;
70 smb2_add_credits(struct TCP_Server_Info *server,
71 const struct cifs_credits *credits, const int optype)
74 unsigned int add = credits->value;
75 unsigned int instance = credits->instance;
76 bool reconnect_detected = false;
78 spin_lock(&server->req_lock);
79 val = server->ops->get_credits_field(server, optype);
81 /* eg found case where write overlapping reconnect messed up credits */
82 if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0))
83 trace_smb3_reconnect_with_invalid_credits(server->CurrentMid,
84 server->hostname, *val);
85 if ((instance == 0) || (instance == server->reconnect_instance))
88 reconnect_detected = true;
91 *val = 65000; /* Don't get near 64K credits, avoid srv bugs */
92 printk_once(KERN_WARNING "server overflowed SMB3 credits\n");
95 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
96 rc = change_conf(server);
98 * Sometimes server returns 0 credits on oplock break ack - we need to
99 * rebalance credits in this case.
101 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
103 if (server->credits > 1) {
105 server->oplock_credits++;
108 spin_unlock(&server->req_lock);
109 wake_up(&server->request_q);
111 if (reconnect_detected)
112 cifs_dbg(FYI, "trying to put %d credits from the old server instance %d\n",
115 if (server->tcpStatus == CifsNeedReconnect
116 || server->tcpStatus == CifsExiting)
121 /* change_conf hasn't been executed */
124 cifs_dbg(VFS, "Possible client or server bug - zero credits\n");
127 cifs_dbg(VFS, "disabling echoes and oplocks\n");
130 cifs_dbg(FYI, "disabling oplocks\n");
133 cifs_dbg(FYI, "add %u credits total=%d\n", add, rc);
138 smb2_set_credits(struct TCP_Server_Info *server, const int val)
140 spin_lock(&server->req_lock);
141 server->credits = val;
143 server->reconnect_instance++;
144 spin_unlock(&server->req_lock);
145 /* don't log while holding the lock */
147 cifs_dbg(FYI, "set credits to 1 due to smb2 reconnect\n");
151 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
155 return &server->echo_credits;
157 return &server->oplock_credits;
159 return &server->credits;
164 smb2_get_credits(struct mid_q_entry *mid)
166 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)mid->resp_buf;
168 if (mid->mid_state == MID_RESPONSE_RECEIVED
169 || mid->mid_state == MID_RESPONSE_MALFORMED)
170 return le16_to_cpu(shdr->CreditRequest);
176 smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
177 unsigned int *num, struct cifs_credits *credits)
180 unsigned int scredits;
182 spin_lock(&server->req_lock);
184 if (server->credits <= 0) {
185 spin_unlock(&server->req_lock);
186 cifs_num_waiters_inc(server);
187 rc = wait_event_killable(server->request_q,
188 has_credits(server, &server->credits, 1));
189 cifs_num_waiters_dec(server);
192 spin_lock(&server->req_lock);
194 if (server->tcpStatus == CifsExiting) {
195 spin_unlock(&server->req_lock);
199 scredits = server->credits;
200 /* can deadlock with reopen */
202 *num = SMB2_MAX_BUFFER_SIZE;
204 credits->instance = 0;
208 /* leave some credits for reopen and other ops */
210 *num = min_t(unsigned int, size,
211 scredits * SMB2_MAX_BUFFER_SIZE);
214 DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
215 credits->instance = server->reconnect_instance;
216 server->credits -= credits->value;
221 spin_unlock(&server->req_lock);
226 smb2_adjust_credits(struct TCP_Server_Info *server,
227 struct cifs_credits *credits,
228 const unsigned int payload_size)
230 int new_val = DIV_ROUND_UP(payload_size, SMB2_MAX_BUFFER_SIZE);
232 if (!credits->value || credits->value == new_val)
235 if (credits->value < new_val) {
236 WARN_ONCE(1, "request has less credits (%d) than required (%d)",
237 credits->value, new_val);
241 spin_lock(&server->req_lock);
243 if (server->reconnect_instance != credits->instance) {
244 spin_unlock(&server->req_lock);
245 cifs_dbg(VFS, "trying to return %d credits to old session\n",
246 credits->value - new_val);
250 server->credits += credits->value - new_val;
251 spin_unlock(&server->req_lock);
252 wake_up(&server->request_q);
253 credits->value = new_val;
258 smb2_get_next_mid(struct TCP_Server_Info *server)
261 /* for SMB2 we need the current value */
262 spin_lock(&GlobalMid_Lock);
263 mid = server->CurrentMid++;
264 spin_unlock(&GlobalMid_Lock);
269 smb2_revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
271 spin_lock(&GlobalMid_Lock);
272 if (server->CurrentMid >= val)
273 server->CurrentMid -= val;
274 spin_unlock(&GlobalMid_Lock);
277 static struct mid_q_entry *
278 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
280 struct mid_q_entry *mid;
281 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
282 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
284 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
285 cifs_dbg(VFS, "encrypted frame parsing not supported yet");
289 spin_lock(&GlobalMid_Lock);
290 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
291 if ((mid->mid == wire_mid) &&
292 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
293 (mid->command == shdr->Command)) {
294 kref_get(&mid->refcount);
295 spin_unlock(&GlobalMid_Lock);
299 spin_unlock(&GlobalMid_Lock);
304 smb2_dump_detail(void *buf, struct TCP_Server_Info *server)
306 #ifdef CONFIG_CIFS_DEBUG2
307 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
309 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
310 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
312 cifs_dbg(VFS, "smb buf %p len %u\n", buf,
313 server->ops->calc_smb_size(buf, server));
318 smb2_need_neg(struct TCP_Server_Info *server)
320 return server->max_read == 0;
324 smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
327 ses->server->CurrentMid = 0;
328 rc = SMB2_negotiate(xid, ses);
329 /* BB we probably don't need to retry with modern servers */
336 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
338 struct TCP_Server_Info *server = tcon->ses->server;
341 /* start with specified wsize, or default */
342 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
343 wsize = min_t(unsigned int, wsize, server->max_write);
344 #ifdef CONFIG_CIFS_SMB_DIRECT
347 wsize = min_t(unsigned int,
348 wsize, server->smbd_conn->max_fragmented_send_size);
350 wsize = min_t(unsigned int,
351 wsize, server->smbd_conn->max_readwrite_size);
354 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
355 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
361 smb3_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
363 struct TCP_Server_Info *server = tcon->ses->server;
366 /* start with specified wsize, or default */
367 wsize = volume_info->wsize ? volume_info->wsize : SMB3_DEFAULT_IOSIZE;
368 wsize = min_t(unsigned int, wsize, server->max_write);
369 #ifdef CONFIG_CIFS_SMB_DIRECT
372 wsize = min_t(unsigned int,
373 wsize, server->smbd_conn->max_fragmented_send_size);
375 wsize = min_t(unsigned int,
376 wsize, server->smbd_conn->max_readwrite_size);
379 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
380 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
386 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
388 struct TCP_Server_Info *server = tcon->ses->server;
391 /* start with specified rsize, or default */
392 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
393 rsize = min_t(unsigned int, rsize, server->max_read);
394 #ifdef CONFIG_CIFS_SMB_DIRECT
397 rsize = min_t(unsigned int,
398 rsize, server->smbd_conn->max_fragmented_recv_size);
400 rsize = min_t(unsigned int,
401 rsize, server->smbd_conn->max_readwrite_size);
405 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
406 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
412 smb3_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
414 struct TCP_Server_Info *server = tcon->ses->server;
417 /* start with specified rsize, or default */
418 rsize = volume_info->rsize ? volume_info->rsize : SMB3_DEFAULT_IOSIZE;
419 rsize = min_t(unsigned int, rsize, server->max_read);
420 #ifdef CONFIG_CIFS_SMB_DIRECT
423 rsize = min_t(unsigned int,
424 rsize, server->smbd_conn->max_fragmented_recv_size);
426 rsize = min_t(unsigned int,
427 rsize, server->smbd_conn->max_readwrite_size);
431 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
432 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
438 parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
440 struct cifs_server_iface **iface_list,
443 struct network_interface_info_ioctl_rsp *p;
444 struct sockaddr_in *addr4;
445 struct sockaddr_in6 *addr6;
446 struct iface_info_ipv4 *p4;
447 struct iface_info_ipv6 *p6;
448 struct cifs_server_iface *info;
458 * Fist pass: count and sanity check
461 bytes_left = buf_len;
463 while (bytes_left >= sizeof(*p)) {
465 next = le32_to_cpu(p->Next);
467 bytes_left -= sizeof(*p);
470 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
475 cifs_dbg(VFS, "%s: malformed interface info\n", __func__);
480 if (bytes_left || p->Next)
481 cifs_dbg(VFS, "%s: incomplete interface info\n", __func__);
485 * Second pass: extract info to internal structure
488 *iface_list = kcalloc(nb_iface, sizeof(**iface_list), GFP_KERNEL);
495 bytes_left = buf_len;
497 while (bytes_left >= sizeof(*p)) {
498 info->speed = le64_to_cpu(p->LinkSpeed);
499 info->rdma_capable = le32_to_cpu(p->Capability & RDMA_CAPABLE);
500 info->rss_capable = le32_to_cpu(p->Capability & RSS_CAPABLE);
502 cifs_dbg(FYI, "%s: adding iface %zu\n", __func__, *iface_count);
503 cifs_dbg(FYI, "%s: speed %zu bps\n", __func__, info->speed);
504 cifs_dbg(FYI, "%s: capabilities 0x%08x\n", __func__,
505 le32_to_cpu(p->Capability));
509 * The kernel and wire socket structures have the same
510 * layout and use network byte order but make the
511 * conversion explicit in case either one changes.
514 addr4 = (struct sockaddr_in *)&info->sockaddr;
515 p4 = (struct iface_info_ipv4 *)p->Buffer;
516 addr4->sin_family = AF_INET;
517 memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
519 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
520 addr4->sin_port = cpu_to_be16(CIFS_PORT);
522 cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
526 addr6 = (struct sockaddr_in6 *)&info->sockaddr;
527 p6 = (struct iface_info_ipv6 *)p->Buffer;
528 addr6->sin6_family = AF_INET6;
529 memcpy(&addr6->sin6_addr, &p6->IPv6Address, 16);
531 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
532 addr6->sin6_flowinfo = 0;
533 addr6->sin6_scope_id = 0;
534 addr6->sin6_port = cpu_to_be16(CIFS_PORT);
536 cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
541 "%s: skipping unsupported socket family\n",
549 next = le32_to_cpu(p->Next);
552 p = (struct network_interface_info_ioctl_rsp *)((u8 *)p+next);
572 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
575 unsigned int ret_data_len = 0;
576 struct network_interface_info_ioctl_rsp *out_buf = NULL;
577 struct cifs_server_iface *iface_list;
579 struct cifs_ses *ses = tcon->ses;
581 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
582 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
583 NULL /* no data input */, 0 /* no data input */,
584 (char **)&out_buf, &ret_data_len);
585 if (rc == -EOPNOTSUPP) {
587 "server does not support query network interfaces\n");
589 } else if (rc != 0) {
590 cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
594 rc = parse_server_interfaces(out_buf, ret_data_len,
595 &iface_list, &iface_count);
599 spin_lock(&ses->iface_lock);
600 kfree(ses->iface_list);
601 ses->iface_list = iface_list;
602 ses->iface_count = iface_count;
603 ses->iface_last_update = jiffies;
604 spin_unlock(&ses->iface_lock);
612 smb2_close_cached_fid(struct kref *ref)
614 struct cached_fid *cfid = container_of(ref, struct cached_fid,
617 if (cfid->is_valid) {
618 cifs_dbg(FYI, "clear cached root file handle\n");
619 SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid,
620 cfid->fid->volatile_fid);
621 cfid->is_valid = false;
622 cfid->file_all_info_is_valid = false;
626 void close_shroot(struct cached_fid *cfid)
628 mutex_lock(&cfid->fid_mutex);
629 kref_put(&cfid->refcount, smb2_close_cached_fid);
630 mutex_unlock(&cfid->fid_mutex);
634 smb2_cached_lease_break(struct work_struct *work)
636 struct cached_fid *cfid = container_of(work,
637 struct cached_fid, lease_break);
643 * Open the directory at the root of a share
645 int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid)
647 struct cifs_ses *ses = tcon->ses;
648 struct TCP_Server_Info *server = ses->server;
649 struct cifs_open_parms oparms;
650 struct smb2_create_rsp *o_rsp = NULL;
651 struct smb2_query_info_rsp *qi_rsp = NULL;
653 struct smb_rqst rqst[2];
654 struct kvec rsp_iov[2];
655 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
656 struct kvec qi_iov[1];
658 __le16 utf16_path = 0; /* Null - since an open of top of share */
659 u8 oplock = SMB2_OPLOCK_LEVEL_II;
661 mutex_lock(&tcon->crfid.fid_mutex);
662 if (tcon->crfid.is_valid) {
663 cifs_dbg(FYI, "found a cached root file handle\n");
664 memcpy(pfid, tcon->crfid.fid, sizeof(struct cifs_fid));
665 kref_get(&tcon->crfid.refcount);
666 mutex_unlock(&tcon->crfid.fid_mutex);
670 if (smb3_encryption_required(tcon))
671 flags |= CIFS_TRANSFORM_REQ;
673 memset(rqst, 0, sizeof(rqst));
674 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
675 memset(rsp_iov, 0, sizeof(rsp_iov));
678 memset(&open_iov, 0, sizeof(open_iov));
679 rqst[0].rq_iov = open_iov;
680 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
683 oparms.create_options = 0;
684 oparms.desired_access = FILE_READ_ATTRIBUTES;
685 oparms.disposition = FILE_OPEN;
687 oparms.reconnect = false;
689 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, &utf16_path);
692 smb2_set_next_command(tcon, &rqst[0]);
694 memset(&qi_iov, 0, sizeof(qi_iov));
695 rqst[1].rq_iov = qi_iov;
698 rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID,
699 COMPOUND_FID, FILE_ALL_INFORMATION,
701 sizeof(struct smb2_file_all_info) +
702 PATH_MAX * 2, 0, NULL);
706 smb2_set_related(&rqst[1]);
708 rc = compound_send_recv(xid, ses, flags, 2, rqst,
709 resp_buftype, rsp_iov);
713 o_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
714 oparms.fid->persistent_fid = o_rsp->PersistentFileId;
715 oparms.fid->volatile_fid = o_rsp->VolatileFileId;
716 #ifdef CONFIG_CIFS_DEBUG2
717 oparms.fid->mid = le64_to_cpu(o_rsp->sync_hdr.MessageId);
718 #endif /* CIFS_DEBUG2 */
720 if (o_rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE)
721 oplock = smb2_parse_lease_state(server, o_rsp,
723 oparms.fid->lease_key);
728 memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid));
729 tcon->crfid.tcon = tcon;
730 tcon->crfid.is_valid = true;
731 kref_init(&tcon->crfid.refcount);
732 kref_get(&tcon->crfid.refcount);
735 qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
736 if (le32_to_cpu(qi_rsp->OutputBufferLength) < sizeof(struct smb2_file_all_info))
738 rc = smb2_validate_and_copy_iov(
739 le16_to_cpu(qi_rsp->OutputBufferOffset),
740 sizeof(struct smb2_file_all_info),
741 &rsp_iov[1], sizeof(struct smb2_file_all_info),
742 (char *)&tcon->crfid.file_all_info);
745 tcon->crfid.file_all_info_is_valid = 1;
748 mutex_unlock(&tcon->crfid.fid_mutex);
749 SMB2_open_free(&rqst[0]);
750 SMB2_query_info_free(&rqst[1]);
751 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
752 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
757 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
760 __le16 srch_path = 0; /* Null - open root of share */
761 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
762 struct cifs_open_parms oparms;
764 bool no_cached_open = tcon->nohandlecache;
767 oparms.desired_access = FILE_READ_ATTRIBUTES;
768 oparms.disposition = FILE_OPEN;
769 oparms.create_options = 0;
771 oparms.reconnect = false;
774 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
777 rc = open_shroot(xid, tcon, &fid);
782 SMB3_request_interfaces(xid, tcon);
784 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
785 FS_ATTRIBUTE_INFORMATION);
786 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
787 FS_DEVICE_INFORMATION);
788 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
789 FS_VOLUME_INFORMATION);
790 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
791 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
793 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
795 close_shroot(&tcon->crfid);
801 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
804 __le16 srch_path = 0; /* Null - open root of share */
805 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
806 struct cifs_open_parms oparms;
810 oparms.desired_access = FILE_READ_ATTRIBUTES;
811 oparms.disposition = FILE_OPEN;
812 oparms.create_options = 0;
814 oparms.reconnect = false;
816 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
820 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
821 FS_ATTRIBUTE_INFORMATION);
822 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
823 FS_DEVICE_INFORMATION);
824 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
829 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
830 struct cifs_sb_info *cifs_sb, const char *full_path)
834 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
835 struct cifs_open_parms oparms;
838 if ((*full_path == 0) && tcon->crfid.is_valid)
841 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
846 oparms.desired_access = FILE_READ_ATTRIBUTES;
847 oparms.disposition = FILE_OPEN;
848 if (backup_cred(cifs_sb))
849 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
851 oparms.create_options = 0;
853 oparms.reconnect = false;
855 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
861 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
867 smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
868 struct cifs_sb_info *cifs_sb, const char *full_path,
869 u64 *uniqueid, FILE_ALL_INFO *data)
871 *uniqueid = le64_to_cpu(data->IndexNumber);
876 smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
877 struct cifs_fid *fid, FILE_ALL_INFO *data)
880 struct smb2_file_all_info *smb2_data;
882 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
884 if (smb2_data == NULL)
887 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
890 move_smb2_info_to_cifs(data, smb2_data);
895 #ifdef CONFIG_CIFS_XATTR
897 move_smb2_ea_to_cifs(char *dst, size_t dst_size,
898 struct smb2_file_full_ea_info *src, size_t src_size,
899 const unsigned char *ea_name)
902 unsigned int ea_name_len = ea_name ? strlen(ea_name) : 0;
904 size_t buf_size = dst_size;
905 size_t name_len, value_len, user_name_len;
907 while (src_size > 0) {
908 name = &src->ea_data[0];
909 name_len = (size_t)src->ea_name_length;
910 value = &src->ea_data[src->ea_name_length + 1];
911 value_len = (size_t)le16_to_cpu(src->ea_value_length);
917 if (src_size < 8 + name_len + 1 + value_len) {
918 cifs_dbg(FYI, "EA entry goes beyond length of list\n");
924 if (ea_name_len == name_len &&
925 memcmp(ea_name, name, name_len) == 0) {
929 if (dst_size < value_len) {
933 memcpy(dst, value, value_len);
937 /* 'user.' plus a terminating null */
938 user_name_len = 5 + 1 + name_len;
941 /* skip copy - calc size only */
943 } else if (dst_size >= user_name_len) {
944 dst_size -= user_name_len;
945 memcpy(dst, "user.", 5);
947 memcpy(dst, src->ea_data, name_len);
953 /* stop before overrun buffer */
959 if (!src->next_entry_offset)
962 if (src_size < le32_to_cpu(src->next_entry_offset)) {
963 /* stop before overrun buffer */
967 src_size -= le32_to_cpu(src->next_entry_offset);
968 src = (void *)((char *)src +
969 le32_to_cpu(src->next_entry_offset));
972 /* didn't find the named attribute */
981 smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
982 const unsigned char *path, const unsigned char *ea_name,
983 char *ea_data, size_t buf_size,
984 struct cifs_sb_info *cifs_sb)
988 struct kvec rsp_iov = {NULL, 0};
989 int buftype = CIFS_NO_BUFFER;
990 struct smb2_query_info_rsp *rsp;
991 struct smb2_file_full_ea_info *info = NULL;
993 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
997 rc = smb2_query_info_compound(xid, tcon, utf16_path,
999 FILE_FULL_EA_INFORMATION,
1002 MAX_SMB2_CREATE_RESPONSE_SIZE -
1003 MAX_SMB2_CLOSE_RESPONSE_SIZE,
1004 &rsp_iov, &buftype, cifs_sb);
1007 * If ea_name is NULL (listxattr) and there are no EAs,
1008 * return 0 as it's not an error. Otherwise, the specified
1009 * ea_name was not found.
1011 if (!ea_name && rc == -ENODATA)
1016 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
1017 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
1018 le32_to_cpu(rsp->OutputBufferLength),
1020 sizeof(struct smb2_file_full_ea_info));
1024 info = (struct smb2_file_full_ea_info *)(
1025 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
1026 rc = move_smb2_ea_to_cifs(ea_data, buf_size, info,
1027 le32_to_cpu(rsp->OutputBufferLength), ea_name);
1031 free_rsp_buf(buftype, rsp_iov.iov_base);
1037 smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
1038 const char *path, const char *ea_name, const void *ea_value,
1039 const __u16 ea_value_len, const struct nls_table *nls_codepage,
1040 struct cifs_sb_info *cifs_sb)
1042 struct cifs_ses *ses = tcon->ses;
1043 __le16 *utf16_path = NULL;
1044 int ea_name_len = strlen(ea_name);
1047 struct smb_rqst rqst[3];
1048 int resp_buftype[3];
1049 struct kvec rsp_iov[3];
1050 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1051 struct cifs_open_parms oparms;
1052 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1053 struct cifs_fid fid;
1054 struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE];
1055 unsigned int size[1];
1057 struct smb2_file_full_ea_info *ea = NULL;
1058 struct kvec close_iov[1];
1061 if (smb3_encryption_required(tcon))
1062 flags |= CIFS_TRANSFORM_REQ;
1064 if (ea_name_len > 255)
1067 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1071 memset(rqst, 0, sizeof(rqst));
1072 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1073 memset(rsp_iov, 0, sizeof(rsp_iov));
1075 if (ses->server->ops->query_all_EAs) {
1077 rc = ses->server->ops->query_all_EAs(xid, tcon, path,
1086 memset(&open_iov, 0, sizeof(open_iov));
1087 rqst[0].rq_iov = open_iov;
1088 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1090 memset(&oparms, 0, sizeof(oparms));
1092 oparms.desired_access = FILE_WRITE_EA;
1093 oparms.disposition = FILE_OPEN;
1094 if (backup_cred(cifs_sb))
1095 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1097 oparms.create_options = 0;
1099 oparms.reconnect = false;
1101 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, utf16_path);
1104 smb2_set_next_command(tcon, &rqst[0]);
1108 memset(&si_iov, 0, sizeof(si_iov));
1109 rqst[1].rq_iov = si_iov;
1110 rqst[1].rq_nvec = 1;
1112 len = sizeof(ea) + ea_name_len + ea_value_len + 1;
1113 ea = kzalloc(len, GFP_KERNEL);
1119 ea->ea_name_length = ea_name_len;
1120 ea->ea_value_length = cpu_to_le16(ea_value_len);
1121 memcpy(ea->ea_data, ea_name, ea_name_len + 1);
1122 memcpy(ea->ea_data + ea_name_len + 1, ea_value, ea_value_len);
1127 rc = SMB2_set_info_init(tcon, &rqst[1], COMPOUND_FID,
1128 COMPOUND_FID, current->tgid,
1129 FILE_FULL_EA_INFORMATION,
1130 SMB2_O_INFO_FILE, 0, data, size);
1131 smb2_set_next_command(tcon, &rqst[1]);
1132 smb2_set_related(&rqst[1]);
1136 memset(&close_iov, 0, sizeof(close_iov));
1137 rqst[2].rq_iov = close_iov;
1138 rqst[2].rq_nvec = 1;
1139 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
1140 smb2_set_related(&rqst[2]);
1142 rc = compound_send_recv(xid, ses, flags, 3, rqst,
1143 resp_buftype, rsp_iov);
1148 SMB2_open_free(&rqst[0]);
1149 SMB2_set_info_free(&rqst[1]);
1150 SMB2_close_free(&rqst[2]);
1151 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1152 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1153 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1159 smb2_can_echo(struct TCP_Server_Info *server)
1161 return server->echoes;
1165 smb2_clear_stats(struct cifs_tcon *tcon)
1168 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
1169 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
1170 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
1175 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
1177 seq_puts(m, "\n\tShare Capabilities:");
1178 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
1179 seq_puts(m, " DFS,");
1180 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
1181 seq_puts(m, " CONTINUOUS AVAILABILITY,");
1182 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
1183 seq_puts(m, " SCALEOUT,");
1184 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
1185 seq_puts(m, " CLUSTER,");
1186 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
1187 seq_puts(m, " ASYMMETRIC,");
1188 if (tcon->capabilities == 0)
1189 seq_puts(m, " None");
1190 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
1191 seq_puts(m, " Aligned,");
1192 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
1193 seq_puts(m, " Partition Aligned,");
1194 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
1195 seq_puts(m, " SSD,");
1196 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
1197 seq_puts(m, " TRIM-support,");
1199 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
1200 seq_printf(m, "\n\ttid: 0x%x", tcon->tid);
1201 if (tcon->perf_sector_size)
1202 seq_printf(m, "\tOptimal sector size: 0x%x",
1203 tcon->perf_sector_size);
1204 seq_printf(m, "\tMaximal Access: 0x%x", tcon->maximal_access);
1208 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
1210 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
1211 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
1214 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1215 * totals (requests sent) since those SMBs are per-session not per tcon
1217 seq_printf(m, "\nBytes read: %llu Bytes written: %llu",
1218 (long long)(tcon->bytes_read),
1219 (long long)(tcon->bytes_written));
1220 seq_printf(m, "\nOpen files: %d total (local), %d open on server",
1221 atomic_read(&tcon->num_local_opens),
1222 atomic_read(&tcon->num_remote_opens));
1223 seq_printf(m, "\nTreeConnects: %d total %d failed",
1224 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
1225 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
1226 seq_printf(m, "\nTreeDisconnects: %d total %d failed",
1227 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
1228 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
1229 seq_printf(m, "\nCreates: %d total %d failed",
1230 atomic_read(&sent[SMB2_CREATE_HE]),
1231 atomic_read(&failed[SMB2_CREATE_HE]));
1232 seq_printf(m, "\nCloses: %d total %d failed",
1233 atomic_read(&sent[SMB2_CLOSE_HE]),
1234 atomic_read(&failed[SMB2_CLOSE_HE]));
1235 seq_printf(m, "\nFlushes: %d total %d failed",
1236 atomic_read(&sent[SMB2_FLUSH_HE]),
1237 atomic_read(&failed[SMB2_FLUSH_HE]));
1238 seq_printf(m, "\nReads: %d total %d failed",
1239 atomic_read(&sent[SMB2_READ_HE]),
1240 atomic_read(&failed[SMB2_READ_HE]));
1241 seq_printf(m, "\nWrites: %d total %d failed",
1242 atomic_read(&sent[SMB2_WRITE_HE]),
1243 atomic_read(&failed[SMB2_WRITE_HE]));
1244 seq_printf(m, "\nLocks: %d total %d failed",
1245 atomic_read(&sent[SMB2_LOCK_HE]),
1246 atomic_read(&failed[SMB2_LOCK_HE]));
1247 seq_printf(m, "\nIOCTLs: %d total %d failed",
1248 atomic_read(&sent[SMB2_IOCTL_HE]),
1249 atomic_read(&failed[SMB2_IOCTL_HE]));
1250 seq_printf(m, "\nQueryDirectories: %d total %d failed",
1251 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
1252 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
1253 seq_printf(m, "\nChangeNotifies: %d total %d failed",
1254 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
1255 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
1256 seq_printf(m, "\nQueryInfos: %d total %d failed",
1257 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
1258 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
1259 seq_printf(m, "\nSetInfos: %d total %d failed",
1260 atomic_read(&sent[SMB2_SET_INFO_HE]),
1261 atomic_read(&failed[SMB2_SET_INFO_HE]));
1262 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
1263 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
1264 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
1268 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
1270 struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
1271 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
1273 cfile->fid.persistent_fid = fid->persistent_fid;
1274 cfile->fid.volatile_fid = fid->volatile_fid;
1275 #ifdef CONFIG_CIFS_DEBUG2
1276 cfile->fid.mid = fid->mid;
1277 #endif /* CIFS_DEBUG2 */
1278 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
1280 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
1281 memcpy(cfile->fid.create_guid, fid->create_guid, 16);
1285 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
1286 struct cifs_fid *fid)
1288 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1292 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
1293 u64 persistent_fid, u64 volatile_fid,
1294 struct copychunk_ioctl *pcchunk)
1297 unsigned int ret_data_len;
1298 struct resume_key_req *res_key;
1300 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
1301 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
1302 NULL, 0 /* no input */,
1303 (char **)&res_key, &ret_data_len);
1306 cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
1307 goto req_res_key_exit;
1309 if (ret_data_len < sizeof(struct resume_key_req)) {
1310 cifs_dbg(VFS, "Invalid refcopy resume key length\n");
1312 goto req_res_key_exit;
1314 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1322 smb2_ioctl_query_info(const unsigned int xid,
1323 struct cifs_tcon *tcon,
1324 __le16 *path, int is_dir,
1327 struct cifs_ses *ses = tcon->ses;
1328 char __user *arg = (char __user *)p;
1329 struct smb_query_info qi;
1330 struct smb_query_info __user *pqi;
1333 struct smb2_query_info_rsp *rsp = NULL;
1334 void *buffer = NULL;
1335 struct smb_rqst rqst[3];
1336 int resp_buftype[3];
1337 struct kvec rsp_iov[3];
1338 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
1339 struct cifs_open_parms oparms;
1340 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1341 struct cifs_fid fid;
1342 struct kvec qi_iov[1];
1343 struct kvec close_iov[1];
1345 memset(rqst, 0, sizeof(rqst));
1346 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
1347 memset(rsp_iov, 0, sizeof(rsp_iov));
1349 if (copy_from_user(&qi, arg, sizeof(struct smb_query_info)))
1352 if (qi.output_buffer_length > 1024)
1355 if (!ses || !(ses->server))
1358 if (smb3_encryption_required(tcon))
1359 flags |= CIFS_TRANSFORM_REQ;
1361 buffer = kmalloc(qi.output_buffer_length, GFP_KERNEL);
1365 if (copy_from_user(buffer, arg + sizeof(struct smb_query_info),
1366 qi.output_buffer_length)) {
1372 memset(&open_iov, 0, sizeof(open_iov));
1373 rqst[0].rq_iov = open_iov;
1374 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
1376 memset(&oparms, 0, sizeof(oparms));
1378 oparms.desired_access = FILE_READ_ATTRIBUTES | READ_CONTROL;
1379 oparms.disposition = FILE_OPEN;
1381 oparms.create_options = CREATE_NOT_FILE;
1383 oparms.create_options = CREATE_NOT_DIR;
1385 oparms.reconnect = false;
1387 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, path);
1390 smb2_set_next_command(tcon, &rqst[0]);
1393 if (qi.flags & PASSTHRU_FSCTL) {
1394 /* Can eventually relax perm check since server enforces too */
1395 if (!capable(CAP_SYS_ADMIN))
1397 else /* TBD: Add code to compound FSCTL */
1399 } else if (qi.flags == PASSTHRU_QUERY_INFO) {
1400 memset(&qi_iov, 0, sizeof(qi_iov));
1401 rqst[1].rq_iov = qi_iov;
1402 rqst[1].rq_nvec = 1;
1404 rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID,
1405 COMPOUND_FID, qi.file_info_class,
1406 qi.info_type, qi.additional_information,
1407 qi.input_buffer_length,
1408 qi.output_buffer_length, buffer);
1409 } else { /* unknown flags */
1410 cifs_dbg(VFS, "invalid passthru query flags: 0x%x\n", qi.flags);
1416 smb2_set_next_command(tcon, &rqst[1]);
1417 smb2_set_related(&rqst[1]);
1420 memset(&close_iov, 0, sizeof(close_iov));
1421 rqst[2].rq_iov = close_iov;
1422 rqst[2].rq_nvec = 1;
1424 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
1427 smb2_set_related(&rqst[2]);
1429 rc = compound_send_recv(xid, ses, flags, 3, rqst,
1430 resp_buftype, rsp_iov);
1433 pqi = (struct smb_query_info __user *)arg;
1434 rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
1435 if (le32_to_cpu(rsp->OutputBufferLength) < qi.input_buffer_length)
1436 qi.input_buffer_length = le32_to_cpu(rsp->OutputBufferLength);
1437 if (copy_to_user(&pqi->input_buffer_length, &qi.input_buffer_length,
1438 sizeof(qi.input_buffer_length))) {
1442 if (copy_to_user(pqi + 1, rsp->Buffer, qi.input_buffer_length)) {
1449 SMB2_open_free(&rqst[0]);
1450 SMB2_query_info_free(&rqst[1]);
1451 SMB2_close_free(&rqst[2]);
1452 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
1453 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
1454 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
1459 smb2_copychunk_range(const unsigned int xid,
1460 struct cifsFileInfo *srcfile,
1461 struct cifsFileInfo *trgtfile, u64 src_off,
1462 u64 len, u64 dest_off)
1465 unsigned int ret_data_len;
1466 struct copychunk_ioctl *pcchunk;
1467 struct copychunk_ioctl_rsp *retbuf = NULL;
1468 struct cifs_tcon *tcon;
1469 int chunks_copied = 0;
1470 bool chunk_sizes_updated = false;
1471 ssize_t bytes_written, total_bytes_written = 0;
1473 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
1475 if (pcchunk == NULL)
1478 cifs_dbg(FYI, "in smb2_copychunk_range - about to call request res key\n");
1479 /* Request a key from the server to identify the source of the copy */
1480 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
1481 srcfile->fid.persistent_fid,
1482 srcfile->fid.volatile_fid, pcchunk);
1484 /* Note: request_res_key sets res_key null only if rc !=0 */
1488 /* For now array only one chunk long, will make more flexible later */
1489 pcchunk->ChunkCount = cpu_to_le32(1);
1490 pcchunk->Reserved = 0;
1491 pcchunk->Reserved2 = 0;
1493 tcon = tlink_tcon(trgtfile->tlink);
1496 pcchunk->SourceOffset = cpu_to_le64(src_off);
1497 pcchunk->TargetOffset = cpu_to_le64(dest_off);
1499 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
1501 /* Request server copy to target from src identified by key */
1502 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1503 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
1504 true /* is_fsctl */, (char *)pcchunk,
1505 sizeof(struct copychunk_ioctl), (char **)&retbuf,
1509 sizeof(struct copychunk_ioctl_rsp)) {
1510 cifs_dbg(VFS, "invalid cchunk response size\n");
1514 if (retbuf->TotalBytesWritten == 0) {
1515 cifs_dbg(FYI, "no bytes copied\n");
1520 * Check if server claimed to write more than we asked
1522 if (le32_to_cpu(retbuf->TotalBytesWritten) >
1523 le32_to_cpu(pcchunk->Length)) {
1524 cifs_dbg(VFS, "invalid copy chunk response\n");
1528 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
1529 cifs_dbg(VFS, "invalid num chunks written\n");
1535 bytes_written = le32_to_cpu(retbuf->TotalBytesWritten);
1536 src_off += bytes_written;
1537 dest_off += bytes_written;
1538 len -= bytes_written;
1539 total_bytes_written += bytes_written;
1541 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
1542 le32_to_cpu(retbuf->ChunksWritten),
1543 le32_to_cpu(retbuf->ChunkBytesWritten),
1545 } else if (rc == -EINVAL) {
1546 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
1549 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1550 le32_to_cpu(retbuf->ChunksWritten),
1551 le32_to_cpu(retbuf->ChunkBytesWritten),
1552 le32_to_cpu(retbuf->TotalBytesWritten));
1555 * Check if this is the first request using these sizes,
1556 * (ie check if copy succeed once with original sizes
1557 * and check if the server gave us different sizes after
1558 * we already updated max sizes on previous request).
1559 * if not then why is the server returning an error now
1561 if ((chunks_copied != 0) || chunk_sizes_updated)
1564 /* Check that server is not asking us to grow size */
1565 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
1566 tcon->max_bytes_chunk)
1567 tcon->max_bytes_chunk =
1568 le32_to_cpu(retbuf->ChunkBytesWritten);
1570 goto cchunk_out; /* server gave us bogus size */
1572 /* No need to change MaxChunks since already set to 1 */
1573 chunk_sizes_updated = true;
1584 return total_bytes_written;
1588 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
1589 struct cifs_fid *fid)
1591 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1595 smb2_read_data_offset(char *buf)
1597 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1598 return rsp->DataOffset;
1602 smb2_read_data_length(char *buf, bool in_remaining)
1604 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
1607 return le32_to_cpu(rsp->DataRemaining);
1609 return le32_to_cpu(rsp->DataLength);
1614 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
1615 struct cifs_io_parms *parms, unsigned int *bytes_read,
1616 char **buf, int *buf_type)
1618 parms->persistent_fid = pfid->persistent_fid;
1619 parms->volatile_fid = pfid->volatile_fid;
1620 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
1624 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
1625 struct cifs_io_parms *parms, unsigned int *written,
1626 struct kvec *iov, unsigned long nr_segs)
1629 parms->persistent_fid = pfid->persistent_fid;
1630 parms->volatile_fid = pfid->volatile_fid;
1631 return SMB2_write(xid, parms, written, iov, nr_segs);
1634 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1635 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
1636 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
1638 struct cifsInodeInfo *cifsi;
1641 cifsi = CIFS_I(inode);
1643 /* if file already sparse don't bother setting sparse again */
1644 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
1645 return true; /* already sparse */
1647 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
1648 return true; /* already not sparse */
1651 * Can't check for sparse support on share the usual way via the
1652 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1653 * since Samba server doesn't set the flag on the share, yet
1654 * supports the set sparse FSCTL and returns sparse correctly
1655 * in the file attributes. If we fail setting sparse though we
1656 * mark that server does not support sparse files for this share
1657 * to avoid repeatedly sending the unsupported fsctl to server
1658 * if the file is repeatedly extended.
1660 if (tcon->broken_sparse_sup)
1663 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1664 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
1666 &setsparse, 1, NULL, NULL);
1668 tcon->broken_sparse_sup = true;
1669 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
1674 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
1676 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
1682 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
1683 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
1685 __le64 eof = cpu_to_le64(size);
1686 struct inode *inode;
1689 * If extending file more than one page make sparse. Many Linux fs
1690 * make files sparse by default when extending via ftruncate
1692 inode = d_inode(cfile->dentry);
1694 if (!set_alloc && (size > inode->i_size + 8192)) {
1695 __u8 set_sparse = 1;
1697 /* whether set sparse succeeds or not, extend the file */
1698 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
1701 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
1702 cfile->fid.volatile_fid, cfile->pid, &eof);
1706 smb2_duplicate_extents(const unsigned int xid,
1707 struct cifsFileInfo *srcfile,
1708 struct cifsFileInfo *trgtfile, u64 src_off,
1709 u64 len, u64 dest_off)
1712 unsigned int ret_data_len;
1713 struct duplicate_extents_to_file dup_ext_buf;
1714 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
1716 /* server fileays advertise duplicate extent support with this flag */
1717 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
1718 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
1721 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
1722 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
1723 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
1724 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
1725 dup_ext_buf.ByteCount = cpu_to_le64(len);
1726 cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld",
1727 src_off, dest_off, len);
1729 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
1731 goto duplicate_extents_out;
1733 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
1734 trgtfile->fid.volatile_fid,
1735 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
1736 true /* is_fsctl */,
1737 (char *)&dup_ext_buf,
1738 sizeof(struct duplicate_extents_to_file),
1742 if (ret_data_len > 0)
1743 cifs_dbg(FYI, "non-zero response length in duplicate extents");
1745 duplicate_extents_out:
1750 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
1751 struct cifsFileInfo *cfile)
1753 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
1754 cfile->fid.volatile_fid);
1758 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
1759 struct cifsFileInfo *cfile)
1761 struct fsctl_set_integrity_information_req integr_info;
1762 unsigned int ret_data_len;
1764 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
1765 integr_info.Flags = 0;
1766 integr_info.Reserved = 0;
1768 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1769 cfile->fid.volatile_fid,
1770 FSCTL_SET_INTEGRITY_INFORMATION,
1771 true /* is_fsctl */,
1772 (char *)&integr_info,
1773 sizeof(struct fsctl_set_integrity_information_req),
1779 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
1780 #define GMT_TOKEN_SIZE 50
1783 * Input buffer contains (empty) struct smb_snapshot array with size filled in
1784 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
1787 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
1788 struct cifsFileInfo *cfile, void __user *ioc_buf)
1790 char *retbuf = NULL;
1791 unsigned int ret_data_len = 0;
1793 struct smb_snapshot_array snapshot_in;
1795 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1796 cfile->fid.volatile_fid,
1797 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
1798 true /* is_fsctl */,
1799 NULL, 0 /* no input data */,
1802 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
1807 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
1809 if (copy_from_user(&snapshot_in, ioc_buf,
1810 sizeof(struct smb_snapshot_array))) {
1817 * Check for min size, ie not large enough to fit even one GMT
1818 * token (snapshot). On the first ioctl some users may pass in
1819 * smaller size (or zero) to simply get the size of the array
1820 * so the user space caller can allocate sufficient memory
1821 * and retry the ioctl again with larger array size sufficient
1822 * to hold all of the snapshot GMT tokens on the second try.
1824 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
1825 ret_data_len = sizeof(struct smb_snapshot_array);
1828 * We return struct SRV_SNAPSHOT_ARRAY, followed by
1829 * the snapshot array (of 50 byte GMT tokens) each
1830 * representing an available previous version of the data
1832 if (ret_data_len > (snapshot_in.snapshot_array_size +
1833 sizeof(struct smb_snapshot_array)))
1834 ret_data_len = snapshot_in.snapshot_array_size +
1835 sizeof(struct smb_snapshot_array);
1837 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
1846 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
1847 const char *path, struct cifs_sb_info *cifs_sb,
1848 struct cifs_fid *fid, __u16 search_flags,
1849 struct cifs_search_info *srch_inf)
1853 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1854 struct cifs_open_parms oparms;
1856 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
1861 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
1862 oparms.disposition = FILE_OPEN;
1863 if (backup_cred(cifs_sb))
1864 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
1866 oparms.create_options = 0;
1868 oparms.reconnect = false;
1870 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
1873 cifs_dbg(FYI, "open dir failed rc=%d\n", rc);
1877 srch_inf->entries_in_buffer = 0;
1878 srch_inf->index_of_last_entry = 2;
1880 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
1881 fid->volatile_fid, 0, srch_inf);
1883 cifs_dbg(FYI, "query directory failed rc=%d\n", rc);
1884 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1890 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
1891 struct cifs_fid *fid, __u16 search_flags,
1892 struct cifs_search_info *srch_inf)
1894 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
1895 fid->volatile_fid, 0, srch_inf);
1899 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
1900 struct cifs_fid *fid)
1902 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1906 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
1907 * the number of credits and return true. Otherwise - return false.
1910 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server)
1912 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
1914 if (shdr->Status != STATUS_PENDING)
1917 if (shdr->CreditRequest) {
1918 spin_lock(&server->req_lock);
1919 server->credits += le16_to_cpu(shdr->CreditRequest);
1920 spin_unlock(&server->req_lock);
1921 wake_up(&server->request_q);
1928 smb2_is_session_expired(char *buf)
1930 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
1932 if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED &&
1933 shdr->Status != STATUS_USER_SESSION_DELETED)
1936 trace_smb3_ses_expired(shdr->TreeId, shdr->SessionId,
1937 le16_to_cpu(shdr->Command),
1938 le64_to_cpu(shdr->MessageId));
1939 cifs_dbg(FYI, "Session expired or deleted\n");
1945 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
1946 struct cifsInodeInfo *cinode)
1948 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
1949 return SMB2_lease_break(0, tcon, cinode->lease_key,
1950 smb2_get_lease_state(cinode));
1952 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
1954 CIFS_CACHE_READ(cinode) ? 1 : 0);
1958 smb2_set_related(struct smb_rqst *rqst)
1960 struct smb2_sync_hdr *shdr;
1962 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
1963 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
1966 char smb2_padding[7] = {0, 0, 0, 0, 0, 0, 0};
1969 smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst)
1971 struct smb2_sync_hdr *shdr;
1972 struct cifs_ses *ses = tcon->ses;
1973 struct TCP_Server_Info *server = ses->server;
1974 unsigned long len = smb_rqst_len(server, rqst);
1977 /* SMB headers in a compound are 8 byte aligned. */
1979 /* No padding needed */
1983 num_padding = 8 - (len & 7);
1984 if (!smb3_encryption_required(tcon)) {
1986 * If we do not have encryption then we can just add an extra
1987 * iov for the padding.
1989 rqst->rq_iov[rqst->rq_nvec].iov_base = smb2_padding;
1990 rqst->rq_iov[rqst->rq_nvec].iov_len = num_padding;
1995 * We can not add a small padding iov for the encryption case
1996 * because the encryption framework can not handle the padding
1998 * We have to flatten this into a single buffer and add
1999 * the padding to it.
2001 for (i = 1; i < rqst->rq_nvec; i++) {
2002 memcpy(rqst->rq_iov[0].iov_base +
2003 rqst->rq_iov[0].iov_len,
2004 rqst->rq_iov[i].iov_base,
2005 rqst->rq_iov[i].iov_len);
2006 rqst->rq_iov[0].iov_len += rqst->rq_iov[i].iov_len;
2008 memset(rqst->rq_iov[0].iov_base + rqst->rq_iov[0].iov_len,
2010 rqst->rq_iov[0].iov_len += num_padding;
2016 shdr = (struct smb2_sync_hdr *)(rqst->rq_iov[0].iov_base);
2017 shdr->NextCommand = cpu_to_le32(len);
2021 * Passes the query info response back to the caller on success.
2022 * Caller need to free this with free_rsp_buf().
2025 smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
2026 __le16 *utf16_path, u32 desired_access,
2027 u32 class, u32 type, u32 output_len,
2028 struct kvec *rsp, int *buftype,
2029 struct cifs_sb_info *cifs_sb)
2031 struct cifs_ses *ses = tcon->ses;
2033 struct smb_rqst rqst[3];
2034 int resp_buftype[3];
2035 struct kvec rsp_iov[3];
2036 struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2037 struct kvec qi_iov[1];
2038 struct kvec close_iov[1];
2039 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2040 struct cifs_open_parms oparms;
2041 struct cifs_fid fid;
2044 if (smb3_encryption_required(tcon))
2045 flags |= CIFS_TRANSFORM_REQ;
2047 memset(rqst, 0, sizeof(rqst));
2048 resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2049 memset(rsp_iov, 0, sizeof(rsp_iov));
2051 memset(&open_iov, 0, sizeof(open_iov));
2052 rqst[0].rq_iov = open_iov;
2053 rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2056 oparms.desired_access = desired_access;
2057 oparms.disposition = FILE_OPEN;
2058 if (cifs_sb && backup_cred(cifs_sb))
2059 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2061 oparms.create_options = 0;
2063 oparms.reconnect = false;
2065 rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, utf16_path);
2068 smb2_set_next_command(tcon, &rqst[0]);
2070 memset(&qi_iov, 0, sizeof(qi_iov));
2071 rqst[1].rq_iov = qi_iov;
2072 rqst[1].rq_nvec = 1;
2074 rc = SMB2_query_info_init(tcon, &rqst[1], COMPOUND_FID, COMPOUND_FID,
2080 smb2_set_next_command(tcon, &rqst[1]);
2081 smb2_set_related(&rqst[1]);
2083 memset(&close_iov, 0, sizeof(close_iov));
2084 rqst[2].rq_iov = close_iov;
2085 rqst[2].rq_nvec = 1;
2087 rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
2090 smb2_set_related(&rqst[2]);
2092 rc = compound_send_recv(xid, ses, flags, 3, rqst,
2093 resp_buftype, rsp_iov);
2095 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2099 *buftype = resp_buftype[1];
2102 SMB2_open_free(&rqst[0]);
2103 SMB2_query_info_free(&rqst[1]);
2104 SMB2_close_free(&rqst[2]);
2105 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2106 free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
2111 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2112 struct kstatfs *buf)
2114 struct smb2_query_info_rsp *rsp;
2115 struct smb2_fs_full_size_info *info = NULL;
2116 __le16 utf16_path = 0; /* Null - open root of share */
2117 struct kvec rsp_iov = {NULL, 0};
2118 int buftype = CIFS_NO_BUFFER;
2122 rc = smb2_query_info_compound(xid, tcon, &utf16_path,
2123 FILE_READ_ATTRIBUTES,
2124 FS_FULL_SIZE_INFORMATION,
2125 SMB2_O_INFO_FILESYSTEM,
2126 sizeof(struct smb2_fs_full_size_info),
2127 &rsp_iov, &buftype, NULL);
2131 rsp = (struct smb2_query_info_rsp *)rsp_iov.iov_base;
2132 buf->f_type = SMB2_MAGIC_NUMBER;
2133 info = (struct smb2_fs_full_size_info *)(
2134 le16_to_cpu(rsp->OutputBufferOffset) + (char *)rsp);
2135 rc = smb2_validate_iov(le16_to_cpu(rsp->OutputBufferOffset),
2136 le32_to_cpu(rsp->OutputBufferLength),
2138 sizeof(struct smb2_fs_full_size_info));
2140 smb2_copy_fs_info_to_kstatfs(info, buf);
2143 free_rsp_buf(buftype, rsp_iov.iov_base);
2148 smb311_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
2149 struct kstatfs *buf)
2152 __le16 srch_path = 0; /* Null - open root of share */
2153 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2154 struct cifs_open_parms oparms;
2155 struct cifs_fid fid;
2157 if (!tcon->posix_extensions)
2158 return smb2_queryfs(xid, tcon, buf);
2161 oparms.desired_access = FILE_READ_ATTRIBUTES;
2162 oparms.disposition = FILE_OPEN;
2163 oparms.create_options = 0;
2165 oparms.reconnect = false;
2167 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, NULL);
2171 rc = SMB311_posix_qfs_info(xid, tcon, fid.persistent_fid,
2172 fid.volatile_fid, buf);
2173 buf->f_type = SMB2_MAGIC_NUMBER;
2174 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2179 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
2181 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
2182 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
2186 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
2187 __u64 length, __u32 type, int lock, int unlock, bool wait)
2189 if (unlock && !lock)
2190 type = SMB2_LOCKFLAG_UNLOCK;
2191 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
2192 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
2193 current->tgid, length, offset, type, wait);
2197 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
2199 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
2203 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
2205 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
2209 smb2_new_lease_key(struct cifs_fid *fid)
2211 generate_random_uuid(fid->lease_key);
2215 smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
2216 const char *search_name,
2217 struct dfs_info3_param **target_nodes,
2218 unsigned int *num_of_nodes,
2219 const struct nls_table *nls_codepage, int remap)
2222 __le16 *utf16_path = NULL;
2223 int utf16_path_len = 0;
2224 struct cifs_tcon *tcon;
2225 struct fsctl_get_dfs_referral_req *dfs_req = NULL;
2226 struct get_dfs_referral_rsp *dfs_rsp = NULL;
2227 u32 dfs_req_size = 0, dfs_rsp_size = 0;
2229 cifs_dbg(FYI, "smb2_get_dfs_refer path <%s>\n", search_name);
2232 * Try to use the IPC tcon, otherwise just use any
2234 tcon = ses->tcon_ipc;
2236 spin_lock(&cifs_tcp_ses_lock);
2237 tcon = list_first_entry_or_null(&ses->tcon_list,
2242 spin_unlock(&cifs_tcp_ses_lock);
2246 cifs_dbg(VFS, "session %p has no tcon available for a dfs referral request\n",
2252 utf16_path = cifs_strndup_to_utf16(search_name, PATH_MAX,
2254 nls_codepage, remap);
2260 dfs_req_size = sizeof(*dfs_req) + utf16_path_len;
2261 dfs_req = kzalloc(dfs_req_size, GFP_KERNEL);
2267 /* Highest DFS referral version understood */
2268 dfs_req->MaxReferralLevel = DFS_VERSION;
2270 /* Path to resolve in an UTF-16 null-terminated string */
2271 memcpy(dfs_req->RequestFileName, utf16_path, utf16_path_len);
2274 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
2275 FSCTL_DFS_GET_REFERRALS,
2276 true /* is_fsctl */,
2277 (char *)dfs_req, dfs_req_size,
2278 (char **)&dfs_rsp, &dfs_rsp_size);
2279 } while (rc == -EAGAIN);
2282 if ((rc != -ENOENT) && (rc != -EOPNOTSUPP))
2283 cifs_dbg(VFS, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc);
2287 rc = parse_dfs_referrals(dfs_rsp, dfs_rsp_size,
2288 num_of_nodes, target_nodes,
2289 nls_codepage, remap, search_name,
2290 true /* is_unicode */);
2292 cifs_dbg(VFS, "parse error in smb2_get_dfs_refer rc=%d\n", rc);
2297 if (tcon && !tcon->ipc) {
2298 /* ipc tcons are not refcounted */
2299 spin_lock(&cifs_tcp_ses_lock);
2301 spin_unlock(&cifs_tcp_ses_lock);
2308 #define SMB2_SYMLINK_STRUCT_SIZE \
2309 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
2312 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
2313 const char *full_path, char **target_path,
2314 struct cifs_sb_info *cifs_sb)
2318 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2319 struct cifs_open_parms oparms;
2320 struct cifs_fid fid;
2321 struct kvec err_iov = {NULL, 0};
2322 struct smb2_err_rsp *err_buf = NULL;
2324 struct smb2_symlink_err_rsp *symlink;
2325 unsigned int sub_len;
2326 unsigned int sub_offset;
2327 unsigned int print_len;
2328 unsigned int print_offset;
2330 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
2332 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
2337 oparms.desired_access = FILE_READ_ATTRIBUTES;
2338 oparms.disposition = FILE_OPEN;
2339 if (backup_cred(cifs_sb))
2340 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2342 oparms.create_options = 0;
2344 oparms.reconnect = false;
2346 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_iov,
2348 if (!rc || !err_iov.iov_base) {
2353 err_buf = err_iov.iov_base;
2354 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
2355 err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) {
2360 /* open must fail on symlink - reset rc */
2362 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
2363 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
2364 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
2365 print_len = le16_to_cpu(symlink->PrintNameLength);
2366 print_offset = le16_to_cpu(symlink->PrintNameOffset);
2368 if (err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
2373 if (err_iov.iov_len <
2374 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
2379 *target_path = cifs_strndup_from_utf16(
2380 (char *)symlink->PathBuffer + sub_offset,
2381 sub_len, true, cifs_sb->local_nls);
2382 if (!(*target_path)) {
2386 convert_delimiter(*target_path, '/');
2387 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
2390 free_rsp_buf(resp_buftype, err_buf);
2396 #ifdef CONFIG_CIFS_ACL
2397 static struct cifs_ntsd *
2398 get_smb2_acl_by_fid(struct cifs_sb_info *cifs_sb,
2399 const struct cifs_fid *cifsfid, u32 *pacllen)
2401 struct cifs_ntsd *pntsd = NULL;
2403 int rc = -EOPNOTSUPP;
2404 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
2407 return ERR_CAST(tlink);
2410 cifs_dbg(FYI, "trying to get acl\n");
2412 rc = SMB2_query_acl(xid, tlink_tcon(tlink), cifsfid->persistent_fid,
2413 cifsfid->volatile_fid, (void **)&pntsd, pacllen);
2416 cifs_put_tlink(tlink);
2418 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
2425 static struct cifs_ntsd *
2426 get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
2427 const char *path, u32 *pacllen)
2429 struct cifs_ntsd *pntsd = NULL;
2430 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2433 struct cifs_tcon *tcon;
2434 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
2435 struct cifs_fid fid;
2436 struct cifs_open_parms oparms;
2439 cifs_dbg(FYI, "get smb3 acl for path %s\n", path);
2441 return ERR_CAST(tlink);
2443 tcon = tlink_tcon(tlink);
2446 if (backup_cred(cifs_sb))
2447 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2449 oparms.create_options = 0;
2451 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2459 oparms.desired_access = READ_CONTROL;
2460 oparms.disposition = FILE_OPEN;
2462 oparms.reconnect = false;
2464 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
2467 rc = SMB2_query_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
2468 fid.volatile_fid, (void **)&pntsd, pacllen);
2469 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2472 cifs_put_tlink(tlink);
2475 cifs_dbg(FYI, "%s: rc = %d ACL len %d\n", __func__, rc, *pacllen);
2481 #ifdef CONFIG_CIFS_ACL
2483 set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
2484 struct inode *inode, const char *path, int aclflag)
2486 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
2488 int rc, access_flags = 0;
2489 struct cifs_tcon *tcon;
2490 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2491 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
2492 struct cifs_fid fid;
2493 struct cifs_open_parms oparms;
2496 cifs_dbg(FYI, "set smb3 acl for path %s\n", path);
2498 return PTR_ERR(tlink);
2500 tcon = tlink_tcon(tlink);
2503 if (backup_cred(cifs_sb))
2504 oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
2506 oparms.create_options = 0;
2508 if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP)
2509 access_flags = WRITE_OWNER;
2511 access_flags = WRITE_DAC;
2513 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
2521 oparms.desired_access = access_flags;
2522 oparms.disposition = FILE_OPEN;
2525 oparms.reconnect = false;
2527 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, NULL);
2530 rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid,
2531 fid.volatile_fid, pnntsd, acllen, aclflag);
2532 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2535 cifs_put_tlink(tlink);
2539 #endif /* CIFS_ACL */
2541 /* Retrieve an ACL from the server */
2542 static struct cifs_ntsd *
2543 get_smb2_acl(struct cifs_sb_info *cifs_sb,
2544 struct inode *inode, const char *path,
2547 struct cifs_ntsd *pntsd = NULL;
2548 struct cifsFileInfo *open_file = NULL;
2551 open_file = find_readable_file(CIFS_I(inode), true);
2553 return get_smb2_acl_by_path(cifs_sb, path, pacllen);
2555 pntsd = get_smb2_acl_by_fid(cifs_sb, &open_file->fid, pacllen);
2556 cifsFileInfo_put(open_file);
2561 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
2562 loff_t offset, loff_t len, bool keep_size)
2564 struct cifs_ses *ses = tcon->ses;
2565 struct inode *inode;
2566 struct cifsInodeInfo *cifsi;
2567 struct cifsFileInfo *cfile = file->private_data;
2568 struct file_zero_data_information fsctl_buf;
2569 struct smb_rqst rqst[2];
2570 int resp_buftype[2];
2571 struct kvec rsp_iov[2];
2572 struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2573 struct kvec si_iov[1];
2574 unsigned int size[1];
2578 int num = 0, flags = 0;
2583 inode = d_inode(cfile->dentry);
2584 cifsi = CIFS_I(inode);
2586 trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
2587 ses->Suid, offset, len);
2590 /* if file not oplocked can't be sure whether asking to extend size */
2591 if (!CIFS_CACHE_READ(cifsi))
2592 if (keep_size == false) {
2594 trace_smb3_zero_err(xid, cfile->fid.persistent_fid,
2595 tcon->tid, ses->Suid, offset, len, rc);
2601 * Must check if file sparse since fallocate -z (zero range) assumes
2602 * non-sparse allocation
2604 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE)) {
2606 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
2607 ses->Suid, offset, len, rc);
2612 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
2614 fsctl_buf.FileOffset = cpu_to_le64(offset);
2615 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
2617 if (smb3_encryption_required(tcon))
2618 flags |= CIFS_TRANSFORM_REQ;
2620 memset(rqst, 0, sizeof(rqst));
2621 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
2622 memset(rsp_iov, 0, sizeof(rsp_iov));
2625 memset(&io_iov, 0, sizeof(io_iov));
2626 rqst[num].rq_iov = io_iov;
2627 rqst[num].rq_nvec = SMB2_IOCTL_IOV_SIZE;
2628 rc = SMB2_ioctl_init(tcon, &rqst[num++], cfile->fid.persistent_fid,
2629 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
2630 true /* is_fctl */, (char *)&fsctl_buf,
2631 sizeof(struct file_zero_data_information));
2633 goto zero_range_exit;
2636 * do we also need to change the size of the file?
2638 if (keep_size == false && i_size_read(inode) < offset + len) {
2639 smb2_set_next_command(tcon, &rqst[0]);
2641 memset(&si_iov, 0, sizeof(si_iov));
2642 rqst[num].rq_iov = si_iov;
2643 rqst[num].rq_nvec = 1;
2645 eof = cpu_to_le64(offset + len);
2646 size[0] = 8; /* sizeof __le64 */
2649 rc = SMB2_set_info_init(tcon, &rqst[num++],
2650 cfile->fid.persistent_fid,
2651 cfile->fid.persistent_fid,
2653 FILE_END_OF_FILE_INFORMATION,
2654 SMB2_O_INFO_FILE, 0, data, size);
2655 smb2_set_related(&rqst[1]);
2658 rc = compound_send_recv(xid, ses, flags, num, rqst,
2659 resp_buftype, rsp_iov);
2662 SMB2_ioctl_free(&rqst[0]);
2663 SMB2_set_info_free(&rqst[1]);
2664 free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2665 free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2668 trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid,
2669 ses->Suid, offset, len, rc);
2671 trace_smb3_zero_done(xid, cfile->fid.persistent_fid, tcon->tid,
2672 ses->Suid, offset, len);
2676 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
2677 loff_t offset, loff_t len)
2679 struct inode *inode;
2680 struct cifsInodeInfo *cifsi;
2681 struct cifsFileInfo *cfile = file->private_data;
2682 struct file_zero_data_information fsctl_buf;
2685 __u8 set_sparse = 1;
2689 inode = d_inode(cfile->dentry);
2690 cifsi = CIFS_I(inode);
2692 /* Need to make file sparse, if not already, before freeing range. */
2693 /* Consider adding equivalent for compressed since it could also work */
2694 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
2700 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
2702 fsctl_buf.FileOffset = cpu_to_le64(offset);
2703 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
2705 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
2706 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
2707 true /* is_fctl */, (char *)&fsctl_buf,
2708 sizeof(struct file_zero_data_information), NULL, NULL);
2713 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
2714 loff_t off, loff_t len, bool keep_size)
2716 struct inode *inode;
2717 struct cifsInodeInfo *cifsi;
2718 struct cifsFileInfo *cfile = file->private_data;
2719 long rc = -EOPNOTSUPP;
2725 inode = d_inode(cfile->dentry);
2726 cifsi = CIFS_I(inode);
2728 trace_smb3_falloc_enter(xid, cfile->fid.persistent_fid, tcon->tid,
2729 tcon->ses->Suid, off, len);
2730 /* if file not oplocked can't be sure whether asking to extend size */
2731 if (!CIFS_CACHE_READ(cifsi))
2732 if (keep_size == false) {
2733 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
2734 tcon->tid, tcon->ses->Suid, off, len, rc);
2740 * Files are non-sparse by default so falloc may be a no-op
2741 * Must check if file sparse. If not sparse, and not extending
2742 * then no need to do anything since file already allocated
2744 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
2745 if (keep_size == true)
2747 /* check if extending file */
2748 else if (i_size_read(inode) >= off + len)
2749 /* not extending file and already not sparse */
2751 /* BB: in future add else clause to extend file */
2755 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
2756 tcon->tid, tcon->ses->Suid, off, len, rc);
2758 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid,
2759 tcon->tid, tcon->ses->Suid, off, len);
2764 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
2766 * Check if falloc starts within first few pages of file
2767 * and ends within a few pages of the end of file to
2768 * ensure that most of file is being forced to be
2769 * fallocated now. If so then setting whole file sparse
2770 * ie potentially making a few extra pages at the beginning
2771 * or end of the file non-sparse via set_sparse is harmless.
2773 if ((off > 8192) || (off + len + 8192 < i_size_read(inode))) {
2775 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid,
2776 tcon->tid, tcon->ses->Suid, off, len, rc);
2781 smb2_set_sparse(xid, tcon, cfile, inode, false);
2784 smb2_set_sparse(xid, tcon, cfile, inode, false);
2786 if (i_size_read(inode) < off + len) {
2787 eof = cpu_to_le64(off + len);
2788 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
2789 cfile->fid.volatile_fid, cfile->pid,
2795 trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
2796 tcon->ses->Suid, off, len, rc);
2798 trace_smb3_falloc_done(xid, cfile->fid.persistent_fid, tcon->tid,
2799 tcon->ses->Suid, off, len);
2806 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
2807 loff_t off, loff_t len)
2809 /* KEEP_SIZE already checked for by do_fallocate */
2810 if (mode & FALLOC_FL_PUNCH_HOLE)
2811 return smb3_punch_hole(file, tcon, off, len);
2812 else if (mode & FALLOC_FL_ZERO_RANGE) {
2813 if (mode & FALLOC_FL_KEEP_SIZE)
2814 return smb3_zero_range(file, tcon, off, len, true);
2815 return smb3_zero_range(file, tcon, off, len, false);
2816 } else if (mode == FALLOC_FL_KEEP_SIZE)
2817 return smb3_simple_falloc(file, tcon, off, len, true);
2819 return smb3_simple_falloc(file, tcon, off, len, false);
2825 smb2_downgrade_oplock(struct TCP_Server_Info *server,
2826 struct cifsInodeInfo *cinode, bool set_level2)
2829 server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
2832 server->ops->set_oplock_level(cinode, 0, 0, NULL);
2836 smb21_downgrade_oplock(struct TCP_Server_Info *server,
2837 struct cifsInodeInfo *cinode, bool set_level2)
2839 server->ops->set_oplock_level(cinode,
2840 set_level2 ? SMB2_LEASE_READ_CACHING_HE :
2845 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
2846 unsigned int epoch, bool *purge_cache)
2849 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
2851 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
2852 cinode->oplock = CIFS_CACHE_RHW_FLG;
2853 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
2854 &cinode->vfs_inode);
2855 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
2856 cinode->oplock = CIFS_CACHE_RW_FLG;
2857 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
2858 &cinode->vfs_inode);
2859 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
2860 cinode->oplock = CIFS_CACHE_READ_FLG;
2861 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
2862 &cinode->vfs_inode);
2868 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
2869 unsigned int epoch, bool *purge_cache)
2871 char message[5] = {0};
2874 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
2878 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
2879 cinode->oplock |= CIFS_CACHE_READ_FLG;
2880 strcat(message, "R");
2882 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
2883 cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
2884 strcat(message, "H");
2886 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
2887 cinode->oplock |= CIFS_CACHE_WRITE_FLG;
2888 strcat(message, "W");
2890 if (!cinode->oplock)
2891 strcat(message, "None");
2892 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
2893 &cinode->vfs_inode);
2897 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
2898 unsigned int epoch, bool *purge_cache)
2900 unsigned int old_oplock = cinode->oplock;
2902 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
2905 *purge_cache = false;
2906 if (old_oplock == CIFS_CACHE_READ_FLG) {
2907 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
2908 (epoch - cinode->epoch > 0))
2909 *purge_cache = true;
2910 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
2911 (epoch - cinode->epoch > 1))
2912 *purge_cache = true;
2913 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
2914 (epoch - cinode->epoch > 1))
2915 *purge_cache = true;
2916 else if (cinode->oplock == 0 &&
2917 (epoch - cinode->epoch > 0))
2918 *purge_cache = true;
2919 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
2920 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
2921 (epoch - cinode->epoch > 0))
2922 *purge_cache = true;
2923 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
2924 (epoch - cinode->epoch > 1))
2925 *purge_cache = true;
2927 cinode->epoch = epoch;
2932 smb2_is_read_op(__u32 oplock)
2934 return oplock == SMB2_OPLOCK_LEVEL_II;
2938 smb21_is_read_op(__u32 oplock)
2940 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
2941 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
2945 map_oplock_to_lease(u8 oplock)
2947 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
2948 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
2949 else if (oplock == SMB2_OPLOCK_LEVEL_II)
2950 return SMB2_LEASE_READ_CACHING;
2951 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
2952 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
2953 SMB2_LEASE_WRITE_CACHING;
2958 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
2960 struct create_lease *buf;
2962 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
2966 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
2967 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
2969 buf->ccontext.DataOffset = cpu_to_le16(offsetof
2970 (struct create_lease, lcontext));
2971 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
2972 buf->ccontext.NameOffset = cpu_to_le16(offsetof
2973 (struct create_lease, Name));
2974 buf->ccontext.NameLength = cpu_to_le16(4);
2975 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
2984 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
2986 struct create_lease_v2 *buf;
2988 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
2992 memcpy(&buf->lcontext.LeaseKey, lease_key, SMB2_LEASE_KEY_SIZE);
2993 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
2995 buf->ccontext.DataOffset = cpu_to_le16(offsetof
2996 (struct create_lease_v2, lcontext));
2997 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
2998 buf->ccontext.NameOffset = cpu_to_le16(offsetof
2999 (struct create_lease_v2, Name));
3000 buf->ccontext.NameLength = cpu_to_le16(4);
3001 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
3010 smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
3012 struct create_lease *lc = (struct create_lease *)buf;
3014 *epoch = 0; /* not used */
3015 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
3016 return SMB2_OPLOCK_LEVEL_NOCHANGE;
3017 return le32_to_cpu(lc->lcontext.LeaseState);
3021 smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
3023 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
3025 *epoch = le16_to_cpu(lc->lcontext.Epoch);
3026 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
3027 return SMB2_OPLOCK_LEVEL_NOCHANGE;
3029 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
3030 return le32_to_cpu(lc->lcontext.LeaseState);
3034 smb2_wp_retry_size(struct inode *inode)
3036 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
3037 SMB2_MAX_BUFFER_SIZE);
3041 smb2_dir_needs_close(struct cifsFileInfo *cfile)
3043 return !cfile->invalidHandle;
3047 fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
3048 struct smb_rqst *old_rq)
3050 struct smb2_sync_hdr *shdr =
3051 (struct smb2_sync_hdr *)old_rq->rq_iov[0].iov_base;
3053 memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
3054 tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
3055 tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
3056 tr_hdr->Flags = cpu_to_le16(0x01);
3057 get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
3058 memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
3061 /* We can not use the normal sg_set_buf() as we will sometimes pass a
3062 * stack object as buf.
3064 static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
3065 unsigned int buflen)
3067 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
3070 /* Assumes the first rqst has a transform header as the first iov.
3072 * rqst[0].rq_iov[0] is transform header
3073 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
3074 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
3076 static struct scatterlist *
3077 init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign)
3079 unsigned int sg_len;
3080 struct scatterlist *sg;
3083 unsigned int idx = 0;
3087 for (i = 0; i < num_rqst; i++)
3088 sg_len += rqst[i].rq_nvec + rqst[i].rq_npages;
3090 sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
3094 sg_init_table(sg, sg_len);
3095 for (i = 0; i < num_rqst; i++) {
3096 for (j = 0; j < rqst[i].rq_nvec; j++) {
3098 * The first rqst has a transform header where the
3099 * first 20 bytes are not part of the encrypted blob
3101 skip = (i == 0) && (j == 0) ? 20 : 0;
3102 smb2_sg_set_buf(&sg[idx++],
3103 rqst[i].rq_iov[j].iov_base + skip,
3104 rqst[i].rq_iov[j].iov_len - skip);
3107 for (j = 0; j < rqst[i].rq_npages; j++) {
3108 unsigned int len, offset;
3110 rqst_page_get_length(&rqst[i], j, &len, &offset);
3111 sg_set_page(&sg[idx++], rqst[i].rq_pages[j], len, offset);
3114 smb2_sg_set_buf(&sg[idx], sign, SMB2_SIGNATURE_SIZE);
3119 smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
3121 struct cifs_ses *ses;
3124 spin_lock(&cifs_tcp_ses_lock);
3125 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
3126 if (ses->Suid != ses_id)
3128 ses_enc_key = enc ? ses->smb3encryptionkey :
3129 ses->smb3decryptionkey;
3130 memcpy(key, ses_enc_key, SMB3_SIGN_KEY_SIZE);
3131 spin_unlock(&cifs_tcp_ses_lock);
3134 spin_unlock(&cifs_tcp_ses_lock);
3139 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
3140 * iov[0] - transform header (associate data),
3141 * iov[1-N] - SMB2 header and pages - data to encrypt.
3142 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
3146 crypt_message(struct TCP_Server_Info *server, int num_rqst,
3147 struct smb_rqst *rqst, int enc)
3149 struct smb2_transform_hdr *tr_hdr =
3150 (struct smb2_transform_hdr *)rqst[0].rq_iov[0].iov_base;
3151 unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
3153 struct scatterlist *sg;
3154 u8 sign[SMB2_SIGNATURE_SIZE] = {};
3155 u8 key[SMB3_SIGN_KEY_SIZE];
3156 struct aead_request *req;
3158 unsigned int iv_len;
3159 DECLARE_CRYPTO_WAIT(wait);
3160 struct crypto_aead *tfm;
3161 unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
3163 rc = smb2_get_enc_key(server, tr_hdr->SessionId, enc, key);
3165 cifs_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
3170 rc = smb3_crypto_aead_allocate(server);
3172 cifs_dbg(VFS, "%s: crypto alloc failed\n", __func__);
3176 tfm = enc ? server->secmech.ccmaesencrypt :
3177 server->secmech.ccmaesdecrypt;
3178 rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
3180 cifs_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
3184 rc = crypto_aead_setauthsize(tfm, SMB2_SIGNATURE_SIZE);
3186 cifs_dbg(VFS, "%s: Failed to set authsize %d\n", __func__, rc);
3190 req = aead_request_alloc(tfm, GFP_KERNEL);
3192 cifs_dbg(VFS, "%s: Failed to alloc aead request", __func__);
3197 memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
3198 crypt_len += SMB2_SIGNATURE_SIZE;
3201 sg = init_sg(num_rqst, rqst, sign);
3203 cifs_dbg(VFS, "%s: Failed to init sg", __func__);
3208 iv_len = crypto_aead_ivsize(tfm);
3209 iv = kzalloc(iv_len, GFP_KERNEL);
3211 cifs_dbg(VFS, "%s: Failed to alloc IV", __func__);
3216 memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
3218 aead_request_set_crypt(req, sg, sg, crypt_len, iv);
3219 aead_request_set_ad(req, assoc_data_len);
3221 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
3222 crypto_req_done, &wait);
3224 rc = crypto_wait_req(enc ? crypto_aead_encrypt(req)
3225 : crypto_aead_decrypt(req), &wait);
3228 memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
3239 smb3_free_compound_rqst(int num_rqst, struct smb_rqst *rqst)
3243 for (i = 0; i < num_rqst; i++) {
3244 if (rqst[i].rq_pages) {
3245 for (j = rqst[i].rq_npages - 1; j >= 0; j--)
3246 put_page(rqst[i].rq_pages[j]);
3247 kfree(rqst[i].rq_pages);
3253 * This function will initialize new_rq and encrypt the content.
3254 * The first entry, new_rq[0], only contains a single iov which contains
3255 * a smb2_transform_hdr and is pre-allocated by the caller.
3256 * This function then populates new_rq[1+] with the content from olq_rq[0+].
3258 * The end result is an array of smb_rqst structures where the first structure
3259 * only contains a single iov for the transform header which we then can pass
3260 * to crypt_message().
3262 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
3263 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
3266 smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
3267 struct smb_rqst *new_rq, struct smb_rqst *old_rq)
3269 struct page **pages;
3270 struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
3271 unsigned int npages;
3272 unsigned int orig_len = 0;
3276 for (i = 1; i < num_rqst; i++) {
3277 npages = old_rq[i - 1].rq_npages;
3278 pages = kmalloc_array(npages, sizeof(struct page *),
3283 new_rq[i].rq_pages = pages;
3284 new_rq[i].rq_npages = npages;
3285 new_rq[i].rq_offset = old_rq[i - 1].rq_offset;
3286 new_rq[i].rq_pagesz = old_rq[i - 1].rq_pagesz;
3287 new_rq[i].rq_tailsz = old_rq[i - 1].rq_tailsz;
3288 new_rq[i].rq_iov = old_rq[i - 1].rq_iov;
3289 new_rq[i].rq_nvec = old_rq[i - 1].rq_nvec;
3291 orig_len += smb_rqst_len(server, &old_rq[i - 1]);
3293 for (j = 0; j < npages; j++) {
3294 pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
3299 /* copy pages form the old */
3300 for (j = 0; j < npages; j++) {
3302 unsigned int offset, len;
3304 rqst_page_get_length(&new_rq[i], j, &len, &offset);
3306 dst = (char *) kmap(new_rq[i].rq_pages[j]) + offset;
3307 src = (char *) kmap(old_rq[i - 1].rq_pages[j]) + offset;
3309 memcpy(dst, src, len);
3310 kunmap(new_rq[i].rq_pages[j]);
3311 kunmap(old_rq[i - 1].rq_pages[j]);
3315 /* fill the 1st iov with a transform header */
3316 fill_transform_hdr(tr_hdr, orig_len, old_rq);
3318 rc = crypt_message(server, num_rqst, new_rq, 1);
3319 cifs_dbg(FYI, "encrypt message returned %d", rc);
3326 smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
3331 smb3_is_transform_hdr(void *buf)
3333 struct smb2_transform_hdr *trhdr = buf;
3335 return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
3339 decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
3340 unsigned int buf_data_size, struct page **pages,
3341 unsigned int npages, unsigned int page_data_size)
3344 struct smb_rqst rqst = {NULL};
3347 iov[0].iov_base = buf;
3348 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
3349 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
3350 iov[1].iov_len = buf_data_size;
3354 rqst.rq_pages = pages;
3355 rqst.rq_npages = npages;
3356 rqst.rq_pagesz = PAGE_SIZE;
3357 rqst.rq_tailsz = (page_data_size % PAGE_SIZE) ? : PAGE_SIZE;
3359 rc = crypt_message(server, 1, &rqst, 0);
3360 cifs_dbg(FYI, "decrypt message returned %d\n", rc);
3365 memmove(buf, iov[1].iov_base, buf_data_size);
3367 server->total_read = buf_data_size + page_data_size;
3373 read_data_into_pages(struct TCP_Server_Info *server, struct page **pages,
3374 unsigned int npages, unsigned int len)
3379 for (i = 0; i < npages; i++) {
3380 struct page *page = pages[i];
3384 if (len >= PAGE_SIZE) {
3385 /* enough data to fill the page */
3389 zero_user(page, len, PAGE_SIZE - len);
3392 length = cifs_read_page_from_socket(server, page, 0, n);
3395 server->total_read += length;
3402 init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
3403 unsigned int cur_off, struct bio_vec **page_vec)
3405 struct bio_vec *bvec;
3408 bvec = kcalloc(npages, sizeof(struct bio_vec), GFP_KERNEL);
3412 for (i = 0; i < npages; i++) {
3413 bvec[i].bv_page = pages[i];
3414 bvec[i].bv_offset = (i == 0) ? cur_off : 0;
3415 bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
3416 data_size -= bvec[i].bv_len;
3419 if (data_size != 0) {
3420 cifs_dbg(VFS, "%s: something went wrong\n", __func__);
3430 handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid,
3431 char *buf, unsigned int buf_len, struct page **pages,
3432 unsigned int npages, unsigned int page_data_size)
3434 unsigned int data_offset;
3435 unsigned int data_len;
3436 unsigned int cur_off;
3437 unsigned int cur_page_idx;
3438 unsigned int pad_len;
3439 struct cifs_readdata *rdata = mid->callback_data;
3440 struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
3441 struct bio_vec *bvec = NULL;
3442 struct iov_iter iter;
3445 bool use_rdma_mr = false;
3447 if (shdr->Command != SMB2_READ) {
3448 cifs_dbg(VFS, "only big read responses are supported\n");
3452 if (server->ops->is_session_expired &&
3453 server->ops->is_session_expired(buf)) {
3454 cifs_reconnect(server);
3455 wake_up(&server->response_q);
3459 if (server->ops->is_status_pending &&
3460 server->ops->is_status_pending(buf, server))
3463 /* set up first two iov to get credits */
3464 rdata->iov[0].iov_base = buf;
3465 rdata->iov[0].iov_len = 0;
3466 rdata->iov[1].iov_base = buf;
3467 rdata->iov[1].iov_len =
3468 min_t(unsigned int, buf_len, server->vals->read_rsp_size);
3469 cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
3470 rdata->iov[0].iov_base, rdata->iov[0].iov_len);
3471 cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
3472 rdata->iov[1].iov_base, rdata->iov[1].iov_len);
3474 rdata->result = server->ops->map_error(buf, true);
3475 if (rdata->result != 0) {
3476 cifs_dbg(FYI, "%s: server returned error %d\n",
3477 __func__, rdata->result);
3478 /* normal error on read response */
3479 dequeue_mid(mid, false);
3483 data_offset = server->ops->read_data_offset(buf);
3484 #ifdef CONFIG_CIFS_SMB_DIRECT
3485 use_rdma_mr = rdata->mr;
3487 data_len = server->ops->read_data_length(buf, use_rdma_mr);
3489 if (data_offset < server->vals->read_rsp_size) {
3491 * win2k8 sometimes sends an offset of 0 when the read
3492 * is beyond the EOF. Treat it as if the data starts just after
3495 cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
3496 __func__, data_offset);
3497 data_offset = server->vals->read_rsp_size;
3498 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
3499 /* data_offset is beyond the end of smallbuf */
3500 cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
3501 __func__, data_offset);
3502 rdata->result = -EIO;
3503 dequeue_mid(mid, rdata->result);
3507 pad_len = data_offset - server->vals->read_rsp_size;
3509 if (buf_len <= data_offset) {
3510 /* read response payload is in pages */
3511 cur_page_idx = pad_len / PAGE_SIZE;
3512 cur_off = pad_len % PAGE_SIZE;
3514 if (cur_page_idx != 0) {
3515 /* data offset is beyond the 1st page of response */
3516 cifs_dbg(FYI, "%s: data offset (%u) beyond 1st page of response\n",
3517 __func__, data_offset);
3518 rdata->result = -EIO;
3519 dequeue_mid(mid, rdata->result);
3523 if (data_len > page_data_size - pad_len) {
3524 /* data_len is corrupt -- discard frame */
3525 rdata->result = -EIO;
3526 dequeue_mid(mid, rdata->result);
3530 rdata->result = init_read_bvec(pages, npages, page_data_size,
3532 if (rdata->result != 0) {
3533 dequeue_mid(mid, rdata->result);
3537 iov_iter_bvec(&iter, WRITE, bvec, npages, data_len);
3538 } else if (buf_len >= data_offset + data_len) {
3539 /* read response payload is in buf */
3540 WARN_ONCE(npages > 0, "read data can be either in buf or in pages");
3541 iov.iov_base = buf + data_offset;
3542 iov.iov_len = data_len;
3543 iov_iter_kvec(&iter, WRITE, &iov, 1, data_len);
3545 /* read response payload cannot be in both buf and pages */
3546 WARN_ONCE(1, "buf can not contain only a part of read data");
3547 rdata->result = -EIO;
3548 dequeue_mid(mid, rdata->result);
3552 length = rdata->copy_into_pages(server, rdata, &iter);
3559 dequeue_mid(mid, false);
3564 receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid)
3566 char *buf = server->smallbuf;
3567 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
3568 unsigned int npages;
3569 struct page **pages;
3571 unsigned int buflen = server->pdu_size;
3575 len = min_t(unsigned int, buflen, server->vals->read_rsp_size +
3576 sizeof(struct smb2_transform_hdr)) - HEADER_SIZE(server) + 1;
3578 rc = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1, len);
3581 server->total_read += rc;
3583 len = le32_to_cpu(tr_hdr->OriginalMessageSize) -
3584 server->vals->read_rsp_size;
3585 npages = DIV_ROUND_UP(len, PAGE_SIZE);
3587 pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL);
3593 for (; i < npages; i++) {
3594 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
3601 /* read read data into pages */
3602 rc = read_data_into_pages(server, pages, npages, len);
3606 rc = cifs_discard_remaining_data(server);
3610 rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
3611 pages, npages, len);
3615 *mid = smb2_find_mid(server, buf);
3617 cifs_dbg(FYI, "mid not found\n");
3619 cifs_dbg(FYI, "mid found\n");
3620 (*mid)->decrypted = true;
3621 rc = handle_read_data(server, *mid, buf,
3622 server->vals->read_rsp_size,
3623 pages, npages, len);
3627 for (i = i - 1; i >= 0; i--)
3632 cifs_discard_remaining_data(server);
3637 receive_encrypted_standard(struct TCP_Server_Info *server,
3638 struct mid_q_entry **mids, char **bufs,
3642 char *buf = server->smallbuf;
3644 struct smb2_sync_hdr *shdr;
3645 unsigned int pdu_length = server->pdu_size;
3646 unsigned int buf_size;
3647 struct mid_q_entry *mid_entry;
3649 char *next_buffer = NULL;
3653 /* switch to large buffer if too big for a small one */
3654 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE) {
3655 server->large_buf = true;
3656 memcpy(server->bigbuf, buf, server->total_read);
3657 buf = server->bigbuf;
3660 /* now read the rest */
3661 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
3662 pdu_length - HEADER_SIZE(server) + 1);
3665 server->total_read += length;
3667 buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
3668 length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0);
3672 next_is_large = server->large_buf;
3674 shdr = (struct smb2_sync_hdr *)buf;
3675 if (shdr->NextCommand) {
3676 if (next_is_large) {
3677 tmpbuf = server->bigbuf;
3678 next_buffer = (char *)cifs_buf_get();
3680 tmpbuf = server->smallbuf;
3681 next_buffer = (char *)cifs_small_buf_get();
3684 tmpbuf + le32_to_cpu(shdr->NextCommand),
3685 pdu_length - le32_to_cpu(shdr->NextCommand));
3688 mid_entry = smb2_find_mid(server, buf);
3689 if (mid_entry == NULL)
3690 cifs_dbg(FYI, "mid not found\n");
3692 cifs_dbg(FYI, "mid found\n");
3693 mid_entry->decrypted = true;
3694 mid_entry->resp_buf_size = server->pdu_size;
3697 if (*num_mids >= MAX_COMPOUND) {
3698 cifs_dbg(VFS, "too many PDUs in compound\n");
3701 bufs[*num_mids] = buf;
3702 mids[(*num_mids)++] = mid_entry;
3704 if (mid_entry && mid_entry->handle)
3705 ret = mid_entry->handle(server, mid_entry);
3707 ret = cifs_handle_standard(server, mid_entry);
3709 if (ret == 0 && shdr->NextCommand) {
3710 pdu_length -= le32_to_cpu(shdr->NextCommand);
3711 server->large_buf = next_is_large;
3713 server->bigbuf = next_buffer;
3715 server->smallbuf = next_buffer;
3717 buf += le32_to_cpu(shdr->NextCommand);
3725 smb3_receive_transform(struct TCP_Server_Info *server,
3726 struct mid_q_entry **mids, char **bufs, int *num_mids)
3728 char *buf = server->smallbuf;
3729 unsigned int pdu_length = server->pdu_size;
3730 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
3731 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
3733 if (pdu_length < sizeof(struct smb2_transform_hdr) +
3734 sizeof(struct smb2_sync_hdr)) {
3735 cifs_dbg(VFS, "Transform message is too small (%u)\n",
3737 cifs_reconnect(server);
3738 wake_up(&server->response_q);
3739 return -ECONNABORTED;
3742 if (pdu_length < orig_len + sizeof(struct smb2_transform_hdr)) {
3743 cifs_dbg(VFS, "Transform message is broken\n");
3744 cifs_reconnect(server);
3745 wake_up(&server->response_q);
3746 return -ECONNABORTED;
3749 /* TODO: add support for compounds containing READ. */
3750 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server)) {
3752 return receive_encrypted_read(server, &mids[0]);
3755 return receive_encrypted_standard(server, mids, bufs, num_mids);
3759 smb3_handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid)
3761 char *buf = server->large_buf ? server->bigbuf : server->smallbuf;
3763 return handle_read_data(server, mid, buf, server->pdu_size,
3768 smb2_next_header(char *buf)
3770 struct smb2_sync_hdr *hdr = (struct smb2_sync_hdr *)buf;
3771 struct smb2_transform_hdr *t_hdr = (struct smb2_transform_hdr *)buf;
3773 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM)
3774 return sizeof(struct smb2_transform_hdr) +
3775 le32_to_cpu(t_hdr->OriginalMessageSize);
3777 return le32_to_cpu(hdr->NextCommand);
3781 smb2_make_node(unsigned int xid, struct inode *inode,
3782 struct dentry *dentry, struct cifs_tcon *tcon,
3783 char *full_path, umode_t mode, dev_t dev)
3785 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
3787 int create_options = CREATE_NOT_DIR | CREATE_OPTION_SPECIAL;
3788 FILE_ALL_INFO *buf = NULL;
3789 struct cifs_io_parms io_parms;
3791 struct cifs_fid fid;
3792 struct cifs_open_parms oparms;
3793 unsigned int bytes_written;
3794 struct win_dev *pdev;
3798 * Check if mounted with mount parm 'sfu' mount parm.
3799 * SFU emulation should work with all servers, but only
3800 * supports block and char device (no socket & fifo),
3801 * and was used by default in earlier versions of Windows
3803 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
3807 * TODO: Add ability to create instead via reparse point. Windows (e.g.
3808 * their current NFS server) uses this approach to expose special files
3809 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
3812 if (!S_ISCHR(mode) && !S_ISBLK(mode))
3815 cifs_dbg(FYI, "sfu compat create special file\n");
3817 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
3823 if (backup_cred(cifs_sb))
3824 create_options |= CREATE_OPEN_BACKUP_INTENT;
3827 oparms.cifs_sb = cifs_sb;
3828 oparms.desired_access = GENERIC_WRITE;
3829 oparms.create_options = create_options;
3830 oparms.disposition = FILE_CREATE;
3831 oparms.path = full_path;
3833 oparms.reconnect = false;
3835 if (tcon->ses->server->oplocks)
3836 oplock = REQ_OPLOCK;
3839 rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf);
3844 * BB Do not bother to decode buf since no local inode yet to put
3845 * timestamps in, but we can reuse it safely.
3848 pdev = (struct win_dev *)buf;
3849 io_parms.pid = current->tgid;
3850 io_parms.tcon = tcon;
3851 io_parms.offset = 0;
3852 io_parms.length = sizeof(struct win_dev);
3853 iov[1].iov_base = buf;
3854 iov[1].iov_len = sizeof(struct win_dev);
3855 if (S_ISCHR(mode)) {
3856 memcpy(pdev->type, "IntxCHR", 8);
3857 pdev->major = cpu_to_le64(MAJOR(dev));
3858 pdev->minor = cpu_to_le64(MINOR(dev));
3859 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
3860 &bytes_written, iov, 1);
3861 } else if (S_ISBLK(mode)) {
3862 memcpy(pdev->type, "IntxBLK", 8);
3863 pdev->major = cpu_to_le64(MAJOR(dev));
3864 pdev->minor = cpu_to_le64(MINOR(dev));
3865 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms,
3866 &bytes_written, iov, 1);
3868 tcon->ses->server->ops->close(xid, tcon, &fid);
3871 /* FIXME: add code here to set EAs */
3878 struct smb_version_operations smb20_operations = {
3879 .compare_fids = smb2_compare_fids,
3880 .setup_request = smb2_setup_request,
3881 .setup_async_request = smb2_setup_async_request,
3882 .check_receive = smb2_check_receive,
3883 .add_credits = smb2_add_credits,
3884 .set_credits = smb2_set_credits,
3885 .get_credits_field = smb2_get_credits_field,
3886 .get_credits = smb2_get_credits,
3887 .wait_mtu_credits = cifs_wait_mtu_credits,
3888 .get_next_mid = smb2_get_next_mid,
3889 .revert_current_mid = smb2_revert_current_mid,
3890 .read_data_offset = smb2_read_data_offset,
3891 .read_data_length = smb2_read_data_length,
3892 .map_error = map_smb2_to_linux_error,
3893 .find_mid = smb2_find_mid,
3894 .check_message = smb2_check_message,
3895 .dump_detail = smb2_dump_detail,
3896 .clear_stats = smb2_clear_stats,
3897 .print_stats = smb2_print_stats,
3898 .is_oplock_break = smb2_is_valid_oplock_break,
3899 .handle_cancelled_mid = smb2_handle_cancelled_mid,
3900 .downgrade_oplock = smb2_downgrade_oplock,
3901 .need_neg = smb2_need_neg,
3902 .negotiate = smb2_negotiate,
3903 .negotiate_wsize = smb2_negotiate_wsize,
3904 .negotiate_rsize = smb2_negotiate_rsize,
3905 .sess_setup = SMB2_sess_setup,
3906 .logoff = SMB2_logoff,
3907 .tree_connect = SMB2_tcon,
3908 .tree_disconnect = SMB2_tdis,
3909 .qfs_tcon = smb2_qfs_tcon,
3910 .is_path_accessible = smb2_is_path_accessible,
3911 .can_echo = smb2_can_echo,
3913 .query_path_info = smb2_query_path_info,
3914 .get_srv_inum = smb2_get_srv_inum,
3915 .query_file_info = smb2_query_file_info,
3916 .set_path_size = smb2_set_path_size,
3917 .set_file_size = smb2_set_file_size,
3918 .set_file_info = smb2_set_file_info,
3919 .set_compression = smb2_set_compression,
3920 .mkdir = smb2_mkdir,
3921 .mkdir_setinfo = smb2_mkdir_setinfo,
3922 .rmdir = smb2_rmdir,
3923 .unlink = smb2_unlink,
3924 .rename = smb2_rename_path,
3925 .create_hardlink = smb2_create_hardlink,
3926 .query_symlink = smb2_query_symlink,
3927 .query_mf_symlink = smb3_query_mf_symlink,
3928 .create_mf_symlink = smb3_create_mf_symlink,
3929 .open = smb2_open_file,
3930 .set_fid = smb2_set_fid,
3931 .close = smb2_close_file,
3932 .flush = smb2_flush_file,
3933 .async_readv = smb2_async_readv,
3934 .async_writev = smb2_async_writev,
3935 .sync_read = smb2_sync_read,
3936 .sync_write = smb2_sync_write,
3937 .query_dir_first = smb2_query_dir_first,
3938 .query_dir_next = smb2_query_dir_next,
3939 .close_dir = smb2_close_dir,
3940 .calc_smb_size = smb2_calc_size,
3941 .is_status_pending = smb2_is_status_pending,
3942 .is_session_expired = smb2_is_session_expired,
3943 .oplock_response = smb2_oplock_response,
3944 .queryfs = smb2_queryfs,
3945 .mand_lock = smb2_mand_lock,
3946 .mand_unlock_range = smb2_unlock_range,
3947 .push_mand_locks = smb2_push_mandatory_locks,
3948 .get_lease_key = smb2_get_lease_key,
3949 .set_lease_key = smb2_set_lease_key,
3950 .new_lease_key = smb2_new_lease_key,
3951 .calc_signature = smb2_calc_signature,
3952 .is_read_op = smb2_is_read_op,
3953 .set_oplock_level = smb2_set_oplock_level,
3954 .create_lease_buf = smb2_create_lease_buf,
3955 .parse_lease_buf = smb2_parse_lease_buf,
3956 .copychunk_range = smb2_copychunk_range,
3957 .wp_retry_size = smb2_wp_retry_size,
3958 .dir_needs_close = smb2_dir_needs_close,
3959 .get_dfs_refer = smb2_get_dfs_refer,
3960 .select_sectype = smb2_select_sectype,
3961 #ifdef CONFIG_CIFS_XATTR
3962 .query_all_EAs = smb2_query_eas,
3963 .set_EA = smb2_set_ea,
3964 #endif /* CIFS_XATTR */
3965 #ifdef CONFIG_CIFS_ACL
3966 .get_acl = get_smb2_acl,
3967 .get_acl_by_fid = get_smb2_acl_by_fid,
3968 .set_acl = set_smb2_acl,
3969 #endif /* CIFS_ACL */
3970 .next_header = smb2_next_header,
3971 .ioctl_query_info = smb2_ioctl_query_info,
3972 .make_node = smb2_make_node,
3975 struct smb_version_operations smb21_operations = {
3976 .compare_fids = smb2_compare_fids,
3977 .setup_request = smb2_setup_request,
3978 .setup_async_request = smb2_setup_async_request,
3979 .check_receive = smb2_check_receive,
3980 .add_credits = smb2_add_credits,
3981 .set_credits = smb2_set_credits,
3982 .get_credits_field = smb2_get_credits_field,
3983 .get_credits = smb2_get_credits,
3984 .wait_mtu_credits = smb2_wait_mtu_credits,
3985 .adjust_credits = smb2_adjust_credits,
3986 .get_next_mid = smb2_get_next_mid,
3987 .revert_current_mid = smb2_revert_current_mid,
3988 .read_data_offset = smb2_read_data_offset,
3989 .read_data_length = smb2_read_data_length,
3990 .map_error = map_smb2_to_linux_error,
3991 .find_mid = smb2_find_mid,
3992 .check_message = smb2_check_message,
3993 .dump_detail = smb2_dump_detail,
3994 .clear_stats = smb2_clear_stats,
3995 .print_stats = smb2_print_stats,
3996 .is_oplock_break = smb2_is_valid_oplock_break,
3997 .handle_cancelled_mid = smb2_handle_cancelled_mid,
3998 .downgrade_oplock = smb21_downgrade_oplock,
3999 .need_neg = smb2_need_neg,
4000 .negotiate = smb2_negotiate,
4001 .negotiate_wsize = smb2_negotiate_wsize,
4002 .negotiate_rsize = smb2_negotiate_rsize,
4003 .sess_setup = SMB2_sess_setup,
4004 .logoff = SMB2_logoff,
4005 .tree_connect = SMB2_tcon,
4006 .tree_disconnect = SMB2_tdis,
4007 .qfs_tcon = smb2_qfs_tcon,
4008 .is_path_accessible = smb2_is_path_accessible,
4009 .can_echo = smb2_can_echo,
4011 .query_path_info = smb2_query_path_info,
4012 .get_srv_inum = smb2_get_srv_inum,
4013 .query_file_info = smb2_query_file_info,
4014 .set_path_size = smb2_set_path_size,
4015 .set_file_size = smb2_set_file_size,
4016 .set_file_info = smb2_set_file_info,
4017 .set_compression = smb2_set_compression,
4018 .mkdir = smb2_mkdir,
4019 .mkdir_setinfo = smb2_mkdir_setinfo,
4020 .rmdir = smb2_rmdir,
4021 .unlink = smb2_unlink,
4022 .rename = smb2_rename_path,
4023 .create_hardlink = smb2_create_hardlink,
4024 .query_symlink = smb2_query_symlink,
4025 .query_mf_symlink = smb3_query_mf_symlink,
4026 .create_mf_symlink = smb3_create_mf_symlink,
4027 .open = smb2_open_file,
4028 .set_fid = smb2_set_fid,
4029 .close = smb2_close_file,
4030 .flush = smb2_flush_file,
4031 .async_readv = smb2_async_readv,
4032 .async_writev = smb2_async_writev,
4033 .sync_read = smb2_sync_read,
4034 .sync_write = smb2_sync_write,
4035 .query_dir_first = smb2_query_dir_first,
4036 .query_dir_next = smb2_query_dir_next,
4037 .close_dir = smb2_close_dir,
4038 .calc_smb_size = smb2_calc_size,
4039 .is_status_pending = smb2_is_status_pending,
4040 .is_session_expired = smb2_is_session_expired,
4041 .oplock_response = smb2_oplock_response,
4042 .queryfs = smb2_queryfs,
4043 .mand_lock = smb2_mand_lock,
4044 .mand_unlock_range = smb2_unlock_range,
4045 .push_mand_locks = smb2_push_mandatory_locks,
4046 .get_lease_key = smb2_get_lease_key,
4047 .set_lease_key = smb2_set_lease_key,
4048 .new_lease_key = smb2_new_lease_key,
4049 .calc_signature = smb2_calc_signature,
4050 .is_read_op = smb21_is_read_op,
4051 .set_oplock_level = smb21_set_oplock_level,
4052 .create_lease_buf = smb2_create_lease_buf,
4053 .parse_lease_buf = smb2_parse_lease_buf,
4054 .copychunk_range = smb2_copychunk_range,
4055 .wp_retry_size = smb2_wp_retry_size,
4056 .dir_needs_close = smb2_dir_needs_close,
4057 .enum_snapshots = smb3_enum_snapshots,
4058 .get_dfs_refer = smb2_get_dfs_refer,
4059 .select_sectype = smb2_select_sectype,
4060 #ifdef CONFIG_CIFS_XATTR
4061 .query_all_EAs = smb2_query_eas,
4062 .set_EA = smb2_set_ea,
4063 #endif /* CIFS_XATTR */
4064 #ifdef CONFIG_CIFS_ACL
4065 .get_acl = get_smb2_acl,
4066 .get_acl_by_fid = get_smb2_acl_by_fid,
4067 .set_acl = set_smb2_acl,
4068 #endif /* CIFS_ACL */
4069 .next_header = smb2_next_header,
4070 .ioctl_query_info = smb2_ioctl_query_info,
4071 .make_node = smb2_make_node,
4074 struct smb_version_operations smb30_operations = {
4075 .compare_fids = smb2_compare_fids,
4076 .setup_request = smb2_setup_request,
4077 .setup_async_request = smb2_setup_async_request,
4078 .check_receive = smb2_check_receive,
4079 .add_credits = smb2_add_credits,
4080 .set_credits = smb2_set_credits,
4081 .get_credits_field = smb2_get_credits_field,
4082 .get_credits = smb2_get_credits,
4083 .wait_mtu_credits = smb2_wait_mtu_credits,
4084 .adjust_credits = smb2_adjust_credits,
4085 .get_next_mid = smb2_get_next_mid,
4086 .revert_current_mid = smb2_revert_current_mid,
4087 .read_data_offset = smb2_read_data_offset,
4088 .read_data_length = smb2_read_data_length,
4089 .map_error = map_smb2_to_linux_error,
4090 .find_mid = smb2_find_mid,
4091 .check_message = smb2_check_message,
4092 .dump_detail = smb2_dump_detail,
4093 .clear_stats = smb2_clear_stats,
4094 .print_stats = smb2_print_stats,
4095 .dump_share_caps = smb2_dump_share_caps,
4096 .is_oplock_break = smb2_is_valid_oplock_break,
4097 .handle_cancelled_mid = smb2_handle_cancelled_mid,
4098 .downgrade_oplock = smb21_downgrade_oplock,
4099 .need_neg = smb2_need_neg,
4100 .negotiate = smb2_negotiate,
4101 .negotiate_wsize = smb3_negotiate_wsize,
4102 .negotiate_rsize = smb3_negotiate_rsize,
4103 .sess_setup = SMB2_sess_setup,
4104 .logoff = SMB2_logoff,
4105 .tree_connect = SMB2_tcon,
4106 .tree_disconnect = SMB2_tdis,
4107 .qfs_tcon = smb3_qfs_tcon,
4108 .is_path_accessible = smb2_is_path_accessible,
4109 .can_echo = smb2_can_echo,
4111 .query_path_info = smb2_query_path_info,
4112 .get_srv_inum = smb2_get_srv_inum,
4113 .query_file_info = smb2_query_file_info,
4114 .set_path_size = smb2_set_path_size,
4115 .set_file_size = smb2_set_file_size,
4116 .set_file_info = smb2_set_file_info,
4117 .set_compression = smb2_set_compression,
4118 .mkdir = smb2_mkdir,
4119 .mkdir_setinfo = smb2_mkdir_setinfo,
4120 .rmdir = smb2_rmdir,
4121 .unlink = smb2_unlink,
4122 .rename = smb2_rename_path,
4123 .create_hardlink = smb2_create_hardlink,
4124 .query_symlink = smb2_query_symlink,
4125 .query_mf_symlink = smb3_query_mf_symlink,
4126 .create_mf_symlink = smb3_create_mf_symlink,
4127 .open = smb2_open_file,
4128 .set_fid = smb2_set_fid,
4129 .close = smb2_close_file,
4130 .flush = smb2_flush_file,
4131 .async_readv = smb2_async_readv,
4132 .async_writev = smb2_async_writev,
4133 .sync_read = smb2_sync_read,
4134 .sync_write = smb2_sync_write,
4135 .query_dir_first = smb2_query_dir_first,
4136 .query_dir_next = smb2_query_dir_next,
4137 .close_dir = smb2_close_dir,
4138 .calc_smb_size = smb2_calc_size,
4139 .is_status_pending = smb2_is_status_pending,
4140 .is_session_expired = smb2_is_session_expired,
4141 .oplock_response = smb2_oplock_response,
4142 .queryfs = smb2_queryfs,
4143 .mand_lock = smb2_mand_lock,
4144 .mand_unlock_range = smb2_unlock_range,
4145 .push_mand_locks = smb2_push_mandatory_locks,
4146 .get_lease_key = smb2_get_lease_key,
4147 .set_lease_key = smb2_set_lease_key,
4148 .new_lease_key = smb2_new_lease_key,
4149 .generate_signingkey = generate_smb30signingkey,
4150 .calc_signature = smb3_calc_signature,
4151 .set_integrity = smb3_set_integrity,
4152 .is_read_op = smb21_is_read_op,
4153 .set_oplock_level = smb3_set_oplock_level,
4154 .create_lease_buf = smb3_create_lease_buf,
4155 .parse_lease_buf = smb3_parse_lease_buf,
4156 .copychunk_range = smb2_copychunk_range,
4157 .duplicate_extents = smb2_duplicate_extents,
4158 .validate_negotiate = smb3_validate_negotiate,
4159 .wp_retry_size = smb2_wp_retry_size,
4160 .dir_needs_close = smb2_dir_needs_close,
4161 .fallocate = smb3_fallocate,
4162 .enum_snapshots = smb3_enum_snapshots,
4163 .init_transform_rq = smb3_init_transform_rq,
4164 .is_transform_hdr = smb3_is_transform_hdr,
4165 .receive_transform = smb3_receive_transform,
4166 .get_dfs_refer = smb2_get_dfs_refer,
4167 .select_sectype = smb2_select_sectype,
4168 #ifdef CONFIG_CIFS_XATTR
4169 .query_all_EAs = smb2_query_eas,
4170 .set_EA = smb2_set_ea,
4171 #endif /* CIFS_XATTR */
4172 #ifdef CONFIG_CIFS_ACL
4173 .get_acl = get_smb2_acl,
4174 .get_acl_by_fid = get_smb2_acl_by_fid,
4175 .set_acl = set_smb2_acl,
4176 #endif /* CIFS_ACL */
4177 .next_header = smb2_next_header,
4178 .ioctl_query_info = smb2_ioctl_query_info,
4179 .make_node = smb2_make_node,
4182 struct smb_version_operations smb311_operations = {
4183 .compare_fids = smb2_compare_fids,
4184 .setup_request = smb2_setup_request,
4185 .setup_async_request = smb2_setup_async_request,
4186 .check_receive = smb2_check_receive,
4187 .add_credits = smb2_add_credits,
4188 .set_credits = smb2_set_credits,
4189 .get_credits_field = smb2_get_credits_field,
4190 .get_credits = smb2_get_credits,
4191 .wait_mtu_credits = smb2_wait_mtu_credits,
4192 .adjust_credits = smb2_adjust_credits,
4193 .get_next_mid = smb2_get_next_mid,
4194 .revert_current_mid = smb2_revert_current_mid,
4195 .read_data_offset = smb2_read_data_offset,
4196 .read_data_length = smb2_read_data_length,
4197 .map_error = map_smb2_to_linux_error,
4198 .find_mid = smb2_find_mid,
4199 .check_message = smb2_check_message,
4200 .dump_detail = smb2_dump_detail,
4201 .clear_stats = smb2_clear_stats,
4202 .print_stats = smb2_print_stats,
4203 .dump_share_caps = smb2_dump_share_caps,
4204 .is_oplock_break = smb2_is_valid_oplock_break,
4205 .handle_cancelled_mid = smb2_handle_cancelled_mid,
4206 .downgrade_oplock = smb21_downgrade_oplock,
4207 .need_neg = smb2_need_neg,
4208 .negotiate = smb2_negotiate,
4209 .negotiate_wsize = smb3_negotiate_wsize,
4210 .negotiate_rsize = smb3_negotiate_rsize,
4211 .sess_setup = SMB2_sess_setup,
4212 .logoff = SMB2_logoff,
4213 .tree_connect = SMB2_tcon,
4214 .tree_disconnect = SMB2_tdis,
4215 .qfs_tcon = smb3_qfs_tcon,
4216 .is_path_accessible = smb2_is_path_accessible,
4217 .can_echo = smb2_can_echo,
4219 .query_path_info = smb2_query_path_info,
4220 .get_srv_inum = smb2_get_srv_inum,
4221 .query_file_info = smb2_query_file_info,
4222 .set_path_size = smb2_set_path_size,
4223 .set_file_size = smb2_set_file_size,
4224 .set_file_info = smb2_set_file_info,
4225 .set_compression = smb2_set_compression,
4226 .mkdir = smb2_mkdir,
4227 .mkdir_setinfo = smb2_mkdir_setinfo,
4228 .posix_mkdir = smb311_posix_mkdir,
4229 .rmdir = smb2_rmdir,
4230 .unlink = smb2_unlink,
4231 .rename = smb2_rename_path,
4232 .create_hardlink = smb2_create_hardlink,
4233 .query_symlink = smb2_query_symlink,
4234 .query_mf_symlink = smb3_query_mf_symlink,
4235 .create_mf_symlink = smb3_create_mf_symlink,
4236 .open = smb2_open_file,
4237 .set_fid = smb2_set_fid,
4238 .close = smb2_close_file,
4239 .flush = smb2_flush_file,
4240 .async_readv = smb2_async_readv,
4241 .async_writev = smb2_async_writev,
4242 .sync_read = smb2_sync_read,
4243 .sync_write = smb2_sync_write,
4244 .query_dir_first = smb2_query_dir_first,
4245 .query_dir_next = smb2_query_dir_next,
4246 .close_dir = smb2_close_dir,
4247 .calc_smb_size = smb2_calc_size,
4248 .is_status_pending = smb2_is_status_pending,
4249 .is_session_expired = smb2_is_session_expired,
4250 .oplock_response = smb2_oplock_response,
4251 .queryfs = smb311_queryfs,
4252 .mand_lock = smb2_mand_lock,
4253 .mand_unlock_range = smb2_unlock_range,
4254 .push_mand_locks = smb2_push_mandatory_locks,
4255 .get_lease_key = smb2_get_lease_key,
4256 .set_lease_key = smb2_set_lease_key,
4257 .new_lease_key = smb2_new_lease_key,
4258 .generate_signingkey = generate_smb311signingkey,
4259 .calc_signature = smb3_calc_signature,
4260 .set_integrity = smb3_set_integrity,
4261 .is_read_op = smb21_is_read_op,
4262 .set_oplock_level = smb3_set_oplock_level,
4263 .create_lease_buf = smb3_create_lease_buf,
4264 .parse_lease_buf = smb3_parse_lease_buf,
4265 .copychunk_range = smb2_copychunk_range,
4266 .duplicate_extents = smb2_duplicate_extents,
4267 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
4268 .wp_retry_size = smb2_wp_retry_size,
4269 .dir_needs_close = smb2_dir_needs_close,
4270 .fallocate = smb3_fallocate,
4271 .enum_snapshots = smb3_enum_snapshots,
4272 .init_transform_rq = smb3_init_transform_rq,
4273 .is_transform_hdr = smb3_is_transform_hdr,
4274 .receive_transform = smb3_receive_transform,
4275 .get_dfs_refer = smb2_get_dfs_refer,
4276 .select_sectype = smb2_select_sectype,
4277 #ifdef CONFIG_CIFS_XATTR
4278 .query_all_EAs = smb2_query_eas,
4279 .set_EA = smb2_set_ea,
4280 #endif /* CIFS_XATTR */
4281 #ifdef CONFIG_CIFS_ACL
4282 .get_acl = get_smb2_acl,
4283 .get_acl_by_fid = get_smb2_acl_by_fid,
4284 .set_acl = set_smb2_acl,
4285 #endif /* CIFS_ACL */
4286 .next_header = smb2_next_header,
4287 .ioctl_query_info = smb2_ioctl_query_info,
4288 .make_node = smb2_make_node,
4291 struct smb_version_values smb20_values = {
4292 .version_string = SMB20_VERSION_STRING,
4293 .protocol_id = SMB20_PROT_ID,
4294 .req_capabilities = 0, /* MBZ */
4295 .large_lock_type = 0,
4296 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4297 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4298 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4299 .header_size = sizeof(struct smb2_sync_hdr),
4300 .header_preamble_size = 0,
4301 .max_header_size = MAX_SMB2_HDR_SIZE,
4302 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4303 .lock_cmd = SMB2_LOCK,
4305 .cap_nt_find = SMB2_NT_FIND,
4306 .cap_large_files = SMB2_LARGE_FILES,
4307 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4308 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4309 .create_lease_size = sizeof(struct create_lease),
4312 struct smb_version_values smb21_values = {
4313 .version_string = SMB21_VERSION_STRING,
4314 .protocol_id = SMB21_PROT_ID,
4315 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
4316 .large_lock_type = 0,
4317 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4318 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4319 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4320 .header_size = sizeof(struct smb2_sync_hdr),
4321 .header_preamble_size = 0,
4322 .max_header_size = MAX_SMB2_HDR_SIZE,
4323 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4324 .lock_cmd = SMB2_LOCK,
4326 .cap_nt_find = SMB2_NT_FIND,
4327 .cap_large_files = SMB2_LARGE_FILES,
4328 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4329 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4330 .create_lease_size = sizeof(struct create_lease),
4333 struct smb_version_values smb3any_values = {
4334 .version_string = SMB3ANY_VERSION_STRING,
4335 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
4336 .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,
4337 .large_lock_type = 0,
4338 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4339 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4340 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4341 .header_size = sizeof(struct smb2_sync_hdr),
4342 .header_preamble_size = 0,
4343 .max_header_size = MAX_SMB2_HDR_SIZE,
4344 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4345 .lock_cmd = SMB2_LOCK,
4347 .cap_nt_find = SMB2_NT_FIND,
4348 .cap_large_files = SMB2_LARGE_FILES,
4349 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4350 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4351 .create_lease_size = sizeof(struct create_lease_v2),
4354 struct smb_version_values smbdefault_values = {
4355 .version_string = SMBDEFAULT_VERSION_STRING,
4356 .protocol_id = SMB302_PROT_ID, /* doesn't matter, send protocol array */
4357 .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,
4358 .large_lock_type = 0,
4359 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4360 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4361 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4362 .header_size = sizeof(struct smb2_sync_hdr),
4363 .header_preamble_size = 0,
4364 .max_header_size = MAX_SMB2_HDR_SIZE,
4365 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4366 .lock_cmd = SMB2_LOCK,
4368 .cap_nt_find = SMB2_NT_FIND,
4369 .cap_large_files = SMB2_LARGE_FILES,
4370 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4371 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4372 .create_lease_size = sizeof(struct create_lease_v2),
4375 struct smb_version_values smb30_values = {
4376 .version_string = SMB30_VERSION_STRING,
4377 .protocol_id = SMB30_PROT_ID,
4378 .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,
4379 .large_lock_type = 0,
4380 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4381 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4382 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4383 .header_size = sizeof(struct smb2_sync_hdr),
4384 .header_preamble_size = 0,
4385 .max_header_size = MAX_SMB2_HDR_SIZE,
4386 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4387 .lock_cmd = SMB2_LOCK,
4389 .cap_nt_find = SMB2_NT_FIND,
4390 .cap_large_files = SMB2_LARGE_FILES,
4391 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4392 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4393 .create_lease_size = sizeof(struct create_lease_v2),
4396 struct smb_version_values smb302_values = {
4397 .version_string = SMB302_VERSION_STRING,
4398 .protocol_id = SMB302_PROT_ID,
4399 .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,
4400 .large_lock_type = 0,
4401 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4402 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4403 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4404 .header_size = sizeof(struct smb2_sync_hdr),
4405 .header_preamble_size = 0,
4406 .max_header_size = MAX_SMB2_HDR_SIZE,
4407 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4408 .lock_cmd = SMB2_LOCK,
4410 .cap_nt_find = SMB2_NT_FIND,
4411 .cap_large_files = SMB2_LARGE_FILES,
4412 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4413 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4414 .create_lease_size = sizeof(struct create_lease_v2),
4417 struct smb_version_values smb311_values = {
4418 .version_string = SMB311_VERSION_STRING,
4419 .protocol_id = SMB311_PROT_ID,
4420 .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,
4421 .large_lock_type = 0,
4422 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
4423 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
4424 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
4425 .header_size = sizeof(struct smb2_sync_hdr),
4426 .header_preamble_size = 0,
4427 .max_header_size = MAX_SMB2_HDR_SIZE,
4428 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
4429 .lock_cmd = SMB2_LOCK,
4431 .cap_nt_find = SMB2_NT_FIND,
4432 .cap_large_files = SMB2_LARGE_FILES,
4433 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
4434 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
4435 .create_lease_size = sizeof(struct create_lease_v2),