2 * SMB2 version specific operations
4 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
6 * This library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License v2 as published
8 * by the Free Software Foundation.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/pagemap.h>
21 #include <linux/vfs.h>
22 #include <linux/falloc.h>
23 #include <linux/scatterlist.h>
24 #include <linux/uuid.h>
25 #include <crypto/aead.h>
28 #include "smb2proto.h"
29 #include "cifsproto.h"
30 #include "cifs_debug.h"
31 #include "cifs_unicode.h"
32 #include "smb2status.h"
34 #include "cifs_ioctl.h"
37 change_conf(struct TCP_Server_Info
*server
)
39 server
->credits
+= server
->echo_credits
+ server
->oplock_credits
;
40 server
->oplock_credits
= server
->echo_credits
= 0;
41 switch (server
->credits
) {
45 server
->echoes
= false;
46 server
->oplocks
= false;
47 cifs_dbg(VFS
, "disabling echoes and oplocks\n");
50 server
->echoes
= true;
51 server
->oplocks
= false;
52 server
->echo_credits
= 1;
53 cifs_dbg(FYI
, "disabling oplocks\n");
56 server
->echoes
= true;
58 server
->oplocks
= true;
59 server
->oplock_credits
= 1;
61 server
->oplocks
= false;
63 server
->echo_credits
= 1;
65 server
->credits
-= server
->echo_credits
+ server
->oplock_credits
;
70 smb2_add_credits(struct TCP_Server_Info
*server
, const unsigned int add
,
74 spin_lock(&server
->req_lock
);
75 val
= server
->ops
->get_credits_field(server
, optype
);
78 *val
= 65000; /* Don't get near 64K credits, avoid srv bugs */
79 printk_once(KERN_WARNING
"server overflowed SMB3 credits\n");
82 if (server
->in_flight
== 0 && (optype
& CIFS_OP_MASK
) != CIFS_NEG_OP
)
83 rc
= change_conf(server
);
85 * Sometimes server returns 0 credits on oplock break ack - we need to
86 * rebalance credits in this case.
88 else if (server
->in_flight
> 0 && server
->oplock_credits
== 0 &&
90 if (server
->credits
> 1) {
92 server
->oplock_credits
++;
95 spin_unlock(&server
->req_lock
);
96 wake_up(&server
->request_q
);
98 cifs_reconnect(server
);
102 smb2_set_credits(struct TCP_Server_Info
*server
, const int val
)
104 spin_lock(&server
->req_lock
);
105 server
->credits
= val
;
106 spin_unlock(&server
->req_lock
);
110 smb2_get_credits_field(struct TCP_Server_Info
*server
, const int optype
)
114 return &server
->echo_credits
;
116 return &server
->oplock_credits
;
118 return &server
->credits
;
123 smb2_get_credits(struct mid_q_entry
*mid
)
125 struct smb2_sync_hdr
*shdr
= get_sync_hdr(mid
->resp_buf
);
127 return le16_to_cpu(shdr
->CreditRequest
);
131 smb2_wait_mtu_credits(struct TCP_Server_Info
*server
, unsigned int size
,
132 unsigned int *num
, unsigned int *credits
)
135 unsigned int scredits
;
137 spin_lock(&server
->req_lock
);
139 if (server
->credits
<= 0) {
140 spin_unlock(&server
->req_lock
);
141 cifs_num_waiters_inc(server
);
142 rc
= wait_event_killable(server
->request_q
,
143 has_credits(server
, &server
->credits
));
144 cifs_num_waiters_dec(server
);
147 spin_lock(&server
->req_lock
);
149 if (server
->tcpStatus
== CifsExiting
) {
150 spin_unlock(&server
->req_lock
);
154 scredits
= server
->credits
;
155 /* can deadlock with reopen */
157 *num
= SMB2_MAX_BUFFER_SIZE
;
162 /* leave one credit for a possible reopen */
164 *num
= min_t(unsigned int, size
,
165 scredits
* SMB2_MAX_BUFFER_SIZE
);
167 *credits
= DIV_ROUND_UP(*num
, SMB2_MAX_BUFFER_SIZE
);
168 server
->credits
-= *credits
;
173 spin_unlock(&server
->req_lock
);
178 smb2_get_next_mid(struct TCP_Server_Info
*server
)
181 /* for SMB2 we need the current value */
182 spin_lock(&GlobalMid_Lock
);
183 mid
= server
->CurrentMid
++;
184 spin_unlock(&GlobalMid_Lock
);
188 static struct mid_q_entry
*
189 smb2_find_mid(struct TCP_Server_Info
*server
, char *buf
)
191 struct mid_q_entry
*mid
;
192 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
193 __u64 wire_mid
= le64_to_cpu(shdr
->MessageId
);
195 if (shdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
) {
196 cifs_dbg(VFS
, "encrypted frame parsing not supported yet");
200 spin_lock(&GlobalMid_Lock
);
201 list_for_each_entry(mid
, &server
->pending_mid_q
, qhead
) {
202 if ((mid
->mid
== wire_mid
) &&
203 (mid
->mid_state
== MID_REQUEST_SUBMITTED
) &&
204 (mid
->command
== shdr
->Command
)) {
205 spin_unlock(&GlobalMid_Lock
);
209 spin_unlock(&GlobalMid_Lock
);
214 smb2_dump_detail(void *buf
)
216 #ifdef CONFIG_CIFS_DEBUG2
217 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
219 cifs_dbg(VFS
, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
220 shdr
->Command
, shdr
->Status
, shdr
->Flags
, shdr
->MessageId
,
222 cifs_dbg(VFS
, "smb buf %p len %u\n", buf
, smb2_calc_size(buf
));
227 smb2_need_neg(struct TCP_Server_Info
*server
)
229 return server
->max_read
== 0;
233 smb2_negotiate(const unsigned int xid
, struct cifs_ses
*ses
)
236 ses
->server
->CurrentMid
= 0;
237 rc
= SMB2_negotiate(xid
, ses
);
238 /* BB we probably don't need to retry with modern servers */
245 smb2_negotiate_wsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
247 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
250 /* start with specified wsize, or default */
251 wsize
= volume_info
->wsize
? volume_info
->wsize
: CIFS_DEFAULT_IOSIZE
;
252 wsize
= min_t(unsigned int, wsize
, server
->max_write
);
254 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
255 wsize
= min_t(unsigned int, wsize
, SMB2_MAX_BUFFER_SIZE
);
261 smb2_negotiate_rsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
263 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
266 /* start with specified rsize, or default */
267 rsize
= volume_info
->rsize
? volume_info
->rsize
: CIFS_DEFAULT_IOSIZE
;
268 rsize
= min_t(unsigned int, rsize
, server
->max_read
);
270 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
271 rsize
= min_t(unsigned int, rsize
, SMB2_MAX_BUFFER_SIZE
);
276 #ifdef CONFIG_CIFS_STATS2
278 SMB3_request_interfaces(const unsigned int xid
, struct cifs_tcon
*tcon
)
281 unsigned int ret_data_len
= 0;
282 struct network_interface_info_ioctl_rsp
*out_buf
;
284 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
285 FSCTL_QUERY_NETWORK_INTERFACE_INFO
, true /* is_fsctl */,
287 NULL
/* no data input */, 0 /* no data input */,
288 (char **)&out_buf
, &ret_data_len
);
290 cifs_dbg(VFS
, "error %d on ioctl to get interface list\n", rc
);
291 else if (ret_data_len
< sizeof(struct network_interface_info_ioctl_rsp
)) {
292 cifs_dbg(VFS
, "server returned bad net interface info buf\n");
295 /* Dump info on first interface */
296 cifs_dbg(FYI
, "Adapter Capability 0x%x\t",
297 le32_to_cpu(out_buf
->Capability
));
298 cifs_dbg(FYI
, "Link Speed %lld\n",
299 le64_to_cpu(out_buf
->LinkSpeed
));
307 smb3_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
310 __le16 srch_path
= 0; /* Null - open root of share */
311 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
312 struct cifs_open_parms oparms
;
316 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
317 oparms
.disposition
= FILE_OPEN
;
318 oparms
.create_options
= 0;
320 oparms
.reconnect
= false;
322 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
326 #ifdef CONFIG_CIFS_STATS2
327 SMB3_request_interfaces(xid
, tcon
);
330 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
331 FS_ATTRIBUTE_INFORMATION
);
332 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
333 FS_DEVICE_INFORMATION
);
334 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
335 FS_SECTOR_SIZE_INFORMATION
); /* SMB3 specific */
336 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
341 smb2_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
344 __le16 srch_path
= 0; /* Null - open root of share */
345 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
346 struct cifs_open_parms oparms
;
350 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
351 oparms
.disposition
= FILE_OPEN
;
352 oparms
.create_options
= 0;
354 oparms
.reconnect
= false;
356 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
360 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
361 FS_ATTRIBUTE_INFORMATION
);
362 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
363 FS_DEVICE_INFORMATION
);
364 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
369 smb2_is_path_accessible(const unsigned int xid
, struct cifs_tcon
*tcon
,
370 struct cifs_sb_info
*cifs_sb
, const char *full_path
)
374 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
375 struct cifs_open_parms oparms
;
378 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
383 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
384 oparms
.disposition
= FILE_OPEN
;
385 oparms
.create_options
= 0;
387 oparms
.reconnect
= false;
389 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
395 rc
= SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
401 smb2_get_srv_inum(const unsigned int xid
, struct cifs_tcon
*tcon
,
402 struct cifs_sb_info
*cifs_sb
, const char *full_path
,
403 u64
*uniqueid
, FILE_ALL_INFO
*data
)
405 *uniqueid
= le64_to_cpu(data
->IndexNumber
);
410 smb2_query_file_info(const unsigned int xid
, struct cifs_tcon
*tcon
,
411 struct cifs_fid
*fid
, FILE_ALL_INFO
*data
)
414 struct smb2_file_all_info
*smb2_data
;
416 smb2_data
= kzalloc(sizeof(struct smb2_file_all_info
) + PATH_MAX
* 2,
418 if (smb2_data
== NULL
)
421 rc
= SMB2_query_info(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
,
424 move_smb2_info_to_cifs(data
, smb2_data
);
429 #ifdef CONFIG_CIFS_XATTR
431 move_smb2_ea_to_cifs(char *dst
, size_t dst_size
,
432 struct smb2_file_full_ea_info
*src
, size_t src_size
,
433 const unsigned char *ea_name
)
436 unsigned int ea_name_len
= ea_name
? strlen(ea_name
) : 0;
438 size_t name_len
, value_len
, user_name_len
;
440 while (src_size
> 0) {
441 name
= &src
->ea_data
[0];
442 name_len
= (size_t)src
->ea_name_length
;
443 value
= &src
->ea_data
[src
->ea_name_length
+ 1];
444 value_len
= (size_t)le16_to_cpu(src
->ea_value_length
);
450 if (src_size
< 8 + name_len
+ 1 + value_len
) {
451 cifs_dbg(FYI
, "EA entry goes beyond length of list\n");
457 if (ea_name_len
== name_len
&&
458 memcmp(ea_name
, name
, name_len
) == 0) {
462 if (dst_size
< value_len
) {
466 memcpy(dst
, value
, value_len
);
470 /* 'user.' plus a terminating null */
471 user_name_len
= 5 + 1 + name_len
;
475 if (dst_size
>= user_name_len
) {
476 dst_size
-= user_name_len
;
477 memcpy(dst
, "user.", 5);
479 memcpy(dst
, src
->ea_data
, name_len
);
483 } else if (dst_size
== 0) {
484 /* skip copy - calc size only */
486 /* stop before overrun buffer */
492 if (!src
->next_entry_offset
)
495 if (src_size
< le32_to_cpu(src
->next_entry_offset
)) {
496 /* stop before overrun buffer */
500 src_size
-= le32_to_cpu(src
->next_entry_offset
);
501 src
= (void *)((char *)src
+
502 le32_to_cpu(src
->next_entry_offset
));
505 /* didn't find the named attribute */
514 smb2_query_eas(const unsigned int xid
, struct cifs_tcon
*tcon
,
515 const unsigned char *path
, const unsigned char *ea_name
,
516 char *ea_data
, size_t buf_size
,
517 struct cifs_sb_info
*cifs_sb
)
521 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
522 struct cifs_open_parms oparms
;
524 struct smb2_file_full_ea_info
*smb2_data
;
526 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
531 oparms
.desired_access
= FILE_READ_EA
;
532 oparms
.disposition
= FILE_OPEN
;
533 oparms
.create_options
= 0;
535 oparms
.reconnect
= false;
537 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
540 cifs_dbg(FYI
, "open failed rc=%d\n", rc
);
544 smb2_data
= kzalloc(SMB2_MAX_EA_BUF
, GFP_KERNEL
);
545 if (smb2_data
== NULL
) {
546 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
550 rc
= SMB2_query_eas(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
552 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
555 rc
= move_smb2_ea_to_cifs(ea_data
, buf_size
, smb2_data
,
556 SMB2_MAX_EA_BUF
, ea_name
);
564 smb2_set_ea(const unsigned int xid
, struct cifs_tcon
*tcon
,
565 const char *path
, const char *ea_name
, const void *ea_value
,
566 const __u16 ea_value_len
, const struct nls_table
*nls_codepage
,
567 struct cifs_sb_info
*cifs_sb
)
571 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
572 struct cifs_open_parms oparms
;
574 struct smb2_file_full_ea_info
*ea
;
575 int ea_name_len
= strlen(ea_name
);
578 if (ea_name_len
> 255)
581 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
586 oparms
.desired_access
= FILE_WRITE_EA
;
587 oparms
.disposition
= FILE_OPEN
;
588 oparms
.create_options
= 0;
590 oparms
.reconnect
= false;
592 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
595 cifs_dbg(FYI
, "open failed rc=%d\n", rc
);
599 len
= sizeof(ea
) + ea_name_len
+ ea_value_len
+ 1;
600 ea
= kzalloc(len
, GFP_KERNEL
);
602 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
606 ea
->ea_name_length
= ea_name_len
;
607 ea
->ea_value_length
= cpu_to_le16(ea_value_len
);
608 memcpy(ea
->ea_data
, ea_name
, ea_name_len
+ 1);
609 memcpy(ea
->ea_data
+ ea_name_len
+ 1, ea_value
, ea_value_len
);
611 rc
= SMB2_set_ea(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
, ea
,
613 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
620 smb2_can_echo(struct TCP_Server_Info
*server
)
622 return server
->echoes
;
626 smb2_clear_stats(struct cifs_tcon
*tcon
)
628 #ifdef CONFIG_CIFS_STATS
630 for (i
= 0; i
< NUMBER_OF_SMB2_COMMANDS
; i
++) {
631 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_sent
[i
], 0);
632 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_failed
[i
], 0);
638 smb2_dump_share_caps(struct seq_file
*m
, struct cifs_tcon
*tcon
)
640 seq_puts(m
, "\n\tShare Capabilities:");
641 if (tcon
->capabilities
& SMB2_SHARE_CAP_DFS
)
642 seq_puts(m
, " DFS,");
643 if (tcon
->capabilities
& SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY
)
644 seq_puts(m
, " CONTINUOUS AVAILABILITY,");
645 if (tcon
->capabilities
& SMB2_SHARE_CAP_SCALEOUT
)
646 seq_puts(m
, " SCALEOUT,");
647 if (tcon
->capabilities
& SMB2_SHARE_CAP_CLUSTER
)
648 seq_puts(m
, " CLUSTER,");
649 if (tcon
->capabilities
& SMB2_SHARE_CAP_ASYMMETRIC
)
650 seq_puts(m
, " ASYMMETRIC,");
651 if (tcon
->capabilities
== 0)
652 seq_puts(m
, " None");
653 if (tcon
->ss_flags
& SSINFO_FLAGS_ALIGNED_DEVICE
)
654 seq_puts(m
, " Aligned,");
655 if (tcon
->ss_flags
& SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE
)
656 seq_puts(m
, " Partition Aligned,");
657 if (tcon
->ss_flags
& SSINFO_FLAGS_NO_SEEK_PENALTY
)
658 seq_puts(m
, " SSD,");
659 if (tcon
->ss_flags
& SSINFO_FLAGS_TRIM_ENABLED
)
660 seq_puts(m
, " TRIM-support,");
662 seq_printf(m
, "\tShare Flags: 0x%x", tcon
->share_flags
);
663 if (tcon
->perf_sector_size
)
664 seq_printf(m
, "\tOptimal sector size: 0x%x",
665 tcon
->perf_sector_size
);
669 smb2_print_stats(struct seq_file
*m
, struct cifs_tcon
*tcon
)
671 #ifdef CONFIG_CIFS_STATS
672 atomic_t
*sent
= tcon
->stats
.smb2_stats
.smb2_com_sent
;
673 atomic_t
*failed
= tcon
->stats
.smb2_stats
.smb2_com_failed
;
674 seq_printf(m
, "\nNegotiates: %d sent %d failed",
675 atomic_read(&sent
[SMB2_NEGOTIATE_HE
]),
676 atomic_read(&failed
[SMB2_NEGOTIATE_HE
]));
677 seq_printf(m
, "\nSessionSetups: %d sent %d failed",
678 atomic_read(&sent
[SMB2_SESSION_SETUP_HE
]),
679 atomic_read(&failed
[SMB2_SESSION_SETUP_HE
]));
680 seq_printf(m
, "\nLogoffs: %d sent %d failed",
681 atomic_read(&sent
[SMB2_LOGOFF_HE
]),
682 atomic_read(&failed
[SMB2_LOGOFF_HE
]));
683 seq_printf(m
, "\nTreeConnects: %d sent %d failed",
684 atomic_read(&sent
[SMB2_TREE_CONNECT_HE
]),
685 atomic_read(&failed
[SMB2_TREE_CONNECT_HE
]));
686 seq_printf(m
, "\nTreeDisconnects: %d sent %d failed",
687 atomic_read(&sent
[SMB2_TREE_DISCONNECT_HE
]),
688 atomic_read(&failed
[SMB2_TREE_DISCONNECT_HE
]));
689 seq_printf(m
, "\nCreates: %d sent %d failed",
690 atomic_read(&sent
[SMB2_CREATE_HE
]),
691 atomic_read(&failed
[SMB2_CREATE_HE
]));
692 seq_printf(m
, "\nCloses: %d sent %d failed",
693 atomic_read(&sent
[SMB2_CLOSE_HE
]),
694 atomic_read(&failed
[SMB2_CLOSE_HE
]));
695 seq_printf(m
, "\nFlushes: %d sent %d failed",
696 atomic_read(&sent
[SMB2_FLUSH_HE
]),
697 atomic_read(&failed
[SMB2_FLUSH_HE
]));
698 seq_printf(m
, "\nReads: %d sent %d failed",
699 atomic_read(&sent
[SMB2_READ_HE
]),
700 atomic_read(&failed
[SMB2_READ_HE
]));
701 seq_printf(m
, "\nWrites: %d sent %d failed",
702 atomic_read(&sent
[SMB2_WRITE_HE
]),
703 atomic_read(&failed
[SMB2_WRITE_HE
]));
704 seq_printf(m
, "\nLocks: %d sent %d failed",
705 atomic_read(&sent
[SMB2_LOCK_HE
]),
706 atomic_read(&failed
[SMB2_LOCK_HE
]));
707 seq_printf(m
, "\nIOCTLs: %d sent %d failed",
708 atomic_read(&sent
[SMB2_IOCTL_HE
]),
709 atomic_read(&failed
[SMB2_IOCTL_HE
]));
710 seq_printf(m
, "\nCancels: %d sent %d failed",
711 atomic_read(&sent
[SMB2_CANCEL_HE
]),
712 atomic_read(&failed
[SMB2_CANCEL_HE
]));
713 seq_printf(m
, "\nEchos: %d sent %d failed",
714 atomic_read(&sent
[SMB2_ECHO_HE
]),
715 atomic_read(&failed
[SMB2_ECHO_HE
]));
716 seq_printf(m
, "\nQueryDirectories: %d sent %d failed",
717 atomic_read(&sent
[SMB2_QUERY_DIRECTORY_HE
]),
718 atomic_read(&failed
[SMB2_QUERY_DIRECTORY_HE
]));
719 seq_printf(m
, "\nChangeNotifies: %d sent %d failed",
720 atomic_read(&sent
[SMB2_CHANGE_NOTIFY_HE
]),
721 atomic_read(&failed
[SMB2_CHANGE_NOTIFY_HE
]));
722 seq_printf(m
, "\nQueryInfos: %d sent %d failed",
723 atomic_read(&sent
[SMB2_QUERY_INFO_HE
]),
724 atomic_read(&failed
[SMB2_QUERY_INFO_HE
]));
725 seq_printf(m
, "\nSetInfos: %d sent %d failed",
726 atomic_read(&sent
[SMB2_SET_INFO_HE
]),
727 atomic_read(&failed
[SMB2_SET_INFO_HE
]));
728 seq_printf(m
, "\nOplockBreaks: %d sent %d failed",
729 atomic_read(&sent
[SMB2_OPLOCK_BREAK_HE
]),
730 atomic_read(&failed
[SMB2_OPLOCK_BREAK_HE
]));
735 smb2_set_fid(struct cifsFileInfo
*cfile
, struct cifs_fid
*fid
, __u32 oplock
)
737 struct cifsInodeInfo
*cinode
= CIFS_I(d_inode(cfile
->dentry
));
738 struct TCP_Server_Info
*server
= tlink_tcon(cfile
->tlink
)->ses
->server
;
740 cfile
->fid
.persistent_fid
= fid
->persistent_fid
;
741 cfile
->fid
.volatile_fid
= fid
->volatile_fid
;
742 server
->ops
->set_oplock_level(cinode
, oplock
, fid
->epoch
,
744 cinode
->can_cache_brlcks
= CIFS_CACHE_WRITE(cinode
);
745 memcpy(cfile
->fid
.create_guid
, fid
->create_guid
, 16);
749 smb2_close_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
750 struct cifs_fid
*fid
)
752 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
756 SMB2_request_res_key(const unsigned int xid
, struct cifs_tcon
*tcon
,
757 u64 persistent_fid
, u64 volatile_fid
,
758 struct copychunk_ioctl
*pcchunk
)
761 unsigned int ret_data_len
;
762 struct resume_key_req
*res_key
;
764 rc
= SMB2_ioctl(xid
, tcon
, persistent_fid
, volatile_fid
,
765 FSCTL_SRV_REQUEST_RESUME_KEY
, true /* is_fsctl */,
767 NULL
, 0 /* no input */,
768 (char **)&res_key
, &ret_data_len
);
771 cifs_dbg(VFS
, "refcpy ioctl error %d getting resume key\n", rc
);
772 goto req_res_key_exit
;
774 if (ret_data_len
< sizeof(struct resume_key_req
)) {
775 cifs_dbg(VFS
, "Invalid refcopy resume key length\n");
777 goto req_res_key_exit
;
779 memcpy(pcchunk
->SourceKey
, res_key
->ResumeKey
, COPY_CHUNK_RES_KEY_SIZE
);
787 smb2_copychunk_range(const unsigned int xid
,
788 struct cifsFileInfo
*srcfile
,
789 struct cifsFileInfo
*trgtfile
, u64 src_off
,
790 u64 len
, u64 dest_off
)
793 unsigned int ret_data_len
;
794 struct copychunk_ioctl
*pcchunk
;
795 struct copychunk_ioctl_rsp
*retbuf
= NULL
;
796 struct cifs_tcon
*tcon
;
797 int chunks_copied
= 0;
798 bool chunk_sizes_updated
= false;
799 ssize_t bytes_written
, total_bytes_written
= 0;
801 pcchunk
= kmalloc(sizeof(struct copychunk_ioctl
), GFP_KERNEL
);
806 cifs_dbg(FYI
, "in smb2_copychunk_range - about to call request res key\n");
807 /* Request a key from the server to identify the source of the copy */
808 rc
= SMB2_request_res_key(xid
, tlink_tcon(srcfile
->tlink
),
809 srcfile
->fid
.persistent_fid
,
810 srcfile
->fid
.volatile_fid
, pcchunk
);
812 /* Note: request_res_key sets res_key null only if rc !=0 */
816 /* For now array only one chunk long, will make more flexible later */
817 pcchunk
->ChunkCount
= cpu_to_le32(1);
818 pcchunk
->Reserved
= 0;
819 pcchunk
->Reserved2
= 0;
821 tcon
= tlink_tcon(trgtfile
->tlink
);
824 pcchunk
->SourceOffset
= cpu_to_le64(src_off
);
825 pcchunk
->TargetOffset
= cpu_to_le64(dest_off
);
827 cpu_to_le32(min_t(u32
, len
, tcon
->max_bytes_chunk
));
829 /* Request server copy to target from src identified by key */
830 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
831 trgtfile
->fid
.volatile_fid
, FSCTL_SRV_COPYCHUNK_WRITE
,
832 true /* is_fsctl */, false /* use_ipc */,
834 sizeof(struct copychunk_ioctl
), (char **)&retbuf
,
838 sizeof(struct copychunk_ioctl_rsp
)) {
839 cifs_dbg(VFS
, "invalid cchunk response size\n");
843 if (retbuf
->TotalBytesWritten
== 0) {
844 cifs_dbg(FYI
, "no bytes copied\n");
849 * Check if server claimed to write more than we asked
851 if (le32_to_cpu(retbuf
->TotalBytesWritten
) >
852 le32_to_cpu(pcchunk
->Length
)) {
853 cifs_dbg(VFS
, "invalid copy chunk response\n");
857 if (le32_to_cpu(retbuf
->ChunksWritten
) != 1) {
858 cifs_dbg(VFS
, "invalid num chunks written\n");
864 bytes_written
= le32_to_cpu(retbuf
->TotalBytesWritten
);
865 src_off
+= bytes_written
;
866 dest_off
+= bytes_written
;
867 len
-= bytes_written
;
868 total_bytes_written
+= bytes_written
;
870 cifs_dbg(FYI
, "Chunks %d PartialChunk %d Total %zu\n",
871 le32_to_cpu(retbuf
->ChunksWritten
),
872 le32_to_cpu(retbuf
->ChunkBytesWritten
),
874 } else if (rc
== -EINVAL
) {
875 if (ret_data_len
!= sizeof(struct copychunk_ioctl_rsp
))
878 cifs_dbg(FYI
, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
879 le32_to_cpu(retbuf
->ChunksWritten
),
880 le32_to_cpu(retbuf
->ChunkBytesWritten
),
881 le32_to_cpu(retbuf
->TotalBytesWritten
));
884 * Check if this is the first request using these sizes,
885 * (ie check if copy succeed once with original sizes
886 * and check if the server gave us different sizes after
887 * we already updated max sizes on previous request).
888 * if not then why is the server returning an error now
890 if ((chunks_copied
!= 0) || chunk_sizes_updated
)
893 /* Check that server is not asking us to grow size */
894 if (le32_to_cpu(retbuf
->ChunkBytesWritten
) <
895 tcon
->max_bytes_chunk
)
896 tcon
->max_bytes_chunk
=
897 le32_to_cpu(retbuf
->ChunkBytesWritten
);
899 goto cchunk_out
; /* server gave us bogus size */
901 /* No need to change MaxChunks since already set to 1 */
902 chunk_sizes_updated
= true;
913 return total_bytes_written
;
917 smb2_flush_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
918 struct cifs_fid
*fid
)
920 return SMB2_flush(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
924 smb2_read_data_offset(char *buf
)
926 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
927 return rsp
->DataOffset
;
931 smb2_read_data_length(char *buf
)
933 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
934 return le32_to_cpu(rsp
->DataLength
);
939 smb2_sync_read(const unsigned int xid
, struct cifs_fid
*pfid
,
940 struct cifs_io_parms
*parms
, unsigned int *bytes_read
,
941 char **buf
, int *buf_type
)
943 parms
->persistent_fid
= pfid
->persistent_fid
;
944 parms
->volatile_fid
= pfid
->volatile_fid
;
945 return SMB2_read(xid
, parms
, bytes_read
, buf
, buf_type
);
949 smb2_sync_write(const unsigned int xid
, struct cifs_fid
*pfid
,
950 struct cifs_io_parms
*parms
, unsigned int *written
,
951 struct kvec
*iov
, unsigned long nr_segs
)
954 parms
->persistent_fid
= pfid
->persistent_fid
;
955 parms
->volatile_fid
= pfid
->volatile_fid
;
956 return SMB2_write(xid
, parms
, written
, iov
, nr_segs
);
959 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
960 static bool smb2_set_sparse(const unsigned int xid
, struct cifs_tcon
*tcon
,
961 struct cifsFileInfo
*cfile
, struct inode
*inode
, __u8 setsparse
)
963 struct cifsInodeInfo
*cifsi
;
966 cifsi
= CIFS_I(inode
);
968 /* if file already sparse don't bother setting sparse again */
969 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && setsparse
)
970 return true; /* already sparse */
972 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && !setsparse
)
973 return true; /* already not sparse */
976 * Can't check for sparse support on share the usual way via the
977 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
978 * since Samba server doesn't set the flag on the share, yet
979 * supports the set sparse FSCTL and returns sparse correctly
980 * in the file attributes. If we fail setting sparse though we
981 * mark that server does not support sparse files for this share
982 * to avoid repeatedly sending the unsupported fsctl to server
983 * if the file is repeatedly extended.
985 if (tcon
->broken_sparse_sup
)
988 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
989 cfile
->fid
.volatile_fid
, FSCTL_SET_SPARSE
,
990 true /* is_fctl */, false /* use_ipc */,
991 &setsparse
, 1, NULL
, NULL
);
993 tcon
->broken_sparse_sup
= true;
994 cifs_dbg(FYI
, "set sparse rc = %d\n", rc
);
999 cifsi
->cifsAttrs
|= FILE_ATTRIBUTE_SPARSE_FILE
;
1001 cifsi
->cifsAttrs
&= (~FILE_ATTRIBUTE_SPARSE_FILE
);
1007 smb2_set_file_size(const unsigned int xid
, struct cifs_tcon
*tcon
,
1008 struct cifsFileInfo
*cfile
, __u64 size
, bool set_alloc
)
1010 __le64 eof
= cpu_to_le64(size
);
1011 struct inode
*inode
;
1014 * If extending file more than one page make sparse. Many Linux fs
1015 * make files sparse by default when extending via ftruncate
1017 inode
= d_inode(cfile
->dentry
);
1019 if (!set_alloc
&& (size
> inode
->i_size
+ 8192)) {
1020 __u8 set_sparse
= 1;
1022 /* whether set sparse succeeds or not, extend the file */
1023 smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
);
1026 return SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
1027 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
, false);
1031 smb2_duplicate_extents(const unsigned int xid
,
1032 struct cifsFileInfo
*srcfile
,
1033 struct cifsFileInfo
*trgtfile
, u64 src_off
,
1034 u64 len
, u64 dest_off
)
1037 unsigned int ret_data_len
;
1038 struct duplicate_extents_to_file dup_ext_buf
;
1039 struct cifs_tcon
*tcon
= tlink_tcon(trgtfile
->tlink
);
1041 /* server fileays advertise duplicate extent support with this flag */
1042 if ((le32_to_cpu(tcon
->fsAttrInfo
.Attributes
) &
1043 FILE_SUPPORTS_BLOCK_REFCOUNTING
) == 0)
1046 dup_ext_buf
.VolatileFileHandle
= srcfile
->fid
.volatile_fid
;
1047 dup_ext_buf
.PersistentFileHandle
= srcfile
->fid
.persistent_fid
;
1048 dup_ext_buf
.SourceFileOffset
= cpu_to_le64(src_off
);
1049 dup_ext_buf
.TargetFileOffset
= cpu_to_le64(dest_off
);
1050 dup_ext_buf
.ByteCount
= cpu_to_le64(len
);
1051 cifs_dbg(FYI
, "duplicate extents: src off %lld dst off %lld len %lld",
1052 src_off
, dest_off
, len
);
1054 rc
= smb2_set_file_size(xid
, tcon
, trgtfile
, dest_off
+ len
, false);
1056 goto duplicate_extents_out
;
1058 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
1059 trgtfile
->fid
.volatile_fid
,
1060 FSCTL_DUPLICATE_EXTENTS_TO_FILE
,
1061 true /* is_fsctl */, false /* use_ipc */,
1062 (char *)&dup_ext_buf
,
1063 sizeof(struct duplicate_extents_to_file
),
1067 if (ret_data_len
> 0)
1068 cifs_dbg(FYI
, "non-zero response length in duplicate extents");
1070 duplicate_extents_out
:
1075 smb2_set_compression(const unsigned int xid
, struct cifs_tcon
*tcon
,
1076 struct cifsFileInfo
*cfile
)
1078 return SMB2_set_compression(xid
, tcon
, cfile
->fid
.persistent_fid
,
1079 cfile
->fid
.volatile_fid
);
1083 smb3_set_integrity(const unsigned int xid
, struct cifs_tcon
*tcon
,
1084 struct cifsFileInfo
*cfile
)
1086 struct fsctl_set_integrity_information_req integr_info
;
1087 unsigned int ret_data_len
;
1089 integr_info
.ChecksumAlgorithm
= cpu_to_le16(CHECKSUM_TYPE_UNCHANGED
);
1090 integr_info
.Flags
= 0;
1091 integr_info
.Reserved
= 0;
1093 return SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1094 cfile
->fid
.volatile_fid
,
1095 FSCTL_SET_INTEGRITY_INFORMATION
,
1096 true /* is_fsctl */, false /* use_ipc */,
1097 (char *)&integr_info
,
1098 sizeof(struct fsctl_set_integrity_information_req
),
1105 smb3_enum_snapshots(const unsigned int xid
, struct cifs_tcon
*tcon
,
1106 struct cifsFileInfo
*cfile
, void __user
*ioc_buf
)
1108 char *retbuf
= NULL
;
1109 unsigned int ret_data_len
= 0;
1111 struct smb_snapshot_array snapshot_in
;
1113 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1114 cfile
->fid
.volatile_fid
,
1115 FSCTL_SRV_ENUMERATE_SNAPSHOTS
,
1116 true /* is_fsctl */, false /* use_ipc */,
1117 NULL
, 0 /* no input data */,
1120 cifs_dbg(FYI
, "enum snaphots ioctl returned %d and ret buflen is %d\n",
1125 if (ret_data_len
&& (ioc_buf
!= NULL
) && (retbuf
!= NULL
)) {
1127 if (copy_from_user(&snapshot_in
, ioc_buf
,
1128 sizeof(struct smb_snapshot_array
))) {
1133 if (snapshot_in
.snapshot_array_size
< sizeof(struct smb_snapshot_array
)) {
1139 if (ret_data_len
> snapshot_in
.snapshot_array_size
)
1140 ret_data_len
= snapshot_in
.snapshot_array_size
;
1142 if (copy_to_user(ioc_buf
, retbuf
, ret_data_len
))
1151 smb2_query_dir_first(const unsigned int xid
, struct cifs_tcon
*tcon
,
1152 const char *path
, struct cifs_sb_info
*cifs_sb
,
1153 struct cifs_fid
*fid
, __u16 search_flags
,
1154 struct cifs_search_info
*srch_inf
)
1158 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1159 struct cifs_open_parms oparms
;
1161 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
1166 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| FILE_READ_DATA
;
1167 oparms
.disposition
= FILE_OPEN
;
1168 oparms
.create_options
= 0;
1170 oparms
.reconnect
= false;
1172 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
1175 cifs_dbg(FYI
, "open dir failed rc=%d\n", rc
);
1179 srch_inf
->entries_in_buffer
= 0;
1180 srch_inf
->index_of_last_entry
= 0;
1182 rc
= SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
1183 fid
->volatile_fid
, 0, srch_inf
);
1185 cifs_dbg(FYI
, "query directory failed rc=%d\n", rc
);
1186 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1192 smb2_query_dir_next(const unsigned int xid
, struct cifs_tcon
*tcon
,
1193 struct cifs_fid
*fid
, __u16 search_flags
,
1194 struct cifs_search_info
*srch_inf
)
1196 return SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
1197 fid
->volatile_fid
, 0, srch_inf
);
1201 smb2_close_dir(const unsigned int xid
, struct cifs_tcon
*tcon
,
1202 struct cifs_fid
*fid
)
1204 return SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1208 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
1209 * the number of credits and return true. Otherwise - return false.
1212 smb2_is_status_pending(char *buf
, struct TCP_Server_Info
*server
, int length
)
1214 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
1216 if (shdr
->Status
!= STATUS_PENDING
)
1220 spin_lock(&server
->req_lock
);
1221 server
->credits
+= le16_to_cpu(shdr
->CreditRequest
);
1222 spin_unlock(&server
->req_lock
);
1223 wake_up(&server
->request_q
);
1230 smb2_is_session_expired(char *buf
)
1232 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
1234 if (shdr
->Status
!= STATUS_NETWORK_SESSION_EXPIRED
)
1237 cifs_dbg(FYI
, "Session expired\n");
1242 smb2_oplock_response(struct cifs_tcon
*tcon
, struct cifs_fid
*fid
,
1243 struct cifsInodeInfo
*cinode
)
1245 if (tcon
->ses
->server
->capabilities
& SMB2_GLOBAL_CAP_LEASING
)
1246 return SMB2_lease_break(0, tcon
, cinode
->lease_key
,
1247 smb2_get_lease_state(cinode
));
1249 return SMB2_oplock_break(0, tcon
, fid
->persistent_fid
,
1251 CIFS_CACHE_READ(cinode
) ? 1 : 0);
1255 smb2_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
1256 struct kstatfs
*buf
)
1259 __le16 srch_path
= 0; /* Null - open root of share */
1260 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1261 struct cifs_open_parms oparms
;
1262 struct cifs_fid fid
;
1265 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
1266 oparms
.disposition
= FILE_OPEN
;
1267 oparms
.create_options
= 0;
1269 oparms
.reconnect
= false;
1271 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
1274 buf
->f_type
= SMB2_MAGIC_NUMBER
;
1275 rc
= SMB2_QFS_info(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
1277 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
1282 smb2_compare_fids(struct cifsFileInfo
*ob1
, struct cifsFileInfo
*ob2
)
1284 return ob1
->fid
.persistent_fid
== ob2
->fid
.persistent_fid
&&
1285 ob1
->fid
.volatile_fid
== ob2
->fid
.volatile_fid
;
1289 smb2_mand_lock(const unsigned int xid
, struct cifsFileInfo
*cfile
, __u64 offset
,
1290 __u64 length
, __u32 type
, int lock
, int unlock
, bool wait
)
1292 if (unlock
&& !lock
)
1293 type
= SMB2_LOCKFLAG_UNLOCK
;
1294 return SMB2_lock(xid
, tlink_tcon(cfile
->tlink
),
1295 cfile
->fid
.persistent_fid
, cfile
->fid
.volatile_fid
,
1296 current
->tgid
, length
, offset
, type
, wait
);
1300 smb2_get_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
1302 memcpy(fid
->lease_key
, CIFS_I(inode
)->lease_key
, SMB2_LEASE_KEY_SIZE
);
1306 smb2_set_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
1308 memcpy(CIFS_I(inode
)->lease_key
, fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
1312 smb2_new_lease_key(struct cifs_fid
*fid
)
1314 generate_random_uuid(fid
->lease_key
);
1318 smb2_get_dfs_refer(const unsigned int xid
, struct cifs_ses
*ses
,
1319 const char *search_name
,
1320 struct dfs_info3_param
**target_nodes
,
1321 unsigned int *num_of_nodes
,
1322 const struct nls_table
*nls_codepage
, int remap
)
1325 __le16
*utf16_path
= NULL
;
1326 int utf16_path_len
= 0;
1327 struct cifs_tcon
*tcon
;
1328 struct fsctl_get_dfs_referral_req
*dfs_req
= NULL
;
1329 struct get_dfs_referral_rsp
*dfs_rsp
= NULL
;
1330 u32 dfs_req_size
= 0, dfs_rsp_size
= 0;
1332 cifs_dbg(FYI
, "smb2_get_dfs_refer path <%s>\n", search_name
);
1335 * Use any tcon from the current session. Here, the first one.
1337 spin_lock(&cifs_tcp_ses_lock
);
1338 tcon
= list_first_entry_or_null(&ses
->tcon_list
, struct cifs_tcon
,
1342 spin_unlock(&cifs_tcp_ses_lock
);
1345 cifs_dbg(VFS
, "session %p has no tcon available for a dfs referral request\n",
1351 utf16_path
= cifs_strndup_to_utf16(search_name
, PATH_MAX
,
1353 nls_codepage
, remap
);
1359 dfs_req_size
= sizeof(*dfs_req
) + utf16_path_len
;
1360 dfs_req
= kzalloc(dfs_req_size
, GFP_KERNEL
);
1366 /* Highest DFS referral version understood */
1367 dfs_req
->MaxReferralLevel
= DFS_VERSION
;
1369 /* Path to resolve in an UTF-16 null-terminated string */
1370 memcpy(dfs_req
->RequestFileName
, utf16_path
, utf16_path_len
);
1373 /* try first with IPC */
1374 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
1375 FSCTL_DFS_GET_REFERRALS
,
1376 true /* is_fsctl */, true /* use_ipc */,
1377 (char *)dfs_req
, dfs_req_size
,
1378 (char **)&dfs_rsp
, &dfs_rsp_size
);
1379 if (rc
== -ENOTCONN
) {
1380 /* try with normal tcon */
1381 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
1382 FSCTL_DFS_GET_REFERRALS
,
1383 true /* is_fsctl */, false /*use_ipc*/,
1384 (char *)dfs_req
, dfs_req_size
,
1385 (char **)&dfs_rsp
, &dfs_rsp_size
);
1387 } while (rc
== -EAGAIN
);
1390 cifs_dbg(VFS
, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc
);
1394 rc
= parse_dfs_referrals(dfs_rsp
, dfs_rsp_size
,
1395 num_of_nodes
, target_nodes
,
1396 nls_codepage
, remap
, search_name
,
1397 true /* is_unicode */);
1399 cifs_dbg(VFS
, "parse error in smb2_get_dfs_refer rc=%d\n", rc
);
1405 spin_lock(&cifs_tcp_ses_lock
);
1407 spin_unlock(&cifs_tcp_ses_lock
);
1414 #define SMB2_SYMLINK_STRUCT_SIZE \
1415 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
1418 smb2_query_symlink(const unsigned int xid
, struct cifs_tcon
*tcon
,
1419 const char *full_path
, char **target_path
,
1420 struct cifs_sb_info
*cifs_sb
)
1424 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1425 struct cifs_open_parms oparms
;
1426 struct cifs_fid fid
;
1427 struct smb2_err_rsp
*err_buf
= NULL
;
1428 struct smb2_symlink_err_rsp
*symlink
;
1429 unsigned int sub_len
;
1430 unsigned int sub_offset
;
1431 unsigned int print_len
;
1432 unsigned int print_offset
;
1434 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, full_path
);
1436 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
1441 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
1442 oparms
.disposition
= FILE_OPEN
;
1443 oparms
.create_options
= 0;
1445 oparms
.reconnect
= false;
1447 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, &err_buf
);
1449 if (!rc
|| !err_buf
) {
1454 if (le32_to_cpu(err_buf
->ByteCount
) < sizeof(struct smb2_symlink_err_rsp
) ||
1455 get_rfc1002_length(err_buf
) + 4 < SMB2_SYMLINK_STRUCT_SIZE
) {
1460 /* open must fail on symlink - reset rc */
1462 symlink
= (struct smb2_symlink_err_rsp
*)err_buf
->ErrorData
;
1463 sub_len
= le16_to_cpu(symlink
->SubstituteNameLength
);
1464 sub_offset
= le16_to_cpu(symlink
->SubstituteNameOffset
);
1465 print_len
= le16_to_cpu(symlink
->PrintNameLength
);
1466 print_offset
= le16_to_cpu(symlink
->PrintNameOffset
);
1468 if (get_rfc1002_length(err_buf
) + 4 <
1469 SMB2_SYMLINK_STRUCT_SIZE
+ sub_offset
+ sub_len
) {
1474 if (get_rfc1002_length(err_buf
) + 4 <
1475 SMB2_SYMLINK_STRUCT_SIZE
+ print_offset
+ print_len
) {
1480 *target_path
= cifs_strndup_from_utf16(
1481 (char *)symlink
->PathBuffer
+ sub_offset
,
1482 sub_len
, true, cifs_sb
->local_nls
);
1483 if (!(*target_path
)) {
1487 convert_delimiter(*target_path
, '/');
1488 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
1493 #ifdef CONFIG_CIFS_ACL
1494 static struct cifs_ntsd
*
1495 get_smb2_acl_by_fid(struct cifs_sb_info
*cifs_sb
,
1496 const struct cifs_fid
*cifsfid
, u32
*pacllen
)
1498 struct cifs_ntsd
*pntsd
= NULL
;
1500 int rc
= -EOPNOTSUPP
;
1501 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
1504 return ERR_CAST(tlink
);
1507 cifs_dbg(FYI
, "trying to get acl\n");
1509 rc
= SMB2_query_acl(xid
, tlink_tcon(tlink
), cifsfid
->persistent_fid
,
1510 cifsfid
->volatile_fid
, (void **)&pntsd
, pacllen
);
1513 cifs_put_tlink(tlink
);
1515 cifs_dbg(FYI
, "%s: rc = %d ACL len %d\n", __func__
, rc
, *pacllen
);
1522 static struct cifs_ntsd
*
1523 get_smb2_acl_by_path(struct cifs_sb_info
*cifs_sb
,
1524 const char *path
, u32
*pacllen
)
1526 struct cifs_ntsd
*pntsd
= NULL
;
1527 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1530 struct cifs_tcon
*tcon
;
1531 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
1532 struct cifs_fid fid
;
1533 struct cifs_open_parms oparms
;
1536 cifs_dbg(FYI
, "get smb3 acl for path %s\n", path
);
1538 return ERR_CAST(tlink
);
1540 tcon
= tlink_tcon(tlink
);
1543 if (backup_cred(cifs_sb
))
1544 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
1546 oparms
.create_options
= 0;
1548 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
1550 return ERR_PTR(-ENOMEM
);
1553 oparms
.desired_access
= READ_CONTROL
;
1554 oparms
.disposition
= FILE_OPEN
;
1556 oparms
.reconnect
= false;
1558 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
1561 rc
= SMB2_query_acl(xid
, tlink_tcon(tlink
), fid
.persistent_fid
,
1562 fid
.volatile_fid
, (void **)&pntsd
, pacllen
);
1563 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
1566 cifs_put_tlink(tlink
);
1569 cifs_dbg(FYI
, "%s: rc = %d ACL len %d\n", __func__
, rc
, *pacllen
);
1575 #ifdef CONFIG_CIFS_ACL
1577 set_smb2_acl(struct cifs_ntsd
*pnntsd
, __u32 acllen
,
1578 struct inode
*inode
, const char *path
, int aclflag
)
1580 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1582 int rc
, access_flags
= 0;
1583 struct cifs_tcon
*tcon
;
1584 struct cifs_sb_info
*cifs_sb
= CIFS_SB(inode
->i_sb
);
1585 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
1586 struct cifs_fid fid
;
1587 struct cifs_open_parms oparms
;
1590 cifs_dbg(FYI
, "set smb3 acl for path %s\n", path
);
1592 return PTR_ERR(tlink
);
1594 tcon
= tlink_tcon(tlink
);
1597 if (backup_cred(cifs_sb
))
1598 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
1600 oparms
.create_options
= 0;
1602 if (aclflag
== CIFS_ACL_OWNER
|| aclflag
== CIFS_ACL_GROUP
)
1603 access_flags
= WRITE_OWNER
;
1605 access_flags
= WRITE_DAC
;
1607 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
1612 oparms
.desired_access
= access_flags
;
1613 oparms
.disposition
= FILE_OPEN
;
1616 oparms
.reconnect
= false;
1618 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
1621 rc
= SMB2_set_acl(xid
, tlink_tcon(tlink
), fid
.persistent_fid
,
1622 fid
.volatile_fid
, pnntsd
, acllen
, aclflag
);
1623 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
1626 cifs_put_tlink(tlink
);
1630 #endif /* CIFS_ACL */
1632 /* Retrieve an ACL from the server */
1633 static struct cifs_ntsd
*
1634 get_smb2_acl(struct cifs_sb_info
*cifs_sb
,
1635 struct inode
*inode
, const char *path
,
1638 struct cifs_ntsd
*pntsd
= NULL
;
1639 struct cifsFileInfo
*open_file
= NULL
;
1642 open_file
= find_readable_file(CIFS_I(inode
), true);
1644 return get_smb2_acl_by_path(cifs_sb
, path
, pacllen
);
1646 pntsd
= get_smb2_acl_by_fid(cifs_sb
, &open_file
->fid
, pacllen
);
1647 cifsFileInfo_put(open_file
);
1652 static long smb3_zero_range(struct file
*file
, struct cifs_tcon
*tcon
,
1653 loff_t offset
, loff_t len
, bool keep_size
)
1655 struct inode
*inode
;
1656 struct cifsInodeInfo
*cifsi
;
1657 struct cifsFileInfo
*cfile
= file
->private_data
;
1658 struct file_zero_data_information fsctl_buf
;
1664 inode
= d_inode(cfile
->dentry
);
1665 cifsi
= CIFS_I(inode
);
1667 /* if file not oplocked can't be sure whether asking to extend size */
1668 if (!CIFS_CACHE_READ(cifsi
))
1669 if (keep_size
== false)
1673 * Must check if file sparse since fallocate -z (zero range) assumes
1674 * non-sparse allocation
1676 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
))
1680 * need to make sure we are not asked to extend the file since the SMB3
1681 * fsctl does not change the file size. In the future we could change
1682 * this to zero the first part of the range then set the file size
1683 * which for a non sparse file would zero the newly extended range
1685 if (keep_size
== false)
1686 if (i_size_read(inode
) < offset
+ len
)
1689 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1691 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1692 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1694 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1695 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1696 true /* is_fctl */, false /* use_ipc */,
1698 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1703 static long smb3_punch_hole(struct file
*file
, struct cifs_tcon
*tcon
,
1704 loff_t offset
, loff_t len
)
1706 struct inode
*inode
;
1707 struct cifsInodeInfo
*cifsi
;
1708 struct cifsFileInfo
*cfile
= file
->private_data
;
1709 struct file_zero_data_information fsctl_buf
;
1712 __u8 set_sparse
= 1;
1716 inode
= d_inode(cfile
->dentry
);
1717 cifsi
= CIFS_I(inode
);
1719 /* Need to make file sparse, if not already, before freeing range. */
1720 /* Consider adding equivalent for compressed since it could also work */
1721 if (!smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
))
1724 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1726 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1727 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1729 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1730 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1731 true /* is_fctl */, false /* use_ipc */,
1733 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1738 static long smb3_simple_falloc(struct file
*file
, struct cifs_tcon
*tcon
,
1739 loff_t off
, loff_t len
, bool keep_size
)
1741 struct inode
*inode
;
1742 struct cifsInodeInfo
*cifsi
;
1743 struct cifsFileInfo
*cfile
= file
->private_data
;
1744 long rc
= -EOPNOTSUPP
;
1749 inode
= d_inode(cfile
->dentry
);
1750 cifsi
= CIFS_I(inode
);
1752 /* if file not oplocked can't be sure whether asking to extend size */
1753 if (!CIFS_CACHE_READ(cifsi
))
1754 if (keep_size
== false)
1758 * Files are non-sparse by default so falloc may be a no-op
1759 * Must check if file sparse. If not sparse, and not extending
1760 * then no need to do anything since file already allocated
1762 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) == 0) {
1763 if (keep_size
== true)
1765 /* check if extending file */
1766 else if (i_size_read(inode
) >= off
+ len
)
1767 /* not extending file and already not sparse */
1769 /* BB: in future add else clause to extend file */
1774 if ((keep_size
== true) || (i_size_read(inode
) >= off
+ len
)) {
1776 * Check if falloc starts within first few pages of file
1777 * and ends within a few pages of the end of file to
1778 * ensure that most of file is being forced to be
1779 * fallocated now. If so then setting whole file sparse
1780 * ie potentially making a few extra pages at the beginning
1781 * or end of the file non-sparse via set_sparse is harmless.
1783 if ((off
> 8192) || (off
+ len
+ 8192 < i_size_read(inode
)))
1786 rc
= smb2_set_sparse(xid
, tcon
, cfile
, inode
, false);
1788 /* BB: else ... in future add code to extend file and set sparse */
1796 static long smb3_fallocate(struct file
*file
, struct cifs_tcon
*tcon
, int mode
,
1797 loff_t off
, loff_t len
)
1799 /* KEEP_SIZE already checked for by do_fallocate */
1800 if (mode
& FALLOC_FL_PUNCH_HOLE
)
1801 return smb3_punch_hole(file
, tcon
, off
, len
);
1802 else if (mode
& FALLOC_FL_ZERO_RANGE
) {
1803 if (mode
& FALLOC_FL_KEEP_SIZE
)
1804 return smb3_zero_range(file
, tcon
, off
, len
, true);
1805 return smb3_zero_range(file
, tcon
, off
, len
, false);
1806 } else if (mode
== FALLOC_FL_KEEP_SIZE
)
1807 return smb3_simple_falloc(file
, tcon
, off
, len
, true);
1809 return smb3_simple_falloc(file
, tcon
, off
, len
, false);
1815 smb2_downgrade_oplock(struct TCP_Server_Info
*server
,
1816 struct cifsInodeInfo
*cinode
, bool set_level2
)
1819 server
->ops
->set_oplock_level(cinode
, SMB2_OPLOCK_LEVEL_II
,
1822 server
->ops
->set_oplock_level(cinode
, 0, 0, NULL
);
1826 smb2_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1827 unsigned int epoch
, bool *purge_cache
)
1830 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1832 if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
) {
1833 cinode
->oplock
= CIFS_CACHE_RHW_FLG
;
1834 cifs_dbg(FYI
, "Batch Oplock granted on inode %p\n",
1835 &cinode
->vfs_inode
);
1836 } else if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
) {
1837 cinode
->oplock
= CIFS_CACHE_RW_FLG
;
1838 cifs_dbg(FYI
, "Exclusive Oplock granted on inode %p\n",
1839 &cinode
->vfs_inode
);
1840 } else if (oplock
== SMB2_OPLOCK_LEVEL_II
) {
1841 cinode
->oplock
= CIFS_CACHE_READ_FLG
;
1842 cifs_dbg(FYI
, "Level II Oplock granted on inode %p\n",
1843 &cinode
->vfs_inode
);
1849 smb21_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1850 unsigned int epoch
, bool *purge_cache
)
1852 char message
[5] = {0};
1855 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1859 if (oplock
& SMB2_LEASE_READ_CACHING_HE
) {
1860 cinode
->oplock
|= CIFS_CACHE_READ_FLG
;
1861 strcat(message
, "R");
1863 if (oplock
& SMB2_LEASE_HANDLE_CACHING_HE
) {
1864 cinode
->oplock
|= CIFS_CACHE_HANDLE_FLG
;
1865 strcat(message
, "H");
1867 if (oplock
& SMB2_LEASE_WRITE_CACHING_HE
) {
1868 cinode
->oplock
|= CIFS_CACHE_WRITE_FLG
;
1869 strcat(message
, "W");
1871 if (!cinode
->oplock
)
1872 strcat(message
, "None");
1873 cifs_dbg(FYI
, "%s Lease granted on inode %p\n", message
,
1874 &cinode
->vfs_inode
);
1878 smb3_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1879 unsigned int epoch
, bool *purge_cache
)
1881 unsigned int old_oplock
= cinode
->oplock
;
1883 smb21_set_oplock_level(cinode
, oplock
, epoch
, purge_cache
);
1886 *purge_cache
= false;
1887 if (old_oplock
== CIFS_CACHE_READ_FLG
) {
1888 if (cinode
->oplock
== CIFS_CACHE_READ_FLG
&&
1889 (epoch
- cinode
->epoch
> 0))
1890 *purge_cache
= true;
1891 else if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1892 (epoch
- cinode
->epoch
> 1))
1893 *purge_cache
= true;
1894 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1895 (epoch
- cinode
->epoch
> 1))
1896 *purge_cache
= true;
1897 else if (cinode
->oplock
== 0 &&
1898 (epoch
- cinode
->epoch
> 0))
1899 *purge_cache
= true;
1900 } else if (old_oplock
== CIFS_CACHE_RH_FLG
) {
1901 if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1902 (epoch
- cinode
->epoch
> 0))
1903 *purge_cache
= true;
1904 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1905 (epoch
- cinode
->epoch
> 1))
1906 *purge_cache
= true;
1908 cinode
->epoch
= epoch
;
1913 smb2_is_read_op(__u32 oplock
)
1915 return oplock
== SMB2_OPLOCK_LEVEL_II
;
1919 smb21_is_read_op(__u32 oplock
)
1921 return (oplock
& SMB2_LEASE_READ_CACHING_HE
) &&
1922 !(oplock
& SMB2_LEASE_WRITE_CACHING_HE
);
1926 map_oplock_to_lease(u8 oplock
)
1928 if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
)
1929 return SMB2_LEASE_WRITE_CACHING
| SMB2_LEASE_READ_CACHING
;
1930 else if (oplock
== SMB2_OPLOCK_LEVEL_II
)
1931 return SMB2_LEASE_READ_CACHING
;
1932 else if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
)
1933 return SMB2_LEASE_HANDLE_CACHING
| SMB2_LEASE_READ_CACHING
|
1934 SMB2_LEASE_WRITE_CACHING
;
1939 smb2_create_lease_buf(u8
*lease_key
, u8 oplock
)
1941 struct create_lease
*buf
;
1943 buf
= kzalloc(sizeof(struct create_lease
), GFP_KERNEL
);
1947 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1948 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1949 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1951 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1952 (struct create_lease
, lcontext
));
1953 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context
));
1954 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1955 (struct create_lease
, Name
));
1956 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1957 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1966 smb3_create_lease_buf(u8
*lease_key
, u8 oplock
)
1968 struct create_lease_v2
*buf
;
1970 buf
= kzalloc(sizeof(struct create_lease_v2
), GFP_KERNEL
);
1974 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1975 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1976 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1978 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1979 (struct create_lease_v2
, lcontext
));
1980 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context_v2
));
1981 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1982 (struct create_lease_v2
, Name
));
1983 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1984 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1993 smb2_parse_lease_buf(void *buf
, unsigned int *epoch
)
1995 struct create_lease
*lc
= (struct create_lease
*)buf
;
1997 *epoch
= 0; /* not used */
1998 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
1999 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
2000 return le32_to_cpu(lc
->lcontext
.LeaseState
);
2004 smb3_parse_lease_buf(void *buf
, unsigned int *epoch
)
2006 struct create_lease_v2
*lc
= (struct create_lease_v2
*)buf
;
2008 *epoch
= le16_to_cpu(lc
->lcontext
.Epoch
);
2009 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
2010 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
2011 return le32_to_cpu(lc
->lcontext
.LeaseState
);
2015 smb2_wp_retry_size(struct inode
*inode
)
2017 return min_t(unsigned int, CIFS_SB(inode
->i_sb
)->wsize
,
2018 SMB2_MAX_BUFFER_SIZE
);
2022 smb2_dir_needs_close(struct cifsFileInfo
*cfile
)
2024 return !cfile
->invalidHandle
;
2028 fill_transform_hdr(struct smb2_transform_hdr
*tr_hdr
, struct smb_rqst
*old_rq
)
2030 struct smb2_sync_hdr
*shdr
=
2031 (struct smb2_sync_hdr
*)old_rq
->rq_iov
[1].iov_base
;
2032 unsigned int orig_len
= get_rfc1002_length(old_rq
->rq_iov
[0].iov_base
);
2034 memset(tr_hdr
, 0, sizeof(struct smb2_transform_hdr
));
2035 tr_hdr
->ProtocolId
= SMB2_TRANSFORM_PROTO_NUM
;
2036 tr_hdr
->OriginalMessageSize
= cpu_to_le32(orig_len
);
2037 tr_hdr
->Flags
= cpu_to_le16(0x01);
2038 get_random_bytes(&tr_hdr
->Nonce
, SMB3_AES128CMM_NONCE
);
2039 memcpy(&tr_hdr
->SessionId
, &shdr
->SessionId
, 8);
2040 inc_rfc1001_len(tr_hdr
, sizeof(struct smb2_transform_hdr
) - 4);
2041 inc_rfc1001_len(tr_hdr
, orig_len
);
2044 static struct scatterlist
*
2045 init_sg(struct smb_rqst
*rqst
, u8
*sign
)
2047 unsigned int sg_len
= rqst
->rq_nvec
+ rqst
->rq_npages
+ 1;
2048 unsigned int assoc_data_len
= sizeof(struct smb2_transform_hdr
) - 24;
2049 struct scatterlist
*sg
;
2053 sg
= kmalloc_array(sg_len
, sizeof(struct scatterlist
), GFP_KERNEL
);
2057 sg_init_table(sg
, sg_len
);
2058 sg_set_buf(&sg
[0], rqst
->rq_iov
[0].iov_base
+ 24, assoc_data_len
);
2059 for (i
= 1; i
< rqst
->rq_nvec
; i
++)
2060 sg_set_buf(&sg
[i
], rqst
->rq_iov
[i
].iov_base
,
2061 rqst
->rq_iov
[i
].iov_len
);
2062 for (j
= 0; i
< sg_len
- 1; i
++, j
++) {
2063 unsigned int len
= (j
< rqst
->rq_npages
- 1) ? rqst
->rq_pagesz
2065 sg_set_page(&sg
[i
], rqst
->rq_pages
[j
], len
, 0);
2067 sg_set_buf(&sg
[sg_len
- 1], sign
, SMB2_SIGNATURE_SIZE
);
2071 struct cifs_crypt_result
{
2073 struct completion completion
;
2076 static void cifs_crypt_complete(struct crypto_async_request
*req
, int err
)
2078 struct cifs_crypt_result
*res
= req
->data
;
2080 if (err
== -EINPROGRESS
)
2084 complete(&res
->completion
);
2088 smb2_get_enc_key(struct TCP_Server_Info
*server
, __u64 ses_id
, int enc
, u8
*key
)
2090 struct cifs_ses
*ses
;
2093 spin_lock(&cifs_tcp_ses_lock
);
2094 list_for_each_entry(ses
, &server
->smb_ses_list
, smb_ses_list
) {
2095 if (ses
->Suid
!= ses_id
)
2097 ses_enc_key
= enc
? ses
->smb3encryptionkey
:
2098 ses
->smb3decryptionkey
;
2099 memcpy(key
, ses_enc_key
, SMB3_SIGN_KEY_SIZE
);
2100 spin_unlock(&cifs_tcp_ses_lock
);
2103 spin_unlock(&cifs_tcp_ses_lock
);
2108 * Encrypt or decrypt @rqst message. @rqst has the following format:
2109 * iov[0] - transform header (associate data),
2110 * iov[1-N] and pages - data to encrypt.
2111 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
2115 crypt_message(struct TCP_Server_Info
*server
, struct smb_rqst
*rqst
, int enc
)
2117 struct smb2_transform_hdr
*tr_hdr
=
2118 (struct smb2_transform_hdr
*)rqst
->rq_iov
[0].iov_base
;
2119 unsigned int assoc_data_len
= sizeof(struct smb2_transform_hdr
) - 24;
2121 struct scatterlist
*sg
;
2122 u8 sign
[SMB2_SIGNATURE_SIZE
] = {};
2123 u8 key
[SMB3_SIGN_KEY_SIZE
];
2124 struct aead_request
*req
;
2126 unsigned int iv_len
;
2127 struct cifs_crypt_result result
= {0, };
2128 struct crypto_aead
*tfm
;
2129 unsigned int crypt_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
2131 init_completion(&result
.completion
);
2133 rc
= smb2_get_enc_key(server
, tr_hdr
->SessionId
, enc
, key
);
2135 cifs_dbg(VFS
, "%s: Could not get %scryption key\n", __func__
,
2140 rc
= smb3_crypto_aead_allocate(server
);
2142 cifs_dbg(VFS
, "%s: crypto alloc failed\n", __func__
);
2146 tfm
= enc
? server
->secmech
.ccmaesencrypt
:
2147 server
->secmech
.ccmaesdecrypt
;
2148 rc
= crypto_aead_setkey(tfm
, key
, SMB3_SIGN_KEY_SIZE
);
2150 cifs_dbg(VFS
, "%s: Failed to set aead key %d\n", __func__
, rc
);
2154 rc
= crypto_aead_setauthsize(tfm
, SMB2_SIGNATURE_SIZE
);
2156 cifs_dbg(VFS
, "%s: Failed to set authsize %d\n", __func__
, rc
);
2160 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
2162 cifs_dbg(VFS
, "%s: Failed to alloc aead request", __func__
);
2167 memcpy(sign
, &tr_hdr
->Signature
, SMB2_SIGNATURE_SIZE
);
2168 crypt_len
+= SMB2_SIGNATURE_SIZE
;
2171 sg
= init_sg(rqst
, sign
);
2173 cifs_dbg(VFS
, "%s: Failed to init sg", __func__
);
2178 iv_len
= crypto_aead_ivsize(tfm
);
2179 iv
= kzalloc(iv_len
, GFP_KERNEL
);
2181 cifs_dbg(VFS
, "%s: Failed to alloc IV", __func__
);
2186 memcpy(iv
+ 1, (char *)tr_hdr
->Nonce
, SMB3_AES128CMM_NONCE
);
2188 aead_request_set_crypt(req
, sg
, sg
, crypt_len
, iv
);
2189 aead_request_set_ad(req
, assoc_data_len
);
2191 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
2192 cifs_crypt_complete
, &result
);
2194 rc
= enc
? crypto_aead_encrypt(req
) : crypto_aead_decrypt(req
);
2196 if (rc
== -EINPROGRESS
|| rc
== -EBUSY
) {
2197 wait_for_completion(&result
.completion
);
2202 memcpy(&tr_hdr
->Signature
, sign
, SMB2_SIGNATURE_SIZE
);
2213 smb3_init_transform_rq(struct TCP_Server_Info
*server
, struct smb_rqst
*new_rq
,
2214 struct smb_rqst
*old_rq
)
2217 struct page
**pages
;
2218 struct smb2_transform_hdr
*tr_hdr
;
2219 unsigned int npages
= old_rq
->rq_npages
;
2223 pages
= kmalloc_array(npages
, sizeof(struct page
*), GFP_KERNEL
);
2227 new_rq
->rq_pages
= pages
;
2228 new_rq
->rq_npages
= old_rq
->rq_npages
;
2229 new_rq
->rq_pagesz
= old_rq
->rq_pagesz
;
2230 new_rq
->rq_tailsz
= old_rq
->rq_tailsz
;
2232 for (i
= 0; i
< npages
; i
++) {
2233 pages
[i
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
2235 goto err_free_pages
;
2238 iov
= kmalloc_array(old_rq
->rq_nvec
, sizeof(struct kvec
), GFP_KERNEL
);
2240 goto err_free_pages
;
2242 /* copy all iovs from the old except the 1st one (rfc1002 length) */
2243 memcpy(&iov
[1], &old_rq
->rq_iov
[1],
2244 sizeof(struct kvec
) * (old_rq
->rq_nvec
- 1));
2245 new_rq
->rq_iov
= iov
;
2246 new_rq
->rq_nvec
= old_rq
->rq_nvec
;
2248 tr_hdr
= kmalloc(sizeof(struct smb2_transform_hdr
), GFP_KERNEL
);
2252 /* fill the 1st iov with a transform header */
2253 fill_transform_hdr(tr_hdr
, old_rq
);
2254 new_rq
->rq_iov
[0].iov_base
= tr_hdr
;
2255 new_rq
->rq_iov
[0].iov_len
= sizeof(struct smb2_transform_hdr
);
2257 /* copy pages form the old */
2258 for (i
= 0; i
< npages
; i
++) {
2259 char *dst
= kmap(new_rq
->rq_pages
[i
]);
2260 char *src
= kmap(old_rq
->rq_pages
[i
]);
2261 unsigned int len
= (i
< npages
- 1) ? new_rq
->rq_pagesz
:
2263 memcpy(dst
, src
, len
);
2264 kunmap(new_rq
->rq_pages
[i
]);
2265 kunmap(old_rq
->rq_pages
[i
]);
2268 rc
= crypt_message(server
, new_rq
, 1);
2269 cifs_dbg(FYI
, "encrypt message returned %d", rc
);
2271 goto err_free_tr_hdr
;
2280 for (i
= i
- 1; i
>= 0; i
--)
2287 smb3_free_transform_rq(struct smb_rqst
*rqst
)
2289 int i
= rqst
->rq_npages
- 1;
2292 put_page(rqst
->rq_pages
[i
]);
2293 kfree(rqst
->rq_pages
);
2294 /* free transform header */
2295 kfree(rqst
->rq_iov
[0].iov_base
);
2296 kfree(rqst
->rq_iov
);
2300 smb3_is_transform_hdr(void *buf
)
2302 struct smb2_transform_hdr
*trhdr
= buf
;
2304 return trhdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
;
2308 decrypt_raw_data(struct TCP_Server_Info
*server
, char *buf
,
2309 unsigned int buf_data_size
, struct page
**pages
,
2310 unsigned int npages
, unsigned int page_data_size
)
2313 struct smb_rqst rqst
= {NULL
};
2314 struct smb2_hdr
*hdr
;
2317 iov
[0].iov_base
= buf
;
2318 iov
[0].iov_len
= sizeof(struct smb2_transform_hdr
);
2319 iov
[1].iov_base
= buf
+ sizeof(struct smb2_transform_hdr
);
2320 iov
[1].iov_len
= buf_data_size
;
2324 rqst
.rq_pages
= pages
;
2325 rqst
.rq_npages
= npages
;
2326 rqst
.rq_pagesz
= PAGE_SIZE
;
2327 rqst
.rq_tailsz
= (page_data_size
% PAGE_SIZE
) ? : PAGE_SIZE
;
2329 rc
= crypt_message(server
, &rqst
, 0);
2330 cifs_dbg(FYI
, "decrypt message returned %d\n", rc
);
2335 memmove(buf
+ 4, iov
[1].iov_base
, buf_data_size
);
2336 hdr
= (struct smb2_hdr
*)buf
;
2337 hdr
->smb2_buf_length
= cpu_to_be32(buf_data_size
+ page_data_size
);
2338 server
->total_read
= buf_data_size
+ page_data_size
+ 4;
2344 read_data_into_pages(struct TCP_Server_Info
*server
, struct page
**pages
,
2345 unsigned int npages
, unsigned int len
)
2350 for (i
= 0; i
< npages
; i
++) {
2351 struct page
*page
= pages
[i
];
2355 if (len
>= PAGE_SIZE
) {
2356 /* enough data to fill the page */
2360 zero_user(page
, len
, PAGE_SIZE
- len
);
2363 length
= cifs_read_page_from_socket(server
, page
, n
);
2366 server
->total_read
+= length
;
2373 init_read_bvec(struct page
**pages
, unsigned int npages
, unsigned int data_size
,
2374 unsigned int cur_off
, struct bio_vec
**page_vec
)
2376 struct bio_vec
*bvec
;
2379 bvec
= kcalloc(npages
, sizeof(struct bio_vec
), GFP_KERNEL
);
2383 for (i
= 0; i
< npages
; i
++) {
2384 bvec
[i
].bv_page
= pages
[i
];
2385 bvec
[i
].bv_offset
= (i
== 0) ? cur_off
: 0;
2386 bvec
[i
].bv_len
= min_t(unsigned int, PAGE_SIZE
, data_size
);
2387 data_size
-= bvec
[i
].bv_len
;
2390 if (data_size
!= 0) {
2391 cifs_dbg(VFS
, "%s: something went wrong\n", __func__
);
2401 handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
,
2402 char *buf
, unsigned int buf_len
, struct page
**pages
,
2403 unsigned int npages
, unsigned int page_data_size
)
2405 unsigned int data_offset
;
2406 unsigned int data_len
;
2407 unsigned int cur_off
;
2408 unsigned int cur_page_idx
;
2409 unsigned int pad_len
;
2410 struct cifs_readdata
*rdata
= mid
->callback_data
;
2411 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
2412 struct bio_vec
*bvec
= NULL
;
2413 struct iov_iter iter
;
2417 if (shdr
->Command
!= SMB2_READ
) {
2418 cifs_dbg(VFS
, "only big read responses are supported\n");
2422 if (server
->ops
->is_session_expired
&&
2423 server
->ops
->is_session_expired(buf
)) {
2424 cifs_reconnect(server
);
2425 wake_up(&server
->response_q
);
2429 if (server
->ops
->is_status_pending
&&
2430 server
->ops
->is_status_pending(buf
, server
, 0))
2433 rdata
->result
= server
->ops
->map_error(buf
, false);
2434 if (rdata
->result
!= 0) {
2435 cifs_dbg(FYI
, "%s: server returned error %d\n",
2436 __func__
, rdata
->result
);
2437 dequeue_mid(mid
, rdata
->result
);
2441 data_offset
= server
->ops
->read_data_offset(buf
) + 4;
2442 data_len
= server
->ops
->read_data_length(buf
);
2444 if (data_offset
< server
->vals
->read_rsp_size
) {
2446 * win2k8 sometimes sends an offset of 0 when the read
2447 * is beyond the EOF. Treat it as if the data starts just after
2450 cifs_dbg(FYI
, "%s: data offset (%u) inside read response header\n",
2451 __func__
, data_offset
);
2452 data_offset
= server
->vals
->read_rsp_size
;
2453 } else if (data_offset
> MAX_CIFS_SMALL_BUFFER_SIZE
) {
2454 /* data_offset is beyond the end of smallbuf */
2455 cifs_dbg(FYI
, "%s: data offset (%u) beyond end of smallbuf\n",
2456 __func__
, data_offset
);
2457 rdata
->result
= -EIO
;
2458 dequeue_mid(mid
, rdata
->result
);
2462 pad_len
= data_offset
- server
->vals
->read_rsp_size
;
2464 if (buf_len
<= data_offset
) {
2465 /* read response payload is in pages */
2466 cur_page_idx
= pad_len
/ PAGE_SIZE
;
2467 cur_off
= pad_len
% PAGE_SIZE
;
2469 if (cur_page_idx
!= 0) {
2470 /* data offset is beyond the 1st page of response */
2471 cifs_dbg(FYI
, "%s: data offset (%u) beyond 1st page of response\n",
2472 __func__
, data_offset
);
2473 rdata
->result
= -EIO
;
2474 dequeue_mid(mid
, rdata
->result
);
2478 if (data_len
> page_data_size
- pad_len
) {
2479 /* data_len is corrupt -- discard frame */
2480 rdata
->result
= -EIO
;
2481 dequeue_mid(mid
, rdata
->result
);
2485 rdata
->result
= init_read_bvec(pages
, npages
, page_data_size
,
2487 if (rdata
->result
!= 0) {
2488 dequeue_mid(mid
, rdata
->result
);
2492 iov_iter_bvec(&iter
, WRITE
| ITER_BVEC
, bvec
, npages
, data_len
);
2493 } else if (buf_len
>= data_offset
+ data_len
) {
2494 /* read response payload is in buf */
2495 WARN_ONCE(npages
> 0, "read data can be either in buf or in pages");
2496 iov
.iov_base
= buf
+ data_offset
;
2497 iov
.iov_len
= data_len
;
2498 iov_iter_kvec(&iter
, WRITE
| ITER_KVEC
, &iov
, 1, data_len
);
2500 /* read response payload cannot be in both buf and pages */
2501 WARN_ONCE(1, "buf can not contain only a part of read data");
2502 rdata
->result
= -EIO
;
2503 dequeue_mid(mid
, rdata
->result
);
2507 /* set up first iov for signature check */
2508 rdata
->iov
[0].iov_base
= buf
;
2509 rdata
->iov
[0].iov_len
= 4;
2510 rdata
->iov
[1].iov_base
= buf
+ 4;
2511 rdata
->iov
[1].iov_len
= server
->vals
->read_rsp_size
- 4;
2512 cifs_dbg(FYI
, "0: iov_base=%p iov_len=%zu\n",
2513 rdata
->iov
[0].iov_base
, server
->vals
->read_rsp_size
);
2515 length
= rdata
->copy_into_pages(server
, rdata
, &iter
);
2522 dequeue_mid(mid
, false);
2527 receive_encrypted_read(struct TCP_Server_Info
*server
, struct mid_q_entry
**mid
)
2529 char *buf
= server
->smallbuf
;
2530 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
2531 unsigned int npages
;
2532 struct page
**pages
;
2534 unsigned int buflen
= get_rfc1002_length(buf
) + 4;
2538 len
= min_t(unsigned int, buflen
, server
->vals
->read_rsp_size
- 4 +
2539 sizeof(struct smb2_transform_hdr
)) - HEADER_SIZE(server
) + 1;
2541 rc
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1, len
);
2544 server
->total_read
+= rc
;
2546 len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
) + 4 -
2547 server
->vals
->read_rsp_size
;
2548 npages
= DIV_ROUND_UP(len
, PAGE_SIZE
);
2550 pages
= kmalloc_array(npages
, sizeof(struct page
*), GFP_KERNEL
);
2556 for (; i
< npages
; i
++) {
2557 pages
[i
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
2564 /* read read data into pages */
2565 rc
= read_data_into_pages(server
, pages
, npages
, len
);
2569 rc
= cifs_discard_remaining_data(server
);
2573 rc
= decrypt_raw_data(server
, buf
, server
->vals
->read_rsp_size
- 4,
2574 pages
, npages
, len
);
2578 *mid
= smb2_find_mid(server
, buf
);
2580 cifs_dbg(FYI
, "mid not found\n");
2582 cifs_dbg(FYI
, "mid found\n");
2583 (*mid
)->decrypted
= true;
2584 rc
= handle_read_data(server
, *mid
, buf
,
2585 server
->vals
->read_rsp_size
,
2586 pages
, npages
, len
);
2590 for (i
= i
- 1; i
>= 0; i
--)
2595 cifs_discard_remaining_data(server
);
2600 receive_encrypted_standard(struct TCP_Server_Info
*server
,
2601 struct mid_q_entry
**mid
)
2604 char *buf
= server
->smallbuf
;
2605 unsigned int pdu_length
= get_rfc1002_length(buf
);
2606 unsigned int buf_size
;
2607 struct mid_q_entry
*mid_entry
;
2609 /* switch to large buffer if too big for a small one */
2610 if (pdu_length
+ 4 > MAX_CIFS_SMALL_BUFFER_SIZE
) {
2611 server
->large_buf
= true;
2612 memcpy(server
->bigbuf
, buf
, server
->total_read
);
2613 buf
= server
->bigbuf
;
2616 /* now read the rest */
2617 length
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1,
2618 pdu_length
- HEADER_SIZE(server
) + 1 + 4);
2621 server
->total_read
+= length
;
2623 buf_size
= pdu_length
+ 4 - sizeof(struct smb2_transform_hdr
);
2624 length
= decrypt_raw_data(server
, buf
, buf_size
, NULL
, 0, 0);
2628 mid_entry
= smb2_find_mid(server
, buf
);
2629 if (mid_entry
== NULL
)
2630 cifs_dbg(FYI
, "mid not found\n");
2632 cifs_dbg(FYI
, "mid found\n");
2633 mid_entry
->decrypted
= true;
2638 if (mid_entry
&& mid_entry
->handle
)
2639 return mid_entry
->handle(server
, mid_entry
);
2641 return cifs_handle_standard(server
, mid_entry
);
2645 smb3_receive_transform(struct TCP_Server_Info
*server
, struct mid_q_entry
**mid
)
2647 char *buf
= server
->smallbuf
;
2648 unsigned int pdu_length
= get_rfc1002_length(buf
);
2649 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
2650 unsigned int orig_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
2652 if (pdu_length
+ 4 < sizeof(struct smb2_transform_hdr
) +
2653 sizeof(struct smb2_sync_hdr
)) {
2654 cifs_dbg(VFS
, "Transform message is too small (%u)\n",
2656 cifs_reconnect(server
);
2657 wake_up(&server
->response_q
);
2658 return -ECONNABORTED
;
2661 if (pdu_length
+ 4 < orig_len
+ sizeof(struct smb2_transform_hdr
)) {
2662 cifs_dbg(VFS
, "Transform message is broken\n");
2663 cifs_reconnect(server
);
2664 wake_up(&server
->response_q
);
2665 return -ECONNABORTED
;
2668 if (pdu_length
+ 4 > CIFSMaxBufSize
+ MAX_HEADER_SIZE(server
))
2669 return receive_encrypted_read(server
, mid
);
2671 return receive_encrypted_standard(server
, mid
);
2675 smb3_handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
)
2677 char *buf
= server
->large_buf
? server
->bigbuf
: server
->smallbuf
;
2679 return handle_read_data(server
, mid
, buf
, get_rfc1002_length(buf
) + 4,
2683 struct smb_version_operations smb20_operations
= {
2684 .compare_fids
= smb2_compare_fids
,
2685 .setup_request
= smb2_setup_request
,
2686 .setup_async_request
= smb2_setup_async_request
,
2687 .check_receive
= smb2_check_receive
,
2688 .add_credits
= smb2_add_credits
,
2689 .set_credits
= smb2_set_credits
,
2690 .get_credits_field
= smb2_get_credits_field
,
2691 .get_credits
= smb2_get_credits
,
2692 .wait_mtu_credits
= cifs_wait_mtu_credits
,
2693 .get_next_mid
= smb2_get_next_mid
,
2694 .read_data_offset
= smb2_read_data_offset
,
2695 .read_data_length
= smb2_read_data_length
,
2696 .map_error
= map_smb2_to_linux_error
,
2697 .find_mid
= smb2_find_mid
,
2698 .check_message
= smb2_check_message
,
2699 .dump_detail
= smb2_dump_detail
,
2700 .clear_stats
= smb2_clear_stats
,
2701 .print_stats
= smb2_print_stats
,
2702 .is_oplock_break
= smb2_is_valid_oplock_break
,
2703 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
2704 .downgrade_oplock
= smb2_downgrade_oplock
,
2705 .need_neg
= smb2_need_neg
,
2706 .negotiate
= smb2_negotiate
,
2707 .negotiate_wsize
= smb2_negotiate_wsize
,
2708 .negotiate_rsize
= smb2_negotiate_rsize
,
2709 .sess_setup
= SMB2_sess_setup
,
2710 .logoff
= SMB2_logoff
,
2711 .tree_connect
= SMB2_tcon
,
2712 .tree_disconnect
= SMB2_tdis
,
2713 .qfs_tcon
= smb2_qfs_tcon
,
2714 .is_path_accessible
= smb2_is_path_accessible
,
2715 .can_echo
= smb2_can_echo
,
2717 .query_path_info
= smb2_query_path_info
,
2718 .get_srv_inum
= smb2_get_srv_inum
,
2719 .query_file_info
= smb2_query_file_info
,
2720 .set_path_size
= smb2_set_path_size
,
2721 .set_file_size
= smb2_set_file_size
,
2722 .set_file_info
= smb2_set_file_info
,
2723 .set_compression
= smb2_set_compression
,
2724 .mkdir
= smb2_mkdir
,
2725 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2726 .rmdir
= smb2_rmdir
,
2727 .unlink
= smb2_unlink
,
2728 .rename
= smb2_rename_path
,
2729 .create_hardlink
= smb2_create_hardlink
,
2730 .query_symlink
= smb2_query_symlink
,
2731 .query_mf_symlink
= smb3_query_mf_symlink
,
2732 .create_mf_symlink
= smb3_create_mf_symlink
,
2733 .open
= smb2_open_file
,
2734 .set_fid
= smb2_set_fid
,
2735 .close
= smb2_close_file
,
2736 .flush
= smb2_flush_file
,
2737 .async_readv
= smb2_async_readv
,
2738 .async_writev
= smb2_async_writev
,
2739 .sync_read
= smb2_sync_read
,
2740 .sync_write
= smb2_sync_write
,
2741 .query_dir_first
= smb2_query_dir_first
,
2742 .query_dir_next
= smb2_query_dir_next
,
2743 .close_dir
= smb2_close_dir
,
2744 .calc_smb_size
= smb2_calc_size
,
2745 .is_status_pending
= smb2_is_status_pending
,
2746 .is_session_expired
= smb2_is_session_expired
,
2747 .oplock_response
= smb2_oplock_response
,
2748 .queryfs
= smb2_queryfs
,
2749 .mand_lock
= smb2_mand_lock
,
2750 .mand_unlock_range
= smb2_unlock_range
,
2751 .push_mand_locks
= smb2_push_mandatory_locks
,
2752 .get_lease_key
= smb2_get_lease_key
,
2753 .set_lease_key
= smb2_set_lease_key
,
2754 .new_lease_key
= smb2_new_lease_key
,
2755 .calc_signature
= smb2_calc_signature
,
2756 .is_read_op
= smb2_is_read_op
,
2757 .set_oplock_level
= smb2_set_oplock_level
,
2758 .create_lease_buf
= smb2_create_lease_buf
,
2759 .parse_lease_buf
= smb2_parse_lease_buf
,
2760 .copychunk_range
= smb2_copychunk_range
,
2761 .wp_retry_size
= smb2_wp_retry_size
,
2762 .dir_needs_close
= smb2_dir_needs_close
,
2763 .get_dfs_refer
= smb2_get_dfs_refer
,
2764 .select_sectype
= smb2_select_sectype
,
2765 #ifdef CONFIG_CIFS_XATTR
2766 .query_all_EAs
= smb2_query_eas
,
2767 .set_EA
= smb2_set_ea
,
2768 #endif /* CIFS_XATTR */
2769 #ifdef CONFIG_CIFS_ACL
2770 .get_acl
= get_smb2_acl
,
2771 .get_acl_by_fid
= get_smb2_acl_by_fid
,
2772 .set_acl
= set_smb2_acl
,
2773 #endif /* CIFS_ACL */
2776 struct smb_version_operations smb21_operations
= {
2777 .compare_fids
= smb2_compare_fids
,
2778 .setup_request
= smb2_setup_request
,
2779 .setup_async_request
= smb2_setup_async_request
,
2780 .check_receive
= smb2_check_receive
,
2781 .add_credits
= smb2_add_credits
,
2782 .set_credits
= smb2_set_credits
,
2783 .get_credits_field
= smb2_get_credits_field
,
2784 .get_credits
= smb2_get_credits
,
2785 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2786 .get_next_mid
= smb2_get_next_mid
,
2787 .read_data_offset
= smb2_read_data_offset
,
2788 .read_data_length
= smb2_read_data_length
,
2789 .map_error
= map_smb2_to_linux_error
,
2790 .find_mid
= smb2_find_mid
,
2791 .check_message
= smb2_check_message
,
2792 .dump_detail
= smb2_dump_detail
,
2793 .clear_stats
= smb2_clear_stats
,
2794 .print_stats
= smb2_print_stats
,
2795 .is_oplock_break
= smb2_is_valid_oplock_break
,
2796 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
2797 .downgrade_oplock
= smb2_downgrade_oplock
,
2798 .need_neg
= smb2_need_neg
,
2799 .negotiate
= smb2_negotiate
,
2800 .negotiate_wsize
= smb2_negotiate_wsize
,
2801 .negotiate_rsize
= smb2_negotiate_rsize
,
2802 .sess_setup
= SMB2_sess_setup
,
2803 .logoff
= SMB2_logoff
,
2804 .tree_connect
= SMB2_tcon
,
2805 .tree_disconnect
= SMB2_tdis
,
2806 .qfs_tcon
= smb2_qfs_tcon
,
2807 .is_path_accessible
= smb2_is_path_accessible
,
2808 .can_echo
= smb2_can_echo
,
2810 .query_path_info
= smb2_query_path_info
,
2811 .get_srv_inum
= smb2_get_srv_inum
,
2812 .query_file_info
= smb2_query_file_info
,
2813 .set_path_size
= smb2_set_path_size
,
2814 .set_file_size
= smb2_set_file_size
,
2815 .set_file_info
= smb2_set_file_info
,
2816 .set_compression
= smb2_set_compression
,
2817 .mkdir
= smb2_mkdir
,
2818 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2819 .rmdir
= smb2_rmdir
,
2820 .unlink
= smb2_unlink
,
2821 .rename
= smb2_rename_path
,
2822 .create_hardlink
= smb2_create_hardlink
,
2823 .query_symlink
= smb2_query_symlink
,
2824 .query_mf_symlink
= smb3_query_mf_symlink
,
2825 .create_mf_symlink
= smb3_create_mf_symlink
,
2826 .open
= smb2_open_file
,
2827 .set_fid
= smb2_set_fid
,
2828 .close
= smb2_close_file
,
2829 .flush
= smb2_flush_file
,
2830 .async_readv
= smb2_async_readv
,
2831 .async_writev
= smb2_async_writev
,
2832 .sync_read
= smb2_sync_read
,
2833 .sync_write
= smb2_sync_write
,
2834 .query_dir_first
= smb2_query_dir_first
,
2835 .query_dir_next
= smb2_query_dir_next
,
2836 .close_dir
= smb2_close_dir
,
2837 .calc_smb_size
= smb2_calc_size
,
2838 .is_status_pending
= smb2_is_status_pending
,
2839 .is_session_expired
= smb2_is_session_expired
,
2840 .oplock_response
= smb2_oplock_response
,
2841 .queryfs
= smb2_queryfs
,
2842 .mand_lock
= smb2_mand_lock
,
2843 .mand_unlock_range
= smb2_unlock_range
,
2844 .push_mand_locks
= smb2_push_mandatory_locks
,
2845 .get_lease_key
= smb2_get_lease_key
,
2846 .set_lease_key
= smb2_set_lease_key
,
2847 .new_lease_key
= smb2_new_lease_key
,
2848 .calc_signature
= smb2_calc_signature
,
2849 .is_read_op
= smb21_is_read_op
,
2850 .set_oplock_level
= smb21_set_oplock_level
,
2851 .create_lease_buf
= smb2_create_lease_buf
,
2852 .parse_lease_buf
= smb2_parse_lease_buf
,
2853 .copychunk_range
= smb2_copychunk_range
,
2854 .wp_retry_size
= smb2_wp_retry_size
,
2855 .dir_needs_close
= smb2_dir_needs_close
,
2856 .enum_snapshots
= smb3_enum_snapshots
,
2857 .get_dfs_refer
= smb2_get_dfs_refer
,
2858 .select_sectype
= smb2_select_sectype
,
2859 #ifdef CONFIG_CIFS_XATTR
2860 .query_all_EAs
= smb2_query_eas
,
2861 .set_EA
= smb2_set_ea
,
2862 #endif /* CIFS_XATTR */
2863 #ifdef CONFIG_CIFS_ACL
2864 .get_acl
= get_smb2_acl
,
2865 .get_acl_by_fid
= get_smb2_acl_by_fid
,
2866 .set_acl
= set_smb2_acl
,
2867 #endif /* CIFS_ACL */
2870 struct smb_version_operations smb30_operations
= {
2871 .compare_fids
= smb2_compare_fids
,
2872 .setup_request
= smb2_setup_request
,
2873 .setup_async_request
= smb2_setup_async_request
,
2874 .check_receive
= smb2_check_receive
,
2875 .add_credits
= smb2_add_credits
,
2876 .set_credits
= smb2_set_credits
,
2877 .get_credits_field
= smb2_get_credits_field
,
2878 .get_credits
= smb2_get_credits
,
2879 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2880 .get_next_mid
= smb2_get_next_mid
,
2881 .read_data_offset
= smb2_read_data_offset
,
2882 .read_data_length
= smb2_read_data_length
,
2883 .map_error
= map_smb2_to_linux_error
,
2884 .find_mid
= smb2_find_mid
,
2885 .check_message
= smb2_check_message
,
2886 .dump_detail
= smb2_dump_detail
,
2887 .clear_stats
= smb2_clear_stats
,
2888 .print_stats
= smb2_print_stats
,
2889 .dump_share_caps
= smb2_dump_share_caps
,
2890 .is_oplock_break
= smb2_is_valid_oplock_break
,
2891 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
2892 .downgrade_oplock
= smb2_downgrade_oplock
,
2893 .need_neg
= smb2_need_neg
,
2894 .negotiate
= smb2_negotiate
,
2895 .negotiate_wsize
= smb2_negotiate_wsize
,
2896 .negotiate_rsize
= smb2_negotiate_rsize
,
2897 .sess_setup
= SMB2_sess_setup
,
2898 .logoff
= SMB2_logoff
,
2899 .tree_connect
= SMB2_tcon
,
2900 .tree_disconnect
= SMB2_tdis
,
2901 .qfs_tcon
= smb3_qfs_tcon
,
2902 .is_path_accessible
= smb2_is_path_accessible
,
2903 .can_echo
= smb2_can_echo
,
2905 .query_path_info
= smb2_query_path_info
,
2906 .get_srv_inum
= smb2_get_srv_inum
,
2907 .query_file_info
= smb2_query_file_info
,
2908 .set_path_size
= smb2_set_path_size
,
2909 .set_file_size
= smb2_set_file_size
,
2910 .set_file_info
= smb2_set_file_info
,
2911 .set_compression
= smb2_set_compression
,
2912 .mkdir
= smb2_mkdir
,
2913 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2914 .rmdir
= smb2_rmdir
,
2915 .unlink
= smb2_unlink
,
2916 .rename
= smb2_rename_path
,
2917 .create_hardlink
= smb2_create_hardlink
,
2918 .query_symlink
= smb2_query_symlink
,
2919 .query_mf_symlink
= smb3_query_mf_symlink
,
2920 .create_mf_symlink
= smb3_create_mf_symlink
,
2921 .open
= smb2_open_file
,
2922 .set_fid
= smb2_set_fid
,
2923 .close
= smb2_close_file
,
2924 .flush
= smb2_flush_file
,
2925 .async_readv
= smb2_async_readv
,
2926 .async_writev
= smb2_async_writev
,
2927 .sync_read
= smb2_sync_read
,
2928 .sync_write
= smb2_sync_write
,
2929 .query_dir_first
= smb2_query_dir_first
,
2930 .query_dir_next
= smb2_query_dir_next
,
2931 .close_dir
= smb2_close_dir
,
2932 .calc_smb_size
= smb2_calc_size
,
2933 .is_status_pending
= smb2_is_status_pending
,
2934 .is_session_expired
= smb2_is_session_expired
,
2935 .oplock_response
= smb2_oplock_response
,
2936 .queryfs
= smb2_queryfs
,
2937 .mand_lock
= smb2_mand_lock
,
2938 .mand_unlock_range
= smb2_unlock_range
,
2939 .push_mand_locks
= smb2_push_mandatory_locks
,
2940 .get_lease_key
= smb2_get_lease_key
,
2941 .set_lease_key
= smb2_set_lease_key
,
2942 .new_lease_key
= smb2_new_lease_key
,
2943 .generate_signingkey
= generate_smb30signingkey
,
2944 .calc_signature
= smb3_calc_signature
,
2945 .set_integrity
= smb3_set_integrity
,
2946 .is_read_op
= smb21_is_read_op
,
2947 .set_oplock_level
= smb3_set_oplock_level
,
2948 .create_lease_buf
= smb3_create_lease_buf
,
2949 .parse_lease_buf
= smb3_parse_lease_buf
,
2950 .copychunk_range
= smb2_copychunk_range
,
2951 .duplicate_extents
= smb2_duplicate_extents
,
2952 .validate_negotiate
= smb3_validate_negotiate
,
2953 .wp_retry_size
= smb2_wp_retry_size
,
2954 .dir_needs_close
= smb2_dir_needs_close
,
2955 .fallocate
= smb3_fallocate
,
2956 .enum_snapshots
= smb3_enum_snapshots
,
2957 .init_transform_rq
= smb3_init_transform_rq
,
2958 .free_transform_rq
= smb3_free_transform_rq
,
2959 .is_transform_hdr
= smb3_is_transform_hdr
,
2960 .receive_transform
= smb3_receive_transform
,
2961 .get_dfs_refer
= smb2_get_dfs_refer
,
2962 .select_sectype
= smb2_select_sectype
,
2963 #ifdef CONFIG_CIFS_XATTR
2964 .query_all_EAs
= smb2_query_eas
,
2965 .set_EA
= smb2_set_ea
,
2966 #endif /* CIFS_XATTR */
2967 #ifdef CONFIG_CIFS_ACL
2968 .get_acl
= get_smb2_acl
,
2969 .get_acl_by_fid
= get_smb2_acl_by_fid
,
2970 .set_acl
= set_smb2_acl
,
2971 #endif /* CIFS_ACL */
2974 #ifdef CONFIG_CIFS_SMB311
2975 struct smb_version_operations smb311_operations
= {
2976 .compare_fids
= smb2_compare_fids
,
2977 .setup_request
= smb2_setup_request
,
2978 .setup_async_request
= smb2_setup_async_request
,
2979 .check_receive
= smb2_check_receive
,
2980 .add_credits
= smb2_add_credits
,
2981 .set_credits
= smb2_set_credits
,
2982 .get_credits_field
= smb2_get_credits_field
,
2983 .get_credits
= smb2_get_credits
,
2984 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2985 .get_next_mid
= smb2_get_next_mid
,
2986 .read_data_offset
= smb2_read_data_offset
,
2987 .read_data_length
= smb2_read_data_length
,
2988 .map_error
= map_smb2_to_linux_error
,
2989 .find_mid
= smb2_find_mid
,
2990 .check_message
= smb2_check_message
,
2991 .dump_detail
= smb2_dump_detail
,
2992 .clear_stats
= smb2_clear_stats
,
2993 .print_stats
= smb2_print_stats
,
2994 .dump_share_caps
= smb2_dump_share_caps
,
2995 .is_oplock_break
= smb2_is_valid_oplock_break
,
2996 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
2997 .downgrade_oplock
= smb2_downgrade_oplock
,
2998 .need_neg
= smb2_need_neg
,
2999 .negotiate
= smb2_negotiate
,
3000 .negotiate_wsize
= smb2_negotiate_wsize
,
3001 .negotiate_rsize
= smb2_negotiate_rsize
,
3002 .sess_setup
= SMB2_sess_setup
,
3003 .logoff
= SMB2_logoff
,
3004 .tree_connect
= SMB2_tcon
,
3005 .tree_disconnect
= SMB2_tdis
,
3006 .qfs_tcon
= smb3_qfs_tcon
,
3007 .is_path_accessible
= smb2_is_path_accessible
,
3008 .can_echo
= smb2_can_echo
,
3010 .query_path_info
= smb2_query_path_info
,
3011 .get_srv_inum
= smb2_get_srv_inum
,
3012 .query_file_info
= smb2_query_file_info
,
3013 .set_path_size
= smb2_set_path_size
,
3014 .set_file_size
= smb2_set_file_size
,
3015 .set_file_info
= smb2_set_file_info
,
3016 .set_compression
= smb2_set_compression
,
3017 .mkdir
= smb2_mkdir
,
3018 .mkdir_setinfo
= smb2_mkdir_setinfo
,
3019 .rmdir
= smb2_rmdir
,
3020 .unlink
= smb2_unlink
,
3021 .rename
= smb2_rename_path
,
3022 .create_hardlink
= smb2_create_hardlink
,
3023 .query_symlink
= smb2_query_symlink
,
3024 .query_mf_symlink
= smb3_query_mf_symlink
,
3025 .create_mf_symlink
= smb3_create_mf_symlink
,
3026 .open
= smb2_open_file
,
3027 .set_fid
= smb2_set_fid
,
3028 .close
= smb2_close_file
,
3029 .flush
= smb2_flush_file
,
3030 .async_readv
= smb2_async_readv
,
3031 .async_writev
= smb2_async_writev
,
3032 .sync_read
= smb2_sync_read
,
3033 .sync_write
= smb2_sync_write
,
3034 .query_dir_first
= smb2_query_dir_first
,
3035 .query_dir_next
= smb2_query_dir_next
,
3036 .close_dir
= smb2_close_dir
,
3037 .calc_smb_size
= smb2_calc_size
,
3038 .is_status_pending
= smb2_is_status_pending
,
3039 .is_session_expired
= smb2_is_session_expired
,
3040 .oplock_response
= smb2_oplock_response
,
3041 .queryfs
= smb2_queryfs
,
3042 .mand_lock
= smb2_mand_lock
,
3043 .mand_unlock_range
= smb2_unlock_range
,
3044 .push_mand_locks
= smb2_push_mandatory_locks
,
3045 .get_lease_key
= smb2_get_lease_key
,
3046 .set_lease_key
= smb2_set_lease_key
,
3047 .new_lease_key
= smb2_new_lease_key
,
3048 .generate_signingkey
= generate_smb311signingkey
,
3049 .calc_signature
= smb3_calc_signature
,
3050 .set_integrity
= smb3_set_integrity
,
3051 .is_read_op
= smb21_is_read_op
,
3052 .set_oplock_level
= smb3_set_oplock_level
,
3053 .create_lease_buf
= smb3_create_lease_buf
,
3054 .parse_lease_buf
= smb3_parse_lease_buf
,
3055 .copychunk_range
= smb2_copychunk_range
,
3056 .duplicate_extents
= smb2_duplicate_extents
,
3057 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
3058 .wp_retry_size
= smb2_wp_retry_size
,
3059 .dir_needs_close
= smb2_dir_needs_close
,
3060 .fallocate
= smb3_fallocate
,
3061 .enum_snapshots
= smb3_enum_snapshots
,
3062 .init_transform_rq
= smb3_init_transform_rq
,
3063 .free_transform_rq
= smb3_free_transform_rq
,
3064 .is_transform_hdr
= smb3_is_transform_hdr
,
3065 .receive_transform
= smb3_receive_transform
,
3066 .get_dfs_refer
= smb2_get_dfs_refer
,
3067 .select_sectype
= smb2_select_sectype
,
3068 #ifdef CONFIG_CIFS_XATTR
3069 .query_all_EAs
= smb2_query_eas
,
3070 .set_EA
= smb2_set_ea
,
3071 #endif /* CIFS_XATTR */
3073 #endif /* CIFS_SMB311 */
3075 struct smb_version_values smb20_values
= {
3076 .version_string
= SMB20_VERSION_STRING
,
3077 .protocol_id
= SMB20_PROT_ID
,
3078 .req_capabilities
= 0, /* MBZ */
3079 .large_lock_type
= 0,
3080 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3081 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3082 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3083 .header_size
= sizeof(struct smb2_hdr
),
3084 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3085 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3086 .lock_cmd
= SMB2_LOCK
,
3088 .cap_nt_find
= SMB2_NT_FIND
,
3089 .cap_large_files
= SMB2_LARGE_FILES
,
3090 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3091 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3092 .create_lease_size
= sizeof(struct create_lease
),
3095 struct smb_version_values smb21_values
= {
3096 .version_string
= SMB21_VERSION_STRING
,
3097 .protocol_id
= SMB21_PROT_ID
,
3098 .req_capabilities
= 0, /* MBZ on negotiate req until SMB3 dialect */
3099 .large_lock_type
= 0,
3100 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3101 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3102 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3103 .header_size
= sizeof(struct smb2_hdr
),
3104 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3105 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3106 .lock_cmd
= SMB2_LOCK
,
3108 .cap_nt_find
= SMB2_NT_FIND
,
3109 .cap_large_files
= SMB2_LARGE_FILES
,
3110 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3111 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3112 .create_lease_size
= sizeof(struct create_lease
),
3115 struct smb_version_values smb3any_values
= {
3116 .version_string
= SMB3ANY_VERSION_STRING
,
3117 .protocol_id
= SMB302_PROT_ID
, /* doesn't matter, send protocol array */
3118 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
3119 .large_lock_type
= 0,
3120 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3121 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3122 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3123 .header_size
= sizeof(struct smb2_hdr
),
3124 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3125 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3126 .lock_cmd
= SMB2_LOCK
,
3128 .cap_nt_find
= SMB2_NT_FIND
,
3129 .cap_large_files
= SMB2_LARGE_FILES
,
3130 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3131 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3132 .create_lease_size
= sizeof(struct create_lease_v2
),
3135 struct smb_version_values smbdefault_values
= {
3136 .version_string
= SMBDEFAULT_VERSION_STRING
,
3137 .protocol_id
= SMB302_PROT_ID
, /* doesn't matter, send protocol array */
3138 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
3139 .large_lock_type
= 0,
3140 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3141 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3142 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3143 .header_size
= sizeof(struct smb2_hdr
),
3144 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3145 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3146 .lock_cmd
= SMB2_LOCK
,
3148 .cap_nt_find
= SMB2_NT_FIND
,
3149 .cap_large_files
= SMB2_LARGE_FILES
,
3150 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3151 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3152 .create_lease_size
= sizeof(struct create_lease_v2
),
3155 struct smb_version_values smb30_values
= {
3156 .version_string
= SMB30_VERSION_STRING
,
3157 .protocol_id
= SMB30_PROT_ID
,
3158 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
3159 .large_lock_type
= 0,
3160 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3161 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3162 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3163 .header_size
= sizeof(struct smb2_hdr
),
3164 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3165 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3166 .lock_cmd
= SMB2_LOCK
,
3168 .cap_nt_find
= SMB2_NT_FIND
,
3169 .cap_large_files
= SMB2_LARGE_FILES
,
3170 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3171 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3172 .create_lease_size
= sizeof(struct create_lease_v2
),
3175 struct smb_version_values smb302_values
= {
3176 .version_string
= SMB302_VERSION_STRING
,
3177 .protocol_id
= SMB302_PROT_ID
,
3178 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
3179 .large_lock_type
= 0,
3180 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3181 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3182 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3183 .header_size
= sizeof(struct smb2_hdr
),
3184 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3185 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3186 .lock_cmd
= SMB2_LOCK
,
3188 .cap_nt_find
= SMB2_NT_FIND
,
3189 .cap_large_files
= SMB2_LARGE_FILES
,
3190 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3191 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3192 .create_lease_size
= sizeof(struct create_lease_v2
),
3195 #ifdef CONFIG_CIFS_SMB311
3196 struct smb_version_values smb311_values
= {
3197 .version_string
= SMB311_VERSION_STRING
,
3198 .protocol_id
= SMB311_PROT_ID
,
3199 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
3200 .large_lock_type
= 0,
3201 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
3202 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
3203 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
3204 .header_size
= sizeof(struct smb2_hdr
),
3205 .max_header_size
= MAX_SMB2_HDR_SIZE
,
3206 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
3207 .lock_cmd
= SMB2_LOCK
,
3209 .cap_nt_find
= SMB2_NT_FIND
,
3210 .cap_large_files
= SMB2_LARGE_FILES
,
3211 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3212 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
3213 .create_lease_size
= sizeof(struct create_lease_v2
),