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 unsigned int add
= credits
->value
;
67 unsigned int instance
= credits
->instance
;
68 bool reconnect_detected
= false;
70 spin_lock(&server
->req_lock
);
71 val
= server
->ops
->get_credits_field(server
, optype
);
73 /* eg found case where write overlapping reconnect messed up credits */
74 if (((optype
& CIFS_OP_MASK
) == CIFS_NEG_OP
) && (*val
!= 0))
75 trace_smb3_reconnect_with_invalid_credits(server
->CurrentMid
,
76 server
->hostname
, *val
, add
);
77 if ((instance
== 0) || (instance
== server
->reconnect_instance
))
80 reconnect_detected
= true;
83 *val
= 65000; /* Don't get near 64K credits, avoid srv bugs */
84 pr_warn_once("server overflowed SMB3 credits\n");
87 if (server
->in_flight
== 0 && (optype
& CIFS_OP_MASK
) != CIFS_NEG_OP
)
88 rc
= change_conf(server
);
90 * Sometimes server returns 0 credits on oplock break ack - we need to
91 * rebalance credits in this case.
93 else if (server
->in_flight
> 0 && server
->oplock_credits
== 0 &&
95 if (server
->credits
> 1) {
97 server
->oplock_credits
++;
100 spin_unlock(&server
->req_lock
);
101 wake_up(&server
->request_q
);
103 if (reconnect_detected
) {
104 cifs_dbg(FYI
, "trying to put %d credits from the old server instance %d\n",
108 if (server
->tcpStatus
== CifsNeedReconnect
109 || server
->tcpStatus
== CifsExiting
)
114 /* change_conf hasn't been executed */
117 cifs_server_dbg(VFS
, "Possible client or server bug - zero credits\n");
120 cifs_server_dbg(VFS
, "disabling echoes and oplocks\n");
123 cifs_dbg(FYI
, "disabling oplocks\n");
126 trace_smb3_add_credits(server
->CurrentMid
,
127 server
->hostname
, rc
, add
);
128 cifs_dbg(FYI
, "%s: added %u credits total=%d\n", __func__
, add
, rc
);
133 smb2_set_credits(struct TCP_Server_Info
*server
, const int val
)
135 spin_lock(&server
->req_lock
);
136 server
->credits
= val
;
138 server
->reconnect_instance
++;
139 spin_unlock(&server
->req_lock
);
141 trace_smb3_set_credits(server
->CurrentMid
,
142 server
->hostname
, val
, val
);
143 cifs_dbg(FYI
, "%s: set %u credits\n", __func__
, val
);
145 /* don't log while holding the lock */
147 cifs_dbg(FYI
, "set credits to 1 due to smb2 reconnect\n");
151 smb2_get_credits_field(struct TCP_Server_Info
*server
, const int optype
)
155 return &server
->echo_credits
;
157 return &server
->oplock_credits
;
159 return &server
->credits
;
164 smb2_get_credits(struct mid_q_entry
*mid
)
166 return mid
->credits_received
;
170 smb2_wait_mtu_credits(struct TCP_Server_Info
*server
, unsigned int size
,
171 unsigned int *num
, struct cifs_credits
*credits
)
174 unsigned int scredits
;
176 spin_lock(&server
->req_lock
);
178 if (server
->credits
<= 0) {
179 spin_unlock(&server
->req_lock
);
180 cifs_num_waiters_inc(server
);
181 rc
= wait_event_killable(server
->request_q
,
182 has_credits(server
, &server
->credits
, 1));
183 cifs_num_waiters_dec(server
);
186 spin_lock(&server
->req_lock
);
188 if (server
->tcpStatus
== CifsExiting
) {
189 spin_unlock(&server
->req_lock
);
193 scredits
= server
->credits
;
194 /* can deadlock with reopen */
196 *num
= SMB2_MAX_BUFFER_SIZE
;
198 credits
->instance
= 0;
202 /* leave some credits for reopen and other ops */
204 *num
= min_t(unsigned int, size
,
205 scredits
* SMB2_MAX_BUFFER_SIZE
);
208 DIV_ROUND_UP(*num
, SMB2_MAX_BUFFER_SIZE
);
209 credits
->instance
= server
->reconnect_instance
;
210 server
->credits
-= credits
->value
;
211 scredits
= server
->credits
;
213 if (server
->in_flight
> server
->max_in_flight
)
214 server
->max_in_flight
= server
->in_flight
;
218 spin_unlock(&server
->req_lock
);
220 trace_smb3_add_credits(server
->CurrentMid
,
221 server
->hostname
, scredits
, -(credits
->value
));
222 cifs_dbg(FYI
, "%s: removed %u credits total=%d\n",
223 __func__
, credits
->value
, scredits
);
229 smb2_adjust_credits(struct TCP_Server_Info
*server
,
230 struct cifs_credits
*credits
,
231 const unsigned int payload_size
)
233 int new_val
= DIV_ROUND_UP(payload_size
, SMB2_MAX_BUFFER_SIZE
);
236 if (!credits
->value
|| credits
->value
== new_val
)
239 if (credits
->value
< new_val
) {
240 trace_smb3_too_many_credits(server
->CurrentMid
,
241 server
->hostname
, 0, credits
->value
- new_val
);
242 cifs_server_dbg(VFS
, "request has less credits (%d) than required (%d)",
243 credits
->value
, new_val
);
248 spin_lock(&server
->req_lock
);
250 if (server
->reconnect_instance
!= credits
->instance
) {
251 spin_unlock(&server
->req_lock
);
252 trace_smb3_reconnect_detected(server
->CurrentMid
,
253 server
->hostname
, 0, 0);
254 cifs_server_dbg(VFS
, "trying to return %d credits to old session\n",
255 credits
->value
- new_val
);
259 server
->credits
+= credits
->value
- new_val
;
260 scredits
= server
->credits
;
261 spin_unlock(&server
->req_lock
);
262 wake_up(&server
->request_q
);
263 credits
->value
= new_val
;
265 trace_smb3_add_credits(server
->CurrentMid
,
266 server
->hostname
, scredits
, credits
->value
- new_val
);
267 cifs_dbg(FYI
, "%s: adjust added %u credits total=%d\n",
268 __func__
, credits
->value
- new_val
, scredits
);
274 smb2_get_next_mid(struct TCP_Server_Info
*server
)
277 /* for SMB2 we need the current value */
278 spin_lock(&GlobalMid_Lock
);
279 mid
= server
->CurrentMid
++;
280 spin_unlock(&GlobalMid_Lock
);
285 smb2_revert_current_mid(struct TCP_Server_Info
*server
, const unsigned int val
)
287 spin_lock(&GlobalMid_Lock
);
288 if (server
->CurrentMid
>= val
)
289 server
->CurrentMid
-= val
;
290 spin_unlock(&GlobalMid_Lock
);
293 static struct mid_q_entry
*
294 __smb2_find_mid(struct TCP_Server_Info
*server
, char *buf
, bool dequeue
)
296 struct mid_q_entry
*mid
;
297 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
298 __u64 wire_mid
= le64_to_cpu(shdr
->MessageId
);
300 if (shdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
) {
301 cifs_server_dbg(VFS
, "Encrypted frame parsing not supported yet\n");
305 spin_lock(&GlobalMid_Lock
);
306 list_for_each_entry(mid
, &server
->pending_mid_q
, qhead
) {
307 if ((mid
->mid
== wire_mid
) &&
308 (mid
->mid_state
== MID_REQUEST_SUBMITTED
) &&
309 (mid
->command
== shdr
->Command
)) {
310 kref_get(&mid
->refcount
);
312 list_del_init(&mid
->qhead
);
313 mid
->mid_flags
|= MID_DELETED
;
315 spin_unlock(&GlobalMid_Lock
);
319 spin_unlock(&GlobalMid_Lock
);
323 static struct mid_q_entry
*
324 smb2_find_mid(struct TCP_Server_Info
*server
, char *buf
)
326 return __smb2_find_mid(server
, buf
, false);
329 static struct mid_q_entry
*
330 smb2_find_dequeue_mid(struct TCP_Server_Info
*server
, char *buf
)
332 return __smb2_find_mid(server
, buf
, true);
336 smb2_dump_detail(void *buf
, struct TCP_Server_Info
*server
)
338 #ifdef CONFIG_CIFS_DEBUG2
339 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
341 cifs_server_dbg(VFS
, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
342 shdr
->Command
, shdr
->Status
, shdr
->Flags
, shdr
->MessageId
,
344 cifs_server_dbg(VFS
, "smb buf %p len %u\n", buf
,
345 server
->ops
->calc_smb_size(buf
, server
));
350 smb2_need_neg(struct TCP_Server_Info
*server
)
352 return server
->max_read
== 0;
356 smb2_negotiate(const unsigned int xid
, struct cifs_ses
*ses
)
360 cifs_ses_server(ses
)->CurrentMid
= 0;
361 rc
= SMB2_negotiate(xid
, ses
);
362 /* BB we probably don't need to retry with modern servers */
369 smb2_negotiate_wsize(struct cifs_tcon
*tcon
, struct smb3_fs_context
*ctx
)
371 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
374 /* start with specified wsize, or default */
375 wsize
= ctx
->wsize
? ctx
->wsize
: CIFS_DEFAULT_IOSIZE
;
376 wsize
= min_t(unsigned int, wsize
, server
->max_write
);
377 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
378 wsize
= min_t(unsigned int, wsize
, SMB2_MAX_BUFFER_SIZE
);
384 smb3_negotiate_wsize(struct cifs_tcon
*tcon
, struct smb3_fs_context
*ctx
)
386 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
389 /* start with specified wsize, or default */
390 wsize
= ctx
->wsize
? ctx
->wsize
: SMB3_DEFAULT_IOSIZE
;
391 wsize
= min_t(unsigned int, wsize
, server
->max_write
);
392 #ifdef CONFIG_CIFS_SMB_DIRECT
396 * Account for SMB2 data transfer packet header and
397 * possible encryption header
399 wsize
= min_t(unsigned int,
401 server
->smbd_conn
->max_fragmented_send_size
-
402 SMB2_READWRITE_PDU_HEADER_SIZE
-
403 sizeof(struct smb2_transform_hdr
));
405 wsize
= min_t(unsigned int,
406 wsize
, server
->smbd_conn
->max_readwrite_size
);
409 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
410 wsize
= min_t(unsigned int, wsize
, SMB2_MAX_BUFFER_SIZE
);
416 smb2_negotiate_rsize(struct cifs_tcon
*tcon
, struct smb3_fs_context
*ctx
)
418 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
421 /* start with specified rsize, or default */
422 rsize
= ctx
->rsize
? ctx
->rsize
: CIFS_DEFAULT_IOSIZE
;
423 rsize
= min_t(unsigned int, rsize
, server
->max_read
);
425 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
426 rsize
= min_t(unsigned int, rsize
, SMB2_MAX_BUFFER_SIZE
);
432 smb3_negotiate_rsize(struct cifs_tcon
*tcon
, struct smb3_fs_context
*ctx
)
434 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
437 /* start with specified rsize, or default */
438 rsize
= ctx
->rsize
? ctx
->rsize
: SMB3_DEFAULT_IOSIZE
;
439 rsize
= min_t(unsigned int, rsize
, server
->max_read
);
440 #ifdef CONFIG_CIFS_SMB_DIRECT
444 * Account for SMB2 data transfer packet header and
445 * possible encryption header
447 rsize
= min_t(unsigned int,
449 server
->smbd_conn
->max_fragmented_recv_size
-
450 SMB2_READWRITE_PDU_HEADER_SIZE
-
451 sizeof(struct smb2_transform_hdr
));
453 rsize
= min_t(unsigned int,
454 rsize
, server
->smbd_conn
->max_readwrite_size
);
458 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
459 rsize
= min_t(unsigned int, rsize
, SMB2_MAX_BUFFER_SIZE
);
465 parse_server_interfaces(struct network_interface_info_ioctl_rsp
*buf
,
467 struct cifs_server_iface
**iface_list
,
470 struct network_interface_info_ioctl_rsp
*p
;
471 struct sockaddr_in
*addr4
;
472 struct sockaddr_in6
*addr6
;
473 struct iface_info_ipv4
*p4
;
474 struct iface_info_ipv6
*p6
;
475 struct cifs_server_iface
*info
;
485 * Fist pass: count and sanity check
488 bytes_left
= buf_len
;
490 while (bytes_left
>= sizeof(*p
)) {
492 next
= le32_to_cpu(p
->Next
);
494 bytes_left
-= sizeof(*p
);
497 p
= (struct network_interface_info_ioctl_rsp
*)((u8
*)p
+next
);
502 cifs_dbg(VFS
, "%s: malformed interface info\n", __func__
);
507 /* Azure rounds the buffer size up 8, to a 16 byte boundary */
508 if ((bytes_left
> 8) || p
->Next
)
509 cifs_dbg(VFS
, "%s: incomplete interface info\n", __func__
);
513 * Second pass: extract info to internal structure
516 *iface_list
= kcalloc(nb_iface
, sizeof(**iface_list
), GFP_KERNEL
);
523 bytes_left
= buf_len
;
525 while (bytes_left
>= sizeof(*p
)) {
526 info
->speed
= le64_to_cpu(p
->LinkSpeed
);
527 info
->rdma_capable
= le32_to_cpu(p
->Capability
& RDMA_CAPABLE
);
528 info
->rss_capable
= le32_to_cpu(p
->Capability
& RSS_CAPABLE
);
530 cifs_dbg(FYI
, "%s: adding iface %zu\n", __func__
, *iface_count
);
531 cifs_dbg(FYI
, "%s: speed %zu bps\n", __func__
, info
->speed
);
532 cifs_dbg(FYI
, "%s: capabilities 0x%08x\n", __func__
,
533 le32_to_cpu(p
->Capability
));
537 * The kernel and wire socket structures have the same
538 * layout and use network byte order but make the
539 * conversion explicit in case either one changes.
542 addr4
= (struct sockaddr_in
*)&info
->sockaddr
;
543 p4
= (struct iface_info_ipv4
*)p
->Buffer
;
544 addr4
->sin_family
= AF_INET
;
545 memcpy(&addr4
->sin_addr
, &p4
->IPv4Address
, 4);
547 /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
548 addr4
->sin_port
= cpu_to_be16(CIFS_PORT
);
550 cifs_dbg(FYI
, "%s: ipv4 %pI4\n", __func__
,
554 addr6
= (struct sockaddr_in6
*)&info
->sockaddr
;
555 p6
= (struct iface_info_ipv6
*)p
->Buffer
;
556 addr6
->sin6_family
= AF_INET6
;
557 memcpy(&addr6
->sin6_addr
, &p6
->IPv6Address
, 16);
559 /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
560 addr6
->sin6_flowinfo
= 0;
561 addr6
->sin6_scope_id
= 0;
562 addr6
->sin6_port
= cpu_to_be16(CIFS_PORT
);
564 cifs_dbg(FYI
, "%s: ipv6 %pI6\n", __func__
,
569 "%s: skipping unsupported socket family\n",
577 next
= le32_to_cpu(p
->Next
);
580 p
= (struct network_interface_info_ioctl_rsp
*)((u8
*)p
+next
);
598 static int compare_iface(const void *ia
, const void *ib
)
600 const struct cifs_server_iface
*a
= (struct cifs_server_iface
*)ia
;
601 const struct cifs_server_iface
*b
= (struct cifs_server_iface
*)ib
;
603 return a
->speed
== b
->speed
? 0 : (a
->speed
> b
->speed
? -1 : 1);
607 SMB3_request_interfaces(const unsigned int xid
, struct cifs_tcon
*tcon
)
610 unsigned int ret_data_len
= 0;
611 struct network_interface_info_ioctl_rsp
*out_buf
= NULL
;
612 struct cifs_server_iface
*iface_list
;
614 struct cifs_ses
*ses
= tcon
->ses
;
616 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
617 FSCTL_QUERY_NETWORK_INTERFACE_INFO
, true /* is_fsctl */,
618 NULL
/* no data input */, 0 /* no data input */,
619 CIFSMaxBufSize
, (char **)&out_buf
, &ret_data_len
);
620 if (rc
== -EOPNOTSUPP
) {
622 "server does not support query network interfaces\n");
624 } else if (rc
!= 0) {
625 cifs_tcon_dbg(VFS
, "error %d on ioctl to get interface list\n", rc
);
629 rc
= parse_server_interfaces(out_buf
, ret_data_len
,
630 &iface_list
, &iface_count
);
634 /* sort interfaces from fastest to slowest */
635 sort(iface_list
, iface_count
, sizeof(*iface_list
), compare_iface
, NULL
);
637 spin_lock(&ses
->iface_lock
);
638 kfree(ses
->iface_list
);
639 ses
->iface_list
= iface_list
;
640 ses
->iface_count
= iface_count
;
641 ses
->iface_last_update
= jiffies
;
642 spin_unlock(&ses
->iface_lock
);
650 smb2_close_cached_fid(struct kref
*ref
)
652 struct cached_fid
*cfid
= container_of(ref
, struct cached_fid
,
655 if (cfid
->is_valid
) {
656 cifs_dbg(FYI
, "clear cached root file handle\n");
657 SMB2_close(0, cfid
->tcon
, cfid
->fid
->persistent_fid
,
658 cfid
->fid
->volatile_fid
);
659 cfid
->is_valid
= false;
660 cfid
->file_all_info_is_valid
= false;
661 cfid
->has_lease
= false;
665 void close_shroot(struct cached_fid
*cfid
)
667 mutex_lock(&cfid
->fid_mutex
);
668 kref_put(&cfid
->refcount
, smb2_close_cached_fid
);
669 mutex_unlock(&cfid
->fid_mutex
);
672 void close_shroot_lease_locked(struct cached_fid
*cfid
)
674 if (cfid
->has_lease
) {
675 cfid
->has_lease
= false;
676 kref_put(&cfid
->refcount
, smb2_close_cached_fid
);
680 void close_shroot_lease(struct cached_fid
*cfid
)
682 mutex_lock(&cfid
->fid_mutex
);
683 close_shroot_lease_locked(cfid
);
684 mutex_unlock(&cfid
->fid_mutex
);
688 smb2_cached_lease_break(struct work_struct
*work
)
690 struct cached_fid
*cfid
= container_of(work
,
691 struct cached_fid
, lease_break
);
693 close_shroot_lease(cfid
);
697 * Open the directory at the root of a share
699 int open_shroot(unsigned int xid
, struct cifs_tcon
*tcon
,
700 struct cifs_sb_info
*cifs_sb
,
701 struct cached_fid
**cfid
)
703 struct cifs_ses
*ses
= tcon
->ses
;
704 struct TCP_Server_Info
*server
= ses
->server
;
705 struct cifs_open_parms oparms
;
706 struct smb2_create_rsp
*o_rsp
= NULL
;
707 struct smb2_query_info_rsp
*qi_rsp
= NULL
;
709 struct smb_rqst rqst
[2];
710 struct kvec rsp_iov
[2];
711 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
712 struct kvec qi_iov
[1];
714 __le16 utf16_path
= 0; /* Null - since an open of top of share */
715 u8 oplock
= SMB2_OPLOCK_LEVEL_II
;
716 struct cifs_fid
*pfid
;
718 mutex_lock(&tcon
->crfid
.fid_mutex
);
719 if (tcon
->crfid
.is_valid
) {
720 cifs_dbg(FYI
, "found a cached root file handle\n");
721 *cfid
= &tcon
->crfid
;
722 kref_get(&tcon
->crfid
.refcount
);
723 mutex_unlock(&tcon
->crfid
.fid_mutex
);
728 * We do not hold the lock for the open because in case
729 * SMB2_open needs to reconnect, it will end up calling
730 * cifs_mark_open_files_invalid() which takes the lock again
731 * thus causing a deadlock
734 mutex_unlock(&tcon
->crfid
.fid_mutex
);
736 if (smb3_encryption_required(tcon
))
737 flags
|= CIFS_TRANSFORM_REQ
;
739 if (!server
->ops
->new_lease_key
)
742 pfid
= tcon
->crfid
.fid
;
743 server
->ops
->new_lease_key(pfid
);
745 memset(rqst
, 0, sizeof(rqst
));
746 resp_buftype
[0] = resp_buftype
[1] = CIFS_NO_BUFFER
;
747 memset(rsp_iov
, 0, sizeof(rsp_iov
));
750 memset(&open_iov
, 0, sizeof(open_iov
));
751 rqst
[0].rq_iov
= open_iov
;
752 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
755 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
756 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
757 oparms
.disposition
= FILE_OPEN
;
759 oparms
.reconnect
= false;
761 rc
= SMB2_open_init(tcon
, server
,
762 &rqst
[0], &oplock
, &oparms
, &utf16_path
);
765 smb2_set_next_command(tcon
, &rqst
[0]);
767 memset(&qi_iov
, 0, sizeof(qi_iov
));
768 rqst
[1].rq_iov
= qi_iov
;
771 rc
= SMB2_query_info_init(tcon
, server
,
772 &rqst
[1], COMPOUND_FID
,
773 COMPOUND_FID
, FILE_ALL_INFORMATION
,
775 sizeof(struct smb2_file_all_info
) +
776 PATH_MAX
* 2, 0, NULL
);
780 smb2_set_related(&rqst
[1]);
782 rc
= compound_send_recv(xid
, ses
, server
,
784 resp_buftype
, rsp_iov
);
785 mutex_lock(&tcon
->crfid
.fid_mutex
);
788 * Now we need to check again as the cached root might have
789 * been successfully re-opened from a concurrent process
792 if (tcon
->crfid
.is_valid
) {
793 /* work was already done */
795 /* stash fids for close() later */
796 struct cifs_fid fid
= {
797 .persistent_fid
= pfid
->persistent_fid
,
798 .volatile_fid
= pfid
->volatile_fid
,
802 * caller expects this func to set pfid to a valid
803 * cached root, so we copy the existing one and get a
806 memcpy(pfid
, tcon
->crfid
.fid
, sizeof(*pfid
));
807 kref_get(&tcon
->crfid
.refcount
);
809 mutex_unlock(&tcon
->crfid
.fid_mutex
);
812 /* close extra handle outside of crit sec */
813 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
819 /* Cached root is still invalid, continue normaly */
822 if (rc
== -EREMCHG
) {
823 tcon
->need_reconnect
= true;
824 pr_warn_once("server share %s deleted\n",
830 atomic_inc(&tcon
->num_remote_opens
);
832 o_rsp
= (struct smb2_create_rsp
*)rsp_iov
[0].iov_base
;
833 oparms
.fid
->persistent_fid
= o_rsp
->PersistentFileId
;
834 oparms
.fid
->volatile_fid
= o_rsp
->VolatileFileId
;
835 #ifdef CONFIG_CIFS_DEBUG2
836 oparms
.fid
->mid
= le64_to_cpu(o_rsp
->sync_hdr
.MessageId
);
837 #endif /* CIFS_DEBUG2 */
839 memcpy(tcon
->crfid
.fid
, pfid
, sizeof(struct cifs_fid
));
840 tcon
->crfid
.tcon
= tcon
;
841 tcon
->crfid
.is_valid
= true;
842 kref_init(&tcon
->crfid
.refcount
);
844 /* BB TBD check to see if oplock level check can be removed below */
845 if (o_rsp
->OplockLevel
== SMB2_OPLOCK_LEVEL_LEASE
) {
846 kref_get(&tcon
->crfid
.refcount
);
847 tcon
->crfid
.has_lease
= true;
848 smb2_parse_contexts(server
, o_rsp
,
850 oparms
.fid
->lease_key
, &oplock
,
855 qi_rsp
= (struct smb2_query_info_rsp
*)rsp_iov
[1].iov_base
;
856 if (le32_to_cpu(qi_rsp
->OutputBufferLength
) < sizeof(struct smb2_file_all_info
))
858 if (!smb2_validate_and_copy_iov(
859 le16_to_cpu(qi_rsp
->OutputBufferOffset
),
860 sizeof(struct smb2_file_all_info
),
861 &rsp_iov
[1], sizeof(struct smb2_file_all_info
),
862 (char *)&tcon
->crfid
.file_all_info
))
863 tcon
->crfid
.file_all_info_is_valid
= true;
866 mutex_unlock(&tcon
->crfid
.fid_mutex
);
868 SMB2_open_free(&rqst
[0]);
869 SMB2_query_info_free(&rqst
[1]);
870 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
871 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
873 *cfid
= &tcon
->crfid
;
878 smb3_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
,
879 struct cifs_sb_info
*cifs_sb
)
882 __le16 srch_path
= 0; /* Null - open root of share */
883 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
884 struct cifs_open_parms oparms
;
886 bool no_cached_open
= tcon
->nohandlecache
;
887 struct cached_fid
*cfid
= NULL
;
890 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
891 oparms
.disposition
= FILE_OPEN
;
892 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
894 oparms
.reconnect
= false;
896 if (no_cached_open
) {
897 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
,
900 rc
= open_shroot(xid
, tcon
, cifs_sb
, &cfid
);
902 memcpy(&fid
, cfid
->fid
, sizeof(struct cifs_fid
));
907 SMB3_request_interfaces(xid
, tcon
);
909 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
910 FS_ATTRIBUTE_INFORMATION
);
911 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
912 FS_DEVICE_INFORMATION
);
913 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
914 FS_VOLUME_INFORMATION
);
915 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
916 FS_SECTOR_SIZE_INFORMATION
); /* SMB3 specific */
918 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
924 smb2_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
,
925 struct cifs_sb_info
*cifs_sb
)
928 __le16 srch_path
= 0; /* Null - open root of share */
929 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
930 struct cifs_open_parms oparms
;
934 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
935 oparms
.disposition
= FILE_OPEN
;
936 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
938 oparms
.reconnect
= false;
940 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
,
945 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
946 FS_ATTRIBUTE_INFORMATION
);
947 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
948 FS_DEVICE_INFORMATION
);
949 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
953 smb2_is_path_accessible(const unsigned int xid
, struct cifs_tcon
*tcon
,
954 struct cifs_sb_info
*cifs_sb
, const char *full_path
)
958 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
959 struct cifs_open_parms oparms
;
962 if ((*full_path
== 0) && tcon
->crfid
.is_valid
)
965 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
970 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
971 oparms
.disposition
= FILE_OPEN
;
972 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
974 oparms
.reconnect
= false;
976 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
, NULL
,
983 rc
= SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
989 smb2_get_srv_inum(const unsigned int xid
, struct cifs_tcon
*tcon
,
990 struct cifs_sb_info
*cifs_sb
, const char *full_path
,
991 u64
*uniqueid
, FILE_ALL_INFO
*data
)
993 *uniqueid
= le64_to_cpu(data
->IndexNumber
);
998 smb2_query_file_info(const unsigned int xid
, struct cifs_tcon
*tcon
,
999 struct cifs_fid
*fid
, FILE_ALL_INFO
*data
)
1002 struct smb2_file_all_info
*smb2_data
;
1004 smb2_data
= kzalloc(sizeof(struct smb2_file_all_info
) + PATH_MAX
* 2,
1006 if (smb2_data
== NULL
)
1009 rc
= SMB2_query_info(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
,
1012 move_smb2_info_to_cifs(data
, smb2_data
);
1017 #ifdef CONFIG_CIFS_XATTR
1019 move_smb2_ea_to_cifs(char *dst
, size_t dst_size
,
1020 struct smb2_file_full_ea_info
*src
, size_t src_size
,
1021 const unsigned char *ea_name
)
1024 unsigned int ea_name_len
= ea_name
? strlen(ea_name
) : 0;
1026 size_t buf_size
= dst_size
;
1027 size_t name_len
, value_len
, user_name_len
;
1029 while (src_size
> 0) {
1030 name
= &src
->ea_data
[0];
1031 name_len
= (size_t)src
->ea_name_length
;
1032 value
= &src
->ea_data
[src
->ea_name_length
+ 1];
1033 value_len
= (size_t)le16_to_cpu(src
->ea_value_length
);
1038 if (src_size
< 8 + name_len
+ 1 + value_len
) {
1039 cifs_dbg(FYI
, "EA entry goes beyond length of list\n");
1045 if (ea_name_len
== name_len
&&
1046 memcmp(ea_name
, name
, name_len
) == 0) {
1050 if (dst_size
< value_len
) {
1054 memcpy(dst
, value
, value_len
);
1058 /* 'user.' plus a terminating null */
1059 user_name_len
= 5 + 1 + name_len
;
1061 if (buf_size
== 0) {
1062 /* skip copy - calc size only */
1063 rc
+= user_name_len
;
1064 } else if (dst_size
>= user_name_len
) {
1065 dst_size
-= user_name_len
;
1066 memcpy(dst
, "user.", 5);
1068 memcpy(dst
, src
->ea_data
, name_len
);
1072 rc
+= user_name_len
;
1074 /* stop before overrun buffer */
1080 if (!src
->next_entry_offset
)
1083 if (src_size
< le32_to_cpu(src
->next_entry_offset
)) {
1084 /* stop before overrun buffer */
1088 src_size
-= le32_to_cpu(src
->next_entry_offset
);
1089 src
= (void *)((char *)src
+
1090 le32_to_cpu(src
->next_entry_offset
));
1093 /* didn't find the named attribute */
1102 smb2_query_eas(const unsigned int xid
, struct cifs_tcon
*tcon
,
1103 const unsigned char *path
, const unsigned char *ea_name
,
1104 char *ea_data
, size_t buf_size
,
1105 struct cifs_sb_info
*cifs_sb
)
1109 struct kvec rsp_iov
= {NULL
, 0};
1110 int buftype
= CIFS_NO_BUFFER
;
1111 struct smb2_query_info_rsp
*rsp
;
1112 struct smb2_file_full_ea_info
*info
= NULL
;
1114 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
1118 rc
= smb2_query_info_compound(xid
, tcon
, utf16_path
,
1120 FILE_FULL_EA_INFORMATION
,
1123 MAX_SMB2_CREATE_RESPONSE_SIZE
-
1124 MAX_SMB2_CLOSE_RESPONSE_SIZE
,
1125 &rsp_iov
, &buftype
, cifs_sb
);
1128 * If ea_name is NULL (listxattr) and there are no EAs,
1129 * return 0 as it's not an error. Otherwise, the specified
1130 * ea_name was not found.
1132 if (!ea_name
&& rc
== -ENODATA
)
1137 rsp
= (struct smb2_query_info_rsp
*)rsp_iov
.iov_base
;
1138 rc
= smb2_validate_iov(le16_to_cpu(rsp
->OutputBufferOffset
),
1139 le32_to_cpu(rsp
->OutputBufferLength
),
1141 sizeof(struct smb2_file_full_ea_info
));
1145 info
= (struct smb2_file_full_ea_info
*)(
1146 le16_to_cpu(rsp
->OutputBufferOffset
) + (char *)rsp
);
1147 rc
= move_smb2_ea_to_cifs(ea_data
, buf_size
, info
,
1148 le32_to_cpu(rsp
->OutputBufferLength
), ea_name
);
1152 free_rsp_buf(buftype
, rsp_iov
.iov_base
);
1158 smb2_set_ea(const unsigned int xid
, struct cifs_tcon
*tcon
,
1159 const char *path
, const char *ea_name
, const void *ea_value
,
1160 const __u16 ea_value_len
, const struct nls_table
*nls_codepage
,
1161 struct cifs_sb_info
*cifs_sb
)
1163 struct cifs_ses
*ses
= tcon
->ses
;
1164 struct TCP_Server_Info
*server
= cifs_pick_channel(ses
);
1165 __le16
*utf16_path
= NULL
;
1166 int ea_name_len
= strlen(ea_name
);
1169 struct smb_rqst rqst
[3];
1170 int resp_buftype
[3];
1171 struct kvec rsp_iov
[3];
1172 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
1173 struct cifs_open_parms oparms
;
1174 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1175 struct cifs_fid fid
;
1176 struct kvec si_iov
[SMB2_SET_INFO_IOV_SIZE
];
1177 unsigned int size
[1];
1179 struct smb2_file_full_ea_info
*ea
= NULL
;
1180 struct kvec close_iov
[1];
1181 struct smb2_query_info_rsp
*rsp
;
1182 int rc
, used_len
= 0;
1184 if (smb3_encryption_required(tcon
))
1185 flags
|= CIFS_TRANSFORM_REQ
;
1187 if (ea_name_len
> 255)
1190 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
1194 memset(rqst
, 0, sizeof(rqst
));
1195 resp_buftype
[0] = resp_buftype
[1] = resp_buftype
[2] = CIFS_NO_BUFFER
;
1196 memset(rsp_iov
, 0, sizeof(rsp_iov
));
1198 if (ses
->server
->ops
->query_all_EAs
) {
1200 rc
= ses
->server
->ops
->query_all_EAs(xid
, tcon
, path
,
1206 /* If we are adding a attribute we should first check
1207 * if there will be enough space available to store
1208 * the new EA. If not we should not add it since we
1209 * would not be able to even read the EAs back.
1211 rc
= smb2_query_info_compound(xid
, tcon
, utf16_path
,
1213 FILE_FULL_EA_INFORMATION
,
1216 MAX_SMB2_CREATE_RESPONSE_SIZE
-
1217 MAX_SMB2_CLOSE_RESPONSE_SIZE
,
1218 &rsp_iov
[1], &resp_buftype
[1], cifs_sb
);
1220 rsp
= (struct smb2_query_info_rsp
*)rsp_iov
[1].iov_base
;
1221 used_len
= le32_to_cpu(rsp
->OutputBufferLength
);
1223 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
1224 resp_buftype
[1] = CIFS_NO_BUFFER
;
1225 memset(&rsp_iov
[1], 0, sizeof(rsp_iov
[1]));
1228 /* Use a fudge factor of 256 bytes in case we collide
1229 * with a different set_EAs command.
1231 if(CIFSMaxBufSize
- MAX_SMB2_CREATE_RESPONSE_SIZE
-
1232 MAX_SMB2_CLOSE_RESPONSE_SIZE
- 256 <
1233 used_len
+ ea_name_len
+ ea_value_len
+ 1) {
1241 memset(&open_iov
, 0, sizeof(open_iov
));
1242 rqst
[0].rq_iov
= open_iov
;
1243 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
1245 memset(&oparms
, 0, sizeof(oparms
));
1247 oparms
.desired_access
= FILE_WRITE_EA
;
1248 oparms
.disposition
= FILE_OPEN
;
1249 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
1251 oparms
.reconnect
= false;
1253 rc
= SMB2_open_init(tcon
, server
,
1254 &rqst
[0], &oplock
, &oparms
, utf16_path
);
1257 smb2_set_next_command(tcon
, &rqst
[0]);
1261 memset(&si_iov
, 0, sizeof(si_iov
));
1262 rqst
[1].rq_iov
= si_iov
;
1263 rqst
[1].rq_nvec
= 1;
1265 len
= sizeof(*ea
) + ea_name_len
+ ea_value_len
+ 1;
1266 ea
= kzalloc(len
, GFP_KERNEL
);
1272 ea
->ea_name_length
= ea_name_len
;
1273 ea
->ea_value_length
= cpu_to_le16(ea_value_len
);
1274 memcpy(ea
->ea_data
, ea_name
, ea_name_len
+ 1);
1275 memcpy(ea
->ea_data
+ ea_name_len
+ 1, ea_value
, ea_value_len
);
1280 rc
= SMB2_set_info_init(tcon
, server
,
1281 &rqst
[1], COMPOUND_FID
,
1282 COMPOUND_FID
, current
->tgid
,
1283 FILE_FULL_EA_INFORMATION
,
1284 SMB2_O_INFO_FILE
, 0, data
, size
);
1285 smb2_set_next_command(tcon
, &rqst
[1]);
1286 smb2_set_related(&rqst
[1]);
1290 memset(&close_iov
, 0, sizeof(close_iov
));
1291 rqst
[2].rq_iov
= close_iov
;
1292 rqst
[2].rq_nvec
= 1;
1293 rc
= SMB2_close_init(tcon
, server
,
1294 &rqst
[2], COMPOUND_FID
, COMPOUND_FID
, false);
1295 smb2_set_related(&rqst
[2]);
1297 rc
= compound_send_recv(xid
, ses
, server
,
1299 resp_buftype
, rsp_iov
);
1300 /* no need to bump num_remote_opens because handle immediately closed */
1305 SMB2_open_free(&rqst
[0]);
1306 SMB2_set_info_free(&rqst
[1]);
1307 SMB2_close_free(&rqst
[2]);
1308 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
1309 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
1310 free_rsp_buf(resp_buftype
[2], rsp_iov
[2].iov_base
);
1316 smb2_can_echo(struct TCP_Server_Info
*server
)
1318 return server
->echoes
;
1322 smb2_clear_stats(struct cifs_tcon
*tcon
)
1326 for (i
= 0; i
< NUMBER_OF_SMB2_COMMANDS
; i
++) {
1327 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_sent
[i
], 0);
1328 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_failed
[i
], 0);
1333 smb2_dump_share_caps(struct seq_file
*m
, struct cifs_tcon
*tcon
)
1335 seq_puts(m
, "\n\tShare Capabilities:");
1336 if (tcon
->capabilities
& SMB2_SHARE_CAP_DFS
)
1337 seq_puts(m
, " DFS,");
1338 if (tcon
->capabilities
& SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY
)
1339 seq_puts(m
, " CONTINUOUS AVAILABILITY,");
1340 if (tcon
->capabilities
& SMB2_SHARE_CAP_SCALEOUT
)
1341 seq_puts(m
, " SCALEOUT,");
1342 if (tcon
->capabilities
& SMB2_SHARE_CAP_CLUSTER
)
1343 seq_puts(m
, " CLUSTER,");
1344 if (tcon
->capabilities
& SMB2_SHARE_CAP_ASYMMETRIC
)
1345 seq_puts(m
, " ASYMMETRIC,");
1346 if (tcon
->capabilities
== 0)
1347 seq_puts(m
, " None");
1348 if (tcon
->ss_flags
& SSINFO_FLAGS_ALIGNED_DEVICE
)
1349 seq_puts(m
, " Aligned,");
1350 if (tcon
->ss_flags
& SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE
)
1351 seq_puts(m
, " Partition Aligned,");
1352 if (tcon
->ss_flags
& SSINFO_FLAGS_NO_SEEK_PENALTY
)
1353 seq_puts(m
, " SSD,");
1354 if (tcon
->ss_flags
& SSINFO_FLAGS_TRIM_ENABLED
)
1355 seq_puts(m
, " TRIM-support,");
1357 seq_printf(m
, "\tShare Flags: 0x%x", tcon
->share_flags
);
1358 seq_printf(m
, "\n\ttid: 0x%x", tcon
->tid
);
1359 if (tcon
->perf_sector_size
)
1360 seq_printf(m
, "\tOptimal sector size: 0x%x",
1361 tcon
->perf_sector_size
);
1362 seq_printf(m
, "\tMaximal Access: 0x%x", tcon
->maximal_access
);
1366 smb2_print_stats(struct seq_file
*m
, struct cifs_tcon
*tcon
)
1368 atomic_t
*sent
= tcon
->stats
.smb2_stats
.smb2_com_sent
;
1369 atomic_t
*failed
= tcon
->stats
.smb2_stats
.smb2_com_failed
;
1372 * Can't display SMB2_NEGOTIATE, SESSION_SETUP, LOGOFF, CANCEL and ECHO
1373 * totals (requests sent) since those SMBs are per-session not per tcon
1375 seq_printf(m
, "\nBytes read: %llu Bytes written: %llu",
1376 (long long)(tcon
->bytes_read
),
1377 (long long)(tcon
->bytes_written
));
1378 seq_printf(m
, "\nOpen files: %d total (local), %d open on server",
1379 atomic_read(&tcon
->num_local_opens
),
1380 atomic_read(&tcon
->num_remote_opens
));
1381 seq_printf(m
, "\nTreeConnects: %d total %d failed",
1382 atomic_read(&sent
[SMB2_TREE_CONNECT_HE
]),
1383 atomic_read(&failed
[SMB2_TREE_CONNECT_HE
]));
1384 seq_printf(m
, "\nTreeDisconnects: %d total %d failed",
1385 atomic_read(&sent
[SMB2_TREE_DISCONNECT_HE
]),
1386 atomic_read(&failed
[SMB2_TREE_DISCONNECT_HE
]));
1387 seq_printf(m
, "\nCreates: %d total %d failed",
1388 atomic_read(&sent
[SMB2_CREATE_HE
]),
1389 atomic_read(&failed
[SMB2_CREATE_HE
]));
1390 seq_printf(m
, "\nCloses: %d total %d failed",
1391 atomic_read(&sent
[SMB2_CLOSE_HE
]),
1392 atomic_read(&failed
[SMB2_CLOSE_HE
]));
1393 seq_printf(m
, "\nFlushes: %d total %d failed",
1394 atomic_read(&sent
[SMB2_FLUSH_HE
]),
1395 atomic_read(&failed
[SMB2_FLUSH_HE
]));
1396 seq_printf(m
, "\nReads: %d total %d failed",
1397 atomic_read(&sent
[SMB2_READ_HE
]),
1398 atomic_read(&failed
[SMB2_READ_HE
]));
1399 seq_printf(m
, "\nWrites: %d total %d failed",
1400 atomic_read(&sent
[SMB2_WRITE_HE
]),
1401 atomic_read(&failed
[SMB2_WRITE_HE
]));
1402 seq_printf(m
, "\nLocks: %d total %d failed",
1403 atomic_read(&sent
[SMB2_LOCK_HE
]),
1404 atomic_read(&failed
[SMB2_LOCK_HE
]));
1405 seq_printf(m
, "\nIOCTLs: %d total %d failed",
1406 atomic_read(&sent
[SMB2_IOCTL_HE
]),
1407 atomic_read(&failed
[SMB2_IOCTL_HE
]));
1408 seq_printf(m
, "\nQueryDirectories: %d total %d failed",
1409 atomic_read(&sent
[SMB2_QUERY_DIRECTORY_HE
]),
1410 atomic_read(&failed
[SMB2_QUERY_DIRECTORY_HE
]));
1411 seq_printf(m
, "\nChangeNotifies: %d total %d failed",
1412 atomic_read(&sent
[SMB2_CHANGE_NOTIFY_HE
]),
1413 atomic_read(&failed
[SMB2_CHANGE_NOTIFY_HE
]));
1414 seq_printf(m
, "\nQueryInfos: %d total %d failed",
1415 atomic_read(&sent
[SMB2_QUERY_INFO_HE
]),
1416 atomic_read(&failed
[SMB2_QUERY_INFO_HE
]));
1417 seq_printf(m
, "\nSetInfos: %d total %d failed",
1418 atomic_read(&sent
[SMB2_SET_INFO_HE
]),
1419 atomic_read(&failed
[SMB2_SET_INFO_HE
]));
1420 seq_printf(m
, "\nOplockBreaks: %d sent %d failed",
1421 atomic_read(&sent
[SMB2_OPLOCK_BREAK_HE
]),
1422 atomic_read(&failed
[SMB2_OPLOCK_BREAK_HE
]));
1426 smb2_set_fid(struct cifsFileInfo
*cfile
, struct cifs_fid
*fid
, __u32 oplock
)
1428 struct cifsInodeInfo
*cinode
= CIFS_I(d_inode(cfile
->dentry
));
1429 struct TCP_Server_Info
*server
= tlink_tcon(cfile
->tlink
)->ses
->server
;
1431 cfile
->fid
.persistent_fid
= fid
->persistent_fid
;
1432 cfile
->fid
.volatile_fid
= fid
->volatile_fid
;
1433 cfile
->fid
.access
= fid
->access
;
1434 #ifdef CONFIG_CIFS_DEBUG2
1435 cfile
->fid
.mid
= fid
->mid
;
1436 #endif /* CIFS_DEBUG2 */
1437 server
->ops
->set_oplock_level(cinode
, oplock
, fid
->epoch
,
1439 cinode
->can_cache_brlcks
= CIFS_CACHE_WRITE(cinode
);
1440 memcpy(cfile
->fid
.create_guid
, fid
->create_guid
, 16);
1444 smb2_close_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
1445 struct cifs_fid
*fid
)
1447 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1451 smb2_close_getattr(const unsigned int xid
, struct cifs_tcon
*tcon
,
1452 struct cifsFileInfo
*cfile
)
1454 struct smb2_file_network_open_info file_inf
;
1455 struct inode
*inode
;
1458 rc
= __SMB2_close(xid
, tcon
, cfile
->fid
.persistent_fid
,
1459 cfile
->fid
.volatile_fid
, &file_inf
);
1463 inode
= d_inode(cfile
->dentry
);
1465 spin_lock(&inode
->i_lock
);
1466 CIFS_I(inode
)->time
= jiffies
;
1468 /* Creation time should not need to be updated on close */
1469 if (file_inf
.LastWriteTime
)
1470 inode
->i_mtime
= cifs_NTtimeToUnix(file_inf
.LastWriteTime
);
1471 if (file_inf
.ChangeTime
)
1472 inode
->i_ctime
= cifs_NTtimeToUnix(file_inf
.ChangeTime
);
1473 if (file_inf
.LastAccessTime
)
1474 inode
->i_atime
= cifs_NTtimeToUnix(file_inf
.LastAccessTime
);
1477 * i_blocks is not related to (i_size / i_blksize),
1478 * but instead 512 byte (2**9) size is required for
1479 * calculating num blocks.
1481 if (le64_to_cpu(file_inf
.AllocationSize
) > 4096)
1483 (512 - 1 + le64_to_cpu(file_inf
.AllocationSize
)) >> 9;
1485 /* End of file and Attributes should not have to be updated on close */
1486 spin_unlock(&inode
->i_lock
);
1490 SMB2_request_res_key(const unsigned int xid
, struct cifs_tcon
*tcon
,
1491 u64 persistent_fid
, u64 volatile_fid
,
1492 struct copychunk_ioctl
*pcchunk
)
1495 unsigned int ret_data_len
;
1496 struct resume_key_req
*res_key
;
1498 rc
= SMB2_ioctl(xid
, tcon
, persistent_fid
, volatile_fid
,
1499 FSCTL_SRV_REQUEST_RESUME_KEY
, true /* is_fsctl */,
1500 NULL
, 0 /* no input */, CIFSMaxBufSize
,
1501 (char **)&res_key
, &ret_data_len
);
1504 cifs_tcon_dbg(VFS
, "refcpy ioctl error %d getting resume key\n", rc
);
1505 goto req_res_key_exit
;
1507 if (ret_data_len
< sizeof(struct resume_key_req
)) {
1508 cifs_tcon_dbg(VFS
, "Invalid refcopy resume key length\n");
1510 goto req_res_key_exit
;
1512 memcpy(pcchunk
->SourceKey
, res_key
->ResumeKey
, COPY_CHUNK_RES_KEY_SIZE
);
1520 struct smb_rqst rqst
[3];
1521 struct kvec rsp_iov
[3];
1522 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
1523 struct kvec qi_iov
[1];
1524 struct kvec io_iov
[SMB2_IOCTL_IOV_SIZE
];
1525 struct kvec si_iov
[SMB2_SET_INFO_IOV_SIZE
];
1526 struct kvec close_iov
[1];
1530 smb2_ioctl_query_info(const unsigned int xid
,
1531 struct cifs_tcon
*tcon
,
1532 struct cifs_sb_info
*cifs_sb
,
1533 __le16
*path
, int is_dir
,
1536 struct iqi_vars
*vars
;
1537 struct smb_rqst
*rqst
;
1538 struct kvec
*rsp_iov
;
1539 struct cifs_ses
*ses
= tcon
->ses
;
1540 struct TCP_Server_Info
*server
= cifs_pick_channel(ses
);
1541 char __user
*arg
= (char __user
*)p
;
1542 struct smb_query_info qi
;
1543 struct smb_query_info __user
*pqi
;
1546 struct smb2_query_info_rsp
*qi_rsp
= NULL
;
1547 struct smb2_ioctl_rsp
*io_rsp
= NULL
;
1548 void *buffer
= NULL
;
1549 int resp_buftype
[3];
1550 struct cifs_open_parms oparms
;
1551 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1552 struct cifs_fid fid
;
1553 unsigned int size
[2];
1555 int create_options
= is_dir
? CREATE_NOT_FILE
: CREATE_NOT_DIR
;
1557 vars
= kzalloc(sizeof(*vars
), GFP_ATOMIC
);
1560 rqst
= &vars
->rqst
[0];
1561 rsp_iov
= &vars
->rsp_iov
[0];
1563 resp_buftype
[0] = resp_buftype
[1] = resp_buftype
[2] = CIFS_NO_BUFFER
;
1565 if (copy_from_user(&qi
, arg
, sizeof(struct smb_query_info
)))
1568 if (qi
.output_buffer_length
> 1024) {
1573 if (!ses
|| !server
) {
1578 if (smb3_encryption_required(tcon
))
1579 flags
|= CIFS_TRANSFORM_REQ
;
1581 buffer
= memdup_user(arg
+ sizeof(struct smb_query_info
),
1582 qi
.output_buffer_length
);
1583 if (IS_ERR(buffer
)) {
1585 return PTR_ERR(buffer
);
1589 rqst
[0].rq_iov
= &vars
->open_iov
[0];
1590 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
1592 memset(&oparms
, 0, sizeof(oparms
));
1594 oparms
.disposition
= FILE_OPEN
;
1595 oparms
.create_options
= cifs_create_options(cifs_sb
, create_options
);
1597 oparms
.reconnect
= false;
1599 if (qi
.flags
& PASSTHRU_FSCTL
) {
1600 switch (qi
.info_type
& FSCTL_DEVICE_ACCESS_MASK
) {
1601 case FSCTL_DEVICE_ACCESS_FILE_READ_WRITE_ACCESS
:
1602 oparms
.desired_access
= FILE_READ_DATA
| FILE_WRITE_DATA
| FILE_READ_ATTRIBUTES
| SYNCHRONIZE
;
1604 case FSCTL_DEVICE_ACCESS_FILE_ANY_ACCESS
:
1605 oparms
.desired_access
= GENERIC_ALL
;
1607 case FSCTL_DEVICE_ACCESS_FILE_READ_ACCESS
:
1608 oparms
.desired_access
= GENERIC_READ
;
1610 case FSCTL_DEVICE_ACCESS_FILE_WRITE_ACCESS
:
1611 oparms
.desired_access
= GENERIC_WRITE
;
1614 } else if (qi
.flags
& PASSTHRU_SET_INFO
) {
1615 oparms
.desired_access
= GENERIC_WRITE
;
1617 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| READ_CONTROL
;
1620 rc
= SMB2_open_init(tcon
, server
,
1621 &rqst
[0], &oplock
, &oparms
, path
);
1624 smb2_set_next_command(tcon
, &rqst
[0]);
1627 if (qi
.flags
& PASSTHRU_FSCTL
) {
1628 /* Can eventually relax perm check since server enforces too */
1629 if (!capable(CAP_SYS_ADMIN
))
1632 rqst
[1].rq_iov
= &vars
->io_iov
[0];
1633 rqst
[1].rq_nvec
= SMB2_IOCTL_IOV_SIZE
;
1635 rc
= SMB2_ioctl_init(tcon
, server
,
1637 COMPOUND_FID
, COMPOUND_FID
,
1638 qi
.info_type
, true, buffer
,
1639 qi
.output_buffer_length
,
1641 MAX_SMB2_CREATE_RESPONSE_SIZE
-
1642 MAX_SMB2_CLOSE_RESPONSE_SIZE
);
1644 } else if (qi
.flags
== PASSTHRU_SET_INFO
) {
1645 /* Can eventually relax perm check since server enforces too */
1646 if (!capable(CAP_SYS_ADMIN
))
1649 rqst
[1].rq_iov
= &vars
->si_iov
[0];
1650 rqst
[1].rq_nvec
= 1;
1655 rc
= SMB2_set_info_init(tcon
, server
,
1657 COMPOUND_FID
, COMPOUND_FID
,
1659 FILE_END_OF_FILE_INFORMATION
,
1660 SMB2_O_INFO_FILE
, 0, data
, size
);
1662 } else if (qi
.flags
== PASSTHRU_QUERY_INFO
) {
1663 rqst
[1].rq_iov
= &vars
->qi_iov
[0];
1664 rqst
[1].rq_nvec
= 1;
1666 rc
= SMB2_query_info_init(tcon
, server
,
1667 &rqst
[1], COMPOUND_FID
,
1668 COMPOUND_FID
, qi
.file_info_class
,
1669 qi
.info_type
, qi
.additional_information
,
1670 qi
.input_buffer_length
,
1671 qi
.output_buffer_length
, buffer
);
1672 } else { /* unknown flags */
1673 cifs_tcon_dbg(VFS
, "Invalid passthru query flags: 0x%x\n",
1680 smb2_set_next_command(tcon
, &rqst
[1]);
1681 smb2_set_related(&rqst
[1]);
1684 rqst
[2].rq_iov
= &vars
->close_iov
[0];
1685 rqst
[2].rq_nvec
= 1;
1687 rc
= SMB2_close_init(tcon
, server
,
1688 &rqst
[2], COMPOUND_FID
, COMPOUND_FID
, false);
1691 smb2_set_related(&rqst
[2]);
1693 rc
= compound_send_recv(xid
, ses
, server
,
1695 resp_buftype
, rsp_iov
);
1699 /* No need to bump num_remote_opens since handle immediately closed */
1700 if (qi
.flags
& PASSTHRU_FSCTL
) {
1701 pqi
= (struct smb_query_info __user
*)arg
;
1702 io_rsp
= (struct smb2_ioctl_rsp
*)rsp_iov
[1].iov_base
;
1703 if (le32_to_cpu(io_rsp
->OutputCount
) < qi
.input_buffer_length
)
1704 qi
.input_buffer_length
= le32_to_cpu(io_rsp
->OutputCount
);
1705 if (qi
.input_buffer_length
> 0 &&
1706 le32_to_cpu(io_rsp
->OutputOffset
) + qi
.input_buffer_length
1707 > rsp_iov
[1].iov_len
)
1710 if (copy_to_user(&pqi
->input_buffer_length
,
1711 &qi
.input_buffer_length
,
1712 sizeof(qi
.input_buffer_length
)))
1715 if (copy_to_user((void __user
*)pqi
+ sizeof(struct smb_query_info
),
1716 (const void *)io_rsp
+ le32_to_cpu(io_rsp
->OutputOffset
),
1717 qi
.input_buffer_length
))
1720 pqi
= (struct smb_query_info __user
*)arg
;
1721 qi_rsp
= (struct smb2_query_info_rsp
*)rsp_iov
[1].iov_base
;
1722 if (le32_to_cpu(qi_rsp
->OutputBufferLength
) < qi
.input_buffer_length
)
1723 qi
.input_buffer_length
= le32_to_cpu(qi_rsp
->OutputBufferLength
);
1724 if (copy_to_user(&pqi
->input_buffer_length
,
1725 &qi
.input_buffer_length
,
1726 sizeof(qi
.input_buffer_length
)))
1729 if (copy_to_user(pqi
+ 1, qi_rsp
->Buffer
,
1730 qi
.input_buffer_length
))
1737 SMB2_open_free(&rqst
[0]);
1738 if (qi
.flags
& PASSTHRU_FSCTL
)
1739 SMB2_ioctl_free(&rqst
[1]);
1741 SMB2_query_info_free(&rqst
[1]);
1743 SMB2_close_free(&rqst
[2]);
1744 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
1745 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
1746 free_rsp_buf(resp_buftype
[2], rsp_iov
[2].iov_base
);
1755 smb2_copychunk_range(const unsigned int xid
,
1756 struct cifsFileInfo
*srcfile
,
1757 struct cifsFileInfo
*trgtfile
, u64 src_off
,
1758 u64 len
, u64 dest_off
)
1761 unsigned int ret_data_len
;
1762 struct copychunk_ioctl
*pcchunk
;
1763 struct copychunk_ioctl_rsp
*retbuf
= NULL
;
1764 struct cifs_tcon
*tcon
;
1765 int chunks_copied
= 0;
1766 bool chunk_sizes_updated
= false;
1767 ssize_t bytes_written
, total_bytes_written
= 0;
1769 pcchunk
= kmalloc(sizeof(struct copychunk_ioctl
), GFP_KERNEL
);
1771 if (pcchunk
== NULL
)
1774 cifs_dbg(FYI
, "%s: about to call request res key\n", __func__
);
1775 /* Request a key from the server to identify the source of the copy */
1776 rc
= SMB2_request_res_key(xid
, tlink_tcon(srcfile
->tlink
),
1777 srcfile
->fid
.persistent_fid
,
1778 srcfile
->fid
.volatile_fid
, pcchunk
);
1780 /* Note: request_res_key sets res_key null only if rc !=0 */
1784 /* For now array only one chunk long, will make more flexible later */
1785 pcchunk
->ChunkCount
= cpu_to_le32(1);
1786 pcchunk
->Reserved
= 0;
1787 pcchunk
->Reserved2
= 0;
1789 tcon
= tlink_tcon(trgtfile
->tlink
);
1792 pcchunk
->SourceOffset
= cpu_to_le64(src_off
);
1793 pcchunk
->TargetOffset
= cpu_to_le64(dest_off
);
1795 cpu_to_le32(min_t(u32
, len
, tcon
->max_bytes_chunk
));
1797 /* Request server copy to target from src identified by key */
1798 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
1799 trgtfile
->fid
.volatile_fid
, FSCTL_SRV_COPYCHUNK_WRITE
,
1800 true /* is_fsctl */, (char *)pcchunk
,
1801 sizeof(struct copychunk_ioctl
), CIFSMaxBufSize
,
1802 (char **)&retbuf
, &ret_data_len
);
1805 sizeof(struct copychunk_ioctl_rsp
)) {
1806 cifs_tcon_dbg(VFS
, "Invalid cchunk response size\n");
1810 if (retbuf
->TotalBytesWritten
== 0) {
1811 cifs_dbg(FYI
, "no bytes copied\n");
1816 * Check if server claimed to write more than we asked
1818 if (le32_to_cpu(retbuf
->TotalBytesWritten
) >
1819 le32_to_cpu(pcchunk
->Length
)) {
1820 cifs_tcon_dbg(VFS
, "Invalid copy chunk response\n");
1824 if (le32_to_cpu(retbuf
->ChunksWritten
) != 1) {
1825 cifs_tcon_dbg(VFS
, "Invalid num chunks written\n");
1831 bytes_written
= le32_to_cpu(retbuf
->TotalBytesWritten
);
1832 src_off
+= bytes_written
;
1833 dest_off
+= bytes_written
;
1834 len
-= bytes_written
;
1835 total_bytes_written
+= bytes_written
;
1837 cifs_dbg(FYI
, "Chunks %d PartialChunk %d Total %zu\n",
1838 le32_to_cpu(retbuf
->ChunksWritten
),
1839 le32_to_cpu(retbuf
->ChunkBytesWritten
),
1841 } else if (rc
== -EINVAL
) {
1842 if (ret_data_len
!= sizeof(struct copychunk_ioctl_rsp
))
1845 cifs_dbg(FYI
, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
1846 le32_to_cpu(retbuf
->ChunksWritten
),
1847 le32_to_cpu(retbuf
->ChunkBytesWritten
),
1848 le32_to_cpu(retbuf
->TotalBytesWritten
));
1851 * Check if this is the first request using these sizes,
1852 * (ie check if copy succeed once with original sizes
1853 * and check if the server gave us different sizes after
1854 * we already updated max sizes on previous request).
1855 * if not then why is the server returning an error now
1857 if ((chunks_copied
!= 0) || chunk_sizes_updated
)
1860 /* Check that server is not asking us to grow size */
1861 if (le32_to_cpu(retbuf
->ChunkBytesWritten
) <
1862 tcon
->max_bytes_chunk
)
1863 tcon
->max_bytes_chunk
=
1864 le32_to_cpu(retbuf
->ChunkBytesWritten
);
1866 goto cchunk_out
; /* server gave us bogus size */
1868 /* No need to change MaxChunks since already set to 1 */
1869 chunk_sizes_updated
= true;
1880 return total_bytes_written
;
1884 smb2_flush_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
1885 struct cifs_fid
*fid
)
1887 return SMB2_flush(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1891 smb2_read_data_offset(char *buf
)
1893 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
1895 return rsp
->DataOffset
;
1899 smb2_read_data_length(char *buf
, bool in_remaining
)
1901 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
1904 return le32_to_cpu(rsp
->DataRemaining
);
1906 return le32_to_cpu(rsp
->DataLength
);
1911 smb2_sync_read(const unsigned int xid
, struct cifs_fid
*pfid
,
1912 struct cifs_io_parms
*parms
, unsigned int *bytes_read
,
1913 char **buf
, int *buf_type
)
1915 parms
->persistent_fid
= pfid
->persistent_fid
;
1916 parms
->volatile_fid
= pfid
->volatile_fid
;
1917 return SMB2_read(xid
, parms
, bytes_read
, buf
, buf_type
);
1921 smb2_sync_write(const unsigned int xid
, struct cifs_fid
*pfid
,
1922 struct cifs_io_parms
*parms
, unsigned int *written
,
1923 struct kvec
*iov
, unsigned long nr_segs
)
1926 parms
->persistent_fid
= pfid
->persistent_fid
;
1927 parms
->volatile_fid
= pfid
->volatile_fid
;
1928 return SMB2_write(xid
, parms
, written
, iov
, nr_segs
);
1931 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
1932 static bool smb2_set_sparse(const unsigned int xid
, struct cifs_tcon
*tcon
,
1933 struct cifsFileInfo
*cfile
, struct inode
*inode
, __u8 setsparse
)
1935 struct cifsInodeInfo
*cifsi
;
1938 cifsi
= CIFS_I(inode
);
1940 /* if file already sparse don't bother setting sparse again */
1941 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && setsparse
)
1942 return true; /* already sparse */
1944 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && !setsparse
)
1945 return true; /* already not sparse */
1948 * Can't check for sparse support on share the usual way via the
1949 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
1950 * since Samba server doesn't set the flag on the share, yet
1951 * supports the set sparse FSCTL and returns sparse correctly
1952 * in the file attributes. If we fail setting sparse though we
1953 * mark that server does not support sparse files for this share
1954 * to avoid repeatedly sending the unsupported fsctl to server
1955 * if the file is repeatedly extended.
1957 if (tcon
->broken_sparse_sup
)
1960 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1961 cfile
->fid
.volatile_fid
, FSCTL_SET_SPARSE
,
1963 &setsparse
, 1, CIFSMaxBufSize
, NULL
, NULL
);
1965 tcon
->broken_sparse_sup
= true;
1966 cifs_dbg(FYI
, "set sparse rc = %d\n", rc
);
1971 cifsi
->cifsAttrs
|= FILE_ATTRIBUTE_SPARSE_FILE
;
1973 cifsi
->cifsAttrs
&= (~FILE_ATTRIBUTE_SPARSE_FILE
);
1979 smb2_set_file_size(const unsigned int xid
, struct cifs_tcon
*tcon
,
1980 struct cifsFileInfo
*cfile
, __u64 size
, bool set_alloc
)
1982 __le64 eof
= cpu_to_le64(size
);
1983 struct inode
*inode
;
1986 * If extending file more than one page make sparse. Many Linux fs
1987 * make files sparse by default when extending via ftruncate
1989 inode
= d_inode(cfile
->dentry
);
1991 if (!set_alloc
&& (size
> inode
->i_size
+ 8192)) {
1992 __u8 set_sparse
= 1;
1994 /* whether set sparse succeeds or not, extend the file */
1995 smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
);
1998 return SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
1999 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
);
2003 smb2_duplicate_extents(const unsigned int xid
,
2004 struct cifsFileInfo
*srcfile
,
2005 struct cifsFileInfo
*trgtfile
, u64 src_off
,
2006 u64 len
, u64 dest_off
)
2009 unsigned int ret_data_len
;
2010 struct duplicate_extents_to_file dup_ext_buf
;
2011 struct cifs_tcon
*tcon
= tlink_tcon(trgtfile
->tlink
);
2013 /* server fileays advertise duplicate extent support with this flag */
2014 if ((le32_to_cpu(tcon
->fsAttrInfo
.Attributes
) &
2015 FILE_SUPPORTS_BLOCK_REFCOUNTING
) == 0)
2018 dup_ext_buf
.VolatileFileHandle
= srcfile
->fid
.volatile_fid
;
2019 dup_ext_buf
.PersistentFileHandle
= srcfile
->fid
.persistent_fid
;
2020 dup_ext_buf
.SourceFileOffset
= cpu_to_le64(src_off
);
2021 dup_ext_buf
.TargetFileOffset
= cpu_to_le64(dest_off
);
2022 dup_ext_buf
.ByteCount
= cpu_to_le64(len
);
2023 cifs_dbg(FYI
, "Duplicate extents: src off %lld dst off %lld len %lld\n",
2024 src_off
, dest_off
, len
);
2026 rc
= smb2_set_file_size(xid
, tcon
, trgtfile
, dest_off
+ len
, false);
2028 goto duplicate_extents_out
;
2030 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
2031 trgtfile
->fid
.volatile_fid
,
2032 FSCTL_DUPLICATE_EXTENTS_TO_FILE
,
2033 true /* is_fsctl */,
2034 (char *)&dup_ext_buf
,
2035 sizeof(struct duplicate_extents_to_file
),
2036 CIFSMaxBufSize
, NULL
,
2039 if (ret_data_len
> 0)
2040 cifs_dbg(FYI
, "Non-zero response length in duplicate extents\n");
2042 duplicate_extents_out
:
2047 smb2_set_compression(const unsigned int xid
, struct cifs_tcon
*tcon
,
2048 struct cifsFileInfo
*cfile
)
2050 return SMB2_set_compression(xid
, tcon
, cfile
->fid
.persistent_fid
,
2051 cfile
->fid
.volatile_fid
);
2055 smb3_set_integrity(const unsigned int xid
, struct cifs_tcon
*tcon
,
2056 struct cifsFileInfo
*cfile
)
2058 struct fsctl_set_integrity_information_req integr_info
;
2059 unsigned int ret_data_len
;
2061 integr_info
.ChecksumAlgorithm
= cpu_to_le16(CHECKSUM_TYPE_UNCHANGED
);
2062 integr_info
.Flags
= 0;
2063 integr_info
.Reserved
= 0;
2065 return SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
2066 cfile
->fid
.volatile_fid
,
2067 FSCTL_SET_INTEGRITY_INFORMATION
,
2068 true /* is_fsctl */,
2069 (char *)&integr_info
,
2070 sizeof(struct fsctl_set_integrity_information_req
),
2071 CIFSMaxBufSize
, NULL
,
2076 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
2077 #define GMT_TOKEN_SIZE 50
2079 #define MIN_SNAPSHOT_ARRAY_SIZE 16 /* See MS-SMB2 section 3.3.5.15.1 */
2082 * Input buffer contains (empty) struct smb_snapshot array with size filled in
2083 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
2086 smb3_enum_snapshots(const unsigned int xid
, struct cifs_tcon
*tcon
,
2087 struct cifsFileInfo
*cfile
, void __user
*ioc_buf
)
2089 char *retbuf
= NULL
;
2090 unsigned int ret_data_len
= 0;
2092 u32 max_response_size
;
2093 struct smb_snapshot_array snapshot_in
;
2096 * On the first query to enumerate the list of snapshots available
2097 * for this volume the buffer begins with 0 (number of snapshots
2098 * which can be returned is zero since at that point we do not know
2099 * how big the buffer needs to be). On the second query,
2100 * it (ret_data_len) is set to number of snapshots so we can
2101 * know to set the maximum response size larger (see below).
2103 if (get_user(ret_data_len
, (unsigned int __user
*)ioc_buf
))
2107 * Note that for snapshot queries that servers like Azure expect that
2108 * the first query be minimal size (and just used to get the number/size
2109 * of previous versions) so response size must be specified as EXACTLY
2110 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple
2113 if (ret_data_len
== 0)
2114 max_response_size
= MIN_SNAPSHOT_ARRAY_SIZE
;
2116 max_response_size
= CIFSMaxBufSize
;
2118 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
2119 cfile
->fid
.volatile_fid
,
2120 FSCTL_SRV_ENUMERATE_SNAPSHOTS
,
2121 true /* is_fsctl */,
2122 NULL
, 0 /* no input data */, max_response_size
,
2125 cifs_dbg(FYI
, "enum snaphots ioctl returned %d and ret buflen is %d\n",
2130 if (ret_data_len
&& (ioc_buf
!= NULL
) && (retbuf
!= NULL
)) {
2132 if (copy_from_user(&snapshot_in
, ioc_buf
,
2133 sizeof(struct smb_snapshot_array
))) {
2140 * Check for min size, ie not large enough to fit even one GMT
2141 * token (snapshot). On the first ioctl some users may pass in
2142 * smaller size (or zero) to simply get the size of the array
2143 * so the user space caller can allocate sufficient memory
2144 * and retry the ioctl again with larger array size sufficient
2145 * to hold all of the snapshot GMT tokens on the second try.
2147 if (snapshot_in
.snapshot_array_size
< GMT_TOKEN_SIZE
)
2148 ret_data_len
= sizeof(struct smb_snapshot_array
);
2151 * We return struct SRV_SNAPSHOT_ARRAY, followed by
2152 * the snapshot array (of 50 byte GMT tokens) each
2153 * representing an available previous version of the data
2155 if (ret_data_len
> (snapshot_in
.snapshot_array_size
+
2156 sizeof(struct smb_snapshot_array
)))
2157 ret_data_len
= snapshot_in
.snapshot_array_size
+
2158 sizeof(struct smb_snapshot_array
);
2160 if (copy_to_user(ioc_buf
, retbuf
, ret_data_len
))
2171 smb3_notify(const unsigned int xid
, struct file
*pfile
,
2172 void __user
*ioc_buf
)
2174 struct smb3_notify notify
;
2175 struct dentry
*dentry
= pfile
->f_path
.dentry
;
2176 struct inode
*inode
= file_inode(pfile
);
2177 struct cifs_sb_info
*cifs_sb
;
2178 struct cifs_open_parms oparms
;
2179 struct cifs_fid fid
;
2180 struct cifs_tcon
*tcon
;
2181 unsigned char *path
= NULL
;
2182 __le16
*utf16_path
= NULL
;
2183 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
2186 path
= build_path_from_dentry(dentry
);
2190 cifs_sb
= CIFS_SB(inode
->i_sb
);
2192 utf16_path
= cifs_convert_path_to_utf16(path
+ 1, cifs_sb
);
2193 if (utf16_path
== NULL
) {
2198 if (copy_from_user(¬ify
, ioc_buf
, sizeof(struct smb3_notify
))) {
2203 tcon
= cifs_sb_master_tcon(cifs_sb
);
2205 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| FILE_READ_DATA
;
2206 oparms
.disposition
= FILE_OPEN
;
2207 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
2209 oparms
.reconnect
= false;
2211 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
, NULL
,
2216 rc
= SMB2_change_notify(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
2217 notify
.watch_tree
, notify
.completion_filter
);
2219 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
2221 cifs_dbg(FYI
, "change notify for path %s rc %d\n", path
, rc
);
2230 smb2_query_dir_first(const unsigned int xid
, struct cifs_tcon
*tcon
,
2231 const char *path
, struct cifs_sb_info
*cifs_sb
,
2232 struct cifs_fid
*fid
, __u16 search_flags
,
2233 struct cifs_search_info
*srch_inf
)
2236 struct smb_rqst rqst
[2];
2237 struct kvec rsp_iov
[2];
2238 int resp_buftype
[2];
2239 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
2240 struct kvec qd_iov
[SMB2_QUERY_DIRECTORY_IOV_SIZE
];
2242 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
2243 struct cifs_open_parms oparms
;
2244 struct smb2_query_directory_rsp
*qd_rsp
= NULL
;
2245 struct smb2_create_rsp
*op_rsp
= NULL
;
2246 struct TCP_Server_Info
*server
= cifs_pick_channel(tcon
->ses
);
2248 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
2252 if (smb3_encryption_required(tcon
))
2253 flags
|= CIFS_TRANSFORM_REQ
;
2255 memset(rqst
, 0, sizeof(rqst
));
2256 resp_buftype
[0] = resp_buftype
[1] = CIFS_NO_BUFFER
;
2257 memset(rsp_iov
, 0, sizeof(rsp_iov
));
2260 memset(&open_iov
, 0, sizeof(open_iov
));
2261 rqst
[0].rq_iov
= open_iov
;
2262 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
2265 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| FILE_READ_DATA
;
2266 oparms
.disposition
= FILE_OPEN
;
2267 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
2269 oparms
.reconnect
= false;
2271 rc
= SMB2_open_init(tcon
, server
,
2272 &rqst
[0], &oplock
, &oparms
, utf16_path
);
2275 smb2_set_next_command(tcon
, &rqst
[0]);
2277 /* Query directory */
2278 srch_inf
->entries_in_buffer
= 0;
2279 srch_inf
->index_of_last_entry
= 2;
2281 memset(&qd_iov
, 0, sizeof(qd_iov
));
2282 rqst
[1].rq_iov
= qd_iov
;
2283 rqst
[1].rq_nvec
= SMB2_QUERY_DIRECTORY_IOV_SIZE
;
2285 rc
= SMB2_query_directory_init(xid
, tcon
, server
,
2287 COMPOUND_FID
, COMPOUND_FID
,
2288 0, srch_inf
->info_level
);
2292 smb2_set_related(&rqst
[1]);
2294 rc
= compound_send_recv(xid
, tcon
->ses
, server
,
2296 resp_buftype
, rsp_iov
);
2298 /* If the open failed there is nothing to do */
2299 op_rsp
= (struct smb2_create_rsp
*)rsp_iov
[0].iov_base
;
2300 if (op_rsp
== NULL
|| op_rsp
->sync_hdr
.Status
!= STATUS_SUCCESS
) {
2301 cifs_dbg(FYI
, "query_dir_first: open failed rc=%d\n", rc
);
2304 fid
->persistent_fid
= op_rsp
->PersistentFileId
;
2305 fid
->volatile_fid
= op_rsp
->VolatileFileId
;
2307 /* Anything else than ENODATA means a genuine error */
2308 if (rc
&& rc
!= -ENODATA
) {
2309 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
2310 cifs_dbg(FYI
, "query_dir_first: query directory failed rc=%d\n", rc
);
2311 trace_smb3_query_dir_err(xid
, fid
->persistent_fid
,
2312 tcon
->tid
, tcon
->ses
->Suid
, 0, 0, rc
);
2316 atomic_inc(&tcon
->num_remote_opens
);
2318 qd_rsp
= (struct smb2_query_directory_rsp
*)rsp_iov
[1].iov_base
;
2319 if (qd_rsp
->sync_hdr
.Status
== STATUS_NO_MORE_FILES
) {
2320 trace_smb3_query_dir_done(xid
, fid
->persistent_fid
,
2321 tcon
->tid
, tcon
->ses
->Suid
, 0, 0);
2322 srch_inf
->endOfSearch
= true;
2327 rc
= smb2_parse_query_directory(tcon
, &rsp_iov
[1], resp_buftype
[1],
2330 trace_smb3_query_dir_err(xid
, fid
->persistent_fid
, tcon
->tid
,
2331 tcon
->ses
->Suid
, 0, 0, rc
);
2334 resp_buftype
[1] = CIFS_NO_BUFFER
;
2336 trace_smb3_query_dir_done(xid
, fid
->persistent_fid
, tcon
->tid
,
2337 tcon
->ses
->Suid
, 0, srch_inf
->entries_in_buffer
);
2341 SMB2_open_free(&rqst
[0]);
2342 SMB2_query_directory_free(&rqst
[1]);
2343 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
2344 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
2349 smb2_query_dir_next(const unsigned int xid
, struct cifs_tcon
*tcon
,
2350 struct cifs_fid
*fid
, __u16 search_flags
,
2351 struct cifs_search_info
*srch_inf
)
2353 return SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
2354 fid
->volatile_fid
, 0, srch_inf
);
2358 smb2_close_dir(const unsigned int xid
, struct cifs_tcon
*tcon
,
2359 struct cifs_fid
*fid
)
2361 return SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
2365 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
2366 * the number of credits and return true. Otherwise - return false.
2369 smb2_is_status_pending(char *buf
, struct TCP_Server_Info
*server
)
2371 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
2374 if (shdr
->Status
!= STATUS_PENDING
)
2377 if (shdr
->CreditRequest
) {
2378 spin_lock(&server
->req_lock
);
2379 server
->credits
+= le16_to_cpu(shdr
->CreditRequest
);
2380 scredits
= server
->credits
;
2381 spin_unlock(&server
->req_lock
);
2382 wake_up(&server
->request_q
);
2384 trace_smb3_add_credits(server
->CurrentMid
,
2385 server
->hostname
, scredits
, le16_to_cpu(shdr
->CreditRequest
));
2386 cifs_dbg(FYI
, "%s: status pending add %u credits total=%d\n",
2387 __func__
, le16_to_cpu(shdr
->CreditRequest
), scredits
);
2394 smb2_is_session_expired(char *buf
)
2396 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
2398 if (shdr
->Status
!= STATUS_NETWORK_SESSION_EXPIRED
&&
2399 shdr
->Status
!= STATUS_USER_SESSION_DELETED
)
2402 trace_smb3_ses_expired(shdr
->TreeId
, shdr
->SessionId
,
2403 le16_to_cpu(shdr
->Command
),
2404 le64_to_cpu(shdr
->MessageId
));
2405 cifs_dbg(FYI
, "Session expired or deleted\n");
2411 smb2_is_status_io_timeout(char *buf
)
2413 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
2415 if (shdr
->Status
== STATUS_IO_TIMEOUT
)
2422 smb2_oplock_response(struct cifs_tcon
*tcon
, struct cifs_fid
*fid
,
2423 struct cifsInodeInfo
*cinode
)
2425 if (tcon
->ses
->server
->capabilities
& SMB2_GLOBAL_CAP_LEASING
)
2426 return SMB2_lease_break(0, tcon
, cinode
->lease_key
,
2427 smb2_get_lease_state(cinode
));
2429 return SMB2_oplock_break(0, tcon
, fid
->persistent_fid
,
2431 CIFS_CACHE_READ(cinode
) ? 1 : 0);
2435 smb2_set_related(struct smb_rqst
*rqst
)
2437 struct smb2_sync_hdr
*shdr
;
2439 shdr
= (struct smb2_sync_hdr
*)(rqst
->rq_iov
[0].iov_base
);
2441 cifs_dbg(FYI
, "shdr NULL in smb2_set_related\n");
2444 shdr
->Flags
|= SMB2_FLAGS_RELATED_OPERATIONS
;
2447 char smb2_padding
[7] = {0, 0, 0, 0, 0, 0, 0};
2450 smb2_set_next_command(struct cifs_tcon
*tcon
, struct smb_rqst
*rqst
)
2452 struct smb2_sync_hdr
*shdr
;
2453 struct cifs_ses
*ses
= tcon
->ses
;
2454 struct TCP_Server_Info
*server
= ses
->server
;
2455 unsigned long len
= smb_rqst_len(server
, rqst
);
2458 shdr
= (struct smb2_sync_hdr
*)(rqst
->rq_iov
[0].iov_base
);
2460 cifs_dbg(FYI
, "shdr NULL in smb2_set_next_command\n");
2464 /* SMB headers in a compound are 8 byte aligned. */
2466 /* No padding needed */
2470 num_padding
= 8 - (len
& 7);
2471 if (!smb3_encryption_required(tcon
)) {
2473 * If we do not have encryption then we can just add an extra
2474 * iov for the padding.
2476 rqst
->rq_iov
[rqst
->rq_nvec
].iov_base
= smb2_padding
;
2477 rqst
->rq_iov
[rqst
->rq_nvec
].iov_len
= num_padding
;
2482 * We can not add a small padding iov for the encryption case
2483 * because the encryption framework can not handle the padding
2485 * We have to flatten this into a single buffer and add
2486 * the padding to it.
2488 for (i
= 1; i
< rqst
->rq_nvec
; i
++) {
2489 memcpy(rqst
->rq_iov
[0].iov_base
+
2490 rqst
->rq_iov
[0].iov_len
,
2491 rqst
->rq_iov
[i
].iov_base
,
2492 rqst
->rq_iov
[i
].iov_len
);
2493 rqst
->rq_iov
[0].iov_len
+= rqst
->rq_iov
[i
].iov_len
;
2495 memset(rqst
->rq_iov
[0].iov_base
+ rqst
->rq_iov
[0].iov_len
,
2497 rqst
->rq_iov
[0].iov_len
+= num_padding
;
2503 shdr
->NextCommand
= cpu_to_le32(len
);
2507 * Passes the query info response back to the caller on success.
2508 * Caller need to free this with free_rsp_buf().
2511 smb2_query_info_compound(const unsigned int xid
, struct cifs_tcon
*tcon
,
2512 __le16
*utf16_path
, u32 desired_access
,
2513 u32
class, u32 type
, u32 output_len
,
2514 struct kvec
*rsp
, int *buftype
,
2515 struct cifs_sb_info
*cifs_sb
)
2517 struct cifs_ses
*ses
= tcon
->ses
;
2518 struct TCP_Server_Info
*server
= cifs_pick_channel(ses
);
2520 struct smb_rqst rqst
[3];
2521 int resp_buftype
[3];
2522 struct kvec rsp_iov
[3];
2523 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
2524 struct kvec qi_iov
[1];
2525 struct kvec close_iov
[1];
2526 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
2527 struct cifs_open_parms oparms
;
2528 struct cifs_fid fid
;
2531 if (smb3_encryption_required(tcon
))
2532 flags
|= CIFS_TRANSFORM_REQ
;
2534 memset(rqst
, 0, sizeof(rqst
));
2535 resp_buftype
[0] = resp_buftype
[1] = resp_buftype
[2] = CIFS_NO_BUFFER
;
2536 memset(rsp_iov
, 0, sizeof(rsp_iov
));
2538 memset(&open_iov
, 0, sizeof(open_iov
));
2539 rqst
[0].rq_iov
= open_iov
;
2540 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
2543 oparms
.desired_access
= desired_access
;
2544 oparms
.disposition
= FILE_OPEN
;
2545 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
2547 oparms
.reconnect
= false;
2549 rc
= SMB2_open_init(tcon
, server
,
2550 &rqst
[0], &oplock
, &oparms
, utf16_path
);
2553 smb2_set_next_command(tcon
, &rqst
[0]);
2555 memset(&qi_iov
, 0, sizeof(qi_iov
));
2556 rqst
[1].rq_iov
= qi_iov
;
2557 rqst
[1].rq_nvec
= 1;
2559 rc
= SMB2_query_info_init(tcon
, server
,
2560 &rqst
[1], COMPOUND_FID
, COMPOUND_FID
,
2566 smb2_set_next_command(tcon
, &rqst
[1]);
2567 smb2_set_related(&rqst
[1]);
2569 memset(&close_iov
, 0, sizeof(close_iov
));
2570 rqst
[2].rq_iov
= close_iov
;
2571 rqst
[2].rq_nvec
= 1;
2573 rc
= SMB2_close_init(tcon
, server
,
2574 &rqst
[2], COMPOUND_FID
, COMPOUND_FID
, false);
2577 smb2_set_related(&rqst
[2]);
2579 rc
= compound_send_recv(xid
, ses
, server
,
2581 resp_buftype
, rsp_iov
);
2583 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
2584 if (rc
== -EREMCHG
) {
2585 tcon
->need_reconnect
= true;
2586 pr_warn_once("server share %s deleted\n",
2592 *buftype
= resp_buftype
[1];
2595 SMB2_open_free(&rqst
[0]);
2596 SMB2_query_info_free(&rqst
[1]);
2597 SMB2_close_free(&rqst
[2]);
2598 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
2599 free_rsp_buf(resp_buftype
[2], rsp_iov
[2].iov_base
);
2604 smb2_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
2605 struct cifs_sb_info
*cifs_sb
, struct kstatfs
*buf
)
2607 struct smb2_query_info_rsp
*rsp
;
2608 struct smb2_fs_full_size_info
*info
= NULL
;
2609 __le16 utf16_path
= 0; /* Null - open root of share */
2610 struct kvec rsp_iov
= {NULL
, 0};
2611 int buftype
= CIFS_NO_BUFFER
;
2615 rc
= smb2_query_info_compound(xid
, tcon
, &utf16_path
,
2616 FILE_READ_ATTRIBUTES
,
2617 FS_FULL_SIZE_INFORMATION
,
2618 SMB2_O_INFO_FILESYSTEM
,
2619 sizeof(struct smb2_fs_full_size_info
),
2620 &rsp_iov
, &buftype
, cifs_sb
);
2624 rsp
= (struct smb2_query_info_rsp
*)rsp_iov
.iov_base
;
2625 buf
->f_type
= SMB2_MAGIC_NUMBER
;
2626 info
= (struct smb2_fs_full_size_info
*)(
2627 le16_to_cpu(rsp
->OutputBufferOffset
) + (char *)rsp
);
2628 rc
= smb2_validate_iov(le16_to_cpu(rsp
->OutputBufferOffset
),
2629 le32_to_cpu(rsp
->OutputBufferLength
),
2631 sizeof(struct smb2_fs_full_size_info
));
2633 smb2_copy_fs_info_to_kstatfs(info
, buf
);
2636 free_rsp_buf(buftype
, rsp_iov
.iov_base
);
2641 smb311_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
2642 struct cifs_sb_info
*cifs_sb
, struct kstatfs
*buf
)
2645 __le16 srch_path
= 0; /* Null - open root of share */
2646 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
2647 struct cifs_open_parms oparms
;
2648 struct cifs_fid fid
;
2650 if (!tcon
->posix_extensions
)
2651 return smb2_queryfs(xid
, tcon
, cifs_sb
, buf
);
2654 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
2655 oparms
.disposition
= FILE_OPEN
;
2656 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
2658 oparms
.reconnect
= false;
2660 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
,
2665 rc
= SMB311_posix_qfs_info(xid
, tcon
, fid
.persistent_fid
,
2666 fid
.volatile_fid
, buf
);
2667 buf
->f_type
= SMB2_MAGIC_NUMBER
;
2668 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
2673 smb2_compare_fids(struct cifsFileInfo
*ob1
, struct cifsFileInfo
*ob2
)
2675 return ob1
->fid
.persistent_fid
== ob2
->fid
.persistent_fid
&&
2676 ob1
->fid
.volatile_fid
== ob2
->fid
.volatile_fid
;
2680 smb2_mand_lock(const unsigned int xid
, struct cifsFileInfo
*cfile
, __u64 offset
,
2681 __u64 length
, __u32 type
, int lock
, int unlock
, bool wait
)
2683 if (unlock
&& !lock
)
2684 type
= SMB2_LOCKFLAG_UNLOCK
;
2685 return SMB2_lock(xid
, tlink_tcon(cfile
->tlink
),
2686 cfile
->fid
.persistent_fid
, cfile
->fid
.volatile_fid
,
2687 current
->tgid
, length
, offset
, type
, wait
);
2691 smb2_get_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
2693 memcpy(fid
->lease_key
, CIFS_I(inode
)->lease_key
, SMB2_LEASE_KEY_SIZE
);
2697 smb2_set_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
2699 memcpy(CIFS_I(inode
)->lease_key
, fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
2703 smb2_new_lease_key(struct cifs_fid
*fid
)
2705 generate_random_uuid(fid
->lease_key
);
2709 smb2_get_dfs_refer(const unsigned int xid
, struct cifs_ses
*ses
,
2710 const char *search_name
,
2711 struct dfs_info3_param
**target_nodes
,
2712 unsigned int *num_of_nodes
,
2713 const struct nls_table
*nls_codepage
, int remap
)
2716 __le16
*utf16_path
= NULL
;
2717 int utf16_path_len
= 0;
2718 struct cifs_tcon
*tcon
;
2719 struct fsctl_get_dfs_referral_req
*dfs_req
= NULL
;
2720 struct get_dfs_referral_rsp
*dfs_rsp
= NULL
;
2721 u32 dfs_req_size
= 0, dfs_rsp_size
= 0;
2723 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, search_name
);
2726 * Try to use the IPC tcon, otherwise just use any
2728 tcon
= ses
->tcon_ipc
;
2730 spin_lock(&cifs_tcp_ses_lock
);
2731 tcon
= list_first_entry_or_null(&ses
->tcon_list
,
2736 spin_unlock(&cifs_tcp_ses_lock
);
2740 cifs_dbg(VFS
, "session %p has no tcon available for a dfs referral request\n",
2746 utf16_path
= cifs_strndup_to_utf16(search_name
, PATH_MAX
,
2748 nls_codepage
, remap
);
2754 dfs_req_size
= sizeof(*dfs_req
) + utf16_path_len
;
2755 dfs_req
= kzalloc(dfs_req_size
, GFP_KERNEL
);
2761 /* Highest DFS referral version understood */
2762 dfs_req
->MaxReferralLevel
= DFS_VERSION
;
2764 /* Path to resolve in an UTF-16 null-terminated string */
2765 memcpy(dfs_req
->RequestFileName
, utf16_path
, utf16_path_len
);
2768 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
2769 FSCTL_DFS_GET_REFERRALS
,
2770 true /* is_fsctl */,
2771 (char *)dfs_req
, dfs_req_size
, CIFSMaxBufSize
,
2772 (char **)&dfs_rsp
, &dfs_rsp_size
);
2773 } while (rc
== -EAGAIN
);
2776 if ((rc
!= -ENOENT
) && (rc
!= -EOPNOTSUPP
))
2777 cifs_tcon_dbg(VFS
, "ioctl error in %s rc=%d\n", __func__
, rc
);
2781 rc
= parse_dfs_referrals(dfs_rsp
, dfs_rsp_size
,
2782 num_of_nodes
, target_nodes
,
2783 nls_codepage
, remap
, search_name
,
2784 true /* is_unicode */);
2786 cifs_tcon_dbg(VFS
, "parse error in %s rc=%d\n", __func__
, rc
);
2791 if (tcon
&& !tcon
->ipc
) {
2792 /* ipc tcons are not refcounted */
2793 spin_lock(&cifs_tcp_ses_lock
);
2795 spin_unlock(&cifs_tcp_ses_lock
);
2804 parse_reparse_posix(struct reparse_posix_data
*symlink_buf
,
2805 u32 plen
, char **target_path
,
2806 struct cifs_sb_info
*cifs_sb
)
2810 /* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */
2811 len
= le16_to_cpu(symlink_buf
->ReparseDataLength
);
2813 if (le64_to_cpu(symlink_buf
->InodeType
) != NFS_SPECFILE_LNK
) {
2814 cifs_dbg(VFS
, "%lld not a supported symlink type\n",
2815 le64_to_cpu(symlink_buf
->InodeType
));
2819 *target_path
= cifs_strndup_from_utf16(
2820 symlink_buf
->PathBuffer
,
2821 len
, true, cifs_sb
->local_nls
);
2822 if (!(*target_path
))
2825 convert_delimiter(*target_path
, '/');
2826 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
2832 parse_reparse_symlink(struct reparse_symlink_data_buffer
*symlink_buf
,
2833 u32 plen
, char **target_path
,
2834 struct cifs_sb_info
*cifs_sb
)
2836 unsigned int sub_len
;
2837 unsigned int sub_offset
;
2839 /* We handle Symbolic Link reparse tag here. See: MS-FSCC 2.1.2.4 */
2841 sub_offset
= le16_to_cpu(symlink_buf
->SubstituteNameOffset
);
2842 sub_len
= le16_to_cpu(symlink_buf
->SubstituteNameLength
);
2843 if (sub_offset
+ 20 > plen
||
2844 sub_offset
+ sub_len
+ 20 > plen
) {
2845 cifs_dbg(VFS
, "srv returned malformed symlink buffer\n");
2849 *target_path
= cifs_strndup_from_utf16(
2850 symlink_buf
->PathBuffer
+ sub_offset
,
2851 sub_len
, true, cifs_sb
->local_nls
);
2852 if (!(*target_path
))
2855 convert_delimiter(*target_path
, '/');
2856 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
2862 parse_reparse_point(struct reparse_data_buffer
*buf
,
2863 u32 plen
, char **target_path
,
2864 struct cifs_sb_info
*cifs_sb
)
2866 if (plen
< sizeof(struct reparse_data_buffer
)) {
2867 cifs_dbg(VFS
, "reparse buffer is too small. Must be at least 8 bytes but was %d\n",
2872 if (plen
< le16_to_cpu(buf
->ReparseDataLength
) +
2873 sizeof(struct reparse_data_buffer
)) {
2874 cifs_dbg(VFS
, "srv returned invalid reparse buf length: %d\n",
2879 /* See MS-FSCC 2.1.2 */
2880 switch (le32_to_cpu(buf
->ReparseTag
)) {
2881 case IO_REPARSE_TAG_NFS
:
2882 return parse_reparse_posix(
2883 (struct reparse_posix_data
*)buf
,
2884 plen
, target_path
, cifs_sb
);
2885 case IO_REPARSE_TAG_SYMLINK
:
2886 return parse_reparse_symlink(
2887 (struct reparse_symlink_data_buffer
*)buf
,
2888 plen
, target_path
, cifs_sb
);
2890 cifs_dbg(VFS
, "srv returned unknown symlink buffer tag:0x%08x\n",
2891 le32_to_cpu(buf
->ReparseTag
));
2896 #define SMB2_SYMLINK_STRUCT_SIZE \
2897 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
2900 smb2_query_symlink(const unsigned int xid
, struct cifs_tcon
*tcon
,
2901 struct cifs_sb_info
*cifs_sb
, const char *full_path
,
2902 char **target_path
, bool is_reparse_point
)
2905 __le16
*utf16_path
= NULL
;
2906 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
2907 struct cifs_open_parms oparms
;
2908 struct cifs_fid fid
;
2909 struct kvec err_iov
= {NULL
, 0};
2910 struct smb2_err_rsp
*err_buf
= NULL
;
2911 struct smb2_symlink_err_rsp
*symlink
;
2912 struct TCP_Server_Info
*server
= cifs_pick_channel(tcon
->ses
);
2913 unsigned int sub_len
;
2914 unsigned int sub_offset
;
2915 unsigned int print_len
;
2916 unsigned int print_offset
;
2918 struct smb_rqst rqst
[3];
2919 int resp_buftype
[3];
2920 struct kvec rsp_iov
[3];
2921 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
2922 struct kvec io_iov
[SMB2_IOCTL_IOV_SIZE
];
2923 struct kvec close_iov
[1];
2924 struct smb2_create_rsp
*create_rsp
;
2925 struct smb2_ioctl_rsp
*ioctl_rsp
;
2926 struct reparse_data_buffer
*reparse_buf
;
2927 int create_options
= is_reparse_point
? OPEN_REPARSE_POINT
: 0;
2930 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, full_path
);
2932 *target_path
= NULL
;
2934 if (smb3_encryption_required(tcon
))
2935 flags
|= CIFS_TRANSFORM_REQ
;
2937 memset(rqst
, 0, sizeof(rqst
));
2938 resp_buftype
[0] = resp_buftype
[1] = resp_buftype
[2] = CIFS_NO_BUFFER
;
2939 memset(rsp_iov
, 0, sizeof(rsp_iov
));
2941 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
2946 memset(&open_iov
, 0, sizeof(open_iov
));
2947 rqst
[0].rq_iov
= open_iov
;
2948 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
2950 memset(&oparms
, 0, sizeof(oparms
));
2952 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
2953 oparms
.disposition
= FILE_OPEN
;
2954 oparms
.create_options
= cifs_create_options(cifs_sb
, create_options
);
2956 oparms
.reconnect
= false;
2958 rc
= SMB2_open_init(tcon
, server
,
2959 &rqst
[0], &oplock
, &oparms
, utf16_path
);
2962 smb2_set_next_command(tcon
, &rqst
[0]);
2966 memset(&io_iov
, 0, sizeof(io_iov
));
2967 rqst
[1].rq_iov
= io_iov
;
2968 rqst
[1].rq_nvec
= SMB2_IOCTL_IOV_SIZE
;
2970 rc
= SMB2_ioctl_init(tcon
, server
,
2971 &rqst
[1], fid
.persistent_fid
,
2972 fid
.volatile_fid
, FSCTL_GET_REPARSE_POINT
,
2973 true /* is_fctl */, NULL
, 0,
2975 MAX_SMB2_CREATE_RESPONSE_SIZE
-
2976 MAX_SMB2_CLOSE_RESPONSE_SIZE
);
2980 smb2_set_next_command(tcon
, &rqst
[1]);
2981 smb2_set_related(&rqst
[1]);
2985 memset(&close_iov
, 0, sizeof(close_iov
));
2986 rqst
[2].rq_iov
= close_iov
;
2987 rqst
[2].rq_nvec
= 1;
2989 rc
= SMB2_close_init(tcon
, server
,
2990 &rqst
[2], COMPOUND_FID
, COMPOUND_FID
, false);
2994 smb2_set_related(&rqst
[2]);
2996 rc
= compound_send_recv(xid
, tcon
->ses
, server
,
2998 resp_buftype
, rsp_iov
);
3000 create_rsp
= rsp_iov
[0].iov_base
;
3001 if (create_rsp
&& create_rsp
->sync_hdr
.Status
)
3002 err_iov
= rsp_iov
[0];
3003 ioctl_rsp
= rsp_iov
[1].iov_base
;
3006 * Open was successful and we got an ioctl response.
3008 if ((rc
== 0) && (is_reparse_point
)) {
3009 /* See MS-FSCC 2.3.23 */
3011 reparse_buf
= (struct reparse_data_buffer
*)
3012 ((char *)ioctl_rsp
+
3013 le32_to_cpu(ioctl_rsp
->OutputOffset
));
3014 plen
= le32_to_cpu(ioctl_rsp
->OutputCount
);
3016 if (plen
+ le32_to_cpu(ioctl_rsp
->OutputOffset
) >
3017 rsp_iov
[1].iov_len
) {
3018 cifs_tcon_dbg(VFS
, "srv returned invalid ioctl len: %d\n",
3024 rc
= parse_reparse_point(reparse_buf
, plen
, target_path
,
3029 if (!rc
|| !err_iov
.iov_base
) {
3034 err_buf
= err_iov
.iov_base
;
3035 if (le32_to_cpu(err_buf
->ByteCount
) < sizeof(struct smb2_symlink_err_rsp
) ||
3036 err_iov
.iov_len
< SMB2_SYMLINK_STRUCT_SIZE
) {
3041 symlink
= (struct smb2_symlink_err_rsp
*)err_buf
->ErrorData
;
3042 if (le32_to_cpu(symlink
->SymLinkErrorTag
) != SYMLINK_ERROR_TAG
||
3043 le32_to_cpu(symlink
->ReparseTag
) != IO_REPARSE_TAG_SYMLINK
) {
3048 /* open must fail on symlink - reset rc */
3050 sub_len
= le16_to_cpu(symlink
->SubstituteNameLength
);
3051 sub_offset
= le16_to_cpu(symlink
->SubstituteNameOffset
);
3052 print_len
= le16_to_cpu(symlink
->PrintNameLength
);
3053 print_offset
= le16_to_cpu(symlink
->PrintNameOffset
);
3055 if (err_iov
.iov_len
< SMB2_SYMLINK_STRUCT_SIZE
+ sub_offset
+ sub_len
) {
3060 if (err_iov
.iov_len
<
3061 SMB2_SYMLINK_STRUCT_SIZE
+ print_offset
+ print_len
) {
3066 *target_path
= cifs_strndup_from_utf16(
3067 (char *)symlink
->PathBuffer
+ sub_offset
,
3068 sub_len
, true, cifs_sb
->local_nls
);
3069 if (!(*target_path
)) {
3073 convert_delimiter(*target_path
, '/');
3074 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
3077 cifs_dbg(FYI
, "query symlink rc %d\n", rc
);
3079 SMB2_open_free(&rqst
[0]);
3080 SMB2_ioctl_free(&rqst
[1]);
3081 SMB2_close_free(&rqst
[2]);
3082 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
3083 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
3084 free_rsp_buf(resp_buftype
[2], rsp_iov
[2].iov_base
);
3089 smb2_query_reparse_tag(const unsigned int xid
, struct cifs_tcon
*tcon
,
3090 struct cifs_sb_info
*cifs_sb
, const char *full_path
,
3094 __le16
*utf16_path
= NULL
;
3095 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
3096 struct cifs_open_parms oparms
;
3097 struct cifs_fid fid
;
3098 struct TCP_Server_Info
*server
= cifs_pick_channel(tcon
->ses
);
3100 struct smb_rqst rqst
[3];
3101 int resp_buftype
[3];
3102 struct kvec rsp_iov
[3];
3103 struct kvec open_iov
[SMB2_CREATE_IOV_SIZE
];
3104 struct kvec io_iov
[SMB2_IOCTL_IOV_SIZE
];
3105 struct kvec close_iov
[1];
3106 struct smb2_ioctl_rsp
*ioctl_rsp
;
3107 struct reparse_data_buffer
*reparse_buf
;
3110 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, full_path
);
3112 if (smb3_encryption_required(tcon
))
3113 flags
|= CIFS_TRANSFORM_REQ
;
3115 memset(rqst
, 0, sizeof(rqst
));
3116 resp_buftype
[0] = resp_buftype
[1] = resp_buftype
[2] = CIFS_NO_BUFFER
;
3117 memset(rsp_iov
, 0, sizeof(rsp_iov
));
3119 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
3124 * setup smb2open - TODO add optimization to call cifs_get_readable_path
3125 * to see if there is a handle already open that we can use
3127 memset(&open_iov
, 0, sizeof(open_iov
));
3128 rqst
[0].rq_iov
= open_iov
;
3129 rqst
[0].rq_nvec
= SMB2_CREATE_IOV_SIZE
;
3131 memset(&oparms
, 0, sizeof(oparms
));
3133 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
3134 oparms
.disposition
= FILE_OPEN
;
3135 oparms
.create_options
= cifs_create_options(cifs_sb
, OPEN_REPARSE_POINT
);
3137 oparms
.reconnect
= false;
3139 rc
= SMB2_open_init(tcon
, server
,
3140 &rqst
[0], &oplock
, &oparms
, utf16_path
);
3143 smb2_set_next_command(tcon
, &rqst
[0]);
3147 memset(&io_iov
, 0, sizeof(io_iov
));
3148 rqst
[1].rq_iov
= io_iov
;
3149 rqst
[1].rq_nvec
= SMB2_IOCTL_IOV_SIZE
;
3151 rc
= SMB2_ioctl_init(tcon
, server
,
3152 &rqst
[1], COMPOUND_FID
,
3153 COMPOUND_FID
, FSCTL_GET_REPARSE_POINT
,
3154 true /* is_fctl */, NULL
, 0,
3156 MAX_SMB2_CREATE_RESPONSE_SIZE
-
3157 MAX_SMB2_CLOSE_RESPONSE_SIZE
);
3161 smb2_set_next_command(tcon
, &rqst
[1]);
3162 smb2_set_related(&rqst
[1]);
3166 memset(&close_iov
, 0, sizeof(close_iov
));
3167 rqst
[2].rq_iov
= close_iov
;
3168 rqst
[2].rq_nvec
= 1;
3170 rc
= SMB2_close_init(tcon
, server
,
3171 &rqst
[2], COMPOUND_FID
, COMPOUND_FID
, false);
3175 smb2_set_related(&rqst
[2]);
3177 rc
= compound_send_recv(xid
, tcon
->ses
, server
,
3179 resp_buftype
, rsp_iov
);
3181 ioctl_rsp
= rsp_iov
[1].iov_base
;
3184 * Open was successful and we got an ioctl response.
3187 /* See MS-FSCC 2.3.23 */
3189 reparse_buf
= (struct reparse_data_buffer
*)
3190 ((char *)ioctl_rsp
+
3191 le32_to_cpu(ioctl_rsp
->OutputOffset
));
3192 plen
= le32_to_cpu(ioctl_rsp
->OutputCount
);
3194 if (plen
+ le32_to_cpu(ioctl_rsp
->OutputOffset
) >
3195 rsp_iov
[1].iov_len
) {
3196 cifs_tcon_dbg(FYI
, "srv returned invalid ioctl len: %d\n",
3201 *tag
= le32_to_cpu(reparse_buf
->ReparseTag
);
3206 SMB2_open_free(&rqst
[0]);
3207 SMB2_ioctl_free(&rqst
[1]);
3208 SMB2_close_free(&rqst
[2]);
3209 free_rsp_buf(resp_buftype
[0], rsp_iov
[0].iov_base
);
3210 free_rsp_buf(resp_buftype
[1], rsp_iov
[1].iov_base
);
3211 free_rsp_buf(resp_buftype
[2], rsp_iov
[2].iov_base
);
3215 static struct cifs_ntsd
*
3216 get_smb2_acl_by_fid(struct cifs_sb_info
*cifs_sb
,
3217 const struct cifs_fid
*cifsfid
, u32
*pacllen
, u32 info
)
3219 struct cifs_ntsd
*pntsd
= NULL
;
3221 int rc
= -EOPNOTSUPP
;
3222 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
3225 return ERR_CAST(tlink
);
3228 cifs_dbg(FYI
, "trying to get acl\n");
3230 rc
= SMB2_query_acl(xid
, tlink_tcon(tlink
), cifsfid
->persistent_fid
,
3231 cifsfid
->volatile_fid
, (void **)&pntsd
, pacllen
,
3235 cifs_put_tlink(tlink
);
3237 cifs_dbg(FYI
, "%s: rc = %d ACL len %d\n", __func__
, rc
, *pacllen
);
3244 static struct cifs_ntsd
*
3245 get_smb2_acl_by_path(struct cifs_sb_info
*cifs_sb
,
3246 const char *path
, u32
*pacllen
, u32 info
)
3248 struct cifs_ntsd
*pntsd
= NULL
;
3249 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
3252 struct cifs_tcon
*tcon
;
3253 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
3254 struct cifs_fid fid
;
3255 struct cifs_open_parms oparms
;
3258 cifs_dbg(FYI
, "get smb3 acl for path %s\n", path
);
3260 return ERR_CAST(tlink
);
3262 tcon
= tlink_tcon(tlink
);
3265 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
3273 oparms
.desired_access
= READ_CONTROL
;
3274 oparms
.disposition
= FILE_OPEN
;
3276 * When querying an ACL, even if the file is a symlink we want to open
3277 * the source not the target, and so the protocol requires that the
3278 * client specify this flag when opening a reparse point
3280 oparms
.create_options
= cifs_create_options(cifs_sb
, 0) | OPEN_REPARSE_POINT
;
3282 oparms
.reconnect
= false;
3284 if (info
& SACL_SECINFO
)
3285 oparms
.desired_access
|= SYSTEM_SECURITY
;
3287 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
, NULL
,
3291 rc
= SMB2_query_acl(xid
, tlink_tcon(tlink
), fid
.persistent_fid
,
3292 fid
.volatile_fid
, (void **)&pntsd
, pacllen
,
3294 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
3297 cifs_put_tlink(tlink
);
3300 cifs_dbg(FYI
, "%s: rc = %d ACL len %d\n", __func__
, rc
, *pacllen
);
3307 set_smb2_acl(struct cifs_ntsd
*pnntsd
, __u32 acllen
,
3308 struct inode
*inode
, const char *path
, int aclflag
)
3310 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
3312 int rc
, access_flags
= 0;
3313 struct cifs_tcon
*tcon
;
3314 struct cifs_sb_info
*cifs_sb
= CIFS_SB(inode
->i_sb
);
3315 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
3316 struct cifs_fid fid
;
3317 struct cifs_open_parms oparms
;
3320 cifs_dbg(FYI
, "set smb3 acl for path %s\n", path
);
3322 return PTR_ERR(tlink
);
3324 tcon
= tlink_tcon(tlink
);
3327 if (aclflag
& CIFS_ACL_OWNER
|| aclflag
& CIFS_ACL_GROUP
)
3328 access_flags
|= WRITE_OWNER
;
3329 if (aclflag
& CIFS_ACL_SACL
)
3330 access_flags
|= SYSTEM_SECURITY
;
3331 if (aclflag
& CIFS_ACL_DACL
)
3332 access_flags
|= WRITE_DAC
;
3334 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
3342 oparms
.desired_access
= access_flags
;
3343 oparms
.create_options
= cifs_create_options(cifs_sb
, 0);
3344 oparms
.disposition
= FILE_OPEN
;
3347 oparms
.reconnect
= false;
3349 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
,
3353 rc
= SMB2_set_acl(xid
, tlink_tcon(tlink
), fid
.persistent_fid
,
3354 fid
.volatile_fid
, pnntsd
, acllen
, aclflag
);
3355 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
3358 cifs_put_tlink(tlink
);
3363 /* Retrieve an ACL from the server */
3364 static struct cifs_ntsd
*
3365 get_smb2_acl(struct cifs_sb_info
*cifs_sb
,
3366 struct inode
*inode
, const char *path
,
3367 u32
*pacllen
, u32 info
)
3369 struct cifs_ntsd
*pntsd
= NULL
;
3370 struct cifsFileInfo
*open_file
= NULL
;
3372 if (inode
&& !(info
& SACL_SECINFO
))
3373 open_file
= find_readable_file(CIFS_I(inode
), true);
3374 if (!open_file
|| (info
& SACL_SECINFO
))
3375 return get_smb2_acl_by_path(cifs_sb
, path
, pacllen
, info
);
3377 pntsd
= get_smb2_acl_by_fid(cifs_sb
, &open_file
->fid
, pacllen
, info
);
3378 cifsFileInfo_put(open_file
);
3382 static long smb3_zero_range(struct file
*file
, struct cifs_tcon
*tcon
,
3383 loff_t offset
, loff_t len
, bool keep_size
)
3385 struct cifs_ses
*ses
= tcon
->ses
;
3386 struct inode
*inode
;
3387 struct cifsInodeInfo
*cifsi
;
3388 struct cifsFileInfo
*cfile
= file
->private_data
;
3389 struct file_zero_data_information fsctl_buf
;
3396 inode
= d_inode(cfile
->dentry
);
3397 cifsi
= CIFS_I(inode
);
3399 trace_smb3_zero_enter(xid
, cfile
->fid
.persistent_fid
, tcon
->tid
,
3400 ses
->Suid
, offset
, len
);
3403 * We zero the range through ioctl, so we need remove the page caches
3404 * first, otherwise the data may be inconsistent with the server.
3406 truncate_pagecache_range(inode
, offset
, offset
+ len
- 1);
3408 /* if file not oplocked can't be sure whether asking to extend size */
3409 if (!CIFS_CACHE_READ(cifsi
))
3410 if (keep_size
== false) {
3412 trace_smb3_zero_err(xid
, cfile
->fid
.persistent_fid
,
3413 tcon
->tid
, ses
->Suid
, offset
, len
, rc
);
3418 cifs_dbg(FYI
, "Offset %lld len %lld\n", offset
, len
);
3420 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
3421 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
3423 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
3424 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
, true,
3426 sizeof(struct file_zero_data_information
),
3429 goto zero_range_exit
;
3432 * do we also need to change the size of the file?
3434 if (keep_size
== false && i_size_read(inode
) < offset
+ len
) {
3435 eof
= cpu_to_le64(offset
+ len
);
3436 rc
= SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
3437 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
);
3443 trace_smb3_zero_err(xid
, cfile
->fid
.persistent_fid
, tcon
->tid
,
3444 ses
->Suid
, offset
, len
, rc
);
3446 trace_smb3_zero_done(xid
, cfile
->fid
.persistent_fid
, tcon
->tid
,
3447 ses
->Suid
, offset
, len
);
3451 static long smb3_punch_hole(struct file
*file
, struct cifs_tcon
*tcon
,
3452 loff_t offset
, loff_t len
)
3454 struct inode
*inode
;
3455 struct cifsFileInfo
*cfile
= file
->private_data
;
3456 struct file_zero_data_information fsctl_buf
;
3459 __u8 set_sparse
= 1;
3463 inode
= d_inode(cfile
->dentry
);
3465 /* Need to make file sparse, if not already, before freeing range. */
3466 /* Consider adding equivalent for compressed since it could also work */
3467 if (!smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
)) {
3474 * We implement the punch hole through ioctl, so we need remove the page
3475 * caches first, otherwise the data may be inconsistent with the server.
3477 truncate_pagecache_range(inode
, offset
, offset
+ len
- 1);
3479 cifs_dbg(FYI
, "Offset %lld len %lld\n", offset
, len
);
3481 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
3482 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
3484 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
3485 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
3486 true /* is_fctl */, (char *)&fsctl_buf
,
3487 sizeof(struct file_zero_data_information
),
3488 CIFSMaxBufSize
, NULL
, NULL
);
3493 static long smb3_simple_falloc(struct file
*file
, struct cifs_tcon
*tcon
,
3494 loff_t off
, loff_t len
, bool keep_size
)
3496 struct inode
*inode
;
3497 struct cifsInodeInfo
*cifsi
;
3498 struct cifsFileInfo
*cfile
= file
->private_data
;
3499 long rc
= -EOPNOTSUPP
;
3505 inode
= d_inode(cfile
->dentry
);
3506 cifsi
= CIFS_I(inode
);
3508 trace_smb3_falloc_enter(xid
, cfile
->fid
.persistent_fid
, tcon
->tid
,
3509 tcon
->ses
->Suid
, off
, len
);
3510 /* if file not oplocked can't be sure whether asking to extend size */
3511 if (!CIFS_CACHE_READ(cifsi
))
3512 if (keep_size
== false) {
3513 trace_smb3_falloc_err(xid
, cfile
->fid
.persistent_fid
,
3514 tcon
->tid
, tcon
->ses
->Suid
, off
, len
, rc
);
3520 * Extending the file
3522 if ((keep_size
== false) && i_size_read(inode
) < off
+ len
) {
3523 rc
= inode_newsize_ok(inode
, off
+ len
);
3527 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) == 0)
3528 smb2_set_sparse(xid
, tcon
, cfile
, inode
, false);
3530 eof
= cpu_to_le64(off
+ len
);
3531 rc
= SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
3532 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
);
3534 cifsi
->server_eof
= off
+ len
;
3535 cifs_setsize(inode
, off
+ len
);
3536 cifs_truncate_page(inode
->i_mapping
, inode
->i_size
);
3537 truncate_setsize(inode
, off
+ len
);
3543 * Files are non-sparse by default so falloc may be a no-op
3544 * Must check if file sparse. If not sparse, and since we are not
3545 * extending then no need to do anything since file already allocated
3547 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) == 0) {
3552 if ((keep_size
== true) || (i_size_read(inode
) >= off
+ len
)) {
3554 * Check if falloc starts within first few pages of file
3555 * and ends within a few pages of the end of file to
3556 * ensure that most of file is being forced to be
3557 * fallocated now. If so then setting whole file sparse
3558 * ie potentially making a few extra pages at the beginning
3559 * or end of the file non-sparse via set_sparse is harmless.
3561 if ((off
> 8192) || (off
+ len
+ 8192 < i_size_read(inode
))) {
3567 smb2_set_sparse(xid
, tcon
, cfile
, inode
, false);
3572 trace_smb3_falloc_err(xid
, cfile
->fid
.persistent_fid
, tcon
->tid
,
3573 tcon
->ses
->Suid
, off
, len
, rc
);
3575 trace_smb3_falloc_done(xid
, cfile
->fid
.persistent_fid
, tcon
->tid
,
3576 tcon
->ses
->Suid
, off
, len
);
3582 static loff_t
smb3_llseek(struct file
*file
, struct cifs_tcon
*tcon
, loff_t offset
, int whence
)
3584 struct cifsFileInfo
*wrcfile
, *cfile
= file
->private_data
;
3585 struct cifsInodeInfo
*cifsi
;
3586 struct inode
*inode
;
3588 struct file_allocated_range_buffer in_data
, *out_data
= NULL
;
3592 if (whence
!= SEEK_HOLE
&& whence
!= SEEK_DATA
)
3593 return generic_file_llseek(file
, offset
, whence
);
3595 inode
= d_inode(cfile
->dentry
);
3596 cifsi
= CIFS_I(inode
);
3598 if (offset
< 0 || offset
>= i_size_read(inode
))
3603 * We need to be sure that all dirty pages are written as they
3604 * might fill holes on the server.
3605 * Note that we also MUST flush any written pages since at least
3606 * some servers (Windows2016) will not reflect recent writes in
3607 * QUERY_ALLOCATED_RANGES until SMB2_flush is called.
3609 wrcfile
= find_writable_file(cifsi
, FIND_WR_ANY
);
3611 filemap_write_and_wait(inode
->i_mapping
);
3612 smb2_flush_file(xid
, tcon
, &wrcfile
->fid
);
3613 cifsFileInfo_put(wrcfile
);
3616 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
)) {
3617 if (whence
== SEEK_HOLE
)
3618 offset
= i_size_read(inode
);
3622 in_data
.file_offset
= cpu_to_le64(offset
);
3623 in_data
.length
= cpu_to_le64(i_size_read(inode
));
3625 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
3626 cfile
->fid
.volatile_fid
,
3627 FSCTL_QUERY_ALLOCATED_RANGES
, true,
3628 (char *)&in_data
, sizeof(in_data
),
3629 sizeof(struct file_allocated_range_buffer
),
3630 (char **)&out_data
, &out_data_len
);
3636 if (whence
== SEEK_HOLE
&& out_data_len
== 0)
3639 if (whence
== SEEK_DATA
&& out_data_len
== 0) {
3644 if (out_data_len
< sizeof(struct file_allocated_range_buffer
)) {
3648 if (whence
== SEEK_DATA
) {
3649 offset
= le64_to_cpu(out_data
->file_offset
);
3652 if (offset
< le64_to_cpu(out_data
->file_offset
))
3655 offset
= le64_to_cpu(out_data
->file_offset
) + le64_to_cpu(out_data
->length
);
3661 return vfs_setpos(file
, offset
, inode
->i_sb
->s_maxbytes
);
3666 static int smb3_fiemap(struct cifs_tcon
*tcon
,
3667 struct cifsFileInfo
*cfile
,
3668 struct fiemap_extent_info
*fei
, u64 start
, u64 len
)
3671 struct file_allocated_range_buffer in_data
, *out_data
;
3673 int i
, num
, rc
, flags
, last_blob
;
3676 rc
= fiemap_prep(d_inode(cfile
->dentry
), fei
, start
, &len
, 0);
3682 in_data
.file_offset
= cpu_to_le64(start
);
3683 in_data
.length
= cpu_to_le64(len
);
3685 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
3686 cfile
->fid
.volatile_fid
,
3687 FSCTL_QUERY_ALLOCATED_RANGES
, true,
3688 (char *)&in_data
, sizeof(in_data
),
3689 1024 * sizeof(struct file_allocated_range_buffer
),
3690 (char **)&out_data
, &out_data_len
);
3699 if (out_data_len
&& out_data_len
< sizeof(struct file_allocated_range_buffer
)) {
3703 if (out_data_len
% sizeof(struct file_allocated_range_buffer
)) {
3708 num
= out_data_len
/ sizeof(struct file_allocated_range_buffer
);
3709 for (i
= 0; i
< num
; i
++) {
3711 if (i
== num
- 1 && last_blob
)
3712 flags
|= FIEMAP_EXTENT_LAST
;
3714 rc
= fiemap_fill_next_extent(fei
,
3715 le64_to_cpu(out_data
[i
].file_offset
),
3716 le64_to_cpu(out_data
[i
].file_offset
),
3717 le64_to_cpu(out_data
[i
].length
),
3728 next
= le64_to_cpu(out_data
[num
- 1].file_offset
) +
3729 le64_to_cpu(out_data
[num
- 1].length
);
3730 len
= len
- (next
- start
);
3741 static long smb3_fallocate(struct file
*file
, struct cifs_tcon
*tcon
, int mode
,
3742 loff_t off
, loff_t len
)
3744 /* KEEP_SIZE already checked for by do_fallocate */
3745 if (mode
& FALLOC_FL_PUNCH_HOLE
)
3746 return smb3_punch_hole(file
, tcon
, off
, len
);
3747 else if (mode
& FALLOC_FL_ZERO_RANGE
) {
3748 if (mode
& FALLOC_FL_KEEP_SIZE
)
3749 return smb3_zero_range(file
, tcon
, off
, len
, true);
3750 return smb3_zero_range(file
, tcon
, off
, len
, false);
3751 } else if (mode
== FALLOC_FL_KEEP_SIZE
)
3752 return smb3_simple_falloc(file
, tcon
, off
, len
, true);
3754 return smb3_simple_falloc(file
, tcon
, off
, len
, false);
3760 smb2_downgrade_oplock(struct TCP_Server_Info
*server
,
3761 struct cifsInodeInfo
*cinode
, __u32 oplock
,
3762 unsigned int epoch
, bool *purge_cache
)
3764 server
->ops
->set_oplock_level(cinode
, oplock
, 0, NULL
);
3768 smb21_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
3769 unsigned int epoch
, bool *purge_cache
);
3772 smb3_downgrade_oplock(struct TCP_Server_Info
*server
,
3773 struct cifsInodeInfo
*cinode
, __u32 oplock
,
3774 unsigned int epoch
, bool *purge_cache
)
3776 unsigned int old_state
= cinode
->oplock
;
3777 unsigned int old_epoch
= cinode
->epoch
;
3778 unsigned int new_state
;
3780 if (epoch
> old_epoch
) {
3781 smb21_set_oplock_level(cinode
, oplock
, 0, NULL
);
3782 cinode
->epoch
= epoch
;
3785 new_state
= cinode
->oplock
;
3786 *purge_cache
= false;
3788 if ((old_state
& CIFS_CACHE_READ_FLG
) != 0 &&
3789 (new_state
& CIFS_CACHE_READ_FLG
) == 0)
3790 *purge_cache
= true;
3791 else if (old_state
== new_state
&& (epoch
- old_epoch
> 1))
3792 *purge_cache
= true;
3796 smb2_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
3797 unsigned int epoch
, bool *purge_cache
)
3800 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
3802 if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
) {
3803 cinode
->oplock
= CIFS_CACHE_RHW_FLG
;
3804 cifs_dbg(FYI
, "Batch Oplock granted on inode %p\n",
3805 &cinode
->vfs_inode
);
3806 } else if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
) {
3807 cinode
->oplock
= CIFS_CACHE_RW_FLG
;
3808 cifs_dbg(FYI
, "Exclusive Oplock granted on inode %p\n",
3809 &cinode
->vfs_inode
);
3810 } else if (oplock
== SMB2_OPLOCK_LEVEL_II
) {
3811 cinode
->oplock
= CIFS_CACHE_READ_FLG
;
3812 cifs_dbg(FYI
, "Level II Oplock granted on inode %p\n",
3813 &cinode
->vfs_inode
);
3819 smb21_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
3820 unsigned int epoch
, bool *purge_cache
)
3822 char message
[5] = {0};
3823 unsigned int new_oplock
= 0;
3826 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
3829 /* Check if the server granted an oplock rather than a lease */
3830 if (oplock
& SMB2_OPLOCK_LEVEL_EXCLUSIVE
)
3831 return smb2_set_oplock_level(cinode
, oplock
, epoch
,
3834 if (oplock
& SMB2_LEASE_READ_CACHING_HE
) {
3835 new_oplock
|= CIFS_CACHE_READ_FLG
;
3836 strcat(message
, "R");
3838 if (oplock
& SMB2_LEASE_HANDLE_CACHING_HE
) {
3839 new_oplock
|= CIFS_CACHE_HANDLE_FLG
;
3840 strcat(message
, "H");
3842 if (oplock
& SMB2_LEASE_WRITE_CACHING_HE
) {
3843 new_oplock
|= CIFS_CACHE_WRITE_FLG
;
3844 strcat(message
, "W");
3847 strncpy(message
, "None", sizeof(message
));
3849 cinode
->oplock
= new_oplock
;
3850 cifs_dbg(FYI
, "%s Lease granted on inode %p\n", message
,
3851 &cinode
->vfs_inode
);
3855 smb3_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
3856 unsigned int epoch
, bool *purge_cache
)
3858 unsigned int old_oplock
= cinode
->oplock
;
3860 smb21_set_oplock_level(cinode
, oplock
, epoch
, purge_cache
);
3863 *purge_cache
= false;
3864 if (old_oplock
== CIFS_CACHE_READ_FLG
) {
3865 if (cinode
->oplock
== CIFS_CACHE_READ_FLG
&&
3866 (epoch
- cinode
->epoch
> 0))
3867 *purge_cache
= true;
3868 else if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
3869 (epoch
- cinode
->epoch
> 1))
3870 *purge_cache
= true;
3871 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
3872 (epoch
- cinode
->epoch
> 1))
3873 *purge_cache
= true;
3874 else if (cinode
->oplock
== 0 &&
3875 (epoch
- cinode
->epoch
> 0))
3876 *purge_cache
= true;
3877 } else if (old_oplock
== CIFS_CACHE_RH_FLG
) {
3878 if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
3879 (epoch
- cinode
->epoch
> 0))
3880 *purge_cache
= true;
3881 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
3882 (epoch
- cinode
->epoch
> 1))
3883 *purge_cache
= true;
3885 cinode
->epoch
= epoch
;
3890 smb2_is_read_op(__u32 oplock
)
3892 return oplock
== SMB2_OPLOCK_LEVEL_II
;
3896 smb21_is_read_op(__u32 oplock
)
3898 return (oplock
& SMB2_LEASE_READ_CACHING_HE
) &&
3899 !(oplock
& SMB2_LEASE_WRITE_CACHING_HE
);
3903 map_oplock_to_lease(u8 oplock
)
3905 if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
)
3906 return SMB2_LEASE_WRITE_CACHING
| SMB2_LEASE_READ_CACHING
;
3907 else if (oplock
== SMB2_OPLOCK_LEVEL_II
)
3908 return SMB2_LEASE_READ_CACHING
;
3909 else if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
)
3910 return SMB2_LEASE_HANDLE_CACHING
| SMB2_LEASE_READ_CACHING
|
3911 SMB2_LEASE_WRITE_CACHING
;
3916 smb2_create_lease_buf(u8
*lease_key
, u8 oplock
)
3918 struct create_lease
*buf
;
3920 buf
= kzalloc(sizeof(struct create_lease
), GFP_KERNEL
);
3924 memcpy(&buf
->lcontext
.LeaseKey
, lease_key
, SMB2_LEASE_KEY_SIZE
);
3925 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
3927 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
3928 (struct create_lease
, lcontext
));
3929 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context
));
3930 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
3931 (struct create_lease
, Name
));
3932 buf
->ccontext
.NameLength
= cpu_to_le16(4);
3933 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
3942 smb3_create_lease_buf(u8
*lease_key
, u8 oplock
)
3944 struct create_lease_v2
*buf
;
3946 buf
= kzalloc(sizeof(struct create_lease_v2
), GFP_KERNEL
);
3950 memcpy(&buf
->lcontext
.LeaseKey
, lease_key
, SMB2_LEASE_KEY_SIZE
);
3951 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
3953 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
3954 (struct create_lease_v2
, lcontext
));
3955 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context_v2
));
3956 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
3957 (struct create_lease_v2
, Name
));
3958 buf
->ccontext
.NameLength
= cpu_to_le16(4);
3959 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
3968 smb2_parse_lease_buf(void *buf
, unsigned int *epoch
, char *lease_key
)
3970 struct create_lease
*lc
= (struct create_lease
*)buf
;
3972 *epoch
= 0; /* not used */
3973 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
3974 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
3975 return le32_to_cpu(lc
->lcontext
.LeaseState
);
3979 smb3_parse_lease_buf(void *buf
, unsigned int *epoch
, char *lease_key
)
3981 struct create_lease_v2
*lc
= (struct create_lease_v2
*)buf
;
3983 *epoch
= le16_to_cpu(lc
->lcontext
.Epoch
);
3984 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
3985 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
3987 memcpy(lease_key
, &lc
->lcontext
.LeaseKey
, SMB2_LEASE_KEY_SIZE
);
3988 return le32_to_cpu(lc
->lcontext
.LeaseState
);
3992 smb2_wp_retry_size(struct inode
*inode
)
3994 return min_t(unsigned int, CIFS_SB(inode
->i_sb
)->ctx
->wsize
,
3995 SMB2_MAX_BUFFER_SIZE
);
3999 smb2_dir_needs_close(struct cifsFileInfo
*cfile
)
4001 return !cfile
->invalidHandle
;
4005 fill_transform_hdr(struct smb2_transform_hdr
*tr_hdr
, unsigned int orig_len
,
4006 struct smb_rqst
*old_rq
, __le16 cipher_type
)
4008 struct smb2_sync_hdr
*shdr
=
4009 (struct smb2_sync_hdr
*)old_rq
->rq_iov
[0].iov_base
;
4011 memset(tr_hdr
, 0, sizeof(struct smb2_transform_hdr
));
4012 tr_hdr
->ProtocolId
= SMB2_TRANSFORM_PROTO_NUM
;
4013 tr_hdr
->OriginalMessageSize
= cpu_to_le32(orig_len
);
4014 tr_hdr
->Flags
= cpu_to_le16(0x01);
4015 if ((cipher_type
== SMB2_ENCRYPTION_AES128_GCM
) ||
4016 (cipher_type
== SMB2_ENCRYPTION_AES256_GCM
))
4017 get_random_bytes(&tr_hdr
->Nonce
, SMB3_AES_GCM_NONCE
);
4019 get_random_bytes(&tr_hdr
->Nonce
, SMB3_AES_CCM_NONCE
);
4020 memcpy(&tr_hdr
->SessionId
, &shdr
->SessionId
, 8);
4023 /* We can not use the normal sg_set_buf() as we will sometimes pass a
4024 * stack object as buf.
4026 static inline void smb2_sg_set_buf(struct scatterlist
*sg
, const void *buf
,
4027 unsigned int buflen
)
4031 * VMAP_STACK (at least) puts stack into the vmalloc address space
4033 if (is_vmalloc_addr(buf
))
4034 addr
= vmalloc_to_page(buf
);
4036 addr
= virt_to_page(buf
);
4037 sg_set_page(sg
, addr
, buflen
, offset_in_page(buf
));
4040 /* Assumes the first rqst has a transform header as the first iov.
4042 * rqst[0].rq_iov[0] is transform header
4043 * rqst[0].rq_iov[1+] data to be encrypted/decrypted
4044 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
4046 static struct scatterlist
*
4047 init_sg(int num_rqst
, struct smb_rqst
*rqst
, u8
*sign
)
4049 unsigned int sg_len
;
4050 struct scatterlist
*sg
;
4053 unsigned int idx
= 0;
4057 for (i
= 0; i
< num_rqst
; i
++)
4058 sg_len
+= rqst
[i
].rq_nvec
+ rqst
[i
].rq_npages
;
4060 sg
= kmalloc_array(sg_len
, sizeof(struct scatterlist
), GFP_KERNEL
);
4064 sg_init_table(sg
, sg_len
);
4065 for (i
= 0; i
< num_rqst
; i
++) {
4066 for (j
= 0; j
< rqst
[i
].rq_nvec
; j
++) {
4068 * The first rqst has a transform header where the
4069 * first 20 bytes are not part of the encrypted blob
4071 skip
= (i
== 0) && (j
== 0) ? 20 : 0;
4072 smb2_sg_set_buf(&sg
[idx
++],
4073 rqst
[i
].rq_iov
[j
].iov_base
+ skip
,
4074 rqst
[i
].rq_iov
[j
].iov_len
- skip
);
4077 for (j
= 0; j
< rqst
[i
].rq_npages
; j
++) {
4078 unsigned int len
, offset
;
4080 rqst_page_get_length(&rqst
[i
], j
, &len
, &offset
);
4081 sg_set_page(&sg
[idx
++], rqst
[i
].rq_pages
[j
], len
, offset
);
4084 smb2_sg_set_buf(&sg
[idx
], sign
, SMB2_SIGNATURE_SIZE
);
4089 smb2_get_enc_key(struct TCP_Server_Info
*server
, __u64 ses_id
, int enc
, u8
*key
)
4091 struct cifs_ses
*ses
;
4094 spin_lock(&cifs_tcp_ses_lock
);
4095 list_for_each_entry(server
, &cifs_tcp_ses_list
, tcp_ses_list
) {
4096 list_for_each_entry(ses
, &server
->smb_ses_list
, smb_ses_list
) {
4097 if (ses
->Suid
== ses_id
) {
4098 ses_enc_key
= enc
? ses
->smb3encryptionkey
:
4099 ses
->smb3decryptionkey
;
4100 memcpy(key
, ses_enc_key
, SMB3_SIGN_KEY_SIZE
);
4101 spin_unlock(&cifs_tcp_ses_lock
);
4106 spin_unlock(&cifs_tcp_ses_lock
);
4111 * Encrypt or decrypt @rqst message. @rqst[0] has the following format:
4112 * iov[0] - transform header (associate data),
4113 * iov[1-N] - SMB2 header and pages - data to encrypt.
4114 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
4118 crypt_message(struct TCP_Server_Info
*server
, int num_rqst
,
4119 struct smb_rqst
*rqst
, int enc
)
4121 struct smb2_transform_hdr
*tr_hdr
=
4122 (struct smb2_transform_hdr
*)rqst
[0].rq_iov
[0].iov_base
;
4123 unsigned int assoc_data_len
= sizeof(struct smb2_transform_hdr
) - 20;
4125 struct scatterlist
*sg
;
4126 u8 sign
[SMB2_SIGNATURE_SIZE
] = {};
4127 u8 key
[SMB3_SIGN_KEY_SIZE
];
4128 struct aead_request
*req
;
4130 unsigned int iv_len
;
4131 DECLARE_CRYPTO_WAIT(wait
);
4132 struct crypto_aead
*tfm
;
4133 unsigned int crypt_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
4135 rc
= smb2_get_enc_key(server
, tr_hdr
->SessionId
, enc
, key
);
4137 cifs_server_dbg(VFS
, "%s: Could not get %scryption key\n", __func__
,
4142 rc
= smb3_crypto_aead_allocate(server
);
4144 cifs_server_dbg(VFS
, "%s: crypto alloc failed\n", __func__
);
4148 tfm
= enc
? server
->secmech
.ccmaesencrypt
:
4149 server
->secmech
.ccmaesdecrypt
;
4151 if (server
->cipher_type
== SMB2_ENCRYPTION_AES256_GCM
)
4152 rc
= crypto_aead_setkey(tfm
, key
, SMB3_GCM256_CRYPTKEY_SIZE
);
4154 rc
= crypto_aead_setkey(tfm
, key
, SMB3_SIGN_KEY_SIZE
);
4157 cifs_server_dbg(VFS
, "%s: Failed to set aead key %d\n", __func__
, rc
);
4161 rc
= crypto_aead_setauthsize(tfm
, SMB2_SIGNATURE_SIZE
);
4163 cifs_server_dbg(VFS
, "%s: Failed to set authsize %d\n", __func__
, rc
);
4167 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
4169 cifs_server_dbg(VFS
, "%s: Failed to alloc aead request\n", __func__
);
4174 memcpy(sign
, &tr_hdr
->Signature
, SMB2_SIGNATURE_SIZE
);
4175 crypt_len
+= SMB2_SIGNATURE_SIZE
;
4178 sg
= init_sg(num_rqst
, rqst
, sign
);
4180 cifs_server_dbg(VFS
, "%s: Failed to init sg\n", __func__
);
4185 iv_len
= crypto_aead_ivsize(tfm
);
4186 iv
= kzalloc(iv_len
, GFP_KERNEL
);
4188 cifs_server_dbg(VFS
, "%s: Failed to alloc iv\n", __func__
);
4193 if ((server
->cipher_type
== SMB2_ENCRYPTION_AES128_GCM
) ||
4194 (server
->cipher_type
== SMB2_ENCRYPTION_AES256_GCM
))
4195 memcpy(iv
, (char *)tr_hdr
->Nonce
, SMB3_AES_GCM_NONCE
);
4198 memcpy(iv
+ 1, (char *)tr_hdr
->Nonce
, SMB3_AES_CCM_NONCE
);
4201 aead_request_set_crypt(req
, sg
, sg
, crypt_len
, iv
);
4202 aead_request_set_ad(req
, assoc_data_len
);
4204 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
4205 crypto_req_done
, &wait
);
4207 rc
= crypto_wait_req(enc
? crypto_aead_encrypt(req
)
4208 : crypto_aead_decrypt(req
), &wait
);
4211 memcpy(&tr_hdr
->Signature
, sign
, SMB2_SIGNATURE_SIZE
);
4222 smb3_free_compound_rqst(int num_rqst
, struct smb_rqst
*rqst
)
4226 for (i
= 0; i
< num_rqst
; i
++) {
4227 if (rqst
[i
].rq_pages
) {
4228 for (j
= rqst
[i
].rq_npages
- 1; j
>= 0; j
--)
4229 put_page(rqst
[i
].rq_pages
[j
]);
4230 kfree(rqst
[i
].rq_pages
);
4236 * This function will initialize new_rq and encrypt the content.
4237 * The first entry, new_rq[0], only contains a single iov which contains
4238 * a smb2_transform_hdr and is pre-allocated by the caller.
4239 * This function then populates new_rq[1+] with the content from olq_rq[0+].
4241 * The end result is an array of smb_rqst structures where the first structure
4242 * only contains a single iov for the transform header which we then can pass
4243 * to crypt_message().
4245 * new_rq[0].rq_iov[0] : smb2_transform_hdr pre-allocated by the caller
4246 * new_rq[1+].rq_iov[*] == old_rq[0+].rq_iov[*] : SMB2/3 requests
4249 smb3_init_transform_rq(struct TCP_Server_Info
*server
, int num_rqst
,
4250 struct smb_rqst
*new_rq
, struct smb_rqst
*old_rq
)
4252 struct page
**pages
;
4253 struct smb2_transform_hdr
*tr_hdr
= new_rq
[0].rq_iov
[0].iov_base
;
4254 unsigned int npages
;
4255 unsigned int orig_len
= 0;
4259 for (i
= 1; i
< num_rqst
; i
++) {
4260 npages
= old_rq
[i
- 1].rq_npages
;
4261 pages
= kmalloc_array(npages
, sizeof(struct page
*),
4266 new_rq
[i
].rq_pages
= pages
;
4267 new_rq
[i
].rq_npages
= npages
;
4268 new_rq
[i
].rq_offset
= old_rq
[i
- 1].rq_offset
;
4269 new_rq
[i
].rq_pagesz
= old_rq
[i
- 1].rq_pagesz
;
4270 new_rq
[i
].rq_tailsz
= old_rq
[i
- 1].rq_tailsz
;
4271 new_rq
[i
].rq_iov
= old_rq
[i
- 1].rq_iov
;
4272 new_rq
[i
].rq_nvec
= old_rq
[i
- 1].rq_nvec
;
4274 orig_len
+= smb_rqst_len(server
, &old_rq
[i
- 1]);
4276 for (j
= 0; j
< npages
; j
++) {
4277 pages
[j
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
4282 /* copy pages form the old */
4283 for (j
= 0; j
< npages
; j
++) {
4285 unsigned int offset
, len
;
4287 rqst_page_get_length(&new_rq
[i
], j
, &len
, &offset
);
4289 dst
= (char *) kmap(new_rq
[i
].rq_pages
[j
]) + offset
;
4290 src
= (char *) kmap(old_rq
[i
- 1].rq_pages
[j
]) + offset
;
4292 memcpy(dst
, src
, len
);
4293 kunmap(new_rq
[i
].rq_pages
[j
]);
4294 kunmap(old_rq
[i
- 1].rq_pages
[j
]);
4298 /* fill the 1st iov with a transform header */
4299 fill_transform_hdr(tr_hdr
, orig_len
, old_rq
, server
->cipher_type
);
4301 rc
= crypt_message(server
, num_rqst
, new_rq
, 1);
4302 cifs_dbg(FYI
, "Encrypt message returned %d\n", rc
);
4309 smb3_free_compound_rqst(num_rqst
- 1, &new_rq
[1]);
4314 smb3_is_transform_hdr(void *buf
)
4316 struct smb2_transform_hdr
*trhdr
= buf
;
4318 return trhdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
;
4322 decrypt_raw_data(struct TCP_Server_Info
*server
, char *buf
,
4323 unsigned int buf_data_size
, struct page
**pages
,
4324 unsigned int npages
, unsigned int page_data_size
,
4328 struct smb_rqst rqst
= {NULL
};
4331 iov
[0].iov_base
= buf
;
4332 iov
[0].iov_len
= sizeof(struct smb2_transform_hdr
);
4333 iov
[1].iov_base
= buf
+ sizeof(struct smb2_transform_hdr
);
4334 iov
[1].iov_len
= buf_data_size
;
4338 rqst
.rq_pages
= pages
;
4339 rqst
.rq_npages
= npages
;
4340 rqst
.rq_pagesz
= PAGE_SIZE
;
4341 rqst
.rq_tailsz
= (page_data_size
% PAGE_SIZE
) ? : PAGE_SIZE
;
4343 rc
= crypt_message(server
, 1, &rqst
, 0);
4344 cifs_dbg(FYI
, "Decrypt message returned %d\n", rc
);
4349 memmove(buf
, iov
[1].iov_base
, buf_data_size
);
4352 server
->total_read
= buf_data_size
+ page_data_size
;
4358 read_data_into_pages(struct TCP_Server_Info
*server
, struct page
**pages
,
4359 unsigned int npages
, unsigned int len
)
4364 for (i
= 0; i
< npages
; i
++) {
4365 struct page
*page
= pages
[i
];
4369 if (len
>= PAGE_SIZE
) {
4370 /* enough data to fill the page */
4374 zero_user(page
, len
, PAGE_SIZE
- len
);
4377 length
= cifs_read_page_from_socket(server
, page
, 0, n
);
4380 server
->total_read
+= length
;
4387 init_read_bvec(struct page
**pages
, unsigned int npages
, unsigned int data_size
,
4388 unsigned int cur_off
, struct bio_vec
**page_vec
)
4390 struct bio_vec
*bvec
;
4393 bvec
= kcalloc(npages
, sizeof(struct bio_vec
), GFP_KERNEL
);
4397 for (i
= 0; i
< npages
; i
++) {
4398 bvec
[i
].bv_page
= pages
[i
];
4399 bvec
[i
].bv_offset
= (i
== 0) ? cur_off
: 0;
4400 bvec
[i
].bv_len
= min_t(unsigned int, PAGE_SIZE
, data_size
);
4401 data_size
-= bvec
[i
].bv_len
;
4404 if (data_size
!= 0) {
4405 cifs_dbg(VFS
, "%s: something went wrong\n", __func__
);
4415 handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
,
4416 char *buf
, unsigned int buf_len
, struct page
**pages
,
4417 unsigned int npages
, unsigned int page_data_size
,
4420 unsigned int data_offset
;
4421 unsigned int data_len
;
4422 unsigned int cur_off
;
4423 unsigned int cur_page_idx
;
4424 unsigned int pad_len
;
4425 struct cifs_readdata
*rdata
= mid
->callback_data
;
4426 struct smb2_sync_hdr
*shdr
= (struct smb2_sync_hdr
*)buf
;
4427 struct bio_vec
*bvec
= NULL
;
4428 struct iov_iter iter
;
4431 bool use_rdma_mr
= false;
4433 if (shdr
->Command
!= SMB2_READ
) {
4434 cifs_server_dbg(VFS
, "only big read responses are supported\n");
4438 if (server
->ops
->is_session_expired
&&
4439 server
->ops
->is_session_expired(buf
)) {
4441 cifs_reconnect(server
);
4445 if (server
->ops
->is_status_pending
&&
4446 server
->ops
->is_status_pending(buf
, server
))
4449 /* set up first two iov to get credits */
4450 rdata
->iov
[0].iov_base
= buf
;
4451 rdata
->iov
[0].iov_len
= 0;
4452 rdata
->iov
[1].iov_base
= buf
;
4453 rdata
->iov
[1].iov_len
=
4454 min_t(unsigned int, buf_len
, server
->vals
->read_rsp_size
);
4455 cifs_dbg(FYI
, "0: iov_base=%p iov_len=%zu\n",
4456 rdata
->iov
[0].iov_base
, rdata
->iov
[0].iov_len
);
4457 cifs_dbg(FYI
, "1: iov_base=%p iov_len=%zu\n",
4458 rdata
->iov
[1].iov_base
, rdata
->iov
[1].iov_len
);
4460 rdata
->result
= server
->ops
->map_error(buf
, true);
4461 if (rdata
->result
!= 0) {
4462 cifs_dbg(FYI
, "%s: server returned error %d\n",
4463 __func__
, rdata
->result
);
4464 /* normal error on read response */
4466 mid
->mid_state
= MID_RESPONSE_RECEIVED
;
4468 dequeue_mid(mid
, false);
4472 data_offset
= server
->ops
->read_data_offset(buf
);
4473 #ifdef CONFIG_CIFS_SMB_DIRECT
4474 use_rdma_mr
= rdata
->mr
;
4476 data_len
= server
->ops
->read_data_length(buf
, use_rdma_mr
);
4478 if (data_offset
< server
->vals
->read_rsp_size
) {
4480 * win2k8 sometimes sends an offset of 0 when the read
4481 * is beyond the EOF. Treat it as if the data starts just after
4484 cifs_dbg(FYI
, "%s: data offset (%u) inside read response header\n",
4485 __func__
, data_offset
);
4486 data_offset
= server
->vals
->read_rsp_size
;
4487 } else if (data_offset
> MAX_CIFS_SMALL_BUFFER_SIZE
) {
4488 /* data_offset is beyond the end of smallbuf */
4489 cifs_dbg(FYI
, "%s: data offset (%u) beyond end of smallbuf\n",
4490 __func__
, data_offset
);
4491 rdata
->result
= -EIO
;
4493 mid
->mid_state
= MID_RESPONSE_MALFORMED
;
4495 dequeue_mid(mid
, rdata
->result
);
4499 pad_len
= data_offset
- server
->vals
->read_rsp_size
;
4501 if (buf_len
<= data_offset
) {
4502 /* read response payload is in pages */
4503 cur_page_idx
= pad_len
/ PAGE_SIZE
;
4504 cur_off
= pad_len
% PAGE_SIZE
;
4506 if (cur_page_idx
!= 0) {
4507 /* data offset is beyond the 1st page of response */
4508 cifs_dbg(FYI
, "%s: data offset (%u) beyond 1st page of response\n",
4509 __func__
, data_offset
);
4510 rdata
->result
= -EIO
;
4512 mid
->mid_state
= MID_RESPONSE_MALFORMED
;
4514 dequeue_mid(mid
, rdata
->result
);
4518 if (data_len
> page_data_size
- pad_len
) {
4519 /* data_len is corrupt -- discard frame */
4520 rdata
->result
= -EIO
;
4522 mid
->mid_state
= MID_RESPONSE_MALFORMED
;
4524 dequeue_mid(mid
, rdata
->result
);
4528 rdata
->result
= init_read_bvec(pages
, npages
, page_data_size
,
4530 if (rdata
->result
!= 0) {
4532 mid
->mid_state
= MID_RESPONSE_MALFORMED
;
4534 dequeue_mid(mid
, rdata
->result
);
4538 iov_iter_bvec(&iter
, WRITE
, bvec
, npages
, data_len
);
4539 } else if (buf_len
>= data_offset
+ data_len
) {
4540 /* read response payload is in buf */
4541 WARN_ONCE(npages
> 0, "read data can be either in buf or in pages");
4542 iov
.iov_base
= buf
+ data_offset
;
4543 iov
.iov_len
= data_len
;
4544 iov_iter_kvec(&iter
, WRITE
, &iov
, 1, data_len
);
4546 /* read response payload cannot be in both buf and pages */
4547 WARN_ONCE(1, "buf can not contain only a part of read data");
4548 rdata
->result
= -EIO
;
4550 mid
->mid_state
= MID_RESPONSE_MALFORMED
;
4552 dequeue_mid(mid
, rdata
->result
);
4556 length
= rdata
->copy_into_pages(server
, rdata
, &iter
);
4564 mid
->mid_state
= MID_RESPONSE_RECEIVED
;
4566 dequeue_mid(mid
, false);
4570 struct smb2_decrypt_work
{
4571 struct work_struct decrypt
;
4572 struct TCP_Server_Info
*server
;
4573 struct page
**ppages
;
4575 unsigned int npages
;
4580 static void smb2_decrypt_offload(struct work_struct
*work
)
4582 struct smb2_decrypt_work
*dw
= container_of(work
,
4583 struct smb2_decrypt_work
, decrypt
);
4585 struct mid_q_entry
*mid
;
4587 rc
= decrypt_raw_data(dw
->server
, dw
->buf
, dw
->server
->vals
->read_rsp_size
,
4588 dw
->ppages
, dw
->npages
, dw
->len
, true);
4590 cifs_dbg(VFS
, "error decrypting rc=%d\n", rc
);
4594 dw
->server
->lstrp
= jiffies
;
4595 mid
= smb2_find_dequeue_mid(dw
->server
, dw
->buf
);
4597 cifs_dbg(FYI
, "mid not found\n");
4599 mid
->decrypted
= true;
4600 rc
= handle_read_data(dw
->server
, mid
, dw
->buf
,
4601 dw
->server
->vals
->read_rsp_size
,
4602 dw
->ppages
, dw
->npages
, dw
->len
,
4605 #ifdef CONFIG_CIFS_STATS2
4606 mid
->when_received
= jiffies
;
4610 spin_lock(&GlobalMid_Lock
);
4611 if (dw
->server
->tcpStatus
== CifsNeedReconnect
) {
4612 mid
->mid_state
= MID_RETRY_NEEDED
;
4613 spin_unlock(&GlobalMid_Lock
);
4616 mid
->mid_state
= MID_REQUEST_SUBMITTED
;
4617 mid
->mid_flags
&= ~(MID_DELETED
);
4618 list_add_tail(&mid
->qhead
,
4619 &dw
->server
->pending_mid_q
);
4620 spin_unlock(&GlobalMid_Lock
);
4623 cifs_mid_q_entry_release(mid
);
4627 for (i
= dw
->npages
-1; i
>= 0; i
--)
4628 put_page(dw
->ppages
[i
]);
4631 cifs_small_buf_release(dw
->buf
);
4637 receive_encrypted_read(struct TCP_Server_Info
*server
, struct mid_q_entry
**mid
,
4640 char *buf
= server
->smallbuf
;
4641 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
4642 unsigned int npages
;
4643 struct page
**pages
;
4645 unsigned int buflen
= server
->pdu_size
;
4648 struct smb2_decrypt_work
*dw
;
4651 len
= min_t(unsigned int, buflen
, server
->vals
->read_rsp_size
+
4652 sizeof(struct smb2_transform_hdr
)) - HEADER_SIZE(server
) + 1;
4654 rc
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1, len
);
4657 server
->total_read
+= rc
;
4659 len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
) -
4660 server
->vals
->read_rsp_size
;
4661 npages
= DIV_ROUND_UP(len
, PAGE_SIZE
);
4663 pages
= kmalloc_array(npages
, sizeof(struct page
*), GFP_KERNEL
);
4669 for (; i
< npages
; i
++) {
4670 pages
[i
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
4677 /* read read data into pages */
4678 rc
= read_data_into_pages(server
, pages
, npages
, len
);
4682 rc
= cifs_discard_remaining_data(server
);
4687 * For large reads, offload to different thread for better performance,
4688 * use more cores decrypting which can be expensive
4691 if ((server
->min_offload
) && (server
->in_flight
> 1) &&
4692 (server
->pdu_size
>= server
->min_offload
)) {
4693 dw
= kmalloc(sizeof(struct smb2_decrypt_work
), GFP_KERNEL
);
4695 goto non_offloaded_decrypt
;
4697 dw
->buf
= server
->smallbuf
;
4698 server
->smallbuf
= (char *)cifs_small_buf_get();
4700 INIT_WORK(&dw
->decrypt
, smb2_decrypt_offload
);
4702 dw
->npages
= npages
;
4703 dw
->server
= server
;
4706 queue_work(decrypt_wq
, &dw
->decrypt
);
4707 *num_mids
= 0; /* worker thread takes care of finding mid */
4711 non_offloaded_decrypt
:
4712 rc
= decrypt_raw_data(server
, buf
, server
->vals
->read_rsp_size
,
4713 pages
, npages
, len
, false);
4717 *mid
= smb2_find_mid(server
, buf
);
4719 cifs_dbg(FYI
, "mid not found\n");
4721 cifs_dbg(FYI
, "mid found\n");
4722 (*mid
)->decrypted
= true;
4723 rc
= handle_read_data(server
, *mid
, buf
,
4724 server
->vals
->read_rsp_size
,
4725 pages
, npages
, len
, false);
4729 for (i
= i
- 1; i
>= 0; i
--)
4734 cifs_discard_remaining_data(server
);
4739 receive_encrypted_standard(struct TCP_Server_Info
*server
,
4740 struct mid_q_entry
**mids
, char **bufs
,
4744 char *buf
= server
->smallbuf
;
4745 struct smb2_sync_hdr
*shdr
;
4746 unsigned int pdu_length
= server
->pdu_size
;
4747 unsigned int buf_size
;
4748 struct mid_q_entry
*mid_entry
;
4750 char *next_buffer
= NULL
;
4754 /* switch to large buffer if too big for a small one */
4755 if (pdu_length
> MAX_CIFS_SMALL_BUFFER_SIZE
) {
4756 server
->large_buf
= true;
4757 memcpy(server
->bigbuf
, buf
, server
->total_read
);
4758 buf
= server
->bigbuf
;
4761 /* now read the rest */
4762 length
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1,
4763 pdu_length
- HEADER_SIZE(server
) + 1);
4766 server
->total_read
+= length
;
4768 buf_size
= pdu_length
- sizeof(struct smb2_transform_hdr
);
4769 length
= decrypt_raw_data(server
, buf
, buf_size
, NULL
, 0, 0, false);
4773 next_is_large
= server
->large_buf
;
4775 shdr
= (struct smb2_sync_hdr
*)buf
;
4776 if (shdr
->NextCommand
) {
4778 next_buffer
= (char *)cifs_buf_get();
4780 next_buffer
= (char *)cifs_small_buf_get();
4782 buf
+ le32_to_cpu(shdr
->NextCommand
),
4783 pdu_length
- le32_to_cpu(shdr
->NextCommand
));
4786 mid_entry
= smb2_find_mid(server
, buf
);
4787 if (mid_entry
== NULL
)
4788 cifs_dbg(FYI
, "mid not found\n");
4790 cifs_dbg(FYI
, "mid found\n");
4791 mid_entry
->decrypted
= true;
4792 mid_entry
->resp_buf_size
= server
->pdu_size
;
4795 if (*num_mids
>= MAX_COMPOUND
) {
4796 cifs_server_dbg(VFS
, "too many PDUs in compound\n");
4799 bufs
[*num_mids
] = buf
;
4800 mids
[(*num_mids
)++] = mid_entry
;
4802 if (mid_entry
&& mid_entry
->handle
)
4803 ret
= mid_entry
->handle(server
, mid_entry
);
4805 ret
= cifs_handle_standard(server
, mid_entry
);
4807 if (ret
== 0 && shdr
->NextCommand
) {
4808 pdu_length
-= le32_to_cpu(shdr
->NextCommand
);
4809 server
->large_buf
= next_is_large
;
4811 server
->bigbuf
= buf
= next_buffer
;
4813 server
->smallbuf
= buf
= next_buffer
;
4815 } else if (ret
!= 0) {
4817 * ret != 0 here means that we didn't get to handle_mid() thus
4818 * server->smallbuf and server->bigbuf are still valid. We need
4819 * to free next_buffer because it is not going to be used
4823 free_rsp_buf(CIFS_LARGE_BUFFER
, next_buffer
);
4825 free_rsp_buf(CIFS_SMALL_BUFFER
, next_buffer
);
4832 smb3_receive_transform(struct TCP_Server_Info
*server
,
4833 struct mid_q_entry
**mids
, char **bufs
, int *num_mids
)
4835 char *buf
= server
->smallbuf
;
4836 unsigned int pdu_length
= server
->pdu_size
;
4837 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
4838 unsigned int orig_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
4840 if (pdu_length
< sizeof(struct smb2_transform_hdr
) +
4841 sizeof(struct smb2_sync_hdr
)) {
4842 cifs_server_dbg(VFS
, "Transform message is too small (%u)\n",
4844 cifs_reconnect(server
);
4845 return -ECONNABORTED
;
4848 if (pdu_length
< orig_len
+ sizeof(struct smb2_transform_hdr
)) {
4849 cifs_server_dbg(VFS
, "Transform message is broken\n");
4850 cifs_reconnect(server
);
4851 return -ECONNABORTED
;
4854 /* TODO: add support for compounds containing READ. */
4855 if (pdu_length
> CIFSMaxBufSize
+ MAX_HEADER_SIZE(server
)) {
4856 return receive_encrypted_read(server
, &mids
[0], num_mids
);
4859 return receive_encrypted_standard(server
, mids
, bufs
, num_mids
);
4863 smb3_handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
)
4865 char *buf
= server
->large_buf
? server
->bigbuf
: server
->smallbuf
;
4867 return handle_read_data(server
, mid
, buf
, server
->pdu_size
,
4872 smb2_next_header(char *buf
)
4874 struct smb2_sync_hdr
*hdr
= (struct smb2_sync_hdr
*)buf
;
4875 struct smb2_transform_hdr
*t_hdr
= (struct smb2_transform_hdr
*)buf
;
4877 if (hdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
)
4878 return sizeof(struct smb2_transform_hdr
) +
4879 le32_to_cpu(t_hdr
->OriginalMessageSize
);
4881 return le32_to_cpu(hdr
->NextCommand
);
4885 smb2_make_node(unsigned int xid
, struct inode
*inode
,
4886 struct dentry
*dentry
, struct cifs_tcon
*tcon
,
4887 char *full_path
, umode_t mode
, dev_t dev
)
4889 struct cifs_sb_info
*cifs_sb
= CIFS_SB(inode
->i_sb
);
4891 FILE_ALL_INFO
*buf
= NULL
;
4892 struct cifs_io_parms io_parms
= {0};
4894 struct cifs_fid fid
;
4895 struct cifs_open_parms oparms
;
4896 unsigned int bytes_written
;
4897 struct win_dev
*pdev
;
4901 * Check if mounted with mount parm 'sfu' mount parm.
4902 * SFU emulation should work with all servers, but only
4903 * supports block and char device (no socket & fifo),
4904 * and was used by default in earlier versions of Windows
4906 if (!(cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_UNX_EMUL
))
4910 * TODO: Add ability to create instead via reparse point. Windows (e.g.
4911 * their current NFS server) uses this approach to expose special files
4912 * over SMB2/SMB3 and Samba will do this with SMB3.1.1 POSIX Extensions
4915 if (!S_ISCHR(mode
) && !S_ISBLK(mode
))
4918 cifs_dbg(FYI
, "sfu compat create special file\n");
4920 buf
= kmalloc(sizeof(FILE_ALL_INFO
), GFP_KERNEL
);
4927 oparms
.cifs_sb
= cifs_sb
;
4928 oparms
.desired_access
= GENERIC_WRITE
;
4929 oparms
.create_options
= cifs_create_options(cifs_sb
, CREATE_NOT_DIR
|
4930 CREATE_OPTION_SPECIAL
);
4931 oparms
.disposition
= FILE_CREATE
;
4932 oparms
.path
= full_path
;
4934 oparms
.reconnect
= false;
4936 if (tcon
->ses
->server
->oplocks
)
4937 oplock
= REQ_OPLOCK
;
4940 rc
= tcon
->ses
->server
->ops
->open(xid
, &oparms
, &oplock
, buf
);
4945 * BB Do not bother to decode buf since no local inode yet to put
4946 * timestamps in, but we can reuse it safely.
4949 pdev
= (struct win_dev
*)buf
;
4950 io_parms
.pid
= current
->tgid
;
4951 io_parms
.tcon
= tcon
;
4952 io_parms
.offset
= 0;
4953 io_parms
.length
= sizeof(struct win_dev
);
4954 iov
[1].iov_base
= buf
;
4955 iov
[1].iov_len
= sizeof(struct win_dev
);
4956 if (S_ISCHR(mode
)) {
4957 memcpy(pdev
->type
, "IntxCHR", 8);
4958 pdev
->major
= cpu_to_le64(MAJOR(dev
));
4959 pdev
->minor
= cpu_to_le64(MINOR(dev
));
4960 rc
= tcon
->ses
->server
->ops
->sync_write(xid
, &fid
, &io_parms
,
4961 &bytes_written
, iov
, 1);
4962 } else if (S_ISBLK(mode
)) {
4963 memcpy(pdev
->type
, "IntxBLK", 8);
4964 pdev
->major
= cpu_to_le64(MAJOR(dev
));
4965 pdev
->minor
= cpu_to_le64(MINOR(dev
));
4966 rc
= tcon
->ses
->server
->ops
->sync_write(xid
, &fid
, &io_parms
,
4967 &bytes_written
, iov
, 1);
4969 tcon
->ses
->server
->ops
->close(xid
, tcon
, &fid
);
4972 /* FIXME: add code here to set EAs */
4979 struct smb_version_operations smb20_operations
= {
4980 .compare_fids
= smb2_compare_fids
,
4981 .setup_request
= smb2_setup_request
,
4982 .setup_async_request
= smb2_setup_async_request
,
4983 .check_receive
= smb2_check_receive
,
4984 .add_credits
= smb2_add_credits
,
4985 .set_credits
= smb2_set_credits
,
4986 .get_credits_field
= smb2_get_credits_field
,
4987 .get_credits
= smb2_get_credits
,
4988 .wait_mtu_credits
= cifs_wait_mtu_credits
,
4989 .get_next_mid
= smb2_get_next_mid
,
4990 .revert_current_mid
= smb2_revert_current_mid
,
4991 .read_data_offset
= smb2_read_data_offset
,
4992 .read_data_length
= smb2_read_data_length
,
4993 .map_error
= map_smb2_to_linux_error
,
4994 .find_mid
= smb2_find_mid
,
4995 .check_message
= smb2_check_message
,
4996 .dump_detail
= smb2_dump_detail
,
4997 .clear_stats
= smb2_clear_stats
,
4998 .print_stats
= smb2_print_stats
,
4999 .is_oplock_break
= smb2_is_valid_oplock_break
,
5000 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
5001 .downgrade_oplock
= smb2_downgrade_oplock
,
5002 .need_neg
= smb2_need_neg
,
5003 .negotiate
= smb2_negotiate
,
5004 .negotiate_wsize
= smb2_negotiate_wsize
,
5005 .negotiate_rsize
= smb2_negotiate_rsize
,
5006 .sess_setup
= SMB2_sess_setup
,
5007 .logoff
= SMB2_logoff
,
5008 .tree_connect
= SMB2_tcon
,
5009 .tree_disconnect
= SMB2_tdis
,
5010 .qfs_tcon
= smb2_qfs_tcon
,
5011 .is_path_accessible
= smb2_is_path_accessible
,
5012 .can_echo
= smb2_can_echo
,
5014 .query_path_info
= smb2_query_path_info
,
5015 .get_srv_inum
= smb2_get_srv_inum
,
5016 .query_file_info
= smb2_query_file_info
,
5017 .set_path_size
= smb2_set_path_size
,
5018 .set_file_size
= smb2_set_file_size
,
5019 .set_file_info
= smb2_set_file_info
,
5020 .set_compression
= smb2_set_compression
,
5021 .mkdir
= smb2_mkdir
,
5022 .mkdir_setinfo
= smb2_mkdir_setinfo
,
5023 .rmdir
= smb2_rmdir
,
5024 .unlink
= smb2_unlink
,
5025 .rename
= smb2_rename_path
,
5026 .create_hardlink
= smb2_create_hardlink
,
5027 .query_symlink
= smb2_query_symlink
,
5028 .query_mf_symlink
= smb3_query_mf_symlink
,
5029 .create_mf_symlink
= smb3_create_mf_symlink
,
5030 .open
= smb2_open_file
,
5031 .set_fid
= smb2_set_fid
,
5032 .close
= smb2_close_file
,
5033 .flush
= smb2_flush_file
,
5034 .async_readv
= smb2_async_readv
,
5035 .async_writev
= smb2_async_writev
,
5036 .sync_read
= smb2_sync_read
,
5037 .sync_write
= smb2_sync_write
,
5038 .query_dir_first
= smb2_query_dir_first
,
5039 .query_dir_next
= smb2_query_dir_next
,
5040 .close_dir
= smb2_close_dir
,
5041 .calc_smb_size
= smb2_calc_size
,
5042 .is_status_pending
= smb2_is_status_pending
,
5043 .is_session_expired
= smb2_is_session_expired
,
5044 .oplock_response
= smb2_oplock_response
,
5045 .queryfs
= smb2_queryfs
,
5046 .mand_lock
= smb2_mand_lock
,
5047 .mand_unlock_range
= smb2_unlock_range
,
5048 .push_mand_locks
= smb2_push_mandatory_locks
,
5049 .get_lease_key
= smb2_get_lease_key
,
5050 .set_lease_key
= smb2_set_lease_key
,
5051 .new_lease_key
= smb2_new_lease_key
,
5052 .calc_signature
= smb2_calc_signature
,
5053 .is_read_op
= smb2_is_read_op
,
5054 .set_oplock_level
= smb2_set_oplock_level
,
5055 .create_lease_buf
= smb2_create_lease_buf
,
5056 .parse_lease_buf
= smb2_parse_lease_buf
,
5057 .copychunk_range
= smb2_copychunk_range
,
5058 .wp_retry_size
= smb2_wp_retry_size
,
5059 .dir_needs_close
= smb2_dir_needs_close
,
5060 .get_dfs_refer
= smb2_get_dfs_refer
,
5061 .select_sectype
= smb2_select_sectype
,
5062 #ifdef CONFIG_CIFS_XATTR
5063 .query_all_EAs
= smb2_query_eas
,
5064 .set_EA
= smb2_set_ea
,
5065 #endif /* CIFS_XATTR */
5066 .get_acl
= get_smb2_acl
,
5067 .get_acl_by_fid
= get_smb2_acl_by_fid
,
5068 .set_acl
= set_smb2_acl
,
5069 .next_header
= smb2_next_header
,
5070 .ioctl_query_info
= smb2_ioctl_query_info
,
5071 .make_node
= smb2_make_node
,
5072 .fiemap
= smb3_fiemap
,
5073 .llseek
= smb3_llseek
,
5074 .is_status_io_timeout
= smb2_is_status_io_timeout
,
5077 struct smb_version_operations smb21_operations
= {
5078 .compare_fids
= smb2_compare_fids
,
5079 .setup_request
= smb2_setup_request
,
5080 .setup_async_request
= smb2_setup_async_request
,
5081 .check_receive
= smb2_check_receive
,
5082 .add_credits
= smb2_add_credits
,
5083 .set_credits
= smb2_set_credits
,
5084 .get_credits_field
= smb2_get_credits_field
,
5085 .get_credits
= smb2_get_credits
,
5086 .wait_mtu_credits
= smb2_wait_mtu_credits
,
5087 .adjust_credits
= smb2_adjust_credits
,
5088 .get_next_mid
= smb2_get_next_mid
,
5089 .revert_current_mid
= smb2_revert_current_mid
,
5090 .read_data_offset
= smb2_read_data_offset
,
5091 .read_data_length
= smb2_read_data_length
,
5092 .map_error
= map_smb2_to_linux_error
,
5093 .find_mid
= smb2_find_mid
,
5094 .check_message
= smb2_check_message
,
5095 .dump_detail
= smb2_dump_detail
,
5096 .clear_stats
= smb2_clear_stats
,
5097 .print_stats
= smb2_print_stats
,
5098 .is_oplock_break
= smb2_is_valid_oplock_break
,
5099 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
5100 .downgrade_oplock
= smb2_downgrade_oplock
,
5101 .need_neg
= smb2_need_neg
,
5102 .negotiate
= smb2_negotiate
,
5103 .negotiate_wsize
= smb2_negotiate_wsize
,
5104 .negotiate_rsize
= smb2_negotiate_rsize
,
5105 .sess_setup
= SMB2_sess_setup
,
5106 .logoff
= SMB2_logoff
,
5107 .tree_connect
= SMB2_tcon
,
5108 .tree_disconnect
= SMB2_tdis
,
5109 .qfs_tcon
= smb2_qfs_tcon
,
5110 .is_path_accessible
= smb2_is_path_accessible
,
5111 .can_echo
= smb2_can_echo
,
5113 .query_path_info
= smb2_query_path_info
,
5114 .get_srv_inum
= smb2_get_srv_inum
,
5115 .query_file_info
= smb2_query_file_info
,
5116 .set_path_size
= smb2_set_path_size
,
5117 .set_file_size
= smb2_set_file_size
,
5118 .set_file_info
= smb2_set_file_info
,
5119 .set_compression
= smb2_set_compression
,
5120 .mkdir
= smb2_mkdir
,
5121 .mkdir_setinfo
= smb2_mkdir_setinfo
,
5122 .rmdir
= smb2_rmdir
,
5123 .unlink
= smb2_unlink
,
5124 .rename
= smb2_rename_path
,
5125 .create_hardlink
= smb2_create_hardlink
,
5126 .query_symlink
= smb2_query_symlink
,
5127 .query_mf_symlink
= smb3_query_mf_symlink
,
5128 .create_mf_symlink
= smb3_create_mf_symlink
,
5129 .open
= smb2_open_file
,
5130 .set_fid
= smb2_set_fid
,
5131 .close
= smb2_close_file
,
5132 .flush
= smb2_flush_file
,
5133 .async_readv
= smb2_async_readv
,
5134 .async_writev
= smb2_async_writev
,
5135 .sync_read
= smb2_sync_read
,
5136 .sync_write
= smb2_sync_write
,
5137 .query_dir_first
= smb2_query_dir_first
,
5138 .query_dir_next
= smb2_query_dir_next
,
5139 .close_dir
= smb2_close_dir
,
5140 .calc_smb_size
= smb2_calc_size
,
5141 .is_status_pending
= smb2_is_status_pending
,
5142 .is_session_expired
= smb2_is_session_expired
,
5143 .oplock_response
= smb2_oplock_response
,
5144 .queryfs
= smb2_queryfs
,
5145 .mand_lock
= smb2_mand_lock
,
5146 .mand_unlock_range
= smb2_unlock_range
,
5147 .push_mand_locks
= smb2_push_mandatory_locks
,
5148 .get_lease_key
= smb2_get_lease_key
,
5149 .set_lease_key
= smb2_set_lease_key
,
5150 .new_lease_key
= smb2_new_lease_key
,
5151 .calc_signature
= smb2_calc_signature
,
5152 .is_read_op
= smb21_is_read_op
,
5153 .set_oplock_level
= smb21_set_oplock_level
,
5154 .create_lease_buf
= smb2_create_lease_buf
,
5155 .parse_lease_buf
= smb2_parse_lease_buf
,
5156 .copychunk_range
= smb2_copychunk_range
,
5157 .wp_retry_size
= smb2_wp_retry_size
,
5158 .dir_needs_close
= smb2_dir_needs_close
,
5159 .enum_snapshots
= smb3_enum_snapshots
,
5160 .notify
= smb3_notify
,
5161 .get_dfs_refer
= smb2_get_dfs_refer
,
5162 .select_sectype
= smb2_select_sectype
,
5163 #ifdef CONFIG_CIFS_XATTR
5164 .query_all_EAs
= smb2_query_eas
,
5165 .set_EA
= smb2_set_ea
,
5166 #endif /* CIFS_XATTR */
5167 .get_acl
= get_smb2_acl
,
5168 .get_acl_by_fid
= get_smb2_acl_by_fid
,
5169 .set_acl
= set_smb2_acl
,
5170 .next_header
= smb2_next_header
,
5171 .ioctl_query_info
= smb2_ioctl_query_info
,
5172 .make_node
= smb2_make_node
,
5173 .fiemap
= smb3_fiemap
,
5174 .llseek
= smb3_llseek
,
5175 .is_status_io_timeout
= smb2_is_status_io_timeout
,
5178 struct smb_version_operations smb30_operations
= {
5179 .compare_fids
= smb2_compare_fids
,
5180 .setup_request
= smb2_setup_request
,
5181 .setup_async_request
= smb2_setup_async_request
,
5182 .check_receive
= smb2_check_receive
,
5183 .add_credits
= smb2_add_credits
,
5184 .set_credits
= smb2_set_credits
,
5185 .get_credits_field
= smb2_get_credits_field
,
5186 .get_credits
= smb2_get_credits
,
5187 .wait_mtu_credits
= smb2_wait_mtu_credits
,
5188 .adjust_credits
= smb2_adjust_credits
,
5189 .get_next_mid
= smb2_get_next_mid
,
5190 .revert_current_mid
= smb2_revert_current_mid
,
5191 .read_data_offset
= smb2_read_data_offset
,
5192 .read_data_length
= smb2_read_data_length
,
5193 .map_error
= map_smb2_to_linux_error
,
5194 .find_mid
= smb2_find_mid
,
5195 .check_message
= smb2_check_message
,
5196 .dump_detail
= smb2_dump_detail
,
5197 .clear_stats
= smb2_clear_stats
,
5198 .print_stats
= smb2_print_stats
,
5199 .dump_share_caps
= smb2_dump_share_caps
,
5200 .is_oplock_break
= smb2_is_valid_oplock_break
,
5201 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
5202 .downgrade_oplock
= smb3_downgrade_oplock
,
5203 .need_neg
= smb2_need_neg
,
5204 .negotiate
= smb2_negotiate
,
5205 .negotiate_wsize
= smb3_negotiate_wsize
,
5206 .negotiate_rsize
= smb3_negotiate_rsize
,
5207 .sess_setup
= SMB2_sess_setup
,
5208 .logoff
= SMB2_logoff
,
5209 .tree_connect
= SMB2_tcon
,
5210 .tree_disconnect
= SMB2_tdis
,
5211 .qfs_tcon
= smb3_qfs_tcon
,
5212 .is_path_accessible
= smb2_is_path_accessible
,
5213 .can_echo
= smb2_can_echo
,
5215 .query_path_info
= smb2_query_path_info
,
5216 /* WSL tags introduced long after smb2.1, enable for SMB3, 3.11 only */
5217 .query_reparse_tag
= smb2_query_reparse_tag
,
5218 .get_srv_inum
= smb2_get_srv_inum
,
5219 .query_file_info
= smb2_query_file_info
,
5220 .set_path_size
= smb2_set_path_size
,
5221 .set_file_size
= smb2_set_file_size
,
5222 .set_file_info
= smb2_set_file_info
,
5223 .set_compression
= smb2_set_compression
,
5224 .mkdir
= smb2_mkdir
,
5225 .mkdir_setinfo
= smb2_mkdir_setinfo
,
5226 .rmdir
= smb2_rmdir
,
5227 .unlink
= smb2_unlink
,
5228 .rename
= smb2_rename_path
,
5229 .create_hardlink
= smb2_create_hardlink
,
5230 .query_symlink
= smb2_query_symlink
,
5231 .query_mf_symlink
= smb3_query_mf_symlink
,
5232 .create_mf_symlink
= smb3_create_mf_symlink
,
5233 .open
= smb2_open_file
,
5234 .set_fid
= smb2_set_fid
,
5235 .close
= smb2_close_file
,
5236 .close_getattr
= smb2_close_getattr
,
5237 .flush
= smb2_flush_file
,
5238 .async_readv
= smb2_async_readv
,
5239 .async_writev
= smb2_async_writev
,
5240 .sync_read
= smb2_sync_read
,
5241 .sync_write
= smb2_sync_write
,
5242 .query_dir_first
= smb2_query_dir_first
,
5243 .query_dir_next
= smb2_query_dir_next
,
5244 .close_dir
= smb2_close_dir
,
5245 .calc_smb_size
= smb2_calc_size
,
5246 .is_status_pending
= smb2_is_status_pending
,
5247 .is_session_expired
= smb2_is_session_expired
,
5248 .oplock_response
= smb2_oplock_response
,
5249 .queryfs
= smb2_queryfs
,
5250 .mand_lock
= smb2_mand_lock
,
5251 .mand_unlock_range
= smb2_unlock_range
,
5252 .push_mand_locks
= smb2_push_mandatory_locks
,
5253 .get_lease_key
= smb2_get_lease_key
,
5254 .set_lease_key
= smb2_set_lease_key
,
5255 .new_lease_key
= smb2_new_lease_key
,
5256 .generate_signingkey
= generate_smb30signingkey
,
5257 .calc_signature
= smb3_calc_signature
,
5258 .set_integrity
= smb3_set_integrity
,
5259 .is_read_op
= smb21_is_read_op
,
5260 .set_oplock_level
= smb3_set_oplock_level
,
5261 .create_lease_buf
= smb3_create_lease_buf
,
5262 .parse_lease_buf
= smb3_parse_lease_buf
,
5263 .copychunk_range
= smb2_copychunk_range
,
5264 .duplicate_extents
= smb2_duplicate_extents
,
5265 .validate_negotiate
= smb3_validate_negotiate
,
5266 .wp_retry_size
= smb2_wp_retry_size
,
5267 .dir_needs_close
= smb2_dir_needs_close
,
5268 .fallocate
= smb3_fallocate
,
5269 .enum_snapshots
= smb3_enum_snapshots
,
5270 .notify
= smb3_notify
,
5271 .init_transform_rq
= smb3_init_transform_rq
,
5272 .is_transform_hdr
= smb3_is_transform_hdr
,
5273 .receive_transform
= smb3_receive_transform
,
5274 .get_dfs_refer
= smb2_get_dfs_refer
,
5275 .select_sectype
= smb2_select_sectype
,
5276 #ifdef CONFIG_CIFS_XATTR
5277 .query_all_EAs
= smb2_query_eas
,
5278 .set_EA
= smb2_set_ea
,
5279 #endif /* CIFS_XATTR */
5280 .get_acl
= get_smb2_acl
,
5281 .get_acl_by_fid
= get_smb2_acl_by_fid
,
5282 .set_acl
= set_smb2_acl
,
5283 .next_header
= smb2_next_header
,
5284 .ioctl_query_info
= smb2_ioctl_query_info
,
5285 .make_node
= smb2_make_node
,
5286 .fiemap
= smb3_fiemap
,
5287 .llseek
= smb3_llseek
,
5288 .is_status_io_timeout
= smb2_is_status_io_timeout
,
5291 struct smb_version_operations smb311_operations
= {
5292 .compare_fids
= smb2_compare_fids
,
5293 .setup_request
= smb2_setup_request
,
5294 .setup_async_request
= smb2_setup_async_request
,
5295 .check_receive
= smb2_check_receive
,
5296 .add_credits
= smb2_add_credits
,
5297 .set_credits
= smb2_set_credits
,
5298 .get_credits_field
= smb2_get_credits_field
,
5299 .get_credits
= smb2_get_credits
,
5300 .wait_mtu_credits
= smb2_wait_mtu_credits
,
5301 .adjust_credits
= smb2_adjust_credits
,
5302 .get_next_mid
= smb2_get_next_mid
,
5303 .revert_current_mid
= smb2_revert_current_mid
,
5304 .read_data_offset
= smb2_read_data_offset
,
5305 .read_data_length
= smb2_read_data_length
,
5306 .map_error
= map_smb2_to_linux_error
,
5307 .find_mid
= smb2_find_mid
,
5308 .check_message
= smb2_check_message
,
5309 .dump_detail
= smb2_dump_detail
,
5310 .clear_stats
= smb2_clear_stats
,
5311 .print_stats
= smb2_print_stats
,
5312 .dump_share_caps
= smb2_dump_share_caps
,
5313 .is_oplock_break
= smb2_is_valid_oplock_break
,
5314 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
5315 .downgrade_oplock
= smb3_downgrade_oplock
,
5316 .need_neg
= smb2_need_neg
,
5317 .negotiate
= smb2_negotiate
,
5318 .negotiate_wsize
= smb3_negotiate_wsize
,
5319 .negotiate_rsize
= smb3_negotiate_rsize
,
5320 .sess_setup
= SMB2_sess_setup
,
5321 .logoff
= SMB2_logoff
,
5322 .tree_connect
= SMB2_tcon
,
5323 .tree_disconnect
= SMB2_tdis
,
5324 .qfs_tcon
= smb3_qfs_tcon
,
5325 .is_path_accessible
= smb2_is_path_accessible
,
5326 .can_echo
= smb2_can_echo
,
5328 .query_path_info
= smb2_query_path_info
,
5329 .query_reparse_tag
= smb2_query_reparse_tag
,
5330 .get_srv_inum
= smb2_get_srv_inum
,
5331 .query_file_info
= smb2_query_file_info
,
5332 .set_path_size
= smb2_set_path_size
,
5333 .set_file_size
= smb2_set_file_size
,
5334 .set_file_info
= smb2_set_file_info
,
5335 .set_compression
= smb2_set_compression
,
5336 .mkdir
= smb2_mkdir
,
5337 .mkdir_setinfo
= smb2_mkdir_setinfo
,
5338 .posix_mkdir
= smb311_posix_mkdir
,
5339 .rmdir
= smb2_rmdir
,
5340 .unlink
= smb2_unlink
,
5341 .rename
= smb2_rename_path
,
5342 .create_hardlink
= smb2_create_hardlink
,
5343 .query_symlink
= smb2_query_symlink
,
5344 .query_mf_symlink
= smb3_query_mf_symlink
,
5345 .create_mf_symlink
= smb3_create_mf_symlink
,
5346 .open
= smb2_open_file
,
5347 .set_fid
= smb2_set_fid
,
5348 .close
= smb2_close_file
,
5349 .close_getattr
= smb2_close_getattr
,
5350 .flush
= smb2_flush_file
,
5351 .async_readv
= smb2_async_readv
,
5352 .async_writev
= smb2_async_writev
,
5353 .sync_read
= smb2_sync_read
,
5354 .sync_write
= smb2_sync_write
,
5355 .query_dir_first
= smb2_query_dir_first
,
5356 .query_dir_next
= smb2_query_dir_next
,
5357 .close_dir
= smb2_close_dir
,
5358 .calc_smb_size
= smb2_calc_size
,
5359 .is_status_pending
= smb2_is_status_pending
,
5360 .is_session_expired
= smb2_is_session_expired
,
5361 .oplock_response
= smb2_oplock_response
,
5362 .queryfs
= smb311_queryfs
,
5363 .mand_lock
= smb2_mand_lock
,
5364 .mand_unlock_range
= smb2_unlock_range
,
5365 .push_mand_locks
= smb2_push_mandatory_locks
,
5366 .get_lease_key
= smb2_get_lease_key
,
5367 .set_lease_key
= smb2_set_lease_key
,
5368 .new_lease_key
= smb2_new_lease_key
,
5369 .generate_signingkey
= generate_smb311signingkey
,
5370 .calc_signature
= smb3_calc_signature
,
5371 .set_integrity
= smb3_set_integrity
,
5372 .is_read_op
= smb21_is_read_op
,
5373 .set_oplock_level
= smb3_set_oplock_level
,
5374 .create_lease_buf
= smb3_create_lease_buf
,
5375 .parse_lease_buf
= smb3_parse_lease_buf
,
5376 .copychunk_range
= smb2_copychunk_range
,
5377 .duplicate_extents
= smb2_duplicate_extents
,
5378 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
5379 .wp_retry_size
= smb2_wp_retry_size
,
5380 .dir_needs_close
= smb2_dir_needs_close
,
5381 .fallocate
= smb3_fallocate
,
5382 .enum_snapshots
= smb3_enum_snapshots
,
5383 .notify
= smb3_notify
,
5384 .init_transform_rq
= smb3_init_transform_rq
,
5385 .is_transform_hdr
= smb3_is_transform_hdr
,
5386 .receive_transform
= smb3_receive_transform
,
5387 .get_dfs_refer
= smb2_get_dfs_refer
,
5388 .select_sectype
= smb2_select_sectype
,
5389 #ifdef CONFIG_CIFS_XATTR
5390 .query_all_EAs
= smb2_query_eas
,
5391 .set_EA
= smb2_set_ea
,
5392 #endif /* CIFS_XATTR */
5393 .get_acl
= get_smb2_acl
,
5394 .get_acl_by_fid
= get_smb2_acl_by_fid
,
5395 .set_acl
= set_smb2_acl
,
5396 .next_header
= smb2_next_header
,
5397 .ioctl_query_info
= smb2_ioctl_query_info
,
5398 .make_node
= smb2_make_node
,
5399 .fiemap
= smb3_fiemap
,
5400 .llseek
= smb3_llseek
,
5401 .is_status_io_timeout
= smb2_is_status_io_timeout
,
5404 struct smb_version_values smb20_values
= {
5405 .version_string
= SMB20_VERSION_STRING
,
5406 .protocol_id
= SMB20_PROT_ID
,
5407 .req_capabilities
= 0, /* MBZ */
5408 .large_lock_type
= 0,
5409 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
5410 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
5411 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
5412 .header_size
= sizeof(struct smb2_sync_hdr
),
5413 .header_preamble_size
= 0,
5414 .max_header_size
= MAX_SMB2_HDR_SIZE
,
5415 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
5416 .lock_cmd
= SMB2_LOCK
,
5418 .cap_nt_find
= SMB2_NT_FIND
,
5419 .cap_large_files
= SMB2_LARGE_FILES
,
5420 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5421 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5422 .create_lease_size
= sizeof(struct create_lease
),
5425 struct smb_version_values smb21_values
= {
5426 .version_string
= SMB21_VERSION_STRING
,
5427 .protocol_id
= SMB21_PROT_ID
,
5428 .req_capabilities
= 0, /* MBZ on negotiate req until SMB3 dialect */
5429 .large_lock_type
= 0,
5430 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
5431 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
5432 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
5433 .header_size
= sizeof(struct smb2_sync_hdr
),
5434 .header_preamble_size
= 0,
5435 .max_header_size
= MAX_SMB2_HDR_SIZE
,
5436 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
5437 .lock_cmd
= SMB2_LOCK
,
5439 .cap_nt_find
= SMB2_NT_FIND
,
5440 .cap_large_files
= SMB2_LARGE_FILES
,
5441 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5442 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5443 .create_lease_size
= sizeof(struct create_lease
),
5446 struct smb_version_values smb3any_values
= {
5447 .version_string
= SMB3ANY_VERSION_STRING
,
5448 .protocol_id
= SMB302_PROT_ID
, /* doesn't matter, send protocol array */
5449 .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
,
5450 .large_lock_type
= 0,
5451 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
5452 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
5453 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
5454 .header_size
= sizeof(struct smb2_sync_hdr
),
5455 .header_preamble_size
= 0,
5456 .max_header_size
= MAX_SMB2_HDR_SIZE
,
5457 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
5458 .lock_cmd
= SMB2_LOCK
,
5460 .cap_nt_find
= SMB2_NT_FIND
,
5461 .cap_large_files
= SMB2_LARGE_FILES
,
5462 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5463 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5464 .create_lease_size
= sizeof(struct create_lease_v2
),
5467 struct smb_version_values smbdefault_values
= {
5468 .version_string
= SMBDEFAULT_VERSION_STRING
,
5469 .protocol_id
= SMB302_PROT_ID
, /* doesn't matter, send protocol array */
5470 .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
,
5471 .large_lock_type
= 0,
5472 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
5473 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
5474 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
5475 .header_size
= sizeof(struct smb2_sync_hdr
),
5476 .header_preamble_size
= 0,
5477 .max_header_size
= MAX_SMB2_HDR_SIZE
,
5478 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
5479 .lock_cmd
= SMB2_LOCK
,
5481 .cap_nt_find
= SMB2_NT_FIND
,
5482 .cap_large_files
= SMB2_LARGE_FILES
,
5483 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5484 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5485 .create_lease_size
= sizeof(struct create_lease_v2
),
5488 struct smb_version_values smb30_values
= {
5489 .version_string
= SMB30_VERSION_STRING
,
5490 .protocol_id
= SMB30_PROT_ID
,
5491 .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
,
5492 .large_lock_type
= 0,
5493 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
5494 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
5495 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
5496 .header_size
= sizeof(struct smb2_sync_hdr
),
5497 .header_preamble_size
= 0,
5498 .max_header_size
= MAX_SMB2_HDR_SIZE
,
5499 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
5500 .lock_cmd
= SMB2_LOCK
,
5502 .cap_nt_find
= SMB2_NT_FIND
,
5503 .cap_large_files
= SMB2_LARGE_FILES
,
5504 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5505 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5506 .create_lease_size
= sizeof(struct create_lease_v2
),
5509 struct smb_version_values smb302_values
= {
5510 .version_string
= SMB302_VERSION_STRING
,
5511 .protocol_id
= SMB302_PROT_ID
,
5512 .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
,
5513 .large_lock_type
= 0,
5514 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
5515 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
5516 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
5517 .header_size
= sizeof(struct smb2_sync_hdr
),
5518 .header_preamble_size
= 0,
5519 .max_header_size
= MAX_SMB2_HDR_SIZE
,
5520 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
5521 .lock_cmd
= SMB2_LOCK
,
5523 .cap_nt_find
= SMB2_NT_FIND
,
5524 .cap_large_files
= SMB2_LARGE_FILES
,
5525 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5526 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5527 .create_lease_size
= sizeof(struct create_lease_v2
),
5530 struct smb_version_values smb311_values
= {
5531 .version_string
= SMB311_VERSION_STRING
,
5532 .protocol_id
= SMB311_PROT_ID
,
5533 .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
,
5534 .large_lock_type
= 0,
5535 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
5536 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
5537 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
5538 .header_size
= sizeof(struct smb2_sync_hdr
),
5539 .header_preamble_size
= 0,
5540 .max_header_size
= MAX_SMB2_HDR_SIZE
,
5541 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
5542 .lock_cmd
= SMB2_LOCK
,
5544 .cap_nt_find
= SMB2_NT_FIND
,
5545 .cap_large_files
= SMB2_LARGE_FILES
,
5546 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5547 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
5548 .create_lease_size
= sizeof(struct create_lease_v2
),