1 // SPDX-License-Identifier: GPL-2.0
3 * SMB2 version specific operations
5 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
8 #include <linux/pagemap.h>
10 #include <linux/falloc.h>
11 #include <linux/scatterlist.h>
12 #include <linux/uuid.h>
13 #include <linux/sort.h>
14 #include <crypto/aead.h>
15 #include <linux/fiemap.h>
19 #include "smb2proto.h"
20 #include "cifsproto.h"
21 #include "cifs_debug.h"
22 #include "cifs_unicode.h"
23 #include "smb2status.h"
25 #include "cifs_ioctl.h"
26 #include "smbdirect.h"
27 #include "fs_context.h"
29 /* Change credits for different ops and return the total number of credits */
31 change_conf(struct TCP_Server_Info
*server
)
33 server
->credits
+= server
->echo_credits
+ server
->oplock_credits
;
34 server
->oplock_credits
= server
->echo_credits
= 0;
35 switch (server
->credits
) {
39 server
->echoes
= false;
40 server
->oplocks
= false;
43 server
->echoes
= true;
44 server
->oplocks
= false;
45 server
->echo_credits
= 1;
48 server
->echoes
= true;
50 server
->oplocks
= true;
51 server
->oplock_credits
= 1;
53 server
->oplocks
= false;
55 server
->echo_credits
= 1;
57 server
->credits
-= server
->echo_credits
+ server
->oplock_credits
;
58 return server
->credits
+ server
->echo_credits
+ server
->oplock_credits
;
62 smb2_add_credits(struct TCP_Server_Info
*server
,
63 const struct cifs_credits
*credits
, const int optype
)
66 int scredits
, in_flight
;
67 unsigned int add
= credits
->value
;
68 unsigned int instance
= credits
->instance
;
69 bool reconnect_detected
= false;
70 bool reconnect_with_invalid_credits
= false;
72 spin_lock(&server
->req_lock
);
73 val
= server
->ops
->get_credits_field(server
, optype
);
75 /* eg found case where write overlapping reconnect messed up credits */
76 if (((optype
& CIFS_OP_MASK
) == CIFS_NEG_OP
) && (*val
!= 0))
77 reconnect_with_invalid_credits
= true;
79 if ((instance
== 0) || (instance
== server
->reconnect_instance
))
82 reconnect_detected
= true;
85 *val
= 65000; /* Don't get near 64K credits, avoid srv bugs */
86 pr_warn_once("server overflowed SMB3 credits\n");
89 if (server
->in_flight
== 0 &&
90 ((optype
& CIFS_OP_MASK
) != CIFS_NEG_OP
) &&
91 ((optype
& CIFS_OP_MASK
) != CIFS_SESS_OP
))
92 rc
= change_conf(server
);
94 * Sometimes server returns 0 credits on oplock break ack - we need to
95 * rebalance credits in this case.
97 else if (server
->in_flight
> 0 && server
->oplock_credits
== 0 &&
99 if (server
->credits
> 1) {
101 server
->oplock_credits
++;
105 in_flight
= server
->in_flight
;
106 spin_unlock(&server
->req_lock
);
107 wake_up(&server
->request_q
);
109 if (reconnect_detected
) {
110 trace_smb3_reconnect_detected(server
->CurrentMid
,
111 server
->conn_id
, server
->hostname
, scredits
, add
, in_flight
);
113 cifs_dbg(FYI
, "trying to put %d credits from the old server instance %d\n",
117 if (reconnect_with_invalid_credits
) {
118 trace_smb3_reconnect_with_invalid_credits(server
->CurrentMid
,
119 server
->conn_id
, server
->hostname
, scredits
, add
, in_flight
);
120 cifs_dbg(FYI
, "Negotiate operation when server credits is non-zero. Optype: %d, server credits: %d, credits added: %d\n",
121 optype
, scredits
, add
);
124 if (server
->tcpStatus
== CifsNeedReconnect
125 || server
->tcpStatus
== CifsExiting
)
130 /* change_conf hasn't been executed */
133 cifs_server_dbg(VFS
, "Possible client or server bug - zero credits\n");
136 cifs_server_dbg(VFS
, "disabling echoes and oplocks\n");
139 cifs_dbg(FYI
, "disabling oplocks\n");
142 /* change_conf rebalanced credits for different types */
146 trace_smb3_add_credits(server
->CurrentMid
,
147 server
->conn_id
, server
->hostname
, scredits
, add
, in_flight
);
148 cifs_dbg(FYI
, "%s: added %u credits total=%d\n", __func__
, add
, scredits
);
152 smb2_set_credits(struct TCP_Server_Info
*server
, const int val
)
154 int scredits
, in_flight
;
156 spin_lock(&server
->req_lock
);
157 server
->credits
= val
;
159 server
->reconnect_instance
++;
160 scredits
= server
->credits
;
161 in_flight
= server
->in_flight
;
162 spin_unlock(&server
->req_lock
);
164 trace_smb3_set_credits(server
->CurrentMid
,
165 server
->conn_id
, server
->hostname
, scredits
, val
, in_flight
);
166 cifs_dbg(FYI
, "%s: set %u credits\n", __func__
, val
);
168 /* don't log while holding the lock */
170 cifs_dbg(FYI
, "set credits to 1 due to smb2 reconnect\n");
174 smb2_get_credits_field(struct TCP_Server_Info
*server
, const int optype
)
178 return &server
->echo_credits
;
180 return &server
->oplock_credits
;
182 return &server
->credits
;
187 smb2_get_credits(struct mid_q_entry
*mid
)
189 return mid
->credits_received
;
193 smb2_wait_mtu_credits(struct TCP_Server_Info
*server
, unsigned int size
,
194 unsigned int *num
, struct cifs_credits
*credits
)
197 unsigned int scredits
, in_flight
;
199 spin_lock(&server
->req_lock
);
201 if (server
->credits
<= 0) {
202 spin_unlock(&server
->req_lock
);
203 cifs_num_waiters_inc(server
);
204 rc
= wait_event_killable(server
->request_q
,
205 has_credits(server
, &server
->credits
, 1));
206 cifs_num_waiters_dec(server
);
209 spin_lock(&server
->req_lock
);
211 if (server
->tcpStatus
== CifsExiting
) {
212 spin_unlock(&server
->req_lock
);
216 scredits
= server
->credits
;
217 /* can deadlock with reopen */
219 *num
= SMB2_MAX_BUFFER_SIZE
;
221 credits
->instance
= 0;
225 /* leave some credits for reopen and other ops */
227 *num
= min_t(unsigned int, size
,
228 scredits
* SMB2_MAX_BUFFER_SIZE
);
231 DIV_ROUND_UP(*num
, SMB2_MAX_BUFFER_SIZE
);
232 credits
->instance
= server
->reconnect_instance
;
233 server
->credits
-= credits
->value
;
235 if (server
->in_flight
> server
->max_in_flight
)
236 server
->max_in_flight
= server
->in_flight
;
240 scredits
= server
->credits
;
241 in_flight
= server
->in_flight
;
242 spin_unlock(&server
->req_lock
);
244 trace_smb3_add_credits(server
->CurrentMid
,
245 server
->conn_id
, server
->hostname
, scredits
, -(credits
->value
), in_flight
);
246 cifs_dbg(FYI
, "%s: removed %u credits total=%d\n",
247 __func__
, credits
->value
, scredits
);
253 smb2_adjust_credits(struct TCP_Server_Info
*server
,
254 struct cifs_credits
*credits
,
255 const unsigned int payload_size
)
257 int new_val
= DIV_ROUND_UP(payload_size
, SMB2_MAX_BUFFER_SIZE
);
258 int scredits
, in_flight
;
260 if (!credits
->value
|| credits
->value
== new_val
)
263 if (credits
->value
< new_val
) {
264 trace_smb3_too_many_credits(server
->CurrentMid
,
265 server
->conn_id
, server
->hostname
, 0, credits
->value
- new_val
, 0);
266 cifs_server_dbg(VFS
, "request has less credits (%d) than required (%d)",
267 credits
->value
, new_val
);
272 spin_lock(&server
->req_lock
);
274 if (server
->reconnect_instance
!= credits
->instance
) {
275 scredits
= server
->credits
;
276 in_flight
= server
->in_flight
;
277 spin_unlock(&server
->req_lock
);
279 trace_smb3_reconnect_detected(server
->CurrentMid
,
280 server
->conn_id
, server
->hostname
, scredits
,
281 credits
->value
- new_val
, in_flight
);
282 cifs_server_dbg(VFS
, "trying to return %d credits to old session\n",
283 credits
->value
- new_val
);
287 server
->credits
+= credits
->value
- new_val
;
288 scredits
= server
->credits
;
289 in_flight
= server
->in_flight
;
290 spin_unlock(&server
->req_lock
);
291 wake_up(&server
->request_q
);
293 trace_smb3_add_credits(server
->CurrentMid
,
294 server
->conn_id
, server
->hostname
, scredits
,
295 credits
->value
- new_val
, in_flight
);
296 cifs_dbg(FYI
, "%s: adjust added %u credits total=%d\n",
297 __func__
, credits
->value
- new_val
, scredits
);
299 credits
->value
= new_val
;
305 smb2_get_next_mid(struct TCP_Server_Info
*server
)
308 /* for SMB2 we need the current value */
309 spin_lock(&GlobalMid_Lock
);
310 mid
= server
->CurrentMid
++;
311 spin_unlock(&GlobalMid_Lock
);
316 smb2_revert_current_mid(struct TCP_Server_Info
*server
, const unsigned int val
)
318 spin_lock(&GlobalMid_Lock
);
319 if (server
->CurrentMid
>= val
)
320 server
->CurrentMid
-= val
;
321 spin_unlock(&GlobalMid_Lock
);
324 static struct mid_q_entry
*
325 __smb2_find_mid(struct TCP_Server_Info
*server
, char *buf
, bool dequeue
)
327 struct mid_q_entry
*mid
;
328 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
329 __u64 wire_mid
= le64_to_cpu(shdr
->MessageId
);
331 if (shdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
) {
332 cifs_server_dbg(VFS
, "Encrypted frame parsing not supported yet\n");
336 spin_lock(&GlobalMid_Lock
);
337 list_for_each_entry(mid
, &server
->pending_mid_q
, qhead
) {
338 if ((mid
->mid
== wire_mid
) &&
339 (mid
->mid_state
== MID_REQUEST_SUBMITTED
) &&
340 (mid
->command
== shdr
->Command
)) {
341 kref_get(&mid
->refcount
);
343 list_del_init(&mid
->qhead
);
344 mid
->mid_flags
|= MID_DELETED
;
346 spin_unlock(&GlobalMid_Lock
);
350 spin_unlock(&GlobalMid_Lock
);
354 static struct mid_q_entry
*
355 smb2_find_mid(struct TCP_Server_Info
*server
, char *buf
)
357 return __smb2_find_mid(server
, buf
, false);
360 static struct mid_q_entry
*
361 smb2_find_dequeue_mid(struct TCP_Server_Info
*server
, char *buf
)
363 return __smb2_find_mid(server
, buf
, true);
367 smb2_dump_detail(void *buf
, struct TCP_Server_Info
*server
)
369 #ifdef CONFIG_CIFS_DEBUG2
370 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
372 cifs_server_dbg(VFS
, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
373 shdr
->Command
, shdr
->Status
, shdr
->Flags
, shdr
->MessageId
,
375 cifs_server_dbg(VFS
, "smb buf %p len %u\n", buf
,
376 server
->ops
->calc_smb_size(buf
, server
));
381 smb2_need_neg(struct TCP_Server_Info
*server
)
383 return server
->max_read
== 0;
387 smb2_negotiate(const unsigned int xid
, struct cifs_ses
*ses
)
391 spin_lock(&GlobalMid_Lock
);
392 cifs_ses_server(ses
)->CurrentMid
= 0;
393 spin_unlock(&GlobalMid_Lock
);
394 rc
= SMB2_negotiate(xid
, ses
);
395 /* BB we probably don't need to retry with modern servers */
402 smb2_negotiate_wsize(struct cifs_tcon
*tcon
, struct smb3_fs_context
*ctx
)
404 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
407 /* start with specified wsize, or default */
408 wsize
= ctx
->wsize
? ctx
->wsize
: CIFS_DEFAULT_IOSIZE
;
409 wsize
= min_t(unsigned int, wsize
, server
->max_write
);
410 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
411 wsize
= min_t(unsigned int, wsize
, SMB2_MAX_BUFFER_SIZE
);
417 smb3_negotiate_wsize(struct cifs_tcon
*tcon
, struct smb3_fs_context
*ctx
)
419 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
422 /* start with specified wsize, or default */
423 wsize
= ctx
->wsize
? ctx
->wsize
: SMB3_DEFAULT_IOSIZE
;
424 wsize
= min_t(unsigned int, wsize
, server
->max_write
);
425 #ifdef CONFIG_CIFS_SMB_DIRECT
429 * Account for SMB2 data transfer packet header and
430 * possible encryption header
432 wsize
= min_t(unsigned int,
434 server
->smbd_conn
->max_fragmented_send_size
-
435 SMB2_READWRITE_PDU_HEADER_SIZE
-
436 sizeof(struct smb2_transform_hdr
));
438 wsize
= min_t(unsigned int,
439 wsize
, server
->smbd_conn
->max_readwrite_size
);
442 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
443 wsize
= min_t(unsigned int, wsize
, SMB2_MAX_BUFFER_SIZE
);
449 smb2_negotiate_rsize(struct cifs_tcon
*tcon
, struct smb3_fs_context
*ctx
)
451 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
454 /* start with specified rsize, or default */
455 rsize
= ctx
->rsize
? ctx
->rsize
: CIFS_DEFAULT_IOSIZE
;
456 rsize
= min_t(unsigned int, rsize
, server
->max_read
);
458 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
459 rsize
= min_t(unsigned int, rsize
, SMB2_MAX_BUFFER_SIZE
);
465 smb3_negotiate_rsize(struct cifs_tcon
*tcon
, struct smb3_fs_context
*ctx
)
467 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
470 /* start with specified rsize, or default */
471 rsize
= ctx
->rsize
? ctx
->rsize
: SMB3_DEFAULT_IOSIZE
;
472 rsize
= min_t(unsigned int, rsize
, server
->max_read
);
473 #ifdef CONFIG_CIFS_SMB_DIRECT
477 * Account for SMB2 data transfer packet header and
478 * possible encryption header
480 rsize
= min_t(unsigned int,
482 server
->smbd_conn
->max_fragmented_recv_size
-
483 SMB2_READWRITE_PDU_HEADER_SIZE
-
484 sizeof(struct smb2_transform_hdr
));
486 rsize
= min_t(unsigned int,
487 rsize
, server
->smbd_conn
->max_readwrite_size
);
491 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
492 rsize
= min_t(unsigned int, rsize
, SMB2_MAX_BUFFER_SIZE
);
498 parse_server_interfaces(struct network_interface_info_ioctl_rsp
*buf
,
500 struct cifs_server_iface
**iface_list
,
503 struct network_interface_info_ioctl_rsp
*p
;
504 struct sockaddr_in
*addr4
;
505 struct sockaddr_in6
*addr6
;
506 struct iface_info_ipv4
*p4
;
507 struct iface_info_ipv6
*p6
;
508 struct cifs_server_iface
*info
;
518 * Fist pass: count and sanity check
521 bytes_left
= buf_len
;
523 while (bytes_left
>= sizeof(*p
)) {
525 next
= le32_to_cpu(p
->Next
);
527 bytes_left
-= sizeof(*p
);
530 p
= (struct network_interface_info_ioctl_rsp
*)((u8
*)p
+next
);
535 cifs_dbg(VFS
, "%s: malformed interface info\n", __func__
);
540 /* Azure rounds the buffer size up 8, to a 16 byte boundary */
541 if ((bytes_left
> 8) || p
->Next
)
542 cifs_dbg(VFS
, "%s: incomplete interface info\n", __func__
);
546 * Second pass: extract info to internal structure
549 *iface_list
= kcalloc(nb_iface
, sizeof(**iface_list
), GFP_KERNEL
);
556 bytes_left
= buf_len
;
558 while (bytes_left
>= sizeof(*p
)) {
559 info
->speed
= le64_to_cpu(p
->LinkSpeed
);
560 info
->rdma_capable
= le32_to_cpu(p
->Capability
& RDMA_CAPABLE
) ? 1 : 0;
561 info
->rss_capable
= le32_to_cpu(p
->Capability
& RSS_CAPABLE
) ? 1 : 0;
563 cifs_dbg(FYI
, "%s: adding iface %zu\n", __func__
, *iface_count
);
564 cifs_dbg(FYI
, "%s: speed %zu bps\n", __func__
, info
->speed
);
565 cifs_dbg(FYI
, "%s: capabilities 0x%08x\n", __func__
,
566 le32_to_cpu(p
->Capability
));
570 * The kernel and wire socket structures have the same
571 * layout and use network byte order but make the
572 * conversion explicit in case either one changes.
575 addr4
= (struct sockaddr_in
*)&info
->sockaddr
;
576 p4
= (struct iface_info_ipv4
*)p
->Buffer
;
577 addr4
->sin_family
= AF_INET
;
578 memcpy(&addr4
->sin_addr
, &p4
->IPv4Address
, 4);
580 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
581 addr4
->sin_port
= cpu_to_be16(CIFS_PORT
);
583 cifs_dbg(FYI
, "%s: ipv4 %pI4\n", __func__
,
587 addr6
= (struct sockaddr_in6
*)&info
->sockaddr
;
588 p6
= (struct iface_info_ipv6
*)p
->Buffer
;
589 addr6
->sin6_family
= AF_INET6
;
590 memcpy(&addr6
->sin6_addr
, &p6
->IPv6Address
, 16);
592 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
593 addr6
->sin6_flowinfo
= 0;
594 addr6
->sin6_scope_id
= 0;
595 addr6
->sin6_port
= cpu_to_be16(CIFS_PORT
);
597 cifs_dbg(FYI
, "%s: ipv6 %pI6\n", __func__
,
602 "%s: skipping unsupported socket family\n",
610 next
= le32_to_cpu(p
->Next
);
613 p
= (struct network_interface_info_ioctl_rsp
*)((u8
*)p
+next
);
631 static int compare_iface(const void *ia
, const void *ib
)
633 const struct cifs_server_iface
*a
= (struct cifs_server_iface
*)ia
;
634 const struct cifs_server_iface
*b
= (struct cifs_server_iface
*)ib
;
636 return a
->speed
== b
->speed
? 0 : (a
->speed
> b
->speed
? -1 : 1);
640 SMB3_request_interfaces(const unsigned int xid
, struct cifs_tcon
*tcon
)
643 unsigned int ret_data_len
= 0;
644 struct network_interface_info_ioctl_rsp
*out_buf
= NULL
;
645 struct cifs_server_iface
*iface_list
;
647 struct cifs_ses
*ses
= tcon
->ses
;
649 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
650 FSCTL_QUERY_NETWORK_INTERFACE_INFO
, true /* is_fsctl */,
651 NULL
/* no data input */, 0 /* no data input */,
652 CIFSMaxBufSize
, (char **)&out_buf
, &ret_data_len
);
653 if (rc
== -EOPNOTSUPP
) {
655 "server does not support query network interfaces\n");
657 } else if (rc
!= 0) {
658 cifs_tcon_dbg(VFS
, "error %d on ioctl to get interface list\n", rc
);
662 rc
= parse_server_interfaces(out_buf
, ret_data_len
,
663 &iface_list
, &iface_count
);
667 /* sort interfaces from fastest to slowest */
668 sort(iface_list
, iface_count
, sizeof(*iface_list
), compare_iface
, NULL
);
670 spin_lock(&ses
->iface_lock
);
671 kfree(ses
->iface_list
);
672 ses
->iface_list
= iface_list
;
673 ses
->iface_count
= iface_count
;
674 ses
->iface_last_update
= jiffies
;
675 spin_unlock(&ses
->iface_lock
);
683 smb2_close_cached_fid(struct kref
*ref
)
685 struct cached_fid
*cfid
= container_of(ref
, struct cached_fid
,
688 if (cfid
->is_valid
) {
689 cifs_dbg(FYI
, "clear cached root file handle\n");
690 SMB2_close(0, cfid
->tcon
, cfid
->fid
->persistent_fid
,
691 cfid
->fid
->volatile_fid
);
695 * We only check validity above to send SMB2_close,
696 * but we still need to invalidate these entries
697 * when this function is called
699 cfid
->is_valid
= false;
700 cfid
->file_all_info_is_valid
= false;
701 cfid
->has_lease
= false;
708 void close_cached_dir(struct cached_fid
*cfid
)
710 mutex_lock(&cfid
->fid_mutex
);
711 kref_put(&cfid
->refcount
, smb2_close_cached_fid
);
712 mutex_unlock(&cfid
->fid_mutex
);
715 void close_cached_dir_lease_locked(struct cached_fid
*cfid
)
717 if (cfid
->has_lease
) {
718 cfid
->has_lease
= false;
719 kref_put(&cfid
->refcount
, smb2_close_cached_fid
);
723 void close_cached_dir_lease(struct cached_fid
*cfid
)
725 mutex_lock(&cfid
->fid_mutex
);
726 close_cached_dir_lease_locked(cfid
);
727 mutex_unlock(&cfid
->fid_mutex
);
731 smb2_cached_lease_break(struct work_struct
*work
)
733 struct cached_fid
*cfid
= container_of(work
,
734 struct cached_fid
, lease_break
);
736 close_cached_dir_lease(cfid
);
740 * Open the and cache a directory handle.
741 * Only supported for the root handle.
743 int open_cached_dir(unsigned int xid
, struct cifs_tcon
*tcon
,
745 struct cifs_sb_info
*cifs_sb
,
746 struct cached_fid
**cfid
)
748 struct cifs_ses
*ses
;
749 struct TCP_Server_Info
*server
;
750 struct cifs_open_parms oparms
;
751 struct smb2_create_rsp
*o_rsp
= NULL
;
752 struct smb2_query_info_rsp
*qi_rsp
= NULL
;
754 struct smb_rqst rqst
[2];
755 struct kvec rsp_iov
[2];
756 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
757 struct kvec qi_iov
[1];
759 __le16 utf16_path
= 0; /* Null - since an open of top of share */
760 u8 oplock
= SMB2_OPLOCK_LEVEL_II
;
761 struct cifs_fid
*pfid
;
762 struct dentry
*dentry
;
764 if (tcon
->nohandlecache
)
768 server
= ses
->server
;
770 if (cifs_sb
->root
== NULL
)
776 dentry
= cifs_sb
->root
;
778 mutex_lock(&tcon
->crfid
.fid_mutex
);
779 if (tcon
->crfid
.is_valid
) {
780 cifs_dbg(FYI
, "found a cached root file handle\n");
781 *cfid
= &tcon
->crfid
;
782 kref_get(&tcon
->crfid
.refcount
);
783 mutex_unlock(&tcon
->crfid
.fid_mutex
);
788 * We do not hold the lock for the open because in case
789 * SMB2_open needs to reconnect, it will end up calling
790 * cifs_mark_open_files_invalid() which takes the lock again
791 * thus causing a deadlock
794 mutex_unlock(&tcon
->crfid
.fid_mutex
);
796 if (smb3_encryption_required(tcon
))
797 flags
|= CIFS_TRANSFORM_REQ
;
799 if (!server
->ops
->new_lease_key
)
802 pfid
= tcon
->crfid
.fid
;
803 server
->ops
->new_lease_key(pfid
);
805 memset(rqst
, 0, sizeof(rqst
));
806 resp_buftype
[0] = resp_buftype
[1] = CIFS_NO_BUFFER
;
807 memset(rsp_iov
, 0, sizeof(rsp_iov
));
810 memset(&open_iov
, 0, sizeof(open_iov
));
811 rqst
[0].rq_iov
= open_iov
;
812 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
815 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
816 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
817 oparms
.disposition
= FILE_OPEN
;
819 oparms
.reconnect
= false;
821 rc
= SMB2_open_init(tcon
, server
,
822 &rqst
[0], &oplock
, &oparms
, &utf16_path
);
825 smb2_set_next_command(tcon
, &rqst
[0]);
827 memset(&qi_iov
, 0, sizeof(qi_iov
));
828 rqst
[1].rq_iov
= qi_iov
;
831 rc
= SMB2_query_info_init(tcon
, server
,
832 &rqst
[1], COMPOUND_FID
,
833 COMPOUND_FID
, FILE_ALL_INFORMATION
,
835 sizeof(struct smb2_file_all_info
) +
836 PATH_MAX
* 2, 0, NULL
);
840 smb2_set_related(&rqst
[1]);
842 rc
= compound_send_recv(xid
, ses
, server
,
844 resp_buftype
, rsp_iov
);
845 mutex_lock(&tcon
->crfid
.fid_mutex
);
848 * Now we need to check again as the cached root might have
849 * been successfully re-opened from a concurrent process
852 if (tcon
->crfid
.is_valid
) {
853 /* work was already done */
855 /* stash fids for close() later */
856 struct cifs_fid fid
= {
857 .persistent_fid
= pfid
->persistent_fid
,
858 .volatile_fid
= pfid
->volatile_fid
,
862 * caller expects this func to set the fid in crfid to valid
863 * cached root, so increment the refcount.
865 kref_get(&tcon
->crfid
.refcount
);
867 mutex_unlock(&tcon
->crfid
.fid_mutex
);
870 /* close extra handle outside of crit sec */
871 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
877 /* Cached root is still invalid, continue normaly */
880 if (rc
== -EREMCHG
) {
881 tcon
->need_reconnect
= true;
882 pr_warn_once("server share %s deleted\n",
888 atomic_inc(&tcon
->num_remote_opens
);
890 o_rsp
= (struct smb2_create_rsp
*)rsp_iov
[0].iov_base
;
891 oparms
.fid
->persistent_fid
= o_rsp
->PersistentFileId
;
892 oparms
.fid
->volatile_fid
= o_rsp
->VolatileFileId
;
893 #ifdef CONFIG_CIFS_DEBUG2
894 oparms
.fid
->mid
= le64_to_cpu(o_rsp
->sync_hdr
.MessageId
);
895 #endif /* CIFS_DEBUG2 */
897 tcon
->crfid
.tcon
= tcon
;
898 tcon
->crfid
.is_valid
= true;
899 tcon
->crfid
.dentry
= dentry
;
901 kref_init(&tcon
->crfid
.refcount
);
903 /* BB TBD check to see if oplock level check can be removed below */
904 if (o_rsp
->OplockLevel
== SMB2_OPLOCK_LEVEL_LEASE
) {
906 * See commit 2f94a3125b87. Increment the refcount when we
907 * get a lease for root, release it if lease break occurs
909 kref_get(&tcon
->crfid
.refcount
);
910 tcon
->crfid
.has_lease
= true;
911 smb2_parse_contexts(server
, o_rsp
,
913 oparms
.fid
->lease_key
, &oplock
,
918 qi_rsp
= (struct smb2_query_info_rsp
*)rsp_iov
[1].iov_base
;
919 if (le32_to_cpu(qi_rsp
->OutputBufferLength
) < sizeof(struct smb2_file_all_info
))
921 if (!smb2_validate_and_copy_iov(
922 le16_to_cpu(qi_rsp
->OutputBufferOffset
),
923 sizeof(struct smb2_file_all_info
),
924 &rsp_iov
[1], sizeof(struct smb2_file_all_info
),
925 (char *)&tcon
->crfid
.file_all_info
))
926 tcon
->crfid
.file_all_info_is_valid
= true;
927 tcon
->crfid
.time
= jiffies
;
931 mutex_unlock(&tcon
->crfid
.fid_mutex
);
933 SMB2_open_free(&rqst
[0]);
934 SMB2_query_info_free(&rqst
[1]);
935 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
936 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
938 *cfid
= &tcon
->crfid
;
942 int open_cached_dir_by_dentry(struct cifs_tcon
*tcon
,
943 struct dentry
*dentry
,
944 struct cached_fid
**cfid
)
946 mutex_lock(&tcon
->crfid
.fid_mutex
);
947 if (tcon
->crfid
.dentry
== dentry
) {
948 cifs_dbg(FYI
, "found a cached root file handle by dentry\n");
949 *cfid
= &tcon
->crfid
;
950 kref_get(&tcon
->crfid
.refcount
);
951 mutex_unlock(&tcon
->crfid
.fid_mutex
);
954 mutex_unlock(&tcon
->crfid
.fid_mutex
);
959 smb3_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
,
960 struct cifs_sb_info
*cifs_sb
)
963 __le16 srch_path
= 0; /* Null - open root of share */
964 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
965 struct cifs_open_parms oparms
;
967 struct cached_fid
*cfid
= NULL
;
970 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
971 oparms
.disposition
= FILE_OPEN
;
972 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
974 oparms
.reconnect
= false;
976 rc
= open_cached_dir(xid
, tcon
, "", cifs_sb
, &cfid
);
978 memcpy(&fid
, cfid
->fid
, sizeof(struct cifs_fid
));
980 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
,
985 SMB3_request_interfaces(xid
, tcon
);
987 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
988 FS_ATTRIBUTE_INFORMATION
);
989 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
990 FS_DEVICE_INFORMATION
);
991 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
992 FS_VOLUME_INFORMATION
);
993 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
994 FS_SECTOR_SIZE_INFORMATION
); /* SMB3 specific */
996 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
998 close_cached_dir(cfid
);
1002 smb2_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
,
1003 struct cifs_sb_info
*cifs_sb
)
1006 __le16 srch_path
= 0; /* Null - open root of share */
1007 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1008 struct cifs_open_parms oparms
;
1009 struct cifs_fid fid
;
1012 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
1013 oparms
.disposition
= FILE_OPEN
;
1014 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
1016 oparms
.reconnect
= false;
1018 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
,
1023 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
1024 FS_ATTRIBUTE_INFORMATION
);
1025 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
1026 FS_DEVICE_INFORMATION
);
1027 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
1031 smb2_is_path_accessible(const unsigned int xid
, struct cifs_tcon
*tcon
,
1032 struct cifs_sb_info
*cifs_sb
, const char *full_path
)
1036 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1037 struct cifs_open_parms oparms
;
1038 struct cifs_fid fid
;
1040 if ((*full_path
== 0) && tcon
->crfid
.is_valid
)
1043 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
1048 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
1049 oparms
.disposition
= FILE_OPEN
;
1050 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
1052 oparms
.reconnect
= false;
1054 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
, NULL
,
1061 rc
= SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
1067 smb2_get_srv_inum(const unsigned int xid
, struct cifs_tcon
*tcon
,
1068 struct cifs_sb_info
*cifs_sb
, const char *full_path
,
1069 u64
*uniqueid
, FILE_ALL_INFO
*data
)
1071 *uniqueid
= le64_to_cpu(data
->IndexNumber
);
1076 smb2_query_file_info(const unsigned int xid
, struct cifs_tcon
*tcon
,
1077 struct cifs_fid
*fid
, FILE_ALL_INFO
*data
)
1080 struct smb2_file_all_info
*smb2_data
;
1082 smb2_data
= kzalloc(sizeof(struct smb2_file_all_info
) + PATH_MAX
* 2,
1084 if (smb2_data
== NULL
)
1087 rc
= SMB2_query_info(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
,
1090 move_smb2_info_to_cifs(data
, smb2_data
);
1095 #ifdef CONFIG_CIFS_XATTR
1097 move_smb2_ea_to_cifs(char *dst
, size_t dst_size
,
1098 struct smb2_file_full_ea_info
*src
, size_t src_size
,
1099 const unsigned char *ea_name
)
1102 unsigned int ea_name_len
= ea_name
? strlen(ea_name
) : 0;
1104 size_t buf_size
= dst_size
;
1105 size_t name_len
, value_len
, user_name_len
;
1107 while (src_size
> 0) {
1108 name
= &src
->ea_data
[0];
1109 name_len
= (size_t)src
->ea_name_length
;
1110 value
= &src
->ea_data
[src
->ea_name_length
+ 1];
1111 value_len
= (size_t)le16_to_cpu(src
->ea_value_length
);
1116 if (src_size
< 8 + name_len
+ 1 + value_len
) {
1117 cifs_dbg(FYI
, "EA entry goes beyond length of list\n");
1123 if (ea_name_len
== name_len
&&
1124 memcmp(ea_name
, name
, name_len
) == 0) {
1128 if (dst_size
< value_len
) {
1132 memcpy(dst
, value
, value_len
);
1136 /* 'user.' plus a terminating null */
1137 user_name_len
= 5 + 1 + name_len
;
1139 if (buf_size
== 0) {
1140 /* skip copy - calc size only */
1141 rc
+= user_name_len
;
1142 } else if (dst_size
>= user_name_len
) {
1143 dst_size
-= user_name_len
;
1144 memcpy(dst
, "user.", 5);
1146 memcpy(dst
, src
->ea_data
, name_len
);
1150 rc
+= user_name_len
;
1152 /* stop before overrun buffer */
1158 if (!src
->next_entry_offset
)
1161 if (src_size
< le32_to_cpu(src
->next_entry_offset
)) {
1162 /* stop before overrun buffer */
1166 src_size
-= le32_to_cpu(src
->next_entry_offset
);
1167 src
= (void *)((char *)src
+
1168 le32_to_cpu(src
->next_entry_offset
));
1171 /* didn't find the named attribute */
1180 smb2_query_eas(const unsigned int xid
, struct cifs_tcon
*tcon
,
1181 const unsigned char *path
, const unsigned char *ea_name
,
1182 char *ea_data
, size_t buf_size
,
1183 struct cifs_sb_info
*cifs_sb
)
1187 struct kvec rsp_iov
= {NULL
, 0};
1188 int buftype
= CIFS_NO_BUFFER
;
1189 struct smb2_query_info_rsp
*rsp
;
1190 struct smb2_file_full_ea_info
*info
= NULL
;
1192 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
1196 rc
= smb2_query_info_compound(xid
, tcon
, utf16_path
,
1198 FILE_FULL_EA_INFORMATION
,
1201 MAX_SMB2_CREATE_RESPONSE_SIZE
-
1202 MAX_SMB2_CLOSE_RESPONSE_SIZE
,
1203 &rsp_iov
, &buftype
, cifs_sb
);
1206 * If ea_name is NULL (listxattr) and there are no EAs,
1207 * return 0 as it's not an error. Otherwise, the specified
1208 * ea_name was not found.
1210 if (!ea_name
&& rc
== -ENODATA
)
1215 rsp
= (struct smb2_query_info_rsp
*)rsp_iov
.iov_base
;
1216 rc
= smb2_validate_iov(le16_to_cpu(rsp
->OutputBufferOffset
),
1217 le32_to_cpu(rsp
->OutputBufferLength
),
1219 sizeof(struct smb2_file_full_ea_info
));
1223 info
= (struct smb2_file_full_ea_info
*)(
1224 le16_to_cpu(rsp
->OutputBufferOffset
) + (char *)rsp
);
1225 rc
= move_smb2_ea_to_cifs(ea_data
, buf_size
, info
,
1226 le32_to_cpu(rsp
->OutputBufferLength
), ea_name
);
1230 free_rsp_buf(buftype
, rsp_iov
.iov_base
);
1236 smb2_set_ea(const unsigned int xid
, struct cifs_tcon
*tcon
,
1237 const char *path
, const char *ea_name
, const void *ea_value
,
1238 const __u16 ea_value_len
, const struct nls_table
*nls_codepage
,
1239 struct cifs_sb_info
*cifs_sb
)
1241 struct cifs_ses
*ses
= tcon
->ses
;
1242 struct TCP_Server_Info
*server
= cifs_pick_channel(ses
);
1243 __le16
*utf16_path
= NULL
;
1244 int ea_name_len
= strlen(ea_name
);
1245 int flags
= CIFS_CP_CREATE_CLOSE_OP
;
1247 struct smb_rqst rqst
[3];
1248 int resp_buftype
[3];
1249 struct kvec rsp_iov
[3];
1250 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
1251 struct cifs_open_parms oparms
;
1252 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1253 struct cifs_fid fid
;
1254 struct kvec si_iov
[SMB2_SET_INFO_IOV_SIZE
];
1255 unsigned int size
[1];
1257 struct smb2_file_full_ea_info
*ea
= NULL
;
1258 struct kvec close_iov
[1];
1259 struct smb2_query_info_rsp
*rsp
;
1260 int rc
, used_len
= 0;
1262 if (smb3_encryption_required(tcon
))
1263 flags
|= CIFS_TRANSFORM_REQ
;
1265 if (ea_name_len
> 255)
1268 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
1272 memset(rqst
, 0, sizeof(rqst
));
1273 resp_buftype
[0] = resp_buftype
[1] = resp_buftype
[2] = CIFS_NO_BUFFER
;
1274 memset(rsp_iov
, 0, sizeof(rsp_iov
));
1276 if (ses
->server
->ops
->query_all_EAs
) {
1278 rc
= ses
->server
->ops
->query_all_EAs(xid
, tcon
, path
,
1284 /* If we are adding a attribute we should first check
1285 * if there will be enough space available to store
1286 * the new EA. If not we should not add it since we
1287 * would not be able to even read the EAs back.
1289 rc
= smb2_query_info_compound(xid
, tcon
, utf16_path
,
1291 FILE_FULL_EA_INFORMATION
,
1294 MAX_SMB2_CREATE_RESPONSE_SIZE
-
1295 MAX_SMB2_CLOSE_RESPONSE_SIZE
,
1296 &rsp_iov
[1], &resp_buftype
[1], cifs_sb
);
1298 rsp
= (struct smb2_query_info_rsp
*)rsp_iov
[1].iov_base
;
1299 used_len
= le32_to_cpu(rsp
->OutputBufferLength
);
1301 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
1302 resp_buftype
[1] = CIFS_NO_BUFFER
;
1303 memset(&rsp_iov
[1], 0, sizeof(rsp_iov
[1]));
1306 /* Use a fudge factor of 256 bytes in case we collide
1307 * with a different set_EAs command.
1309 if(CIFSMaxBufSize
- MAX_SMB2_CREATE_RESPONSE_SIZE
-
1310 MAX_SMB2_CLOSE_RESPONSE_SIZE
- 256 <
1311 used_len
+ ea_name_len
+ ea_value_len
+ 1) {
1319 memset(&open_iov
, 0, sizeof(open_iov
));
1320 rqst
[0].rq_iov
= open_iov
;
1321 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
1323 memset(&oparms
, 0, sizeof(oparms
));
1325 oparms
.desired_access
= FILE_WRITE_EA
;
1326 oparms
.disposition
= FILE_OPEN
;
1327 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
1329 oparms
.reconnect
= false;
1331 rc
= SMB2_open_init(tcon
, server
,
1332 &rqst
[0], &oplock
, &oparms
, utf16_path
);
1335 smb2_set_next_command(tcon
, &rqst
[0]);
1339 memset(&si_iov
, 0, sizeof(si_iov
));
1340 rqst
[1].rq_iov
= si_iov
;
1341 rqst
[1].rq_nvec
= 1;
1343 len
= sizeof(*ea
) + ea_name_len
+ ea_value_len
+ 1;
1344 ea
= kzalloc(len
, GFP_KERNEL
);
1350 ea
->ea_name_length
= ea_name_len
;
1351 ea
->ea_value_length
= cpu_to_le16(ea_value_len
);
1352 memcpy(ea
->ea_data
, ea_name
, ea_name_len
+ 1);
1353 memcpy(ea
->ea_data
+ ea_name_len
+ 1, ea_value
, ea_value_len
);
1358 rc
= SMB2_set_info_init(tcon
, server
,
1359 &rqst
[1], COMPOUND_FID
,
1360 COMPOUND_FID
, current
->tgid
,
1361 FILE_FULL_EA_INFORMATION
,
1362 SMB2_O_INFO_FILE
, 0, data
, size
);
1363 smb2_set_next_command(tcon
, &rqst
[1]);
1364 smb2_set_related(&rqst
[1]);
1368 memset(&close_iov
, 0, sizeof(close_iov
));
1369 rqst
[2].rq_iov
= close_iov
;
1370 rqst
[2].rq_nvec
= 1;
1371 rc
= SMB2_close_init(tcon
, server
,
1372 &rqst
[2], COMPOUND_FID
, COMPOUND_FID
, false);
1373 smb2_set_related(&rqst
[2]);
1375 rc
= compound_send_recv(xid
, ses
, server
,
1377 resp_buftype
, rsp_iov
);
1378 /* no need to bump num_remote_opens because handle immediately closed */
1383 SMB2_open_free(&rqst
[0]);
1384 SMB2_set_info_free(&rqst
[1]);
1385 SMB2_close_free(&rqst
[2]);
1386 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
1387 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
1388 free_rsp_buf(resp_buftype
[2], rsp_iov
[2].iov_base
);
1394 smb2_can_echo(struct TCP_Server_Info
*server
)
1396 return server
->echoes
;
1400 smb2_clear_stats(struct cifs_tcon
*tcon
)
1404 for (i
= 0; i
< NUMBER_OF_SMB2_COMMANDS
; i
++) {
1405 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_sent
[i
], 0);
1406 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_failed
[i
], 0);
1411 smb2_dump_share_caps(struct seq_file
*m
, struct cifs_tcon
*tcon
)
1413 seq_puts(m
, "\n\tShare Capabilities:");
1414 if (tcon
->capabilities
& SMB2_SHARE_CAP_DFS
)
1415 seq_puts(m
, " DFS,");
1416 if (tcon
->capabilities
& SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY
)
1417 seq_puts(m
, " CONTINUOUS AVAILABILITY,");
1418 if (tcon
->capabilities
& SMB2_SHARE_CAP_SCALEOUT
)
1419 seq_puts(m
, " SCALEOUT,");
1420 if (tcon
->capabilities
& SMB2_SHARE_CAP_CLUSTER
)
1421 seq_puts(m
, " CLUSTER,");
1422 if (tcon
->capabilities
& SMB2_SHARE_CAP_ASYMMETRIC
)
1423 seq_puts(m
, " ASYMMETRIC,");
1424 if (tcon
->capabilities
== 0)
1425 seq_puts(m
, " None");
1426 if (tcon
->ss_flags
& SSINFO_FLAGS_ALIGNED_DEVICE
)
1427 seq_puts(m
, " Aligned,");
1428 if (tcon
->ss_flags
& SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE
)
1429 seq_puts(m
, " Partition Aligned,");
1430 if (tcon
->ss_flags
& SSINFO_FLAGS_NO_SEEK_PENALTY
)
1431 seq_puts(m
, " SSD,");
1432 if (tcon
->ss_flags
& SSINFO_FLAGS_TRIM_ENABLED
)
1433 seq_puts(m
, " TRIM-support,");
1435 seq_printf(m
, "\tShare Flags: 0x%x", tcon
->share_flags
);
1436 seq_printf(m
, "\n\ttid: 0x%x", tcon
->tid
);
1437 if (tcon
->perf_sector_size
)
1438 seq_printf(m
, "\tOptimal sector size: 0x%x",
1439 tcon
->perf_sector_size
);
1440 seq_printf(m
, "\tMaximal Access: 0x%x", tcon
->maximal_access
);
1444 smb2_print_stats(struct seq_file
*m
, struct cifs_tcon
*tcon
)
1446 atomic_t
*sent
= tcon
->stats
.smb2_stats
.smb2_com_sent
;
1447 atomic_t
*failed
= tcon
->stats
.smb2_stats
.smb2_com_failed
;
1450 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1451 * totals (requests sent) since those SMBs are per-session not per tcon
1453 seq_printf(m
, "\nBytes read: %llu Bytes written: %llu",
1454 (long long)(tcon
->bytes_read
),
1455 (long long)(tcon
->bytes_written
));
1456 seq_printf(m
, "\nOpen files: %d total (local), %d open on server",
1457 atomic_read(&tcon
->num_local_opens
),
1458 atomic_read(&tcon
->num_remote_opens
));
1459 seq_printf(m
, "\nTreeConnects: %d total %d failed",
1460 atomic_read(&sent
[SMB2_TREE_CONNECT_HE
]),
1461 atomic_read(&failed
[SMB2_TREE_CONNECT_HE
]));
1462 seq_printf(m
, "\nTreeDisconnects: %d total %d failed",
1463 atomic_read(&sent
[SMB2_TREE_DISCONNECT_HE
]),
1464 atomic_read(&failed
[SMB2_TREE_DISCONNECT_HE
]));
1465 seq_printf(m
, "\nCreates: %d total %d failed",
1466 atomic_read(&sent
[SMB2_CREATE_HE
]),
1467 atomic_read(&failed
[SMB2_CREATE_HE
]));
1468 seq_printf(m
, "\nCloses: %d total %d failed",
1469 atomic_read(&sent
[SMB2_CLOSE_HE
]),
1470 atomic_read(&failed
[SMB2_CLOSE_HE
]));
1471 seq_printf(m
, "\nFlushes: %d total %d failed",
1472 atomic_read(&sent
[SMB2_FLUSH_HE
]),
1473 atomic_read(&failed
[SMB2_FLUSH_HE
]));
1474 seq_printf(m
, "\nReads: %d total %d failed",
1475 atomic_read(&sent
[SMB2_READ_HE
]),
1476 atomic_read(&failed
[SMB2_READ_HE
]));
1477 seq_printf(m
, "\nWrites: %d total %d failed",
1478 atomic_read(&sent
[SMB2_WRITE_HE
]),
1479 atomic_read(&failed
[SMB2_WRITE_HE
]));
1480 seq_printf(m
, "\nLocks: %d total %d failed",
1481 atomic_read(&sent
[SMB2_LOCK_HE
]),
1482 atomic_read(&failed
[SMB2_LOCK_HE
]));
1483 seq_printf(m
, "\nIOCTLs: %d total %d failed",
1484 atomic_read(&sent
[SMB2_IOCTL_HE
]),
1485 atomic_read(&failed
[SMB2_IOCTL_HE
]));
1486 seq_printf(m
, "\nQueryDirectories: %d total %d failed",
1487 atomic_read(&sent
[SMB2_QUERY_DIRECTORY_HE
]),
1488 atomic_read(&failed
[SMB2_QUERY_DIRECTORY_HE
]));
1489 seq_printf(m
, "\nChangeNotifies: %d total %d failed",
1490 atomic_read(&sent
[SMB2_CHANGE_NOTIFY_HE
]),
1491 atomic_read(&failed
[SMB2_CHANGE_NOTIFY_HE
]));
1492 seq_printf(m
, "\nQueryInfos: %d total %d failed",
1493 atomic_read(&sent
[SMB2_QUERY_INFO_HE
]),
1494 atomic_read(&failed
[SMB2_QUERY_INFO_HE
]));
1495 seq_printf(m
, "\nSetInfos: %d total %d failed",
1496 atomic_read(&sent
[SMB2_SET_INFO_HE
]),
1497 atomic_read(&failed
[SMB2_SET_INFO_HE
]));
1498 seq_printf(m
, "\nOplockBreaks: %d sent %d failed",
1499 atomic_read(&sent
[SMB2_OPLOCK_BREAK_HE
]),
1500 atomic_read(&failed
[SMB2_OPLOCK_BREAK_HE
]));
1504 smb2_set_fid(struct cifsFileInfo
*cfile
, struct cifs_fid
*fid
, __u32 oplock
)
1506 struct cifsInodeInfo
*cinode
= CIFS_I(d_inode(cfile
->dentry
));
1507 struct TCP_Server_Info
*server
= tlink_tcon(cfile
->tlink
)->ses
->server
;
1509 cfile
->fid
.persistent_fid
= fid
->persistent_fid
;
1510 cfile
->fid
.volatile_fid
= fid
->volatile_fid
;
1511 cfile
->fid
.access
= fid
->access
;
1512 #ifdef CONFIG_CIFS_DEBUG2
1513 cfile
->fid
.mid
= fid
->mid
;
1514 #endif /* CIFS_DEBUG2 */
1515 server
->ops
->set_oplock_level(cinode
, oplock
, fid
->epoch
,
1517 cinode
->can_cache_brlcks
= CIFS_CACHE_WRITE(cinode
);
1518 memcpy(cfile
->fid
.create_guid
, fid
->create_guid
, 16);
1522 smb2_close_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
1523 struct cifs_fid
*fid
)
1525 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1529 smb2_close_getattr(const unsigned int xid
, struct cifs_tcon
*tcon
,
1530 struct cifsFileInfo
*cfile
)
1532 struct smb2_file_network_open_info file_inf
;
1533 struct inode
*inode
;
1536 rc
= __SMB2_close(xid
, tcon
, cfile
->fid
.persistent_fid
,
1537 cfile
->fid
.volatile_fid
, &file_inf
);
1541 inode
= d_inode(cfile
->dentry
);
1543 spin_lock(&inode
->i_lock
);
1544 CIFS_I(inode
)->time
= jiffies
;
1546 /* Creation time should not need to be updated on close */
1547 if (file_inf
.LastWriteTime
)
1548 inode
->i_mtime
= cifs_NTtimeToUnix(file_inf
.LastWriteTime
);
1549 if (file_inf
.ChangeTime
)
1550 inode
->i_ctime
= cifs_NTtimeToUnix(file_inf
.ChangeTime
);
1551 if (file_inf
.LastAccessTime
)
1552 inode
->i_atime
= cifs_NTtimeToUnix(file_inf
.LastAccessTime
);
1555 * i_blocks is not related to (i_size / i_blksize),
1556 * but instead 512 byte (2**9) size is required for
1557 * calculating num blocks.
1559 if (le64_to_cpu(file_inf
.AllocationSize
) > 4096)
1561 (512 - 1 + le64_to_cpu(file_inf
.AllocationSize
)) >> 9;
1563 /* End of file and Attributes should not have to be updated on close */
1564 spin_unlock(&inode
->i_lock
);
1568 SMB2_request_res_key(const unsigned int xid
, struct cifs_tcon
*tcon
,
1569 u64 persistent_fid
, u64 volatile_fid
,
1570 struct copychunk_ioctl
*pcchunk
)
1573 unsigned int ret_data_len
;
1574 struct resume_key_req
*res_key
;
1576 rc
= SMB2_ioctl(xid
, tcon
, persistent_fid
, volatile_fid
,
1577 FSCTL_SRV_REQUEST_RESUME_KEY
, true /* is_fsctl */,
1578 NULL
, 0 /* no input */, CIFSMaxBufSize
,
1579 (char **)&res_key
, &ret_data_len
);
1581 if (rc
== -EOPNOTSUPP
) {
1582 pr_warn_once("Server share %s does not support copy range\n", tcon
->treeName
);
1583 goto req_res_key_exit
;
1585 cifs_tcon_dbg(VFS
, "refcpy ioctl error %d getting resume key\n", rc
);
1586 goto req_res_key_exit
;
1588 if (ret_data_len
< sizeof(struct resume_key_req
)) {
1589 cifs_tcon_dbg(VFS
, "Invalid refcopy resume key length\n");
1591 goto req_res_key_exit
;
1593 memcpy(pcchunk
->SourceKey
, res_key
->ResumeKey
, COPY_CHUNK_RES_KEY_SIZE
);
1601 struct smb_rqst rqst
[3];
1602 struct kvec rsp_iov
[3];
1603 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
1604 struct kvec qi_iov
[1];
1605 struct kvec io_iov
[SMB2_IOCTL_IOV_SIZE
];
1606 struct kvec si_iov
[SMB2_SET_INFO_IOV_SIZE
];
1607 struct kvec close_iov
[1];
1611 smb2_ioctl_query_info(const unsigned int xid
,
1612 struct cifs_tcon
*tcon
,
1613 struct cifs_sb_info
*cifs_sb
,
1614 __le16
*path
, int is_dir
,
1617 struct iqi_vars
*vars
;
1618 struct smb_rqst
*rqst
;
1619 struct kvec
*rsp_iov
;
1620 struct cifs_ses
*ses
= tcon
->ses
;
1621 struct TCP_Server_Info
*server
= cifs_pick_channel(ses
);
1622 char __user
*arg
= (char __user
*)p
;
1623 struct smb_query_info qi
;
1624 struct smb_query_info __user
*pqi
;
1626 int flags
= CIFS_CP_CREATE_CLOSE_OP
;
1627 struct smb2_query_info_rsp
*qi_rsp
= NULL
;
1628 struct smb2_ioctl_rsp
*io_rsp
= NULL
;
1629 void *buffer
= NULL
;
1630 int resp_buftype
[3];
1631 struct cifs_open_parms oparms
;
1632 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1633 struct cifs_fid fid
;
1634 unsigned int size
[2];
1636 int create_options
= is_dir
? CREATE_NOT_FILE
: CREATE_NOT_DIR
;
1637 void (*free_req1_func
)(struct smb_rqst
*r
);
1639 vars
= kzalloc(sizeof(*vars
), GFP_ATOMIC
);
1642 rqst
= &vars
->rqst
[0];
1643 rsp_iov
= &vars
->rsp_iov
[0];
1645 resp_buftype
[0] = resp_buftype
[1] = resp_buftype
[2] = CIFS_NO_BUFFER
;
1647 if (copy_from_user(&qi
, arg
, sizeof(struct smb_query_info
))) {
1651 if (qi
.output_buffer_length
> 1024) {
1656 if (!ses
|| !server
) {
1661 if (smb3_encryption_required(tcon
))
1662 flags
|= CIFS_TRANSFORM_REQ
;
1664 if (qi
.output_buffer_length
) {
1665 buffer
= memdup_user(arg
+ sizeof(struct smb_query_info
), qi
.output_buffer_length
);
1666 if (IS_ERR(buffer
)) {
1667 rc
= PTR_ERR(buffer
);
1673 rqst
[0].rq_iov
= &vars
->open_iov
[0];
1674 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
1676 memset(&oparms
, 0, sizeof(oparms
));
1678 oparms
.disposition
= FILE_OPEN
;
1679 oparms
.create_options
= cifs_create_options(cifs_sb
, create_options
);
1681 oparms
.reconnect
= false;
1683 if (qi
.flags
& PASSTHRU_FSCTL
) {
1684 switch (qi
.info_type
& FSCTL_DEVICE_ACCESS_MASK
) {
1685 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS
:
1686 oparms
.desired_access
= FILE_READ_DATA
| FILE_WRITE_DATA
| FILE_READ_ATTRIBUTES
| SYNCHRONIZE
;
1688 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS
:
1689 oparms
.desired_access
= GENERIC_ALL
;
1691 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS
:
1692 oparms
.desired_access
= GENERIC_READ
;
1694 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS
:
1695 oparms
.desired_access
= GENERIC_WRITE
;
1698 } else if (qi
.flags
& PASSTHRU_SET_INFO
) {
1699 oparms
.desired_access
= GENERIC_WRITE
;
1701 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| READ_CONTROL
;
1704 rc
= SMB2_open_init(tcon
, server
,
1705 &rqst
[0], &oplock
, &oparms
, path
);
1707 goto free_output_buffer
;
1708 smb2_set_next_command(tcon
, &rqst
[0]);
1711 if (qi
.flags
& PASSTHRU_FSCTL
) {
1712 /* Can eventually relax perm check since server enforces too */
1713 if (!capable(CAP_SYS_ADMIN
)) {
1717 rqst
[1].rq_iov
= &vars
->io_iov
[0];
1718 rqst
[1].rq_nvec
= SMB2_IOCTL_IOV_SIZE
;
1720 rc
= SMB2_ioctl_init(tcon
, server
, &rqst
[1], COMPOUND_FID
, COMPOUND_FID
,
1721 qi
.info_type
, true, buffer
, qi
.output_buffer_length
,
1722 CIFSMaxBufSize
- MAX_SMB2_CREATE_RESPONSE_SIZE
-
1723 MAX_SMB2_CLOSE_RESPONSE_SIZE
);
1724 free_req1_func
= SMB2_ioctl_free
;
1725 } else if (qi
.flags
== PASSTHRU_SET_INFO
) {
1726 /* Can eventually relax perm check since server enforces too */
1727 if (!capable(CAP_SYS_ADMIN
)) {
1731 if (qi
.output_buffer_length
< 8) {
1735 rqst
[1].rq_iov
= &vars
->si_iov
[0];
1736 rqst
[1].rq_nvec
= 1;
1738 /* MS-FSCC 2.4.13 FileEndOfFileInformation */
1742 rc
= SMB2_set_info_init(tcon
, server
, &rqst
[1], COMPOUND_FID
, COMPOUND_FID
,
1743 current
->tgid
, FILE_END_OF_FILE_INFORMATION
,
1744 SMB2_O_INFO_FILE
, 0, data
, size
);
1745 free_req1_func
= SMB2_set_info_free
;
1746 } else if (qi
.flags
== PASSTHRU_QUERY_INFO
) {
1747 rqst
[1].rq_iov
= &vars
->qi_iov
[0];
1748 rqst
[1].rq_nvec
= 1;
1750 rc
= SMB2_query_info_init(tcon
, server
,
1751 &rqst
[1], COMPOUND_FID
,
1752 COMPOUND_FID
, qi
.file_info_class
,
1753 qi
.info_type
, qi
.additional_information
,
1754 qi
.input_buffer_length
,
1755 qi
.output_buffer_length
, buffer
);
1756 free_req1_func
= SMB2_query_info_free
;
1757 } else { /* unknown flags */
1758 cifs_tcon_dbg(VFS
, "Invalid passthru query flags: 0x%x\n",
1765 smb2_set_next_command(tcon
, &rqst
[1]);
1766 smb2_set_related(&rqst
[1]);
1769 rqst
[2].rq_iov
= &vars
->close_iov
[0];
1770 rqst
[2].rq_nvec
= 1;
1772 rc
= SMB2_close_init(tcon
, server
,
1773 &rqst
[2], COMPOUND_FID
, COMPOUND_FID
, false);
1776 smb2_set_related(&rqst
[2]);
1778 rc
= compound_send_recv(xid
, ses
, server
,
1780 resp_buftype
, rsp_iov
);
1784 /* No need to bump num_remote_opens since handle immediately closed */
1785 if (qi
.flags
& PASSTHRU_FSCTL
) {
1786 pqi
= (struct smb_query_info __user
*)arg
;
1787 io_rsp
= (struct smb2_ioctl_rsp
*)rsp_iov
[1].iov_base
;
1788 if (le32_to_cpu(io_rsp
->OutputCount
) < qi
.input_buffer_length
)
1789 qi
.input_buffer_length
= le32_to_cpu(io_rsp
->OutputCount
);
1790 if (qi
.input_buffer_length
> 0 &&
1791 le32_to_cpu(io_rsp
->OutputOffset
) + qi
.input_buffer_length
1792 > rsp_iov
[1].iov_len
) {
1797 if (copy_to_user(&pqi
->input_buffer_length
,
1798 &qi
.input_buffer_length
,
1799 sizeof(qi
.input_buffer_length
))) {
1804 if (copy_to_user((void __user
*)pqi
+ sizeof(struct smb_query_info
),
1805 (const void *)io_rsp
+ le32_to_cpu(io_rsp
->OutputOffset
),
1806 qi
.input_buffer_length
))
1809 pqi
= (struct smb_query_info __user
*)arg
;
1810 qi_rsp
= (struct smb2_query_info_rsp
*)rsp_iov
[1].iov_base
;
1811 if (le32_to_cpu(qi_rsp
->OutputBufferLength
) < qi
.input_buffer_length
)
1812 qi
.input_buffer_length
= le32_to_cpu(qi_rsp
->OutputBufferLength
);
1813 if (copy_to_user(&pqi
->input_buffer_length
,
1814 &qi
.input_buffer_length
,
1815 sizeof(qi
.input_buffer_length
))) {
1820 if (copy_to_user(pqi
+ 1, qi_rsp
->Buffer
,
1821 qi
.input_buffer_length
))
1826 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
1827 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
1828 free_rsp_buf(resp_buftype
[2], rsp_iov
[2].iov_base
);
1829 SMB2_close_free(&rqst
[2]);
1831 free_req1_func(&rqst
[1]);
1833 SMB2_open_free(&rqst
[0]);
1842 smb2_copychunk_range(const unsigned int xid
,
1843 struct cifsFileInfo
*srcfile
,
1844 struct cifsFileInfo
*trgtfile
, u64 src_off
,
1845 u64 len
, u64 dest_off
)
1848 unsigned int ret_data_len
;
1849 struct copychunk_ioctl
*pcchunk
;
1850 struct copychunk_ioctl_rsp
*retbuf
= NULL
;
1851 struct cifs_tcon
*tcon
;
1852 int chunks_copied
= 0;
1853 bool chunk_sizes_updated
= false;
1854 ssize_t bytes_written
, total_bytes_written
= 0;
1855 struct inode
*inode
;
1857 pcchunk
= kmalloc(sizeof(struct copychunk_ioctl
), GFP_KERNEL
);
1860 * We need to flush all unwritten data before we can send the
1861 * copychunk ioctl to the server.
1863 inode
= d_inode(trgtfile
->dentry
);
1864 filemap_write_and_wait(inode
->i_mapping
);
1866 if (pcchunk
== NULL
)
1869 cifs_dbg(FYI
, "%s: about to call request res key\n", __func__
);
1870 /* Request a key from the server to identify the source of the copy */
1871 rc
= SMB2_request_res_key(xid
, tlink_tcon(srcfile
->tlink
),
1872 srcfile
->fid
.persistent_fid
,
1873 srcfile
->fid
.volatile_fid
, pcchunk
);
1875 /* Note: request_res_key sets res_key null only if rc !=0 */
1879 /* For now array only one chunk long, will make more flexible later */
1880 pcchunk
->ChunkCount
= cpu_to_le32(1);
1881 pcchunk
->Reserved
= 0;
1882 pcchunk
->Reserved2
= 0;
1884 tcon
= tlink_tcon(trgtfile
->tlink
);
1887 pcchunk
->SourceOffset
= cpu_to_le64(src_off
);
1888 pcchunk
->TargetOffset
= cpu_to_le64(dest_off
);
1890 cpu_to_le32(min_t(u32
, len
, tcon
->max_bytes_chunk
));
1892 /* Request server copy to target from src identified by key */
1895 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
1896 trgtfile
->fid
.volatile_fid
, FSCTL_SRV_COPYCHUNK_WRITE
,
1897 true /* is_fsctl */, (char *)pcchunk
,
1898 sizeof(struct copychunk_ioctl
), CIFSMaxBufSize
,
1899 (char **)&retbuf
, &ret_data_len
);
1902 sizeof(struct copychunk_ioctl_rsp
)) {
1903 cifs_tcon_dbg(VFS
, "Invalid cchunk response size\n");
1907 if (retbuf
->TotalBytesWritten
== 0) {
1908 cifs_dbg(FYI
, "no bytes copied\n");
1913 * Check if server claimed to write more than we asked
1915 if (le32_to_cpu(retbuf
->TotalBytesWritten
) >
1916 le32_to_cpu(pcchunk
->Length
)) {
1917 cifs_tcon_dbg(VFS
, "Invalid copy chunk response\n");
1921 if (le32_to_cpu(retbuf
->ChunksWritten
) != 1) {
1922 cifs_tcon_dbg(VFS
, "Invalid num chunks written\n");
1928 bytes_written
= le32_to_cpu(retbuf
->TotalBytesWritten
);
1929 src_off
+= bytes_written
;
1930 dest_off
+= bytes_written
;
1931 len
-= bytes_written
;
1932 total_bytes_written
+= bytes_written
;
1934 cifs_dbg(FYI
, "Chunks %d PartialChunk %d Total %zu\n",
1935 le32_to_cpu(retbuf
->ChunksWritten
),
1936 le32_to_cpu(retbuf
->ChunkBytesWritten
),
1938 } else if (rc
== -EINVAL
) {
1939 if (ret_data_len
!= sizeof(struct copychunk_ioctl_rsp
))
1942 cifs_dbg(FYI
, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1943 le32_to_cpu(retbuf
->ChunksWritten
),
1944 le32_to_cpu(retbuf
->ChunkBytesWritten
),
1945 le32_to_cpu(retbuf
->TotalBytesWritten
));
1948 * Check if this is the first request using these sizes,
1949 * (ie check if copy succeed once with original sizes
1950 * and check if the server gave us different sizes after
1951 * we already updated max sizes on previous request).
1952 * if not then why is the server returning an error now
1954 if ((chunks_copied
!= 0) || chunk_sizes_updated
)
1957 /* Check that server is not asking us to grow size */
1958 if (le32_to_cpu(retbuf
->ChunkBytesWritten
) <
1959 tcon
->max_bytes_chunk
)
1960 tcon
->max_bytes_chunk
=
1961 le32_to_cpu(retbuf
->ChunkBytesWritten
);
1963 goto cchunk_out
; /* server gave us bogus size */
1965 /* No need to change MaxChunks since already set to 1 */
1966 chunk_sizes_updated
= true;
1977 return total_bytes_written
;
1981 smb2_flush_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
1982 struct cifs_fid
*fid
)
1984 return SMB2_flush(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1988 smb2_read_data_offset(char *buf
)
1990 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
1992 return rsp
->DataOffset
;
1996 smb2_read_data_length(char *buf
, bool in_remaining
)
1998 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
2001 return le32_to_cpu(rsp
->DataRemaining
);
2003 return le32_to_cpu(rsp
->DataLength
);
2008 smb2_sync_read(const unsigned int xid
, struct cifs_fid
*pfid
,
2009 struct cifs_io_parms
*parms
, unsigned int *bytes_read
,
2010 char **buf
, int *buf_type
)
2012 parms
->persistent_fid
= pfid
->persistent_fid
;
2013 parms
->volatile_fid
= pfid
->volatile_fid
;
2014 return SMB2_read(xid
, parms
, bytes_read
, buf
, buf_type
);
2018 smb2_sync_write(const unsigned int xid
, struct cifs_fid
*pfid
,
2019 struct cifs_io_parms
*parms
, unsigned int *written
,
2020 struct kvec
*iov
, unsigned long nr_segs
)
2023 parms
->persistent_fid
= pfid
->persistent_fid
;
2024 parms
->volatile_fid
= pfid
->volatile_fid
;
2025 return SMB2_write(xid
, parms
, written
, iov
, nr_segs
);
2028 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
2029 static bool smb2_set_sparse(const unsigned int xid
, struct cifs_tcon
*tcon
,
2030 struct cifsFileInfo
*cfile
, struct inode
*inode
, __u8 setsparse
)
2032 struct cifsInodeInfo
*cifsi
;
2035 cifsi
= CIFS_I(inode
);
2037 /* if file already sparse don't bother setting sparse again */
2038 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && setsparse
)
2039 return true; /* already sparse */
2041 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && !setsparse
)
2042 return true; /* already not sparse */
2045 * Can't check for sparse support on share the usual way via the
2046 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
2047 * since Samba server doesn't set the flag on the share, yet
2048 * supports the set sparse FSCTL and returns sparse correctly
2049 * in the file attributes. If we fail setting sparse though we
2050 * mark that server does not support sparse files for this share
2051 * to avoid repeatedly sending the unsupported fsctl to server
2052 * if the file is repeatedly extended.
2054 if (tcon
->broken_sparse_sup
)
2057 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
2058 cfile
->fid
.volatile_fid
, FSCTL_SET_SPARSE
,
2060 &setsparse
, 1, CIFSMaxBufSize
, NULL
, NULL
);
2062 tcon
->broken_sparse_sup
= true;
2063 cifs_dbg(FYI
, "set sparse rc = %d\n", rc
);
2068 cifsi
->cifsAttrs
|= FILE_ATTRIBUTE_SPARSE_FILE
;
2070 cifsi
->cifsAttrs
&= (~FILE_ATTRIBUTE_SPARSE_FILE
);
2076 smb2_set_file_size(const unsigned int xid
, struct cifs_tcon
*tcon
,
2077 struct cifsFileInfo
*cfile
, __u64 size
, bool set_alloc
)
2079 __le64 eof
= cpu_to_le64(size
);
2080 struct inode
*inode
;
2083 * If extending file more than one page make sparse. Many Linux fs
2084 * make files sparse by default when extending via ftruncate
2086 inode
= d_inode(cfile
->dentry
);
2088 if (!set_alloc
&& (size
> inode
->i_size
+ 8192)) {
2089 __u8 set_sparse
= 1;
2091 /* whether set sparse succeeds or not, extend the file */
2092 smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
);
2095 return SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
2096 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
);
2100 smb2_duplicate_extents(const unsigned int xid
,
2101 struct cifsFileInfo
*srcfile
,
2102 struct cifsFileInfo
*trgtfile
, u64 src_off
,
2103 u64 len
, u64 dest_off
)
2106 unsigned int ret_data_len
;
2107 struct inode
*inode
;
2108 struct duplicate_extents_to_file dup_ext_buf
;
2109 struct cifs_tcon
*tcon
= tlink_tcon(trgtfile
->tlink
);
2111 /* server fileays advertise duplicate extent support with this flag */
2112 if ((le32_to_cpu(tcon
->fsAttrInfo
.Attributes
) &
2113 FILE_SUPPORTS_BLOCK_REFCOUNTING
) == 0)
2116 dup_ext_buf
.VolatileFileHandle
= srcfile
->fid
.volatile_fid
;
2117 dup_ext_buf
.PersistentFileHandle
= srcfile
->fid
.persistent_fid
;
2118 dup_ext_buf
.SourceFileOffset
= cpu_to_le64(src_off
);
2119 dup_ext_buf
.TargetFileOffset
= cpu_to_le64(dest_off
);
2120 dup_ext_buf
.ByteCount
= cpu_to_le64(len
);
2121 cifs_dbg(FYI
, "Duplicate extents: src off %lld dst off %lld len %lld\n",
2122 src_off
, dest_off
, len
);
2124 inode
= d_inode(trgtfile
->dentry
);
2125 if (inode
->i_size
< dest_off
+ len
) {
2126 rc
= smb2_set_file_size(xid
, tcon
, trgtfile
, dest_off
+ len
, false);
2128 goto duplicate_extents_out
;
2131 * Although also could set plausible allocation size (i_blocks)
2132 * here in addition to setting the file size, in reflink
2133 * it is likely that the target file is sparse. Its allocation
2134 * size will be queried on next revalidate, but it is important
2135 * to make sure that file's cached size is updated immediately
2137 cifs_setsize(inode
, dest_off
+ len
);
2139 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
2140 trgtfile
->fid
.volatile_fid
,
2141 FSCTL_DUPLICATE_EXTENTS_TO_FILE
,
2142 true /* is_fsctl */,
2143 (char *)&dup_ext_buf
,
2144 sizeof(struct duplicate_extents_to_file
),
2145 CIFSMaxBufSize
, NULL
,
2148 if (ret_data_len
> 0)
2149 cifs_dbg(FYI
, "Non-zero response length in duplicate extents\n");
2151 duplicate_extents_out
:
2156 smb2_set_compression(const unsigned int xid
, struct cifs_tcon
*tcon
,
2157 struct cifsFileInfo
*cfile
)
2159 return SMB2_set_compression(xid
, tcon
, cfile
->fid
.persistent_fid
,
2160 cfile
->fid
.volatile_fid
);
2164 smb3_set_integrity(const unsigned int xid
, struct cifs_tcon
*tcon
,
2165 struct cifsFileInfo
*cfile
)
2167 struct fsctl_set_integrity_information_req integr_info
;
2168 unsigned int ret_data_len
;
2170 integr_info
.ChecksumAlgorithm
= cpu_to_le16(CHECKSUM_TYPE_UNCHANGED
);
2171 integr_info
.Flags
= 0;
2172 integr_info
.Reserved
= 0;
2174 return SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
2175 cfile
->fid
.volatile_fid
,
2176 FSCTL_SET_INTEGRITY_INFORMATION
,
2177 true /* is_fsctl */,
2178 (char *)&integr_info
,
2179 sizeof(struct fsctl_set_integrity_information_req
),
2180 CIFSMaxBufSize
, NULL
,
2185 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
2186 #define GMT_TOKEN_SIZE 50
2188 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
2191 * Input buffer contains (empty) struct smb_snapshot array with size filled in
2192 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
2195 smb3_enum_snapshots(const unsigned int xid
, struct cifs_tcon
*tcon
,
2196 struct cifsFileInfo
*cfile
, void __user
*ioc_buf
)
2198 char *retbuf
= NULL
;
2199 unsigned int ret_data_len
= 0;
2201 u32 max_response_size
;
2202 struct smb_snapshot_array snapshot_in
;
2205 * On the first query to enumerate the list of snapshots available
2206 * for this volume the buffer begins with 0 (number of snapshots
2207 * which can be returned is zero since at that point we do not know
2208 * how big the buffer needs to be). On the second query,
2209 * it (ret_data_len) is set to number of snapshots so we can
2210 * know to set the maximum response size larger (see below).
2212 if (get_user(ret_data_len
, (unsigned int __user
*)ioc_buf
))
2216 * Note that for snapshot queries that servers like Azure expect that
2217 * the first query be minimal size (and just used to get the number/size
2218 * of previous versions) so response size must be specified as EXACTLY
2219 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
2222 if (ret_data_len
== 0)
2223 max_response_size
= MIN_SNAPSHOT_ARRAY_SIZE
;
2225 max_response_size
= CIFSMaxBufSize
;
2227 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
2228 cfile
->fid
.volatile_fid
,
2229 FSCTL_SRV_ENUMERATE_SNAPSHOTS
,
2230 true /* is_fsctl */,
2231 NULL
, 0 /* no input data */, max_response_size
,
2234 cifs_dbg(FYI
, "enum snaphots ioctl returned %d and ret buflen is %d\n",
2239 if (ret_data_len
&& (ioc_buf
!= NULL
) && (retbuf
!= NULL
)) {
2241 if (copy_from_user(&snapshot_in
, ioc_buf
,
2242 sizeof(struct smb_snapshot_array
))) {
2249 * Check for min size, ie not large enough to fit even one GMT
2250 * token (snapshot). On the first ioctl some users may pass in
2251 * smaller size (or zero) to simply get the size of the array
2252 * so the user space caller can allocate sufficient memory
2253 * and retry the ioctl again with larger array size sufficient
2254 * to hold all of the snapshot GMT tokens on the second try.
2256 if (snapshot_in
.snapshot_array_size
< GMT_TOKEN_SIZE
)
2257 ret_data_len
= sizeof(struct smb_snapshot_array
);
2260 * We return struct SRV_SNAPSHOT_ARRAY, followed by
2261 * the snapshot array (of 50 byte GMT tokens) each
2262 * representing an available previous version of the data
2264 if (ret_data_len
> (snapshot_in
.snapshot_array_size
+
2265 sizeof(struct smb_snapshot_array
)))
2266 ret_data_len
= snapshot_in
.snapshot_array_size
+
2267 sizeof(struct smb_snapshot_array
);
2269 if (copy_to_user(ioc_buf
, retbuf
, ret_data_len
))
2280 smb3_notify(const unsigned int xid
, struct file
*pfile
,
2281 void __user
*ioc_buf
)
2283 struct smb3_notify notify
;
2284 struct dentry
*dentry
= pfile
->f_path
.dentry
;
2285 struct inode
*inode
= file_inode(pfile
);
2286 struct cifs_sb_info
*cifs_sb
= CIFS_SB(inode
->i_sb
);
2287 struct cifs_open_parms oparms
;
2288 struct cifs_fid fid
;
2289 struct cifs_tcon
*tcon
;
2290 const unsigned char *path
;
2291 void *page
= alloc_dentry_path();
2292 __le16
*utf16_path
= NULL
;
2293 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
2296 path
= build_path_from_dentry(dentry
, page
);
2302 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
2303 if (utf16_path
== NULL
) {
2308 if (copy_from_user(¬ify
, ioc_buf
, sizeof(struct smb3_notify
))) {
2313 tcon
= cifs_sb_master_tcon(cifs_sb
);
2315 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| FILE_READ_DATA
;
2316 oparms
.disposition
= FILE_OPEN
;
2317 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
2319 oparms
.reconnect
= false;
2321 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
, NULL
,
2326 rc
= SMB2_change_notify(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
2327 notify
.watch_tree
, notify
.completion_filter
);
2329 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
2331 cifs_dbg(FYI
, "change notify for path %s rc %d\n", path
, rc
);
2334 free_dentry_path(page
);
2340 smb2_query_dir_first(const unsigned int xid
, struct cifs_tcon
*tcon
,
2341 const char *path
, struct cifs_sb_info
*cifs_sb
,
2342 struct cifs_fid
*fid
, __u16 search_flags
,
2343 struct cifs_search_info
*srch_inf
)
2346 struct smb_rqst rqst
[2];
2347 struct kvec rsp_iov
[2];
2348 int resp_buftype
[2];
2349 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
2350 struct kvec qd_iov
[SMB2_QUERY_DIRECTORY_IOV_SIZE
];
2352 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
2353 struct cifs_open_parms oparms
;
2354 struct smb2_query_directory_rsp
*qd_rsp
= NULL
;
2355 struct smb2_create_rsp
*op_rsp
= NULL
;
2356 struct TCP_Server_Info
*server
= cifs_pick_channel(tcon
->ses
);
2357 int retry_count
= 0;
2359 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
2363 if (smb3_encryption_required(tcon
))
2364 flags
|= CIFS_TRANSFORM_REQ
;
2366 memset(rqst
, 0, sizeof(rqst
));
2367 resp_buftype
[0] = resp_buftype
[1] = CIFS_NO_BUFFER
;
2368 memset(rsp_iov
, 0, sizeof(rsp_iov
));
2371 memset(&open_iov
, 0, sizeof(open_iov
));
2372 rqst
[0].rq_iov
= open_iov
;
2373 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
2376 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| FILE_READ_DATA
;
2377 oparms
.disposition
= FILE_OPEN
;
2378 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
2380 oparms
.reconnect
= false;
2382 rc
= SMB2_open_init(tcon
, server
,
2383 &rqst
[0], &oplock
, &oparms
, utf16_path
);
2386 smb2_set_next_command(tcon
, &rqst
[0]);
2388 /* Query directory */
2389 srch_inf
->entries_in_buffer
= 0;
2390 srch_inf
->index_of_last_entry
= 2;
2392 memset(&qd_iov
, 0, sizeof(qd_iov
));
2393 rqst
[1].rq_iov
= qd_iov
;
2394 rqst
[1].rq_nvec
= SMB2_QUERY_DIRECTORY_IOV_SIZE
;
2396 rc
= SMB2_query_directory_init(xid
, tcon
, server
,
2398 COMPOUND_FID
, COMPOUND_FID
,
2399 0, srch_inf
->info_level
);
2403 smb2_set_related(&rqst
[1]);
2406 rc
= compound_send_recv(xid
, tcon
->ses
, server
,
2408 resp_buftype
, rsp_iov
);
2410 if (rc
== -EAGAIN
&& retry_count
++ < 10)
2413 /* If the open failed there is nothing to do */
2414 op_rsp
= (struct smb2_create_rsp
*)rsp_iov
[0].iov_base
;
2415 if (op_rsp
== NULL
|| op_rsp
->sync_hdr
.Status
!= STATUS_SUCCESS
) {
2416 cifs_dbg(FYI
, "query_dir_first: open failed rc=%d\n", rc
);
2419 fid
->persistent_fid
= op_rsp
->PersistentFileId
;
2420 fid
->volatile_fid
= op_rsp
->VolatileFileId
;
2422 /* Anything else than ENODATA means a genuine error */
2423 if (rc
&& rc
!= -ENODATA
) {
2424 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
2425 cifs_dbg(FYI
, "query_dir_first: query directory failed rc=%d\n", rc
);
2426 trace_smb3_query_dir_err(xid
, fid
->persistent_fid
,
2427 tcon
->tid
, tcon
->ses
->Suid
, 0, 0, rc
);
2431 atomic_inc(&tcon
->num_remote_opens
);
2433 qd_rsp
= (struct smb2_query_directory_rsp
*)rsp_iov
[1].iov_base
;
2434 if (qd_rsp
->sync_hdr
.Status
== STATUS_NO_MORE_FILES
) {
2435 trace_smb3_query_dir_done(xid
, fid
->persistent_fid
,
2436 tcon
->tid
, tcon
->ses
->Suid
, 0, 0);
2437 srch_inf
->endOfSearch
= true;
2442 rc
= smb2_parse_query_directory(tcon
, &rsp_iov
[1], resp_buftype
[1],
2445 trace_smb3_query_dir_err(xid
, fid
->persistent_fid
, tcon
->tid
,
2446 tcon
->ses
->Suid
, 0, 0, rc
);
2449 resp_buftype
[1] = CIFS_NO_BUFFER
;
2451 trace_smb3_query_dir_done(xid
, fid
->persistent_fid
, tcon
->tid
,
2452 tcon
->ses
->Suid
, 0, srch_inf
->entries_in_buffer
);
2456 SMB2_open_free(&rqst
[0]);
2457 SMB2_query_directory_free(&rqst
[1]);
2458 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
2459 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
2464 smb2_query_dir_next(const unsigned int xid
, struct cifs_tcon
*tcon
,
2465 struct cifs_fid
*fid
, __u16 search_flags
,
2466 struct cifs_search_info
*srch_inf
)
2468 return SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
2469 fid
->volatile_fid
, 0, srch_inf
);
2473 smb2_close_dir(const unsigned int xid
, struct cifs_tcon
*tcon
,
2474 struct cifs_fid
*fid
)
2476 return SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
2480 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2481 * the number of credits and return true. Otherwise - return false.
2484 smb2_is_status_pending(char *buf
, struct TCP_Server_Info
*server
)
2486 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
2487 int scredits
, in_flight
;
2489 if (shdr
->Status
!= STATUS_PENDING
)
2492 if (shdr
->CreditRequest
) {
2493 spin_lock(&server
->req_lock
);
2494 server
->credits
+= le16_to_cpu(shdr
->CreditRequest
);
2495 scredits
= server
->credits
;
2496 in_flight
= server
->in_flight
;
2497 spin_unlock(&server
->req_lock
);
2498 wake_up(&server
->request_q
);
2500 trace_smb3_add_credits(server
->CurrentMid
,
2501 server
->conn_id
, server
->hostname
, scredits
,
2502 le16_to_cpu(shdr
->CreditRequest
), in_flight
);
2503 cifs_dbg(FYI
, "%s: status pending add %u credits total=%d\n",
2504 __func__
, le16_to_cpu(shdr
->CreditRequest
), scredits
);
2511 smb2_is_session_expired(char *buf
)
2513 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
2515 if (shdr
->Status
!= STATUS_NETWORK_SESSION_EXPIRED
&&
2516 shdr
->Status
!= STATUS_USER_SESSION_DELETED
)
2519 trace_smb3_ses_expired(shdr
->TreeId
, shdr
->SessionId
,
2520 le16_to_cpu(shdr
->Command
),
2521 le64_to_cpu(shdr
->MessageId
));
2522 cifs_dbg(FYI
, "Session expired or deleted\n");
2528 smb2_is_status_io_timeout(char *buf
)
2530 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
2532 if (shdr
->Status
== STATUS_IO_TIMEOUT
)
2539 smb2_is_network_name_deleted(char *buf
, struct TCP_Server_Info
*server
)
2541 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
2542 struct list_head
*tmp
, *tmp1
;
2543 struct cifs_ses
*ses
;
2544 struct cifs_tcon
*tcon
;
2546 if (shdr
->Status
!= STATUS_NETWORK_NAME_DELETED
)
2549 spin_lock(&cifs_tcp_ses_lock
);
2550 list_for_each(tmp
, &server
->smb_ses_list
) {
2551 ses
= list_entry(tmp
, struct cifs_ses
, smb_ses_list
);
2552 list_for_each(tmp1
, &ses
->tcon_list
) {
2553 tcon
= list_entry(tmp1
, struct cifs_tcon
, tcon_list
);
2554 if (tcon
->tid
== shdr
->TreeId
) {
2555 tcon
->need_reconnect
= true;
2556 spin_unlock(&cifs_tcp_ses_lock
);
2557 pr_warn_once("Server share %s deleted.\n",
2563 spin_unlock(&cifs_tcp_ses_lock
);
2567 smb2_oplock_response(struct cifs_tcon
*tcon
, struct cifs_fid
*fid
,
2568 struct cifsInodeInfo
*cinode
)
2570 if (tcon
->ses
->server
->capabilities
& SMB2_GLOBAL_CAP_LEASING
)
2571 return SMB2_lease_break(0, tcon
, cinode
->lease_key
,
2572 smb2_get_lease_state(cinode
));
2574 return SMB2_oplock_break(0, tcon
, fid
->persistent_fid
,
2576 CIFS_CACHE_READ(cinode
) ? 1 : 0);
2580 smb2_set_related(struct smb_rqst
*rqst
)
2582 struct smb2_sync_hdr
*shdr
;
2584 shdr
= (struct smb2_sync_hdr
*)(rqst
->rq_iov
[0].iov_base
);
2586 cifs_dbg(FYI
, "shdr NULL in smb2_set_related\n");
2589 shdr
->Flags
|= SMB2_FLAGS_RELATED_OPERATIONS
;
2592 char smb2_padding
[7] = {0, 0, 0, 0, 0, 0, 0};
2595 smb2_set_next_command(struct cifs_tcon
*tcon
, struct smb_rqst
*rqst
)
2597 struct smb2_sync_hdr
*shdr
;
2598 struct cifs_ses
*ses
= tcon
->ses
;
2599 struct TCP_Server_Info
*server
= ses
->server
;
2600 unsigned long len
= smb_rqst_len(server
, rqst
);
2603 shdr
= (struct smb2_sync_hdr
*)(rqst
->rq_iov
[0].iov_base
);
2605 cifs_dbg(FYI
, "shdr NULL in smb2_set_next_command\n");
2609 /* SMB headers in a compound are 8 byte aligned. */
2611 /* No padding needed */
2615 num_padding
= 8 - (len
& 7);
2616 if (!smb3_encryption_required(tcon
)) {
2618 * If we do not have encryption then we can just add an extra
2619 * iov for the padding.
2621 rqst
->rq_iov
[rqst
->rq_nvec
].iov_base
= smb2_padding
;
2622 rqst
->rq_iov
[rqst
->rq_nvec
].iov_len
= num_padding
;
2627 * We can not add a small padding iov for the encryption case
2628 * because the encryption framework can not handle the padding
2630 * We have to flatten this into a single buffer and add
2631 * the padding to it.
2633 for (i
= 1; i
< rqst
->rq_nvec
; i
++) {
2634 memcpy(rqst
->rq_iov
[0].iov_base
+
2635 rqst
->rq_iov
[0].iov_len
,
2636 rqst
->rq_iov
[i
].iov_base
,
2637 rqst
->rq_iov
[i
].iov_len
);
2638 rqst
->rq_iov
[0].iov_len
+= rqst
->rq_iov
[i
].iov_len
;
2640 memset(rqst
->rq_iov
[0].iov_base
+ rqst
->rq_iov
[0].iov_len
,
2642 rqst
->rq_iov
[0].iov_len
+= num_padding
;
2648 shdr
->NextCommand
= cpu_to_le32(len
);
2652 * Passes the query info response back to the caller on success.
2653 * Caller need to free this with free_rsp_buf().
2656 smb2_query_info_compound(const unsigned int xid
, struct cifs_tcon
*tcon
,
2657 __le16
*utf16_path
, u32 desired_access
,
2658 u32
class, u32 type
, u32 output_len
,
2659 struct kvec
*rsp
, int *buftype
,
2660 struct cifs_sb_info
*cifs_sb
)
2662 struct cifs_ses
*ses
= tcon
->ses
;
2663 struct TCP_Server_Info
*server
= cifs_pick_channel(ses
);
2664 int flags
= CIFS_CP_CREATE_CLOSE_OP
;
2665 struct smb_rqst rqst
[3];
2666 int resp_buftype
[3];
2667 struct kvec rsp_iov
[3];
2668 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
2669 struct kvec qi_iov
[1];
2670 struct kvec close_iov
[1];
2671 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
2672 struct cifs_open_parms oparms
;
2673 struct cifs_fid fid
;
2676 if (smb3_encryption_required(tcon
))
2677 flags
|= CIFS_TRANSFORM_REQ
;
2679 memset(rqst
, 0, sizeof(rqst
));
2680 resp_buftype
[0] = resp_buftype
[1] = resp_buftype
[2] = CIFS_NO_BUFFER
;
2681 memset(rsp_iov
, 0, sizeof(rsp_iov
));
2683 memset(&open_iov
, 0, sizeof(open_iov
));
2684 rqst
[0].rq_iov
= open_iov
;
2685 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
2688 oparms
.desired_access
= desired_access
;
2689 oparms
.disposition
= FILE_OPEN
;
2690 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
2692 oparms
.reconnect
= false;
2694 rc
= SMB2_open_init(tcon
, server
,
2695 &rqst
[0], &oplock
, &oparms
, utf16_path
);
2698 smb2_set_next_command(tcon
, &rqst
[0]);
2700 memset(&qi_iov
, 0, sizeof(qi_iov
));
2701 rqst
[1].rq_iov
= qi_iov
;
2702 rqst
[1].rq_nvec
= 1;
2704 rc
= SMB2_query_info_init(tcon
, server
,
2705 &rqst
[1], COMPOUND_FID
, COMPOUND_FID
,
2711 smb2_set_next_command(tcon
, &rqst
[1]);
2712 smb2_set_related(&rqst
[1]);
2714 memset(&close_iov
, 0, sizeof(close_iov
));
2715 rqst
[2].rq_iov
= close_iov
;
2716 rqst
[2].rq_nvec
= 1;
2718 rc
= SMB2_close_init(tcon
, server
,
2719 &rqst
[2], COMPOUND_FID
, COMPOUND_FID
, false);
2722 smb2_set_related(&rqst
[2]);
2724 rc
= compound_send_recv(xid
, ses
, server
,
2726 resp_buftype
, rsp_iov
);
2728 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
2729 if (rc
== -EREMCHG
) {
2730 tcon
->need_reconnect
= true;
2731 pr_warn_once("server share %s deleted\n",
2737 *buftype
= resp_buftype
[1];
2740 SMB2_open_free(&rqst
[0]);
2741 SMB2_query_info_free(&rqst
[1]);
2742 SMB2_close_free(&rqst
[2]);
2743 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
2744 free_rsp_buf(resp_buftype
[2], rsp_iov
[2].iov_base
);
2749 smb2_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
2750 struct cifs_sb_info
*cifs_sb
, struct kstatfs
*buf
)
2752 struct smb2_query_info_rsp
*rsp
;
2753 struct smb2_fs_full_size_info
*info
= NULL
;
2754 __le16 utf16_path
= 0; /* Null - open root of share */
2755 struct kvec rsp_iov
= {NULL
, 0};
2756 int buftype
= CIFS_NO_BUFFER
;
2760 rc
= smb2_query_info_compound(xid
, tcon
, &utf16_path
,
2761 FILE_READ_ATTRIBUTES
,
2762 FS_FULL_SIZE_INFORMATION
,
2763 SMB2_O_INFO_FILESYSTEM
,
2764 sizeof(struct smb2_fs_full_size_info
),
2765 &rsp_iov
, &buftype
, cifs_sb
);
2769 rsp
= (struct smb2_query_info_rsp
*)rsp_iov
.iov_base
;
2770 buf
->f_type
= SMB2_MAGIC_NUMBER
;
2771 info
= (struct smb2_fs_full_size_info
*)(
2772 le16_to_cpu(rsp
->OutputBufferOffset
) + (char *)rsp
);
2773 rc
= smb2_validate_iov(le16_to_cpu(rsp
->OutputBufferOffset
),
2774 le32_to_cpu(rsp
->OutputBufferLength
),
2776 sizeof(struct smb2_fs_full_size_info
));
2778 smb2_copy_fs_info_to_kstatfs(info
, buf
);
2781 free_rsp_buf(buftype
, rsp_iov
.iov_base
);
2786 smb311_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
2787 struct cifs_sb_info
*cifs_sb
, struct kstatfs
*buf
)
2790 __le16 srch_path
= 0; /* Null - open root of share */
2791 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
2792 struct cifs_open_parms oparms
;
2793 struct cifs_fid fid
;
2795 if (!tcon
->posix_extensions
)
2796 return smb2_queryfs(xid
, tcon
, cifs_sb
, buf
);
2799 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
2800 oparms
.disposition
= FILE_OPEN
;
2801 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
2803 oparms
.reconnect
= false;
2805 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
,
2810 rc
= SMB311_posix_qfs_info(xid
, tcon
, fid
.persistent_fid
,
2811 fid
.volatile_fid
, buf
);
2812 buf
->f_type
= SMB2_MAGIC_NUMBER
;
2813 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
2818 smb2_compare_fids(struct cifsFileInfo
*ob1
, struct cifsFileInfo
*ob2
)
2820 return ob1
->fid
.persistent_fid
== ob2
->fid
.persistent_fid
&&
2821 ob1
->fid
.volatile_fid
== ob2
->fid
.volatile_fid
;
2825 smb2_mand_lock(const unsigned int xid
, struct cifsFileInfo
*cfile
, __u64 offset
,
2826 __u64 length
, __u32 type
, int lock
, int unlock
, bool wait
)
2828 if (unlock
&& !lock
)
2829 type
= SMB2_LOCKFLAG_UNLOCK
;
2830 return SMB2_lock(xid
, tlink_tcon(cfile
->tlink
),
2831 cfile
->fid
.persistent_fid
, cfile
->fid
.volatile_fid
,
2832 current
->tgid
, length
, offset
, type
, wait
);
2836 smb2_get_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
2838 memcpy(fid
->lease_key
, CIFS_I(inode
)->lease_key
, SMB2_LEASE_KEY_SIZE
);
2842 smb2_set_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
2844 memcpy(CIFS_I(inode
)->lease_key
, fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
2848 smb2_new_lease_key(struct cifs_fid
*fid
)
2850 generate_random_uuid(fid
->lease_key
);
2854 smb2_get_dfs_refer(const unsigned int xid
, struct cifs_ses
*ses
,
2855 const char *search_name
,
2856 struct dfs_info3_param
**target_nodes
,
2857 unsigned int *num_of_nodes
,
2858 const struct nls_table
*nls_codepage
, int remap
)
2861 __le16
*utf16_path
= NULL
;
2862 int utf16_path_len
= 0;
2863 struct cifs_tcon
*tcon
;
2864 struct fsctl_get_dfs_referral_req
*dfs_req
= NULL
;
2865 struct get_dfs_referral_rsp
*dfs_rsp
= NULL
;
2866 u32 dfs_req_size
= 0, dfs_rsp_size
= 0;
2868 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, search_name
);
2871 * Try to use the IPC tcon, otherwise just use any
2873 tcon
= ses
->tcon_ipc
;
2875 spin_lock(&cifs_tcp_ses_lock
);
2876 tcon
= list_first_entry_or_null(&ses
->tcon_list
,
2881 spin_unlock(&cifs_tcp_ses_lock
);
2885 cifs_dbg(VFS
, "session %p has no tcon available for a dfs referral request\n",
2891 utf16_path
= cifs_strndup_to_utf16(search_name
, PATH_MAX
,
2893 nls_codepage
, remap
);
2899 dfs_req_size
= sizeof(*dfs_req
) + utf16_path_len
;
2900 dfs_req
= kzalloc(dfs_req_size
, GFP_KERNEL
);
2906 /* Highest DFS referral version understood */
2907 dfs_req
->MaxReferralLevel
= DFS_VERSION
;
2909 /* Path to resolve in an UTF-16 null-terminated string */
2910 memcpy(dfs_req
->RequestFileName
, utf16_path
, utf16_path_len
);
2913 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
2914 FSCTL_DFS_GET_REFERRALS
,
2915 true /* is_fsctl */,
2916 (char *)dfs_req
, dfs_req_size
, CIFSMaxBufSize
,
2917 (char **)&dfs_rsp
, &dfs_rsp_size
);
2918 } while (rc
== -EAGAIN
);
2921 if ((rc
!= -ENOENT
) && (rc
!= -EOPNOTSUPP
))
2922 cifs_tcon_dbg(VFS
, "ioctl error in %s rc=%d\n", __func__
, rc
);
2926 rc
= parse_dfs_referrals(dfs_rsp
, dfs_rsp_size
,
2927 num_of_nodes
, target_nodes
,
2928 nls_codepage
, remap
, search_name
,
2929 true /* is_unicode */);
2931 cifs_tcon_dbg(VFS
, "parse error in %s rc=%d\n", __func__
, rc
);
2936 if (tcon
&& !tcon
->ipc
) {
2937 /* ipc tcons are not refcounted */
2938 spin_lock(&cifs_tcp_ses_lock
);
2940 /* tc_count can never go negative */
2941 WARN_ON(tcon
->tc_count
< 0);
2942 spin_unlock(&cifs_tcp_ses_lock
);
2951 parse_reparse_posix(struct reparse_posix_data
*symlink_buf
,
2952 u32 plen
, char **target_path
,
2953 struct cifs_sb_info
*cifs_sb
)
2957 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
2958 len
= le16_to_cpu(symlink_buf
->ReparseDataLength
);
2960 if (le64_to_cpu(symlink_buf
->InodeType
) != NFS_SPECFILE_LNK
) {
2961 cifs_dbg(VFS
, "%lld not a supported symlink type\n",
2962 le64_to_cpu(symlink_buf
->InodeType
));
2966 *target_path
= cifs_strndup_from_utf16(
2967 symlink_buf
->PathBuffer
,
2968 len
, true, cifs_sb
->local_nls
);
2969 if (!(*target_path
))
2972 convert_delimiter(*target_path
, '/');
2973 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
2979 parse_reparse_symlink(struct reparse_symlink_data_buffer
*symlink_buf
,
2980 u32 plen
, char **target_path
,
2981 struct cifs_sb_info
*cifs_sb
)
2983 unsigned int sub_len
;
2984 unsigned int sub_offset
;
2986 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */
2988 sub_offset
= le16_to_cpu(symlink_buf
->SubstituteNameOffset
);
2989 sub_len
= le16_to_cpu(symlink_buf
->SubstituteNameLength
);
2990 if (sub_offset
+ 20 > plen
||
2991 sub_offset
+ sub_len
+ 20 > plen
) {
2992 cifs_dbg(VFS
, "srv returned malformed symlink buffer\n");
2996 *target_path
= cifs_strndup_from_utf16(
2997 symlink_buf
->PathBuffer
+ sub_offset
,
2998 sub_len
, true, cifs_sb
->local_nls
);
2999 if (!(*target_path
))
3002 convert_delimiter(*target_path
, '/');
3003 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
3009 parse_reparse_point(struct reparse_data_buffer
*buf
,
3010 u32 plen
, char **target_path
,
3011 struct cifs_sb_info
*cifs_sb
)
3013 if (plen
< sizeof(struct reparse_data_buffer
)) {
3014 cifs_dbg(VFS
, "reparse buffer is too small. Must be at least 8 bytes but was %d\n",
3019 if (plen
< le16_to_cpu(buf
->ReparseDataLength
) +
3020 sizeof(struct reparse_data_buffer
)) {
3021 cifs_dbg(VFS
, "srv returned invalid reparse buf length: %d\n",
3026 /* See MS-FSCC 2.1.2 */
3027 switch (le32_to_cpu(buf
->ReparseTag
)) {
3028 case IO_REPARSE_TAG_NFS
:
3029 return parse_reparse_posix(
3030 (struct reparse_posix_data
*)buf
,
3031 plen
, target_path
, cifs_sb
);
3032 case IO_REPARSE_TAG_SYMLINK
:
3033 return parse_reparse_symlink(
3034 (struct reparse_symlink_data_buffer
*)buf
,
3035 plen
, target_path
, cifs_sb
);
3037 cifs_dbg(VFS
, "srv returned unknown symlink buffer tag:0x%08x\n",
3038 le32_to_cpu(buf
->ReparseTag
));
3043 #define SMB2_SYMLINK_STRUCT_SIZE \
3044 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
3047 smb2_query_symlink(const unsigned int xid
, struct cifs_tcon
*tcon
,
3048 struct cifs_sb_info
*cifs_sb
, const char *full_path
,
3049 char **target_path
, bool is_reparse_point
)
3052 __le16
*utf16_path
= NULL
;
3053 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
3054 struct cifs_open_parms oparms
;
3055 struct cifs_fid fid
;
3056 struct kvec err_iov
= {NULL
, 0};
3057 struct smb2_err_rsp
*err_buf
= NULL
;
3058 struct smb2_symlink_err_rsp
*symlink
;
3059 struct TCP_Server_Info
*server
= cifs_pick_channel(tcon
->ses
);
3060 unsigned int sub_len
;
3061 unsigned int sub_offset
;
3062 unsigned int print_len
;
3063 unsigned int print_offset
;
3064 int flags
= CIFS_CP_CREATE_CLOSE_OP
;
3065 struct smb_rqst rqst
[3];
3066 int resp_buftype
[3];
3067 struct kvec rsp_iov
[3];
3068 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
3069 struct kvec io_iov
[SMB2_IOCTL_IOV_SIZE
];
3070 struct kvec close_iov
[1];
3071 struct smb2_create_rsp
*create_rsp
;
3072 struct smb2_ioctl_rsp
*ioctl_rsp
;
3073 struct reparse_data_buffer
*reparse_buf
;
3074 int create_options
= is_reparse_point
? OPEN_REPARSE_POINT
: 0;
3077 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, full_path
);
3079 *target_path
= NULL
;
3081 if (smb3_encryption_required(tcon
))
3082 flags
|= CIFS_TRANSFORM_REQ
;
3084 memset(rqst
, 0, sizeof(rqst
));
3085 resp_buftype
[0] = resp_buftype
[1] = resp_buftype
[2] = CIFS_NO_BUFFER
;
3086 memset(rsp_iov
, 0, sizeof(rsp_iov
));
3088 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
3093 memset(&open_iov
, 0, sizeof(open_iov
));
3094 rqst
[0].rq_iov
= open_iov
;
3095 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
3097 memset(&oparms
, 0, sizeof(oparms
));
3099 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
3100 oparms
.disposition
= FILE_OPEN
;
3101 oparms
.create_options
= cifs_create_options(cifs_sb
, create_options
);
3103 oparms
.reconnect
= false;
3105 rc
= SMB2_open_init(tcon
, server
,
3106 &rqst
[0], &oplock
, &oparms
, utf16_path
);
3109 smb2_set_next_command(tcon
, &rqst
[0]);
3113 memset(&io_iov
, 0, sizeof(io_iov
));
3114 rqst
[1].rq_iov
= io_iov
;
3115 rqst
[1].rq_nvec
= SMB2_IOCTL_IOV_SIZE
;
3117 rc
= SMB2_ioctl_init(tcon
, server
,
3118 &rqst
[1], fid
.persistent_fid
,
3119 fid
.volatile_fid
, FSCTL_GET_REPARSE_POINT
,
3120 true /* is_fctl */, NULL
, 0,
3122 MAX_SMB2_CREATE_RESPONSE_SIZE
-
3123 MAX_SMB2_CLOSE_RESPONSE_SIZE
);
3127 smb2_set_next_command(tcon
, &rqst
[1]);
3128 smb2_set_related(&rqst
[1]);
3132 memset(&close_iov
, 0, sizeof(close_iov
));
3133 rqst
[2].rq_iov
= close_iov
;
3134 rqst
[2].rq_nvec
= 1;
3136 rc
= SMB2_close_init(tcon
, server
,
3137 &rqst
[2], COMPOUND_FID
, COMPOUND_FID
, false);
3141 smb2_set_related(&rqst
[2]);
3143 rc
= compound_send_recv(xid
, tcon
->ses
, server
,
3145 resp_buftype
, rsp_iov
);
3147 create_rsp
= rsp_iov
[0].iov_base
;
3148 if (create_rsp
&& create_rsp
->sync_hdr
.Status
)
3149 err_iov
= rsp_iov
[0];
3150 ioctl_rsp
= rsp_iov
[1].iov_base
;
3153 * Open was successful and we got an ioctl response.
3155 if ((rc
== 0) && (is_reparse_point
)) {
3156 /* See MS-FSCC 2.3.23 */
3158 reparse_buf
= (struct reparse_data_buffer
*)
3159 ((char *)ioctl_rsp
+
3160 le32_to_cpu(ioctl_rsp
->OutputOffset
));
3161 plen
= le32_to_cpu(ioctl_rsp
->OutputCount
);
3163 if (plen
+ le32_to_cpu(ioctl_rsp
->OutputOffset
) >
3164 rsp_iov
[1].iov_len
) {
3165 cifs_tcon_dbg(VFS
, "srv returned invalid ioctl len: %d\n",
3171 rc
= parse_reparse_point(reparse_buf
, plen
, target_path
,
3176 if (!rc
|| !err_iov
.iov_base
) {
3181 err_buf
= err_iov
.iov_base
;
3182 if (le32_to_cpu(err_buf
->ByteCount
) < sizeof(struct smb2_symlink_err_rsp
) ||
3183 err_iov
.iov_len
< SMB2_SYMLINK_STRUCT_SIZE
) {
3188 symlink
= (struct smb2_symlink_err_rsp
*)err_buf
->ErrorData
;
3189 if (le32_to_cpu(symlink
->SymLinkErrorTag
) != SYMLINK_ERROR_TAG
||
3190 le32_to_cpu(symlink
->ReparseTag
) != IO_REPARSE_TAG_SYMLINK
) {
3195 /* open must fail on symlink - reset rc */
3197 sub_len
= le16_to_cpu(symlink
->SubstituteNameLength
);
3198 sub_offset
= le16_to_cpu(symlink
->SubstituteNameOffset
);
3199 print_len
= le16_to_cpu(symlink
->PrintNameLength
);
3200 print_offset
= le16_to_cpu(symlink
->PrintNameOffset
);
3202 if (err_iov
.iov_len
< SMB2_SYMLINK_STRUCT_SIZE
+ sub_offset
+ sub_len
) {
3207 if (err_iov
.iov_len
<
3208 SMB2_SYMLINK_STRUCT_SIZE
+ print_offset
+ print_len
) {
3213 *target_path
= cifs_strndup_from_utf16(
3214 (char *)symlink
->PathBuffer
+ sub_offset
,
3215 sub_len
, true, cifs_sb
->local_nls
);
3216 if (!(*target_path
)) {
3220 convert_delimiter(*target_path
, '/');
3221 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
3224 cifs_dbg(FYI
, "query symlink rc %d\n", rc
);
3226 SMB2_open_free(&rqst
[0]);
3227 SMB2_ioctl_free(&rqst
[1]);
3228 SMB2_close_free(&rqst
[2]);
3229 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
3230 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
3231 free_rsp_buf(resp_buftype
[2], rsp_iov
[2].iov_base
);
3236 smb2_query_reparse_tag(const unsigned int xid
, struct cifs_tcon
*tcon
,
3237 struct cifs_sb_info
*cifs_sb
, const char *full_path
,
3241 __le16
*utf16_path
= NULL
;
3242 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
3243 struct cifs_open_parms oparms
;
3244 struct cifs_fid fid
;
3245 struct TCP_Server_Info
*server
= cifs_pick_channel(tcon
->ses
);
3246 int flags
= CIFS_CP_CREATE_CLOSE_OP
;
3247 struct smb_rqst rqst
[3];
3248 int resp_buftype
[3];
3249 struct kvec rsp_iov
[3];
3250 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
3251 struct kvec io_iov
[SMB2_IOCTL_IOV_SIZE
];
3252 struct kvec close_iov
[1];
3253 struct smb2_ioctl_rsp
*ioctl_rsp
;
3254 struct reparse_data_buffer
*reparse_buf
;
3257 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, full_path
);
3259 if (smb3_encryption_required(tcon
))
3260 flags
|= CIFS_TRANSFORM_REQ
;
3262 memset(rqst
, 0, sizeof(rqst
));
3263 resp_buftype
[0] = resp_buftype
[1] = resp_buftype
[2] = CIFS_NO_BUFFER
;
3264 memset(rsp_iov
, 0, sizeof(rsp_iov
));
3266 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
3271 * setup smb2open - TODO add optimization to call cifs_get_readable_path
3272 * to see if there is a handle already open that we can use
3274 memset(&open_iov
, 0, sizeof(open_iov
));
3275 rqst
[0].rq_iov
= open_iov
;
3276 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
3278 memset(&oparms
, 0, sizeof(oparms
));
3280 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
3281 oparms
.disposition
= FILE_OPEN
;
3282 oparms
.create_options
= cifs_create_options(cifs_sb
, OPEN_REPARSE_POINT
);
3284 oparms
.reconnect
= false;
3286 rc
= SMB2_open_init(tcon
, server
,
3287 &rqst
[0], &oplock
, &oparms
, utf16_path
);
3290 smb2_set_next_command(tcon
, &rqst
[0]);
3294 memset(&io_iov
, 0, sizeof(io_iov
));
3295 rqst
[1].rq_iov
= io_iov
;
3296 rqst
[1].rq_nvec
= SMB2_IOCTL_IOV_SIZE
;
3298 rc
= SMB2_ioctl_init(tcon
, server
,
3299 &rqst
[1], COMPOUND_FID
,
3300 COMPOUND_FID
, FSCTL_GET_REPARSE_POINT
,
3301 true /* is_fctl */, NULL
, 0,
3303 MAX_SMB2_CREATE_RESPONSE_SIZE
-
3304 MAX_SMB2_CLOSE_RESPONSE_SIZE
);
3308 smb2_set_next_command(tcon
, &rqst
[1]);
3309 smb2_set_related(&rqst
[1]);
3313 memset(&close_iov
, 0, sizeof(close_iov
));
3314 rqst
[2].rq_iov
= close_iov
;
3315 rqst
[2].rq_nvec
= 1;
3317 rc
= SMB2_close_init(tcon
, server
,
3318 &rqst
[2], COMPOUND_FID
, COMPOUND_FID
, false);
3322 smb2_set_related(&rqst
[2]);
3324 rc
= compound_send_recv(xid
, tcon
->ses
, server
,
3326 resp_buftype
, rsp_iov
);
3328 ioctl_rsp
= rsp_iov
[1].iov_base
;
3331 * Open was successful and we got an ioctl response.
3334 /* See MS-FSCC 2.3.23 */
3336 reparse_buf
= (struct reparse_data_buffer
*)
3337 ((char *)ioctl_rsp
+
3338 le32_to_cpu(ioctl_rsp
->OutputOffset
));
3339 plen
= le32_to_cpu(ioctl_rsp
->OutputCount
);
3341 if (plen
+ le32_to_cpu(ioctl_rsp
->OutputOffset
) >
3342 rsp_iov
[1].iov_len
) {
3343 cifs_tcon_dbg(FYI
, "srv returned invalid ioctl len: %d\n",
3348 *tag
= le32_to_cpu(reparse_buf
->ReparseTag
);
3353 SMB2_open_free(&rqst
[0]);
3354 SMB2_ioctl_free(&rqst
[1]);
3355 SMB2_close_free(&rqst
[2]);
3356 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
3357 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
3358 free_rsp_buf(resp_buftype
[2], rsp_iov
[2].iov_base
);
3362 static struct cifs_ntsd
*
3363 get_smb2_acl_by_fid(struct cifs_sb_info
*cifs_sb
,
3364 const struct cifs_fid
*cifsfid
, u32
*pacllen
, u32 info
)
3366 struct cifs_ntsd
*pntsd
= NULL
;
3368 int rc
= -EOPNOTSUPP
;
3369 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
3372 return ERR_CAST(tlink
);
3375 cifs_dbg(FYI
, "trying to get acl\n");
3377 rc
= SMB2_query_acl(xid
, tlink_tcon(tlink
), cifsfid
->persistent_fid
,
3378 cifsfid
->volatile_fid
, (void **)&pntsd
, pacllen
,
3382 cifs_put_tlink(tlink
);
3384 cifs_dbg(FYI
, "%s: rc = %d ACL len %d\n", __func__
, rc
, *pacllen
);
3391 static struct cifs_ntsd
*
3392 get_smb2_acl_by_path(struct cifs_sb_info
*cifs_sb
,
3393 const char *path
, u32
*pacllen
, u32 info
)
3395 struct cifs_ntsd
*pntsd
= NULL
;
3396 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
3399 struct cifs_tcon
*tcon
;
3400 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
3401 struct cifs_fid fid
;
3402 struct cifs_open_parms oparms
;
3405 cifs_dbg(FYI
, "get smb3 acl for path %s\n", path
);
3407 return ERR_CAST(tlink
);
3409 tcon
= tlink_tcon(tlink
);
3412 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
3420 oparms
.desired_access
= READ_CONTROL
;
3421 oparms
.disposition
= FILE_OPEN
;
3423 * When querying an ACL, even if the file is a symlink we want to open
3424 * the source not the target, and so the protocol requires that the
3425 * client specify this flag when opening a reparse point
3427 oparms
.create_options
= cifs_create_options(cifs_sb
, 0) | OPEN_REPARSE_POINT
;
3429 oparms
.reconnect
= false;
3431 if (info
& SACL_SECINFO
)
3432 oparms
.desired_access
|= SYSTEM_SECURITY
;
3434 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
, NULL
,
3438 rc
= SMB2_query_acl(xid
, tlink_tcon(tlink
), fid
.persistent_fid
,
3439 fid
.volatile_fid
, (void **)&pntsd
, pacllen
,
3441 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
3444 cifs_put_tlink(tlink
);
3447 cifs_dbg(FYI
, "%s: rc = %d ACL len %d\n", __func__
, rc
, *pacllen
);
3454 set_smb2_acl(struct cifs_ntsd
*pnntsd
, __u32 acllen
,
3455 struct inode
*inode
, const char *path
, int aclflag
)
3457 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
3459 int rc
, access_flags
= 0;
3460 struct cifs_tcon
*tcon
;
3461 struct cifs_sb_info
*cifs_sb
= CIFS_SB(inode
->i_sb
);
3462 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
3463 struct cifs_fid fid
;
3464 struct cifs_open_parms oparms
;
3467 cifs_dbg(FYI
, "set smb3 acl for path %s\n", path
);
3469 return PTR_ERR(tlink
);
3471 tcon
= tlink_tcon(tlink
);
3474 if (aclflag
& CIFS_ACL_OWNER
|| aclflag
& CIFS_ACL_GROUP
)
3475 access_flags
|= WRITE_OWNER
;
3476 if (aclflag
& CIFS_ACL_SACL
)
3477 access_flags
|= SYSTEM_SECURITY
;
3478 if (aclflag
& CIFS_ACL_DACL
)
3479 access_flags
|= WRITE_DAC
;
3481 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
3489 oparms
.desired_access
= access_flags
;
3490 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
3491 oparms
.disposition
= FILE_OPEN
;
3494 oparms
.reconnect
= false;
3496 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
,
3500 rc
= SMB2_set_acl(xid
, tlink_tcon(tlink
), fid
.persistent_fid
,
3501 fid
.volatile_fid
, pnntsd
, acllen
, aclflag
);
3502 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
3505 cifs_put_tlink(tlink
);
3510 /* Retrieve an ACL from the server */
3511 static struct cifs_ntsd
*
3512 get_smb2_acl(struct cifs_sb_info
*cifs_sb
,
3513 struct inode
*inode
, const char *path
,
3514 u32
*pacllen
, u32 info
)
3516 struct cifs_ntsd
*pntsd
= NULL
;
3517 struct cifsFileInfo
*open_file
= NULL
;
3519 if (inode
&& !(info
& SACL_SECINFO
))
3520 open_file
= find_readable_file(CIFS_I(inode
), true);
3521 if (!open_file
|| (info
& SACL_SECINFO
))
3522 return get_smb2_acl_by_path(cifs_sb
, path
, pacllen
, info
);
3524 pntsd
= get_smb2_acl_by_fid(cifs_sb
, &open_file
->fid
, pacllen
, info
);
3525 cifsFileInfo_put(open_file
);
3529 static long smb3_zero_range(struct file
*file
, struct cifs_tcon
*tcon
,
3530 loff_t offset
, loff_t len
, bool keep_size
)
3532 struct cifs_ses
*ses
= tcon
->ses
;
3533 struct inode
*inode
;
3534 struct cifsInodeInfo
*cifsi
;
3535 struct cifsFileInfo
*cfile
= file
->private_data
;
3536 struct file_zero_data_information fsctl_buf
;
3543 inode
= d_inode(cfile
->dentry
);
3544 cifsi
= CIFS_I(inode
);
3546 trace_smb3_zero_enter(xid
, cfile
->fid
.persistent_fid
, tcon
->tid
,
3547 ses
->Suid
, offset
, len
);
3550 * We zero the range through ioctl, so we need remove the page caches
3551 * first, otherwise the data may be inconsistent with the server.
3553 truncate_pagecache_range(inode
, offset
, offset
+ len
- 1);
3555 /* if file not oplocked can't be sure whether asking to extend size */
3556 if (!CIFS_CACHE_READ(cifsi
))
3557 if (keep_size
== false) {
3559 trace_smb3_zero_err(xid
, cfile
->fid
.persistent_fid
,
3560 tcon
->tid
, ses
->Suid
, offset
, len
, rc
);
3565 cifs_dbg(FYI
, "Offset %lld len %lld\n", offset
, len
);
3567 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
3568 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
3570 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
3571 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
, true,
3573 sizeof(struct file_zero_data_information
),
3576 goto zero_range_exit
;
3579 * do we also need to change the size of the file?
3581 if (keep_size
== false && i_size_read(inode
) < offset
+ len
) {
3582 eof
= cpu_to_le64(offset
+ len
);
3583 rc
= SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
3584 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
);
3590 trace_smb3_zero_err(xid
, cfile
->fid
.persistent_fid
, tcon
->tid
,
3591 ses
->Suid
, offset
, len
, rc
);
3593 trace_smb3_zero_done(xid
, cfile
->fid
.persistent_fid
, tcon
->tid
,
3594 ses
->Suid
, offset
, len
);
3598 static long smb3_punch_hole(struct file
*file
, struct cifs_tcon
*tcon
,
3599 loff_t offset
, loff_t len
)
3601 struct inode
*inode
;
3602 struct cifsFileInfo
*cfile
= file
->private_data
;
3603 struct file_zero_data_information fsctl_buf
;
3606 __u8 set_sparse
= 1;
3610 inode
= d_inode(cfile
->dentry
);
3612 /* Need to make file sparse, if not already, before freeing range. */
3613 /* Consider adding equivalent for compressed since it could also work */
3614 if (!smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
)) {
3620 filemap_invalidate_lock(inode
->i_mapping
);
3622 * We implement the punch hole through ioctl, so we need remove the page
3623 * caches first, otherwise the data may be inconsistent with the server.
3625 truncate_pagecache_range(inode
, offset
, offset
+ len
- 1);
3627 cifs_dbg(FYI
, "Offset %lld len %lld\n", offset
, len
);
3629 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
3630 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
3632 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
3633 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
3634 true /* is_fctl */, (char *)&fsctl_buf
,
3635 sizeof(struct file_zero_data_information
),
3636 CIFSMaxBufSize
, NULL
, NULL
);
3638 filemap_invalidate_unlock(inode
->i_mapping
);
3642 static int smb3_simple_fallocate_write_range(unsigned int xid
,
3643 struct cifs_tcon
*tcon
,
3644 struct cifsFileInfo
*cfile
,
3645 loff_t off
, loff_t len
,
3648 struct cifs_io_parms io_parms
= {0};
3653 io_parms
.netfid
= cfile
->fid
.netfid
;
3654 io_parms
.pid
= current
->tgid
;
3655 io_parms
.tcon
= tcon
;
3656 io_parms
.persistent_fid
= cfile
->fid
.persistent_fid
;
3657 io_parms
.volatile_fid
= cfile
->fid
.volatile_fid
;
3660 io_parms
.offset
= off
;
3661 io_parms
.length
= len
;
3662 if (io_parms
.length
> SMB2_MAX_BUFFER_SIZE
)
3663 io_parms
.length
= SMB2_MAX_BUFFER_SIZE
;
3664 /* iov[0] is reserved for smb header */
3665 iov
[1].iov_base
= buf
;
3666 iov
[1].iov_len
= io_parms
.length
;
3667 rc
= SMB2_write(xid
, &io_parms
, &nbytes
, iov
, 1);
3679 static int smb3_simple_fallocate_range(unsigned int xid
,
3680 struct cifs_tcon
*tcon
,
3681 struct cifsFileInfo
*cfile
,
3682 loff_t off
, loff_t len
)
3684 struct file_allocated_range_buffer in_data
, *out_data
= NULL
, *tmp_data
;
3690 in_data
.file_offset
= cpu_to_le64(off
);
3691 in_data
.length
= cpu_to_le64(len
);
3692 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
3693 cfile
->fid
.volatile_fid
,
3694 FSCTL_QUERY_ALLOCATED_RANGES
, true,
3695 (char *)&in_data
, sizeof(in_data
),
3696 1024 * sizeof(struct file_allocated_range_buffer
),
3697 (char **)&out_data
, &out_data_len
);
3701 buf
= kzalloc(1024 * 1024, GFP_KERNEL
);
3707 tmp_data
= out_data
;
3710 * The rest of the region is unmapped so write it all.
3712 if (out_data_len
== 0) {
3713 rc
= smb3_simple_fallocate_write_range(xid
, tcon
,
3714 cfile
, off
, len
, buf
);
3718 if (out_data_len
< sizeof(struct file_allocated_range_buffer
)) {
3723 if (off
< le64_to_cpu(tmp_data
->file_offset
)) {
3725 * We are at a hole. Write until the end of the region
3726 * or until the next allocated data,
3727 * whichever comes next.
3729 l
= le64_to_cpu(tmp_data
->file_offset
) - off
;
3732 rc
= smb3_simple_fallocate_write_range(xid
, tcon
,
3733 cfile
, off
, l
, buf
);
3742 * We are at a section of allocated data, just skip forward
3743 * until the end of the data or the end of the region
3744 * we are supposed to fallocate, whichever comes first.
3746 l
= le64_to_cpu(tmp_data
->length
);
3752 tmp_data
= &tmp_data
[1];
3753 out_data_len
-= sizeof(struct file_allocated_range_buffer
);
3763 static long smb3_simple_falloc(struct file
*file
, struct cifs_tcon
*tcon
,
3764 loff_t off
, loff_t len
, bool keep_size
)
3766 struct inode
*inode
;
3767 struct cifsInodeInfo
*cifsi
;
3768 struct cifsFileInfo
*cfile
= file
->private_data
;
3769 long rc
= -EOPNOTSUPP
;
3775 inode
= d_inode(cfile
->dentry
);
3776 cifsi
= CIFS_I(inode
);
3778 trace_smb3_falloc_enter(xid
, cfile
->fid
.persistent_fid
, tcon
->tid
,
3779 tcon
->ses
->Suid
, off
, len
);
3780 /* if file not oplocked can't be sure whether asking to extend size */
3781 if (!CIFS_CACHE_READ(cifsi
))
3782 if (keep_size
== false) {
3783 trace_smb3_falloc_err(xid
, cfile
->fid
.persistent_fid
,
3784 tcon
->tid
, tcon
->ses
->Suid
, off
, len
, rc
);
3790 * Extending the file
3792 if ((keep_size
== false) && i_size_read(inode
) < off
+ len
) {
3793 rc
= inode_newsize_ok(inode
, off
+ len
);
3797 if (cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
)
3798 smb2_set_sparse(xid
, tcon
, cfile
, inode
, false);
3800 eof
= cpu_to_le64(off
+ len
);
3801 rc
= SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
3802 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
);
3804 cifsi
->server_eof
= off
+ len
;
3805 cifs_setsize(inode
, off
+ len
);
3806 cifs_truncate_page(inode
->i_mapping
, inode
->i_size
);
3807 truncate_setsize(inode
, off
+ len
);
3813 * Files are non-sparse by default so falloc may be a no-op
3814 * Must check if file sparse. If not sparse, and since we are not
3815 * extending then no need to do anything since file already allocated
3817 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) == 0) {
3822 if (keep_size
== true) {
3824 * We can not preallocate pages beyond the end of the file
3827 if (off
>= i_size_read(inode
)) {
3832 * For fallocates that are partially beyond the end of file,
3833 * clamp len so we only fallocate up to the end of file.
3835 if (off
+ len
> i_size_read(inode
)) {
3836 len
= i_size_read(inode
) - off
;
3840 if ((keep_size
== true) || (i_size_read(inode
) >= off
+ len
)) {
3842 * At this point, we are trying to fallocate an internal
3843 * regions of a sparse file. Since smb2 does not have a
3844 * fallocate command we have two otions on how to emulate this.
3845 * We can either turn the entire file to become non-sparse
3846 * which we only do if the fallocate is for virtually
3847 * the whole file, or we can overwrite the region with zeroes
3848 * using SMB2_write, which could be prohibitevly expensive
3852 * We are only trying to fallocate a small region so
3853 * just write it with zero.
3855 if (len
<= 1024 * 1024) {
3856 rc
= smb3_simple_fallocate_range(xid
, tcon
, cfile
,
3862 * Check if falloc starts within first few pages of file
3863 * and ends within a few pages of the end of file to
3864 * ensure that most of file is being forced to be
3865 * fallocated now. If so then setting whole file sparse
3866 * ie potentially making a few extra pages at the beginning
3867 * or end of the file non-sparse via set_sparse is harmless.
3869 if ((off
> 8192) || (off
+ len
+ 8192 < i_size_read(inode
))) {
3875 smb2_set_sparse(xid
, tcon
, cfile
, inode
, false);
3880 trace_smb3_falloc_err(xid
, cfile
->fid
.persistent_fid
, tcon
->tid
,
3881 tcon
->ses
->Suid
, off
, len
, rc
);
3883 trace_smb3_falloc_done(xid
, cfile
->fid
.persistent_fid
, tcon
->tid
,
3884 tcon
->ses
->Suid
, off
, len
);
3890 static long smb3_collapse_range(struct file
*file
, struct cifs_tcon
*tcon
,
3891 loff_t off
, loff_t len
)
3895 struct cifsFileInfo
*cfile
= file
->private_data
;
3900 if (off
>= i_size_read(file
->f_inode
) ||
3901 off
+ len
>= i_size_read(file
->f_inode
)) {
3906 rc
= smb2_copychunk_range(xid
, cfile
, cfile
, off
+ len
,
3907 i_size_read(file
->f_inode
) - off
- len
, off
);
3911 eof
= cpu_to_le64(i_size_read(file
->f_inode
) - len
);
3912 rc
= SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
3913 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
);
3923 static long smb3_insert_range(struct file
*file
, struct cifs_tcon
*tcon
,
3924 loff_t off
, loff_t len
)
3928 struct cifsFileInfo
*cfile
= file
->private_data
;
3934 if (off
>= i_size_read(file
->f_inode
)) {
3939 count
= i_size_read(file
->f_inode
) - off
;
3940 eof
= cpu_to_le64(i_size_read(file
->f_inode
) + len
);
3942 rc
= SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
3943 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
);
3947 rc
= smb2_copychunk_range(xid
, cfile
, cfile
, off
, count
, off
+ len
);
3951 rc
= smb3_zero_range(file
, tcon
, off
, len
, 1);
3961 static loff_t
smb3_llseek(struct file
*file
, struct cifs_tcon
*tcon
, loff_t offset
, int whence
)
3963 struct cifsFileInfo
*wrcfile
, *cfile
= file
->private_data
;
3964 struct cifsInodeInfo
*cifsi
;
3965 struct inode
*inode
;
3967 struct file_allocated_range_buffer in_data
, *out_data
= NULL
;
3971 if (whence
!= SEEK_HOLE
&& whence
!= SEEK_DATA
)
3972 return generic_file_llseek(file
, offset
, whence
);
3974 inode
= d_inode(cfile
->dentry
);
3975 cifsi
= CIFS_I(inode
);
3977 if (offset
< 0 || offset
>= i_size_read(inode
))
3982 * We need to be sure that all dirty pages are written as they
3983 * might fill holes on the server.
3984 * Note that we also MUST flush any written pages since at least
3985 * some servers (Windows2016) will not reflect recent writes in
3986 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3988 wrcfile
= find_writable_file(cifsi
, FIND_WR_ANY
);
3990 filemap_write_and_wait(inode
->i_mapping
);
3991 smb2_flush_file(xid
, tcon
, &wrcfile
->fid
);
3992 cifsFileInfo_put(wrcfile
);
3995 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
)) {
3996 if (whence
== SEEK_HOLE
)
3997 offset
= i_size_read(inode
);
4001 in_data
.file_offset
= cpu_to_le64(offset
);
4002 in_data
.length
= cpu_to_le64(i_size_read(inode
));
4004 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
4005 cfile
->fid
.volatile_fid
,
4006 FSCTL_QUERY_ALLOCATED_RANGES
, true,
4007 (char *)&in_data
, sizeof(in_data
),
4008 sizeof(struct file_allocated_range_buffer
),
4009 (char **)&out_data
, &out_data_len
);
4015 if (whence
== SEEK_HOLE
&& out_data_len
== 0)
4018 if (whence
== SEEK_DATA
&& out_data_len
== 0) {
4023 if (out_data_len
< sizeof(struct file_allocated_range_buffer
)) {
4027 if (whence
== SEEK_DATA
) {
4028 offset
= le64_to_cpu(out_data
->file_offset
);
4031 if (offset
< le64_to_cpu(out_data
->file_offset
))
4034 offset
= le64_to_cpu(out_data
->file_offset
) + le64_to_cpu(out_data
->length
);
4040 return vfs_setpos(file
, offset
, inode
->i_sb
->s_maxbytes
);
4045 static int smb3_fiemap(struct cifs_tcon
*tcon
,
4046 struct cifsFileInfo
*cfile
,
4047 struct fiemap_extent_info
*fei
, u64 start
, u64 len
)
4050 struct file_allocated_range_buffer in_data
, *out_data
;
4052 int i
, num
, rc
, flags
, last_blob
;
4055 rc
= fiemap_prep(d_inode(cfile
->dentry
), fei
, start
, &len
, 0);
4061 in_data
.file_offset
= cpu_to_le64(start
);
4062 in_data
.length
= cpu_to_le64(len
);
4064 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
4065 cfile
->fid
.volatile_fid
,
4066 FSCTL_QUERY_ALLOCATED_RANGES
, true,
4067 (char *)&in_data
, sizeof(in_data
),
4068 1024 * sizeof(struct file_allocated_range_buffer
),
4069 (char **)&out_data
, &out_data_len
);
4078 if (out_data_len
&& out_data_len
< sizeof(struct file_allocated_range_buffer
)) {
4082 if (out_data_len
% sizeof(struct file_allocated_range_buffer
)) {
4087 num
= out_data_len
/ sizeof(struct file_allocated_range_buffer
);
4088 for (i
= 0; i
< num
; i
++) {
4090 if (i
== num
- 1 && last_blob
)
4091 flags
|= FIEMAP_EXTENT_LAST
;
4093 rc
= fiemap_fill_next_extent(fei
,
4094 le64_to_cpu(out_data
[i
].file_offset
),
4095 le64_to_cpu(out_data
[i
].file_offset
),
4096 le64_to_cpu(out_data
[i
].length
),
4107 next
= le64_to_cpu(out_data
[num
- 1].file_offset
) +
4108 le64_to_cpu(out_data
[num
- 1].length
);
4109 len
= len
- (next
- start
);
4120 static long smb3_fallocate(struct file
*file
, struct cifs_tcon
*tcon
, int mode
,
4121 loff_t off
, loff_t len
)
4123 /* KEEP_SIZE already checked for by do_fallocate */
4124 if (mode
& FALLOC_FL_PUNCH_HOLE
)
4125 return smb3_punch_hole(file
, tcon
, off
, len
);
4126 else if (mode
& FALLOC_FL_ZERO_RANGE
) {
4127 if (mode
& FALLOC_FL_KEEP_SIZE
)
4128 return smb3_zero_range(file
, tcon
, off
, len
, true);
4129 return smb3_zero_range(file
, tcon
, off
, len
, false);
4130 } else if (mode
== FALLOC_FL_KEEP_SIZE
)
4131 return smb3_simple_falloc(file
, tcon
, off
, len
, true);
4132 else if (mode
== FALLOC_FL_COLLAPSE_RANGE
)
4133 return smb3_collapse_range(file
, tcon
, off
, len
);
4134 else if (mode
== FALLOC_FL_INSERT_RANGE
)
4135 return smb3_insert_range(file
, tcon
, off
, len
);
4137 return smb3_simple_falloc(file
, tcon
, off
, len
, false);
4143 smb2_downgrade_oplock(struct TCP_Server_Info
*server
,
4144 struct cifsInodeInfo
*cinode
, __u32 oplock
,
4145 unsigned int epoch
, bool *purge_cache
)
4147 server
->ops
->set_oplock_level(cinode
, oplock
, 0, NULL
);
4151 smb21_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
4152 unsigned int epoch
, bool *purge_cache
);
4155 smb3_downgrade_oplock(struct TCP_Server_Info
*server
,
4156 struct cifsInodeInfo
*cinode
, __u32 oplock
,
4157 unsigned int epoch
, bool *purge_cache
)
4159 unsigned int old_state
= cinode
->oplock
;
4160 unsigned int old_epoch
= cinode
->epoch
;
4161 unsigned int new_state
;
4163 if (epoch
> old_epoch
) {
4164 smb21_set_oplock_level(cinode
, oplock
, 0, NULL
);
4165 cinode
->epoch
= epoch
;
4168 new_state
= cinode
->oplock
;
4169 *purge_cache
= false;
4171 if ((old_state
& CIFS_CACHE_READ_FLG
) != 0 &&
4172 (new_state
& CIFS_CACHE_READ_FLG
) == 0)
4173 *purge_cache
= true;
4174 else if (old_state
== new_state
&& (epoch
- old_epoch
> 1))
4175 *purge_cache
= true;
4179 smb2_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
4180 unsigned int epoch
, bool *purge_cache
)
4183 cinode
->lease_granted
= false;
4184 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
4186 if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
) {
4187 cinode
->oplock
= CIFS_CACHE_RHW_FLG
;
4188 cifs_dbg(FYI
, "Batch Oplock granted on inode %p\n",
4189 &cinode
->vfs_inode
);
4190 } else if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
) {
4191 cinode
->oplock
= CIFS_CACHE_RW_FLG
;
4192 cifs_dbg(FYI
, "Exclusive Oplock granted on inode %p\n",
4193 &cinode
->vfs_inode
);
4194 } else if (oplock
== SMB2_OPLOCK_LEVEL_II
) {
4195 cinode
->oplock
= CIFS_CACHE_READ_FLG
;
4196 cifs_dbg(FYI
, "Level II Oplock granted on inode %p\n",
4197 &cinode
->vfs_inode
);
4203 smb21_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
4204 unsigned int epoch
, bool *purge_cache
)
4206 char message
[5] = {0};
4207 unsigned int new_oplock
= 0;
4210 cinode
->lease_granted
= true;
4211 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
4214 /* Check if the server granted an oplock rather than a lease */
4215 if (oplock
& SMB2_OPLOCK_LEVEL_EXCLUSIVE
)
4216 return smb2_set_oplock_level(cinode
, oplock
, epoch
,
4219 if (oplock
& SMB2_LEASE_READ_CACHING_HE
) {
4220 new_oplock
|= CIFS_CACHE_READ_FLG
;
4221 strcat(message
, "R");
4223 if (oplock
& SMB2_LEASE_HANDLE_CACHING_HE
) {
4224 new_oplock
|= CIFS_CACHE_HANDLE_FLG
;
4225 strcat(message
, "H");
4227 if (oplock
& SMB2_LEASE_WRITE_CACHING_HE
) {
4228 new_oplock
|= CIFS_CACHE_WRITE_FLG
;
4229 strcat(message
, "W");
4232 strncpy(message
, "None", sizeof(message
));
4234 cinode
->oplock
= new_oplock
;
4235 cifs_dbg(FYI
, "%s Lease granted on inode %p\n", message
,
4236 &cinode
->vfs_inode
);
4240 smb3_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
4241 unsigned int epoch
, bool *purge_cache
)
4243 unsigned int old_oplock
= cinode
->oplock
;
4245 smb21_set_oplock_level(cinode
, oplock
, epoch
, purge_cache
);
4248 *purge_cache
= false;
4249 if (old_oplock
== CIFS_CACHE_READ_FLG
) {
4250 if (cinode
->oplock
== CIFS_CACHE_READ_FLG
&&
4251 (epoch
- cinode
->epoch
> 0))
4252 *purge_cache
= true;
4253 else if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
4254 (epoch
- cinode
->epoch
> 1))
4255 *purge_cache
= true;
4256 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
4257 (epoch
- cinode
->epoch
> 1))
4258 *purge_cache
= true;
4259 else if (cinode
->oplock
== 0 &&
4260 (epoch
- cinode
->epoch
> 0))
4261 *purge_cache
= true;
4262 } else if (old_oplock
== CIFS_CACHE_RH_FLG
) {
4263 if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
4264 (epoch
- cinode
->epoch
> 0))
4265 *purge_cache
= true;
4266 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
4267 (epoch
- cinode
->epoch
> 1))
4268 *purge_cache
= true;
4270 cinode
->epoch
= epoch
;
4274 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
4276 smb2_is_read_op(__u32 oplock
)
4278 return oplock
== SMB2_OPLOCK_LEVEL_II
;
4280 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
4283 smb21_is_read_op(__u32 oplock
)
4285 return (oplock
& SMB2_LEASE_READ_CACHING_HE
) &&
4286 !(oplock
& SMB2_LEASE_WRITE_CACHING_HE
);
4290 map_oplock_to_lease(u8 oplock
)
4292 if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
)
4293 return SMB2_LEASE_WRITE_CACHING
| SMB2_LEASE_READ_CACHING
;
4294 else if (oplock
== SMB2_OPLOCK_LEVEL_II
)
4295 return SMB2_LEASE_READ_CACHING
;
4296 else if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
)
4297 return SMB2_LEASE_HANDLE_CACHING
| SMB2_LEASE_READ_CACHING
|
4298 SMB2_LEASE_WRITE_CACHING
;
4303 smb2_create_lease_buf(u8
*lease_key
, u8 oplock
)
4305 struct create_lease
*buf
;
4307 buf
= kzalloc(sizeof(struct create_lease
), GFP_KERNEL
);
4311 memcpy(&buf
->lcontext
.LeaseKey
, lease_key
, SMB2_LEASE_KEY_SIZE
);
4312 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
4314 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
4315 (struct create_lease
, lcontext
));
4316 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context
));
4317 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
4318 (struct create_lease
, Name
));
4319 buf
->ccontext
.NameLength
= cpu_to_le16(4);
4320 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4329 smb3_create_lease_buf(u8
*lease_key
, u8 oplock
)
4331 struct create_lease_v2
*buf
;
4333 buf
= kzalloc(sizeof(struct create_lease_v2
), GFP_KERNEL
);
4337 memcpy(&buf
->lcontext
.LeaseKey
, lease_key
, SMB2_LEASE_KEY_SIZE
);
4338 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
4340 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
4341 (struct create_lease_v2
, lcontext
));
4342 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context_v2
));
4343 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
4344 (struct create_lease_v2
, Name
));
4345 buf
->ccontext
.NameLength
= cpu_to_le16(4);
4346 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
4355 smb2_parse_lease_buf(void *buf
, unsigned int *epoch
, char *lease_key
)
4357 struct create_lease
*lc
= (struct create_lease
*)buf
;
4359 *epoch
= 0; /* not used */
4360 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
4361 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
4362 return le32_to_cpu(lc
->lcontext
.LeaseState
);
4366 smb3_parse_lease_buf(void *buf
, unsigned int *epoch
, char *lease_key
)
4368 struct create_lease_v2
*lc
= (struct create_lease_v2
*)buf
;
4370 *epoch
= le16_to_cpu(lc
->lcontext
.Epoch
);
4371 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
4372 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
4374 memcpy(lease_key
, &lc
->lcontext
.LeaseKey
, SMB2_LEASE_KEY_SIZE
);
4375 return le32_to_cpu(lc
->lcontext
.LeaseState
);
4379 smb2_wp_retry_size(struct inode
*inode
)
4381 return min_t(unsigned int, CIFS_SB(inode
->i_sb
)->ctx
->wsize
,
4382 SMB2_MAX_BUFFER_SIZE
);
4386 smb2_dir_needs_close(struct cifsFileInfo
*cfile
)
4388 return !cfile
->invalidHandle
;
4392 fill_transform_hdr(struct smb2_transform_hdr
*tr_hdr
, unsigned int orig_len
,
4393 struct smb_rqst
*old_rq
, __le16 cipher_type
)
4395 struct smb2_sync_hdr
*shdr
=
4396 (struct smb2_sync_hdr
*)old_rq
->rq_iov
[0].iov_base
;
4398 memset(tr_hdr
, 0, sizeof(struct smb2_transform_hdr
));
4399 tr_hdr
->ProtocolId
= SMB2_TRANSFORM_PROTO_NUM
;
4400 tr_hdr
->OriginalMessageSize
= cpu_to_le32(orig_len
);
4401 tr_hdr
->Flags
= cpu_to_le16(0x01);
4402 if ((cipher_type
== SMB2_ENCRYPTION_AES128_GCM
) ||
4403 (cipher_type
== SMB2_ENCRYPTION_AES256_GCM
))
4404 get_random_bytes(&tr_hdr
->Nonce
, SMB3_AES_GCM_NONCE
);
4406 get_random_bytes(&tr_hdr
->Nonce
, SMB3_AES_CCM_NONCE
);
4407 memcpy(&tr_hdr
->SessionId
, &shdr
->SessionId
, 8);
4410 /* We can not use the normal sg_set_buf() as we will sometimes pass a
4411 * stack object as buf.
4413 static inline void smb2_sg_set_buf(struct scatterlist
*sg
, const void *buf
,
4414 unsigned int buflen
)
4418 * VMAP_STACK (at least) puts stack into the vmalloc address space
4420 if (is_vmalloc_addr(buf
))
4421 addr
= vmalloc_to_page(buf
);
4423 addr
= virt_to_page(buf
);
4424 sg_set_page(sg
, addr
, buflen
, offset_in_page(buf
));
4427 /* Assumes the first rqst has a transform header as the first iov.
4429 * rqst[0].rq_iov[0] is transform header
4430 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
4431 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
4433 static struct scatterlist
*
4434 init_sg(int num_rqst
, struct smb_rqst
*rqst
, u8
*sign
)
4436 unsigned int sg_len
;
4437 struct scatterlist
*sg
;
4440 unsigned int idx
= 0;
4444 for (i
= 0; i
< num_rqst
; i
++)
4445 sg_len
+= rqst
[i
].rq_nvec
+ rqst
[i
].rq_npages
;
4447 sg
= kmalloc_array(sg_len
, sizeof(struct scatterlist
), GFP_KERNEL
);
4451 sg_init_table(sg
, sg_len
);
4452 for (i
= 0; i
< num_rqst
; i
++) {
4453 for (j
= 0; j
< rqst
[i
].rq_nvec
; j
++) {
4455 * The first rqst has a transform header where the
4456 * first 20 bytes are not part of the encrypted blob
4458 skip
= (i
== 0) && (j
== 0) ? 20 : 0;
4459 smb2_sg_set_buf(&sg
[idx
++],
4460 rqst
[i
].rq_iov
[j
].iov_base
+ skip
,
4461 rqst
[i
].rq_iov
[j
].iov_len
- skip
);
4464 for (j
= 0; j
< rqst
[i
].rq_npages
; j
++) {
4465 unsigned int len
, offset
;
4467 rqst_page_get_length(&rqst
[i
], j
, &len
, &offset
);
4468 sg_set_page(&sg
[idx
++], rqst
[i
].rq_pages
[j
], len
, offset
);
4471 smb2_sg_set_buf(&sg
[idx
], sign
, SMB2_SIGNATURE_SIZE
);
4476 smb2_get_enc_key(struct TCP_Server_Info
*server
, __u64 ses_id
, int enc
, u8
*key
)
4478 struct cifs_ses
*ses
;
4481 spin_lock(&cifs_tcp_ses_lock
);
4482 list_for_each_entry(server
, &cifs_tcp_ses_list
, tcp_ses_list
) {
4483 list_for_each_entry(ses
, &server
->smb_ses_list
, smb_ses_list
) {
4484 if (ses
->Suid
== ses_id
) {
4485 ses_enc_key
= enc
? ses
->smb3encryptionkey
:
4486 ses
->smb3decryptionkey
;
4487 memcpy(key
, ses_enc_key
, SMB3_ENC_DEC_KEY_SIZE
);
4488 spin_unlock(&cifs_tcp_ses_lock
);
4493 spin_unlock(&cifs_tcp_ses_lock
);
4498 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
4499 * iov[0] - transform header (associate data),
4500 * iov[1-N] - SMB2 header and pages - data to encrypt.
4501 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4505 crypt_message(struct TCP_Server_Info
*server
, int num_rqst
,
4506 struct smb_rqst
*rqst
, int enc
)
4508 struct smb2_transform_hdr
*tr_hdr
=
4509 (struct smb2_transform_hdr
*)rqst
[0].rq_iov
[0].iov_base
;
4510 unsigned int assoc_data_len
= sizeof(struct smb2_transform_hdr
) - 20;
4512 struct scatterlist
*sg
;
4513 u8 sign
[SMB2_SIGNATURE_SIZE
] = {};
4514 u8 key
[SMB3_ENC_DEC_KEY_SIZE
];
4515 struct aead_request
*req
;
4517 unsigned int iv_len
;
4518 DECLARE_CRYPTO_WAIT(wait
);
4519 struct crypto_aead
*tfm
;
4520 unsigned int crypt_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
4522 rc
= smb2_get_enc_key(server
, tr_hdr
->SessionId
, enc
, key
);
4524 cifs_server_dbg(VFS
, "%s: Could not get %scryption key\n", __func__
,
4529 rc
= smb3_crypto_aead_allocate(server
);
4531 cifs_server_dbg(VFS
, "%s: crypto alloc failed\n", __func__
);
4535 tfm
= enc
? server
->secmech
.ccmaesencrypt
:
4536 server
->secmech
.ccmaesdecrypt
;
4538 if ((server
->cipher_type
== SMB2_ENCRYPTION_AES256_CCM
) ||
4539 (server
->cipher_type
== SMB2_ENCRYPTION_AES256_GCM
))
4540 rc
= crypto_aead_setkey(tfm
, key
, SMB3_GCM256_CRYPTKEY_SIZE
);
4542 rc
= crypto_aead_setkey(tfm
, key
, SMB3_GCM128_CRYPTKEY_SIZE
);
4545 cifs_server_dbg(VFS
, "%s: Failed to set aead key %d\n", __func__
, rc
);
4549 rc
= crypto_aead_setauthsize(tfm
, SMB2_SIGNATURE_SIZE
);
4551 cifs_server_dbg(VFS
, "%s: Failed to set authsize %d\n", __func__
, rc
);
4555 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
4557 cifs_server_dbg(VFS
, "%s: Failed to alloc aead request\n", __func__
);
4562 memcpy(sign
, &tr_hdr
->Signature
, SMB2_SIGNATURE_SIZE
);
4563 crypt_len
+= SMB2_SIGNATURE_SIZE
;
4566 sg
= init_sg(num_rqst
, rqst
, sign
);
4568 cifs_server_dbg(VFS
, "%s: Failed to init sg\n", __func__
);
4573 iv_len
= crypto_aead_ivsize(tfm
);
4574 iv
= kzalloc(iv_len
, GFP_KERNEL
);
4576 cifs_server_dbg(VFS
, "%s: Failed to alloc iv\n", __func__
);
4581 if ((server
->cipher_type
== SMB2_ENCRYPTION_AES128_GCM
) ||
4582 (server
->cipher_type
== SMB2_ENCRYPTION_AES256_GCM
))
4583 memcpy(iv
, (char *)tr_hdr
->Nonce
, SMB3_AES_GCM_NONCE
);
4586 memcpy(iv
+ 1, (char *)tr_hdr
->Nonce
, SMB3_AES_CCM_NONCE
);
4589 aead_request_set_crypt(req
, sg
, sg
, crypt_len
, iv
);
4590 aead_request_set_ad(req
, assoc_data_len
);
4592 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
4593 crypto_req_done
, &wait
);
4595 rc
= crypto_wait_req(enc
? crypto_aead_encrypt(req
)
4596 : crypto_aead_decrypt(req
), &wait
);
4599 memcpy(&tr_hdr
->Signature
, sign
, SMB2_SIGNATURE_SIZE
);
4610 smb3_free_compound_rqst(int num_rqst
, struct smb_rqst
*rqst
)
4614 for (i
= 0; i
< num_rqst
; i
++) {
4615 if (rqst
[i
].rq_pages
) {
4616 for (j
= rqst
[i
].rq_npages
- 1; j
>= 0; j
--)
4617 put_page(rqst
[i
].rq_pages
[j
]);
4618 kfree(rqst
[i
].rq_pages
);
4624 * This function will initialize new_rq and encrypt the content.
4625 * The first entry, new_rq[0], only contains a single iov which contains
4626 * a smb2_transform_hdr and is pre-allocated by the caller.
4627 * This function then populates new_rq[1+] with the content from olq_rq[0+].
4629 * The end result is an array of smb_rqst structures where the first structure
4630 * only contains a single iov for the transform header which we then can pass
4631 * to crypt_message().
4633 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4634 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
4637 smb3_init_transform_rq(struct TCP_Server_Info
*server
, int num_rqst
,
4638 struct smb_rqst
*new_rq
, struct smb_rqst
*old_rq
)
4640 struct page
**pages
;
4641 struct smb2_transform_hdr
*tr_hdr
= new_rq
[0].rq_iov
[0].iov_base
;
4642 unsigned int npages
;
4643 unsigned int orig_len
= 0;
4647 for (i
= 1; i
< num_rqst
; i
++) {
4648 npages
= old_rq
[i
- 1].rq_npages
;
4649 pages
= kmalloc_array(npages
, sizeof(struct page
*),
4654 new_rq
[i
].rq_pages
= pages
;
4655 new_rq
[i
].rq_npages
= npages
;
4656 new_rq
[i
].rq_offset
= old_rq
[i
- 1].rq_offset
;
4657 new_rq
[i
].rq_pagesz
= old_rq
[i
- 1].rq_pagesz
;
4658 new_rq
[i
].rq_tailsz
= old_rq
[i
- 1].rq_tailsz
;
4659 new_rq
[i
].rq_iov
= old_rq
[i
- 1].rq_iov
;
4660 new_rq
[i
].rq_nvec
= old_rq
[i
- 1].rq_nvec
;
4662 orig_len
+= smb_rqst_len(server
, &old_rq
[i
- 1]);
4664 for (j
= 0; j
< npages
; j
++) {
4665 pages
[j
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
4670 /* copy pages form the old */
4671 for (j
= 0; j
< npages
; j
++) {
4673 unsigned int offset
, len
;
4675 rqst_page_get_length(&new_rq
[i
], j
, &len
, &offset
);
4677 dst
= (char *) kmap(new_rq
[i
].rq_pages
[j
]) + offset
;
4678 src
= (char *) kmap(old_rq
[i
- 1].rq_pages
[j
]) + offset
;
4680 memcpy(dst
, src
, len
);
4681 kunmap(new_rq
[i
].rq_pages
[j
]);
4682 kunmap(old_rq
[i
- 1].rq_pages
[j
]);
4686 /* fill the 1st iov with a transform header */
4687 fill_transform_hdr(tr_hdr
, orig_len
, old_rq
, server
->cipher_type
);
4689 rc
= crypt_message(server
, num_rqst
, new_rq
, 1);
4690 cifs_dbg(FYI
, "Encrypt message returned %d\n", rc
);
4697 smb3_free_compound_rqst(num_rqst
- 1, &new_rq
[1]);
4702 smb3_is_transform_hdr(void *buf
)
4704 struct smb2_transform_hdr
*trhdr
= buf
;
4706 return trhdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
;
4710 decrypt_raw_data(struct TCP_Server_Info
*server
, char *buf
,
4711 unsigned int buf_data_size
, struct page
**pages
,
4712 unsigned int npages
, unsigned int page_data_size
,
4716 struct smb_rqst rqst
= {NULL
};
4719 iov
[0].iov_base
= buf
;
4720 iov
[0].iov_len
= sizeof(struct smb2_transform_hdr
);
4721 iov
[1].iov_base
= buf
+ sizeof(struct smb2_transform_hdr
);
4722 iov
[1].iov_len
= buf_data_size
;
4726 rqst
.rq_pages
= pages
;
4727 rqst
.rq_npages
= npages
;
4728 rqst
.rq_pagesz
= PAGE_SIZE
;
4729 rqst
.rq_tailsz
= (page_data_size
% PAGE_SIZE
) ? : PAGE_SIZE
;
4731 rc
= crypt_message(server
, 1, &rqst
, 0);
4732 cifs_dbg(FYI
, "Decrypt message returned %d\n", rc
);
4737 memmove(buf
, iov
[1].iov_base
, buf_data_size
);
4740 server
->total_read
= buf_data_size
+ page_data_size
;
4746 read_data_into_pages(struct TCP_Server_Info
*server
, struct page
**pages
,
4747 unsigned int npages
, unsigned int len
)
4752 for (i
= 0; i
< npages
; i
++) {
4753 struct page
*page
= pages
[i
];
4757 if (len
>= PAGE_SIZE
) {
4758 /* enough data to fill the page */
4762 zero_user(page
, len
, PAGE_SIZE
- len
);
4765 length
= cifs_read_page_from_socket(server
, page
, 0, n
);
4768 server
->total_read
+= length
;
4775 init_read_bvec(struct page
**pages
, unsigned int npages
, unsigned int data_size
,
4776 unsigned int cur_off
, struct bio_vec
**page_vec
)
4778 struct bio_vec
*bvec
;
4781 bvec
= kcalloc(npages
, sizeof(struct bio_vec
), GFP_KERNEL
);
4785 for (i
= 0; i
< npages
; i
++) {
4786 bvec
[i
].bv_page
= pages
[i
];
4787 bvec
[i
].bv_offset
= (i
== 0) ? cur_off
: 0;
4788 bvec
[i
].bv_len
= min_t(unsigned int, PAGE_SIZE
, data_size
);
4789 data_size
-= bvec
[i
].bv_len
;
4792 if (data_size
!= 0) {
4793 cifs_dbg(VFS
, "%s: something went wrong\n", __func__
);
4803 handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
,
4804 char *buf
, unsigned int buf_len
, struct page
**pages
,
4805 unsigned int npages
, unsigned int page_data_size
,
4808 unsigned int data_offset
;
4809 unsigned int data_len
;
4810 unsigned int cur_off
;
4811 unsigned int cur_page_idx
;
4812 unsigned int pad_len
;
4813 struct cifs_readdata
*rdata
= mid
->callback_data
;
4814 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
4815 struct bio_vec
*bvec
= NULL
;
4816 struct iov_iter iter
;
4819 bool use_rdma_mr
= false;
4821 if (shdr
->Command
!= SMB2_READ
) {
4822 cifs_server_dbg(VFS
, "only big read responses are supported\n");
4826 if (server
->ops
->is_session_expired
&&
4827 server
->ops
->is_session_expired(buf
)) {
4829 cifs_reconnect(server
);
4833 if (server
->ops
->is_status_pending
&&
4834 server
->ops
->is_status_pending(buf
, server
))
4837 /* set up first two iov to get credits */
4838 rdata
->iov
[0].iov_base
= buf
;
4839 rdata
->iov
[0].iov_len
= 0;
4840 rdata
->iov
[1].iov_base
= buf
;
4841 rdata
->iov
[1].iov_len
=
4842 min_t(unsigned int, buf_len
, server
->vals
->read_rsp_size
);
4843 cifs_dbg(FYI
, "0: iov_base=%p iov_len=%zu\n",
4844 rdata
->iov
[0].iov_base
, rdata
->iov
[0].iov_len
);
4845 cifs_dbg(FYI
, "1: iov_base=%p iov_len=%zu\n",
4846 rdata
->iov
[1].iov_base
, rdata
->iov
[1].iov_len
);
4848 rdata
->result
= server
->ops
->map_error(buf
, true);
4849 if (rdata
->result
!= 0) {
4850 cifs_dbg(FYI
, "%s: server returned error %d\n",
4851 __func__
, rdata
->result
);
4852 /* normal error on read response */
4854 mid
->mid_state
= MID_RESPONSE_RECEIVED
;
4856 dequeue_mid(mid
, false);
4860 data_offset
= server
->ops
->read_data_offset(buf
);
4861 #ifdef CONFIG_CIFS_SMB_DIRECT
4862 use_rdma_mr
= rdata
->mr
;
4864 data_len
= server
->ops
->read_data_length(buf
, use_rdma_mr
);
4866 if (data_offset
< server
->vals
->read_rsp_size
) {
4868 * win2k8 sometimes sends an offset of 0 when the read
4869 * is beyond the EOF. Treat it as if the data starts just after
4872 cifs_dbg(FYI
, "%s: data offset (%u) inside read response header\n",
4873 __func__
, data_offset
);
4874 data_offset
= server
->vals
->read_rsp_size
;
4875 } else if (data_offset
> MAX_CIFS_SMALL_BUFFER_SIZE
) {
4876 /* data_offset is beyond the end of smallbuf */
4877 cifs_dbg(FYI
, "%s: data offset (%u) beyond end of smallbuf\n",
4878 __func__
, data_offset
);
4879 rdata
->result
= -EIO
;
4881 mid
->mid_state
= MID_RESPONSE_MALFORMED
;
4883 dequeue_mid(mid
, rdata
->result
);
4887 pad_len
= data_offset
- server
->vals
->read_rsp_size
;
4889 if (buf_len
<= data_offset
) {
4890 /* read response payload is in pages */
4891 cur_page_idx
= pad_len
/ PAGE_SIZE
;
4892 cur_off
= pad_len
% PAGE_SIZE
;
4894 if (cur_page_idx
!= 0) {
4895 /* data offset is beyond the 1st page of response */
4896 cifs_dbg(FYI
, "%s: data offset (%u) beyond 1st page of response\n",
4897 __func__
, data_offset
);
4898 rdata
->result
= -EIO
;
4900 mid
->mid_state
= MID_RESPONSE_MALFORMED
;
4902 dequeue_mid(mid
, rdata
->result
);
4906 if (data_len
> page_data_size
- pad_len
) {
4907 /* data_len is corrupt -- discard frame */
4908 rdata
->result
= -EIO
;
4910 mid
->mid_state
= MID_RESPONSE_MALFORMED
;
4912 dequeue_mid(mid
, rdata
->result
);
4916 rdata
->result
= init_read_bvec(pages
, npages
, page_data_size
,
4918 if (rdata
->result
!= 0) {
4920 mid
->mid_state
= MID_RESPONSE_MALFORMED
;
4922 dequeue_mid(mid
, rdata
->result
);
4926 iov_iter_bvec(&iter
, WRITE
, bvec
, npages
, data_len
);
4927 } else if (buf_len
>= data_offset
+ data_len
) {
4928 /* read response payload is in buf */
4929 WARN_ONCE(npages
> 0, "read data can be either in buf or in pages");
4930 iov
.iov_base
= buf
+ data_offset
;
4931 iov
.iov_len
= data_len
;
4932 iov_iter_kvec(&iter
, WRITE
, &iov
, 1, data_len
);
4934 /* read response payload cannot be in both buf and pages */
4935 WARN_ONCE(1, "buf can not contain only a part of read data");
4936 rdata
->result
= -EIO
;
4938 mid
->mid_state
= MID_RESPONSE_MALFORMED
;
4940 dequeue_mid(mid
, rdata
->result
);
4944 length
= rdata
->copy_into_pages(server
, rdata
, &iter
);
4952 mid
->mid_state
= MID_RESPONSE_RECEIVED
;
4954 dequeue_mid(mid
, false);
4958 struct smb2_decrypt_work
{
4959 struct work_struct decrypt
;
4960 struct TCP_Server_Info
*server
;
4961 struct page
**ppages
;
4963 unsigned int npages
;
4968 static void smb2_decrypt_offload(struct work_struct
*work
)
4970 struct smb2_decrypt_work
*dw
= container_of(work
,
4971 struct smb2_decrypt_work
, decrypt
);
4973 struct mid_q_entry
*mid
;
4975 rc
= decrypt_raw_data(dw
->server
, dw
->buf
, dw
->server
->vals
->read_rsp_size
,
4976 dw
->ppages
, dw
->npages
, dw
->len
, true);
4978 cifs_dbg(VFS
, "error decrypting rc=%d\n", rc
);
4982 dw
->server
->lstrp
= jiffies
;
4983 mid
= smb2_find_dequeue_mid(dw
->server
, dw
->buf
);
4985 cifs_dbg(FYI
, "mid not found\n");
4987 mid
->decrypted
= true;
4988 rc
= handle_read_data(dw
->server
, mid
, dw
->buf
,
4989 dw
->server
->vals
->read_rsp_size
,
4990 dw
->ppages
, dw
->npages
, dw
->len
,
4993 #ifdef CONFIG_CIFS_STATS2
4994 mid
->when_received
= jiffies
;
4996 if (dw
->server
->ops
->is_network_name_deleted
)
4997 dw
->server
->ops
->is_network_name_deleted(dw
->buf
,
5002 spin_lock(&GlobalMid_Lock
);
5003 if (dw
->server
->tcpStatus
== CifsNeedReconnect
) {
5004 mid
->mid_state
= MID_RETRY_NEEDED
;
5005 spin_unlock(&GlobalMid_Lock
);
5008 mid
->mid_state
= MID_REQUEST_SUBMITTED
;
5009 mid
->mid_flags
&= ~(MID_DELETED
);
5010 list_add_tail(&mid
->qhead
,
5011 &dw
->server
->pending_mid_q
);
5012 spin_unlock(&GlobalMid_Lock
);
5015 cifs_mid_q_entry_release(mid
);
5019 for (i
= dw
->npages
-1; i
>= 0; i
--)
5020 put_page(dw
->ppages
[i
]);
5023 cifs_small_buf_release(dw
->buf
);
5029 receive_encrypted_read(struct TCP_Server_Info
*server
, struct mid_q_entry
**mid
,
5032 char *buf
= server
->smallbuf
;
5033 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
5034 unsigned int npages
;
5035 struct page
**pages
;
5037 unsigned int buflen
= server
->pdu_size
;
5040 struct smb2_decrypt_work
*dw
;
5043 len
= min_t(unsigned int, buflen
, server
->vals
->read_rsp_size
+
5044 sizeof(struct smb2_transform_hdr
)) - HEADER_SIZE(server
) + 1;
5046 rc
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1, len
);
5049 server
->total_read
+= rc
;
5051 len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
) -
5052 server
->vals
->read_rsp_size
;
5053 npages
= DIV_ROUND_UP(len
, PAGE_SIZE
);
5055 pages
= kmalloc_array(npages
, sizeof(struct page
*), GFP_KERNEL
);
5061 for (; i
< npages
; i
++) {
5062 pages
[i
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
5069 /* read read data into pages */
5070 rc
= read_data_into_pages(server
, pages
, npages
, len
);
5074 rc
= cifs_discard_remaining_data(server
);
5079 * For large reads, offload to different thread for better performance,
5080 * use more cores decrypting which can be expensive
5083 if ((server
->min_offload
) && (server
->in_flight
> 1) &&
5084 (server
->pdu_size
>= server
->min_offload
)) {
5085 dw
= kmalloc(sizeof(struct smb2_decrypt_work
), GFP_KERNEL
);
5087 goto non_offloaded_decrypt
;
5089 dw
->buf
= server
->smallbuf
;
5090 server
->smallbuf
= (char *)cifs_small_buf_get();
5092 INIT_WORK(&dw
->decrypt
, smb2_decrypt_offload
);
5094 dw
->npages
= npages
;
5095 dw
->server
= server
;
5098 queue_work(decrypt_wq
, &dw
->decrypt
);
5099 *num_mids
= 0; /* worker thread takes care of finding mid */
5103 non_offloaded_decrypt
:
5104 rc
= decrypt_raw_data(server
, buf
, server
->vals
->read_rsp_size
,
5105 pages
, npages
, len
, false);
5109 *mid
= smb2_find_mid(server
, buf
);
5111 cifs_dbg(FYI
, "mid not found\n");
5113 cifs_dbg(FYI
, "mid found\n");
5114 (*mid
)->decrypted
= true;
5115 rc
= handle_read_data(server
, *mid
, buf
,
5116 server
->vals
->read_rsp_size
,
5117 pages
, npages
, len
, false);
5119 if (server
->ops
->is_network_name_deleted
) {
5120 server
->ops
->is_network_name_deleted(buf
,
5127 for (i
= i
- 1; i
>= 0; i
--)
5132 cifs_discard_remaining_data(server
);
5137 receive_encrypted_standard(struct TCP_Server_Info
*server
,
5138 struct mid_q_entry
**mids
, char **bufs
,
5142 char *buf
= server
->smallbuf
;
5143 struct smb2_sync_hdr
*shdr
;
5144 unsigned int pdu_length
= server
->pdu_size
;
5145 unsigned int buf_size
;
5146 struct mid_q_entry
*mid_entry
;
5148 char *next_buffer
= NULL
;
5152 /* switch to large buffer if too big for a small one */
5153 if (pdu_length
> MAX_CIFS_SMALL_BUFFER_SIZE
) {
5154 server
->large_buf
= true;
5155 memcpy(server
->bigbuf
, buf
, server
->total_read
);
5156 buf
= server
->bigbuf
;
5159 /* now read the rest */
5160 length
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1,
5161 pdu_length
- HEADER_SIZE(server
) + 1);
5164 server
->total_read
+= length
;
5166 buf_size
= pdu_length
- sizeof(struct smb2_transform_hdr
);
5167 length
= decrypt_raw_data(server
, buf
, buf_size
, NULL
, 0, 0, false);
5171 next_is_large
= server
->large_buf
;
5173 shdr
= (struct smb2_sync_hdr
*)buf
;
5174 if (shdr
->NextCommand
) {
5176 next_buffer
= (char *)cifs_buf_get();
5178 next_buffer
= (char *)cifs_small_buf_get();
5180 buf
+ le32_to_cpu(shdr
->NextCommand
),
5181 pdu_length
- le32_to_cpu(shdr
->NextCommand
));
5184 mid_entry
= smb2_find_mid(server
, buf
);
5185 if (mid_entry
== NULL
)
5186 cifs_dbg(FYI
, "mid not found\n");
5188 cifs_dbg(FYI
, "mid found\n");
5189 mid_entry
->decrypted
= true;
5190 mid_entry
->resp_buf_size
= server
->pdu_size
;
5193 if (*num_mids
>= MAX_COMPOUND
) {
5194 cifs_server_dbg(VFS
, "too many PDUs in compound\n");
5197 bufs
[*num_mids
] = buf
;
5198 mids
[(*num_mids
)++] = mid_entry
;
5200 if (mid_entry
&& mid_entry
->handle
)
5201 ret
= mid_entry
->handle(server
, mid_entry
);
5203 ret
= cifs_handle_standard(server
, mid_entry
);
5205 if (ret
== 0 && shdr
->NextCommand
) {
5206 pdu_length
-= le32_to_cpu(shdr
->NextCommand
);
5207 server
->large_buf
= next_is_large
;
5209 server
->bigbuf
= buf
= next_buffer
;
5211 server
->smallbuf
= buf
= next_buffer
;
5213 } else if (ret
!= 0) {
5215 * ret != 0 here means that we didn't get to handle_mid() thus
5216 * server->smallbuf and server->bigbuf are still valid. We need
5217 * to free next_buffer because it is not going to be used
5221 free_rsp_buf(CIFS_LARGE_BUFFER
, next_buffer
);
5223 free_rsp_buf(CIFS_SMALL_BUFFER
, next_buffer
);
5230 smb3_receive_transform(struct TCP_Server_Info
*server
,
5231 struct mid_q_entry
**mids
, char **bufs
, int *num_mids
)
5233 char *buf
= server
->smallbuf
;
5234 unsigned int pdu_length
= server
->pdu_size
;
5235 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
5236 unsigned int orig_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
5238 if (pdu_length
< sizeof(struct smb2_transform_hdr
) +
5239 sizeof(struct smb2_sync_hdr
)) {
5240 cifs_server_dbg(VFS
, "Transform message is too small (%u)\n",
5242 cifs_reconnect(server
);
5243 return -ECONNABORTED
;
5246 if (pdu_length
< orig_len
+ sizeof(struct smb2_transform_hdr
)) {
5247 cifs_server_dbg(VFS
, "Transform message is broken\n");
5248 cifs_reconnect(server
);
5249 return -ECONNABORTED
;
5252 /* TODO: add support for compounds containing READ. */
5253 if (pdu_length
> CIFSMaxBufSize
+ MAX_HEADER_SIZE(server
)) {
5254 return receive_encrypted_read(server
, &mids
[0], num_mids
);
5257 return receive_encrypted_standard(server
, mids
, bufs
, num_mids
);
5261 smb3_handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
)
5263 char *buf
= server
->large_buf
? server
->bigbuf
: server
->smallbuf
;
5265 return handle_read_data(server
, mid
, buf
, server
->pdu_size
,
5270 smb2_next_header(char *buf
)
5272 struct smb2_sync_hdr
*hdr
= (struct smb2_sync_hdr
*)buf
;
5273 struct smb2_transform_hdr
*t_hdr
= (struct smb2_transform_hdr
*)buf
;
5275 if (hdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
)
5276 return sizeof(struct smb2_transform_hdr
) +
5277 le32_to_cpu(t_hdr
->OriginalMessageSize
);
5279 return le32_to_cpu(hdr
->NextCommand
);
5283 smb2_make_node(unsigned int xid
, struct inode
*inode
,
5284 struct dentry
*dentry
, struct cifs_tcon
*tcon
,
5285 const char *full_path
, umode_t mode
, dev_t dev
)
5287 struct cifs_sb_info
*cifs_sb
= CIFS_SB(inode
->i_sb
);
5289 FILE_ALL_INFO
*buf
= NULL
;
5290 struct cifs_io_parms io_parms
= {0};
5292 struct cifs_fid fid
;
5293 struct cifs_open_parms oparms
;
5294 unsigned int bytes_written
;
5295 struct win_dev
*pdev
;
5299 * Check if mounted with mount parm 'sfu' mount parm.
5300 * SFU emulation should work with all servers, but only
5301 * supports block and char device (no socket & fifo),
5302 * and was used by default in earlier versions of Windows
5304 if (!(cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_UNX_EMUL
))
5308 * TODO: Add ability to create instead via reparse point. Windows (e.g.
5309 * their current NFS server) uses this approach to expose special files
5310 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
5313 if (!S_ISCHR(mode
) && !S_ISBLK(mode
))
5316 cifs_dbg(FYI
, "sfu compat create special file\n");
5318 buf
= kmalloc(sizeof(FILE_ALL_INFO
), GFP_KERNEL
);
5325 oparms
.cifs_sb
= cifs_sb
;
5326 oparms
.desired_access
= GENERIC_WRITE
;
5327 oparms
.create_options
= cifs_create_options(cifs_sb
, CREATE_NOT_DIR
|
5328 CREATE_OPTION_SPECIAL
);
5329 oparms
.disposition
= FILE_CREATE
;
5330 oparms
.path
= full_path
;
5332 oparms
.reconnect
= false;
5334 if (tcon
->ses
->server
->oplocks
)
5335 oplock
= REQ_OPLOCK
;
5338 rc
= tcon
->ses
->server
->ops
->open(xid
, &oparms
, &oplock
, buf
);
5343 * BB Do not bother to decode buf since no local inode yet to put
5344 * timestamps in, but we can reuse it safely.
5347 pdev
= (struct win_dev
*)buf
;
5348 io_parms
.pid
= current
->tgid
;
5349 io_parms
.tcon
= tcon
;
5350 io_parms
.offset
= 0;
5351 io_parms
.length
= sizeof(struct win_dev
);
5352 iov
[1].iov_base
= buf
;
5353 iov
[1].iov_len
= sizeof(struct win_dev
);
5354 if (S_ISCHR(mode
)) {
5355 memcpy(pdev
->type
, "IntxCHR", 8);
5356 pdev
->major
= cpu_to_le64(MAJOR(dev
));
5357 pdev
->minor
= cpu_to_le64(MINOR(dev
));
5358 rc
= tcon
->ses
->server
->ops
->sync_write(xid
, &fid
, &io_parms
,
5359 &bytes_written
, iov
, 1);
5360 } else if (S_ISBLK(mode
)) {
5361 memcpy(pdev
->type
, "IntxBLK", 8);
5362 pdev
->major
= cpu_to_le64(MAJOR(dev
));
5363 pdev
->minor
= cpu_to_le64(MINOR(dev
));
5364 rc
= tcon
->ses
->server
->ops
->sync_write(xid
, &fid
, &io_parms
,
5365 &bytes_written
, iov
, 1);
5367 tcon
->ses
->server
->ops
->close(xid
, tcon
, &fid
);
5370 /* FIXME: add code here to set EAs */
5376 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5377 struct smb_version_operations smb20_operations
= {
5378 .compare_fids
= smb2_compare_fids
,
5379 .setup_request
= smb2_setup_request
,
5380 .setup_async_request
= smb2_setup_async_request
,
5381 .check_receive
= smb2_check_receive
,
5382 .add_credits
= smb2_add_credits
,
5383 .set_credits
= smb2_set_credits
,
5384 .get_credits_field
= smb2_get_credits_field
,
5385 .get_credits
= smb2_get_credits
,
5386 .wait_mtu_credits
= cifs_wait_mtu_credits
,
5387 .get_next_mid
= smb2_get_next_mid
,
5388 .revert_current_mid
= smb2_revert_current_mid
,
5389 .read_data_offset
= smb2_read_data_offset
,
5390 .read_data_length
= smb2_read_data_length
,
5391 .map_error
= map_smb2_to_linux_error
,
5392 .find_mid
= smb2_find_mid
,
5393 .check_message
= smb2_check_message
,
5394 .dump_detail
= smb2_dump_detail
,
5395 .clear_stats
= smb2_clear_stats
,
5396 .print_stats
= smb2_print_stats
,
5397 .is_oplock_break
= smb2_is_valid_oplock_break
,
5398 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
5399 .downgrade_oplock
= smb2_downgrade_oplock
,
5400 .need_neg
= smb2_need_neg
,
5401 .negotiate
= smb2_negotiate
,
5402 .negotiate_wsize
= smb2_negotiate_wsize
,
5403 .negotiate_rsize
= smb2_negotiate_rsize
,
5404 .sess_setup
= SMB2_sess_setup
,
5405 .logoff
= SMB2_logoff
,
5406 .tree_connect
= SMB2_tcon
,
5407 .tree_disconnect
= SMB2_tdis
,
5408 .qfs_tcon
= smb2_qfs_tcon
,
5409 .is_path_accessible
= smb2_is_path_accessible
,
5410 .can_echo
= smb2_can_echo
,
5412 .query_path_info
= smb2_query_path_info
,
5413 .get_srv_inum
= smb2_get_srv_inum
,
5414 .query_file_info
= smb2_query_file_info
,
5415 .set_path_size
= smb2_set_path_size
,
5416 .set_file_size
= smb2_set_file_size
,
5417 .set_file_info
= smb2_set_file_info
,
5418 .set_compression
= smb2_set_compression
,
5419 .mkdir
= smb2_mkdir
,
5420 .mkdir_setinfo
= smb2_mkdir_setinfo
,
5421 .rmdir
= smb2_rmdir
,
5422 .unlink
= smb2_unlink
,
5423 .rename
= smb2_rename_path
,
5424 .create_hardlink
= smb2_create_hardlink
,
5425 .query_symlink
= smb2_query_symlink
,
5426 .query_mf_symlink
= smb3_query_mf_symlink
,
5427 .create_mf_symlink
= smb3_create_mf_symlink
,
5428 .open
= smb2_open_file
,
5429 .set_fid
= smb2_set_fid
,
5430 .close
= smb2_close_file
,
5431 .flush
= smb2_flush_file
,
5432 .async_readv
= smb2_async_readv
,
5433 .async_writev
= smb2_async_writev
,
5434 .sync_read
= smb2_sync_read
,
5435 .sync_write
= smb2_sync_write
,
5436 .query_dir_first
= smb2_query_dir_first
,
5437 .query_dir_next
= smb2_query_dir_next
,
5438 .close_dir
= smb2_close_dir
,
5439 .calc_smb_size
= smb2_calc_size
,
5440 .is_status_pending
= smb2_is_status_pending
,
5441 .is_session_expired
= smb2_is_session_expired
,
5442 .oplock_response
= smb2_oplock_response
,
5443 .queryfs
= smb2_queryfs
,
5444 .mand_lock
= smb2_mand_lock
,
5445 .mand_unlock_range
= smb2_unlock_range
,
5446 .push_mand_locks
= smb2_push_mandatory_locks
,
5447 .get_lease_key
= smb2_get_lease_key
,
5448 .set_lease_key
= smb2_set_lease_key
,
5449 .new_lease_key
= smb2_new_lease_key
,
5450 .calc_signature
= smb2_calc_signature
,
5451 .is_read_op
= smb2_is_read_op
,
5452 .set_oplock_level
= smb2_set_oplock_level
,
5453 .create_lease_buf
= smb2_create_lease_buf
,
5454 .parse_lease_buf
= smb2_parse_lease_buf
,
5455 .copychunk_range
= smb2_copychunk_range
,
5456 .wp_retry_size
= smb2_wp_retry_size
,
5457 .dir_needs_close
= smb2_dir_needs_close
,
5458 .get_dfs_refer
= smb2_get_dfs_refer
,
5459 .select_sectype
= smb2_select_sectype
,
5460 #ifdef CONFIG_CIFS_XATTR
5461 .query_all_EAs
= smb2_query_eas
,
5462 .set_EA
= smb2_set_ea
,
5463 #endif /* CIFS_XATTR */
5464 .get_acl
= get_smb2_acl
,
5465 .get_acl_by_fid
= get_smb2_acl_by_fid
,
5466 .set_acl
= set_smb2_acl
,
5467 .next_header
= smb2_next_header
,
5468 .ioctl_query_info
= smb2_ioctl_query_info
,
5469 .make_node
= smb2_make_node
,
5470 .fiemap
= smb3_fiemap
,
5471 .llseek
= smb3_llseek
,
5472 .is_status_io_timeout
= smb2_is_status_io_timeout
,
5473 .is_network_name_deleted
= smb2_is_network_name_deleted
,
5475 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
5477 struct smb_version_operations smb21_operations
= {
5478 .compare_fids
= smb2_compare_fids
,
5479 .setup_request
= smb2_setup_request
,
5480 .setup_async_request
= smb2_setup_async_request
,
5481 .check_receive
= smb2_check_receive
,
5482 .add_credits
= smb2_add_credits
,
5483 .set_credits
= smb2_set_credits
,
5484 .get_credits_field
= smb2_get_credits_field
,
5485 .get_credits
= smb2_get_credits
,
5486 .wait_mtu_credits
= smb2_wait_mtu_credits
,
5487 .adjust_credits
= smb2_adjust_credits
,
5488 .get_next_mid
= smb2_get_next_mid
,
5489 .revert_current_mid
= smb2_revert_current_mid
,
5490 .read_data_offset
= smb2_read_data_offset
,
5491 .read_data_length
= smb2_read_data_length
,
5492 .map_error
= map_smb2_to_linux_error
,
5493 .find_mid
= smb2_find_mid
,
5494 .check_message
= smb2_check_message
,
5495 .dump_detail
= smb2_dump_detail
,
5496 .clear_stats
= smb2_clear_stats
,
5497 .print_stats
= smb2_print_stats
,
5498 .is_oplock_break
= smb2_is_valid_oplock_break
,
5499 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
5500 .downgrade_oplock
= smb2_downgrade_oplock
,
5501 .need_neg
= smb2_need_neg
,
5502 .negotiate
= smb2_negotiate
,
5503 .negotiate_wsize
= smb2_negotiate_wsize
,
5504 .negotiate_rsize
= smb2_negotiate_rsize
,
5505 .sess_setup
= SMB2_sess_setup
,
5506 .logoff
= SMB2_logoff
,
5507 .tree_connect
= SMB2_tcon
,
5508 .tree_disconnect
= SMB2_tdis
,
5509 .qfs_tcon
= smb2_qfs_tcon
,
5510 .is_path_accessible
= smb2_is_path_accessible
,
5511 .can_echo
= smb2_can_echo
,
5513 .query_path_info
= smb2_query_path_info
,
5514 .get_srv_inum
= smb2_get_srv_inum
,
5515 .query_file_info
= smb2_query_file_info
,
5516 .set_path_size
= smb2_set_path_size
,
5517 .set_file_size
= smb2_set_file_size
,
5518 .set_file_info
= smb2_set_file_info
,
5519 .set_compression
= smb2_set_compression
,
5520 .mkdir
= smb2_mkdir
,
5521 .mkdir_setinfo
= smb2_mkdir_setinfo
,
5522 .rmdir
= smb2_rmdir
,
5523 .unlink
= smb2_unlink
,
5524 .rename
= smb2_rename_path
,
5525 .create_hardlink
= smb2_create_hardlink
,
5526 .query_symlink
= smb2_query_symlink
,
5527 .query_mf_symlink
= smb3_query_mf_symlink
,
5528 .create_mf_symlink
= smb3_create_mf_symlink
,
5529 .open
= smb2_open_file
,
5530 .set_fid
= smb2_set_fid
,
5531 .close
= smb2_close_file
,
5532 .flush
= smb2_flush_file
,
5533 .async_readv
= smb2_async_readv
,
5534 .async_writev
= smb2_async_writev
,
5535 .sync_read
= smb2_sync_read
,
5536 .sync_write
= smb2_sync_write
,
5537 .query_dir_first
= smb2_query_dir_first
,
5538 .query_dir_next
= smb2_query_dir_next
,
5539 .close_dir
= smb2_close_dir
,
5540 .calc_smb_size
= smb2_calc_size
,
5541 .is_status_pending
= smb2_is_status_pending
,
5542 .is_session_expired
= smb2_is_session_expired
,
5543 .oplock_response
= smb2_oplock_response
,
5544 .queryfs
= smb2_queryfs
,
5545 .mand_lock
= smb2_mand_lock
,
5546 .mand_unlock_range
= smb2_unlock_range
,
5547 .push_mand_locks
= smb2_push_mandatory_locks
,
5548 .get_lease_key
= smb2_get_lease_key
,
5549 .set_lease_key
= smb2_set_lease_key
,
5550 .new_lease_key
= smb2_new_lease_key
,
5551 .calc_signature
= smb2_calc_signature
,
5552 .is_read_op
= smb21_is_read_op
,
5553 .set_oplock_level
= smb21_set_oplock_level
,
5554 .create_lease_buf
= smb2_create_lease_buf
,
5555 .parse_lease_buf
= smb2_parse_lease_buf
,
5556 .copychunk_range
= smb2_copychunk_range
,
5557 .wp_retry_size
= smb2_wp_retry_size
,
5558 .dir_needs_close
= smb2_dir_needs_close
,
5559 .enum_snapshots
= smb3_enum_snapshots
,
5560 .notify
= smb3_notify
,
5561 .get_dfs_refer
= smb2_get_dfs_refer
,
5562 .select_sectype
= smb2_select_sectype
,
5563 #ifdef CONFIG_CIFS_XATTR
5564 .query_all_EAs
= smb2_query_eas
,
5565 .set_EA
= smb2_set_ea
,
5566 #endif /* CIFS_XATTR */
5567 .get_acl
= get_smb2_acl
,
5568 .get_acl_by_fid
= get_smb2_acl_by_fid
,
5569 .set_acl
= set_smb2_acl
,
5570 .next_header
= smb2_next_header
,
5571 .ioctl_query_info
= smb2_ioctl_query_info
,
5572 .make_node
= smb2_make_node
,
5573 .fiemap
= smb3_fiemap
,
5574 .llseek
= smb3_llseek
,
5575 .is_status_io_timeout
= smb2_is_status_io_timeout
,
5576 .is_network_name_deleted
= smb2_is_network_name_deleted
,
5579 struct smb_version_operations smb30_operations
= {
5580 .compare_fids
= smb2_compare_fids
,
5581 .setup_request
= smb2_setup_request
,
5582 .setup_async_request
= smb2_setup_async_request
,
5583 .check_receive
= smb2_check_receive
,
5584 .add_credits
= smb2_add_credits
,
5585 .set_credits
= smb2_set_credits
,
5586 .get_credits_field
= smb2_get_credits_field
,
5587 .get_credits
= smb2_get_credits
,
5588 .wait_mtu_credits
= smb2_wait_mtu_credits
,
5589 .adjust_credits
= smb2_adjust_credits
,
5590 .get_next_mid
= smb2_get_next_mid
,
5591 .revert_current_mid
= smb2_revert_current_mid
,
5592 .read_data_offset
= smb2_read_data_offset
,
5593 .read_data_length
= smb2_read_data_length
,
5594 .map_error
= map_smb2_to_linux_error
,
5595 .find_mid
= smb2_find_mid
,
5596 .check_message
= smb2_check_message
,
5597 .dump_detail
= smb2_dump_detail
,
5598 .clear_stats
= smb2_clear_stats
,
5599 .print_stats
= smb2_print_stats
,
5600 .dump_share_caps
= smb2_dump_share_caps
,
5601 .is_oplock_break
= smb2_is_valid_oplock_break
,
5602 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
5603 .downgrade_oplock
= smb3_downgrade_oplock
,
5604 .need_neg
= smb2_need_neg
,
5605 .negotiate
= smb2_negotiate
,
5606 .negotiate_wsize
= smb3_negotiate_wsize
,
5607 .negotiate_rsize
= smb3_negotiate_rsize
,
5608 .sess_setup
= SMB2_sess_setup
,
5609 .logoff
= SMB2_logoff
,
5610 .tree_connect
= SMB2_tcon
,
5611 .tree_disconnect
= SMB2_tdis
,
5612 .qfs_tcon
= smb3_qfs_tcon
,
5613 .is_path_accessible
= smb2_is_path_accessible
,
5614 .can_echo
= smb2_can_echo
,
5616 .query_path_info
= smb2_query_path_info
,
5617 /* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */
5618 .query_reparse_tag
= smb2_query_reparse_tag
,
5619 .get_srv_inum
= smb2_get_srv_inum
,
5620 .query_file_info
= smb2_query_file_info
,
5621 .set_path_size
= smb2_set_path_size
,
5622 .set_file_size
= smb2_set_file_size
,
5623 .set_file_info
= smb2_set_file_info
,
5624 .set_compression
= smb2_set_compression
,
5625 .mkdir
= smb2_mkdir
,
5626 .mkdir_setinfo
= smb2_mkdir_setinfo
,
5627 .rmdir
= smb2_rmdir
,
5628 .unlink
= smb2_unlink
,
5629 .rename
= smb2_rename_path
,
5630 .create_hardlink
= smb2_create_hardlink
,
5631 .query_symlink
= smb2_query_symlink
,
5632 .query_mf_symlink
= smb3_query_mf_symlink
,
5633 .create_mf_symlink
= smb3_create_mf_symlink
,
5634 .open
= smb2_open_file
,
5635 .set_fid
= smb2_set_fid
,
5636 .close
= smb2_close_file
,
5637 .close_getattr
= smb2_close_getattr
,
5638 .flush
= smb2_flush_file
,
5639 .async_readv
= smb2_async_readv
,
5640 .async_writev
= smb2_async_writev
,
5641 .sync_read
= smb2_sync_read
,
5642 .sync_write
= smb2_sync_write
,
5643 .query_dir_first
= smb2_query_dir_first
,
5644 .query_dir_next
= smb2_query_dir_next
,
5645 .close_dir
= smb2_close_dir
,
5646 .calc_smb_size
= smb2_calc_size
,
5647 .is_status_pending
= smb2_is_status_pending
,
5648 .is_session_expired
= smb2_is_session_expired
,
5649 .oplock_response
= smb2_oplock_response
,
5650 .queryfs
= smb2_queryfs
,
5651 .mand_lock
= smb2_mand_lock
,
5652 .mand_unlock_range
= smb2_unlock_range
,
5653 .push_mand_locks
= smb2_push_mandatory_locks
,
5654 .get_lease_key
= smb2_get_lease_key
,
5655 .set_lease_key
= smb2_set_lease_key
,
5656 .new_lease_key
= smb2_new_lease_key
,
5657 .generate_signingkey
= generate_smb30signingkey
,
5658 .calc_signature
= smb3_calc_signature
,
5659 .set_integrity
= smb3_set_integrity
,
5660 .is_read_op
= smb21_is_read_op
,
5661 .set_oplock_level
= smb3_set_oplock_level
,
5662 .create_lease_buf
= smb3_create_lease_buf
,
5663 .parse_lease_buf
= smb3_parse_lease_buf
,
5664 .copychunk_range
= smb2_copychunk_range
,
5665 .duplicate_extents
= smb2_duplicate_extents
,
5666 .validate_negotiate
= smb3_validate_negotiate
,
5667 .wp_retry_size
= smb2_wp_retry_size
,
5668 .dir_needs_close
= smb2_dir_needs_close
,
5669 .fallocate
= smb3_fallocate
,
5670 .enum_snapshots
= smb3_enum_snapshots
,
5671 .notify
= smb3_notify
,
5672 .init_transform_rq
= smb3_init_transform_rq
,
5673 .is_transform_hdr
= smb3_is_transform_hdr
,
5674 .receive_transform
= smb3_receive_transform
,
5675 .get_dfs_refer
= smb2_get_dfs_refer
,
5676 .select_sectype
= smb2_select_sectype
,
5677 #ifdef CONFIG_CIFS_XATTR
5678 .query_all_EAs
= smb2_query_eas
,
5679 .set_EA
= smb2_set_ea
,
5680 #endif /* CIFS_XATTR */
5681 .get_acl
= get_smb2_acl
,
5682 .get_acl_by_fid
= get_smb2_acl_by_fid
,
5683 .set_acl
= set_smb2_acl
,
5684 .next_header
= smb2_next_header
,
5685 .ioctl_query_info
= smb2_ioctl_query_info
,
5686 .make_node
= smb2_make_node
,
5687 .fiemap
= smb3_fiemap
,
5688 .llseek
= smb3_llseek
,
5689 .is_status_io_timeout
= smb2_is_status_io_timeout
,
5690 .is_network_name_deleted
= smb2_is_network_name_deleted
,
5693 struct smb_version_operations smb311_operations
= {
5694 .compare_fids
= smb2_compare_fids
,
5695 .setup_request
= smb2_setup_request
,
5696 .setup_async_request
= smb2_setup_async_request
,
5697 .check_receive
= smb2_check_receive
,
5698 .add_credits
= smb2_add_credits
,
5699 .set_credits
= smb2_set_credits
,
5700 .get_credits_field
= smb2_get_credits_field
,
5701 .get_credits
= smb2_get_credits
,
5702 .wait_mtu_credits
= smb2_wait_mtu_credits
,
5703 .adjust_credits
= smb2_adjust_credits
,
5704 .get_next_mid
= smb2_get_next_mid
,
5705 .revert_current_mid
= smb2_revert_current_mid
,
5706 .read_data_offset
= smb2_read_data_offset
,
5707 .read_data_length
= smb2_read_data_length
,
5708 .map_error
= map_smb2_to_linux_error
,
5709 .find_mid
= smb2_find_mid
,
5710 .check_message
= smb2_check_message
,
5711 .dump_detail
= smb2_dump_detail
,
5712 .clear_stats
= smb2_clear_stats
,
5713 .print_stats
= smb2_print_stats
,
5714 .dump_share_caps
= smb2_dump_share_caps
,
5715 .is_oplock_break
= smb2_is_valid_oplock_break
,
5716 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
5717 .downgrade_oplock
= smb3_downgrade_oplock
,
5718 .need_neg
= smb2_need_neg
,
5719 .negotiate
= smb2_negotiate
,
5720 .negotiate_wsize
= smb3_negotiate_wsize
,
5721 .negotiate_rsize
= smb3_negotiate_rsize
,
5722 .sess_setup
= SMB2_sess_setup
,
5723 .logoff
= SMB2_logoff
,
5724 .tree_connect
= SMB2_tcon
,
5725 .tree_disconnect
= SMB2_tdis
,
5726 .qfs_tcon
= smb3_qfs_tcon
,
5727 .is_path_accessible
= smb2_is_path_accessible
,
5728 .can_echo
= smb2_can_echo
,
5730 .query_path_info
= smb2_query_path_info
,
5731 .query_reparse_tag
= smb2_query_reparse_tag
,
5732 .get_srv_inum
= smb2_get_srv_inum
,
5733 .query_file_info
= smb2_query_file_info
,
5734 .set_path_size
= smb2_set_path_size
,
5735 .set_file_size
= smb2_set_file_size
,
5736 .set_file_info
= smb2_set_file_info
,
5737 .set_compression
= smb2_set_compression
,
5738 .mkdir
= smb2_mkdir
,
5739 .mkdir_setinfo
= smb2_mkdir_setinfo
,
5740 .posix_mkdir
= smb311_posix_mkdir
,
5741 .rmdir
= smb2_rmdir
,
5742 .unlink
= smb2_unlink
,
5743 .rename
= smb2_rename_path
,
5744 .create_hardlink
= smb2_create_hardlink
,
5745 .query_symlink
= smb2_query_symlink
,
5746 .query_mf_symlink
= smb3_query_mf_symlink
,
5747 .create_mf_symlink
= smb3_create_mf_symlink
,
5748 .open
= smb2_open_file
,
5749 .set_fid
= smb2_set_fid
,
5750 .close
= smb2_close_file
,
5751 .close_getattr
= smb2_close_getattr
,
5752 .flush
= smb2_flush_file
,
5753 .async_readv
= smb2_async_readv
,
5754 .async_writev
= smb2_async_writev
,
5755 .sync_read
= smb2_sync_read
,
5756 .sync_write
= smb2_sync_write
,
5757 .query_dir_first
= smb2_query_dir_first
,
5758 .query_dir_next
= smb2_query_dir_next
,
5759 .close_dir
= smb2_close_dir
,
5760 .calc_smb_size
= smb2_calc_size
,
5761 .is_status_pending
= smb2_is_status_pending
,
5762 .is_session_expired
= smb2_is_session_expired
,
5763 .oplock_response
= smb2_oplock_response
,
5764 .queryfs
= smb311_queryfs
,
5765 .mand_lock
= smb2_mand_lock
,
5766 .mand_unlock_range
= smb2_unlock_range
,
5767 .push_mand_locks
= smb2_push_mandatory_locks
,
5768 .get_lease_key
= smb2_get_lease_key
,
5769 .set_lease_key
= smb2_set_lease_key
,
5770 .new_lease_key
= smb2_new_lease_key
,
5771 .generate_signingkey
= generate_smb311signingkey
,
5772 .calc_signature
= smb3_calc_signature
,
5773 .set_integrity
= smb3_set_integrity
,
5774 .is_read_op
= smb21_is_read_op
,
5775 .set_oplock_level
= smb3_set_oplock_level
,
5776 .create_lease_buf
= smb3_create_lease_buf
,
5777 .parse_lease_buf
= smb3_parse_lease_buf
,
5778 .copychunk_range
= smb2_copychunk_range
,
5779 .duplicate_extents
= smb2_duplicate_extents
,
5780 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
5781 .wp_retry_size
= smb2_wp_retry_size
,
5782 .dir_needs_close
= smb2_dir_needs_close
,
5783 .fallocate
= smb3_fallocate
,
5784 .enum_snapshots
= smb3_enum_snapshots
,
5785 .notify
= smb3_notify
,
5786 .init_transform_rq
= smb3_init_transform_rq
,
5787 .is_transform_hdr
= smb3_is_transform_hdr
,
5788 .receive_transform
= smb3_receive_transform
,
5789 .get_dfs_refer
= smb2_get_dfs_refer
,
5790 .select_sectype
= smb2_select_sectype
,
5791 #ifdef CONFIG_CIFS_XATTR
5792 .query_all_EAs
= smb2_query_eas
,
5793 .set_EA
= smb2_set_ea
,
5794 #endif /* CIFS_XATTR */
5795 .get_acl
= get_smb2_acl
,
5796 .get_acl_by_fid
= get_smb2_acl_by_fid
,
5797 .set_acl
= set_smb2_acl
,
5798 .next_header
= smb2_next_header
,
5799 .ioctl_query_info
= smb2_ioctl_query_info
,
5800 .make_node
= smb2_make_node
,
5801 .fiemap
= smb3_fiemap
,
5802 .llseek
= smb3_llseek
,
5803 .is_status_io_timeout
= smb2_is_status_io_timeout
,
5804 .is_network_name_deleted
= smb2_is_network_name_deleted
,
5807 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
5808 struct smb_version_values smb20_values
= {
5809 .version_string
= SMB20_VERSION_STRING
,
5810 .protocol_id
= SMB20_PROT_ID
,
5811 .req_capabilities
= 0, /* MBZ */
5812 .large_lock_type
= 0,
5813 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
5814 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
5815 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
5816 .header_size
= sizeof(struct smb2_sync_hdr
),
5817 .header_preamble_size
= 0,
5818 .max_header_size
= MAX_SMB2_HDR_SIZE
,
5819 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
5820 .lock_cmd
= SMB2_LOCK
,
5822 .cap_nt_find
= SMB2_NT_FIND
,
5823 .cap_large_files
= SMB2_LARGE_FILES
,
5824 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5825 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5826 .create_lease_size
= sizeof(struct create_lease
),
5828 #endif /* ALLOW_INSECURE_LEGACY */
5830 struct smb_version_values smb21_values
= {
5831 .version_string
= SMB21_VERSION_STRING
,
5832 .protocol_id
= SMB21_PROT_ID
,
5833 .req_capabilities
= 0, /* MBZ on negotiate req until SMB3 dialect */
5834 .large_lock_type
= 0,
5835 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
5836 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
5837 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
5838 .header_size
= sizeof(struct smb2_sync_hdr
),
5839 .header_preamble_size
= 0,
5840 .max_header_size
= MAX_SMB2_HDR_SIZE
,
5841 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
5842 .lock_cmd
= SMB2_LOCK
,
5844 .cap_nt_find
= SMB2_NT_FIND
,
5845 .cap_large_files
= SMB2_LARGE_FILES
,
5846 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5847 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5848 .create_lease_size
= sizeof(struct create_lease
),
5851 struct smb_version_values smb3any_values
= {
5852 .version_string
= SMB3ANY_VERSION_STRING
,
5853 .protocol_id
= SMB302_PROT_ID
, /* doesn't matter, send protocol array */
5854 .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
,
5855 .large_lock_type
= 0,
5856 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
5857 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
5858 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
5859 .header_size
= sizeof(struct smb2_sync_hdr
),
5860 .header_preamble_size
= 0,
5861 .max_header_size
= MAX_SMB2_HDR_SIZE
,
5862 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
5863 .lock_cmd
= SMB2_LOCK
,
5865 .cap_nt_find
= SMB2_NT_FIND
,
5866 .cap_large_files
= SMB2_LARGE_FILES
,
5867 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5868 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5869 .create_lease_size
= sizeof(struct create_lease_v2
),
5872 struct smb_version_values smbdefault_values
= {
5873 .version_string
= SMBDEFAULT_VERSION_STRING
,
5874 .protocol_id
= SMB302_PROT_ID
, /* doesn't matter, send protocol array */
5875 .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
,
5876 .large_lock_type
= 0,
5877 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
5878 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
5879 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
5880 .header_size
= sizeof(struct smb2_sync_hdr
),
5881 .header_preamble_size
= 0,
5882 .max_header_size
= MAX_SMB2_HDR_SIZE
,
5883 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
5884 .lock_cmd
= SMB2_LOCK
,
5886 .cap_nt_find
= SMB2_NT_FIND
,
5887 .cap_large_files
= SMB2_LARGE_FILES
,
5888 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5889 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5890 .create_lease_size
= sizeof(struct create_lease_v2
),
5893 struct smb_version_values smb30_values
= {
5894 .version_string
= SMB30_VERSION_STRING
,
5895 .protocol_id
= SMB30_PROT_ID
,
5896 .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
,
5897 .large_lock_type
= 0,
5898 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
5899 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
5900 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
5901 .header_size
= sizeof(struct smb2_sync_hdr
),
5902 .header_preamble_size
= 0,
5903 .max_header_size
= MAX_SMB2_HDR_SIZE
,
5904 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
5905 .lock_cmd
= SMB2_LOCK
,
5907 .cap_nt_find
= SMB2_NT_FIND
,
5908 .cap_large_files
= SMB2_LARGE_FILES
,
5909 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5910 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5911 .create_lease_size
= sizeof(struct create_lease_v2
),
5914 struct smb_version_values smb302_values
= {
5915 .version_string
= SMB302_VERSION_STRING
,
5916 .protocol_id
= SMB302_PROT_ID
,
5917 .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
,
5918 .large_lock_type
= 0,
5919 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
5920 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
5921 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
5922 .header_size
= sizeof(struct smb2_sync_hdr
),
5923 .header_preamble_size
= 0,
5924 .max_header_size
= MAX_SMB2_HDR_SIZE
,
5925 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
5926 .lock_cmd
= SMB2_LOCK
,
5928 .cap_nt_find
= SMB2_NT_FIND
,
5929 .cap_large_files
= SMB2_LARGE_FILES
,
5930 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5931 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5932 .create_lease_size
= sizeof(struct create_lease_v2
),
5935 struct smb_version_values smb311_values
= {
5936 .version_string
= SMB311_VERSION_STRING
,
5937 .protocol_id
= SMB311_PROT_ID
,
5938 .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
,
5939 .large_lock_type
= 0,
5940 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
5941 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
5942 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
5943 .header_size
= sizeof(struct smb2_sync_hdr
),
5944 .header_preamble_size
= 0,
5945 .max_header_size
= MAX_SMB2_HDR_SIZE
,
5946 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
5947 .lock_cmd
= SMB2_LOCK
,
5949 .cap_nt_find
= SMB2_NT_FIND
,
5950 .cap_large_files
= SMB2_LARGE_FILES
,
5951 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5952 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5953 .create_lease_size
= sizeof(struct create_lease_v2
),