2 * SMB2 version specific operations
4 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
6 * This library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License v2 as published
8 * by the Free Software Foundation.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/pagemap.h>
21 #include <linux/vfs.h>
22 #include <linux/falloc.h>
23 #include <linux/scatterlist.h>
24 #include <linux/uuid.h>
25 #include <crypto/aead.h>
28 #include "smb2proto.h"
29 #include "cifsproto.h"
30 #include "cifs_debug.h"
31 #include "cifs_unicode.h"
32 #include "smb2status.h"
34 #include "cifs_ioctl.h"
35 #include "smbdirect.h"
37 /* Change credits for different ops and return the total number of credits */
39 change_conf(struct TCP_Server_Info
*server
)
41 server
->credits
+= server
->echo_credits
+ server
->oplock_credits
;
42 server
->oplock_credits
= server
->echo_credits
= 0;
43 switch (server
->credits
) {
47 server
->echoes
= false;
48 server
->oplocks
= false;
51 server
->echoes
= true;
52 server
->oplocks
= false;
53 server
->echo_credits
= 1;
56 server
->echoes
= true;
58 server
->oplocks
= true;
59 server
->oplock_credits
= 1;
61 server
->oplocks
= false;
63 server
->echo_credits
= 1;
65 server
->credits
-= server
->echo_credits
+ server
->oplock_credits
;
66 return server
->credits
+ server
->echo_credits
+ server
->oplock_credits
;
70 smb2_add_credits(struct TCP_Server_Info
*server
,
71 const struct cifs_credits
*credits
, const int optype
)
74 unsigned int add
= credits
->value
;
75 unsigned int instance
= credits
->instance
;
76 bool reconnect_detected
= false;
78 spin_lock(&server
->req_lock
);
79 val
= server
->ops
->get_credits_field(server
, optype
);
81 /* eg found case where write overlapping reconnect messed up credits */
82 if (((optype
& CIFS_OP_MASK
) == CIFS_NEG_OP
) && (*val
!= 0))
83 trace_smb3_reconnect_with_invalid_credits(server
->CurrentMid
,
84 server
->hostname
, *val
);
85 if ((instance
== 0) || (instance
== server
->reconnect_instance
))
88 reconnect_detected
= true;
91 *val
= 65000; /* Don't get near 64K credits, avoid srv bugs */
92 printk_once(KERN_WARNING
"server overflowed SMB3 credits\n");
95 if (server
->in_flight
== 0 && (optype
& CIFS_OP_MASK
) != CIFS_NEG_OP
)
96 rc
= change_conf(server
);
98 * Sometimes server returns 0 credits on oplock break ack - we need to
99 * rebalance credits in this case.
101 else if (server
->in_flight
> 0 && server
->oplock_credits
== 0 &&
103 if (server
->credits
> 1) {
105 server
->oplock_credits
++;
108 spin_unlock(&server
->req_lock
);
109 wake_up(&server
->request_q
);
111 if (reconnect_detected
)
112 cifs_dbg(FYI
, "trying to put %d credits from the old server instance %d\n",
115 if (server
->tcpStatus
== CifsNeedReconnect
116 || server
->tcpStatus
== CifsExiting
)
121 /* change_conf hasn't been executed */
124 cifs_dbg(VFS
, "Possible client or server bug - zero credits\n");
127 cifs_dbg(VFS
, "disabling echoes and oplocks\n");
130 cifs_dbg(FYI
, "disabling oplocks\n");
133 cifs_dbg(FYI
, "add %u credits total=%d\n", add
, rc
);
138 smb2_set_credits(struct TCP_Server_Info
*server
, const int val
)
140 spin_lock(&server
->req_lock
);
141 server
->credits
= val
;
143 server
->reconnect_instance
++;
144 spin_unlock(&server
->req_lock
);
145 /* don't log while holding the lock */
147 cifs_dbg(FYI
, "set credits to 1 due to smb2 reconnect\n");
151 smb2_get_credits_field(struct TCP_Server_Info
*server
, const int optype
)
155 return &server
->echo_credits
;
157 return &server
->oplock_credits
;
159 return &server
->credits
;
164 smb2_get_credits(struct mid_q_entry
*mid
)
166 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)mid
->resp_buf
;
168 if (mid
->mid_state
== MID_RESPONSE_RECEIVED
169 || mid
->mid_state
== MID_RESPONSE_MALFORMED
)
170 return le16_to_cpu(shdr
->CreditRequest
);
176 smb2_wait_mtu_credits(struct TCP_Server_Info
*server
, unsigned int size
,
177 unsigned int *num
, struct cifs_credits
*credits
)
180 unsigned int scredits
;
182 spin_lock(&server
->req_lock
);
184 if (server
->credits
<= 0) {
185 spin_unlock(&server
->req_lock
);
186 cifs_num_waiters_inc(server
);
187 rc
= wait_event_killable(server
->request_q
,
188 has_credits(server
, &server
->credits
, 1));
189 cifs_num_waiters_dec(server
);
192 spin_lock(&server
->req_lock
);
194 if (server
->tcpStatus
== CifsExiting
) {
195 spin_unlock(&server
->req_lock
);
199 scredits
= server
->credits
;
200 /* can deadlock with reopen */
202 *num
= SMB2_MAX_BUFFER_SIZE
;
204 credits
->instance
= 0;
208 /* leave some credits for reopen and other ops */
210 *num
= min_t(unsigned int, size
,
211 scredits
* SMB2_MAX_BUFFER_SIZE
);
214 DIV_ROUND_UP(*num
, SMB2_MAX_BUFFER_SIZE
);
215 credits
->instance
= server
->reconnect_instance
;
216 server
->credits
-= credits
->value
;
221 spin_unlock(&server
->req_lock
);
226 smb2_adjust_credits(struct TCP_Server_Info
*server
,
227 struct cifs_credits
*credits
,
228 const unsigned int payload_size
)
230 int new_val
= DIV_ROUND_UP(payload_size
, SMB2_MAX_BUFFER_SIZE
);
232 if (!credits
->value
|| credits
->value
== new_val
)
235 if (credits
->value
< new_val
) {
236 WARN_ONCE(1, "request has less credits (%d) than required (%d)",
237 credits
->value
, new_val
);
241 spin_lock(&server
->req_lock
);
243 if (server
->reconnect_instance
!= credits
->instance
) {
244 spin_unlock(&server
->req_lock
);
245 cifs_dbg(VFS
, "trying to return %d credits to old session\n",
246 credits
->value
- new_val
);
250 server
->credits
+= credits
->value
- new_val
;
251 spin_unlock(&server
->req_lock
);
252 wake_up(&server
->request_q
);
253 credits
->value
= new_val
;
258 smb2_get_next_mid(struct TCP_Server_Info
*server
)
261 /* for SMB2 we need the current value */
262 spin_lock(&GlobalMid_Lock
);
263 mid
= server
->CurrentMid
++;
264 spin_unlock(&GlobalMid_Lock
);
269 smb2_revert_current_mid(struct TCP_Server_Info
*server
, const unsigned int val
)
271 spin_lock(&GlobalMid_Lock
);
272 if (server
->CurrentMid
>= val
)
273 server
->CurrentMid
-= val
;
274 spin_unlock(&GlobalMid_Lock
);
277 static struct mid_q_entry
*
278 smb2_find_mid(struct TCP_Server_Info
*server
, char *buf
)
280 struct mid_q_entry
*mid
;
281 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
282 __u64 wire_mid
= le64_to_cpu(shdr
->MessageId
);
284 if (shdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
) {
285 cifs_dbg(VFS
, "encrypted frame parsing not supported yet");
289 spin_lock(&GlobalMid_Lock
);
290 list_for_each_entry(mid
, &server
->pending_mid_q
, qhead
) {
291 if ((mid
->mid
== wire_mid
) &&
292 (mid
->mid_state
== MID_REQUEST_SUBMITTED
) &&
293 (mid
->command
== shdr
->Command
)) {
294 kref_get(&mid
->refcount
);
295 spin_unlock(&GlobalMid_Lock
);
299 spin_unlock(&GlobalMid_Lock
);
304 smb2_dump_detail(void *buf
, struct TCP_Server_Info
*server
)
306 #ifdef CONFIG_CIFS_DEBUG2
307 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
309 cifs_dbg(VFS
, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
310 shdr
->Command
, shdr
->Status
, shdr
->Flags
, shdr
->MessageId
,
312 cifs_dbg(VFS
, "smb buf %p len %u\n", buf
,
313 server
->ops
->calc_smb_size(buf
, server
));
318 smb2_need_neg(struct TCP_Server_Info
*server
)
320 return server
->max_read
== 0;
324 smb2_negotiate(const unsigned int xid
, struct cifs_ses
*ses
)
327 ses
->server
->CurrentMid
= 0;
328 rc
= SMB2_negotiate(xid
, ses
);
329 /* BB we probably don't need to retry with modern servers */
336 smb2_negotiate_wsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
338 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
341 /* start with specified wsize, or default */
342 wsize
= volume_info
->wsize
? volume_info
->wsize
: CIFS_DEFAULT_IOSIZE
;
343 wsize
= min_t(unsigned int, wsize
, server
->max_write
);
344 #ifdef CONFIG_CIFS_SMB_DIRECT
347 wsize
= min_t(unsigned int,
348 wsize
, server
->smbd_conn
->max_fragmented_send_size
);
350 wsize
= min_t(unsigned int,
351 wsize
, server
->smbd_conn
->max_readwrite_size
);
354 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
355 wsize
= min_t(unsigned int, wsize
, SMB2_MAX_BUFFER_SIZE
);
361 smb3_negotiate_wsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
363 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
366 /* start with specified wsize, or default */
367 wsize
= volume_info
->wsize
? volume_info
->wsize
: SMB3_DEFAULT_IOSIZE
;
368 wsize
= min_t(unsigned int, wsize
, server
->max_write
);
369 #ifdef CONFIG_CIFS_SMB_DIRECT
372 wsize
= min_t(unsigned int,
373 wsize
, server
->smbd_conn
->max_fragmented_send_size
);
375 wsize
= min_t(unsigned int,
376 wsize
, server
->smbd_conn
->max_readwrite_size
);
379 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
380 wsize
= min_t(unsigned int, wsize
, SMB2_MAX_BUFFER_SIZE
);
386 smb2_negotiate_rsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
388 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
391 /* start with specified rsize, or default */
392 rsize
= volume_info
->rsize
? volume_info
->rsize
: CIFS_DEFAULT_IOSIZE
;
393 rsize
= min_t(unsigned int, rsize
, server
->max_read
);
394 #ifdef CONFIG_CIFS_SMB_DIRECT
397 rsize
= min_t(unsigned int,
398 rsize
, server
->smbd_conn
->max_fragmented_recv_size
);
400 rsize
= min_t(unsigned int,
401 rsize
, server
->smbd_conn
->max_readwrite_size
);
405 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
406 rsize
= min_t(unsigned int, rsize
, SMB2_MAX_BUFFER_SIZE
);
412 smb3_negotiate_rsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
414 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
417 /* start with specified rsize, or default */
418 rsize
= volume_info
->rsize
? volume_info
->rsize
: SMB3_DEFAULT_IOSIZE
;
419 rsize
= min_t(unsigned int, rsize
, server
->max_read
);
420 #ifdef CONFIG_CIFS_SMB_DIRECT
423 rsize
= min_t(unsigned int,
424 rsize
, server
->smbd_conn
->max_fragmented_recv_size
);
426 rsize
= min_t(unsigned int,
427 rsize
, server
->smbd_conn
->max_readwrite_size
);
431 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
432 rsize
= min_t(unsigned int, rsize
, SMB2_MAX_BUFFER_SIZE
);
438 parse_server_interfaces(struct network_interface_info_ioctl_rsp
*buf
,
440 struct cifs_server_iface
**iface_list
,
443 struct network_interface_info_ioctl_rsp
*p
;
444 struct sockaddr_in
*addr4
;
445 struct sockaddr_in6
*addr6
;
446 struct iface_info_ipv4
*p4
;
447 struct iface_info_ipv6
*p6
;
448 struct cifs_server_iface
*info
;
458 * Fist pass: count and sanity check
461 bytes_left
= buf_len
;
463 while (bytes_left
>= sizeof(*p
)) {
465 next
= le32_to_cpu(p
->Next
);
467 bytes_left
-= sizeof(*p
);
470 p
= (struct network_interface_info_ioctl_rsp
*)((u8
*)p
+next
);
475 cifs_dbg(VFS
, "%s: malformed interface info\n", __func__
);
480 if (bytes_left
|| p
->Next
)
481 cifs_dbg(VFS
, "%s: incomplete interface info\n", __func__
);
485 * Second pass: extract info to internal structure
488 *iface_list
= kcalloc(nb_iface
, sizeof(**iface_list
), GFP_KERNEL
);
495 bytes_left
= buf_len
;
497 while (bytes_left
>= sizeof(*p
)) {
498 info
->speed
= le64_to_cpu(p
->LinkSpeed
);
499 info
->rdma_capable
= le32_to_cpu(p
->Capability
& RDMA_CAPABLE
);
500 info
->rss_capable
= le32_to_cpu(p
->Capability
& RSS_CAPABLE
);
502 cifs_dbg(FYI
, "%s: adding iface %zu\n", __func__
, *iface_count
);
503 cifs_dbg(FYI
, "%s: speed %zu bps\n", __func__
, info
->speed
);
504 cifs_dbg(FYI
, "%s: capabilities 0x%08x\n", __func__
,
505 le32_to_cpu(p
->Capability
));
509 * The kernel and wire socket structures have the same
510 * layout and use network byte order but make the
511 * conversion explicit in case either one changes.
514 addr4
= (struct sockaddr_in
*)&info
->sockaddr
;
515 p4
= (struct iface_info_ipv4
*)p
->Buffer
;
516 addr4
->sin_family
= AF_INET
;
517 memcpy(&addr4
->sin_addr
, &p4
->IPv4Address
, 4);
519 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
520 addr4
->sin_port
= cpu_to_be16(CIFS_PORT
);
522 cifs_dbg(FYI
, "%s: ipv4 %pI4\n", __func__
,
526 addr6
= (struct sockaddr_in6
*)&info
->sockaddr
;
527 p6
= (struct iface_info_ipv6
*)p
->Buffer
;
528 addr6
->sin6_family
= AF_INET6
;
529 memcpy(&addr6
->sin6_addr
, &p6
->IPv6Address
, 16);
531 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
532 addr6
->sin6_flowinfo
= 0;
533 addr6
->sin6_scope_id
= 0;
534 addr6
->sin6_port
= cpu_to_be16(CIFS_PORT
);
536 cifs_dbg(FYI
, "%s: ipv6 %pI6\n", __func__
,
541 "%s: skipping unsupported socket family\n",
549 next
= le32_to_cpu(p
->Next
);
552 p
= (struct network_interface_info_ioctl_rsp
*)((u8
*)p
+next
);
572 SMB3_request_interfaces(const unsigned int xid
, struct cifs_tcon
*tcon
)
575 unsigned int ret_data_len
= 0;
576 struct network_interface_info_ioctl_rsp
*out_buf
= NULL
;
577 struct cifs_server_iface
*iface_list
;
579 struct cifs_ses
*ses
= tcon
->ses
;
581 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
582 FSCTL_QUERY_NETWORK_INTERFACE_INFO
, true /* is_fsctl */,
583 NULL
/* no data input */, 0 /* no data input */,
584 CIFSMaxBufSize
, (char **)&out_buf
, &ret_data_len
);
585 if (rc
== -EOPNOTSUPP
) {
587 "server does not support query network interfaces\n");
589 } else if (rc
!= 0) {
590 cifs_dbg(VFS
, "error %d on ioctl to get interface list\n", rc
);
594 rc
= parse_server_interfaces(out_buf
, ret_data_len
,
595 &iface_list
, &iface_count
);
599 spin_lock(&ses
->iface_lock
);
600 kfree(ses
->iface_list
);
601 ses
->iface_list
= iface_list
;
602 ses
->iface_count
= iface_count
;
603 ses
->iface_last_update
= jiffies
;
604 spin_unlock(&ses
->iface_lock
);
612 smb2_close_cached_fid(struct kref
*ref
)
614 struct cached_fid
*cfid
= container_of(ref
, struct cached_fid
,
617 if (cfid
->is_valid
) {
618 cifs_dbg(FYI
, "clear cached root file handle\n");
619 SMB2_close(0, cfid
->tcon
, cfid
->fid
->persistent_fid
,
620 cfid
->fid
->volatile_fid
);
621 cfid
->is_valid
= false;
622 cfid
->file_all_info_is_valid
= false;
626 void close_shroot(struct cached_fid
*cfid
)
628 mutex_lock(&cfid
->fid_mutex
);
629 kref_put(&cfid
->refcount
, smb2_close_cached_fid
);
630 mutex_unlock(&cfid
->fid_mutex
);
634 smb2_cached_lease_break(struct work_struct
*work
)
636 struct cached_fid
*cfid
= container_of(work
,
637 struct cached_fid
, lease_break
);
643 * Open the directory at the root of a share
645 int open_shroot(unsigned int xid
, struct cifs_tcon
*tcon
, struct cifs_fid
*pfid
)
647 struct cifs_ses
*ses
= tcon
->ses
;
648 struct TCP_Server_Info
*server
= ses
->server
;
649 struct cifs_open_parms oparms
;
650 struct smb2_create_rsp
*o_rsp
= NULL
;
651 struct smb2_query_info_rsp
*qi_rsp
= NULL
;
653 struct smb_rqst rqst
[2];
654 struct kvec rsp_iov
[2];
655 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
656 struct kvec qi_iov
[1];
658 __le16 utf16_path
= 0; /* Null - since an open of top of share */
659 u8 oplock
= SMB2_OPLOCK_LEVEL_II
;
661 mutex_lock(&tcon
->crfid
.fid_mutex
);
662 if (tcon
->crfid
.is_valid
) {
663 cifs_dbg(FYI
, "found a cached root file handle\n");
664 memcpy(pfid
, tcon
->crfid
.fid
, sizeof(struct cifs_fid
));
665 kref_get(&tcon
->crfid
.refcount
);
666 mutex_unlock(&tcon
->crfid
.fid_mutex
);
670 if (smb3_encryption_required(tcon
))
671 flags
|= CIFS_TRANSFORM_REQ
;
673 memset(rqst
, 0, sizeof(rqst
));
674 resp_buftype
[0] = resp_buftype
[1] = CIFS_NO_BUFFER
;
675 memset(rsp_iov
, 0, sizeof(rsp_iov
));
678 memset(&open_iov
, 0, sizeof(open_iov
));
679 rqst
[0].rq_iov
= open_iov
;
680 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
683 oparms
.create_options
= 0;
684 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
685 oparms
.disposition
= FILE_OPEN
;
687 oparms
.reconnect
= false;
689 rc
= SMB2_open_init(tcon
, &rqst
[0], &oplock
, &oparms
, &utf16_path
);
692 smb2_set_next_command(tcon
, &rqst
[0]);
694 memset(&qi_iov
, 0, sizeof(qi_iov
));
695 rqst
[1].rq_iov
= qi_iov
;
698 rc
= SMB2_query_info_init(tcon
, &rqst
[1], COMPOUND_FID
,
699 COMPOUND_FID
, FILE_ALL_INFORMATION
,
701 sizeof(struct smb2_file_all_info
) +
702 PATH_MAX
* 2, 0, NULL
);
706 smb2_set_related(&rqst
[1]);
709 * We do not hold the lock for the open because in case
710 * SMB2_open needs to reconnect, it will end up calling
711 * cifs_mark_open_files_invalid() which takes the lock again
712 * thus causing a deadlock
715 mutex_unlock(&tcon
->crfid
.fid_mutex
);
716 rc
= compound_send_recv(xid
, ses
, flags
, 2, rqst
,
717 resp_buftype
, rsp_iov
);
718 mutex_lock(&tcon
->crfid
.fid_mutex
);
721 * Now we need to check again as the cached root might have
722 * been successfully re-opened from a concurrent process
725 if (tcon
->crfid
.is_valid
) {
726 /* work was already done */
728 /* stash fids for close() later */
729 struct cifs_fid fid
= {
730 .persistent_fid
= pfid
->persistent_fid
,
731 .volatile_fid
= pfid
->volatile_fid
,
735 * caller expects this func to set pfid to a valid
736 * cached root, so we copy the existing one and get a
739 memcpy(pfid
, tcon
->crfid
.fid
, sizeof(*pfid
));
740 kref_get(&tcon
->crfid
.refcount
);
742 mutex_unlock(&tcon
->crfid
.fid_mutex
);
745 /* close extra handle outside of crit sec */
746 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
751 /* Cached root is still invalid, continue normaly */
756 o_rsp
= (struct smb2_create_rsp
*)rsp_iov
[0].iov_base
;
757 oparms
.fid
->persistent_fid
= o_rsp
->PersistentFileId
;
758 oparms
.fid
->volatile_fid
= o_rsp
->VolatileFileId
;
759 #ifdef CONFIG_CIFS_DEBUG2
760 oparms
.fid
->mid
= le64_to_cpu(o_rsp
->sync_hdr
.MessageId
);
761 #endif /* CIFS_DEBUG2 */
763 memcpy(tcon
->crfid
.fid
, pfid
, sizeof(struct cifs_fid
));
764 tcon
->crfid
.tcon
= tcon
;
765 tcon
->crfid
.is_valid
= true;
766 kref_init(&tcon
->crfid
.refcount
);
768 if (o_rsp
->OplockLevel
== SMB2_OPLOCK_LEVEL_LEASE
) {
769 kref_get(&tcon
->crfid
.refcount
);
770 oplock
= smb2_parse_lease_state(server
, o_rsp
,
772 oparms
.fid
->lease_key
);
776 qi_rsp
= (struct smb2_query_info_rsp
*)rsp_iov
[1].iov_base
;
777 if (le32_to_cpu(qi_rsp
->OutputBufferLength
) < sizeof(struct smb2_file_all_info
))
779 if (!smb2_validate_and_copy_iov(
780 le16_to_cpu(qi_rsp
->OutputBufferOffset
),
781 sizeof(struct smb2_file_all_info
),
782 &rsp_iov
[1], sizeof(struct smb2_file_all_info
),
783 (char *)&tcon
->crfid
.file_all_info
))
784 tcon
->crfid
.file_all_info_is_valid
= 1;
787 mutex_unlock(&tcon
->crfid
.fid_mutex
);
789 SMB2_open_free(&rqst
[0]);
790 SMB2_query_info_free(&rqst
[1]);
791 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
792 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
797 smb3_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
800 __le16 srch_path
= 0; /* Null - open root of share */
801 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
802 struct cifs_open_parms oparms
;
804 bool no_cached_open
= tcon
->nohandlecache
;
807 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
808 oparms
.disposition
= FILE_OPEN
;
809 oparms
.create_options
= 0;
811 oparms
.reconnect
= false;
814 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
,
817 rc
= open_shroot(xid
, tcon
, &fid
);
822 SMB3_request_interfaces(xid
, tcon
);
824 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
825 FS_ATTRIBUTE_INFORMATION
);
826 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
827 FS_DEVICE_INFORMATION
);
828 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
829 FS_VOLUME_INFORMATION
);
830 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
831 FS_SECTOR_SIZE_INFORMATION
); /* SMB3 specific */
833 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
835 close_shroot(&tcon
->crfid
);
841 smb2_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
844 __le16 srch_path
= 0; /* Null - open root of share */
845 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
846 struct cifs_open_parms oparms
;
850 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
851 oparms
.disposition
= FILE_OPEN
;
852 oparms
.create_options
= 0;
854 oparms
.reconnect
= false;
856 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
, NULL
);
860 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
861 FS_ATTRIBUTE_INFORMATION
);
862 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
863 FS_DEVICE_INFORMATION
);
864 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
869 smb2_is_path_accessible(const unsigned int xid
, struct cifs_tcon
*tcon
,
870 struct cifs_sb_info
*cifs_sb
, const char *full_path
)
874 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
875 struct cifs_open_parms oparms
;
878 if ((*full_path
== 0) && tcon
->crfid
.is_valid
)
881 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
886 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
887 oparms
.disposition
= FILE_OPEN
;
888 if (backup_cred(cifs_sb
))
889 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
891 oparms
.create_options
= 0;
893 oparms
.reconnect
= false;
895 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
, NULL
);
901 rc
= SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
907 smb2_get_srv_inum(const unsigned int xid
, struct cifs_tcon
*tcon
,
908 struct cifs_sb_info
*cifs_sb
, const char *full_path
,
909 u64
*uniqueid
, FILE_ALL_INFO
*data
)
911 *uniqueid
= le64_to_cpu(data
->IndexNumber
);
916 smb2_query_file_info(const unsigned int xid
, struct cifs_tcon
*tcon
,
917 struct cifs_fid
*fid
, FILE_ALL_INFO
*data
)
920 struct smb2_file_all_info
*smb2_data
;
922 smb2_data
= kzalloc(sizeof(struct smb2_file_all_info
) + PATH_MAX
* 2,
924 if (smb2_data
== NULL
)
927 rc
= SMB2_query_info(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
,
930 move_smb2_info_to_cifs(data
, smb2_data
);
935 #ifdef CONFIG_CIFS_XATTR
937 move_smb2_ea_to_cifs(char *dst
, size_t dst_size
,
938 struct smb2_file_full_ea_info
*src
, size_t src_size
,
939 const unsigned char *ea_name
)
942 unsigned int ea_name_len
= ea_name
? strlen(ea_name
) : 0;
944 size_t buf_size
= dst_size
;
945 size_t name_len
, value_len
, user_name_len
;
947 while (src_size
> 0) {
948 name
= &src
->ea_data
[0];
949 name_len
= (size_t)src
->ea_name_length
;
950 value
= &src
->ea_data
[src
->ea_name_length
+ 1];
951 value_len
= (size_t)le16_to_cpu(src
->ea_value_length
);
957 if (src_size
< 8 + name_len
+ 1 + value_len
) {
958 cifs_dbg(FYI
, "EA entry goes beyond length of list\n");
964 if (ea_name_len
== name_len
&&
965 memcmp(ea_name
, name
, name_len
) == 0) {
969 if (dst_size
< value_len
) {
973 memcpy(dst
, value
, value_len
);
977 /* 'user.' plus a terminating null */
978 user_name_len
= 5 + 1 + name_len
;
981 /* skip copy - calc size only */
983 } else if (dst_size
>= user_name_len
) {
984 dst_size
-= user_name_len
;
985 memcpy(dst
, "user.", 5);
987 memcpy(dst
, src
->ea_data
, name_len
);
993 /* stop before overrun buffer */
999 if (!src
->next_entry_offset
)
1002 if (src_size
< le32_to_cpu(src
->next_entry_offset
)) {
1003 /* stop before overrun buffer */
1007 src_size
-= le32_to_cpu(src
->next_entry_offset
);
1008 src
= (void *)((char *)src
+
1009 le32_to_cpu(src
->next_entry_offset
));
1012 /* didn't find the named attribute */
1021 smb2_query_eas(const unsigned int xid
, struct cifs_tcon
*tcon
,
1022 const unsigned char *path
, const unsigned char *ea_name
,
1023 char *ea_data
, size_t buf_size
,
1024 struct cifs_sb_info
*cifs_sb
)
1028 struct kvec rsp_iov
= {NULL
, 0};
1029 int buftype
= CIFS_NO_BUFFER
;
1030 struct smb2_query_info_rsp
*rsp
;
1031 struct smb2_file_full_ea_info
*info
= NULL
;
1033 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
1037 rc
= smb2_query_info_compound(xid
, tcon
, utf16_path
,
1039 FILE_FULL_EA_INFORMATION
,
1042 MAX_SMB2_CREATE_RESPONSE_SIZE
-
1043 MAX_SMB2_CLOSE_RESPONSE_SIZE
,
1044 &rsp_iov
, &buftype
, cifs_sb
);
1047 * If ea_name is NULL (listxattr) and there are no EAs,
1048 * return 0 as it's not an error. Otherwise, the specified
1049 * ea_name was not found.
1051 if (!ea_name
&& rc
== -ENODATA
)
1056 rsp
= (struct smb2_query_info_rsp
*)rsp_iov
.iov_base
;
1057 rc
= smb2_validate_iov(le16_to_cpu(rsp
->OutputBufferOffset
),
1058 le32_to_cpu(rsp
->OutputBufferLength
),
1060 sizeof(struct smb2_file_full_ea_info
));
1064 info
= (struct smb2_file_full_ea_info
*)(
1065 le16_to_cpu(rsp
->OutputBufferOffset
) + (char *)rsp
);
1066 rc
= move_smb2_ea_to_cifs(ea_data
, buf_size
, info
,
1067 le32_to_cpu(rsp
->OutputBufferLength
), ea_name
);
1071 free_rsp_buf(buftype
, rsp_iov
.iov_base
);
1077 smb2_set_ea(const unsigned int xid
, struct cifs_tcon
*tcon
,
1078 const char *path
, const char *ea_name
, const void *ea_value
,
1079 const __u16 ea_value_len
, const struct nls_table
*nls_codepage
,
1080 struct cifs_sb_info
*cifs_sb
)
1082 struct cifs_ses
*ses
= tcon
->ses
;
1083 __le16
*utf16_path
= NULL
;
1084 int ea_name_len
= strlen(ea_name
);
1087 struct smb_rqst rqst
[3];
1088 int resp_buftype
[3];
1089 struct kvec rsp_iov
[3];
1090 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
1091 struct cifs_open_parms oparms
;
1092 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1093 struct cifs_fid fid
;
1094 struct kvec si_iov
[SMB2_SET_INFO_IOV_SIZE
];
1095 unsigned int size
[1];
1097 struct smb2_file_full_ea_info
*ea
= NULL
;
1098 struct kvec close_iov
[1];
1101 if (smb3_encryption_required(tcon
))
1102 flags
|= CIFS_TRANSFORM_REQ
;
1104 if (ea_name_len
> 255)
1107 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
1111 memset(rqst
, 0, sizeof(rqst
));
1112 resp_buftype
[0] = resp_buftype
[1] = resp_buftype
[2] = CIFS_NO_BUFFER
;
1113 memset(rsp_iov
, 0, sizeof(rsp_iov
));
1115 if (ses
->server
->ops
->query_all_EAs
) {
1117 rc
= ses
->server
->ops
->query_all_EAs(xid
, tcon
, path
,
1126 memset(&open_iov
, 0, sizeof(open_iov
));
1127 rqst
[0].rq_iov
= open_iov
;
1128 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
1130 memset(&oparms
, 0, sizeof(oparms
));
1132 oparms
.desired_access
= FILE_WRITE_EA
;
1133 oparms
.disposition
= FILE_OPEN
;
1134 if (backup_cred(cifs_sb
))
1135 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
1137 oparms
.create_options
= 0;
1139 oparms
.reconnect
= false;
1141 rc
= SMB2_open_init(tcon
, &rqst
[0], &oplock
, &oparms
, utf16_path
);
1144 smb2_set_next_command(tcon
, &rqst
[0]);
1148 memset(&si_iov
, 0, sizeof(si_iov
));
1149 rqst
[1].rq_iov
= si_iov
;
1150 rqst
[1].rq_nvec
= 1;
1152 len
= sizeof(ea
) + ea_name_len
+ ea_value_len
+ 1;
1153 ea
= kzalloc(len
, GFP_KERNEL
);
1159 ea
->ea_name_length
= ea_name_len
;
1160 ea
->ea_value_length
= cpu_to_le16(ea_value_len
);
1161 memcpy(ea
->ea_data
, ea_name
, ea_name_len
+ 1);
1162 memcpy(ea
->ea_data
+ ea_name_len
+ 1, ea_value
, ea_value_len
);
1167 rc
= SMB2_set_info_init(tcon
, &rqst
[1], COMPOUND_FID
,
1168 COMPOUND_FID
, current
->tgid
,
1169 FILE_FULL_EA_INFORMATION
,
1170 SMB2_O_INFO_FILE
, 0, data
, size
);
1171 smb2_set_next_command(tcon
, &rqst
[1]);
1172 smb2_set_related(&rqst
[1]);
1176 memset(&close_iov
, 0, sizeof(close_iov
));
1177 rqst
[2].rq_iov
= close_iov
;
1178 rqst
[2].rq_nvec
= 1;
1179 rc
= SMB2_close_init(tcon
, &rqst
[2], COMPOUND_FID
, COMPOUND_FID
);
1180 smb2_set_related(&rqst
[2]);
1182 rc
= compound_send_recv(xid
, ses
, flags
, 3, rqst
,
1183 resp_buftype
, rsp_iov
);
1188 SMB2_open_free(&rqst
[0]);
1189 SMB2_set_info_free(&rqst
[1]);
1190 SMB2_close_free(&rqst
[2]);
1191 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
1192 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
1193 free_rsp_buf(resp_buftype
[2], rsp_iov
[2].iov_base
);
1199 smb2_can_echo(struct TCP_Server_Info
*server
)
1201 return server
->echoes
;
1205 smb2_clear_stats(struct cifs_tcon
*tcon
)
1208 for (i
= 0; i
< NUMBER_OF_SMB2_COMMANDS
; i
++) {
1209 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_sent
[i
], 0);
1210 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_failed
[i
], 0);
1215 smb2_dump_share_caps(struct seq_file
*m
, struct cifs_tcon
*tcon
)
1217 seq_puts(m
, "\n\tShare Capabilities:");
1218 if (tcon
->capabilities
& SMB2_SHARE_CAP_DFS
)
1219 seq_puts(m
, " DFS,");
1220 if (tcon
->capabilities
& SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY
)
1221 seq_puts(m
, " CONTINUOUS AVAILABILITY,");
1222 if (tcon
->capabilities
& SMB2_SHARE_CAP_SCALEOUT
)
1223 seq_puts(m
, " SCALEOUT,");
1224 if (tcon
->capabilities
& SMB2_SHARE_CAP_CLUSTER
)
1225 seq_puts(m
, " CLUSTER,");
1226 if (tcon
->capabilities
& SMB2_SHARE_CAP_ASYMMETRIC
)
1227 seq_puts(m
, " ASYMMETRIC,");
1228 if (tcon
->capabilities
== 0)
1229 seq_puts(m
, " None");
1230 if (tcon
->ss_flags
& SSINFO_FLAGS_ALIGNED_DEVICE
)
1231 seq_puts(m
, " Aligned,");
1232 if (tcon
->ss_flags
& SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE
)
1233 seq_puts(m
, " Partition Aligned,");
1234 if (tcon
->ss_flags
& SSINFO_FLAGS_NO_SEEK_PENALTY
)
1235 seq_puts(m
, " SSD,");
1236 if (tcon
->ss_flags
& SSINFO_FLAGS_TRIM_ENABLED
)
1237 seq_puts(m
, " TRIM-support,");
1239 seq_printf(m
, "\tShare Flags: 0x%x", tcon
->share_flags
);
1240 seq_printf(m
, "\n\ttid: 0x%x", tcon
->tid
);
1241 if (tcon
->perf_sector_size
)
1242 seq_printf(m
, "\tOptimal sector size: 0x%x",
1243 tcon
->perf_sector_size
);
1244 seq_printf(m
, "\tMaximal Access: 0x%x", tcon
->maximal_access
);
1248 smb2_print_stats(struct seq_file
*m
, struct cifs_tcon
*tcon
)
1250 atomic_t
*sent
= tcon
->stats
.smb2_stats
.smb2_com_sent
;
1251 atomic_t
*failed
= tcon
->stats
.smb2_stats
.smb2_com_failed
;
1254 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1255 * totals (requests sent) since those SMBs are per-session not per tcon
1257 seq_printf(m
, "\nBytes read: %llu Bytes written: %llu",
1258 (long long)(tcon
->bytes_read
),
1259 (long long)(tcon
->bytes_written
));
1260 seq_printf(m
, "\nOpen files: %d total (local), %d open on server",
1261 atomic_read(&tcon
->num_local_opens
),
1262 atomic_read(&tcon
->num_remote_opens
));
1263 seq_printf(m
, "\nTreeConnects: %d total %d failed",
1264 atomic_read(&sent
[SMB2_TREE_CONNECT_HE
]),
1265 atomic_read(&failed
[SMB2_TREE_CONNECT_HE
]));
1266 seq_printf(m
, "\nTreeDisconnects: %d total %d failed",
1267 atomic_read(&sent
[SMB2_TREE_DISCONNECT_HE
]),
1268 atomic_read(&failed
[SMB2_TREE_DISCONNECT_HE
]));
1269 seq_printf(m
, "\nCreates: %d total %d failed",
1270 atomic_read(&sent
[SMB2_CREATE_HE
]),
1271 atomic_read(&failed
[SMB2_CREATE_HE
]));
1272 seq_printf(m
, "\nCloses: %d total %d failed",
1273 atomic_read(&sent
[SMB2_CLOSE_HE
]),
1274 atomic_read(&failed
[SMB2_CLOSE_HE
]));
1275 seq_printf(m
, "\nFlushes: %d total %d failed",
1276 atomic_read(&sent
[SMB2_FLUSH_HE
]),
1277 atomic_read(&failed
[SMB2_FLUSH_HE
]));
1278 seq_printf(m
, "\nReads: %d total %d failed",
1279 atomic_read(&sent
[SMB2_READ_HE
]),
1280 atomic_read(&failed
[SMB2_READ_HE
]));
1281 seq_printf(m
, "\nWrites: %d total %d failed",
1282 atomic_read(&sent
[SMB2_WRITE_HE
]),
1283 atomic_read(&failed
[SMB2_WRITE_HE
]));
1284 seq_printf(m
, "\nLocks: %d total %d failed",
1285 atomic_read(&sent
[SMB2_LOCK_HE
]),
1286 atomic_read(&failed
[SMB2_LOCK_HE
]));
1287 seq_printf(m
, "\nIOCTLs: %d total %d failed",
1288 atomic_read(&sent
[SMB2_IOCTL_HE
]),
1289 atomic_read(&failed
[SMB2_IOCTL_HE
]));
1290 seq_printf(m
, "\nQueryDirectories: %d total %d failed",
1291 atomic_read(&sent
[SMB2_QUERY_DIRECTORY_HE
]),
1292 atomic_read(&failed
[SMB2_QUERY_DIRECTORY_HE
]));
1293 seq_printf(m
, "\nChangeNotifies: %d total %d failed",
1294 atomic_read(&sent
[SMB2_CHANGE_NOTIFY_HE
]),
1295 atomic_read(&failed
[SMB2_CHANGE_NOTIFY_HE
]));
1296 seq_printf(m
, "\nQueryInfos: %d total %d failed",
1297 atomic_read(&sent
[SMB2_QUERY_INFO_HE
]),
1298 atomic_read(&failed
[SMB2_QUERY_INFO_HE
]));
1299 seq_printf(m
, "\nSetInfos: %d total %d failed",
1300 atomic_read(&sent
[SMB2_SET_INFO_HE
]),
1301 atomic_read(&failed
[SMB2_SET_INFO_HE
]));
1302 seq_printf(m
, "\nOplockBreaks: %d sent %d failed",
1303 atomic_read(&sent
[SMB2_OPLOCK_BREAK_HE
]),
1304 atomic_read(&failed
[SMB2_OPLOCK_BREAK_HE
]));
1308 smb2_set_fid(struct cifsFileInfo
*cfile
, struct cifs_fid
*fid
, __u32 oplock
)
1310 struct cifsInodeInfo
*cinode
= CIFS_I(d_inode(cfile
->dentry
));
1311 struct TCP_Server_Info
*server
= tlink_tcon(cfile
->tlink
)->ses
->server
;
1313 cfile
->fid
.persistent_fid
= fid
->persistent_fid
;
1314 cfile
->fid
.volatile_fid
= fid
->volatile_fid
;
1315 #ifdef CONFIG_CIFS_DEBUG2
1316 cfile
->fid
.mid
= fid
->mid
;
1317 #endif /* CIFS_DEBUG2 */
1318 server
->ops
->set_oplock_level(cinode
, oplock
, fid
->epoch
,
1320 cinode
->can_cache_brlcks
= CIFS_CACHE_WRITE(cinode
);
1321 memcpy(cfile
->fid
.create_guid
, fid
->create_guid
, 16);
1325 smb2_close_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
1326 struct cifs_fid
*fid
)
1328 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1332 SMB2_request_res_key(const unsigned int xid
, struct cifs_tcon
*tcon
,
1333 u64 persistent_fid
, u64 volatile_fid
,
1334 struct copychunk_ioctl
*pcchunk
)
1337 unsigned int ret_data_len
;
1338 struct resume_key_req
*res_key
;
1340 rc
= SMB2_ioctl(xid
, tcon
, persistent_fid
, volatile_fid
,
1341 FSCTL_SRV_REQUEST_RESUME_KEY
, true /* is_fsctl */,
1342 NULL
, 0 /* no input */, CIFSMaxBufSize
,
1343 (char **)&res_key
, &ret_data_len
);
1346 cifs_dbg(VFS
, "refcpy ioctl error %d getting resume key\n", rc
);
1347 goto req_res_key_exit
;
1349 if (ret_data_len
< sizeof(struct resume_key_req
)) {
1350 cifs_dbg(VFS
, "Invalid refcopy resume key length\n");
1352 goto req_res_key_exit
;
1354 memcpy(pcchunk
->SourceKey
, res_key
->ResumeKey
, COPY_CHUNK_RES_KEY_SIZE
);
1362 smb2_ioctl_query_info(const unsigned int xid
,
1363 struct cifs_tcon
*tcon
,
1364 __le16
*path
, int is_dir
,
1367 struct cifs_ses
*ses
= tcon
->ses
;
1368 char __user
*arg
= (char __user
*)p
;
1369 struct smb_query_info qi
;
1370 struct smb_query_info __user
*pqi
;
1373 struct smb2_query_info_rsp
*qi_rsp
= NULL
;
1374 struct smb2_ioctl_rsp
*io_rsp
= NULL
;
1375 void *buffer
= NULL
;
1376 struct smb_rqst rqst
[3];
1377 int resp_buftype
[3];
1378 struct kvec rsp_iov
[3];
1379 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
1380 struct cifs_open_parms oparms
;
1381 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1382 struct cifs_fid fid
;
1383 struct kvec qi_iov
[1];
1384 struct kvec io_iov
[SMB2_IOCTL_IOV_SIZE
];
1385 struct kvec close_iov
[1];
1387 memset(rqst
, 0, sizeof(rqst
));
1388 resp_buftype
[0] = resp_buftype
[1] = resp_buftype
[2] = CIFS_NO_BUFFER
;
1389 memset(rsp_iov
, 0, sizeof(rsp_iov
));
1391 if (copy_from_user(&qi
, arg
, sizeof(struct smb_query_info
)))
1394 if (qi
.output_buffer_length
> 1024)
1397 if (!ses
|| !(ses
->server
))
1400 if (smb3_encryption_required(tcon
))
1401 flags
|= CIFS_TRANSFORM_REQ
;
1403 buffer
= kmalloc(qi
.output_buffer_length
, GFP_KERNEL
);
1407 if (copy_from_user(buffer
, arg
+ sizeof(struct smb_query_info
),
1408 qi
.output_buffer_length
)) {
1414 memset(&open_iov
, 0, sizeof(open_iov
));
1415 rqst
[0].rq_iov
= open_iov
;
1416 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
1418 memset(&oparms
, 0, sizeof(oparms
));
1420 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| READ_CONTROL
;
1421 oparms
.disposition
= FILE_OPEN
;
1423 oparms
.create_options
= CREATE_NOT_FILE
;
1425 oparms
.create_options
= CREATE_NOT_DIR
;
1427 oparms
.reconnect
= false;
1429 rc
= SMB2_open_init(tcon
, &rqst
[0], &oplock
, &oparms
, path
);
1432 smb2_set_next_command(tcon
, &rqst
[0]);
1435 if (qi
.flags
& PASSTHRU_FSCTL
) {
1436 /* Can eventually relax perm check since server enforces too */
1437 if (!capable(CAP_SYS_ADMIN
))
1440 memset(&io_iov
, 0, sizeof(io_iov
));
1441 rqst
[1].rq_iov
= io_iov
;
1442 rqst
[1].rq_nvec
= SMB2_IOCTL_IOV_SIZE
;
1444 rc
= SMB2_ioctl_init(tcon
, &rqst
[1],
1445 COMPOUND_FID
, COMPOUND_FID
,
1446 qi
.info_type
, true, NULL
,
1449 } else if (qi
.flags
== PASSTHRU_QUERY_INFO
) {
1450 memset(&qi_iov
, 0, sizeof(qi_iov
));
1451 rqst
[1].rq_iov
= qi_iov
;
1452 rqst
[1].rq_nvec
= 1;
1454 rc
= SMB2_query_info_init(tcon
, &rqst
[1], COMPOUND_FID
,
1455 COMPOUND_FID
, qi
.file_info_class
,
1456 qi
.info_type
, qi
.additional_information
,
1457 qi
.input_buffer_length
,
1458 qi
.output_buffer_length
, buffer
);
1459 } else { /* unknown flags */
1460 cifs_dbg(VFS
, "invalid passthru query flags: 0x%x\n", qi
.flags
);
1466 smb2_set_next_command(tcon
, &rqst
[1]);
1467 smb2_set_related(&rqst
[1]);
1470 memset(&close_iov
, 0, sizeof(close_iov
));
1471 rqst
[2].rq_iov
= close_iov
;
1472 rqst
[2].rq_nvec
= 1;
1474 rc
= SMB2_close_init(tcon
, &rqst
[2], COMPOUND_FID
, COMPOUND_FID
);
1477 smb2_set_related(&rqst
[2]);
1479 rc
= compound_send_recv(xid
, ses
, flags
, 3, rqst
,
1480 resp_buftype
, rsp_iov
);
1483 if (qi
.flags
& PASSTHRU_FSCTL
) {
1484 pqi
= (struct smb_query_info __user
*)arg
;
1485 io_rsp
= (struct smb2_ioctl_rsp
*)rsp_iov
[1].iov_base
;
1486 if (le32_to_cpu(io_rsp
->OutputCount
) < qi
.input_buffer_length
)
1487 qi
.input_buffer_length
= le32_to_cpu(io_rsp
->OutputCount
);
1488 if (copy_to_user(&pqi
->input_buffer_length
, &qi
.input_buffer_length
,
1489 sizeof(qi
.input_buffer_length
))) {
1493 if (copy_to_user(pqi
+ 1, &io_rsp
[1], qi
.input_buffer_length
)) {
1498 pqi
= (struct smb_query_info __user
*)arg
;
1499 qi_rsp
= (struct smb2_query_info_rsp
*)rsp_iov
[1].iov_base
;
1500 if (le32_to_cpu(qi_rsp
->OutputBufferLength
) < qi
.input_buffer_length
)
1501 qi
.input_buffer_length
= le32_to_cpu(qi_rsp
->OutputBufferLength
);
1502 if (copy_to_user(&pqi
->input_buffer_length
, &qi
.input_buffer_length
,
1503 sizeof(qi
.input_buffer_length
))) {
1507 if (copy_to_user(pqi
+ 1, qi_rsp
->Buffer
, qi
.input_buffer_length
)) {
1515 SMB2_open_free(&rqst
[0]);
1516 if (qi
.flags
& PASSTHRU_FSCTL
)
1517 SMB2_ioctl_free(&rqst
[1]);
1519 SMB2_query_info_free(&rqst
[1]);
1521 SMB2_close_free(&rqst
[2]);
1522 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
1523 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
1524 free_rsp_buf(resp_buftype
[2], rsp_iov
[2].iov_base
);
1529 smb2_copychunk_range(const unsigned int xid
,
1530 struct cifsFileInfo
*srcfile
,
1531 struct cifsFileInfo
*trgtfile
, u64 src_off
,
1532 u64 len
, u64 dest_off
)
1535 unsigned int ret_data_len
;
1536 struct copychunk_ioctl
*pcchunk
;
1537 struct copychunk_ioctl_rsp
*retbuf
= NULL
;
1538 struct cifs_tcon
*tcon
;
1539 int chunks_copied
= 0;
1540 bool chunk_sizes_updated
= false;
1541 ssize_t bytes_written
, total_bytes_written
= 0;
1543 pcchunk
= kmalloc(sizeof(struct copychunk_ioctl
), GFP_KERNEL
);
1545 if (pcchunk
== NULL
)
1548 cifs_dbg(FYI
, "in smb2_copychunk_range - about to call request res key\n");
1549 /* Request a key from the server to identify the source of the copy */
1550 rc
= SMB2_request_res_key(xid
, tlink_tcon(srcfile
->tlink
),
1551 srcfile
->fid
.persistent_fid
,
1552 srcfile
->fid
.volatile_fid
, pcchunk
);
1554 /* Note: request_res_key sets res_key null only if rc !=0 */
1558 /* For now array only one chunk long, will make more flexible later */
1559 pcchunk
->ChunkCount
= cpu_to_le32(1);
1560 pcchunk
->Reserved
= 0;
1561 pcchunk
->Reserved2
= 0;
1563 tcon
= tlink_tcon(trgtfile
->tlink
);
1566 pcchunk
->SourceOffset
= cpu_to_le64(src_off
);
1567 pcchunk
->TargetOffset
= cpu_to_le64(dest_off
);
1569 cpu_to_le32(min_t(u32
, len
, tcon
->max_bytes_chunk
));
1571 /* Request server copy to target from src identified by key */
1572 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
1573 trgtfile
->fid
.volatile_fid
, FSCTL_SRV_COPYCHUNK_WRITE
,
1574 true /* is_fsctl */, (char *)pcchunk
,
1575 sizeof(struct copychunk_ioctl
), CIFSMaxBufSize
,
1576 (char **)&retbuf
, &ret_data_len
);
1579 sizeof(struct copychunk_ioctl_rsp
)) {
1580 cifs_dbg(VFS
, "invalid cchunk response size\n");
1584 if (retbuf
->TotalBytesWritten
== 0) {
1585 cifs_dbg(FYI
, "no bytes copied\n");
1590 * Check if server claimed to write more than we asked
1592 if (le32_to_cpu(retbuf
->TotalBytesWritten
) >
1593 le32_to_cpu(pcchunk
->Length
)) {
1594 cifs_dbg(VFS
, "invalid copy chunk response\n");
1598 if (le32_to_cpu(retbuf
->ChunksWritten
) != 1) {
1599 cifs_dbg(VFS
, "invalid num chunks written\n");
1605 bytes_written
= le32_to_cpu(retbuf
->TotalBytesWritten
);
1606 src_off
+= bytes_written
;
1607 dest_off
+= bytes_written
;
1608 len
-= bytes_written
;
1609 total_bytes_written
+= bytes_written
;
1611 cifs_dbg(FYI
, "Chunks %d PartialChunk %d Total %zu\n",
1612 le32_to_cpu(retbuf
->ChunksWritten
),
1613 le32_to_cpu(retbuf
->ChunkBytesWritten
),
1615 } else if (rc
== -EINVAL
) {
1616 if (ret_data_len
!= sizeof(struct copychunk_ioctl_rsp
))
1619 cifs_dbg(FYI
, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1620 le32_to_cpu(retbuf
->ChunksWritten
),
1621 le32_to_cpu(retbuf
->ChunkBytesWritten
),
1622 le32_to_cpu(retbuf
->TotalBytesWritten
));
1625 * Check if this is the first request using these sizes,
1626 * (ie check if copy succeed once with original sizes
1627 * and check if the server gave us different sizes after
1628 * we already updated max sizes on previous request).
1629 * if not then why is the server returning an error now
1631 if ((chunks_copied
!= 0) || chunk_sizes_updated
)
1634 /* Check that server is not asking us to grow size */
1635 if (le32_to_cpu(retbuf
->ChunkBytesWritten
) <
1636 tcon
->max_bytes_chunk
)
1637 tcon
->max_bytes_chunk
=
1638 le32_to_cpu(retbuf
->ChunkBytesWritten
);
1640 goto cchunk_out
; /* server gave us bogus size */
1642 /* No need to change MaxChunks since already set to 1 */
1643 chunk_sizes_updated
= true;
1654 return total_bytes_written
;
1658 smb2_flush_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
1659 struct cifs_fid
*fid
)
1661 return SMB2_flush(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1665 smb2_read_data_offset(char *buf
)
1667 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
1668 return rsp
->DataOffset
;
1672 smb2_read_data_length(char *buf
, bool in_remaining
)
1674 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
1677 return le32_to_cpu(rsp
->DataRemaining
);
1679 return le32_to_cpu(rsp
->DataLength
);
1684 smb2_sync_read(const unsigned int xid
, struct cifs_fid
*pfid
,
1685 struct cifs_io_parms
*parms
, unsigned int *bytes_read
,
1686 char **buf
, int *buf_type
)
1688 parms
->persistent_fid
= pfid
->persistent_fid
;
1689 parms
->volatile_fid
= pfid
->volatile_fid
;
1690 return SMB2_read(xid
, parms
, bytes_read
, buf
, buf_type
);
1694 smb2_sync_write(const unsigned int xid
, struct cifs_fid
*pfid
,
1695 struct cifs_io_parms
*parms
, unsigned int *written
,
1696 struct kvec
*iov
, unsigned long nr_segs
)
1699 parms
->persistent_fid
= pfid
->persistent_fid
;
1700 parms
->volatile_fid
= pfid
->volatile_fid
;
1701 return SMB2_write(xid
, parms
, written
, iov
, nr_segs
);
1704 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1705 static bool smb2_set_sparse(const unsigned int xid
, struct cifs_tcon
*tcon
,
1706 struct cifsFileInfo
*cfile
, struct inode
*inode
, __u8 setsparse
)
1708 struct cifsInodeInfo
*cifsi
;
1711 cifsi
= CIFS_I(inode
);
1713 /* if file already sparse don't bother setting sparse again */
1714 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && setsparse
)
1715 return true; /* already sparse */
1717 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && !setsparse
)
1718 return true; /* already not sparse */
1721 * Can't check for sparse support on share the usual way via the
1722 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1723 * since Samba server doesn't set the flag on the share, yet
1724 * supports the set sparse FSCTL and returns sparse correctly
1725 * in the file attributes. If we fail setting sparse though we
1726 * mark that server does not support sparse files for this share
1727 * to avoid repeatedly sending the unsupported fsctl to server
1728 * if the file is repeatedly extended.
1730 if (tcon
->broken_sparse_sup
)
1733 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1734 cfile
->fid
.volatile_fid
, FSCTL_SET_SPARSE
,
1736 &setsparse
, 1, CIFSMaxBufSize
, NULL
, NULL
);
1738 tcon
->broken_sparse_sup
= true;
1739 cifs_dbg(FYI
, "set sparse rc = %d\n", rc
);
1744 cifsi
->cifsAttrs
|= FILE_ATTRIBUTE_SPARSE_FILE
;
1746 cifsi
->cifsAttrs
&= (~FILE_ATTRIBUTE_SPARSE_FILE
);
1752 smb2_set_file_size(const unsigned int xid
, struct cifs_tcon
*tcon
,
1753 struct cifsFileInfo
*cfile
, __u64 size
, bool set_alloc
)
1755 __le64 eof
= cpu_to_le64(size
);
1756 struct inode
*inode
;
1759 * If extending file more than one page make sparse. Many Linux fs
1760 * make files sparse by default when extending via ftruncate
1762 inode
= d_inode(cfile
->dentry
);
1764 if (!set_alloc
&& (size
> inode
->i_size
+ 8192)) {
1765 __u8 set_sparse
= 1;
1767 /* whether set sparse succeeds or not, extend the file */
1768 smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
);
1771 return SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
1772 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
);
1776 smb2_duplicate_extents(const unsigned int xid
,
1777 struct cifsFileInfo
*srcfile
,
1778 struct cifsFileInfo
*trgtfile
, u64 src_off
,
1779 u64 len
, u64 dest_off
)
1782 unsigned int ret_data_len
;
1783 struct duplicate_extents_to_file dup_ext_buf
;
1784 struct cifs_tcon
*tcon
= tlink_tcon(trgtfile
->tlink
);
1786 /* server fileays advertise duplicate extent support with this flag */
1787 if ((le32_to_cpu(tcon
->fsAttrInfo
.Attributes
) &
1788 FILE_SUPPORTS_BLOCK_REFCOUNTING
) == 0)
1791 dup_ext_buf
.VolatileFileHandle
= srcfile
->fid
.volatile_fid
;
1792 dup_ext_buf
.PersistentFileHandle
= srcfile
->fid
.persistent_fid
;
1793 dup_ext_buf
.SourceFileOffset
= cpu_to_le64(src_off
);
1794 dup_ext_buf
.TargetFileOffset
= cpu_to_le64(dest_off
);
1795 dup_ext_buf
.ByteCount
= cpu_to_le64(len
);
1796 cifs_dbg(FYI
, "duplicate extents: src off %lld dst off %lld len %lld",
1797 src_off
, dest_off
, len
);
1799 rc
= smb2_set_file_size(xid
, tcon
, trgtfile
, dest_off
+ len
, false);
1801 goto duplicate_extents_out
;
1803 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
1804 trgtfile
->fid
.volatile_fid
,
1805 FSCTL_DUPLICATE_EXTENTS_TO_FILE
,
1806 true /* is_fsctl */,
1807 (char *)&dup_ext_buf
,
1808 sizeof(struct duplicate_extents_to_file
),
1809 CIFSMaxBufSize
, NULL
,
1812 if (ret_data_len
> 0)
1813 cifs_dbg(FYI
, "non-zero response length in duplicate extents");
1815 duplicate_extents_out
:
1820 smb2_set_compression(const unsigned int xid
, struct cifs_tcon
*tcon
,
1821 struct cifsFileInfo
*cfile
)
1823 return SMB2_set_compression(xid
, tcon
, cfile
->fid
.persistent_fid
,
1824 cfile
->fid
.volatile_fid
);
1828 smb3_set_integrity(const unsigned int xid
, struct cifs_tcon
*tcon
,
1829 struct cifsFileInfo
*cfile
)
1831 struct fsctl_set_integrity_information_req integr_info
;
1832 unsigned int ret_data_len
;
1834 integr_info
.ChecksumAlgorithm
= cpu_to_le16(CHECKSUM_TYPE_UNCHANGED
);
1835 integr_info
.Flags
= 0;
1836 integr_info
.Reserved
= 0;
1838 return SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1839 cfile
->fid
.volatile_fid
,
1840 FSCTL_SET_INTEGRITY_INFORMATION
,
1841 true /* is_fsctl */,
1842 (char *)&integr_info
,
1843 sizeof(struct fsctl_set_integrity_information_req
),
1844 CIFSMaxBufSize
, NULL
,
1849 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
1850 #define GMT_TOKEN_SIZE 50
1852 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
1855 * Input buffer contains (empty) struct smb_snapshot array with size filled in
1856 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
1859 smb3_enum_snapshots(const unsigned int xid
, struct cifs_tcon
*tcon
,
1860 struct cifsFileInfo
*cfile
, void __user
*ioc_buf
)
1862 char *retbuf
= NULL
;
1863 unsigned int ret_data_len
= 0;
1865 u32 max_response_size
;
1866 struct smb_snapshot_array snapshot_in
;
1868 if (get_user(ret_data_len
, (unsigned int __user
*)ioc_buf
))
1872 * Note that for snapshot queries that servers like Azure expect that
1873 * the first query be minimal size (and just used to get the number/size
1874 * of previous versions) so response size must be specified as EXACTLY
1875 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
1878 if (ret_data_len
== 0)
1879 max_response_size
= MIN_SNAPSHOT_ARRAY_SIZE
;
1881 max_response_size
= CIFSMaxBufSize
;
1883 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1884 cfile
->fid
.volatile_fid
,
1885 FSCTL_SRV_ENUMERATE_SNAPSHOTS
,
1886 true /* is_fsctl */,
1887 NULL
, 0 /* no input data */, max_response_size
,
1890 cifs_dbg(FYI
, "enum snaphots ioctl returned %d and ret buflen is %d\n",
1895 if (ret_data_len
&& (ioc_buf
!= NULL
) && (retbuf
!= NULL
)) {
1897 if (copy_from_user(&snapshot_in
, ioc_buf
,
1898 sizeof(struct smb_snapshot_array
))) {
1905 * Check for min size, ie not large enough to fit even one GMT
1906 * token (snapshot). On the first ioctl some users may pass in
1907 * smaller size (or zero) to simply get the size of the array
1908 * so the user space caller can allocate sufficient memory
1909 * and retry the ioctl again with larger array size sufficient
1910 * to hold all of the snapshot GMT tokens on the second try.
1912 if (snapshot_in
.snapshot_array_size
< GMT_TOKEN_SIZE
)
1913 ret_data_len
= sizeof(struct smb_snapshot_array
);
1916 * We return struct SRV_SNAPSHOT_ARRAY, followed by
1917 * the snapshot array (of 50 byte GMT tokens) each
1918 * representing an available previous version of the data
1920 if (ret_data_len
> (snapshot_in
.snapshot_array_size
+
1921 sizeof(struct smb_snapshot_array
)))
1922 ret_data_len
= snapshot_in
.snapshot_array_size
+
1923 sizeof(struct smb_snapshot_array
);
1925 if (copy_to_user(ioc_buf
, retbuf
, ret_data_len
))
1934 smb2_query_dir_first(const unsigned int xid
, struct cifs_tcon
*tcon
,
1935 const char *path
, struct cifs_sb_info
*cifs_sb
,
1936 struct cifs_fid
*fid
, __u16 search_flags
,
1937 struct cifs_search_info
*srch_inf
)
1941 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1942 struct cifs_open_parms oparms
;
1944 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
1949 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| FILE_READ_DATA
;
1950 oparms
.disposition
= FILE_OPEN
;
1951 if (backup_cred(cifs_sb
))
1952 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
1954 oparms
.create_options
= 0;
1956 oparms
.reconnect
= false;
1958 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
, NULL
);
1961 cifs_dbg(FYI
, "open dir failed rc=%d\n", rc
);
1965 srch_inf
->entries_in_buffer
= 0;
1966 srch_inf
->index_of_last_entry
= 2;
1968 rc
= SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
1969 fid
->volatile_fid
, 0, srch_inf
);
1971 cifs_dbg(FYI
, "query directory failed rc=%d\n", rc
);
1972 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1978 smb2_query_dir_next(const unsigned int xid
, struct cifs_tcon
*tcon
,
1979 struct cifs_fid
*fid
, __u16 search_flags
,
1980 struct cifs_search_info
*srch_inf
)
1982 return SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
1983 fid
->volatile_fid
, 0, srch_inf
);
1987 smb2_close_dir(const unsigned int xid
, struct cifs_tcon
*tcon
,
1988 struct cifs_fid
*fid
)
1990 return SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1994 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
1995 * the number of credits and return true. Otherwise - return false.
1998 smb2_is_status_pending(char *buf
, struct TCP_Server_Info
*server
)
2000 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
2002 if (shdr
->Status
!= STATUS_PENDING
)
2005 if (shdr
->CreditRequest
) {
2006 spin_lock(&server
->req_lock
);
2007 server
->credits
+= le16_to_cpu(shdr
->CreditRequest
);
2008 spin_unlock(&server
->req_lock
);
2009 wake_up(&server
->request_q
);
2016 smb2_is_session_expired(char *buf
)
2018 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
2020 if (shdr
->Status
!= STATUS_NETWORK_SESSION_EXPIRED
&&
2021 shdr
->Status
!= STATUS_USER_SESSION_DELETED
)
2024 trace_smb3_ses_expired(shdr
->TreeId
, shdr
->SessionId
,
2025 le16_to_cpu(shdr
->Command
),
2026 le64_to_cpu(shdr
->MessageId
));
2027 cifs_dbg(FYI
, "Session expired or deleted\n");
2033 smb2_oplock_response(struct cifs_tcon
*tcon
, struct cifs_fid
*fid
,
2034 struct cifsInodeInfo
*cinode
)
2036 if (tcon
->ses
->server
->capabilities
& SMB2_GLOBAL_CAP_LEASING
)
2037 return SMB2_lease_break(0, tcon
, cinode
->lease_key
,
2038 smb2_get_lease_state(cinode
));
2040 return SMB2_oplock_break(0, tcon
, fid
->persistent_fid
,
2042 CIFS_CACHE_READ(cinode
) ? 1 : 0);
2046 smb2_set_related(struct smb_rqst
*rqst
)
2048 struct smb2_sync_hdr
*shdr
;
2050 shdr
= (struct smb2_sync_hdr
*)(rqst
->rq_iov
[0].iov_base
);
2052 cifs_dbg(FYI
, "shdr NULL in smb2_set_related\n");
2055 shdr
->Flags
|= SMB2_FLAGS_RELATED_OPERATIONS
;
2058 char smb2_padding
[7] = {0, 0, 0, 0, 0, 0, 0};
2061 smb2_set_next_command(struct cifs_tcon
*tcon
, struct smb_rqst
*rqst
)
2063 struct smb2_sync_hdr
*shdr
;
2064 struct cifs_ses
*ses
= tcon
->ses
;
2065 struct TCP_Server_Info
*server
= ses
->server
;
2066 unsigned long len
= smb_rqst_len(server
, rqst
);
2069 shdr
= (struct smb2_sync_hdr
*)(rqst
->rq_iov
[0].iov_base
);
2071 cifs_dbg(FYI
, "shdr NULL in smb2_set_next_command\n");
2075 /* SMB headers in a compound are 8 byte aligned. */
2077 /* No padding needed */
2081 num_padding
= 8 - (len
& 7);
2082 if (!smb3_encryption_required(tcon
)) {
2084 * If we do not have encryption then we can just add an extra
2085 * iov for the padding.
2087 rqst
->rq_iov
[rqst
->rq_nvec
].iov_base
= smb2_padding
;
2088 rqst
->rq_iov
[rqst
->rq_nvec
].iov_len
= num_padding
;
2093 * We can not add a small padding iov for the encryption case
2094 * because the encryption framework can not handle the padding
2096 * We have to flatten this into a single buffer and add
2097 * the padding to it.
2099 for (i
= 1; i
< rqst
->rq_nvec
; i
++) {
2100 memcpy(rqst
->rq_iov
[0].iov_base
+
2101 rqst
->rq_iov
[0].iov_len
,
2102 rqst
->rq_iov
[i
].iov_base
,
2103 rqst
->rq_iov
[i
].iov_len
);
2104 rqst
->rq_iov
[0].iov_len
+= rqst
->rq_iov
[i
].iov_len
;
2106 memset(rqst
->rq_iov
[0].iov_base
+ rqst
->rq_iov
[0].iov_len
,
2108 rqst
->rq_iov
[0].iov_len
+= num_padding
;
2114 shdr
->NextCommand
= cpu_to_le32(len
);
2118 * Passes the query info response back to the caller on success.
2119 * Caller need to free this with free_rsp_buf().
2122 smb2_query_info_compound(const unsigned int xid
, struct cifs_tcon
*tcon
,
2123 __le16
*utf16_path
, u32 desired_access
,
2124 u32
class, u32 type
, u32 output_len
,
2125 struct kvec
*rsp
, int *buftype
,
2126 struct cifs_sb_info
*cifs_sb
)
2128 struct cifs_ses
*ses
= tcon
->ses
;
2130 struct smb_rqst rqst
[3];
2131 int resp_buftype
[3];
2132 struct kvec rsp_iov
[3];
2133 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
2134 struct kvec qi_iov
[1];
2135 struct kvec close_iov
[1];
2136 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
2137 struct cifs_open_parms oparms
;
2138 struct cifs_fid fid
;
2141 if (smb3_encryption_required(tcon
))
2142 flags
|= CIFS_TRANSFORM_REQ
;
2144 memset(rqst
, 0, sizeof(rqst
));
2145 resp_buftype
[0] = resp_buftype
[1] = resp_buftype
[2] = CIFS_NO_BUFFER
;
2146 memset(rsp_iov
, 0, sizeof(rsp_iov
));
2148 memset(&open_iov
, 0, sizeof(open_iov
));
2149 rqst
[0].rq_iov
= open_iov
;
2150 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
2153 oparms
.desired_access
= desired_access
;
2154 oparms
.disposition
= FILE_OPEN
;
2155 if (cifs_sb
&& backup_cred(cifs_sb
))
2156 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
2158 oparms
.create_options
= 0;
2160 oparms
.reconnect
= false;
2162 rc
= SMB2_open_init(tcon
, &rqst
[0], &oplock
, &oparms
, utf16_path
);
2165 smb2_set_next_command(tcon
, &rqst
[0]);
2167 memset(&qi_iov
, 0, sizeof(qi_iov
));
2168 rqst
[1].rq_iov
= qi_iov
;
2169 rqst
[1].rq_nvec
= 1;
2171 rc
= SMB2_query_info_init(tcon
, &rqst
[1], COMPOUND_FID
, COMPOUND_FID
,
2177 smb2_set_next_command(tcon
, &rqst
[1]);
2178 smb2_set_related(&rqst
[1]);
2180 memset(&close_iov
, 0, sizeof(close_iov
));
2181 rqst
[2].rq_iov
= close_iov
;
2182 rqst
[2].rq_nvec
= 1;
2184 rc
= SMB2_close_init(tcon
, &rqst
[2], COMPOUND_FID
, COMPOUND_FID
);
2187 smb2_set_related(&rqst
[2]);
2189 rc
= compound_send_recv(xid
, ses
, flags
, 3, rqst
,
2190 resp_buftype
, rsp_iov
);
2192 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
2196 *buftype
= resp_buftype
[1];
2199 SMB2_open_free(&rqst
[0]);
2200 SMB2_query_info_free(&rqst
[1]);
2201 SMB2_close_free(&rqst
[2]);
2202 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
2203 free_rsp_buf(resp_buftype
[2], rsp_iov
[2].iov_base
);
2208 smb2_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
2209 struct kstatfs
*buf
)
2211 struct smb2_query_info_rsp
*rsp
;
2212 struct smb2_fs_full_size_info
*info
= NULL
;
2213 __le16 utf16_path
= 0; /* Null - open root of share */
2214 struct kvec rsp_iov
= {NULL
, 0};
2215 int buftype
= CIFS_NO_BUFFER
;
2219 rc
= smb2_query_info_compound(xid
, tcon
, &utf16_path
,
2220 FILE_READ_ATTRIBUTES
,
2221 FS_FULL_SIZE_INFORMATION
,
2222 SMB2_O_INFO_FILESYSTEM
,
2223 sizeof(struct smb2_fs_full_size_info
),
2224 &rsp_iov
, &buftype
, NULL
);
2228 rsp
= (struct smb2_query_info_rsp
*)rsp_iov
.iov_base
;
2229 buf
->f_type
= SMB2_MAGIC_NUMBER
;
2230 info
= (struct smb2_fs_full_size_info
*)(
2231 le16_to_cpu(rsp
->OutputBufferOffset
) + (char *)rsp
);
2232 rc
= smb2_validate_iov(le16_to_cpu(rsp
->OutputBufferOffset
),
2233 le32_to_cpu(rsp
->OutputBufferLength
),
2235 sizeof(struct smb2_fs_full_size_info
));
2237 smb2_copy_fs_info_to_kstatfs(info
, buf
);
2240 free_rsp_buf(buftype
, rsp_iov
.iov_base
);
2245 smb311_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
2246 struct kstatfs
*buf
)
2249 __le16 srch_path
= 0; /* Null - open root of share */
2250 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
2251 struct cifs_open_parms oparms
;
2252 struct cifs_fid fid
;
2254 if (!tcon
->posix_extensions
)
2255 return smb2_queryfs(xid
, tcon
, buf
);
2258 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
2259 oparms
.disposition
= FILE_OPEN
;
2260 oparms
.create_options
= 0;
2262 oparms
.reconnect
= false;
2264 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
, NULL
);
2268 rc
= SMB311_posix_qfs_info(xid
, tcon
, fid
.persistent_fid
,
2269 fid
.volatile_fid
, buf
);
2270 buf
->f_type
= SMB2_MAGIC_NUMBER
;
2271 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
2276 smb2_compare_fids(struct cifsFileInfo
*ob1
, struct cifsFileInfo
*ob2
)
2278 return ob1
->fid
.persistent_fid
== ob2
->fid
.persistent_fid
&&
2279 ob1
->fid
.volatile_fid
== ob2
->fid
.volatile_fid
;
2283 smb2_mand_lock(const unsigned int xid
, struct cifsFileInfo
*cfile
, __u64 offset
,
2284 __u64 length
, __u32 type
, int lock
, int unlock
, bool wait
)
2286 if (unlock
&& !lock
)
2287 type
= SMB2_LOCKFLAG_UNLOCK
;
2288 return SMB2_lock(xid
, tlink_tcon(cfile
->tlink
),
2289 cfile
->fid
.persistent_fid
, cfile
->fid
.volatile_fid
,
2290 current
->tgid
, length
, offset
, type
, wait
);
2294 smb2_get_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
2296 memcpy(fid
->lease_key
, CIFS_I(inode
)->lease_key
, SMB2_LEASE_KEY_SIZE
);
2300 smb2_set_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
2302 memcpy(CIFS_I(inode
)->lease_key
, fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
2306 smb2_new_lease_key(struct cifs_fid
*fid
)
2308 generate_random_uuid(fid
->lease_key
);
2312 smb2_get_dfs_refer(const unsigned int xid
, struct cifs_ses
*ses
,
2313 const char *search_name
,
2314 struct dfs_info3_param
**target_nodes
,
2315 unsigned int *num_of_nodes
,
2316 const struct nls_table
*nls_codepage
, int remap
)
2319 __le16
*utf16_path
= NULL
;
2320 int utf16_path_len
= 0;
2321 struct cifs_tcon
*tcon
;
2322 struct fsctl_get_dfs_referral_req
*dfs_req
= NULL
;
2323 struct get_dfs_referral_rsp
*dfs_rsp
= NULL
;
2324 u32 dfs_req_size
= 0, dfs_rsp_size
= 0;
2326 cifs_dbg(FYI
, "smb2_get_dfs_refer path <%s>\n", search_name
);
2329 * Try to use the IPC tcon, otherwise just use any
2331 tcon
= ses
->tcon_ipc
;
2333 spin_lock(&cifs_tcp_ses_lock
);
2334 tcon
= list_first_entry_or_null(&ses
->tcon_list
,
2339 spin_unlock(&cifs_tcp_ses_lock
);
2343 cifs_dbg(VFS
, "session %p has no tcon available for a dfs referral request\n",
2349 utf16_path
= cifs_strndup_to_utf16(search_name
, PATH_MAX
,
2351 nls_codepage
, remap
);
2357 dfs_req_size
= sizeof(*dfs_req
) + utf16_path_len
;
2358 dfs_req
= kzalloc(dfs_req_size
, GFP_KERNEL
);
2364 /* Highest DFS referral version understood */
2365 dfs_req
->MaxReferralLevel
= DFS_VERSION
;
2367 /* Path to resolve in an UTF-16 null-terminated string */
2368 memcpy(dfs_req
->RequestFileName
, utf16_path
, utf16_path_len
);
2371 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
2372 FSCTL_DFS_GET_REFERRALS
,
2373 true /* is_fsctl */,
2374 (char *)dfs_req
, dfs_req_size
, CIFSMaxBufSize
,
2375 (char **)&dfs_rsp
, &dfs_rsp_size
);
2376 } while (rc
== -EAGAIN
);
2379 if ((rc
!= -ENOENT
) && (rc
!= -EOPNOTSUPP
))
2380 cifs_dbg(VFS
, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc
);
2384 rc
= parse_dfs_referrals(dfs_rsp
, dfs_rsp_size
,
2385 num_of_nodes
, target_nodes
,
2386 nls_codepage
, remap
, search_name
,
2387 true /* is_unicode */);
2389 cifs_dbg(VFS
, "parse error in smb2_get_dfs_refer rc=%d\n", rc
);
2394 if (tcon
&& !tcon
->ipc
) {
2395 /* ipc tcons are not refcounted */
2396 spin_lock(&cifs_tcp_ses_lock
);
2398 spin_unlock(&cifs_tcp_ses_lock
);
2405 #define SMB2_SYMLINK_STRUCT_SIZE \
2406 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
2409 smb2_query_symlink(const unsigned int xid
, struct cifs_tcon
*tcon
,
2410 const char *full_path
, char **target_path
,
2411 struct cifs_sb_info
*cifs_sb
)
2415 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
2416 struct cifs_open_parms oparms
;
2417 struct cifs_fid fid
;
2418 struct kvec err_iov
= {NULL
, 0};
2419 struct smb2_err_rsp
*err_buf
= NULL
;
2421 struct smb2_symlink_err_rsp
*symlink
;
2422 unsigned int sub_len
;
2423 unsigned int sub_offset
;
2424 unsigned int print_len
;
2425 unsigned int print_offset
;
2427 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, full_path
);
2429 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
2434 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
2435 oparms
.disposition
= FILE_OPEN
;
2436 if (backup_cred(cifs_sb
))
2437 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
2439 oparms
.create_options
= 0;
2441 oparms
.reconnect
= false;
2443 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, &err_iov
,
2446 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
2447 if (!rc
|| !err_iov
.iov_base
) {
2452 err_buf
= err_iov
.iov_base
;
2453 if (le32_to_cpu(err_buf
->ByteCount
) < sizeof(struct smb2_symlink_err_rsp
) ||
2454 err_iov
.iov_len
< SMB2_SYMLINK_STRUCT_SIZE
) {
2459 /* open must fail on symlink - reset rc */
2461 symlink
= (struct smb2_symlink_err_rsp
*)err_buf
->ErrorData
;
2462 sub_len
= le16_to_cpu(symlink
->SubstituteNameLength
);
2463 sub_offset
= le16_to_cpu(symlink
->SubstituteNameOffset
);
2464 print_len
= le16_to_cpu(symlink
->PrintNameLength
);
2465 print_offset
= le16_to_cpu(symlink
->PrintNameOffset
);
2467 if (err_iov
.iov_len
< SMB2_SYMLINK_STRUCT_SIZE
+ sub_offset
+ sub_len
) {
2472 if (err_iov
.iov_len
<
2473 SMB2_SYMLINK_STRUCT_SIZE
+ print_offset
+ print_len
) {
2478 *target_path
= cifs_strndup_from_utf16(
2479 (char *)symlink
->PathBuffer
+ sub_offset
,
2480 sub_len
, true, cifs_sb
->local_nls
);
2481 if (!(*target_path
)) {
2485 convert_delimiter(*target_path
, '/');
2486 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
2489 free_rsp_buf(resp_buftype
, err_buf
);
2495 #ifdef CONFIG_CIFS_ACL
2496 static struct cifs_ntsd
*
2497 get_smb2_acl_by_fid(struct cifs_sb_info
*cifs_sb
,
2498 const struct cifs_fid
*cifsfid
, u32
*pacllen
)
2500 struct cifs_ntsd
*pntsd
= NULL
;
2502 int rc
= -EOPNOTSUPP
;
2503 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
2506 return ERR_CAST(tlink
);
2509 cifs_dbg(FYI
, "trying to get acl\n");
2511 rc
= SMB2_query_acl(xid
, tlink_tcon(tlink
), cifsfid
->persistent_fid
,
2512 cifsfid
->volatile_fid
, (void **)&pntsd
, pacllen
);
2515 cifs_put_tlink(tlink
);
2517 cifs_dbg(FYI
, "%s: rc = %d ACL len %d\n", __func__
, rc
, *pacllen
);
2524 static struct cifs_ntsd
*
2525 get_smb2_acl_by_path(struct cifs_sb_info
*cifs_sb
,
2526 const char *path
, u32
*pacllen
)
2528 struct cifs_ntsd
*pntsd
= NULL
;
2529 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
2532 struct cifs_tcon
*tcon
;
2533 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
2534 struct cifs_fid fid
;
2535 struct cifs_open_parms oparms
;
2538 cifs_dbg(FYI
, "get smb3 acl for path %s\n", path
);
2540 return ERR_CAST(tlink
);
2542 tcon
= tlink_tcon(tlink
);
2545 if (backup_cred(cifs_sb
))
2546 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
2548 oparms
.create_options
= 0;
2550 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
2558 oparms
.desired_access
= READ_CONTROL
;
2559 oparms
.disposition
= FILE_OPEN
;
2561 oparms
.reconnect
= false;
2563 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
, NULL
);
2566 rc
= SMB2_query_acl(xid
, tlink_tcon(tlink
), fid
.persistent_fid
,
2567 fid
.volatile_fid
, (void **)&pntsd
, pacllen
);
2568 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
2571 cifs_put_tlink(tlink
);
2574 cifs_dbg(FYI
, "%s: rc = %d ACL len %d\n", __func__
, rc
, *pacllen
);
2580 #ifdef CONFIG_CIFS_ACL
2582 set_smb2_acl(struct cifs_ntsd
*pnntsd
, __u32 acllen
,
2583 struct inode
*inode
, const char *path
, int aclflag
)
2585 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
2587 int rc
, access_flags
= 0;
2588 struct cifs_tcon
*tcon
;
2589 struct cifs_sb_info
*cifs_sb
= CIFS_SB(inode
->i_sb
);
2590 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
2591 struct cifs_fid fid
;
2592 struct cifs_open_parms oparms
;
2595 cifs_dbg(FYI
, "set smb3 acl for path %s\n", path
);
2597 return PTR_ERR(tlink
);
2599 tcon
= tlink_tcon(tlink
);
2602 if (backup_cred(cifs_sb
))
2603 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
2605 oparms
.create_options
= 0;
2607 if (aclflag
== CIFS_ACL_OWNER
|| aclflag
== CIFS_ACL_GROUP
)
2608 access_flags
= WRITE_OWNER
;
2610 access_flags
= WRITE_DAC
;
2612 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
2620 oparms
.desired_access
= access_flags
;
2621 oparms
.disposition
= FILE_OPEN
;
2624 oparms
.reconnect
= false;
2626 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
, NULL
);
2629 rc
= SMB2_set_acl(xid
, tlink_tcon(tlink
), fid
.persistent_fid
,
2630 fid
.volatile_fid
, pnntsd
, acllen
, aclflag
);
2631 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
2634 cifs_put_tlink(tlink
);
2638 #endif /* CIFS_ACL */
2640 /* Retrieve an ACL from the server */
2641 static struct cifs_ntsd
*
2642 get_smb2_acl(struct cifs_sb_info
*cifs_sb
,
2643 struct inode
*inode
, const char *path
,
2646 struct cifs_ntsd
*pntsd
= NULL
;
2647 struct cifsFileInfo
*open_file
= NULL
;
2650 open_file
= find_readable_file(CIFS_I(inode
), true);
2652 return get_smb2_acl_by_path(cifs_sb
, path
, pacllen
);
2654 pntsd
= get_smb2_acl_by_fid(cifs_sb
, &open_file
->fid
, pacllen
);
2655 cifsFileInfo_put(open_file
);
2660 static long smb3_zero_range(struct file
*file
, struct cifs_tcon
*tcon
,
2661 loff_t offset
, loff_t len
, bool keep_size
)
2663 struct cifs_ses
*ses
= tcon
->ses
;
2664 struct inode
*inode
;
2665 struct cifsInodeInfo
*cifsi
;
2666 struct cifsFileInfo
*cfile
= file
->private_data
;
2667 struct file_zero_data_information fsctl_buf
;
2668 struct smb_rqst rqst
[2];
2669 int resp_buftype
[2];
2670 struct kvec rsp_iov
[2];
2671 struct kvec io_iov
[SMB2_IOCTL_IOV_SIZE
];
2672 struct kvec si_iov
[1];
2673 unsigned int size
[1];
2677 int num
= 0, flags
= 0;
2682 inode
= d_inode(cfile
->dentry
);
2683 cifsi
= CIFS_I(inode
);
2685 trace_smb3_zero_enter(xid
, cfile
->fid
.persistent_fid
, tcon
->tid
,
2686 ses
->Suid
, offset
, len
);
2689 /* if file not oplocked can't be sure whether asking to extend size */
2690 if (!CIFS_CACHE_READ(cifsi
))
2691 if (keep_size
== false) {
2693 trace_smb3_zero_err(xid
, cfile
->fid
.persistent_fid
,
2694 tcon
->tid
, ses
->Suid
, offset
, len
, rc
);
2700 * Must check if file sparse since fallocate -z (zero range) assumes
2701 * non-sparse allocation
2703 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
)) {
2705 trace_smb3_zero_err(xid
, cfile
->fid
.persistent_fid
, tcon
->tid
,
2706 ses
->Suid
, offset
, len
, rc
);
2711 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
2713 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
2714 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
2716 if (smb3_encryption_required(tcon
))
2717 flags
|= CIFS_TRANSFORM_REQ
;
2719 memset(rqst
, 0, sizeof(rqst
));
2720 resp_buftype
[0] = resp_buftype
[1] = CIFS_NO_BUFFER
;
2721 memset(rsp_iov
, 0, sizeof(rsp_iov
));
2724 memset(&io_iov
, 0, sizeof(io_iov
));
2725 rqst
[num
].rq_iov
= io_iov
;
2726 rqst
[num
].rq_nvec
= SMB2_IOCTL_IOV_SIZE
;
2727 rc
= SMB2_ioctl_init(tcon
, &rqst
[num
++], cfile
->fid
.persistent_fid
,
2728 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
2729 true /* is_fctl */, (char *)&fsctl_buf
,
2730 sizeof(struct file_zero_data_information
),
2733 goto zero_range_exit
;
2736 * do we also need to change the size of the file?
2738 if (keep_size
== false && i_size_read(inode
) < offset
+ len
) {
2739 smb2_set_next_command(tcon
, &rqst
[0]);
2741 memset(&si_iov
, 0, sizeof(si_iov
));
2742 rqst
[num
].rq_iov
= si_iov
;
2743 rqst
[num
].rq_nvec
= 1;
2745 eof
= cpu_to_le64(offset
+ len
);
2746 size
[0] = 8; /* sizeof __le64 */
2749 rc
= SMB2_set_info_init(tcon
, &rqst
[num
++],
2750 cfile
->fid
.persistent_fid
,
2751 cfile
->fid
.persistent_fid
,
2753 FILE_END_OF_FILE_INFORMATION
,
2754 SMB2_O_INFO_FILE
, 0, data
, size
);
2755 smb2_set_related(&rqst
[1]);
2758 rc
= compound_send_recv(xid
, ses
, flags
, num
, rqst
,
2759 resp_buftype
, rsp_iov
);
2762 SMB2_ioctl_free(&rqst
[0]);
2763 SMB2_set_info_free(&rqst
[1]);
2764 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
2765 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
2768 trace_smb3_zero_err(xid
, cfile
->fid
.persistent_fid
, tcon
->tid
,
2769 ses
->Suid
, offset
, len
, rc
);
2771 trace_smb3_zero_done(xid
, cfile
->fid
.persistent_fid
, tcon
->tid
,
2772 ses
->Suid
, offset
, len
);
2776 static long smb3_punch_hole(struct file
*file
, struct cifs_tcon
*tcon
,
2777 loff_t offset
, loff_t len
)
2779 struct inode
*inode
;
2780 struct cifsInodeInfo
*cifsi
;
2781 struct cifsFileInfo
*cfile
= file
->private_data
;
2782 struct file_zero_data_information fsctl_buf
;
2785 __u8 set_sparse
= 1;
2789 inode
= d_inode(cfile
->dentry
);
2790 cifsi
= CIFS_I(inode
);
2792 /* Need to make file sparse, if not already, before freeing range. */
2793 /* Consider adding equivalent for compressed since it could also work */
2794 if (!smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
)) {
2800 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
2802 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
2803 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
2805 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
2806 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
2807 true /* is_fctl */, (char *)&fsctl_buf
,
2808 sizeof(struct file_zero_data_information
),
2809 CIFSMaxBufSize
, NULL
, NULL
);
2814 static long smb3_simple_falloc(struct file
*file
, struct cifs_tcon
*tcon
,
2815 loff_t off
, loff_t len
, bool keep_size
)
2817 struct inode
*inode
;
2818 struct cifsInodeInfo
*cifsi
;
2819 struct cifsFileInfo
*cfile
= file
->private_data
;
2820 long rc
= -EOPNOTSUPP
;
2826 inode
= d_inode(cfile
->dentry
);
2827 cifsi
= CIFS_I(inode
);
2829 trace_smb3_falloc_enter(xid
, cfile
->fid
.persistent_fid
, tcon
->tid
,
2830 tcon
->ses
->Suid
, off
, len
);
2831 /* if file not oplocked can't be sure whether asking to extend size */
2832 if (!CIFS_CACHE_READ(cifsi
))
2833 if (keep_size
== false) {
2834 trace_smb3_falloc_err(xid
, cfile
->fid
.persistent_fid
,
2835 tcon
->tid
, tcon
->ses
->Suid
, off
, len
, rc
);
2841 * Files are non-sparse by default so falloc may be a no-op
2842 * Must check if file sparse. If not sparse, and not extending
2843 * then no need to do anything since file already allocated
2845 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) == 0) {
2846 if (keep_size
== true)
2848 /* check if extending file */
2849 else if (i_size_read(inode
) >= off
+ len
)
2850 /* not extending file and already not sparse */
2852 /* BB: in future add else clause to extend file */
2856 trace_smb3_falloc_err(xid
, cfile
->fid
.persistent_fid
,
2857 tcon
->tid
, tcon
->ses
->Suid
, off
, len
, rc
);
2859 trace_smb3_falloc_done(xid
, cfile
->fid
.persistent_fid
,
2860 tcon
->tid
, tcon
->ses
->Suid
, off
, len
);
2865 if ((keep_size
== true) || (i_size_read(inode
) >= off
+ len
)) {
2867 * Check if falloc starts within first few pages of file
2868 * and ends within a few pages of the end of file to
2869 * ensure that most of file is being forced to be
2870 * fallocated now. If so then setting whole file sparse
2871 * ie potentially making a few extra pages at the beginning
2872 * or end of the file non-sparse via set_sparse is harmless.
2874 if ((off
> 8192) || (off
+ len
+ 8192 < i_size_read(inode
))) {
2876 trace_smb3_falloc_err(xid
, cfile
->fid
.persistent_fid
,
2877 tcon
->tid
, tcon
->ses
->Suid
, off
, len
, rc
);
2882 smb2_set_sparse(xid
, tcon
, cfile
, inode
, false);
2885 smb2_set_sparse(xid
, tcon
, cfile
, inode
, false);
2887 if (i_size_read(inode
) < off
+ len
) {
2888 eof
= cpu_to_le64(off
+ len
);
2889 rc
= SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
2890 cfile
->fid
.volatile_fid
, cfile
->pid
,
2896 trace_smb3_falloc_err(xid
, cfile
->fid
.persistent_fid
, tcon
->tid
,
2897 tcon
->ses
->Suid
, off
, len
, rc
);
2899 trace_smb3_falloc_done(xid
, cfile
->fid
.persistent_fid
, tcon
->tid
,
2900 tcon
->ses
->Suid
, off
, len
);
2907 static long smb3_fallocate(struct file
*file
, struct cifs_tcon
*tcon
, int mode
,
2908 loff_t off
, loff_t len
)
2910 /* KEEP_SIZE already checked for by do_fallocate */
2911 if (mode
& FALLOC_FL_PUNCH_HOLE
)
2912 return smb3_punch_hole(file
, tcon
, off
, len
);
2913 else if (mode
& FALLOC_FL_ZERO_RANGE
) {
2914 if (mode
& FALLOC_FL_KEEP_SIZE
)
2915 return smb3_zero_range(file
, tcon
, off
, len
, true);
2916 return smb3_zero_range(file
, tcon
, off
, len
, false);
2917 } else if (mode
== FALLOC_FL_KEEP_SIZE
)
2918 return smb3_simple_falloc(file
, tcon
, off
, len
, true);
2920 return smb3_simple_falloc(file
, tcon
, off
, len
, false);
2926 smb2_downgrade_oplock(struct TCP_Server_Info
*server
,
2927 struct cifsInodeInfo
*cinode
, bool set_level2
)
2930 server
->ops
->set_oplock_level(cinode
, SMB2_OPLOCK_LEVEL_II
,
2933 server
->ops
->set_oplock_level(cinode
, 0, 0, NULL
);
2937 smb21_downgrade_oplock(struct TCP_Server_Info
*server
,
2938 struct cifsInodeInfo
*cinode
, bool set_level2
)
2940 server
->ops
->set_oplock_level(cinode
,
2941 set_level2
? SMB2_LEASE_READ_CACHING_HE
:
2946 smb2_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
2947 unsigned int epoch
, bool *purge_cache
)
2950 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
2952 if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
) {
2953 cinode
->oplock
= CIFS_CACHE_RHW_FLG
;
2954 cifs_dbg(FYI
, "Batch Oplock granted on inode %p\n",
2955 &cinode
->vfs_inode
);
2956 } else if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
) {
2957 cinode
->oplock
= CIFS_CACHE_RW_FLG
;
2958 cifs_dbg(FYI
, "Exclusive Oplock granted on inode %p\n",
2959 &cinode
->vfs_inode
);
2960 } else if (oplock
== SMB2_OPLOCK_LEVEL_II
) {
2961 cinode
->oplock
= CIFS_CACHE_READ_FLG
;
2962 cifs_dbg(FYI
, "Level II Oplock granted on inode %p\n",
2963 &cinode
->vfs_inode
);
2969 smb21_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
2970 unsigned int epoch
, bool *purge_cache
)
2972 char message
[5] = {0};
2973 unsigned int new_oplock
= 0;
2976 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
2979 if (oplock
& SMB2_LEASE_READ_CACHING_HE
) {
2980 new_oplock
|= CIFS_CACHE_READ_FLG
;
2981 strcat(message
, "R");
2983 if (oplock
& SMB2_LEASE_HANDLE_CACHING_HE
) {
2984 new_oplock
|= CIFS_CACHE_HANDLE_FLG
;
2985 strcat(message
, "H");
2987 if (oplock
& SMB2_LEASE_WRITE_CACHING_HE
) {
2988 new_oplock
|= CIFS_CACHE_WRITE_FLG
;
2989 strcat(message
, "W");
2992 strncpy(message
, "None", sizeof(message
));
2994 cinode
->oplock
= new_oplock
;
2995 cifs_dbg(FYI
, "%s Lease granted on inode %p\n", message
,
2996 &cinode
->vfs_inode
);
3000 smb3_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
3001 unsigned int epoch
, bool *purge_cache
)
3003 unsigned int old_oplock
= cinode
->oplock
;
3005 smb21_set_oplock_level(cinode
, oplock
, epoch
, purge_cache
);
3008 *purge_cache
= false;
3009 if (old_oplock
== CIFS_CACHE_READ_FLG
) {
3010 if (cinode
->oplock
== CIFS_CACHE_READ_FLG
&&
3011 (epoch
- cinode
->epoch
> 0))
3012 *purge_cache
= true;
3013 else if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
3014 (epoch
- cinode
->epoch
> 1))
3015 *purge_cache
= true;
3016 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
3017 (epoch
- cinode
->epoch
> 1))
3018 *purge_cache
= true;
3019 else if (cinode
->oplock
== 0 &&
3020 (epoch
- cinode
->epoch
> 0))
3021 *purge_cache
= true;
3022 } else if (old_oplock
== CIFS_CACHE_RH_FLG
) {
3023 if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
3024 (epoch
- cinode
->epoch
> 0))
3025 *purge_cache
= true;
3026 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
3027 (epoch
- cinode
->epoch
> 1))
3028 *purge_cache
= true;
3030 cinode
->epoch
= epoch
;
3035 smb2_is_read_op(__u32 oplock
)
3037 return oplock
== SMB2_OPLOCK_LEVEL_II
;
3041 smb21_is_read_op(__u32 oplock
)
3043 return (oplock
& SMB2_LEASE_READ_CACHING_HE
) &&
3044 !(oplock
& SMB2_LEASE_WRITE_CACHING_HE
);
3048 map_oplock_to_lease(u8 oplock
)
3050 if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
)
3051 return SMB2_LEASE_WRITE_CACHING
| SMB2_LEASE_READ_CACHING
;
3052 else if (oplock
== SMB2_OPLOCK_LEVEL_II
)
3053 return SMB2_LEASE_READ_CACHING
;
3054 else if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
)
3055 return SMB2_LEASE_HANDLE_CACHING
| SMB2_LEASE_READ_CACHING
|
3056 SMB2_LEASE_WRITE_CACHING
;
3061 smb2_create_lease_buf(u8
*lease_key
, u8 oplock
)
3063 struct create_lease
*buf
;
3065 buf
= kzalloc(sizeof(struct create_lease
), GFP_KERNEL
);
3069 memcpy(&buf
->lcontext
.LeaseKey
, lease_key
, SMB2_LEASE_KEY_SIZE
);
3070 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
3072 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
3073 (struct create_lease
, lcontext
));
3074 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context
));
3075 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
3076 (struct create_lease
, Name
));
3077 buf
->ccontext
.NameLength
= cpu_to_le16(4);
3078 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
3087 smb3_create_lease_buf(u8
*lease_key
, u8 oplock
)
3089 struct create_lease_v2
*buf
;
3091 buf
= kzalloc(sizeof(struct create_lease_v2
), GFP_KERNEL
);
3095 memcpy(&buf
->lcontext
.LeaseKey
, lease_key
, SMB2_LEASE_KEY_SIZE
);
3096 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
3098 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
3099 (struct create_lease_v2
, lcontext
));
3100 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context_v2
));
3101 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
3102 (struct create_lease_v2
, Name
));
3103 buf
->ccontext
.NameLength
= cpu_to_le16(4);
3104 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
3113 smb2_parse_lease_buf(void *buf
, unsigned int *epoch
, char *lease_key
)
3115 struct create_lease
*lc
= (struct create_lease
*)buf
;
3117 *epoch
= 0; /* not used */
3118 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
3119 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
3120 return le32_to_cpu(lc
->lcontext
.LeaseState
);
3124 smb3_parse_lease_buf(void *buf
, unsigned int *epoch
, char *lease_key
)
3126 struct create_lease_v2
*lc
= (struct create_lease_v2
*)buf
;
3128 *epoch
= le16_to_cpu(lc
->lcontext
.Epoch
);
3129 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
3130 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
3132 memcpy(lease_key
, &lc
->lcontext
.LeaseKey
, SMB2_LEASE_KEY_SIZE
);
3133 return le32_to_cpu(lc
->lcontext
.LeaseState
);
3137 smb2_wp_retry_size(struct inode
*inode
)
3139 return min_t(unsigned int, CIFS_SB(inode
->i_sb
)->wsize
,
3140 SMB2_MAX_BUFFER_SIZE
);
3144 smb2_dir_needs_close(struct cifsFileInfo
*cfile
)
3146 return !cfile
->invalidHandle
;
3150 fill_transform_hdr(struct smb2_transform_hdr
*tr_hdr
, unsigned int orig_len
,
3151 struct smb_rqst
*old_rq
)
3153 struct smb2_sync_hdr
*shdr
=
3154 (struct smb2_sync_hdr
*)old_rq
->rq_iov
[0].iov_base
;
3156 memset(tr_hdr
, 0, sizeof(struct smb2_transform_hdr
));
3157 tr_hdr
->ProtocolId
= SMB2_TRANSFORM_PROTO_NUM
;
3158 tr_hdr
->OriginalMessageSize
= cpu_to_le32(orig_len
);
3159 tr_hdr
->Flags
= cpu_to_le16(0x01);
3160 get_random_bytes(&tr_hdr
->Nonce
, SMB3_AES128CMM_NONCE
);
3161 memcpy(&tr_hdr
->SessionId
, &shdr
->SessionId
, 8);
3164 /* We can not use the normal sg_set_buf() as we will sometimes pass a
3165 * stack object as buf.
3167 static inline void smb2_sg_set_buf(struct scatterlist
*sg
, const void *buf
,
3168 unsigned int buflen
)
3170 sg_set_page(sg
, virt_to_page(buf
), buflen
, offset_in_page(buf
));
3173 /* Assumes the first rqst has a transform header as the first iov.
3175 * rqst[0].rq_iov[0] is transform header
3176 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
3177 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
3179 static struct scatterlist
*
3180 init_sg(int num_rqst
, struct smb_rqst
*rqst
, u8
*sign
)
3182 unsigned int sg_len
;
3183 struct scatterlist
*sg
;
3186 unsigned int idx
= 0;
3190 for (i
= 0; i
< num_rqst
; i
++)
3191 sg_len
+= rqst
[i
].rq_nvec
+ rqst
[i
].rq_npages
;
3193 sg
= kmalloc_array(sg_len
, sizeof(struct scatterlist
), GFP_KERNEL
);
3197 sg_init_table(sg
, sg_len
);
3198 for (i
= 0; i
< num_rqst
; i
++) {
3199 for (j
= 0; j
< rqst
[i
].rq_nvec
; j
++) {
3201 * The first rqst has a transform header where the
3202 * first 20 bytes are not part of the encrypted blob
3204 skip
= (i
== 0) && (j
== 0) ? 20 : 0;
3205 smb2_sg_set_buf(&sg
[idx
++],
3206 rqst
[i
].rq_iov
[j
].iov_base
+ skip
,
3207 rqst
[i
].rq_iov
[j
].iov_len
- skip
);
3210 for (j
= 0; j
< rqst
[i
].rq_npages
; j
++) {
3211 unsigned int len
, offset
;
3213 rqst_page_get_length(&rqst
[i
], j
, &len
, &offset
);
3214 sg_set_page(&sg
[idx
++], rqst
[i
].rq_pages
[j
], len
, offset
);
3217 smb2_sg_set_buf(&sg
[idx
], sign
, SMB2_SIGNATURE_SIZE
);
3222 smb2_get_enc_key(struct TCP_Server_Info
*server
, __u64 ses_id
, int enc
, u8
*key
)
3224 struct cifs_ses
*ses
;
3227 spin_lock(&cifs_tcp_ses_lock
);
3228 list_for_each_entry(ses
, &server
->smb_ses_list
, smb_ses_list
) {
3229 if (ses
->Suid
!= ses_id
)
3231 ses_enc_key
= enc
? ses
->smb3encryptionkey
:
3232 ses
->smb3decryptionkey
;
3233 memcpy(key
, ses_enc_key
, SMB3_SIGN_KEY_SIZE
);
3234 spin_unlock(&cifs_tcp_ses_lock
);
3237 spin_unlock(&cifs_tcp_ses_lock
);
3242 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
3243 * iov[0] - transform header (associate data),
3244 * iov[1-N] - SMB2 header and pages - data to encrypt.
3245 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
3249 crypt_message(struct TCP_Server_Info
*server
, int num_rqst
,
3250 struct smb_rqst
*rqst
, int enc
)
3252 struct smb2_transform_hdr
*tr_hdr
=
3253 (struct smb2_transform_hdr
*)rqst
[0].rq_iov
[0].iov_base
;
3254 unsigned int assoc_data_len
= sizeof(struct smb2_transform_hdr
) - 20;
3256 struct scatterlist
*sg
;
3257 u8 sign
[SMB2_SIGNATURE_SIZE
] = {};
3258 u8 key
[SMB3_SIGN_KEY_SIZE
];
3259 struct aead_request
*req
;
3261 unsigned int iv_len
;
3262 DECLARE_CRYPTO_WAIT(wait
);
3263 struct crypto_aead
*tfm
;
3264 unsigned int crypt_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
3266 rc
= smb2_get_enc_key(server
, tr_hdr
->SessionId
, enc
, key
);
3268 cifs_dbg(VFS
, "%s: Could not get %scryption key\n", __func__
,
3273 rc
= smb3_crypto_aead_allocate(server
);
3275 cifs_dbg(VFS
, "%s: crypto alloc failed\n", __func__
);
3279 tfm
= enc
? server
->secmech
.ccmaesencrypt
:
3280 server
->secmech
.ccmaesdecrypt
;
3281 rc
= crypto_aead_setkey(tfm
, key
, SMB3_SIGN_KEY_SIZE
);
3283 cifs_dbg(VFS
, "%s: Failed to set aead key %d\n", __func__
, rc
);
3287 rc
= crypto_aead_setauthsize(tfm
, SMB2_SIGNATURE_SIZE
);
3289 cifs_dbg(VFS
, "%s: Failed to set authsize %d\n", __func__
, rc
);
3293 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
3295 cifs_dbg(VFS
, "%s: Failed to alloc aead request", __func__
);
3300 memcpy(sign
, &tr_hdr
->Signature
, SMB2_SIGNATURE_SIZE
);
3301 crypt_len
+= SMB2_SIGNATURE_SIZE
;
3304 sg
= init_sg(num_rqst
, rqst
, sign
);
3306 cifs_dbg(VFS
, "%s: Failed to init sg", __func__
);
3311 iv_len
= crypto_aead_ivsize(tfm
);
3312 iv
= kzalloc(iv_len
, GFP_KERNEL
);
3314 cifs_dbg(VFS
, "%s: Failed to alloc IV", __func__
);
3319 memcpy(iv
+ 1, (char *)tr_hdr
->Nonce
, SMB3_AES128CMM_NONCE
);
3321 aead_request_set_crypt(req
, sg
, sg
, crypt_len
, iv
);
3322 aead_request_set_ad(req
, assoc_data_len
);
3324 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
3325 crypto_req_done
, &wait
);
3327 rc
= crypto_wait_req(enc
? crypto_aead_encrypt(req
)
3328 : crypto_aead_decrypt(req
), &wait
);
3331 memcpy(&tr_hdr
->Signature
, sign
, SMB2_SIGNATURE_SIZE
);
3342 smb3_free_compound_rqst(int num_rqst
, struct smb_rqst
*rqst
)
3346 for (i
= 0; i
< num_rqst
; i
++) {
3347 if (rqst
[i
].rq_pages
) {
3348 for (j
= rqst
[i
].rq_npages
- 1; j
>= 0; j
--)
3349 put_page(rqst
[i
].rq_pages
[j
]);
3350 kfree(rqst
[i
].rq_pages
);
3356 * This function will initialize new_rq and encrypt the content.
3357 * The first entry, new_rq[0], only contains a single iov which contains
3358 * a smb2_transform_hdr and is pre-allocated by the caller.
3359 * This function then populates new_rq[1+] with the content from olq_rq[0+].
3361 * The end result is an array of smb_rqst structures where the first structure
3362 * only contains a single iov for the transform header which we then can pass
3363 * to crypt_message().
3365 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
3366 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
3369 smb3_init_transform_rq(struct TCP_Server_Info
*server
, int num_rqst
,
3370 struct smb_rqst
*new_rq
, struct smb_rqst
*old_rq
)
3372 struct page
**pages
;
3373 struct smb2_transform_hdr
*tr_hdr
= new_rq
[0].rq_iov
[0].iov_base
;
3374 unsigned int npages
;
3375 unsigned int orig_len
= 0;
3379 for (i
= 1; i
< num_rqst
; i
++) {
3380 npages
= old_rq
[i
- 1].rq_npages
;
3381 pages
= kmalloc_array(npages
, sizeof(struct page
*),
3386 new_rq
[i
].rq_pages
= pages
;
3387 new_rq
[i
].rq_npages
= npages
;
3388 new_rq
[i
].rq_offset
= old_rq
[i
- 1].rq_offset
;
3389 new_rq
[i
].rq_pagesz
= old_rq
[i
- 1].rq_pagesz
;
3390 new_rq
[i
].rq_tailsz
= old_rq
[i
- 1].rq_tailsz
;
3391 new_rq
[i
].rq_iov
= old_rq
[i
- 1].rq_iov
;
3392 new_rq
[i
].rq_nvec
= old_rq
[i
- 1].rq_nvec
;
3394 orig_len
+= smb_rqst_len(server
, &old_rq
[i
- 1]);
3396 for (j
= 0; j
< npages
; j
++) {
3397 pages
[j
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
3402 /* copy pages form the old */
3403 for (j
= 0; j
< npages
; j
++) {
3405 unsigned int offset
, len
;
3407 rqst_page_get_length(&new_rq
[i
], j
, &len
, &offset
);
3409 dst
= (char *) kmap(new_rq
[i
].rq_pages
[j
]) + offset
;
3410 src
= (char *) kmap(old_rq
[i
- 1].rq_pages
[j
]) + offset
;
3412 memcpy(dst
, src
, len
);
3413 kunmap(new_rq
[i
].rq_pages
[j
]);
3414 kunmap(old_rq
[i
- 1].rq_pages
[j
]);
3418 /* fill the 1st iov with a transform header */
3419 fill_transform_hdr(tr_hdr
, orig_len
, old_rq
);
3421 rc
= crypt_message(server
, num_rqst
, new_rq
, 1);
3422 cifs_dbg(FYI
, "encrypt message returned %d", rc
);
3429 smb3_free_compound_rqst(num_rqst
- 1, &new_rq
[1]);
3434 smb3_is_transform_hdr(void *buf
)
3436 struct smb2_transform_hdr
*trhdr
= buf
;
3438 return trhdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
;
3442 decrypt_raw_data(struct TCP_Server_Info
*server
, char *buf
,
3443 unsigned int buf_data_size
, struct page
**pages
,
3444 unsigned int npages
, unsigned int page_data_size
)
3447 struct smb_rqst rqst
= {NULL
};
3450 iov
[0].iov_base
= buf
;
3451 iov
[0].iov_len
= sizeof(struct smb2_transform_hdr
);
3452 iov
[1].iov_base
= buf
+ sizeof(struct smb2_transform_hdr
);
3453 iov
[1].iov_len
= buf_data_size
;
3457 rqst
.rq_pages
= pages
;
3458 rqst
.rq_npages
= npages
;
3459 rqst
.rq_pagesz
= PAGE_SIZE
;
3460 rqst
.rq_tailsz
= (page_data_size
% PAGE_SIZE
) ? : PAGE_SIZE
;
3462 rc
= crypt_message(server
, 1, &rqst
, 0);
3463 cifs_dbg(FYI
, "decrypt message returned %d\n", rc
);
3468 memmove(buf
, iov
[1].iov_base
, buf_data_size
);
3470 server
->total_read
= buf_data_size
+ page_data_size
;
3476 read_data_into_pages(struct TCP_Server_Info
*server
, struct page
**pages
,
3477 unsigned int npages
, unsigned int len
)
3482 for (i
= 0; i
< npages
; i
++) {
3483 struct page
*page
= pages
[i
];
3487 if (len
>= PAGE_SIZE
) {
3488 /* enough data to fill the page */
3492 zero_user(page
, len
, PAGE_SIZE
- len
);
3495 length
= cifs_read_page_from_socket(server
, page
, 0, n
);
3498 server
->total_read
+= length
;
3505 init_read_bvec(struct page
**pages
, unsigned int npages
, unsigned int data_size
,
3506 unsigned int cur_off
, struct bio_vec
**page_vec
)
3508 struct bio_vec
*bvec
;
3511 bvec
= kcalloc(npages
, sizeof(struct bio_vec
), GFP_KERNEL
);
3515 for (i
= 0; i
< npages
; i
++) {
3516 bvec
[i
].bv_page
= pages
[i
];
3517 bvec
[i
].bv_offset
= (i
== 0) ? cur_off
: 0;
3518 bvec
[i
].bv_len
= min_t(unsigned int, PAGE_SIZE
, data_size
);
3519 data_size
-= bvec
[i
].bv_len
;
3522 if (data_size
!= 0) {
3523 cifs_dbg(VFS
, "%s: something went wrong\n", __func__
);
3533 handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
,
3534 char *buf
, unsigned int buf_len
, struct page
**pages
,
3535 unsigned int npages
, unsigned int page_data_size
)
3537 unsigned int data_offset
;
3538 unsigned int data_len
;
3539 unsigned int cur_off
;
3540 unsigned int cur_page_idx
;
3541 unsigned int pad_len
;
3542 struct cifs_readdata
*rdata
= mid
->callback_data
;
3543 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
3544 struct bio_vec
*bvec
= NULL
;
3545 struct iov_iter iter
;
3548 bool use_rdma_mr
= false;
3550 if (shdr
->Command
!= SMB2_READ
) {
3551 cifs_dbg(VFS
, "only big read responses are supported\n");
3555 if (server
->ops
->is_session_expired
&&
3556 server
->ops
->is_session_expired(buf
)) {
3557 cifs_reconnect(server
);
3558 wake_up(&server
->response_q
);
3562 if (server
->ops
->is_status_pending
&&
3563 server
->ops
->is_status_pending(buf
, server
))
3566 /* set up first two iov to get credits */
3567 rdata
->iov
[0].iov_base
= buf
;
3568 rdata
->iov
[0].iov_len
= 0;
3569 rdata
->iov
[1].iov_base
= buf
;
3570 rdata
->iov
[1].iov_len
=
3571 min_t(unsigned int, buf_len
, server
->vals
->read_rsp_size
);
3572 cifs_dbg(FYI
, "0: iov_base=%p iov_len=%zu\n",
3573 rdata
->iov
[0].iov_base
, rdata
->iov
[0].iov_len
);
3574 cifs_dbg(FYI
, "1: iov_base=%p iov_len=%zu\n",
3575 rdata
->iov
[1].iov_base
, rdata
->iov
[1].iov_len
);
3577 rdata
->result
= server
->ops
->map_error(buf
, true);
3578 if (rdata
->result
!= 0) {
3579 cifs_dbg(FYI
, "%s: server returned error %d\n",
3580 __func__
, rdata
->result
);
3581 /* normal error on read response */
3582 dequeue_mid(mid
, false);
3586 data_offset
= server
->ops
->read_data_offset(buf
);
3587 #ifdef CONFIG_CIFS_SMB_DIRECT
3588 use_rdma_mr
= rdata
->mr
;
3590 data_len
= server
->ops
->read_data_length(buf
, use_rdma_mr
);
3592 if (data_offset
< server
->vals
->read_rsp_size
) {
3594 * win2k8 sometimes sends an offset of 0 when the read
3595 * is beyond the EOF. Treat it as if the data starts just after
3598 cifs_dbg(FYI
, "%s: data offset (%u) inside read response header\n",
3599 __func__
, data_offset
);
3600 data_offset
= server
->vals
->read_rsp_size
;
3601 } else if (data_offset
> MAX_CIFS_SMALL_BUFFER_SIZE
) {
3602 /* data_offset is beyond the end of smallbuf */
3603 cifs_dbg(FYI
, "%s: data offset (%u) beyond end of smallbuf\n",
3604 __func__
, data_offset
);
3605 rdata
->result
= -EIO
;
3606 dequeue_mid(mid
, rdata
->result
);
3610 pad_len
= data_offset
- server
->vals
->read_rsp_size
;
3612 if (buf_len
<= data_offset
) {
3613 /* read response payload is in pages */
3614 cur_page_idx
= pad_len
/ PAGE_SIZE
;
3615 cur_off
= pad_len
% PAGE_SIZE
;
3617 if (cur_page_idx
!= 0) {
3618 /* data offset is beyond the 1st page of response */
3619 cifs_dbg(FYI
, "%s: data offset (%u) beyond 1st page of response\n",
3620 __func__
, data_offset
);
3621 rdata
->result
= -EIO
;
3622 dequeue_mid(mid
, rdata
->result
);
3626 if (data_len
> page_data_size
- pad_len
) {
3627 /* data_len is corrupt -- discard frame */
3628 rdata
->result
= -EIO
;
3629 dequeue_mid(mid
, rdata
->result
);
3633 rdata
->result
= init_read_bvec(pages
, npages
, page_data_size
,
3635 if (rdata
->result
!= 0) {
3636 dequeue_mid(mid
, rdata
->result
);
3640 iov_iter_bvec(&iter
, WRITE
, bvec
, npages
, data_len
);
3641 } else if (buf_len
>= data_offset
+ data_len
) {
3642 /* read response payload is in buf */
3643 WARN_ONCE(npages
> 0, "read data can be either in buf or in pages");
3644 iov
.iov_base
= buf
+ data_offset
;
3645 iov
.iov_len
= data_len
;
3646 iov_iter_kvec(&iter
, WRITE
, &iov
, 1, data_len
);
3648 /* read response payload cannot be in both buf and pages */
3649 WARN_ONCE(1, "buf can not contain only a part of read data");
3650 rdata
->result
= -EIO
;
3651 dequeue_mid(mid
, rdata
->result
);
3655 length
= rdata
->copy_into_pages(server
, rdata
, &iter
);
3662 dequeue_mid(mid
, false);
3667 receive_encrypted_read(struct TCP_Server_Info
*server
, struct mid_q_entry
**mid
)
3669 char *buf
= server
->smallbuf
;
3670 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
3671 unsigned int npages
;
3672 struct page
**pages
;
3674 unsigned int buflen
= server
->pdu_size
;
3678 len
= min_t(unsigned int, buflen
, server
->vals
->read_rsp_size
+
3679 sizeof(struct smb2_transform_hdr
)) - HEADER_SIZE(server
) + 1;
3681 rc
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1, len
);
3684 server
->total_read
+= rc
;
3686 len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
) -
3687 server
->vals
->read_rsp_size
;
3688 npages
= DIV_ROUND_UP(len
, PAGE_SIZE
);
3690 pages
= kmalloc_array(npages
, sizeof(struct page
*), GFP_KERNEL
);
3696 for (; i
< npages
; i
++) {
3697 pages
[i
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
3704 /* read read data into pages */
3705 rc
= read_data_into_pages(server
, pages
, npages
, len
);
3709 rc
= cifs_discard_remaining_data(server
);
3713 rc
= decrypt_raw_data(server
, buf
, server
->vals
->read_rsp_size
,
3714 pages
, npages
, len
);
3718 *mid
= smb2_find_mid(server
, buf
);
3720 cifs_dbg(FYI
, "mid not found\n");
3722 cifs_dbg(FYI
, "mid found\n");
3723 (*mid
)->decrypted
= true;
3724 rc
= handle_read_data(server
, *mid
, buf
,
3725 server
->vals
->read_rsp_size
,
3726 pages
, npages
, len
);
3730 for (i
= i
- 1; i
>= 0; i
--)
3735 cifs_discard_remaining_data(server
);
3740 receive_encrypted_standard(struct TCP_Server_Info
*server
,
3741 struct mid_q_entry
**mids
, char **bufs
,
3745 char *buf
= server
->smallbuf
;
3747 struct smb2_sync_hdr
*shdr
;
3748 unsigned int pdu_length
= server
->pdu_size
;
3749 unsigned int buf_size
;
3750 struct mid_q_entry
*mid_entry
;
3752 char *next_buffer
= NULL
;
3756 /* switch to large buffer if too big for a small one */
3757 if (pdu_length
> MAX_CIFS_SMALL_BUFFER_SIZE
) {
3758 server
->large_buf
= true;
3759 memcpy(server
->bigbuf
, buf
, server
->total_read
);
3760 buf
= server
->bigbuf
;
3763 /* now read the rest */
3764 length
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1,
3765 pdu_length
- HEADER_SIZE(server
) + 1);
3768 server
->total_read
+= length
;
3770 buf_size
= pdu_length
- sizeof(struct smb2_transform_hdr
);
3771 length
= decrypt_raw_data(server
, buf
, buf_size
, NULL
, 0, 0);
3775 next_is_large
= server
->large_buf
;
3777 shdr
= (struct smb2_sync_hdr
*)buf
;
3778 if (shdr
->NextCommand
) {
3779 if (next_is_large
) {
3780 tmpbuf
= server
->bigbuf
;
3781 next_buffer
= (char *)cifs_buf_get();
3783 tmpbuf
= server
->smallbuf
;
3784 next_buffer
= (char *)cifs_small_buf_get();
3787 tmpbuf
+ le32_to_cpu(shdr
->NextCommand
),
3788 pdu_length
- le32_to_cpu(shdr
->NextCommand
));
3791 mid_entry
= smb2_find_mid(server
, buf
);
3792 if (mid_entry
== NULL
)
3793 cifs_dbg(FYI
, "mid not found\n");
3795 cifs_dbg(FYI
, "mid found\n");
3796 mid_entry
->decrypted
= true;
3797 mid_entry
->resp_buf_size
= server
->pdu_size
;
3800 if (*num_mids
>= MAX_COMPOUND
) {
3801 cifs_dbg(VFS
, "too many PDUs in compound\n");
3804 bufs
[*num_mids
] = buf
;
3805 mids
[(*num_mids
)++] = mid_entry
;
3807 if (mid_entry
&& mid_entry
->handle
)
3808 ret
= mid_entry
->handle(server
, mid_entry
);
3810 ret
= cifs_handle_standard(server
, mid_entry
);
3812 if (ret
== 0 && shdr
->NextCommand
) {
3813 pdu_length
-= le32_to_cpu(shdr
->NextCommand
);
3814 server
->large_buf
= next_is_large
;
3816 server
->bigbuf
= next_buffer
;
3818 server
->smallbuf
= next_buffer
;
3820 buf
+= le32_to_cpu(shdr
->NextCommand
);
3828 smb3_receive_transform(struct TCP_Server_Info
*server
,
3829 struct mid_q_entry
**mids
, char **bufs
, int *num_mids
)
3831 char *buf
= server
->smallbuf
;
3832 unsigned int pdu_length
= server
->pdu_size
;
3833 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
3834 unsigned int orig_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
3836 if (pdu_length
< sizeof(struct smb2_transform_hdr
) +
3837 sizeof(struct smb2_sync_hdr
)) {
3838 cifs_dbg(VFS
, "Transform message is too small (%u)\n",
3840 cifs_reconnect(server
);
3841 wake_up(&server
->response_q
);
3842 return -ECONNABORTED
;
3845 if (pdu_length
< orig_len
+ sizeof(struct smb2_transform_hdr
)) {
3846 cifs_dbg(VFS
, "Transform message is broken\n");
3847 cifs_reconnect(server
);
3848 wake_up(&server
->response_q
);
3849 return -ECONNABORTED
;
3852 /* TODO: add support for compounds containing READ. */
3853 if (pdu_length
> CIFSMaxBufSize
+ MAX_HEADER_SIZE(server
)) {
3855 return receive_encrypted_read(server
, &mids
[0]);
3858 return receive_encrypted_standard(server
, mids
, bufs
, num_mids
);
3862 smb3_handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
)
3864 char *buf
= server
->large_buf
? server
->bigbuf
: server
->smallbuf
;
3866 return handle_read_data(server
, mid
, buf
, server
->pdu_size
,
3871 smb2_next_header(char *buf
)
3873 struct smb2_sync_hdr
*hdr
= (struct smb2_sync_hdr
*)buf
;
3874 struct smb2_transform_hdr
*t_hdr
= (struct smb2_transform_hdr
*)buf
;
3876 if (hdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
)
3877 return sizeof(struct smb2_transform_hdr
) +
3878 le32_to_cpu(t_hdr
->OriginalMessageSize
);
3880 return le32_to_cpu(hdr
->NextCommand
);
3884 smb2_make_node(unsigned int xid
, struct inode
*inode
,
3885 struct dentry
*dentry
, struct cifs_tcon
*tcon
,
3886 char *full_path
, umode_t mode
, dev_t dev
)
3888 struct cifs_sb_info
*cifs_sb
= CIFS_SB(inode
->i_sb
);
3890 int create_options
= CREATE_NOT_DIR
| CREATE_OPTION_SPECIAL
;
3891 FILE_ALL_INFO
*buf
= NULL
;
3892 struct cifs_io_parms io_parms
;
3894 struct cifs_fid fid
;
3895 struct cifs_open_parms oparms
;
3896 unsigned int bytes_written
;
3897 struct win_dev
*pdev
;
3901 * Check if mounted with mount parm 'sfu' mount parm.
3902 * SFU emulation should work with all servers, but only
3903 * supports block and char device (no socket & fifo),
3904 * and was used by default in earlier versions of Windows
3906 if (!(cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_UNX_EMUL
))
3910 * TODO: Add ability to create instead via reparse point. Windows (e.g.
3911 * their current NFS server) uses this approach to expose special files
3912 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
3915 if (!S_ISCHR(mode
) && !S_ISBLK(mode
))
3918 cifs_dbg(FYI
, "sfu compat create special file\n");
3920 buf
= kmalloc(sizeof(FILE_ALL_INFO
), GFP_KERNEL
);
3926 if (backup_cred(cifs_sb
))
3927 create_options
|= CREATE_OPEN_BACKUP_INTENT
;
3930 oparms
.cifs_sb
= cifs_sb
;
3931 oparms
.desired_access
= GENERIC_WRITE
;
3932 oparms
.create_options
= create_options
;
3933 oparms
.disposition
= FILE_CREATE
;
3934 oparms
.path
= full_path
;
3936 oparms
.reconnect
= false;
3938 if (tcon
->ses
->server
->oplocks
)
3939 oplock
= REQ_OPLOCK
;
3942 rc
= tcon
->ses
->server
->ops
->open(xid
, &oparms
, &oplock
, buf
);
3947 * BB Do not bother to decode buf since no local inode yet to put
3948 * timestamps in, but we can reuse it safely.
3951 pdev
= (struct win_dev
*)buf
;
3952 io_parms
.pid
= current
->tgid
;
3953 io_parms
.tcon
= tcon
;
3954 io_parms
.offset
= 0;
3955 io_parms
.length
= sizeof(struct win_dev
);
3956 iov
[1].iov_base
= buf
;
3957 iov
[1].iov_len
= sizeof(struct win_dev
);
3958 if (S_ISCHR(mode
)) {
3959 memcpy(pdev
->type
, "IntxCHR", 8);
3960 pdev
->major
= cpu_to_le64(MAJOR(dev
));
3961 pdev
->minor
= cpu_to_le64(MINOR(dev
));
3962 rc
= tcon
->ses
->server
->ops
->sync_write(xid
, &fid
, &io_parms
,
3963 &bytes_written
, iov
, 1);
3964 } else if (S_ISBLK(mode
)) {
3965 memcpy(pdev
->type
, "IntxBLK", 8);
3966 pdev
->major
= cpu_to_le64(MAJOR(dev
));
3967 pdev
->minor
= cpu_to_le64(MINOR(dev
));
3968 rc
= tcon
->ses
->server
->ops
->sync_write(xid
, &fid
, &io_parms
,
3969 &bytes_written
, iov
, 1);
3971 tcon
->ses
->server
->ops
->close(xid
, tcon
, &fid
);
3974 /* FIXME: add code here to set EAs */
3981 struct smb_version_operations smb20_operations
= {
3982 .compare_fids
= smb2_compare_fids
,
3983 .setup_request
= smb2_setup_request
,
3984 .setup_async_request
= smb2_setup_async_request
,
3985 .check_receive
= smb2_check_receive
,
3986 .add_credits
= smb2_add_credits
,
3987 .set_credits
= smb2_set_credits
,
3988 .get_credits_field
= smb2_get_credits_field
,
3989 .get_credits
= smb2_get_credits
,
3990 .wait_mtu_credits
= cifs_wait_mtu_credits
,
3991 .get_next_mid
= smb2_get_next_mid
,
3992 .revert_current_mid
= smb2_revert_current_mid
,
3993 .read_data_offset
= smb2_read_data_offset
,
3994 .read_data_length
= smb2_read_data_length
,
3995 .map_error
= map_smb2_to_linux_error
,
3996 .find_mid
= smb2_find_mid
,
3997 .check_message
= smb2_check_message
,
3998 .dump_detail
= smb2_dump_detail
,
3999 .clear_stats
= smb2_clear_stats
,
4000 .print_stats
= smb2_print_stats
,
4001 .is_oplock_break
= smb2_is_valid_oplock_break
,
4002 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
4003 .downgrade_oplock
= smb2_downgrade_oplock
,
4004 .need_neg
= smb2_need_neg
,
4005 .negotiate
= smb2_negotiate
,
4006 .negotiate_wsize
= smb2_negotiate_wsize
,
4007 .negotiate_rsize
= smb2_negotiate_rsize
,
4008 .sess_setup
= SMB2_sess_setup
,
4009 .logoff
= SMB2_logoff
,
4010 .tree_connect
= SMB2_tcon
,
4011 .tree_disconnect
= SMB2_tdis
,
4012 .qfs_tcon
= smb2_qfs_tcon
,
4013 .is_path_accessible
= smb2_is_path_accessible
,
4014 .can_echo
= smb2_can_echo
,
4016 .query_path_info
= smb2_query_path_info
,
4017 .get_srv_inum
= smb2_get_srv_inum
,
4018 .query_file_info
= smb2_query_file_info
,
4019 .set_path_size
= smb2_set_path_size
,
4020 .set_file_size
= smb2_set_file_size
,
4021 .set_file_info
= smb2_set_file_info
,
4022 .set_compression
= smb2_set_compression
,
4023 .mkdir
= smb2_mkdir
,
4024 .mkdir_setinfo
= smb2_mkdir_setinfo
,
4025 .rmdir
= smb2_rmdir
,
4026 .unlink
= smb2_unlink
,
4027 .rename
= smb2_rename_path
,
4028 .create_hardlink
= smb2_create_hardlink
,
4029 .query_symlink
= smb2_query_symlink
,
4030 .query_mf_symlink
= smb3_query_mf_symlink
,
4031 .create_mf_symlink
= smb3_create_mf_symlink
,
4032 .open
= smb2_open_file
,
4033 .set_fid
= smb2_set_fid
,
4034 .close
= smb2_close_file
,
4035 .flush
= smb2_flush_file
,
4036 .async_readv
= smb2_async_readv
,
4037 .async_writev
= smb2_async_writev
,
4038 .sync_read
= smb2_sync_read
,
4039 .sync_write
= smb2_sync_write
,
4040 .query_dir_first
= smb2_query_dir_first
,
4041 .query_dir_next
= smb2_query_dir_next
,
4042 .close_dir
= smb2_close_dir
,
4043 .calc_smb_size
= smb2_calc_size
,
4044 .is_status_pending
= smb2_is_status_pending
,
4045 .is_session_expired
= smb2_is_session_expired
,
4046 .oplock_response
= smb2_oplock_response
,
4047 .queryfs
= smb2_queryfs
,
4048 .mand_lock
= smb2_mand_lock
,
4049 .mand_unlock_range
= smb2_unlock_range
,
4050 .push_mand_locks
= smb2_push_mandatory_locks
,
4051 .get_lease_key
= smb2_get_lease_key
,
4052 .set_lease_key
= smb2_set_lease_key
,
4053 .new_lease_key
= smb2_new_lease_key
,
4054 .calc_signature
= smb2_calc_signature
,
4055 .is_read_op
= smb2_is_read_op
,
4056 .set_oplock_level
= smb2_set_oplock_level
,
4057 .create_lease_buf
= smb2_create_lease_buf
,
4058 .parse_lease_buf
= smb2_parse_lease_buf
,
4059 .copychunk_range
= smb2_copychunk_range
,
4060 .wp_retry_size
= smb2_wp_retry_size
,
4061 .dir_needs_close
= smb2_dir_needs_close
,
4062 .get_dfs_refer
= smb2_get_dfs_refer
,
4063 .select_sectype
= smb2_select_sectype
,
4064 #ifdef CONFIG_CIFS_XATTR
4065 .query_all_EAs
= smb2_query_eas
,
4066 .set_EA
= smb2_set_ea
,
4067 #endif /* CIFS_XATTR */
4068 #ifdef CONFIG_CIFS_ACL
4069 .get_acl
= get_smb2_acl
,
4070 .get_acl_by_fid
= get_smb2_acl_by_fid
,
4071 .set_acl
= set_smb2_acl
,
4072 #endif /* CIFS_ACL */
4073 .next_header
= smb2_next_header
,
4074 .ioctl_query_info
= smb2_ioctl_query_info
,
4075 .make_node
= smb2_make_node
,
4078 struct smb_version_operations smb21_operations
= {
4079 .compare_fids
= smb2_compare_fids
,
4080 .setup_request
= smb2_setup_request
,
4081 .setup_async_request
= smb2_setup_async_request
,
4082 .check_receive
= smb2_check_receive
,
4083 .add_credits
= smb2_add_credits
,
4084 .set_credits
= smb2_set_credits
,
4085 .get_credits_field
= smb2_get_credits_field
,
4086 .get_credits
= smb2_get_credits
,
4087 .wait_mtu_credits
= smb2_wait_mtu_credits
,
4088 .adjust_credits
= smb2_adjust_credits
,
4089 .get_next_mid
= smb2_get_next_mid
,
4090 .revert_current_mid
= smb2_revert_current_mid
,
4091 .read_data_offset
= smb2_read_data_offset
,
4092 .read_data_length
= smb2_read_data_length
,
4093 .map_error
= map_smb2_to_linux_error
,
4094 .find_mid
= smb2_find_mid
,
4095 .check_message
= smb2_check_message
,
4096 .dump_detail
= smb2_dump_detail
,
4097 .clear_stats
= smb2_clear_stats
,
4098 .print_stats
= smb2_print_stats
,
4099 .is_oplock_break
= smb2_is_valid_oplock_break
,
4100 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
4101 .downgrade_oplock
= smb21_downgrade_oplock
,
4102 .need_neg
= smb2_need_neg
,
4103 .negotiate
= smb2_negotiate
,
4104 .negotiate_wsize
= smb2_negotiate_wsize
,
4105 .negotiate_rsize
= smb2_negotiate_rsize
,
4106 .sess_setup
= SMB2_sess_setup
,
4107 .logoff
= SMB2_logoff
,
4108 .tree_connect
= SMB2_tcon
,
4109 .tree_disconnect
= SMB2_tdis
,
4110 .qfs_tcon
= smb2_qfs_tcon
,
4111 .is_path_accessible
= smb2_is_path_accessible
,
4112 .can_echo
= smb2_can_echo
,
4114 .query_path_info
= smb2_query_path_info
,
4115 .get_srv_inum
= smb2_get_srv_inum
,
4116 .query_file_info
= smb2_query_file_info
,
4117 .set_path_size
= smb2_set_path_size
,
4118 .set_file_size
= smb2_set_file_size
,
4119 .set_file_info
= smb2_set_file_info
,
4120 .set_compression
= smb2_set_compression
,
4121 .mkdir
= smb2_mkdir
,
4122 .mkdir_setinfo
= smb2_mkdir_setinfo
,
4123 .rmdir
= smb2_rmdir
,
4124 .unlink
= smb2_unlink
,
4125 .rename
= smb2_rename_path
,
4126 .create_hardlink
= smb2_create_hardlink
,
4127 .query_symlink
= smb2_query_symlink
,
4128 .query_mf_symlink
= smb3_query_mf_symlink
,
4129 .create_mf_symlink
= smb3_create_mf_symlink
,
4130 .open
= smb2_open_file
,
4131 .set_fid
= smb2_set_fid
,
4132 .close
= smb2_close_file
,
4133 .flush
= smb2_flush_file
,
4134 .async_readv
= smb2_async_readv
,
4135 .async_writev
= smb2_async_writev
,
4136 .sync_read
= smb2_sync_read
,
4137 .sync_write
= smb2_sync_write
,
4138 .query_dir_first
= smb2_query_dir_first
,
4139 .query_dir_next
= smb2_query_dir_next
,
4140 .close_dir
= smb2_close_dir
,
4141 .calc_smb_size
= smb2_calc_size
,
4142 .is_status_pending
= smb2_is_status_pending
,
4143 .is_session_expired
= smb2_is_session_expired
,
4144 .oplock_response
= smb2_oplock_response
,
4145 .queryfs
= smb2_queryfs
,
4146 .mand_lock
= smb2_mand_lock
,
4147 .mand_unlock_range
= smb2_unlock_range
,
4148 .push_mand_locks
= smb2_push_mandatory_locks
,
4149 .get_lease_key
= smb2_get_lease_key
,
4150 .set_lease_key
= smb2_set_lease_key
,
4151 .new_lease_key
= smb2_new_lease_key
,
4152 .calc_signature
= smb2_calc_signature
,
4153 .is_read_op
= smb21_is_read_op
,
4154 .set_oplock_level
= smb21_set_oplock_level
,
4155 .create_lease_buf
= smb2_create_lease_buf
,
4156 .parse_lease_buf
= smb2_parse_lease_buf
,
4157 .copychunk_range
= smb2_copychunk_range
,
4158 .wp_retry_size
= smb2_wp_retry_size
,
4159 .dir_needs_close
= smb2_dir_needs_close
,
4160 .enum_snapshots
= smb3_enum_snapshots
,
4161 .get_dfs_refer
= smb2_get_dfs_refer
,
4162 .select_sectype
= smb2_select_sectype
,
4163 #ifdef CONFIG_CIFS_XATTR
4164 .query_all_EAs
= smb2_query_eas
,
4165 .set_EA
= smb2_set_ea
,
4166 #endif /* CIFS_XATTR */
4167 #ifdef CONFIG_CIFS_ACL
4168 .get_acl
= get_smb2_acl
,
4169 .get_acl_by_fid
= get_smb2_acl_by_fid
,
4170 .set_acl
= set_smb2_acl
,
4171 #endif /* CIFS_ACL */
4172 .next_header
= smb2_next_header
,
4173 .ioctl_query_info
= smb2_ioctl_query_info
,
4174 .make_node
= smb2_make_node
,
4177 struct smb_version_operations smb30_operations
= {
4178 .compare_fids
= smb2_compare_fids
,
4179 .setup_request
= smb2_setup_request
,
4180 .setup_async_request
= smb2_setup_async_request
,
4181 .check_receive
= smb2_check_receive
,
4182 .add_credits
= smb2_add_credits
,
4183 .set_credits
= smb2_set_credits
,
4184 .get_credits_field
= smb2_get_credits_field
,
4185 .get_credits
= smb2_get_credits
,
4186 .wait_mtu_credits
= smb2_wait_mtu_credits
,
4187 .adjust_credits
= smb2_adjust_credits
,
4188 .get_next_mid
= smb2_get_next_mid
,
4189 .revert_current_mid
= smb2_revert_current_mid
,
4190 .read_data_offset
= smb2_read_data_offset
,
4191 .read_data_length
= smb2_read_data_length
,
4192 .map_error
= map_smb2_to_linux_error
,
4193 .find_mid
= smb2_find_mid
,
4194 .check_message
= smb2_check_message
,
4195 .dump_detail
= smb2_dump_detail
,
4196 .clear_stats
= smb2_clear_stats
,
4197 .print_stats
= smb2_print_stats
,
4198 .dump_share_caps
= smb2_dump_share_caps
,
4199 .is_oplock_break
= smb2_is_valid_oplock_break
,
4200 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
4201 .downgrade_oplock
= smb21_downgrade_oplock
,
4202 .need_neg
= smb2_need_neg
,
4203 .negotiate
= smb2_negotiate
,
4204 .negotiate_wsize
= smb3_negotiate_wsize
,
4205 .negotiate_rsize
= smb3_negotiate_rsize
,
4206 .sess_setup
= SMB2_sess_setup
,
4207 .logoff
= SMB2_logoff
,
4208 .tree_connect
= SMB2_tcon
,
4209 .tree_disconnect
= SMB2_tdis
,
4210 .qfs_tcon
= smb3_qfs_tcon
,
4211 .is_path_accessible
= smb2_is_path_accessible
,
4212 .can_echo
= smb2_can_echo
,
4214 .query_path_info
= smb2_query_path_info
,
4215 .get_srv_inum
= smb2_get_srv_inum
,
4216 .query_file_info
= smb2_query_file_info
,
4217 .set_path_size
= smb2_set_path_size
,
4218 .set_file_size
= smb2_set_file_size
,
4219 .set_file_info
= smb2_set_file_info
,
4220 .set_compression
= smb2_set_compression
,
4221 .mkdir
= smb2_mkdir
,
4222 .mkdir_setinfo
= smb2_mkdir_setinfo
,
4223 .rmdir
= smb2_rmdir
,
4224 .unlink
= smb2_unlink
,
4225 .rename
= smb2_rename_path
,
4226 .create_hardlink
= smb2_create_hardlink
,
4227 .query_symlink
= smb2_query_symlink
,
4228 .query_mf_symlink
= smb3_query_mf_symlink
,
4229 .create_mf_symlink
= smb3_create_mf_symlink
,
4230 .open
= smb2_open_file
,
4231 .set_fid
= smb2_set_fid
,
4232 .close
= smb2_close_file
,
4233 .flush
= smb2_flush_file
,
4234 .async_readv
= smb2_async_readv
,
4235 .async_writev
= smb2_async_writev
,
4236 .sync_read
= smb2_sync_read
,
4237 .sync_write
= smb2_sync_write
,
4238 .query_dir_first
= smb2_query_dir_first
,
4239 .query_dir_next
= smb2_query_dir_next
,
4240 .close_dir
= smb2_close_dir
,
4241 .calc_smb_size
= smb2_calc_size
,
4242 .is_status_pending
= smb2_is_status_pending
,
4243 .is_session_expired
= smb2_is_session_expired
,
4244 .oplock_response
= smb2_oplock_response
,
4245 .queryfs
= smb2_queryfs
,
4246 .mand_lock
= smb2_mand_lock
,
4247 .mand_unlock_range
= smb2_unlock_range
,
4248 .push_mand_locks
= smb2_push_mandatory_locks
,
4249 .get_lease_key
= smb2_get_lease_key
,
4250 .set_lease_key
= smb2_set_lease_key
,
4251 .new_lease_key
= smb2_new_lease_key
,
4252 .generate_signingkey
= generate_smb30signingkey
,
4253 .calc_signature
= smb3_calc_signature
,
4254 .set_integrity
= smb3_set_integrity
,
4255 .is_read_op
= smb21_is_read_op
,
4256 .set_oplock_level
= smb3_set_oplock_level
,
4257 .create_lease_buf
= smb3_create_lease_buf
,
4258 .parse_lease_buf
= smb3_parse_lease_buf
,
4259 .copychunk_range
= smb2_copychunk_range
,
4260 .duplicate_extents
= smb2_duplicate_extents
,
4261 .validate_negotiate
= smb3_validate_negotiate
,
4262 .wp_retry_size
= smb2_wp_retry_size
,
4263 .dir_needs_close
= smb2_dir_needs_close
,
4264 .fallocate
= smb3_fallocate
,
4265 .enum_snapshots
= smb3_enum_snapshots
,
4266 .init_transform_rq
= smb3_init_transform_rq
,
4267 .is_transform_hdr
= smb3_is_transform_hdr
,
4268 .receive_transform
= smb3_receive_transform
,
4269 .get_dfs_refer
= smb2_get_dfs_refer
,
4270 .select_sectype
= smb2_select_sectype
,
4271 #ifdef CONFIG_CIFS_XATTR
4272 .query_all_EAs
= smb2_query_eas
,
4273 .set_EA
= smb2_set_ea
,
4274 #endif /* CIFS_XATTR */
4275 #ifdef CONFIG_CIFS_ACL
4276 .get_acl
= get_smb2_acl
,
4277 .get_acl_by_fid
= get_smb2_acl_by_fid
,
4278 .set_acl
= set_smb2_acl
,
4279 #endif /* CIFS_ACL */
4280 .next_header
= smb2_next_header
,
4281 .ioctl_query_info
= smb2_ioctl_query_info
,
4282 .make_node
= smb2_make_node
,
4285 struct smb_version_operations smb311_operations
= {
4286 .compare_fids
= smb2_compare_fids
,
4287 .setup_request
= smb2_setup_request
,
4288 .setup_async_request
= smb2_setup_async_request
,
4289 .check_receive
= smb2_check_receive
,
4290 .add_credits
= smb2_add_credits
,
4291 .set_credits
= smb2_set_credits
,
4292 .get_credits_field
= smb2_get_credits_field
,
4293 .get_credits
= smb2_get_credits
,
4294 .wait_mtu_credits
= smb2_wait_mtu_credits
,
4295 .adjust_credits
= smb2_adjust_credits
,
4296 .get_next_mid
= smb2_get_next_mid
,
4297 .revert_current_mid
= smb2_revert_current_mid
,
4298 .read_data_offset
= smb2_read_data_offset
,
4299 .read_data_length
= smb2_read_data_length
,
4300 .map_error
= map_smb2_to_linux_error
,
4301 .find_mid
= smb2_find_mid
,
4302 .check_message
= smb2_check_message
,
4303 .dump_detail
= smb2_dump_detail
,
4304 .clear_stats
= smb2_clear_stats
,
4305 .print_stats
= smb2_print_stats
,
4306 .dump_share_caps
= smb2_dump_share_caps
,
4307 .is_oplock_break
= smb2_is_valid_oplock_break
,
4308 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
4309 .downgrade_oplock
= smb21_downgrade_oplock
,
4310 .need_neg
= smb2_need_neg
,
4311 .negotiate
= smb2_negotiate
,
4312 .negotiate_wsize
= smb3_negotiate_wsize
,
4313 .negotiate_rsize
= smb3_negotiate_rsize
,
4314 .sess_setup
= SMB2_sess_setup
,
4315 .logoff
= SMB2_logoff
,
4316 .tree_connect
= SMB2_tcon
,
4317 .tree_disconnect
= SMB2_tdis
,
4318 .qfs_tcon
= smb3_qfs_tcon
,
4319 .is_path_accessible
= smb2_is_path_accessible
,
4320 .can_echo
= smb2_can_echo
,
4322 .query_path_info
= smb2_query_path_info
,
4323 .get_srv_inum
= smb2_get_srv_inum
,
4324 .query_file_info
= smb2_query_file_info
,
4325 .set_path_size
= smb2_set_path_size
,
4326 .set_file_size
= smb2_set_file_size
,
4327 .set_file_info
= smb2_set_file_info
,
4328 .set_compression
= smb2_set_compression
,
4329 .mkdir
= smb2_mkdir
,
4330 .mkdir_setinfo
= smb2_mkdir_setinfo
,
4331 .posix_mkdir
= smb311_posix_mkdir
,
4332 .rmdir
= smb2_rmdir
,
4333 .unlink
= smb2_unlink
,
4334 .rename
= smb2_rename_path
,
4335 .create_hardlink
= smb2_create_hardlink
,
4336 .query_symlink
= smb2_query_symlink
,
4337 .query_mf_symlink
= smb3_query_mf_symlink
,
4338 .create_mf_symlink
= smb3_create_mf_symlink
,
4339 .open
= smb2_open_file
,
4340 .set_fid
= smb2_set_fid
,
4341 .close
= smb2_close_file
,
4342 .flush
= smb2_flush_file
,
4343 .async_readv
= smb2_async_readv
,
4344 .async_writev
= smb2_async_writev
,
4345 .sync_read
= smb2_sync_read
,
4346 .sync_write
= smb2_sync_write
,
4347 .query_dir_first
= smb2_query_dir_first
,
4348 .query_dir_next
= smb2_query_dir_next
,
4349 .close_dir
= smb2_close_dir
,
4350 .calc_smb_size
= smb2_calc_size
,
4351 .is_status_pending
= smb2_is_status_pending
,
4352 .is_session_expired
= smb2_is_session_expired
,
4353 .oplock_response
= smb2_oplock_response
,
4354 .queryfs
= smb311_queryfs
,
4355 .mand_lock
= smb2_mand_lock
,
4356 .mand_unlock_range
= smb2_unlock_range
,
4357 .push_mand_locks
= smb2_push_mandatory_locks
,
4358 .get_lease_key
= smb2_get_lease_key
,
4359 .set_lease_key
= smb2_set_lease_key
,
4360 .new_lease_key
= smb2_new_lease_key
,
4361 .generate_signingkey
= generate_smb311signingkey
,
4362 .calc_signature
= smb3_calc_signature
,
4363 .set_integrity
= smb3_set_integrity
,
4364 .is_read_op
= smb21_is_read_op
,
4365 .set_oplock_level
= smb3_set_oplock_level
,
4366 .create_lease_buf
= smb3_create_lease_buf
,
4367 .parse_lease_buf
= smb3_parse_lease_buf
,
4368 .copychunk_range
= smb2_copychunk_range
,
4369 .duplicate_extents
= smb2_duplicate_extents
,
4370 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
4371 .wp_retry_size
= smb2_wp_retry_size
,
4372 .dir_needs_close
= smb2_dir_needs_close
,
4373 .fallocate
= smb3_fallocate
,
4374 .enum_snapshots
= smb3_enum_snapshots
,
4375 .init_transform_rq
= smb3_init_transform_rq
,
4376 .is_transform_hdr
= smb3_is_transform_hdr
,
4377 .receive_transform
= smb3_receive_transform
,
4378 .get_dfs_refer
= smb2_get_dfs_refer
,
4379 .select_sectype
= smb2_select_sectype
,
4380 #ifdef CONFIG_CIFS_XATTR
4381 .query_all_EAs
= smb2_query_eas
,
4382 .set_EA
= smb2_set_ea
,
4383 #endif /* CIFS_XATTR */
4384 #ifdef CONFIG_CIFS_ACL
4385 .get_acl
= get_smb2_acl
,
4386 .get_acl_by_fid
= get_smb2_acl_by_fid
,
4387 .set_acl
= set_smb2_acl
,
4388 #endif /* CIFS_ACL */
4389 .next_header
= smb2_next_header
,
4390 .ioctl_query_info
= smb2_ioctl_query_info
,
4391 .make_node
= smb2_make_node
,
4394 struct smb_version_values smb20_values
= {
4395 .version_string
= SMB20_VERSION_STRING
,
4396 .protocol_id
= SMB20_PROT_ID
,
4397 .req_capabilities
= 0, /* MBZ */
4398 .large_lock_type
= 0,
4399 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
4400 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
4401 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
4402 .header_size
= sizeof(struct smb2_sync_hdr
),
4403 .header_preamble_size
= 0,
4404 .max_header_size
= MAX_SMB2_HDR_SIZE
,
4405 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
4406 .lock_cmd
= SMB2_LOCK
,
4408 .cap_nt_find
= SMB2_NT_FIND
,
4409 .cap_large_files
= SMB2_LARGE_FILES
,
4410 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4411 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4412 .create_lease_size
= sizeof(struct create_lease
),
4415 struct smb_version_values smb21_values
= {
4416 .version_string
= SMB21_VERSION_STRING
,
4417 .protocol_id
= SMB21_PROT_ID
,
4418 .req_capabilities
= 0, /* MBZ on negotiate req until SMB3 dialect */
4419 .large_lock_type
= 0,
4420 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
4421 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
4422 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
4423 .header_size
= sizeof(struct smb2_sync_hdr
),
4424 .header_preamble_size
= 0,
4425 .max_header_size
= MAX_SMB2_HDR_SIZE
,
4426 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
4427 .lock_cmd
= SMB2_LOCK
,
4429 .cap_nt_find
= SMB2_NT_FIND
,
4430 .cap_large_files
= SMB2_LARGE_FILES
,
4431 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4432 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4433 .create_lease_size
= sizeof(struct create_lease
),
4436 struct smb_version_values smb3any_values
= {
4437 .version_string
= SMB3ANY_VERSION_STRING
,
4438 .protocol_id
= SMB302_PROT_ID
, /* doesn't matter, send protocol array */
4439 .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
,
4440 .large_lock_type
= 0,
4441 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
4442 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
4443 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
4444 .header_size
= sizeof(struct smb2_sync_hdr
),
4445 .header_preamble_size
= 0,
4446 .max_header_size
= MAX_SMB2_HDR_SIZE
,
4447 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
4448 .lock_cmd
= SMB2_LOCK
,
4450 .cap_nt_find
= SMB2_NT_FIND
,
4451 .cap_large_files
= SMB2_LARGE_FILES
,
4452 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4453 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4454 .create_lease_size
= sizeof(struct create_lease_v2
),
4457 struct smb_version_values smbdefault_values
= {
4458 .version_string
= SMBDEFAULT_VERSION_STRING
,
4459 .protocol_id
= SMB302_PROT_ID
, /* doesn't matter, send protocol array */
4460 .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
,
4461 .large_lock_type
= 0,
4462 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
4463 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
4464 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
4465 .header_size
= sizeof(struct smb2_sync_hdr
),
4466 .header_preamble_size
= 0,
4467 .max_header_size
= MAX_SMB2_HDR_SIZE
,
4468 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
4469 .lock_cmd
= SMB2_LOCK
,
4471 .cap_nt_find
= SMB2_NT_FIND
,
4472 .cap_large_files
= SMB2_LARGE_FILES
,
4473 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4474 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4475 .create_lease_size
= sizeof(struct create_lease_v2
),
4478 struct smb_version_values smb30_values
= {
4479 .version_string
= SMB30_VERSION_STRING
,
4480 .protocol_id
= SMB30_PROT_ID
,
4481 .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
,
4482 .large_lock_type
= 0,
4483 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
4484 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
4485 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
4486 .header_size
= sizeof(struct smb2_sync_hdr
),
4487 .header_preamble_size
= 0,
4488 .max_header_size
= MAX_SMB2_HDR_SIZE
,
4489 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
4490 .lock_cmd
= SMB2_LOCK
,
4492 .cap_nt_find
= SMB2_NT_FIND
,
4493 .cap_large_files
= SMB2_LARGE_FILES
,
4494 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4495 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4496 .create_lease_size
= sizeof(struct create_lease_v2
),
4499 struct smb_version_values smb302_values
= {
4500 .version_string
= SMB302_VERSION_STRING
,
4501 .protocol_id
= SMB302_PROT_ID
,
4502 .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
,
4503 .large_lock_type
= 0,
4504 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
4505 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
4506 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
4507 .header_size
= sizeof(struct smb2_sync_hdr
),
4508 .header_preamble_size
= 0,
4509 .max_header_size
= MAX_SMB2_HDR_SIZE
,
4510 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
4511 .lock_cmd
= SMB2_LOCK
,
4513 .cap_nt_find
= SMB2_NT_FIND
,
4514 .cap_large_files
= SMB2_LARGE_FILES
,
4515 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4516 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4517 .create_lease_size
= sizeof(struct create_lease_v2
),
4520 struct smb_version_values smb311_values
= {
4521 .version_string
= SMB311_VERSION_STRING
,
4522 .protocol_id
= SMB311_PROT_ID
,
4523 .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
,
4524 .large_lock_type
= 0,
4525 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
4526 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
4527 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
4528 .header_size
= sizeof(struct smb2_sync_hdr
),
4529 .header_preamble_size
= 0,
4530 .max_header_size
= MAX_SMB2_HDR_SIZE
,
4531 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
4532 .lock_cmd
= SMB2_LOCK
,
4534 .cap_nt_find
= SMB2_NT_FIND
,
4535 .cap_large_files
= SMB2_LARGE_FILES
,
4536 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4537 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
4538 .create_lease_size
= sizeof(struct create_lease_v2
),