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
, const unsigned int add
,
75 spin_lock(&server
->req_lock
);
76 val
= server
->ops
->get_credits_field(server
, optype
);
78 /* eg found case where write overlapping reconnect messed up credits */
79 if (((optype
& CIFS_OP_MASK
) == CIFS_NEG_OP
) && (*val
!= 0))
80 trace_smb3_reconnect_with_invalid_credits(server
->CurrentMid
,
81 server
->hostname
, *val
);
85 *val
= 65000; /* Don't get near 64K credits, avoid srv bugs */
86 printk_once(KERN_WARNING
"server overflowed SMB3 credits\n");
89 if (server
->in_flight
== 0 && (optype
& CIFS_OP_MASK
) != CIFS_NEG_OP
)
90 rc
= change_conf(server
);
92 * Sometimes server returns 0 credits on oplock break ack - we need to
93 * rebalance credits in this case.
95 else if (server
->in_flight
> 0 && server
->oplock_credits
== 0 &&
97 if (server
->credits
> 1) {
99 server
->oplock_credits
++;
102 spin_unlock(&server
->req_lock
);
103 wake_up(&server
->request_q
);
105 if (server
->tcpStatus
== CifsNeedReconnect
)
110 /* change_conf hasn't been executed */
113 cifs_dbg(VFS
, "Possible client or server bug - zero credits\n");
116 cifs_dbg(VFS
, "disabling echoes and oplocks\n");
119 cifs_dbg(FYI
, "disabling oplocks\n");
122 cifs_dbg(FYI
, "add %u credits total=%d\n", add
, rc
);
127 smb2_set_credits(struct TCP_Server_Info
*server
, const int val
)
129 spin_lock(&server
->req_lock
);
130 server
->credits
= val
;
132 server
->reconnect_instance
++;
133 spin_unlock(&server
->req_lock
);
134 /* don't log while holding the lock */
136 cifs_dbg(FYI
, "set credits to 1 due to smb2 reconnect\n");
140 smb2_get_credits_field(struct TCP_Server_Info
*server
, const int optype
)
144 return &server
->echo_credits
;
146 return &server
->oplock_credits
;
148 return &server
->credits
;
153 smb2_get_credits(struct mid_q_entry
*mid
)
155 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)mid
->resp_buf
;
157 return le16_to_cpu(shdr
->CreditRequest
);
161 smb2_wait_mtu_credits(struct TCP_Server_Info
*server
, unsigned int size
,
162 unsigned int *num
, unsigned int *credits
)
165 unsigned int scredits
;
167 spin_lock(&server
->req_lock
);
169 if (server
->credits
<= 0) {
170 spin_unlock(&server
->req_lock
);
171 cifs_num_waiters_inc(server
);
172 rc
= wait_event_killable(server
->request_q
,
173 has_credits(server
, &server
->credits
));
174 cifs_num_waiters_dec(server
);
177 spin_lock(&server
->req_lock
);
179 if (server
->tcpStatus
== CifsExiting
) {
180 spin_unlock(&server
->req_lock
);
184 scredits
= server
->credits
;
185 /* can deadlock with reopen */
187 *num
= SMB2_MAX_BUFFER_SIZE
;
192 /* leave some credits for reopen and other ops */
194 *num
= min_t(unsigned int, size
,
195 scredits
* SMB2_MAX_BUFFER_SIZE
);
197 *credits
= DIV_ROUND_UP(*num
, SMB2_MAX_BUFFER_SIZE
);
198 server
->credits
-= *credits
;
203 spin_unlock(&server
->req_lock
);
208 smb2_get_next_mid(struct TCP_Server_Info
*server
)
211 /* for SMB2 we need the current value */
212 spin_lock(&GlobalMid_Lock
);
213 mid
= server
->CurrentMid
++;
214 spin_unlock(&GlobalMid_Lock
);
218 static struct mid_q_entry
*
219 smb2_find_mid(struct TCP_Server_Info
*server
, char *buf
)
221 struct mid_q_entry
*mid
;
222 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
223 __u64 wire_mid
= le64_to_cpu(shdr
->MessageId
);
225 if (shdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
) {
226 cifs_dbg(VFS
, "encrypted frame parsing not supported yet");
230 spin_lock(&GlobalMid_Lock
);
231 list_for_each_entry(mid
, &server
->pending_mid_q
, qhead
) {
232 if ((mid
->mid
== wire_mid
) &&
233 (mid
->mid_state
== MID_REQUEST_SUBMITTED
) &&
234 (mid
->command
== shdr
->Command
)) {
235 kref_get(&mid
->refcount
);
236 spin_unlock(&GlobalMid_Lock
);
240 spin_unlock(&GlobalMid_Lock
);
245 smb2_dump_detail(void *buf
, struct TCP_Server_Info
*server
)
247 #ifdef CONFIG_CIFS_DEBUG2
248 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
250 cifs_dbg(VFS
, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
251 shdr
->Command
, shdr
->Status
, shdr
->Flags
, shdr
->MessageId
,
253 cifs_dbg(VFS
, "smb buf %p len %u\n", buf
,
254 server
->ops
->calc_smb_size(buf
, server
));
259 smb2_need_neg(struct TCP_Server_Info
*server
)
261 return server
->max_read
== 0;
265 smb2_negotiate(const unsigned int xid
, struct cifs_ses
*ses
)
268 ses
->server
->CurrentMid
= 0;
269 rc
= SMB2_negotiate(xid
, ses
);
270 /* BB we probably don't need to retry with modern servers */
277 smb2_negotiate_wsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
279 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
282 /* start with specified wsize, or default */
283 wsize
= volume_info
->wsize
? volume_info
->wsize
: CIFS_DEFAULT_IOSIZE
;
284 wsize
= min_t(unsigned int, wsize
, server
->max_write
);
285 #ifdef CONFIG_CIFS_SMB_DIRECT
288 wsize
= min_t(unsigned int,
289 wsize
, server
->smbd_conn
->max_fragmented_send_size
);
291 wsize
= min_t(unsigned int,
292 wsize
, server
->smbd_conn
->max_readwrite_size
);
295 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
296 wsize
= min_t(unsigned int, wsize
, SMB2_MAX_BUFFER_SIZE
);
302 smb3_negotiate_wsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
304 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
307 /* start with specified wsize, or default */
308 wsize
= volume_info
->wsize
? volume_info
->wsize
: SMB3_DEFAULT_IOSIZE
;
309 wsize
= min_t(unsigned int, wsize
, server
->max_write
);
310 #ifdef CONFIG_CIFS_SMB_DIRECT
313 wsize
= min_t(unsigned int,
314 wsize
, server
->smbd_conn
->max_fragmented_send_size
);
316 wsize
= min_t(unsigned int,
317 wsize
, server
->smbd_conn
->max_readwrite_size
);
320 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
321 wsize
= min_t(unsigned int, wsize
, SMB2_MAX_BUFFER_SIZE
);
327 smb2_negotiate_rsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
329 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
332 /* start with specified rsize, or default */
333 rsize
= volume_info
->rsize
? volume_info
->rsize
: CIFS_DEFAULT_IOSIZE
;
334 rsize
= min_t(unsigned int, rsize
, server
->max_read
);
335 #ifdef CONFIG_CIFS_SMB_DIRECT
338 rsize
= min_t(unsigned int,
339 rsize
, server
->smbd_conn
->max_fragmented_recv_size
);
341 rsize
= min_t(unsigned int,
342 rsize
, server
->smbd_conn
->max_readwrite_size
);
346 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
347 rsize
= min_t(unsigned int, rsize
, SMB2_MAX_BUFFER_SIZE
);
353 smb3_negotiate_rsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
355 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
358 /* start with specified rsize, or default */
359 rsize
= volume_info
->rsize
? volume_info
->rsize
: SMB3_DEFAULT_IOSIZE
;
360 rsize
= min_t(unsigned int, rsize
, server
->max_read
);
361 #ifdef CONFIG_CIFS_SMB_DIRECT
364 rsize
= min_t(unsigned int,
365 rsize
, server
->smbd_conn
->max_fragmented_recv_size
);
367 rsize
= min_t(unsigned int,
368 rsize
, server
->smbd_conn
->max_readwrite_size
);
372 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
373 rsize
= min_t(unsigned int, rsize
, SMB2_MAX_BUFFER_SIZE
);
379 parse_server_interfaces(struct network_interface_info_ioctl_rsp
*buf
,
381 struct cifs_server_iface
**iface_list
,
384 struct network_interface_info_ioctl_rsp
*p
;
385 struct sockaddr_in
*addr4
;
386 struct sockaddr_in6
*addr6
;
387 struct iface_info_ipv4
*p4
;
388 struct iface_info_ipv6
*p6
;
389 struct cifs_server_iface
*info
;
399 * Fist pass: count and sanity check
402 bytes_left
= buf_len
;
404 while (bytes_left
>= sizeof(*p
)) {
406 next
= le32_to_cpu(p
->Next
);
408 bytes_left
-= sizeof(*p
);
411 p
= (struct network_interface_info_ioctl_rsp
*)((u8
*)p
+next
);
416 cifs_dbg(VFS
, "%s: malformed interface info\n", __func__
);
421 if (bytes_left
|| p
->Next
)
422 cifs_dbg(VFS
, "%s: incomplete interface info\n", __func__
);
426 * Second pass: extract info to internal structure
429 *iface_list
= kcalloc(nb_iface
, sizeof(**iface_list
), GFP_KERNEL
);
436 bytes_left
= buf_len
;
438 while (bytes_left
>= sizeof(*p
)) {
439 info
->speed
= le64_to_cpu(p
->LinkSpeed
);
440 info
->rdma_capable
= le32_to_cpu(p
->Capability
& RDMA_CAPABLE
);
441 info
->rss_capable
= le32_to_cpu(p
->Capability
& RSS_CAPABLE
);
443 cifs_dbg(FYI
, "%s: adding iface %zu\n", __func__
, *iface_count
);
444 cifs_dbg(FYI
, "%s: speed %zu bps\n", __func__
, info
->speed
);
445 cifs_dbg(FYI
, "%s: capabilities 0x%08x\n", __func__
,
446 le32_to_cpu(p
->Capability
));
450 * The kernel and wire socket structures have the same
451 * layout and use network byte order but make the
452 * conversion explicit in case either one changes.
455 addr4
= (struct sockaddr_in
*)&info
->sockaddr
;
456 p4
= (struct iface_info_ipv4
*)p
->Buffer
;
457 addr4
->sin_family
= AF_INET
;
458 memcpy(&addr4
->sin_addr
, &p4
->IPv4Address
, 4);
460 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
461 addr4
->sin_port
= cpu_to_be16(CIFS_PORT
);
463 cifs_dbg(FYI
, "%s: ipv4 %pI4\n", __func__
,
467 addr6
= (struct sockaddr_in6
*)&info
->sockaddr
;
468 p6
= (struct iface_info_ipv6
*)p
->Buffer
;
469 addr6
->sin6_family
= AF_INET6
;
470 memcpy(&addr6
->sin6_addr
, &p6
->IPv6Address
, 16);
472 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
473 addr6
->sin6_flowinfo
= 0;
474 addr6
->sin6_scope_id
= 0;
475 addr6
->sin6_port
= cpu_to_be16(CIFS_PORT
);
477 cifs_dbg(FYI
, "%s: ipv6 %pI6\n", __func__
,
482 "%s: skipping unsupported socket family\n",
490 next
= le32_to_cpu(p
->Next
);
493 p
= (struct network_interface_info_ioctl_rsp
*)((u8
*)p
+next
);
513 SMB3_request_interfaces(const unsigned int xid
, struct cifs_tcon
*tcon
)
516 unsigned int ret_data_len
= 0;
517 struct network_interface_info_ioctl_rsp
*out_buf
= NULL
;
518 struct cifs_server_iface
*iface_list
;
520 struct cifs_ses
*ses
= tcon
->ses
;
522 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
523 FSCTL_QUERY_NETWORK_INTERFACE_INFO
, true /* is_fsctl */,
524 NULL
/* no data input */, 0 /* no data input */,
525 (char **)&out_buf
, &ret_data_len
);
526 if (rc
== -EOPNOTSUPP
) {
528 "server does not support query network interfaces\n");
530 } else if (rc
!= 0) {
531 cifs_dbg(VFS
, "error %d on ioctl to get interface list\n", rc
);
535 rc
= parse_server_interfaces(out_buf
, ret_data_len
,
536 &iface_list
, &iface_count
);
540 spin_lock(&ses
->iface_lock
);
541 kfree(ses
->iface_list
);
542 ses
->iface_list
= iface_list
;
543 ses
->iface_count
= iface_count
;
544 ses
->iface_last_update
= jiffies
;
545 spin_unlock(&ses
->iface_lock
);
553 smb2_close_cached_fid(struct kref
*ref
)
555 struct cached_fid
*cfid
= container_of(ref
, struct cached_fid
,
558 if (cfid
->is_valid
) {
559 cifs_dbg(FYI
, "clear cached root file handle\n");
560 SMB2_close(0, cfid
->tcon
, cfid
->fid
->persistent_fid
,
561 cfid
->fid
->volatile_fid
);
562 cfid
->is_valid
= false;
566 void close_shroot(struct cached_fid
*cfid
)
568 mutex_lock(&cfid
->fid_mutex
);
569 kref_put(&cfid
->refcount
, smb2_close_cached_fid
);
570 mutex_unlock(&cfid
->fid_mutex
);
574 smb2_cached_lease_break(struct work_struct
*work
)
576 struct cached_fid
*cfid
= container_of(work
,
577 struct cached_fid
, lease_break
);
583 * Open the directory at the root of a share
585 int open_shroot(unsigned int xid
, struct cifs_tcon
*tcon
, struct cifs_fid
*pfid
)
587 struct cifs_open_parms oparams
;
589 __le16 srch_path
= 0; /* Null - since an open of top of share */
590 u8 oplock
= SMB2_OPLOCK_LEVEL_II
;
592 mutex_lock(&tcon
->crfid
.fid_mutex
);
593 if (tcon
->crfid
.is_valid
) {
594 cifs_dbg(FYI
, "found a cached root file handle\n");
595 memcpy(pfid
, tcon
->crfid
.fid
, sizeof(struct cifs_fid
));
596 kref_get(&tcon
->crfid
.refcount
);
597 mutex_unlock(&tcon
->crfid
.fid_mutex
);
602 oparams
.create_options
= 0;
603 oparams
.desired_access
= FILE_READ_ATTRIBUTES
;
604 oparams
.disposition
= FILE_OPEN
;
606 oparams
.reconnect
= false;
608 rc
= SMB2_open(xid
, &oparams
, &srch_path
, &oplock
, NULL
, NULL
, NULL
);
610 memcpy(tcon
->crfid
.fid
, pfid
, sizeof(struct cifs_fid
));
611 tcon
->crfid
.tcon
= tcon
;
612 tcon
->crfid
.is_valid
= true;
613 kref_init(&tcon
->crfid
.refcount
);
614 kref_get(&tcon
->crfid
.refcount
);
616 mutex_unlock(&tcon
->crfid
.fid_mutex
);
621 smb3_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
624 __le16 srch_path
= 0; /* Null - open root of share */
625 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
626 struct cifs_open_parms oparms
;
628 bool no_cached_open
= tcon
->nohandlecache
;
631 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
632 oparms
.disposition
= FILE_OPEN
;
633 oparms
.create_options
= 0;
635 oparms
.reconnect
= false;
638 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
,
641 rc
= open_shroot(xid
, tcon
, &fid
);
646 SMB3_request_interfaces(xid
, tcon
);
648 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
649 FS_ATTRIBUTE_INFORMATION
);
650 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
651 FS_DEVICE_INFORMATION
);
652 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
653 FS_VOLUME_INFORMATION
);
654 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
655 FS_SECTOR_SIZE_INFORMATION
); /* SMB3 specific */
657 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
659 close_shroot(&tcon
->crfid
);
665 smb2_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
668 __le16 srch_path
= 0; /* Null - open root of share */
669 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
670 struct cifs_open_parms oparms
;
674 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
675 oparms
.disposition
= FILE_OPEN
;
676 oparms
.create_options
= 0;
678 oparms
.reconnect
= false;
680 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
, NULL
);
684 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
685 FS_ATTRIBUTE_INFORMATION
);
686 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
687 FS_DEVICE_INFORMATION
);
688 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
693 smb2_is_path_accessible(const unsigned int xid
, struct cifs_tcon
*tcon
,
694 struct cifs_sb_info
*cifs_sb
, const char *full_path
)
698 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
699 struct cifs_open_parms oparms
;
702 if ((*full_path
== 0) && tcon
->crfid
.is_valid
)
705 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
710 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
711 oparms
.disposition
= FILE_OPEN
;
712 if (backup_cred(cifs_sb
))
713 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
715 oparms
.create_options
= 0;
717 oparms
.reconnect
= false;
719 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
, NULL
);
725 rc
= SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
731 smb2_get_srv_inum(const unsigned int xid
, struct cifs_tcon
*tcon
,
732 struct cifs_sb_info
*cifs_sb
, const char *full_path
,
733 u64
*uniqueid
, FILE_ALL_INFO
*data
)
735 *uniqueid
= le64_to_cpu(data
->IndexNumber
);
740 smb2_query_file_info(const unsigned int xid
, struct cifs_tcon
*tcon
,
741 struct cifs_fid
*fid
, FILE_ALL_INFO
*data
)
744 struct smb2_file_all_info
*smb2_data
;
746 smb2_data
= kzalloc(sizeof(struct smb2_file_all_info
) + PATH_MAX
* 2,
748 if (smb2_data
== NULL
)
751 rc
= SMB2_query_info(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
,
754 move_smb2_info_to_cifs(data
, smb2_data
);
759 #ifdef CONFIG_CIFS_XATTR
761 move_smb2_ea_to_cifs(char *dst
, size_t dst_size
,
762 struct smb2_file_full_ea_info
*src
, size_t src_size
,
763 const unsigned char *ea_name
)
766 unsigned int ea_name_len
= ea_name
? strlen(ea_name
) : 0;
768 size_t buf_size
= dst_size
;
769 size_t name_len
, value_len
, user_name_len
;
771 while (src_size
> 0) {
772 name
= &src
->ea_data
[0];
773 name_len
= (size_t)src
->ea_name_length
;
774 value
= &src
->ea_data
[src
->ea_name_length
+ 1];
775 value_len
= (size_t)le16_to_cpu(src
->ea_value_length
);
781 if (src_size
< 8 + name_len
+ 1 + value_len
) {
782 cifs_dbg(FYI
, "EA entry goes beyond length of list\n");
788 if (ea_name_len
== name_len
&&
789 memcmp(ea_name
, name
, name_len
) == 0) {
793 if (dst_size
< value_len
) {
797 memcpy(dst
, value
, value_len
);
801 /* 'user.' plus a terminating null */
802 user_name_len
= 5 + 1 + name_len
;
805 /* skip copy - calc size only */
807 } else if (dst_size
>= user_name_len
) {
808 dst_size
-= user_name_len
;
809 memcpy(dst
, "user.", 5);
811 memcpy(dst
, src
->ea_data
, name_len
);
817 /* stop before overrun buffer */
823 if (!src
->next_entry_offset
)
826 if (src_size
< le32_to_cpu(src
->next_entry_offset
)) {
827 /* stop before overrun buffer */
831 src_size
-= le32_to_cpu(src
->next_entry_offset
);
832 src
= (void *)((char *)src
+
833 le32_to_cpu(src
->next_entry_offset
));
836 /* didn't find the named attribute */
845 smb2_query_eas(const unsigned int xid
, struct cifs_tcon
*tcon
,
846 const unsigned char *path
, const unsigned char *ea_name
,
847 char *ea_data
, size_t buf_size
,
848 struct cifs_sb_info
*cifs_sb
)
852 struct kvec rsp_iov
= {NULL
, 0};
853 int buftype
= CIFS_NO_BUFFER
;
854 struct smb2_query_info_rsp
*rsp
;
855 struct smb2_file_full_ea_info
*info
= NULL
;
857 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
861 rc
= smb2_query_info_compound(xid
, tcon
, utf16_path
,
863 FILE_FULL_EA_INFORMATION
,
866 &rsp_iov
, &buftype
, cifs_sb
);
869 * If ea_name is NULL (listxattr) and there are no EAs,
870 * return 0 as it's not an error. Otherwise, the specified
871 * ea_name was not found.
873 if (!ea_name
&& rc
== -ENODATA
)
878 rsp
= (struct smb2_query_info_rsp
*)rsp_iov
.iov_base
;
879 rc
= smb2_validate_iov(le16_to_cpu(rsp
->OutputBufferOffset
),
880 le32_to_cpu(rsp
->OutputBufferLength
),
882 sizeof(struct smb2_file_full_ea_info
));
886 info
= (struct smb2_file_full_ea_info
*)(
887 le16_to_cpu(rsp
->OutputBufferOffset
) + (char *)rsp
);
888 rc
= move_smb2_ea_to_cifs(ea_data
, buf_size
, info
,
889 le32_to_cpu(rsp
->OutputBufferLength
), ea_name
);
893 free_rsp_buf(buftype
, rsp_iov
.iov_base
);
899 smb2_set_ea(const unsigned int xid
, struct cifs_tcon
*tcon
,
900 const char *path
, const char *ea_name
, const void *ea_value
,
901 const __u16 ea_value_len
, const struct nls_table
*nls_codepage
,
902 struct cifs_sb_info
*cifs_sb
)
904 struct cifs_ses
*ses
= tcon
->ses
;
905 __le16
*utf16_path
= NULL
;
906 int ea_name_len
= strlen(ea_name
);
909 struct smb_rqst rqst
[3];
911 struct kvec rsp_iov
[3];
912 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
913 struct cifs_open_parms oparms
;
914 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
916 struct kvec si_iov
[SMB2_SET_INFO_IOV_SIZE
];
917 unsigned int size
[1];
919 struct smb2_file_full_ea_info
*ea
= NULL
;
920 struct kvec close_iov
[1];
923 if (smb3_encryption_required(tcon
))
924 flags
|= CIFS_TRANSFORM_REQ
;
926 if (ea_name_len
> 255)
929 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
933 memset(rqst
, 0, sizeof(rqst
));
934 resp_buftype
[0] = resp_buftype
[1] = resp_buftype
[2] = CIFS_NO_BUFFER
;
935 memset(rsp_iov
, 0, sizeof(rsp_iov
));
938 memset(&open_iov
, 0, sizeof(open_iov
));
939 rqst
[0].rq_iov
= open_iov
;
940 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
942 memset(&oparms
, 0, sizeof(oparms
));
944 oparms
.desired_access
= FILE_WRITE_EA
;
945 oparms
.disposition
= FILE_OPEN
;
946 if (backup_cred(cifs_sb
))
947 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
949 oparms
.create_options
= 0;
951 oparms
.reconnect
= false;
953 rc
= SMB2_open_init(tcon
, &rqst
[0], &oplock
, &oparms
, utf16_path
);
956 smb2_set_next_command(tcon
, &rqst
[0]);
960 memset(&si_iov
, 0, sizeof(si_iov
));
961 rqst
[1].rq_iov
= si_iov
;
964 len
= sizeof(ea
) + ea_name_len
+ ea_value_len
+ 1;
965 ea
= kzalloc(len
, GFP_KERNEL
);
971 ea
->ea_name_length
= ea_name_len
;
972 ea
->ea_value_length
= cpu_to_le16(ea_value_len
);
973 memcpy(ea
->ea_data
, ea_name
, ea_name_len
+ 1);
974 memcpy(ea
->ea_data
+ ea_name_len
+ 1, ea_value
, ea_value_len
);
979 rc
= SMB2_set_info_init(tcon
, &rqst
[1], COMPOUND_FID
,
980 COMPOUND_FID
, current
->tgid
,
981 FILE_FULL_EA_INFORMATION
,
982 SMB2_O_INFO_FILE
, 0, data
, size
);
983 smb2_set_next_command(tcon
, &rqst
[1]);
984 smb2_set_related(&rqst
[1]);
988 memset(&close_iov
, 0, sizeof(close_iov
));
989 rqst
[2].rq_iov
= close_iov
;
991 rc
= SMB2_close_init(tcon
, &rqst
[2], COMPOUND_FID
, COMPOUND_FID
);
992 smb2_set_related(&rqst
[2]);
994 rc
= compound_send_recv(xid
, ses
, flags
, 3, rqst
,
995 resp_buftype
, rsp_iov
);
1000 SMB2_open_free(&rqst
[0]);
1001 SMB2_set_info_free(&rqst
[1]);
1002 SMB2_close_free(&rqst
[2]);
1003 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
1004 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
1005 free_rsp_buf(resp_buftype
[2], rsp_iov
[2].iov_base
);
1011 smb2_can_echo(struct TCP_Server_Info
*server
)
1013 return server
->echoes
;
1017 smb2_clear_stats(struct cifs_tcon
*tcon
)
1020 for (i
= 0; i
< NUMBER_OF_SMB2_COMMANDS
; i
++) {
1021 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_sent
[i
], 0);
1022 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_failed
[i
], 0);
1027 smb2_dump_share_caps(struct seq_file
*m
, struct cifs_tcon
*tcon
)
1029 seq_puts(m
, "\n\tShare Capabilities:");
1030 if (tcon
->capabilities
& SMB2_SHARE_CAP_DFS
)
1031 seq_puts(m
, " DFS,");
1032 if (tcon
->capabilities
& SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY
)
1033 seq_puts(m
, " CONTINUOUS AVAILABILITY,");
1034 if (tcon
->capabilities
& SMB2_SHARE_CAP_SCALEOUT
)
1035 seq_puts(m
, " SCALEOUT,");
1036 if (tcon
->capabilities
& SMB2_SHARE_CAP_CLUSTER
)
1037 seq_puts(m
, " CLUSTER,");
1038 if (tcon
->capabilities
& SMB2_SHARE_CAP_ASYMMETRIC
)
1039 seq_puts(m
, " ASYMMETRIC,");
1040 if (tcon
->capabilities
== 0)
1041 seq_puts(m
, " None");
1042 if (tcon
->ss_flags
& SSINFO_FLAGS_ALIGNED_DEVICE
)
1043 seq_puts(m
, " Aligned,");
1044 if (tcon
->ss_flags
& SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE
)
1045 seq_puts(m
, " Partition Aligned,");
1046 if (tcon
->ss_flags
& SSINFO_FLAGS_NO_SEEK_PENALTY
)
1047 seq_puts(m
, " SSD,");
1048 if (tcon
->ss_flags
& SSINFO_FLAGS_TRIM_ENABLED
)
1049 seq_puts(m
, " TRIM-support,");
1051 seq_printf(m
, "\tShare Flags: 0x%x", tcon
->share_flags
);
1052 seq_printf(m
, "\n\ttid: 0x%x", tcon
->tid
);
1053 if (tcon
->perf_sector_size
)
1054 seq_printf(m
, "\tOptimal sector size: 0x%x",
1055 tcon
->perf_sector_size
);
1056 seq_printf(m
, "\tMaximal Access: 0x%x", tcon
->maximal_access
);
1060 smb2_print_stats(struct seq_file
*m
, struct cifs_tcon
*tcon
)
1062 atomic_t
*sent
= tcon
->stats
.smb2_stats
.smb2_com_sent
;
1063 atomic_t
*failed
= tcon
->stats
.smb2_stats
.smb2_com_failed
;
1066 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1067 * totals (requests sent) since those SMBs are per-session not per tcon
1069 seq_printf(m
, "\nBytes read: %llu Bytes written: %llu",
1070 (long long)(tcon
->bytes_read
),
1071 (long long)(tcon
->bytes_written
));
1072 seq_printf(m
, "\nOpen files: %d total (local), %d open on server",
1073 atomic_read(&tcon
->num_local_opens
),
1074 atomic_read(&tcon
->num_remote_opens
));
1075 seq_printf(m
, "\nTreeConnects: %d total %d failed",
1076 atomic_read(&sent
[SMB2_TREE_CONNECT_HE
]),
1077 atomic_read(&failed
[SMB2_TREE_CONNECT_HE
]));
1078 seq_printf(m
, "\nTreeDisconnects: %d total %d failed",
1079 atomic_read(&sent
[SMB2_TREE_DISCONNECT_HE
]),
1080 atomic_read(&failed
[SMB2_TREE_DISCONNECT_HE
]));
1081 seq_printf(m
, "\nCreates: %d total %d failed",
1082 atomic_read(&sent
[SMB2_CREATE_HE
]),
1083 atomic_read(&failed
[SMB2_CREATE_HE
]));
1084 seq_printf(m
, "\nCloses: %d total %d failed",
1085 atomic_read(&sent
[SMB2_CLOSE_HE
]),
1086 atomic_read(&failed
[SMB2_CLOSE_HE
]));
1087 seq_printf(m
, "\nFlushes: %d total %d failed",
1088 atomic_read(&sent
[SMB2_FLUSH_HE
]),
1089 atomic_read(&failed
[SMB2_FLUSH_HE
]));
1090 seq_printf(m
, "\nReads: %d total %d failed",
1091 atomic_read(&sent
[SMB2_READ_HE
]),
1092 atomic_read(&failed
[SMB2_READ_HE
]));
1093 seq_printf(m
, "\nWrites: %d total %d failed",
1094 atomic_read(&sent
[SMB2_WRITE_HE
]),
1095 atomic_read(&failed
[SMB2_WRITE_HE
]));
1096 seq_printf(m
, "\nLocks: %d total %d failed",
1097 atomic_read(&sent
[SMB2_LOCK_HE
]),
1098 atomic_read(&failed
[SMB2_LOCK_HE
]));
1099 seq_printf(m
, "\nIOCTLs: %d total %d failed",
1100 atomic_read(&sent
[SMB2_IOCTL_HE
]),
1101 atomic_read(&failed
[SMB2_IOCTL_HE
]));
1102 seq_printf(m
, "\nQueryDirectories: %d total %d failed",
1103 atomic_read(&sent
[SMB2_QUERY_DIRECTORY_HE
]),
1104 atomic_read(&failed
[SMB2_QUERY_DIRECTORY_HE
]));
1105 seq_printf(m
, "\nChangeNotifies: %d total %d failed",
1106 atomic_read(&sent
[SMB2_CHANGE_NOTIFY_HE
]),
1107 atomic_read(&failed
[SMB2_CHANGE_NOTIFY_HE
]));
1108 seq_printf(m
, "\nQueryInfos: %d total %d failed",
1109 atomic_read(&sent
[SMB2_QUERY_INFO_HE
]),
1110 atomic_read(&failed
[SMB2_QUERY_INFO_HE
]));
1111 seq_printf(m
, "\nSetInfos: %d total %d failed",
1112 atomic_read(&sent
[SMB2_SET_INFO_HE
]),
1113 atomic_read(&failed
[SMB2_SET_INFO_HE
]));
1114 seq_printf(m
, "\nOplockBreaks: %d sent %d failed",
1115 atomic_read(&sent
[SMB2_OPLOCK_BREAK_HE
]),
1116 atomic_read(&failed
[SMB2_OPLOCK_BREAK_HE
]));
1120 smb2_set_fid(struct cifsFileInfo
*cfile
, struct cifs_fid
*fid
, __u32 oplock
)
1122 struct cifsInodeInfo
*cinode
= CIFS_I(d_inode(cfile
->dentry
));
1123 struct TCP_Server_Info
*server
= tlink_tcon(cfile
->tlink
)->ses
->server
;
1125 cfile
->fid
.persistent_fid
= fid
->persistent_fid
;
1126 cfile
->fid
.volatile_fid
= fid
->volatile_fid
;
1127 #ifdef CONFIG_CIFS_DEBUG2
1128 cfile
->fid
.mid
= fid
->mid
;
1129 #endif /* CIFS_DEBUG2 */
1130 server
->ops
->set_oplock_level(cinode
, oplock
, fid
->epoch
,
1132 cinode
->can_cache_brlcks
= CIFS_CACHE_WRITE(cinode
);
1133 memcpy(cfile
->fid
.create_guid
, fid
->create_guid
, 16);
1137 smb2_close_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
1138 struct cifs_fid
*fid
)
1140 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1144 SMB2_request_res_key(const unsigned int xid
, struct cifs_tcon
*tcon
,
1145 u64 persistent_fid
, u64 volatile_fid
,
1146 struct copychunk_ioctl
*pcchunk
)
1149 unsigned int ret_data_len
;
1150 struct resume_key_req
*res_key
;
1152 rc
= SMB2_ioctl(xid
, tcon
, persistent_fid
, volatile_fid
,
1153 FSCTL_SRV_REQUEST_RESUME_KEY
, true /* is_fsctl */,
1154 NULL
, 0 /* no input */,
1155 (char **)&res_key
, &ret_data_len
);
1158 cifs_dbg(VFS
, "refcpy ioctl error %d getting resume key\n", rc
);
1159 goto req_res_key_exit
;
1161 if (ret_data_len
< sizeof(struct resume_key_req
)) {
1162 cifs_dbg(VFS
, "Invalid refcopy resume key length\n");
1164 goto req_res_key_exit
;
1166 memcpy(pcchunk
->SourceKey
, res_key
->ResumeKey
, COPY_CHUNK_RES_KEY_SIZE
);
1174 smb2_ioctl_query_info(const unsigned int xid
,
1175 struct cifs_tcon
*tcon
,
1176 __le16
*path
, int is_dir
,
1179 struct cifs_ses
*ses
= tcon
->ses
;
1180 char __user
*arg
= (char __user
*)p
;
1181 struct smb_query_info qi
;
1182 struct smb_query_info __user
*pqi
;
1185 struct smb2_query_info_rsp
*rsp
= NULL
;
1186 void *buffer
= NULL
;
1187 struct smb_rqst rqst
[3];
1188 int resp_buftype
[3];
1189 struct kvec rsp_iov
[3];
1190 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
1191 struct cifs_open_parms oparms
;
1192 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1193 struct cifs_fid fid
;
1194 struct kvec qi_iov
[1];
1195 struct kvec close_iov
[1];
1197 memset(rqst
, 0, sizeof(rqst
));
1198 resp_buftype
[0] = resp_buftype
[1] = resp_buftype
[2] = CIFS_NO_BUFFER
;
1199 memset(rsp_iov
, 0, sizeof(rsp_iov
));
1201 if (copy_from_user(&qi
, arg
, sizeof(struct smb_query_info
)))
1204 if (qi
.output_buffer_length
> 1024)
1207 if (!ses
|| !(ses
->server
))
1210 if (smb3_encryption_required(tcon
))
1211 flags
|= CIFS_TRANSFORM_REQ
;
1213 buffer
= kmalloc(qi
.output_buffer_length
, GFP_KERNEL
);
1217 if (copy_from_user(buffer
, arg
+ sizeof(struct smb_query_info
),
1218 qi
.output_buffer_length
)) {
1224 memset(&open_iov
, 0, sizeof(open_iov
));
1225 rqst
[0].rq_iov
= open_iov
;
1226 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
1228 memset(&oparms
, 0, sizeof(oparms
));
1230 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| READ_CONTROL
;
1231 oparms
.disposition
= FILE_OPEN
;
1233 oparms
.create_options
= CREATE_NOT_FILE
;
1235 oparms
.create_options
= CREATE_NOT_DIR
;
1237 oparms
.reconnect
= false;
1239 rc
= SMB2_open_init(tcon
, &rqst
[0], &oplock
, &oparms
, path
);
1242 smb2_set_next_command(tcon
, &rqst
[0]);
1245 memset(&qi_iov
, 0, sizeof(qi_iov
));
1246 rqst
[1].rq_iov
= qi_iov
;
1247 rqst
[1].rq_nvec
= 1;
1249 rc
= SMB2_query_info_init(tcon
, &rqst
[1], COMPOUND_FID
, COMPOUND_FID
,
1250 qi
.file_info_class
, qi
.info_type
,
1251 qi
.additional_information
,
1252 qi
.input_buffer_length
,
1253 qi
.output_buffer_length
, buffer
);
1256 smb2_set_next_command(tcon
, &rqst
[1]);
1257 smb2_set_related(&rqst
[1]);
1260 memset(&close_iov
, 0, sizeof(close_iov
));
1261 rqst
[2].rq_iov
= close_iov
;
1262 rqst
[2].rq_nvec
= 1;
1264 rc
= SMB2_close_init(tcon
, &rqst
[2], COMPOUND_FID
, COMPOUND_FID
);
1267 smb2_set_related(&rqst
[2]);
1269 rc
= compound_send_recv(xid
, ses
, flags
, 3, rqst
,
1270 resp_buftype
, rsp_iov
);
1273 pqi
= (struct smb_query_info __user
*)arg
;
1274 rsp
= (struct smb2_query_info_rsp
*)rsp_iov
[1].iov_base
;
1275 if (le32_to_cpu(rsp
->OutputBufferLength
) < qi
.input_buffer_length
)
1276 qi
.input_buffer_length
= le32_to_cpu(rsp
->OutputBufferLength
);
1277 if (copy_to_user(&pqi
->input_buffer_length
, &qi
.input_buffer_length
,
1278 sizeof(qi
.input_buffer_length
))) {
1282 if (copy_to_user(pqi
+ 1, rsp
->Buffer
, qi
.input_buffer_length
)) {
1289 SMB2_open_free(&rqst
[0]);
1290 SMB2_query_info_free(&rqst
[1]);
1291 SMB2_close_free(&rqst
[2]);
1292 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
1293 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
1294 free_rsp_buf(resp_buftype
[2], rsp_iov
[2].iov_base
);
1299 smb2_copychunk_range(const unsigned int xid
,
1300 struct cifsFileInfo
*srcfile
,
1301 struct cifsFileInfo
*trgtfile
, u64 src_off
,
1302 u64 len
, u64 dest_off
)
1305 unsigned int ret_data_len
;
1306 struct copychunk_ioctl
*pcchunk
;
1307 struct copychunk_ioctl_rsp
*retbuf
= NULL
;
1308 struct cifs_tcon
*tcon
;
1309 int chunks_copied
= 0;
1310 bool chunk_sizes_updated
= false;
1311 ssize_t bytes_written
, total_bytes_written
= 0;
1313 pcchunk
= kmalloc(sizeof(struct copychunk_ioctl
), GFP_KERNEL
);
1315 if (pcchunk
== NULL
)
1318 cifs_dbg(FYI
, "in smb2_copychunk_range - about to call request res key\n");
1319 /* Request a key from the server to identify the source of the copy */
1320 rc
= SMB2_request_res_key(xid
, tlink_tcon(srcfile
->tlink
),
1321 srcfile
->fid
.persistent_fid
,
1322 srcfile
->fid
.volatile_fid
, pcchunk
);
1324 /* Note: request_res_key sets res_key null only if rc !=0 */
1328 /* For now array only one chunk long, will make more flexible later */
1329 pcchunk
->ChunkCount
= cpu_to_le32(1);
1330 pcchunk
->Reserved
= 0;
1331 pcchunk
->Reserved2
= 0;
1333 tcon
= tlink_tcon(trgtfile
->tlink
);
1336 pcchunk
->SourceOffset
= cpu_to_le64(src_off
);
1337 pcchunk
->TargetOffset
= cpu_to_le64(dest_off
);
1339 cpu_to_le32(min_t(u32
, len
, tcon
->max_bytes_chunk
));
1341 /* Request server copy to target from src identified by key */
1342 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
1343 trgtfile
->fid
.volatile_fid
, FSCTL_SRV_COPYCHUNK_WRITE
,
1344 true /* is_fsctl */, (char *)pcchunk
,
1345 sizeof(struct copychunk_ioctl
), (char **)&retbuf
,
1349 sizeof(struct copychunk_ioctl_rsp
)) {
1350 cifs_dbg(VFS
, "invalid cchunk response size\n");
1354 if (retbuf
->TotalBytesWritten
== 0) {
1355 cifs_dbg(FYI
, "no bytes copied\n");
1360 * Check if server claimed to write more than we asked
1362 if (le32_to_cpu(retbuf
->TotalBytesWritten
) >
1363 le32_to_cpu(pcchunk
->Length
)) {
1364 cifs_dbg(VFS
, "invalid copy chunk response\n");
1368 if (le32_to_cpu(retbuf
->ChunksWritten
) != 1) {
1369 cifs_dbg(VFS
, "invalid num chunks written\n");
1375 bytes_written
= le32_to_cpu(retbuf
->TotalBytesWritten
);
1376 src_off
+= bytes_written
;
1377 dest_off
+= bytes_written
;
1378 len
-= bytes_written
;
1379 total_bytes_written
+= bytes_written
;
1381 cifs_dbg(FYI
, "Chunks %d PartialChunk %d Total %zu\n",
1382 le32_to_cpu(retbuf
->ChunksWritten
),
1383 le32_to_cpu(retbuf
->ChunkBytesWritten
),
1385 } else if (rc
== -EINVAL
) {
1386 if (ret_data_len
!= sizeof(struct copychunk_ioctl_rsp
))
1389 cifs_dbg(FYI
, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1390 le32_to_cpu(retbuf
->ChunksWritten
),
1391 le32_to_cpu(retbuf
->ChunkBytesWritten
),
1392 le32_to_cpu(retbuf
->TotalBytesWritten
));
1395 * Check if this is the first request using these sizes,
1396 * (ie check if copy succeed once with original sizes
1397 * and check if the server gave us different sizes after
1398 * we already updated max sizes on previous request).
1399 * if not then why is the server returning an error now
1401 if ((chunks_copied
!= 0) || chunk_sizes_updated
)
1404 /* Check that server is not asking us to grow size */
1405 if (le32_to_cpu(retbuf
->ChunkBytesWritten
) <
1406 tcon
->max_bytes_chunk
)
1407 tcon
->max_bytes_chunk
=
1408 le32_to_cpu(retbuf
->ChunkBytesWritten
);
1410 goto cchunk_out
; /* server gave us bogus size */
1412 /* No need to change MaxChunks since already set to 1 */
1413 chunk_sizes_updated
= true;
1424 return total_bytes_written
;
1428 smb2_flush_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
1429 struct cifs_fid
*fid
)
1431 return SMB2_flush(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1435 smb2_read_data_offset(char *buf
)
1437 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
1438 return rsp
->DataOffset
;
1442 smb2_read_data_length(char *buf
, bool in_remaining
)
1444 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
1447 return le32_to_cpu(rsp
->DataRemaining
);
1449 return le32_to_cpu(rsp
->DataLength
);
1454 smb2_sync_read(const unsigned int xid
, struct cifs_fid
*pfid
,
1455 struct cifs_io_parms
*parms
, unsigned int *bytes_read
,
1456 char **buf
, int *buf_type
)
1458 parms
->persistent_fid
= pfid
->persistent_fid
;
1459 parms
->volatile_fid
= pfid
->volatile_fid
;
1460 return SMB2_read(xid
, parms
, bytes_read
, buf
, buf_type
);
1464 smb2_sync_write(const unsigned int xid
, struct cifs_fid
*pfid
,
1465 struct cifs_io_parms
*parms
, unsigned int *written
,
1466 struct kvec
*iov
, unsigned long nr_segs
)
1469 parms
->persistent_fid
= pfid
->persistent_fid
;
1470 parms
->volatile_fid
= pfid
->volatile_fid
;
1471 return SMB2_write(xid
, parms
, written
, iov
, nr_segs
);
1474 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1475 static bool smb2_set_sparse(const unsigned int xid
, struct cifs_tcon
*tcon
,
1476 struct cifsFileInfo
*cfile
, struct inode
*inode
, __u8 setsparse
)
1478 struct cifsInodeInfo
*cifsi
;
1481 cifsi
= CIFS_I(inode
);
1483 /* if file already sparse don't bother setting sparse again */
1484 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && setsparse
)
1485 return true; /* already sparse */
1487 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && !setsparse
)
1488 return true; /* already not sparse */
1491 * Can't check for sparse support on share the usual way via the
1492 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1493 * since Samba server doesn't set the flag on the share, yet
1494 * supports the set sparse FSCTL and returns sparse correctly
1495 * in the file attributes. If we fail setting sparse though we
1496 * mark that server does not support sparse files for this share
1497 * to avoid repeatedly sending the unsupported fsctl to server
1498 * if the file is repeatedly extended.
1500 if (tcon
->broken_sparse_sup
)
1503 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1504 cfile
->fid
.volatile_fid
, FSCTL_SET_SPARSE
,
1506 &setsparse
, 1, NULL
, NULL
);
1508 tcon
->broken_sparse_sup
= true;
1509 cifs_dbg(FYI
, "set sparse rc = %d\n", rc
);
1514 cifsi
->cifsAttrs
|= FILE_ATTRIBUTE_SPARSE_FILE
;
1516 cifsi
->cifsAttrs
&= (~FILE_ATTRIBUTE_SPARSE_FILE
);
1522 smb2_set_file_size(const unsigned int xid
, struct cifs_tcon
*tcon
,
1523 struct cifsFileInfo
*cfile
, __u64 size
, bool set_alloc
)
1525 __le64 eof
= cpu_to_le64(size
);
1526 struct inode
*inode
;
1529 * If extending file more than one page make sparse. Many Linux fs
1530 * make files sparse by default when extending via ftruncate
1532 inode
= d_inode(cfile
->dentry
);
1534 if (!set_alloc
&& (size
> inode
->i_size
+ 8192)) {
1535 __u8 set_sparse
= 1;
1537 /* whether set sparse succeeds or not, extend the file */
1538 smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
);
1541 return SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
1542 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
);
1546 smb2_duplicate_extents(const unsigned int xid
,
1547 struct cifsFileInfo
*srcfile
,
1548 struct cifsFileInfo
*trgtfile
, u64 src_off
,
1549 u64 len
, u64 dest_off
)
1552 unsigned int ret_data_len
;
1553 struct duplicate_extents_to_file dup_ext_buf
;
1554 struct cifs_tcon
*tcon
= tlink_tcon(trgtfile
->tlink
);
1556 /* server fileays advertise duplicate extent support with this flag */
1557 if ((le32_to_cpu(tcon
->fsAttrInfo
.Attributes
) &
1558 FILE_SUPPORTS_BLOCK_REFCOUNTING
) == 0)
1561 dup_ext_buf
.VolatileFileHandle
= srcfile
->fid
.volatile_fid
;
1562 dup_ext_buf
.PersistentFileHandle
= srcfile
->fid
.persistent_fid
;
1563 dup_ext_buf
.SourceFileOffset
= cpu_to_le64(src_off
);
1564 dup_ext_buf
.TargetFileOffset
= cpu_to_le64(dest_off
);
1565 dup_ext_buf
.ByteCount
= cpu_to_le64(len
);
1566 cifs_dbg(FYI
, "duplicate extents: src off %lld dst off %lld len %lld",
1567 src_off
, dest_off
, len
);
1569 rc
= smb2_set_file_size(xid
, tcon
, trgtfile
, dest_off
+ len
, false);
1571 goto duplicate_extents_out
;
1573 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
1574 trgtfile
->fid
.volatile_fid
,
1575 FSCTL_DUPLICATE_EXTENTS_TO_FILE
,
1576 true /* is_fsctl */,
1577 (char *)&dup_ext_buf
,
1578 sizeof(struct duplicate_extents_to_file
),
1582 if (ret_data_len
> 0)
1583 cifs_dbg(FYI
, "non-zero response length in duplicate extents");
1585 duplicate_extents_out
:
1590 smb2_set_compression(const unsigned int xid
, struct cifs_tcon
*tcon
,
1591 struct cifsFileInfo
*cfile
)
1593 return SMB2_set_compression(xid
, tcon
, cfile
->fid
.persistent_fid
,
1594 cfile
->fid
.volatile_fid
);
1598 smb3_set_integrity(const unsigned int xid
, struct cifs_tcon
*tcon
,
1599 struct cifsFileInfo
*cfile
)
1601 struct fsctl_set_integrity_information_req integr_info
;
1602 unsigned int ret_data_len
;
1604 integr_info
.ChecksumAlgorithm
= cpu_to_le16(CHECKSUM_TYPE_UNCHANGED
);
1605 integr_info
.Flags
= 0;
1606 integr_info
.Reserved
= 0;
1608 return SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1609 cfile
->fid
.volatile_fid
,
1610 FSCTL_SET_INTEGRITY_INFORMATION
,
1611 true /* is_fsctl */,
1612 (char *)&integr_info
,
1613 sizeof(struct fsctl_set_integrity_information_req
),
1619 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
1620 #define GMT_TOKEN_SIZE 50
1623 * Input buffer contains (empty) struct smb_snapshot array with size filled in
1624 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
1627 smb3_enum_snapshots(const unsigned int xid
, struct cifs_tcon
*tcon
,
1628 struct cifsFileInfo
*cfile
, void __user
*ioc_buf
)
1630 char *retbuf
= NULL
;
1631 unsigned int ret_data_len
= 0;
1633 struct smb_snapshot_array snapshot_in
;
1635 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1636 cfile
->fid
.volatile_fid
,
1637 FSCTL_SRV_ENUMERATE_SNAPSHOTS
,
1638 true /* is_fsctl */,
1639 NULL
, 0 /* no input data */,
1642 cifs_dbg(FYI
, "enum snaphots ioctl returned %d and ret buflen is %d\n",
1647 if (ret_data_len
&& (ioc_buf
!= NULL
) && (retbuf
!= NULL
)) {
1649 if (copy_from_user(&snapshot_in
, ioc_buf
,
1650 sizeof(struct smb_snapshot_array
))) {
1657 * Check for min size, ie not large enough to fit even one GMT
1658 * token (snapshot). On the first ioctl some users may pass in
1659 * smaller size (or zero) to simply get the size of the array
1660 * so the user space caller can allocate sufficient memory
1661 * and retry the ioctl again with larger array size sufficient
1662 * to hold all of the snapshot GMT tokens on the second try.
1664 if (snapshot_in
.snapshot_array_size
< GMT_TOKEN_SIZE
)
1665 ret_data_len
= sizeof(struct smb_snapshot_array
);
1668 * We return struct SRV_SNAPSHOT_ARRAY, followed by
1669 * the snapshot array (of 50 byte GMT tokens) each
1670 * representing an available previous version of the data
1672 if (ret_data_len
> (snapshot_in
.snapshot_array_size
+
1673 sizeof(struct smb_snapshot_array
)))
1674 ret_data_len
= snapshot_in
.snapshot_array_size
+
1675 sizeof(struct smb_snapshot_array
);
1677 if (copy_to_user(ioc_buf
, retbuf
, ret_data_len
))
1686 smb2_query_dir_first(const unsigned int xid
, struct cifs_tcon
*tcon
,
1687 const char *path
, struct cifs_sb_info
*cifs_sb
,
1688 struct cifs_fid
*fid
, __u16 search_flags
,
1689 struct cifs_search_info
*srch_inf
)
1693 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1694 struct cifs_open_parms oparms
;
1696 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
1701 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| FILE_READ_DATA
;
1702 oparms
.disposition
= FILE_OPEN
;
1703 if (backup_cred(cifs_sb
))
1704 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
1706 oparms
.create_options
= 0;
1708 oparms
.reconnect
= false;
1710 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
, NULL
);
1713 cifs_dbg(FYI
, "open dir failed rc=%d\n", rc
);
1717 srch_inf
->entries_in_buffer
= 0;
1718 srch_inf
->index_of_last_entry
= 2;
1720 rc
= SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
1721 fid
->volatile_fid
, 0, srch_inf
);
1723 cifs_dbg(FYI
, "query directory failed rc=%d\n", rc
);
1724 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1730 smb2_query_dir_next(const unsigned int xid
, struct cifs_tcon
*tcon
,
1731 struct cifs_fid
*fid
, __u16 search_flags
,
1732 struct cifs_search_info
*srch_inf
)
1734 return SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
1735 fid
->volatile_fid
, 0, srch_inf
);
1739 smb2_close_dir(const unsigned int xid
, struct cifs_tcon
*tcon
,
1740 struct cifs_fid
*fid
)
1742 return SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1746 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
1747 * the number of credits and return true. Otherwise - return false.
1750 smb2_is_status_pending(char *buf
, struct TCP_Server_Info
*server
, int length
)
1752 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
1754 if (shdr
->Status
!= STATUS_PENDING
)
1758 spin_lock(&server
->req_lock
);
1759 server
->credits
+= le16_to_cpu(shdr
->CreditRequest
);
1760 spin_unlock(&server
->req_lock
);
1761 wake_up(&server
->request_q
);
1768 smb2_is_session_expired(char *buf
)
1770 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
1772 if (shdr
->Status
!= STATUS_NETWORK_SESSION_EXPIRED
&&
1773 shdr
->Status
!= STATUS_USER_SESSION_DELETED
)
1776 trace_smb3_ses_expired(shdr
->TreeId
, shdr
->SessionId
,
1777 le16_to_cpu(shdr
->Command
),
1778 le64_to_cpu(shdr
->MessageId
));
1779 cifs_dbg(FYI
, "Session expired or deleted\n");
1785 smb2_oplock_response(struct cifs_tcon
*tcon
, struct cifs_fid
*fid
,
1786 struct cifsInodeInfo
*cinode
)
1788 if (tcon
->ses
->server
->capabilities
& SMB2_GLOBAL_CAP_LEASING
)
1789 return SMB2_lease_break(0, tcon
, cinode
->lease_key
,
1790 smb2_get_lease_state(cinode
));
1792 return SMB2_oplock_break(0, tcon
, fid
->persistent_fid
,
1794 CIFS_CACHE_READ(cinode
) ? 1 : 0);
1798 smb2_set_related(struct smb_rqst
*rqst
)
1800 struct smb2_sync_hdr
*shdr
;
1802 shdr
= (struct smb2_sync_hdr
*)(rqst
->rq_iov
[0].iov_base
);
1803 shdr
->Flags
|= SMB2_FLAGS_RELATED_OPERATIONS
;
1806 char smb2_padding
[7] = {0, 0, 0, 0, 0, 0, 0};
1809 smb2_set_next_command(struct cifs_tcon
*tcon
, struct smb_rqst
*rqst
)
1811 struct smb2_sync_hdr
*shdr
;
1812 struct cifs_ses
*ses
= tcon
->ses
;
1813 struct TCP_Server_Info
*server
= ses
->server
;
1814 unsigned long len
= smb_rqst_len(server
, rqst
);
1817 /* SMB headers in a compound are 8 byte aligned. */
1819 /* No padding needed */
1823 num_padding
= 8 - (len
& 7);
1824 if (!smb3_encryption_required(tcon
)) {
1826 * If we do not have encryption then we can just add an extra
1827 * iov for the padding.
1829 rqst
->rq_iov
[rqst
->rq_nvec
].iov_base
= smb2_padding
;
1830 rqst
->rq_iov
[rqst
->rq_nvec
].iov_len
= num_padding
;
1835 * We can not add a small padding iov for the encryption case
1836 * because the encryption framework can not handle the padding
1838 * We have to flatten this into a single buffer and add
1839 * the padding to it.
1841 for (i
= 1; i
< rqst
->rq_nvec
; i
++) {
1842 memcpy(rqst
->rq_iov
[0].iov_base
+
1843 rqst
->rq_iov
[0].iov_len
,
1844 rqst
->rq_iov
[i
].iov_base
,
1845 rqst
->rq_iov
[i
].iov_len
);
1846 rqst
->rq_iov
[0].iov_len
+= rqst
->rq_iov
[i
].iov_len
;
1848 memset(rqst
->rq_iov
[0].iov_base
+ rqst
->rq_iov
[0].iov_len
,
1850 rqst
->rq_iov
[0].iov_len
+= num_padding
;
1856 shdr
= (struct smb2_sync_hdr
*)(rqst
->rq_iov
[0].iov_base
);
1857 shdr
->NextCommand
= cpu_to_le32(len
);
1861 * Passes the query info response back to the caller on success.
1862 * Caller need to free this with free_rsp_buf().
1865 smb2_query_info_compound(const unsigned int xid
, struct cifs_tcon
*tcon
,
1866 __le16
*utf16_path
, u32 desired_access
,
1867 u32
class, u32 type
, u32 output_len
,
1868 struct kvec
*rsp
, int *buftype
,
1869 struct cifs_sb_info
*cifs_sb
)
1871 struct cifs_ses
*ses
= tcon
->ses
;
1873 struct smb_rqst rqst
[3];
1874 int resp_buftype
[3];
1875 struct kvec rsp_iov
[3];
1876 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
1877 struct kvec qi_iov
[1];
1878 struct kvec close_iov
[1];
1879 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1880 struct cifs_open_parms oparms
;
1881 struct cifs_fid fid
;
1884 if (smb3_encryption_required(tcon
))
1885 flags
|= CIFS_TRANSFORM_REQ
;
1887 memset(rqst
, 0, sizeof(rqst
));
1888 resp_buftype
[0] = resp_buftype
[1] = resp_buftype
[2] = CIFS_NO_BUFFER
;
1889 memset(rsp_iov
, 0, sizeof(rsp_iov
));
1891 memset(&open_iov
, 0, sizeof(open_iov
));
1892 rqst
[0].rq_iov
= open_iov
;
1893 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
1896 oparms
.desired_access
= desired_access
;
1897 oparms
.disposition
= FILE_OPEN
;
1898 if (cifs_sb
&& backup_cred(cifs_sb
))
1899 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
1901 oparms
.create_options
= 0;
1903 oparms
.reconnect
= false;
1905 rc
= SMB2_open_init(tcon
, &rqst
[0], &oplock
, &oparms
, utf16_path
);
1908 smb2_set_next_command(tcon
, &rqst
[0]);
1910 memset(&qi_iov
, 0, sizeof(qi_iov
));
1911 rqst
[1].rq_iov
= qi_iov
;
1912 rqst
[1].rq_nvec
= 1;
1914 rc
= SMB2_query_info_init(tcon
, &rqst
[1], COMPOUND_FID
, COMPOUND_FID
,
1920 smb2_set_next_command(tcon
, &rqst
[1]);
1921 smb2_set_related(&rqst
[1]);
1923 memset(&close_iov
, 0, sizeof(close_iov
));
1924 rqst
[2].rq_iov
= close_iov
;
1925 rqst
[2].rq_nvec
= 1;
1927 rc
= SMB2_close_init(tcon
, &rqst
[2], COMPOUND_FID
, COMPOUND_FID
);
1930 smb2_set_related(&rqst
[2]);
1932 rc
= compound_send_recv(xid
, ses
, flags
, 3, rqst
,
1933 resp_buftype
, rsp_iov
);
1935 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
1939 *buftype
= resp_buftype
[1];
1942 SMB2_open_free(&rqst
[0]);
1943 SMB2_query_info_free(&rqst
[1]);
1944 SMB2_close_free(&rqst
[2]);
1945 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
1946 free_rsp_buf(resp_buftype
[2], rsp_iov
[2].iov_base
);
1951 smb2_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
1952 struct kstatfs
*buf
)
1954 struct smb2_query_info_rsp
*rsp
;
1955 struct smb2_fs_full_size_info
*info
= NULL
;
1956 __le16 utf16_path
= 0; /* Null - open root of share */
1957 struct kvec rsp_iov
= {NULL
, 0};
1958 int buftype
= CIFS_NO_BUFFER
;
1962 rc
= smb2_query_info_compound(xid
, tcon
, &utf16_path
,
1963 FILE_READ_ATTRIBUTES
,
1964 FS_FULL_SIZE_INFORMATION
,
1965 SMB2_O_INFO_FILESYSTEM
,
1966 sizeof(struct smb2_fs_full_size_info
),
1967 &rsp_iov
, &buftype
, NULL
);
1971 rsp
= (struct smb2_query_info_rsp
*)rsp_iov
.iov_base
;
1972 buf
->f_type
= SMB2_MAGIC_NUMBER
;
1973 info
= (struct smb2_fs_full_size_info
*)(
1974 le16_to_cpu(rsp
->OutputBufferOffset
) + (char *)rsp
);
1975 rc
= smb2_validate_iov(le16_to_cpu(rsp
->OutputBufferOffset
),
1976 le32_to_cpu(rsp
->OutputBufferLength
),
1978 sizeof(struct smb2_fs_full_size_info
));
1980 smb2_copy_fs_info_to_kstatfs(info
, buf
);
1983 free_rsp_buf(buftype
, rsp_iov
.iov_base
);
1988 smb311_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
1989 struct kstatfs
*buf
)
1992 __le16 srch_path
= 0; /* Null - open root of share */
1993 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1994 struct cifs_open_parms oparms
;
1995 struct cifs_fid fid
;
1997 if (!tcon
->posix_extensions
)
1998 return smb2_queryfs(xid
, tcon
, buf
);
2001 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
2002 oparms
.disposition
= FILE_OPEN
;
2003 oparms
.create_options
= 0;
2005 oparms
.reconnect
= false;
2007 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
, NULL
);
2011 rc
= SMB311_posix_qfs_info(xid
, tcon
, fid
.persistent_fid
,
2012 fid
.volatile_fid
, buf
);
2013 buf
->f_type
= SMB2_MAGIC_NUMBER
;
2014 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
2019 smb2_compare_fids(struct cifsFileInfo
*ob1
, struct cifsFileInfo
*ob2
)
2021 return ob1
->fid
.persistent_fid
== ob2
->fid
.persistent_fid
&&
2022 ob1
->fid
.volatile_fid
== ob2
->fid
.volatile_fid
;
2026 smb2_mand_lock(const unsigned int xid
, struct cifsFileInfo
*cfile
, __u64 offset
,
2027 __u64 length
, __u32 type
, int lock
, int unlock
, bool wait
)
2029 if (unlock
&& !lock
)
2030 type
= SMB2_LOCKFLAG_UNLOCK
;
2031 return SMB2_lock(xid
, tlink_tcon(cfile
->tlink
),
2032 cfile
->fid
.persistent_fid
, cfile
->fid
.volatile_fid
,
2033 current
->tgid
, length
, offset
, type
, wait
);
2037 smb2_get_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
2039 memcpy(fid
->lease_key
, CIFS_I(inode
)->lease_key
, SMB2_LEASE_KEY_SIZE
);
2043 smb2_set_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
2045 memcpy(CIFS_I(inode
)->lease_key
, fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
2049 smb2_new_lease_key(struct cifs_fid
*fid
)
2051 generate_random_uuid(fid
->lease_key
);
2055 smb2_get_dfs_refer(const unsigned int xid
, struct cifs_ses
*ses
,
2056 const char *search_name
,
2057 struct dfs_info3_param
**target_nodes
,
2058 unsigned int *num_of_nodes
,
2059 const struct nls_table
*nls_codepage
, int remap
)
2062 __le16
*utf16_path
= NULL
;
2063 int utf16_path_len
= 0;
2064 struct cifs_tcon
*tcon
;
2065 struct fsctl_get_dfs_referral_req
*dfs_req
= NULL
;
2066 struct get_dfs_referral_rsp
*dfs_rsp
= NULL
;
2067 u32 dfs_req_size
= 0, dfs_rsp_size
= 0;
2069 cifs_dbg(FYI
, "smb2_get_dfs_refer path <%s>\n", search_name
);
2072 * Try to use the IPC tcon, otherwise just use any
2074 tcon
= ses
->tcon_ipc
;
2076 spin_lock(&cifs_tcp_ses_lock
);
2077 tcon
= list_first_entry_or_null(&ses
->tcon_list
,
2082 spin_unlock(&cifs_tcp_ses_lock
);
2086 cifs_dbg(VFS
, "session %p has no tcon available for a dfs referral request\n",
2092 utf16_path
= cifs_strndup_to_utf16(search_name
, PATH_MAX
,
2094 nls_codepage
, remap
);
2100 dfs_req_size
= sizeof(*dfs_req
) + utf16_path_len
;
2101 dfs_req
= kzalloc(dfs_req_size
, GFP_KERNEL
);
2107 /* Highest DFS referral version understood */
2108 dfs_req
->MaxReferralLevel
= DFS_VERSION
;
2110 /* Path to resolve in an UTF-16 null-terminated string */
2111 memcpy(dfs_req
->RequestFileName
, utf16_path
, utf16_path_len
);
2114 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
2115 FSCTL_DFS_GET_REFERRALS
,
2116 true /* is_fsctl */,
2117 (char *)dfs_req
, dfs_req_size
,
2118 (char **)&dfs_rsp
, &dfs_rsp_size
);
2119 } while (rc
== -EAGAIN
);
2122 if ((rc
!= -ENOENT
) && (rc
!= -EOPNOTSUPP
))
2123 cifs_dbg(VFS
, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc
);
2127 rc
= parse_dfs_referrals(dfs_rsp
, dfs_rsp_size
,
2128 num_of_nodes
, target_nodes
,
2129 nls_codepage
, remap
, search_name
,
2130 true /* is_unicode */);
2132 cifs_dbg(VFS
, "parse error in smb2_get_dfs_refer rc=%d\n", rc
);
2137 if (tcon
&& !tcon
->ipc
) {
2138 /* ipc tcons are not refcounted */
2139 spin_lock(&cifs_tcp_ses_lock
);
2141 spin_unlock(&cifs_tcp_ses_lock
);
2148 #define SMB2_SYMLINK_STRUCT_SIZE \
2149 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
2152 smb2_query_symlink(const unsigned int xid
, struct cifs_tcon
*tcon
,
2153 const char *full_path
, char **target_path
,
2154 struct cifs_sb_info
*cifs_sb
)
2158 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
2159 struct cifs_open_parms oparms
;
2160 struct cifs_fid fid
;
2161 struct kvec err_iov
= {NULL
, 0};
2162 struct smb2_err_rsp
*err_buf
= NULL
;
2164 struct smb2_symlink_err_rsp
*symlink
;
2165 unsigned int sub_len
;
2166 unsigned int sub_offset
;
2167 unsigned int print_len
;
2168 unsigned int print_offset
;
2170 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, full_path
);
2172 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
2177 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
2178 oparms
.disposition
= FILE_OPEN
;
2179 if (backup_cred(cifs_sb
))
2180 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
2182 oparms
.create_options
= 0;
2184 oparms
.reconnect
= false;
2186 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, &err_iov
,
2188 if (!rc
|| !err_iov
.iov_base
) {
2193 err_buf
= err_iov
.iov_base
;
2194 if (le32_to_cpu(err_buf
->ByteCount
) < sizeof(struct smb2_symlink_err_rsp
) ||
2195 err_iov
.iov_len
< SMB2_SYMLINK_STRUCT_SIZE
) {
2200 /* open must fail on symlink - reset rc */
2202 symlink
= (struct smb2_symlink_err_rsp
*)err_buf
->ErrorData
;
2203 sub_len
= le16_to_cpu(symlink
->SubstituteNameLength
);
2204 sub_offset
= le16_to_cpu(symlink
->SubstituteNameOffset
);
2205 print_len
= le16_to_cpu(symlink
->PrintNameLength
);
2206 print_offset
= le16_to_cpu(symlink
->PrintNameOffset
);
2208 if (err_iov
.iov_len
< SMB2_SYMLINK_STRUCT_SIZE
+ sub_offset
+ sub_len
) {
2213 if (err_iov
.iov_len
<
2214 SMB2_SYMLINK_STRUCT_SIZE
+ print_offset
+ print_len
) {
2219 *target_path
= cifs_strndup_from_utf16(
2220 (char *)symlink
->PathBuffer
+ sub_offset
,
2221 sub_len
, true, cifs_sb
->local_nls
);
2222 if (!(*target_path
)) {
2226 convert_delimiter(*target_path
, '/');
2227 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
2230 free_rsp_buf(resp_buftype
, err_buf
);
2236 #ifdef CONFIG_CIFS_ACL
2237 static struct cifs_ntsd
*
2238 get_smb2_acl_by_fid(struct cifs_sb_info
*cifs_sb
,
2239 const struct cifs_fid
*cifsfid
, u32
*pacllen
)
2241 struct cifs_ntsd
*pntsd
= NULL
;
2243 int rc
= -EOPNOTSUPP
;
2244 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
2247 return ERR_CAST(tlink
);
2250 cifs_dbg(FYI
, "trying to get acl\n");
2252 rc
= SMB2_query_acl(xid
, tlink_tcon(tlink
), cifsfid
->persistent_fid
,
2253 cifsfid
->volatile_fid
, (void **)&pntsd
, pacllen
);
2256 cifs_put_tlink(tlink
);
2258 cifs_dbg(FYI
, "%s: rc = %d ACL len %d\n", __func__
, rc
, *pacllen
);
2265 static struct cifs_ntsd
*
2266 get_smb2_acl_by_path(struct cifs_sb_info
*cifs_sb
,
2267 const char *path
, u32
*pacllen
)
2269 struct cifs_ntsd
*pntsd
= NULL
;
2270 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
2273 struct cifs_tcon
*tcon
;
2274 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
2275 struct cifs_fid fid
;
2276 struct cifs_open_parms oparms
;
2279 cifs_dbg(FYI
, "get smb3 acl for path %s\n", path
);
2281 return ERR_CAST(tlink
);
2283 tcon
= tlink_tcon(tlink
);
2286 if (backup_cred(cifs_sb
))
2287 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
2289 oparms
.create_options
= 0;
2291 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
2299 oparms
.desired_access
= READ_CONTROL
;
2300 oparms
.disposition
= FILE_OPEN
;
2302 oparms
.reconnect
= false;
2304 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
, NULL
);
2307 rc
= SMB2_query_acl(xid
, tlink_tcon(tlink
), fid
.persistent_fid
,
2308 fid
.volatile_fid
, (void **)&pntsd
, pacllen
);
2309 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
2312 cifs_put_tlink(tlink
);
2315 cifs_dbg(FYI
, "%s: rc = %d ACL len %d\n", __func__
, rc
, *pacllen
);
2321 #ifdef CONFIG_CIFS_ACL
2323 set_smb2_acl(struct cifs_ntsd
*pnntsd
, __u32 acllen
,
2324 struct inode
*inode
, const char *path
, int aclflag
)
2326 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
2328 int rc
, access_flags
= 0;
2329 struct cifs_tcon
*tcon
;
2330 struct cifs_sb_info
*cifs_sb
= CIFS_SB(inode
->i_sb
);
2331 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
2332 struct cifs_fid fid
;
2333 struct cifs_open_parms oparms
;
2336 cifs_dbg(FYI
, "set smb3 acl for path %s\n", path
);
2338 return PTR_ERR(tlink
);
2340 tcon
= tlink_tcon(tlink
);
2343 if (backup_cred(cifs_sb
))
2344 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
2346 oparms
.create_options
= 0;
2348 if (aclflag
== CIFS_ACL_OWNER
|| aclflag
== CIFS_ACL_GROUP
)
2349 access_flags
= WRITE_OWNER
;
2351 access_flags
= WRITE_DAC
;
2353 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
2361 oparms
.desired_access
= access_flags
;
2362 oparms
.disposition
= FILE_OPEN
;
2365 oparms
.reconnect
= false;
2367 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
, NULL
);
2370 rc
= SMB2_set_acl(xid
, tlink_tcon(tlink
), fid
.persistent_fid
,
2371 fid
.volatile_fid
, pnntsd
, acllen
, aclflag
);
2372 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
2375 cifs_put_tlink(tlink
);
2379 #endif /* CIFS_ACL */
2381 /* Retrieve an ACL from the server */
2382 static struct cifs_ntsd
*
2383 get_smb2_acl(struct cifs_sb_info
*cifs_sb
,
2384 struct inode
*inode
, const char *path
,
2387 struct cifs_ntsd
*pntsd
= NULL
;
2388 struct cifsFileInfo
*open_file
= NULL
;
2391 open_file
= find_readable_file(CIFS_I(inode
), true);
2393 return get_smb2_acl_by_path(cifs_sb
, path
, pacllen
);
2395 pntsd
= get_smb2_acl_by_fid(cifs_sb
, &open_file
->fid
, pacllen
);
2396 cifsFileInfo_put(open_file
);
2401 static long smb3_zero_range(struct file
*file
, struct cifs_tcon
*tcon
,
2402 loff_t offset
, loff_t len
, bool keep_size
)
2404 struct inode
*inode
;
2405 struct cifsInodeInfo
*cifsi
;
2406 struct cifsFileInfo
*cfile
= file
->private_data
;
2407 struct file_zero_data_information fsctl_buf
;
2413 inode
= d_inode(cfile
->dentry
);
2414 cifsi
= CIFS_I(inode
);
2416 /* if file not oplocked can't be sure whether asking to extend size */
2417 if (!CIFS_CACHE_READ(cifsi
))
2418 if (keep_size
== false) {
2425 * Must check if file sparse since fallocate -z (zero range) assumes
2426 * non-sparse allocation
2428 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
)) {
2435 * need to make sure we are not asked to extend the file since the SMB3
2436 * fsctl does not change the file size. In the future we could change
2437 * this to zero the first part of the range then set the file size
2438 * which for a non sparse file would zero the newly extended range
2440 if (keep_size
== false)
2441 if (i_size_read(inode
) < offset
+ len
) {
2447 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
2449 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
2450 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
2452 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
2453 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
2454 true /* is_fctl */, (char *)&fsctl_buf
,
2455 sizeof(struct file_zero_data_information
), NULL
, NULL
);
2460 static long smb3_punch_hole(struct file
*file
, struct cifs_tcon
*tcon
,
2461 loff_t offset
, loff_t len
)
2463 struct inode
*inode
;
2464 struct cifsInodeInfo
*cifsi
;
2465 struct cifsFileInfo
*cfile
= file
->private_data
;
2466 struct file_zero_data_information fsctl_buf
;
2469 __u8 set_sparse
= 1;
2473 inode
= d_inode(cfile
->dentry
);
2474 cifsi
= CIFS_I(inode
);
2476 /* Need to make file sparse, if not already, before freeing range. */
2477 /* Consider adding equivalent for compressed since it could also work */
2478 if (!smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
)) {
2484 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
2486 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
2487 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
2489 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
2490 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
2491 true /* is_fctl */, (char *)&fsctl_buf
,
2492 sizeof(struct file_zero_data_information
), NULL
, NULL
);
2497 static long smb3_simple_falloc(struct file
*file
, struct cifs_tcon
*tcon
,
2498 loff_t off
, loff_t len
, bool keep_size
)
2500 struct inode
*inode
;
2501 struct cifsInodeInfo
*cifsi
;
2502 struct cifsFileInfo
*cfile
= file
->private_data
;
2503 long rc
= -EOPNOTSUPP
;
2508 inode
= d_inode(cfile
->dentry
);
2509 cifsi
= CIFS_I(inode
);
2511 /* if file not oplocked can't be sure whether asking to extend size */
2512 if (!CIFS_CACHE_READ(cifsi
))
2513 if (keep_size
== false) {
2519 * Files are non-sparse by default so falloc may be a no-op
2520 * Must check if file sparse. If not sparse, and not extending
2521 * then no need to do anything since file already allocated
2523 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) == 0) {
2524 if (keep_size
== true)
2526 /* check if extending file */
2527 else if (i_size_read(inode
) >= off
+ len
)
2528 /* not extending file and already not sparse */
2530 /* BB: in future add else clause to extend file */
2537 if ((keep_size
== true) || (i_size_read(inode
) >= off
+ len
)) {
2539 * Check if falloc starts within first few pages of file
2540 * and ends within a few pages of the end of file to
2541 * ensure that most of file is being forced to be
2542 * fallocated now. If so then setting whole file sparse
2543 * ie potentially making a few extra pages at the beginning
2544 * or end of the file non-sparse via set_sparse is harmless.
2546 if ((off
> 8192) || (off
+ len
+ 8192 < i_size_read(inode
))) {
2552 rc
= smb2_set_sparse(xid
, tcon
, cfile
, inode
, false);
2554 /* BB: else ... in future add code to extend file and set sparse */
2562 static long smb3_fallocate(struct file
*file
, struct cifs_tcon
*tcon
, int mode
,
2563 loff_t off
, loff_t len
)
2565 /* KEEP_SIZE already checked for by do_fallocate */
2566 if (mode
& FALLOC_FL_PUNCH_HOLE
)
2567 return smb3_punch_hole(file
, tcon
, off
, len
);
2568 else if (mode
& FALLOC_FL_ZERO_RANGE
) {
2569 if (mode
& FALLOC_FL_KEEP_SIZE
)
2570 return smb3_zero_range(file
, tcon
, off
, len
, true);
2571 return smb3_zero_range(file
, tcon
, off
, len
, false);
2572 } else if (mode
== FALLOC_FL_KEEP_SIZE
)
2573 return smb3_simple_falloc(file
, tcon
, off
, len
, true);
2575 return smb3_simple_falloc(file
, tcon
, off
, len
, false);
2581 smb2_downgrade_oplock(struct TCP_Server_Info
*server
,
2582 struct cifsInodeInfo
*cinode
, bool set_level2
)
2585 server
->ops
->set_oplock_level(cinode
, SMB2_OPLOCK_LEVEL_II
,
2588 server
->ops
->set_oplock_level(cinode
, 0, 0, NULL
);
2592 smb2_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
2593 unsigned int epoch
, bool *purge_cache
)
2596 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
2598 if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
) {
2599 cinode
->oplock
= CIFS_CACHE_RHW_FLG
;
2600 cifs_dbg(FYI
, "Batch Oplock granted on inode %p\n",
2601 &cinode
->vfs_inode
);
2602 } else if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
) {
2603 cinode
->oplock
= CIFS_CACHE_RW_FLG
;
2604 cifs_dbg(FYI
, "Exclusive Oplock granted on inode %p\n",
2605 &cinode
->vfs_inode
);
2606 } else if (oplock
== SMB2_OPLOCK_LEVEL_II
) {
2607 cinode
->oplock
= CIFS_CACHE_READ_FLG
;
2608 cifs_dbg(FYI
, "Level II Oplock granted on inode %p\n",
2609 &cinode
->vfs_inode
);
2615 smb21_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
2616 unsigned int epoch
, bool *purge_cache
)
2618 char message
[5] = {0};
2621 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
2625 if (oplock
& SMB2_LEASE_READ_CACHING_HE
) {
2626 cinode
->oplock
|= CIFS_CACHE_READ_FLG
;
2627 strcat(message
, "R");
2629 if (oplock
& SMB2_LEASE_HANDLE_CACHING_HE
) {
2630 cinode
->oplock
|= CIFS_CACHE_HANDLE_FLG
;
2631 strcat(message
, "H");
2633 if (oplock
& SMB2_LEASE_WRITE_CACHING_HE
) {
2634 cinode
->oplock
|= CIFS_CACHE_WRITE_FLG
;
2635 strcat(message
, "W");
2637 if (!cinode
->oplock
)
2638 strcat(message
, "None");
2639 cifs_dbg(FYI
, "%s Lease granted on inode %p\n", message
,
2640 &cinode
->vfs_inode
);
2644 smb3_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
2645 unsigned int epoch
, bool *purge_cache
)
2647 unsigned int old_oplock
= cinode
->oplock
;
2649 smb21_set_oplock_level(cinode
, oplock
, epoch
, purge_cache
);
2652 *purge_cache
= false;
2653 if (old_oplock
== CIFS_CACHE_READ_FLG
) {
2654 if (cinode
->oplock
== CIFS_CACHE_READ_FLG
&&
2655 (epoch
- cinode
->epoch
> 0))
2656 *purge_cache
= true;
2657 else if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
2658 (epoch
- cinode
->epoch
> 1))
2659 *purge_cache
= true;
2660 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
2661 (epoch
- cinode
->epoch
> 1))
2662 *purge_cache
= true;
2663 else if (cinode
->oplock
== 0 &&
2664 (epoch
- cinode
->epoch
> 0))
2665 *purge_cache
= true;
2666 } else if (old_oplock
== CIFS_CACHE_RH_FLG
) {
2667 if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
2668 (epoch
- cinode
->epoch
> 0))
2669 *purge_cache
= true;
2670 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
2671 (epoch
- cinode
->epoch
> 1))
2672 *purge_cache
= true;
2674 cinode
->epoch
= epoch
;
2679 smb2_is_read_op(__u32 oplock
)
2681 return oplock
== SMB2_OPLOCK_LEVEL_II
;
2685 smb21_is_read_op(__u32 oplock
)
2687 return (oplock
& SMB2_LEASE_READ_CACHING_HE
) &&
2688 !(oplock
& SMB2_LEASE_WRITE_CACHING_HE
);
2692 map_oplock_to_lease(u8 oplock
)
2694 if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
)
2695 return SMB2_LEASE_WRITE_CACHING
| SMB2_LEASE_READ_CACHING
;
2696 else if (oplock
== SMB2_OPLOCK_LEVEL_II
)
2697 return SMB2_LEASE_READ_CACHING
;
2698 else if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
)
2699 return SMB2_LEASE_HANDLE_CACHING
| SMB2_LEASE_READ_CACHING
|
2700 SMB2_LEASE_WRITE_CACHING
;
2705 smb2_create_lease_buf(u8
*lease_key
, u8 oplock
)
2707 struct create_lease
*buf
;
2709 buf
= kzalloc(sizeof(struct create_lease
), GFP_KERNEL
);
2713 memcpy(&buf
->lcontext
.LeaseKey
, lease_key
, SMB2_LEASE_KEY_SIZE
);
2714 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
2716 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
2717 (struct create_lease
, lcontext
));
2718 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context
));
2719 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
2720 (struct create_lease
, Name
));
2721 buf
->ccontext
.NameLength
= cpu_to_le16(4);
2722 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
2731 smb3_create_lease_buf(u8
*lease_key
, u8 oplock
)
2733 struct create_lease_v2
*buf
;
2735 buf
= kzalloc(sizeof(struct create_lease_v2
), GFP_KERNEL
);
2739 memcpy(&buf
->lcontext
.LeaseKey
, lease_key
, SMB2_LEASE_KEY_SIZE
);
2740 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
2742 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
2743 (struct create_lease_v2
, lcontext
));
2744 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context_v2
));
2745 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
2746 (struct create_lease_v2
, Name
));
2747 buf
->ccontext
.NameLength
= cpu_to_le16(4);
2748 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
2757 smb2_parse_lease_buf(void *buf
, unsigned int *epoch
, char *lease_key
)
2759 struct create_lease
*lc
= (struct create_lease
*)buf
;
2761 *epoch
= 0; /* not used */
2762 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
2763 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
2764 return le32_to_cpu(lc
->lcontext
.LeaseState
);
2768 smb3_parse_lease_buf(void *buf
, unsigned int *epoch
, char *lease_key
)
2770 struct create_lease_v2
*lc
= (struct create_lease_v2
*)buf
;
2772 *epoch
= le16_to_cpu(lc
->lcontext
.Epoch
);
2773 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
2774 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
2776 memcpy(lease_key
, &lc
->lcontext
.LeaseKey
, SMB2_LEASE_KEY_SIZE
);
2777 return le32_to_cpu(lc
->lcontext
.LeaseState
);
2781 smb2_wp_retry_size(struct inode
*inode
)
2783 return min_t(unsigned int, CIFS_SB(inode
->i_sb
)->wsize
,
2784 SMB2_MAX_BUFFER_SIZE
);
2788 smb2_dir_needs_close(struct cifsFileInfo
*cfile
)
2790 return !cfile
->invalidHandle
;
2794 fill_transform_hdr(struct smb2_transform_hdr
*tr_hdr
, unsigned int orig_len
,
2795 struct smb_rqst
*old_rq
)
2797 struct smb2_sync_hdr
*shdr
=
2798 (struct smb2_sync_hdr
*)old_rq
->rq_iov
[0].iov_base
;
2800 memset(tr_hdr
, 0, sizeof(struct smb2_transform_hdr
));
2801 tr_hdr
->ProtocolId
= SMB2_TRANSFORM_PROTO_NUM
;
2802 tr_hdr
->OriginalMessageSize
= cpu_to_le32(orig_len
);
2803 tr_hdr
->Flags
= cpu_to_le16(0x01);
2804 get_random_bytes(&tr_hdr
->Nonce
, SMB3_AES128CMM_NONCE
);
2805 memcpy(&tr_hdr
->SessionId
, &shdr
->SessionId
, 8);
2808 /* We can not use the normal sg_set_buf() as we will sometimes pass a
2809 * stack object as buf.
2811 static inline void smb2_sg_set_buf(struct scatterlist
*sg
, const void *buf
,
2812 unsigned int buflen
)
2814 sg_set_page(sg
, virt_to_page(buf
), buflen
, offset_in_page(buf
));
2817 /* Assumes the first rqst has a transform header as the first iov.
2819 * rqst[0].rq_iov[0] is transform header
2820 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
2821 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
2823 static struct scatterlist
*
2824 init_sg(int num_rqst
, struct smb_rqst
*rqst
, u8
*sign
)
2826 unsigned int sg_len
;
2827 struct scatterlist
*sg
;
2830 unsigned int idx
= 0;
2834 for (i
= 0; i
< num_rqst
; i
++)
2835 sg_len
+= rqst
[i
].rq_nvec
+ rqst
[i
].rq_npages
;
2837 sg
= kmalloc_array(sg_len
, sizeof(struct scatterlist
), GFP_KERNEL
);
2841 sg_init_table(sg
, sg_len
);
2842 for (i
= 0; i
< num_rqst
; i
++) {
2843 for (j
= 0; j
< rqst
[i
].rq_nvec
; j
++) {
2845 * The first rqst has a transform header where the
2846 * first 20 bytes are not part of the encrypted blob
2848 skip
= (i
== 0) && (j
== 0) ? 20 : 0;
2849 smb2_sg_set_buf(&sg
[idx
++],
2850 rqst
[i
].rq_iov
[j
].iov_base
+ skip
,
2851 rqst
[i
].rq_iov
[j
].iov_len
- skip
);
2854 for (j
= 0; j
< rqst
[i
].rq_npages
; j
++) {
2855 unsigned int len
, offset
;
2857 rqst_page_get_length(&rqst
[i
], j
, &len
, &offset
);
2858 sg_set_page(&sg
[idx
++], rqst
[i
].rq_pages
[j
], len
, offset
);
2861 smb2_sg_set_buf(&sg
[idx
], sign
, SMB2_SIGNATURE_SIZE
);
2866 smb2_get_enc_key(struct TCP_Server_Info
*server
, __u64 ses_id
, int enc
, u8
*key
)
2868 struct cifs_ses
*ses
;
2871 spin_lock(&cifs_tcp_ses_lock
);
2872 list_for_each_entry(ses
, &server
->smb_ses_list
, smb_ses_list
) {
2873 if (ses
->Suid
!= ses_id
)
2875 ses_enc_key
= enc
? ses
->smb3encryptionkey
:
2876 ses
->smb3decryptionkey
;
2877 memcpy(key
, ses_enc_key
, SMB3_SIGN_KEY_SIZE
);
2878 spin_unlock(&cifs_tcp_ses_lock
);
2881 spin_unlock(&cifs_tcp_ses_lock
);
2886 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
2887 * iov[0] - transform header (associate data),
2888 * iov[1-N] - SMB2 header and pages - data to encrypt.
2889 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
2893 crypt_message(struct TCP_Server_Info
*server
, int num_rqst
,
2894 struct smb_rqst
*rqst
, int enc
)
2896 struct smb2_transform_hdr
*tr_hdr
=
2897 (struct smb2_transform_hdr
*)rqst
[0].rq_iov
[0].iov_base
;
2898 unsigned int assoc_data_len
= sizeof(struct smb2_transform_hdr
) - 20;
2900 struct scatterlist
*sg
;
2901 u8 sign
[SMB2_SIGNATURE_SIZE
] = {};
2902 u8 key
[SMB3_SIGN_KEY_SIZE
];
2903 struct aead_request
*req
;
2905 unsigned int iv_len
;
2906 DECLARE_CRYPTO_WAIT(wait
);
2907 struct crypto_aead
*tfm
;
2908 unsigned int crypt_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
2910 rc
= smb2_get_enc_key(server
, tr_hdr
->SessionId
, enc
, key
);
2912 cifs_dbg(VFS
, "%s: Could not get %scryption key\n", __func__
,
2917 rc
= smb3_crypto_aead_allocate(server
);
2919 cifs_dbg(VFS
, "%s: crypto alloc failed\n", __func__
);
2923 tfm
= enc
? server
->secmech
.ccmaesencrypt
:
2924 server
->secmech
.ccmaesdecrypt
;
2925 rc
= crypto_aead_setkey(tfm
, key
, SMB3_SIGN_KEY_SIZE
);
2927 cifs_dbg(VFS
, "%s: Failed to set aead key %d\n", __func__
, rc
);
2931 rc
= crypto_aead_setauthsize(tfm
, SMB2_SIGNATURE_SIZE
);
2933 cifs_dbg(VFS
, "%s: Failed to set authsize %d\n", __func__
, rc
);
2937 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
2939 cifs_dbg(VFS
, "%s: Failed to alloc aead request", __func__
);
2944 memcpy(sign
, &tr_hdr
->Signature
, SMB2_SIGNATURE_SIZE
);
2945 crypt_len
+= SMB2_SIGNATURE_SIZE
;
2948 sg
= init_sg(num_rqst
, rqst
, sign
);
2950 cifs_dbg(VFS
, "%s: Failed to init sg", __func__
);
2955 iv_len
= crypto_aead_ivsize(tfm
);
2956 iv
= kzalloc(iv_len
, GFP_KERNEL
);
2958 cifs_dbg(VFS
, "%s: Failed to alloc IV", __func__
);
2963 memcpy(iv
+ 1, (char *)tr_hdr
->Nonce
, SMB3_AES128CMM_NONCE
);
2965 aead_request_set_crypt(req
, sg
, sg
, crypt_len
, iv
);
2966 aead_request_set_ad(req
, assoc_data_len
);
2968 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
2969 crypto_req_done
, &wait
);
2971 rc
= crypto_wait_req(enc
? crypto_aead_encrypt(req
)
2972 : crypto_aead_decrypt(req
), &wait
);
2975 memcpy(&tr_hdr
->Signature
, sign
, SMB2_SIGNATURE_SIZE
);
2986 smb3_free_compound_rqst(int num_rqst
, struct smb_rqst
*rqst
)
2990 for (i
= 0; i
< num_rqst
; i
++) {
2991 if (rqst
[i
].rq_pages
) {
2992 for (j
= rqst
[i
].rq_npages
- 1; j
>= 0; j
--)
2993 put_page(rqst
[i
].rq_pages
[j
]);
2994 kfree(rqst
[i
].rq_pages
);
3000 * This function will initialize new_rq and encrypt the content.
3001 * The first entry, new_rq[0], only contains a single iov which contains
3002 * a smb2_transform_hdr and is pre-allocated by the caller.
3003 * This function then populates new_rq[1+] with the content from olq_rq[0+].
3005 * The end result is an array of smb_rqst structures where the first structure
3006 * only contains a single iov for the transform header which we then can pass
3007 * to crypt_message().
3009 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
3010 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
3013 smb3_init_transform_rq(struct TCP_Server_Info
*server
, int num_rqst
,
3014 struct smb_rqst
*new_rq
, struct smb_rqst
*old_rq
)
3016 struct page
**pages
;
3017 struct smb2_transform_hdr
*tr_hdr
= new_rq
[0].rq_iov
[0].iov_base
;
3018 unsigned int npages
;
3019 unsigned int orig_len
= 0;
3023 for (i
= 1; i
< num_rqst
; i
++) {
3024 npages
= old_rq
[i
- 1].rq_npages
;
3025 pages
= kmalloc_array(npages
, sizeof(struct page
*),
3030 new_rq
[i
].rq_pages
= pages
;
3031 new_rq
[i
].rq_npages
= npages
;
3032 new_rq
[i
].rq_offset
= old_rq
[i
- 1].rq_offset
;
3033 new_rq
[i
].rq_pagesz
= old_rq
[i
- 1].rq_pagesz
;
3034 new_rq
[i
].rq_tailsz
= old_rq
[i
- 1].rq_tailsz
;
3035 new_rq
[i
].rq_iov
= old_rq
[i
- 1].rq_iov
;
3036 new_rq
[i
].rq_nvec
= old_rq
[i
- 1].rq_nvec
;
3038 orig_len
+= smb_rqst_len(server
, &old_rq
[i
- 1]);
3040 for (j
= 0; j
< npages
; j
++) {
3041 pages
[j
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
3046 /* copy pages form the old */
3047 for (j
= 0; j
< npages
; j
++) {
3049 unsigned int offset
, len
;
3051 rqst_page_get_length(&new_rq
[i
], j
, &len
, &offset
);
3053 dst
= (char *) kmap(new_rq
[i
].rq_pages
[j
]) + offset
;
3054 src
= (char *) kmap(old_rq
[i
- 1].rq_pages
[j
]) + offset
;
3056 memcpy(dst
, src
, len
);
3057 kunmap(new_rq
[i
].rq_pages
[j
]);
3058 kunmap(old_rq
[i
- 1].rq_pages
[j
]);
3062 /* fill the 1st iov with a transform header */
3063 fill_transform_hdr(tr_hdr
, orig_len
, old_rq
);
3065 rc
= crypt_message(server
, num_rqst
, new_rq
, 1);
3066 cifs_dbg(FYI
, "encrypt message returned %d", rc
);
3073 smb3_free_compound_rqst(num_rqst
- 1, &new_rq
[1]);
3078 smb3_is_transform_hdr(void *buf
)
3080 struct smb2_transform_hdr
*trhdr
= buf
;
3082 return trhdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
;
3086 decrypt_raw_data(struct TCP_Server_Info
*server
, char *buf
,
3087 unsigned int buf_data_size
, struct page
**pages
,
3088 unsigned int npages
, unsigned int page_data_size
)
3091 struct smb_rqst rqst
= {NULL
};
3094 iov
[0].iov_base
= buf
;
3095 iov
[0].iov_len
= sizeof(struct smb2_transform_hdr
);
3096 iov
[1].iov_base
= buf
+ sizeof(struct smb2_transform_hdr
);
3097 iov
[1].iov_len
= buf_data_size
;
3101 rqst
.rq_pages
= pages
;
3102 rqst
.rq_npages
= npages
;
3103 rqst
.rq_pagesz
= PAGE_SIZE
;
3104 rqst
.rq_tailsz
= (page_data_size
% PAGE_SIZE
) ? : PAGE_SIZE
;
3106 rc
= crypt_message(server
, 1, &rqst
, 0);
3107 cifs_dbg(FYI
, "decrypt message returned %d\n", rc
);
3112 memmove(buf
, iov
[1].iov_base
, buf_data_size
);
3114 server
->total_read
= buf_data_size
+ page_data_size
;
3120 read_data_into_pages(struct TCP_Server_Info
*server
, struct page
**pages
,
3121 unsigned int npages
, unsigned int len
)
3126 for (i
= 0; i
< npages
; i
++) {
3127 struct page
*page
= pages
[i
];
3131 if (len
>= PAGE_SIZE
) {
3132 /* enough data to fill the page */
3136 zero_user(page
, len
, PAGE_SIZE
- len
);
3139 length
= cifs_read_page_from_socket(server
, page
, 0, n
);
3142 server
->total_read
+= length
;
3149 init_read_bvec(struct page
**pages
, unsigned int npages
, unsigned int data_size
,
3150 unsigned int cur_off
, struct bio_vec
**page_vec
)
3152 struct bio_vec
*bvec
;
3155 bvec
= kcalloc(npages
, sizeof(struct bio_vec
), GFP_KERNEL
);
3159 for (i
= 0; i
< npages
; i
++) {
3160 bvec
[i
].bv_page
= pages
[i
];
3161 bvec
[i
].bv_offset
= (i
== 0) ? cur_off
: 0;
3162 bvec
[i
].bv_len
= min_t(unsigned int, PAGE_SIZE
, data_size
);
3163 data_size
-= bvec
[i
].bv_len
;
3166 if (data_size
!= 0) {
3167 cifs_dbg(VFS
, "%s: something went wrong\n", __func__
);
3177 handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
,
3178 char *buf
, unsigned int buf_len
, struct page
**pages
,
3179 unsigned int npages
, unsigned int page_data_size
)
3181 unsigned int data_offset
;
3182 unsigned int data_len
;
3183 unsigned int cur_off
;
3184 unsigned int cur_page_idx
;
3185 unsigned int pad_len
;
3186 struct cifs_readdata
*rdata
= mid
->callback_data
;
3187 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
3188 struct bio_vec
*bvec
= NULL
;
3189 struct iov_iter iter
;
3192 bool use_rdma_mr
= false;
3194 if (shdr
->Command
!= SMB2_READ
) {
3195 cifs_dbg(VFS
, "only big read responses are supported\n");
3199 if (server
->ops
->is_session_expired
&&
3200 server
->ops
->is_session_expired(buf
)) {
3201 cifs_reconnect(server
);
3202 wake_up(&server
->response_q
);
3206 if (server
->ops
->is_status_pending
&&
3207 server
->ops
->is_status_pending(buf
, server
, 0))
3210 rdata
->result
= server
->ops
->map_error(buf
, false);
3211 if (rdata
->result
!= 0) {
3212 cifs_dbg(FYI
, "%s: server returned error %d\n",
3213 __func__
, rdata
->result
);
3214 dequeue_mid(mid
, rdata
->result
);
3218 data_offset
= server
->ops
->read_data_offset(buf
);
3219 #ifdef CONFIG_CIFS_SMB_DIRECT
3220 use_rdma_mr
= rdata
->mr
;
3222 data_len
= server
->ops
->read_data_length(buf
, use_rdma_mr
);
3224 if (data_offset
< server
->vals
->read_rsp_size
) {
3226 * win2k8 sometimes sends an offset of 0 when the read
3227 * is beyond the EOF. Treat it as if the data starts just after
3230 cifs_dbg(FYI
, "%s: data offset (%u) inside read response header\n",
3231 __func__
, data_offset
);
3232 data_offset
= server
->vals
->read_rsp_size
;
3233 } else if (data_offset
> MAX_CIFS_SMALL_BUFFER_SIZE
) {
3234 /* data_offset is beyond the end of smallbuf */
3235 cifs_dbg(FYI
, "%s: data offset (%u) beyond end of smallbuf\n",
3236 __func__
, data_offset
);
3237 rdata
->result
= -EIO
;
3238 dequeue_mid(mid
, rdata
->result
);
3242 pad_len
= data_offset
- server
->vals
->read_rsp_size
;
3244 if (buf_len
<= data_offset
) {
3245 /* read response payload is in pages */
3246 cur_page_idx
= pad_len
/ PAGE_SIZE
;
3247 cur_off
= pad_len
% PAGE_SIZE
;
3249 if (cur_page_idx
!= 0) {
3250 /* data offset is beyond the 1st page of response */
3251 cifs_dbg(FYI
, "%s: data offset (%u) beyond 1st page of response\n",
3252 __func__
, data_offset
);
3253 rdata
->result
= -EIO
;
3254 dequeue_mid(mid
, rdata
->result
);
3258 if (data_len
> page_data_size
- pad_len
) {
3259 /* data_len is corrupt -- discard frame */
3260 rdata
->result
= -EIO
;
3261 dequeue_mid(mid
, rdata
->result
);
3265 rdata
->result
= init_read_bvec(pages
, npages
, page_data_size
,
3267 if (rdata
->result
!= 0) {
3268 dequeue_mid(mid
, rdata
->result
);
3272 iov_iter_bvec(&iter
, WRITE
, bvec
, npages
, data_len
);
3273 } else if (buf_len
>= data_offset
+ data_len
) {
3274 /* read response payload is in buf */
3275 WARN_ONCE(npages
> 0, "read data can be either in buf or in pages");
3276 iov
.iov_base
= buf
+ data_offset
;
3277 iov
.iov_len
= data_len
;
3278 iov_iter_kvec(&iter
, WRITE
, &iov
, 1, data_len
);
3280 /* read response payload cannot be in both buf and pages */
3281 WARN_ONCE(1, "buf can not contain only a part of read data");
3282 rdata
->result
= -EIO
;
3283 dequeue_mid(mid
, rdata
->result
);
3287 /* set up first iov for signature check */
3288 rdata
->iov
[0].iov_base
= buf
;
3289 rdata
->iov
[0].iov_len
= 4;
3290 rdata
->iov
[1].iov_base
= buf
+ 4;
3291 rdata
->iov
[1].iov_len
= server
->vals
->read_rsp_size
- 4;
3292 cifs_dbg(FYI
, "0: iov_base=%p iov_len=%zu\n",
3293 rdata
->iov
[0].iov_base
, server
->vals
->read_rsp_size
);
3295 length
= rdata
->copy_into_pages(server
, rdata
, &iter
);
3302 dequeue_mid(mid
, false);
3307 receive_encrypted_read(struct TCP_Server_Info
*server
, struct mid_q_entry
**mid
)
3309 char *buf
= server
->smallbuf
;
3310 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
3311 unsigned int npages
;
3312 struct page
**pages
;
3314 unsigned int buflen
= server
->pdu_size
;
3318 len
= min_t(unsigned int, buflen
, server
->vals
->read_rsp_size
+
3319 sizeof(struct smb2_transform_hdr
)) - HEADER_SIZE(server
) + 1;
3321 rc
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1, len
);
3324 server
->total_read
+= rc
;
3326 len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
) -
3327 server
->vals
->read_rsp_size
;
3328 npages
= DIV_ROUND_UP(len
, PAGE_SIZE
);
3330 pages
= kmalloc_array(npages
, sizeof(struct page
*), GFP_KERNEL
);
3336 for (; i
< npages
; i
++) {
3337 pages
[i
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
3344 /* read read data into pages */
3345 rc
= read_data_into_pages(server
, pages
, npages
, len
);
3349 rc
= cifs_discard_remaining_data(server
);
3353 rc
= decrypt_raw_data(server
, buf
, server
->vals
->read_rsp_size
,
3354 pages
, npages
, len
);
3358 *mid
= smb2_find_mid(server
, buf
);
3360 cifs_dbg(FYI
, "mid not found\n");
3362 cifs_dbg(FYI
, "mid found\n");
3363 (*mid
)->decrypted
= true;
3364 rc
= handle_read_data(server
, *mid
, buf
,
3365 server
->vals
->read_rsp_size
,
3366 pages
, npages
, len
);
3370 for (i
= i
- 1; i
>= 0; i
--)
3375 cifs_discard_remaining_data(server
);
3380 receive_encrypted_standard(struct TCP_Server_Info
*server
,
3381 struct mid_q_entry
**mids
, char **bufs
,
3385 char *buf
= server
->smallbuf
;
3387 struct smb2_sync_hdr
*shdr
;
3388 unsigned int pdu_length
= server
->pdu_size
;
3389 unsigned int buf_size
;
3390 struct mid_q_entry
*mid_entry
;
3392 char *next_buffer
= NULL
;
3396 /* switch to large buffer if too big for a small one */
3397 if (pdu_length
> MAX_CIFS_SMALL_BUFFER_SIZE
) {
3398 server
->large_buf
= true;
3399 memcpy(server
->bigbuf
, buf
, server
->total_read
);
3400 buf
= server
->bigbuf
;
3403 /* now read the rest */
3404 length
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1,
3405 pdu_length
- HEADER_SIZE(server
) + 1);
3408 server
->total_read
+= length
;
3410 buf_size
= pdu_length
- sizeof(struct smb2_transform_hdr
);
3411 length
= decrypt_raw_data(server
, buf
, buf_size
, NULL
, 0, 0);
3415 next_is_large
= server
->large_buf
;
3417 shdr
= (struct smb2_sync_hdr
*)buf
;
3418 if (shdr
->NextCommand
) {
3419 if (next_is_large
) {
3420 tmpbuf
= server
->bigbuf
;
3421 next_buffer
= (char *)cifs_buf_get();
3423 tmpbuf
= server
->smallbuf
;
3424 next_buffer
= (char *)cifs_small_buf_get();
3427 tmpbuf
+ le32_to_cpu(shdr
->NextCommand
),
3428 pdu_length
- le32_to_cpu(shdr
->NextCommand
));
3431 mid_entry
= smb2_find_mid(server
, buf
);
3432 if (mid_entry
== NULL
)
3433 cifs_dbg(FYI
, "mid not found\n");
3435 cifs_dbg(FYI
, "mid found\n");
3436 mid_entry
->decrypted
= true;
3437 mid_entry
->resp_buf_size
= server
->pdu_size
;
3440 if (*num_mids
>= MAX_COMPOUND
) {
3441 cifs_dbg(VFS
, "too many PDUs in compound\n");
3444 bufs
[*num_mids
] = buf
;
3445 mids
[(*num_mids
)++] = mid_entry
;
3447 if (mid_entry
&& mid_entry
->handle
)
3448 ret
= mid_entry
->handle(server
, mid_entry
);
3450 ret
= cifs_handle_standard(server
, mid_entry
);
3452 if (ret
== 0 && shdr
->NextCommand
) {
3453 pdu_length
-= le32_to_cpu(shdr
->NextCommand
);
3454 server
->large_buf
= next_is_large
;
3456 server
->bigbuf
= next_buffer
;
3458 server
->smallbuf
= next_buffer
;
3460 buf
+= le32_to_cpu(shdr
->NextCommand
);
3468 smb3_receive_transform(struct TCP_Server_Info
*server
,
3469 struct mid_q_entry
**mids
, char **bufs
, int *num_mids
)
3471 char *buf
= server
->smallbuf
;
3472 unsigned int pdu_length
= server
->pdu_size
;
3473 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
3474 unsigned int orig_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
3476 if (pdu_length
< sizeof(struct smb2_transform_hdr
) +
3477 sizeof(struct smb2_sync_hdr
)) {
3478 cifs_dbg(VFS
, "Transform message is too small (%u)\n",
3480 cifs_reconnect(server
);
3481 wake_up(&server
->response_q
);
3482 return -ECONNABORTED
;
3485 if (pdu_length
< orig_len
+ sizeof(struct smb2_transform_hdr
)) {
3486 cifs_dbg(VFS
, "Transform message is broken\n");
3487 cifs_reconnect(server
);
3488 wake_up(&server
->response_q
);
3489 return -ECONNABORTED
;
3492 /* TODO: add support for compounds containing READ. */
3493 if (pdu_length
> CIFSMaxBufSize
+ MAX_HEADER_SIZE(server
)) {
3495 return receive_encrypted_read(server
, &mids
[0]);
3498 return receive_encrypted_standard(server
, mids
, bufs
, num_mids
);
3502 smb3_handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
)
3504 char *buf
= server
->large_buf
? server
->bigbuf
: server
->smallbuf
;
3506 return handle_read_data(server
, mid
, buf
, server
->pdu_size
,
3511 smb2_next_header(char *buf
)
3513 struct smb2_sync_hdr
*hdr
= (struct smb2_sync_hdr
*)buf
;
3514 struct smb2_transform_hdr
*t_hdr
= (struct smb2_transform_hdr
*)buf
;
3516 if (hdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
)
3517 return sizeof(struct smb2_transform_hdr
) +
3518 le32_to_cpu(t_hdr
->OriginalMessageSize
);
3520 return le32_to_cpu(hdr
->NextCommand
);
3523 struct smb_version_operations smb20_operations
= {
3524 .compare_fids
= smb2_compare_fids
,
3525 .setup_request
= smb2_setup_request
,
3526 .setup_async_request
= smb2_setup_async_request
,
3527 .check_receive
= smb2_check_receive
,
3528 .add_credits
= smb2_add_credits
,
3529 .set_credits
= smb2_set_credits
,
3530 .get_credits_field
= smb2_get_credits_field
,
3531 .get_credits
= smb2_get_credits
,
3532 .wait_mtu_credits
= cifs_wait_mtu_credits
,
3533 .get_next_mid
= smb2_get_next_mid
,
3534 .read_data_offset
= smb2_read_data_offset
,
3535 .read_data_length
= smb2_read_data_length
,
3536 .map_error
= map_smb2_to_linux_error
,
3537 .find_mid
= smb2_find_mid
,
3538 .check_message
= smb2_check_message
,
3539 .dump_detail
= smb2_dump_detail
,
3540 .clear_stats
= smb2_clear_stats
,
3541 .print_stats
= smb2_print_stats
,
3542 .is_oplock_break
= smb2_is_valid_oplock_break
,
3543 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
3544 .downgrade_oplock
= smb2_downgrade_oplock
,
3545 .need_neg
= smb2_need_neg
,
3546 .negotiate
= smb2_negotiate
,
3547 .negotiate_wsize
= smb2_negotiate_wsize
,
3548 .negotiate_rsize
= smb2_negotiate_rsize
,
3549 .sess_setup
= SMB2_sess_setup
,
3550 .logoff
= SMB2_logoff
,
3551 .tree_connect
= SMB2_tcon
,
3552 .tree_disconnect
= SMB2_tdis
,
3553 .qfs_tcon
= smb2_qfs_tcon
,
3554 .is_path_accessible
= smb2_is_path_accessible
,
3555 .can_echo
= smb2_can_echo
,
3557 .query_path_info
= smb2_query_path_info
,
3558 .get_srv_inum
= smb2_get_srv_inum
,
3559 .query_file_info
= smb2_query_file_info
,
3560 .set_path_size
= smb2_set_path_size
,
3561 .set_file_size
= smb2_set_file_size
,
3562 .set_file_info
= smb2_set_file_info
,
3563 .set_compression
= smb2_set_compression
,
3564 .mkdir
= smb2_mkdir
,
3565 .mkdir_setinfo
= smb2_mkdir_setinfo
,
3566 .rmdir
= smb2_rmdir
,
3567 .unlink
= smb2_unlink
,
3568 .rename
= smb2_rename_path
,
3569 .create_hardlink
= smb2_create_hardlink
,
3570 .query_symlink
= smb2_query_symlink
,
3571 .query_mf_symlink
= smb3_query_mf_symlink
,
3572 .create_mf_symlink
= smb3_create_mf_symlink
,
3573 .open
= smb2_open_file
,
3574 .set_fid
= smb2_set_fid
,
3575 .close
= smb2_close_file
,
3576 .flush
= smb2_flush_file
,
3577 .async_readv
= smb2_async_readv
,
3578 .async_writev
= smb2_async_writev
,
3579 .sync_read
= smb2_sync_read
,
3580 .sync_write
= smb2_sync_write
,
3581 .query_dir_first
= smb2_query_dir_first
,
3582 .query_dir_next
= smb2_query_dir_next
,
3583 .close_dir
= smb2_close_dir
,
3584 .calc_smb_size
= smb2_calc_size
,
3585 .is_status_pending
= smb2_is_status_pending
,
3586 .is_session_expired
= smb2_is_session_expired
,
3587 .oplock_response
= smb2_oplock_response
,
3588 .queryfs
= smb2_queryfs
,
3589 .mand_lock
= smb2_mand_lock
,
3590 .mand_unlock_range
= smb2_unlock_range
,
3591 .push_mand_locks
= smb2_push_mandatory_locks
,
3592 .get_lease_key
= smb2_get_lease_key
,
3593 .set_lease_key
= smb2_set_lease_key
,
3594 .new_lease_key
= smb2_new_lease_key
,
3595 .calc_signature
= smb2_calc_signature
,
3596 .is_read_op
= smb2_is_read_op
,
3597 .set_oplock_level
= smb2_set_oplock_level
,
3598 .create_lease_buf
= smb2_create_lease_buf
,
3599 .parse_lease_buf
= smb2_parse_lease_buf
,
3600 .copychunk_range
= smb2_copychunk_range
,
3601 .wp_retry_size
= smb2_wp_retry_size
,
3602 .dir_needs_close
= smb2_dir_needs_close
,
3603 .get_dfs_refer
= smb2_get_dfs_refer
,
3604 .select_sectype
= smb2_select_sectype
,
3605 #ifdef CONFIG_CIFS_XATTR
3606 .query_all_EAs
= smb2_query_eas
,
3607 .set_EA
= smb2_set_ea
,
3608 #endif /* CIFS_XATTR */
3609 #ifdef CONFIG_CIFS_ACL
3610 .get_acl
= get_smb2_acl
,
3611 .get_acl_by_fid
= get_smb2_acl_by_fid
,
3612 .set_acl
= set_smb2_acl
,
3613 #endif /* CIFS_ACL */
3614 .next_header
= smb2_next_header
,
3615 .ioctl_query_info
= smb2_ioctl_query_info
,
3618 struct smb_version_operations smb21_operations
= {
3619 .compare_fids
= smb2_compare_fids
,
3620 .setup_request
= smb2_setup_request
,
3621 .setup_async_request
= smb2_setup_async_request
,
3622 .check_receive
= smb2_check_receive
,
3623 .add_credits
= smb2_add_credits
,
3624 .set_credits
= smb2_set_credits
,
3625 .get_credits_field
= smb2_get_credits_field
,
3626 .get_credits
= smb2_get_credits
,
3627 .wait_mtu_credits
= smb2_wait_mtu_credits
,
3628 .get_next_mid
= smb2_get_next_mid
,
3629 .read_data_offset
= smb2_read_data_offset
,
3630 .read_data_length
= smb2_read_data_length
,
3631 .map_error
= map_smb2_to_linux_error
,
3632 .find_mid
= smb2_find_mid
,
3633 .check_message
= smb2_check_message
,
3634 .dump_detail
= smb2_dump_detail
,
3635 .clear_stats
= smb2_clear_stats
,
3636 .print_stats
= smb2_print_stats
,
3637 .is_oplock_break
= smb2_is_valid_oplock_break
,
3638 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
3639 .downgrade_oplock
= smb2_downgrade_oplock
,
3640 .need_neg
= smb2_need_neg
,
3641 .negotiate
= smb2_negotiate
,
3642 .negotiate_wsize
= smb2_negotiate_wsize
,
3643 .negotiate_rsize
= smb2_negotiate_rsize
,
3644 .sess_setup
= SMB2_sess_setup
,
3645 .logoff
= SMB2_logoff
,
3646 .tree_connect
= SMB2_tcon
,
3647 .tree_disconnect
= SMB2_tdis
,
3648 .qfs_tcon
= smb2_qfs_tcon
,
3649 .is_path_accessible
= smb2_is_path_accessible
,
3650 .can_echo
= smb2_can_echo
,
3652 .query_path_info
= smb2_query_path_info
,
3653 .get_srv_inum
= smb2_get_srv_inum
,
3654 .query_file_info
= smb2_query_file_info
,
3655 .set_path_size
= smb2_set_path_size
,
3656 .set_file_size
= smb2_set_file_size
,
3657 .set_file_info
= smb2_set_file_info
,
3658 .set_compression
= smb2_set_compression
,
3659 .mkdir
= smb2_mkdir
,
3660 .mkdir_setinfo
= smb2_mkdir_setinfo
,
3661 .rmdir
= smb2_rmdir
,
3662 .unlink
= smb2_unlink
,
3663 .rename
= smb2_rename_path
,
3664 .create_hardlink
= smb2_create_hardlink
,
3665 .query_symlink
= smb2_query_symlink
,
3666 .query_mf_symlink
= smb3_query_mf_symlink
,
3667 .create_mf_symlink
= smb3_create_mf_symlink
,
3668 .open
= smb2_open_file
,
3669 .set_fid
= smb2_set_fid
,
3670 .close
= smb2_close_file
,
3671 .flush
= smb2_flush_file
,
3672 .async_readv
= smb2_async_readv
,
3673 .async_writev
= smb2_async_writev
,
3674 .sync_read
= smb2_sync_read
,
3675 .sync_write
= smb2_sync_write
,
3676 .query_dir_first
= smb2_query_dir_first
,
3677 .query_dir_next
= smb2_query_dir_next
,
3678 .close_dir
= smb2_close_dir
,
3679 .calc_smb_size
= smb2_calc_size
,
3680 .is_status_pending
= smb2_is_status_pending
,
3681 .is_session_expired
= smb2_is_session_expired
,
3682 .oplock_response
= smb2_oplock_response
,
3683 .queryfs
= smb2_queryfs
,
3684 .mand_lock
= smb2_mand_lock
,
3685 .mand_unlock_range
= smb2_unlock_range
,
3686 .push_mand_locks
= smb2_push_mandatory_locks
,
3687 .get_lease_key
= smb2_get_lease_key
,
3688 .set_lease_key
= smb2_set_lease_key
,
3689 .new_lease_key
= smb2_new_lease_key
,
3690 .calc_signature
= smb2_calc_signature
,
3691 .is_read_op
= smb21_is_read_op
,
3692 .set_oplock_level
= smb21_set_oplock_level
,
3693 .create_lease_buf
= smb2_create_lease_buf
,
3694 .parse_lease_buf
= smb2_parse_lease_buf
,
3695 .copychunk_range
= smb2_copychunk_range
,
3696 .wp_retry_size
= smb2_wp_retry_size
,
3697 .dir_needs_close
= smb2_dir_needs_close
,
3698 .enum_snapshots
= smb3_enum_snapshots
,
3699 .get_dfs_refer
= smb2_get_dfs_refer
,
3700 .select_sectype
= smb2_select_sectype
,
3701 #ifdef CONFIG_CIFS_XATTR
3702 .query_all_EAs
= smb2_query_eas
,
3703 .set_EA
= smb2_set_ea
,
3704 #endif /* CIFS_XATTR */
3705 #ifdef CONFIG_CIFS_ACL
3706 .get_acl
= get_smb2_acl
,
3707 .get_acl_by_fid
= get_smb2_acl_by_fid
,
3708 .set_acl
= set_smb2_acl
,
3709 #endif /* CIFS_ACL */
3710 .next_header
= smb2_next_header
,
3711 .ioctl_query_info
= smb2_ioctl_query_info
,
3714 struct smb_version_operations smb30_operations
= {
3715 .compare_fids
= smb2_compare_fids
,
3716 .setup_request
= smb2_setup_request
,
3717 .setup_async_request
= smb2_setup_async_request
,
3718 .check_receive
= smb2_check_receive
,
3719 .add_credits
= smb2_add_credits
,
3720 .set_credits
= smb2_set_credits
,
3721 .get_credits_field
= smb2_get_credits_field
,
3722 .get_credits
= smb2_get_credits
,
3723 .wait_mtu_credits
= smb2_wait_mtu_credits
,
3724 .get_next_mid
= smb2_get_next_mid
,
3725 .read_data_offset
= smb2_read_data_offset
,
3726 .read_data_length
= smb2_read_data_length
,
3727 .map_error
= map_smb2_to_linux_error
,
3728 .find_mid
= smb2_find_mid
,
3729 .check_message
= smb2_check_message
,
3730 .dump_detail
= smb2_dump_detail
,
3731 .clear_stats
= smb2_clear_stats
,
3732 .print_stats
= smb2_print_stats
,
3733 .dump_share_caps
= smb2_dump_share_caps
,
3734 .is_oplock_break
= smb2_is_valid_oplock_break
,
3735 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
3736 .downgrade_oplock
= smb2_downgrade_oplock
,
3737 .need_neg
= smb2_need_neg
,
3738 .negotiate
= smb2_negotiate
,
3739 .negotiate_wsize
= smb3_negotiate_wsize
,
3740 .negotiate_rsize
= smb3_negotiate_rsize
,
3741 .sess_setup
= SMB2_sess_setup
,
3742 .logoff
= SMB2_logoff
,
3743 .tree_connect
= SMB2_tcon
,
3744 .tree_disconnect
= SMB2_tdis
,
3745 .qfs_tcon
= smb3_qfs_tcon
,
3746 .is_path_accessible
= smb2_is_path_accessible
,
3747 .can_echo
= smb2_can_echo
,
3749 .query_path_info
= smb2_query_path_info
,
3750 .get_srv_inum
= smb2_get_srv_inum
,
3751 .query_file_info
= smb2_query_file_info
,
3752 .set_path_size
= smb2_set_path_size
,
3753 .set_file_size
= smb2_set_file_size
,
3754 .set_file_info
= smb2_set_file_info
,
3755 .set_compression
= smb2_set_compression
,
3756 .mkdir
= smb2_mkdir
,
3757 .mkdir_setinfo
= smb2_mkdir_setinfo
,
3758 .rmdir
= smb2_rmdir
,
3759 .unlink
= smb2_unlink
,
3760 .rename
= smb2_rename_path
,
3761 .create_hardlink
= smb2_create_hardlink
,
3762 .query_symlink
= smb2_query_symlink
,
3763 .query_mf_symlink
= smb3_query_mf_symlink
,
3764 .create_mf_symlink
= smb3_create_mf_symlink
,
3765 .open
= smb2_open_file
,
3766 .set_fid
= smb2_set_fid
,
3767 .close
= smb2_close_file
,
3768 .flush
= smb2_flush_file
,
3769 .async_readv
= smb2_async_readv
,
3770 .async_writev
= smb2_async_writev
,
3771 .sync_read
= smb2_sync_read
,
3772 .sync_write
= smb2_sync_write
,
3773 .query_dir_first
= smb2_query_dir_first
,
3774 .query_dir_next
= smb2_query_dir_next
,
3775 .close_dir
= smb2_close_dir
,
3776 .calc_smb_size
= smb2_calc_size
,
3777 .is_status_pending
= smb2_is_status_pending
,
3778 .is_session_expired
= smb2_is_session_expired
,
3779 .oplock_response
= smb2_oplock_response
,
3780 .queryfs
= smb2_queryfs
,
3781 .mand_lock
= smb2_mand_lock
,
3782 .mand_unlock_range
= smb2_unlock_range
,
3783 .push_mand_locks
= smb2_push_mandatory_locks
,
3784 .get_lease_key
= smb2_get_lease_key
,
3785 .set_lease_key
= smb2_set_lease_key
,
3786 .new_lease_key
= smb2_new_lease_key
,
3787 .generate_signingkey
= generate_smb30signingkey
,
3788 .calc_signature
= smb3_calc_signature
,
3789 .set_integrity
= smb3_set_integrity
,
3790 .is_read_op
= smb21_is_read_op
,
3791 .set_oplock_level
= smb3_set_oplock_level
,
3792 .create_lease_buf
= smb3_create_lease_buf
,
3793 .parse_lease_buf
= smb3_parse_lease_buf
,
3794 .copychunk_range
= smb2_copychunk_range
,
3795 .duplicate_extents
= smb2_duplicate_extents
,
3796 .validate_negotiate
= smb3_validate_negotiate
,
3797 .wp_retry_size
= smb2_wp_retry_size
,
3798 .dir_needs_close
= smb2_dir_needs_close
,
3799 .fallocate
= smb3_fallocate
,
3800 .enum_snapshots
= smb3_enum_snapshots
,
3801 .init_transform_rq
= smb3_init_transform_rq
,
3802 .is_transform_hdr
= smb3_is_transform_hdr
,
3803 .receive_transform
= smb3_receive_transform
,
3804 .get_dfs_refer
= smb2_get_dfs_refer
,
3805 .select_sectype
= smb2_select_sectype
,
3806 #ifdef CONFIG_CIFS_XATTR
3807 .query_all_EAs
= smb2_query_eas
,
3808 .set_EA
= smb2_set_ea
,
3809 #endif /* CIFS_XATTR */
3810 #ifdef CONFIG_CIFS_ACL
3811 .get_acl
= get_smb2_acl
,
3812 .get_acl_by_fid
= get_smb2_acl_by_fid
,
3813 .set_acl
= set_smb2_acl
,
3814 #endif /* CIFS_ACL */
3815 .next_header
= smb2_next_header
,
3816 .ioctl_query_info
= smb2_ioctl_query_info
,
3819 struct smb_version_operations smb311_operations
= {
3820 .compare_fids
= smb2_compare_fids
,
3821 .setup_request
= smb2_setup_request
,
3822 .setup_async_request
= smb2_setup_async_request
,
3823 .check_receive
= smb2_check_receive
,
3824 .add_credits
= smb2_add_credits
,
3825 .set_credits
= smb2_set_credits
,
3826 .get_credits_field
= smb2_get_credits_field
,
3827 .get_credits
= smb2_get_credits
,
3828 .wait_mtu_credits
= smb2_wait_mtu_credits
,
3829 .get_next_mid
= smb2_get_next_mid
,
3830 .read_data_offset
= smb2_read_data_offset
,
3831 .read_data_length
= smb2_read_data_length
,
3832 .map_error
= map_smb2_to_linux_error
,
3833 .find_mid
= smb2_find_mid
,
3834 .check_message
= smb2_check_message
,
3835 .dump_detail
= smb2_dump_detail
,
3836 .clear_stats
= smb2_clear_stats
,
3837 .print_stats
= smb2_print_stats
,
3838 .dump_share_caps
= smb2_dump_share_caps
,
3839 .is_oplock_break
= smb2_is_valid_oplock_break
,
3840 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
3841 .downgrade_oplock
= smb2_downgrade_oplock
,
3842 .need_neg
= smb2_need_neg
,
3843 .negotiate
= smb2_negotiate
,
3844 .negotiate_wsize
= smb3_negotiate_wsize
,
3845 .negotiate_rsize
= smb3_negotiate_rsize
,
3846 .sess_setup
= SMB2_sess_setup
,
3847 .logoff
= SMB2_logoff
,
3848 .tree_connect
= SMB2_tcon
,
3849 .tree_disconnect
= SMB2_tdis
,
3850 .qfs_tcon
= smb3_qfs_tcon
,
3851 .is_path_accessible
= smb2_is_path_accessible
,
3852 .can_echo
= smb2_can_echo
,
3854 .query_path_info
= smb2_query_path_info
,
3855 .get_srv_inum
= smb2_get_srv_inum
,
3856 .query_file_info
= smb2_query_file_info
,
3857 .set_path_size
= smb2_set_path_size
,
3858 .set_file_size
= smb2_set_file_size
,
3859 .set_file_info
= smb2_set_file_info
,
3860 .set_compression
= smb2_set_compression
,
3861 .mkdir
= smb2_mkdir
,
3862 .mkdir_setinfo
= smb2_mkdir_setinfo
,
3863 .posix_mkdir
= smb311_posix_mkdir
,
3864 .rmdir
= smb2_rmdir
,
3865 .unlink
= smb2_unlink
,
3866 .rename
= smb2_rename_path
,
3867 .create_hardlink
= smb2_create_hardlink
,
3868 .query_symlink
= smb2_query_symlink
,
3869 .query_mf_symlink
= smb3_query_mf_symlink
,
3870 .create_mf_symlink
= smb3_create_mf_symlink
,
3871 .open
= smb2_open_file
,
3872 .set_fid
= smb2_set_fid
,
3873 .close
= smb2_close_file
,
3874 .flush
= smb2_flush_file
,
3875 .async_readv
= smb2_async_readv
,
3876 .async_writev
= smb2_async_writev
,
3877 .sync_read
= smb2_sync_read
,
3878 .sync_write
= smb2_sync_write
,
3879 .query_dir_first
= smb2_query_dir_first
,
3880 .query_dir_next
= smb2_query_dir_next
,
3881 .close_dir
= smb2_close_dir
,
3882 .calc_smb_size
= smb2_calc_size
,
3883 .is_status_pending
= smb2_is_status_pending
,
3884 .is_session_expired
= smb2_is_session_expired
,
3885 .oplock_response
= smb2_oplock_response
,
3886 .queryfs
= smb311_queryfs
,
3887 .mand_lock
= smb2_mand_lock
,
3888 .mand_unlock_range
= smb2_unlock_range
,
3889 .push_mand_locks
= smb2_push_mandatory_locks
,
3890 .get_lease_key
= smb2_get_lease_key
,
3891 .set_lease_key
= smb2_set_lease_key
,
3892 .new_lease_key
= smb2_new_lease_key
,
3893 .generate_signingkey
= generate_smb311signingkey
,
3894 .calc_signature
= smb3_calc_signature
,
3895 .set_integrity
= smb3_set_integrity
,
3896 .is_read_op
= smb21_is_read_op
,
3897 .set_oplock_level
= smb3_set_oplock_level
,
3898 .create_lease_buf
= smb3_create_lease_buf
,
3899 .parse_lease_buf
= smb3_parse_lease_buf
,
3900 .copychunk_range
= smb2_copychunk_range
,
3901 .duplicate_extents
= smb2_duplicate_extents
,
3902 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
3903 .wp_retry_size
= smb2_wp_retry_size
,
3904 .dir_needs_close
= smb2_dir_needs_close
,
3905 .fallocate
= smb3_fallocate
,
3906 .enum_snapshots
= smb3_enum_snapshots
,
3907 .init_transform_rq
= smb3_init_transform_rq
,
3908 .is_transform_hdr
= smb3_is_transform_hdr
,
3909 .receive_transform
= smb3_receive_transform
,
3910 .get_dfs_refer
= smb2_get_dfs_refer
,
3911 .select_sectype
= smb2_select_sectype
,
3912 #ifdef CONFIG_CIFS_XATTR
3913 .query_all_EAs
= smb2_query_eas
,
3914 .set_EA
= smb2_set_ea
,
3915 #endif /* CIFS_XATTR */
3916 #ifdef CONFIG_CIFS_ACL
3917 .get_acl
= get_smb2_acl
,
3918 .get_acl_by_fid
= get_smb2_acl_by_fid
,
3919 .set_acl
= set_smb2_acl
,
3920 #endif /* CIFS_ACL */
3921 .next_header
= smb2_next_header
,
3922 .ioctl_query_info
= smb2_ioctl_query_info
,
3925 struct smb_version_values smb20_values
= {
3926 .version_string
= SMB20_VERSION_STRING
,
3927 .protocol_id
= SMB20_PROT_ID
,
3928 .req_capabilities
= 0, /* MBZ */
3929 .large_lock_type
= 0,
3930 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3931 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3932 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3933 .header_size
= sizeof(struct smb2_sync_hdr
),
3934 .header_preamble_size
= 0,
3935 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3936 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3937 .lock_cmd
= SMB2_LOCK
,
3939 .cap_nt_find
= SMB2_NT_FIND
,
3940 .cap_large_files
= SMB2_LARGE_FILES
,
3941 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3942 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3943 .create_lease_size
= sizeof(struct create_lease
),
3946 struct smb_version_values smb21_values
= {
3947 .version_string
= SMB21_VERSION_STRING
,
3948 .protocol_id
= SMB21_PROT_ID
,
3949 .req_capabilities
= 0, /* MBZ on negotiate req until SMB3 dialect */
3950 .large_lock_type
= 0,
3951 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3952 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3953 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3954 .header_size
= sizeof(struct smb2_sync_hdr
),
3955 .header_preamble_size
= 0,
3956 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3957 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3958 .lock_cmd
= SMB2_LOCK
,
3960 .cap_nt_find
= SMB2_NT_FIND
,
3961 .cap_large_files
= SMB2_LARGE_FILES
,
3962 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3963 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3964 .create_lease_size
= sizeof(struct create_lease
),
3967 struct smb_version_values smb3any_values
= {
3968 .version_string
= SMB3ANY_VERSION_STRING
,
3969 .protocol_id
= SMB302_PROT_ID
, /* doesn't matter, send protocol array */
3970 .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
,
3971 .large_lock_type
= 0,
3972 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3973 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3974 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3975 .header_size
= sizeof(struct smb2_sync_hdr
),
3976 .header_preamble_size
= 0,
3977 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3978 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3979 .lock_cmd
= SMB2_LOCK
,
3981 .cap_nt_find
= SMB2_NT_FIND
,
3982 .cap_large_files
= SMB2_LARGE_FILES
,
3983 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3984 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3985 .create_lease_size
= sizeof(struct create_lease_v2
),
3988 struct smb_version_values smbdefault_values
= {
3989 .version_string
= SMBDEFAULT_VERSION_STRING
,
3990 .protocol_id
= SMB302_PROT_ID
, /* doesn't matter, send protocol array */
3991 .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
,
3992 .large_lock_type
= 0,
3993 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3994 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3995 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3996 .header_size
= sizeof(struct smb2_sync_hdr
),
3997 .header_preamble_size
= 0,
3998 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3999 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
4000 .lock_cmd
= SMB2_LOCK
,
4002 .cap_nt_find
= SMB2_NT_FIND
,
4003 .cap_large_files
= SMB2_LARGE_FILES
,
4004 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4005 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4006 .create_lease_size
= sizeof(struct create_lease_v2
),
4009 struct smb_version_values smb30_values
= {
4010 .version_string
= SMB30_VERSION_STRING
,
4011 .protocol_id
= SMB30_PROT_ID
,
4012 .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
,
4013 .large_lock_type
= 0,
4014 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
4015 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
4016 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
4017 .header_size
= sizeof(struct smb2_sync_hdr
),
4018 .header_preamble_size
= 0,
4019 .max_header_size
= MAX_SMB2_HDR_SIZE
,
4020 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
4021 .lock_cmd
= SMB2_LOCK
,
4023 .cap_nt_find
= SMB2_NT_FIND
,
4024 .cap_large_files
= SMB2_LARGE_FILES
,
4025 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4026 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4027 .create_lease_size
= sizeof(struct create_lease_v2
),
4030 struct smb_version_values smb302_values
= {
4031 .version_string
= SMB302_VERSION_STRING
,
4032 .protocol_id
= SMB302_PROT_ID
,
4033 .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
,
4034 .large_lock_type
= 0,
4035 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
4036 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
4037 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
4038 .header_size
= sizeof(struct smb2_sync_hdr
),
4039 .header_preamble_size
= 0,
4040 .max_header_size
= MAX_SMB2_HDR_SIZE
,
4041 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
4042 .lock_cmd
= SMB2_LOCK
,
4044 .cap_nt_find
= SMB2_NT_FIND
,
4045 .cap_large_files
= SMB2_LARGE_FILES
,
4046 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4047 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4048 .create_lease_size
= sizeof(struct create_lease_v2
),
4051 struct smb_version_values smb311_values
= {
4052 .version_string
= SMB311_VERSION_STRING
,
4053 .protocol_id
= SMB311_PROT_ID
,
4054 .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
,
4055 .large_lock_type
= 0,
4056 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
4057 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
4058 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
4059 .header_size
= sizeof(struct smb2_sync_hdr
),
4060 .header_preamble_size
= 0,
4061 .max_header_size
= MAX_SMB2_HDR_SIZE
,
4062 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
4063 .lock_cmd
= SMB2_LOCK
,
4065 .cap_nt_find
= SMB2_NT_FIND
,
4066 .cap_large_files
= SMB2_LARGE_FILES
,
4067 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4068 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4069 .create_lease_size
= sizeof(struct create_lease_v2
),