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 <crypto/aead.h>
27 #include "smb2proto.h"
28 #include "cifsproto.h"
29 #include "cifs_debug.h"
30 #include "cifs_unicode.h"
31 #include "smb2status.h"
33 #include "cifs_ioctl.h"
36 change_conf(struct TCP_Server_Info
*server
)
38 server
->credits
+= server
->echo_credits
+ server
->oplock_credits
;
39 server
->oplock_credits
= server
->echo_credits
= 0;
40 switch (server
->credits
) {
44 server
->echoes
= false;
45 server
->oplocks
= false;
46 cifs_dbg(VFS
, "disabling echoes and oplocks\n");
49 server
->echoes
= true;
50 server
->oplocks
= false;
51 server
->echo_credits
= 1;
52 cifs_dbg(FYI
, "disabling oplocks\n");
55 server
->echoes
= true;
57 server
->oplocks
= true;
58 server
->oplock_credits
= 1;
60 server
->oplocks
= false;
62 server
->echo_credits
= 1;
64 server
->credits
-= server
->echo_credits
+ server
->oplock_credits
;
69 smb2_add_credits(struct TCP_Server_Info
*server
, const unsigned int add
,
73 spin_lock(&server
->req_lock
);
74 val
= server
->ops
->get_credits_field(server
, optype
);
77 *val
= 65000; /* Don't get near 64K credits, avoid srv bugs */
78 printk_once(KERN_WARNING
"server overflowed SMB3 credits\n");
81 if (server
->in_flight
== 0 && (optype
& CIFS_OP_MASK
) != CIFS_NEG_OP
)
82 rc
= change_conf(server
);
84 * Sometimes server returns 0 credits on oplock break ack - we need to
85 * rebalance credits in this case.
87 else if (server
->in_flight
> 0 && server
->oplock_credits
== 0 &&
89 if (server
->credits
> 1) {
91 server
->oplock_credits
++;
94 spin_unlock(&server
->req_lock
);
95 wake_up(&server
->request_q
);
97 cifs_reconnect(server
);
101 smb2_set_credits(struct TCP_Server_Info
*server
, const int val
)
103 spin_lock(&server
->req_lock
);
104 server
->credits
= val
;
105 spin_unlock(&server
->req_lock
);
109 smb2_get_credits_field(struct TCP_Server_Info
*server
, const int optype
)
113 return &server
->echo_credits
;
115 return &server
->oplock_credits
;
117 return &server
->credits
;
122 smb2_get_credits(struct mid_q_entry
*mid
)
124 struct smb2_sync_hdr
*shdr
= get_sync_hdr(mid
->resp_buf
);
126 return le16_to_cpu(shdr
->CreditRequest
);
130 smb2_wait_mtu_credits(struct TCP_Server_Info
*server
, unsigned int size
,
131 unsigned int *num
, unsigned int *credits
)
134 unsigned int scredits
;
136 spin_lock(&server
->req_lock
);
138 if (server
->credits
<= 0) {
139 spin_unlock(&server
->req_lock
);
140 cifs_num_waiters_inc(server
);
141 rc
= wait_event_killable(server
->request_q
,
142 has_credits(server
, &server
->credits
));
143 cifs_num_waiters_dec(server
);
146 spin_lock(&server
->req_lock
);
148 if (server
->tcpStatus
== CifsExiting
) {
149 spin_unlock(&server
->req_lock
);
153 scredits
= server
->credits
;
154 /* can deadlock with reopen */
156 *num
= SMB2_MAX_BUFFER_SIZE
;
161 /* leave one credit for a possible reopen */
163 *num
= min_t(unsigned int, size
,
164 scredits
* SMB2_MAX_BUFFER_SIZE
);
166 *credits
= DIV_ROUND_UP(*num
, SMB2_MAX_BUFFER_SIZE
);
167 server
->credits
-= *credits
;
172 spin_unlock(&server
->req_lock
);
177 smb2_get_next_mid(struct TCP_Server_Info
*server
)
180 /* for SMB2 we need the current value */
181 spin_lock(&GlobalMid_Lock
);
182 mid
= server
->CurrentMid
++;
183 spin_unlock(&GlobalMid_Lock
);
187 static struct mid_q_entry
*
188 smb2_find_mid(struct TCP_Server_Info
*server
, char *buf
)
190 struct mid_q_entry
*mid
;
191 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
192 __u64 wire_mid
= le64_to_cpu(shdr
->MessageId
);
194 if (shdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
) {
195 cifs_dbg(VFS
, "encrypted frame parsing not supported yet");
199 spin_lock(&GlobalMid_Lock
);
200 list_for_each_entry(mid
, &server
->pending_mid_q
, qhead
) {
201 if ((mid
->mid
== wire_mid
) &&
202 (mid
->mid_state
== MID_REQUEST_SUBMITTED
) &&
203 (mid
->command
== shdr
->Command
)) {
204 spin_unlock(&GlobalMid_Lock
);
208 spin_unlock(&GlobalMid_Lock
);
213 smb2_dump_detail(void *buf
)
215 #ifdef CONFIG_CIFS_DEBUG2
216 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
218 cifs_dbg(VFS
, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
219 shdr
->Command
, shdr
->Status
, shdr
->Flags
, shdr
->MessageId
,
221 cifs_dbg(VFS
, "smb buf %p len %u\n", buf
, smb2_calc_size(buf
));
226 smb2_need_neg(struct TCP_Server_Info
*server
)
228 return server
->max_read
== 0;
232 smb2_negotiate(const unsigned int xid
, struct cifs_ses
*ses
)
235 ses
->server
->CurrentMid
= 0;
236 rc
= SMB2_negotiate(xid
, ses
);
237 /* BB we probably don't need to retry with modern servers */
244 smb2_negotiate_wsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
246 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
249 /* start with specified wsize, or default */
250 wsize
= volume_info
->wsize
? volume_info
->wsize
: CIFS_DEFAULT_IOSIZE
;
251 wsize
= min_t(unsigned int, wsize
, server
->max_write
);
253 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
254 wsize
= min_t(unsigned int, wsize
, SMB2_MAX_BUFFER_SIZE
);
260 smb2_negotiate_rsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
262 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
265 /* start with specified rsize, or default */
266 rsize
= volume_info
->rsize
? volume_info
->rsize
: CIFS_DEFAULT_IOSIZE
;
267 rsize
= min_t(unsigned int, rsize
, server
->max_read
);
269 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
270 rsize
= min_t(unsigned int, rsize
, SMB2_MAX_BUFFER_SIZE
);
275 #ifdef CONFIG_CIFS_STATS2
277 SMB3_request_interfaces(const unsigned int xid
, struct cifs_tcon
*tcon
)
280 unsigned int ret_data_len
= 0;
281 struct network_interface_info_ioctl_rsp
*out_buf
;
283 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
284 FSCTL_QUERY_NETWORK_INTERFACE_INFO
, true /* is_fsctl */,
285 NULL
/* no data input */, 0 /* no data input */,
286 (char **)&out_buf
, &ret_data_len
);
288 cifs_dbg(VFS
, "error %d on ioctl to get interface list\n", rc
);
289 else if (ret_data_len
< sizeof(struct network_interface_info_ioctl_rsp
)) {
290 cifs_dbg(VFS
, "server returned bad net interface info buf\n");
293 /* Dump info on first interface */
294 cifs_dbg(FYI
, "Adapter Capability 0x%x\t",
295 le32_to_cpu(out_buf
->Capability
));
296 cifs_dbg(FYI
, "Link Speed %lld\n",
297 le64_to_cpu(out_buf
->LinkSpeed
));
305 smb3_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
308 __le16 srch_path
= 0; /* Null - open root of share */
309 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
310 struct cifs_open_parms oparms
;
314 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
315 oparms
.disposition
= FILE_OPEN
;
316 oparms
.create_options
= 0;
318 oparms
.reconnect
= false;
320 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
324 #ifdef CONFIG_CIFS_STATS2
325 SMB3_request_interfaces(xid
, tcon
);
328 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
329 FS_ATTRIBUTE_INFORMATION
);
330 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
331 FS_DEVICE_INFORMATION
);
332 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
333 FS_SECTOR_SIZE_INFORMATION
); /* SMB3 specific */
334 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
339 smb2_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
342 __le16 srch_path
= 0; /* Null - open root of share */
343 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
344 struct cifs_open_parms oparms
;
348 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
349 oparms
.disposition
= FILE_OPEN
;
350 oparms
.create_options
= 0;
352 oparms
.reconnect
= false;
354 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
358 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
359 FS_ATTRIBUTE_INFORMATION
);
360 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
361 FS_DEVICE_INFORMATION
);
362 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
367 smb2_is_path_accessible(const unsigned int xid
, struct cifs_tcon
*tcon
,
368 struct cifs_sb_info
*cifs_sb
, const char *full_path
)
372 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
373 struct cifs_open_parms oparms
;
376 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
381 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
382 oparms
.disposition
= FILE_OPEN
;
383 oparms
.create_options
= 0;
385 oparms
.reconnect
= false;
387 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
393 rc
= SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
399 smb2_get_srv_inum(const unsigned int xid
, struct cifs_tcon
*tcon
,
400 struct cifs_sb_info
*cifs_sb
, const char *full_path
,
401 u64
*uniqueid
, FILE_ALL_INFO
*data
)
403 *uniqueid
= le64_to_cpu(data
->IndexNumber
);
408 smb2_query_file_info(const unsigned int xid
, struct cifs_tcon
*tcon
,
409 struct cifs_fid
*fid
, FILE_ALL_INFO
*data
)
412 struct smb2_file_all_info
*smb2_data
;
414 smb2_data
= kzalloc(sizeof(struct smb2_file_all_info
) + PATH_MAX
* 2,
416 if (smb2_data
== NULL
)
419 rc
= SMB2_query_info(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
,
422 move_smb2_info_to_cifs(data
, smb2_data
);
428 smb2_can_echo(struct TCP_Server_Info
*server
)
430 return server
->echoes
;
434 smb2_clear_stats(struct cifs_tcon
*tcon
)
436 #ifdef CONFIG_CIFS_STATS
438 for (i
= 0; i
< NUMBER_OF_SMB2_COMMANDS
; i
++) {
439 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_sent
[i
], 0);
440 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_failed
[i
], 0);
446 smb2_dump_share_caps(struct seq_file
*m
, struct cifs_tcon
*tcon
)
448 seq_puts(m
, "\n\tShare Capabilities:");
449 if (tcon
->capabilities
& SMB2_SHARE_CAP_DFS
)
450 seq_puts(m
, " DFS,");
451 if (tcon
->capabilities
& SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY
)
452 seq_puts(m
, " CONTINUOUS AVAILABILITY,");
453 if (tcon
->capabilities
& SMB2_SHARE_CAP_SCALEOUT
)
454 seq_puts(m
, " SCALEOUT,");
455 if (tcon
->capabilities
& SMB2_SHARE_CAP_CLUSTER
)
456 seq_puts(m
, " CLUSTER,");
457 if (tcon
->capabilities
& SMB2_SHARE_CAP_ASYMMETRIC
)
458 seq_puts(m
, " ASYMMETRIC,");
459 if (tcon
->capabilities
== 0)
460 seq_puts(m
, " None");
461 if (tcon
->ss_flags
& SSINFO_FLAGS_ALIGNED_DEVICE
)
462 seq_puts(m
, " Aligned,");
463 if (tcon
->ss_flags
& SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE
)
464 seq_puts(m
, " Partition Aligned,");
465 if (tcon
->ss_flags
& SSINFO_FLAGS_NO_SEEK_PENALTY
)
466 seq_puts(m
, " SSD,");
467 if (tcon
->ss_flags
& SSINFO_FLAGS_TRIM_ENABLED
)
468 seq_puts(m
, " TRIM-support,");
470 seq_printf(m
, "\tShare Flags: 0x%x", tcon
->share_flags
);
471 if (tcon
->perf_sector_size
)
472 seq_printf(m
, "\tOptimal sector size: 0x%x",
473 tcon
->perf_sector_size
);
477 smb2_print_stats(struct seq_file
*m
, struct cifs_tcon
*tcon
)
479 #ifdef CONFIG_CIFS_STATS
480 atomic_t
*sent
= tcon
->stats
.smb2_stats
.smb2_com_sent
;
481 atomic_t
*failed
= tcon
->stats
.smb2_stats
.smb2_com_failed
;
482 seq_printf(m
, "\nNegotiates: %d sent %d failed",
483 atomic_read(&sent
[SMB2_NEGOTIATE_HE
]),
484 atomic_read(&failed
[SMB2_NEGOTIATE_HE
]));
485 seq_printf(m
, "\nSessionSetups: %d sent %d failed",
486 atomic_read(&sent
[SMB2_SESSION_SETUP_HE
]),
487 atomic_read(&failed
[SMB2_SESSION_SETUP_HE
]));
488 seq_printf(m
, "\nLogoffs: %d sent %d failed",
489 atomic_read(&sent
[SMB2_LOGOFF_HE
]),
490 atomic_read(&failed
[SMB2_LOGOFF_HE
]));
491 seq_printf(m
, "\nTreeConnects: %d sent %d failed",
492 atomic_read(&sent
[SMB2_TREE_CONNECT_HE
]),
493 atomic_read(&failed
[SMB2_TREE_CONNECT_HE
]));
494 seq_printf(m
, "\nTreeDisconnects: %d sent %d failed",
495 atomic_read(&sent
[SMB2_TREE_DISCONNECT_HE
]),
496 atomic_read(&failed
[SMB2_TREE_DISCONNECT_HE
]));
497 seq_printf(m
, "\nCreates: %d sent %d failed",
498 atomic_read(&sent
[SMB2_CREATE_HE
]),
499 atomic_read(&failed
[SMB2_CREATE_HE
]));
500 seq_printf(m
, "\nCloses: %d sent %d failed",
501 atomic_read(&sent
[SMB2_CLOSE_HE
]),
502 atomic_read(&failed
[SMB2_CLOSE_HE
]));
503 seq_printf(m
, "\nFlushes: %d sent %d failed",
504 atomic_read(&sent
[SMB2_FLUSH_HE
]),
505 atomic_read(&failed
[SMB2_FLUSH_HE
]));
506 seq_printf(m
, "\nReads: %d sent %d failed",
507 atomic_read(&sent
[SMB2_READ_HE
]),
508 atomic_read(&failed
[SMB2_READ_HE
]));
509 seq_printf(m
, "\nWrites: %d sent %d failed",
510 atomic_read(&sent
[SMB2_WRITE_HE
]),
511 atomic_read(&failed
[SMB2_WRITE_HE
]));
512 seq_printf(m
, "\nLocks: %d sent %d failed",
513 atomic_read(&sent
[SMB2_LOCK_HE
]),
514 atomic_read(&failed
[SMB2_LOCK_HE
]));
515 seq_printf(m
, "\nIOCTLs: %d sent %d failed",
516 atomic_read(&sent
[SMB2_IOCTL_HE
]),
517 atomic_read(&failed
[SMB2_IOCTL_HE
]));
518 seq_printf(m
, "\nCancels: %d sent %d failed",
519 atomic_read(&sent
[SMB2_CANCEL_HE
]),
520 atomic_read(&failed
[SMB2_CANCEL_HE
]));
521 seq_printf(m
, "\nEchos: %d sent %d failed",
522 atomic_read(&sent
[SMB2_ECHO_HE
]),
523 atomic_read(&failed
[SMB2_ECHO_HE
]));
524 seq_printf(m
, "\nQueryDirectories: %d sent %d failed",
525 atomic_read(&sent
[SMB2_QUERY_DIRECTORY_HE
]),
526 atomic_read(&failed
[SMB2_QUERY_DIRECTORY_HE
]));
527 seq_printf(m
, "\nChangeNotifies: %d sent %d failed",
528 atomic_read(&sent
[SMB2_CHANGE_NOTIFY_HE
]),
529 atomic_read(&failed
[SMB2_CHANGE_NOTIFY_HE
]));
530 seq_printf(m
, "\nQueryInfos: %d sent %d failed",
531 atomic_read(&sent
[SMB2_QUERY_INFO_HE
]),
532 atomic_read(&failed
[SMB2_QUERY_INFO_HE
]));
533 seq_printf(m
, "\nSetInfos: %d sent %d failed",
534 atomic_read(&sent
[SMB2_SET_INFO_HE
]),
535 atomic_read(&failed
[SMB2_SET_INFO_HE
]));
536 seq_printf(m
, "\nOplockBreaks: %d sent %d failed",
537 atomic_read(&sent
[SMB2_OPLOCK_BREAK_HE
]),
538 atomic_read(&failed
[SMB2_OPLOCK_BREAK_HE
]));
543 smb2_set_fid(struct cifsFileInfo
*cfile
, struct cifs_fid
*fid
, __u32 oplock
)
545 struct cifsInodeInfo
*cinode
= CIFS_I(d_inode(cfile
->dentry
));
546 struct TCP_Server_Info
*server
= tlink_tcon(cfile
->tlink
)->ses
->server
;
548 cfile
->fid
.persistent_fid
= fid
->persistent_fid
;
549 cfile
->fid
.volatile_fid
= fid
->volatile_fid
;
550 server
->ops
->set_oplock_level(cinode
, oplock
, fid
->epoch
,
552 cinode
->can_cache_brlcks
= CIFS_CACHE_WRITE(cinode
);
553 memcpy(cfile
->fid
.create_guid
, fid
->create_guid
, 16);
557 smb2_close_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
558 struct cifs_fid
*fid
)
560 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
564 SMB2_request_res_key(const unsigned int xid
, struct cifs_tcon
*tcon
,
565 u64 persistent_fid
, u64 volatile_fid
,
566 struct copychunk_ioctl
*pcchunk
)
569 unsigned int ret_data_len
;
570 struct resume_key_req
*res_key
;
572 rc
= SMB2_ioctl(xid
, tcon
, persistent_fid
, volatile_fid
,
573 FSCTL_SRV_REQUEST_RESUME_KEY
, true /* is_fsctl */,
574 NULL
, 0 /* no input */,
575 (char **)&res_key
, &ret_data_len
);
578 cifs_dbg(VFS
, "refcpy ioctl error %d getting resume key\n", rc
);
579 goto req_res_key_exit
;
581 if (ret_data_len
< sizeof(struct resume_key_req
)) {
582 cifs_dbg(VFS
, "Invalid refcopy resume key length\n");
584 goto req_res_key_exit
;
586 memcpy(pcchunk
->SourceKey
, res_key
->ResumeKey
, COPY_CHUNK_RES_KEY_SIZE
);
594 smb2_clone_range(const unsigned int xid
,
595 struct cifsFileInfo
*srcfile
,
596 struct cifsFileInfo
*trgtfile
, u64 src_off
,
597 u64 len
, u64 dest_off
)
600 unsigned int ret_data_len
;
601 struct copychunk_ioctl
*pcchunk
;
602 struct copychunk_ioctl_rsp
*retbuf
= NULL
;
603 struct cifs_tcon
*tcon
;
604 int chunks_copied
= 0;
605 bool chunk_sizes_updated
= false;
607 pcchunk
= kmalloc(sizeof(struct copychunk_ioctl
), GFP_KERNEL
);
612 cifs_dbg(FYI
, "in smb2_clone_range - about to call request res key\n");
613 /* Request a key from the server to identify the source of the copy */
614 rc
= SMB2_request_res_key(xid
, tlink_tcon(srcfile
->tlink
),
615 srcfile
->fid
.persistent_fid
,
616 srcfile
->fid
.volatile_fid
, pcchunk
);
618 /* Note: request_res_key sets res_key null only if rc !=0 */
622 /* For now array only one chunk long, will make more flexible later */
623 pcchunk
->ChunkCount
= cpu_to_le32(1);
624 pcchunk
->Reserved
= 0;
625 pcchunk
->Reserved2
= 0;
627 tcon
= tlink_tcon(trgtfile
->tlink
);
630 pcchunk
->SourceOffset
= cpu_to_le64(src_off
);
631 pcchunk
->TargetOffset
= cpu_to_le64(dest_off
);
633 cpu_to_le32(min_t(u32
, len
, tcon
->max_bytes_chunk
));
635 /* Request server copy to target from src identified by key */
636 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
637 trgtfile
->fid
.volatile_fid
, FSCTL_SRV_COPYCHUNK_WRITE
,
638 true /* is_fsctl */, (char *)pcchunk
,
639 sizeof(struct copychunk_ioctl
), (char **)&retbuf
,
643 sizeof(struct copychunk_ioctl_rsp
)) {
644 cifs_dbg(VFS
, "invalid cchunk response size\n");
648 if (retbuf
->TotalBytesWritten
== 0) {
649 cifs_dbg(FYI
, "no bytes copied\n");
654 * Check if server claimed to write more than we asked
656 if (le32_to_cpu(retbuf
->TotalBytesWritten
) >
657 le32_to_cpu(pcchunk
->Length
)) {
658 cifs_dbg(VFS
, "invalid copy chunk response\n");
662 if (le32_to_cpu(retbuf
->ChunksWritten
) != 1) {
663 cifs_dbg(VFS
, "invalid num chunks written\n");
669 src_off
+= le32_to_cpu(retbuf
->TotalBytesWritten
);
670 dest_off
+= le32_to_cpu(retbuf
->TotalBytesWritten
);
671 len
-= le32_to_cpu(retbuf
->TotalBytesWritten
);
673 cifs_dbg(FYI
, "Chunks %d PartialChunk %d Total %d\n",
674 le32_to_cpu(retbuf
->ChunksWritten
),
675 le32_to_cpu(retbuf
->ChunkBytesWritten
),
676 le32_to_cpu(retbuf
->TotalBytesWritten
));
677 } else if (rc
== -EINVAL
) {
678 if (ret_data_len
!= sizeof(struct copychunk_ioctl_rsp
))
681 cifs_dbg(FYI
, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
682 le32_to_cpu(retbuf
->ChunksWritten
),
683 le32_to_cpu(retbuf
->ChunkBytesWritten
),
684 le32_to_cpu(retbuf
->TotalBytesWritten
));
687 * Check if this is the first request using these sizes,
688 * (ie check if copy succeed once with original sizes
689 * and check if the server gave us different sizes after
690 * we already updated max sizes on previous request).
691 * if not then why is the server returning an error now
693 if ((chunks_copied
!= 0) || chunk_sizes_updated
)
696 /* Check that server is not asking us to grow size */
697 if (le32_to_cpu(retbuf
->ChunkBytesWritten
) <
698 tcon
->max_bytes_chunk
)
699 tcon
->max_bytes_chunk
=
700 le32_to_cpu(retbuf
->ChunkBytesWritten
);
702 goto cchunk_out
; /* server gave us bogus size */
704 /* No need to change MaxChunks since already set to 1 */
705 chunk_sizes_updated
= true;
717 smb2_flush_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
718 struct cifs_fid
*fid
)
720 return SMB2_flush(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
724 smb2_read_data_offset(char *buf
)
726 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
727 return rsp
->DataOffset
;
731 smb2_read_data_length(char *buf
)
733 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
734 return le32_to_cpu(rsp
->DataLength
);
739 smb2_sync_read(const unsigned int xid
, struct cifs_fid
*pfid
,
740 struct cifs_io_parms
*parms
, unsigned int *bytes_read
,
741 char **buf
, int *buf_type
)
743 parms
->persistent_fid
= pfid
->persistent_fid
;
744 parms
->volatile_fid
= pfid
->volatile_fid
;
745 return SMB2_read(xid
, parms
, bytes_read
, buf
, buf_type
);
749 smb2_sync_write(const unsigned int xid
, struct cifs_fid
*pfid
,
750 struct cifs_io_parms
*parms
, unsigned int *written
,
751 struct kvec
*iov
, unsigned long nr_segs
)
754 parms
->persistent_fid
= pfid
->persistent_fid
;
755 parms
->volatile_fid
= pfid
->volatile_fid
;
756 return SMB2_write(xid
, parms
, written
, iov
, nr_segs
);
759 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
760 static bool smb2_set_sparse(const unsigned int xid
, struct cifs_tcon
*tcon
,
761 struct cifsFileInfo
*cfile
, struct inode
*inode
, __u8 setsparse
)
763 struct cifsInodeInfo
*cifsi
;
766 cifsi
= CIFS_I(inode
);
768 /* if file already sparse don't bother setting sparse again */
769 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && setsparse
)
770 return true; /* already sparse */
772 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && !setsparse
)
773 return true; /* already not sparse */
776 * Can't check for sparse support on share the usual way via the
777 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
778 * since Samba server doesn't set the flag on the share, yet
779 * supports the set sparse FSCTL and returns sparse correctly
780 * in the file attributes. If we fail setting sparse though we
781 * mark that server does not support sparse files for this share
782 * to avoid repeatedly sending the unsupported fsctl to server
783 * if the file is repeatedly extended.
785 if (tcon
->broken_sparse_sup
)
788 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
789 cfile
->fid
.volatile_fid
, FSCTL_SET_SPARSE
,
790 true /* is_fctl */, &setsparse
, 1, NULL
, NULL
);
792 tcon
->broken_sparse_sup
= true;
793 cifs_dbg(FYI
, "set sparse rc = %d\n", rc
);
798 cifsi
->cifsAttrs
|= FILE_ATTRIBUTE_SPARSE_FILE
;
800 cifsi
->cifsAttrs
&= (~FILE_ATTRIBUTE_SPARSE_FILE
);
806 smb2_set_file_size(const unsigned int xid
, struct cifs_tcon
*tcon
,
807 struct cifsFileInfo
*cfile
, __u64 size
, bool set_alloc
)
809 __le64 eof
= cpu_to_le64(size
);
813 * If extending file more than one page make sparse. Many Linux fs
814 * make files sparse by default when extending via ftruncate
816 inode
= d_inode(cfile
->dentry
);
818 if (!set_alloc
&& (size
> inode
->i_size
+ 8192)) {
821 /* whether set sparse succeeds or not, extend the file */
822 smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
);
825 return SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
826 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
, false);
830 smb2_duplicate_extents(const unsigned int xid
,
831 struct cifsFileInfo
*srcfile
,
832 struct cifsFileInfo
*trgtfile
, u64 src_off
,
833 u64 len
, u64 dest_off
)
836 unsigned int ret_data_len
;
837 struct duplicate_extents_to_file dup_ext_buf
;
838 struct cifs_tcon
*tcon
= tlink_tcon(trgtfile
->tlink
);
840 /* server fileays advertise duplicate extent support with this flag */
841 if ((le32_to_cpu(tcon
->fsAttrInfo
.Attributes
) &
842 FILE_SUPPORTS_BLOCK_REFCOUNTING
) == 0)
845 dup_ext_buf
.VolatileFileHandle
= srcfile
->fid
.volatile_fid
;
846 dup_ext_buf
.PersistentFileHandle
= srcfile
->fid
.persistent_fid
;
847 dup_ext_buf
.SourceFileOffset
= cpu_to_le64(src_off
);
848 dup_ext_buf
.TargetFileOffset
= cpu_to_le64(dest_off
);
849 dup_ext_buf
.ByteCount
= cpu_to_le64(len
);
850 cifs_dbg(FYI
, "duplicate extents: src off %lld dst off %lld len %lld",
851 src_off
, dest_off
, len
);
853 rc
= smb2_set_file_size(xid
, tcon
, trgtfile
, dest_off
+ len
, false);
855 goto duplicate_extents_out
;
857 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
858 trgtfile
->fid
.volatile_fid
,
859 FSCTL_DUPLICATE_EXTENTS_TO_FILE
,
860 true /* is_fsctl */, (char *)&dup_ext_buf
,
861 sizeof(struct duplicate_extents_to_file
),
865 if (ret_data_len
> 0)
866 cifs_dbg(FYI
, "non-zero response length in duplicate extents");
868 duplicate_extents_out
:
873 smb2_set_compression(const unsigned int xid
, struct cifs_tcon
*tcon
,
874 struct cifsFileInfo
*cfile
)
876 return SMB2_set_compression(xid
, tcon
, cfile
->fid
.persistent_fid
,
877 cfile
->fid
.volatile_fid
);
881 smb3_set_integrity(const unsigned int xid
, struct cifs_tcon
*tcon
,
882 struct cifsFileInfo
*cfile
)
884 struct fsctl_set_integrity_information_req integr_info
;
885 unsigned int ret_data_len
;
887 integr_info
.ChecksumAlgorithm
= cpu_to_le16(CHECKSUM_TYPE_UNCHANGED
);
888 integr_info
.Flags
= 0;
889 integr_info
.Reserved
= 0;
891 return SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
892 cfile
->fid
.volatile_fid
,
893 FSCTL_SET_INTEGRITY_INFORMATION
,
894 true /* is_fsctl */, (char *)&integr_info
,
895 sizeof(struct fsctl_set_integrity_information_req
),
902 smb3_enum_snapshots(const unsigned int xid
, struct cifs_tcon
*tcon
,
903 struct cifsFileInfo
*cfile
, void __user
*ioc_buf
)
906 unsigned int ret_data_len
= 0;
908 struct smb_snapshot_array snapshot_in
;
910 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
911 cfile
->fid
.volatile_fid
,
912 FSCTL_SRV_ENUMERATE_SNAPSHOTS
,
913 true /* is_fsctl */, NULL
, 0 /* no input data */,
916 cifs_dbg(FYI
, "enum snaphots ioctl returned %d and ret buflen is %d\n",
921 if (ret_data_len
&& (ioc_buf
!= NULL
) && (retbuf
!= NULL
)) {
923 if (copy_from_user(&snapshot_in
, ioc_buf
,
924 sizeof(struct smb_snapshot_array
))) {
929 if (snapshot_in
.snapshot_array_size
< sizeof(struct smb_snapshot_array
)) {
935 if (ret_data_len
> snapshot_in
.snapshot_array_size
)
936 ret_data_len
= snapshot_in
.snapshot_array_size
;
938 if (copy_to_user(ioc_buf
, retbuf
, ret_data_len
))
947 smb2_query_dir_first(const unsigned int xid
, struct cifs_tcon
*tcon
,
948 const char *path
, struct cifs_sb_info
*cifs_sb
,
949 struct cifs_fid
*fid
, __u16 search_flags
,
950 struct cifs_search_info
*srch_inf
)
954 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
955 struct cifs_open_parms oparms
;
957 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
962 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| FILE_READ_DATA
;
963 oparms
.disposition
= FILE_OPEN
;
964 oparms
.create_options
= 0;
966 oparms
.reconnect
= false;
968 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
971 cifs_dbg(VFS
, "open dir failed\n");
975 srch_inf
->entries_in_buffer
= 0;
976 srch_inf
->index_of_last_entry
= 0;
978 rc
= SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
979 fid
->volatile_fid
, 0, srch_inf
);
981 cifs_dbg(VFS
, "query directory failed\n");
982 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
988 smb2_query_dir_next(const unsigned int xid
, struct cifs_tcon
*tcon
,
989 struct cifs_fid
*fid
, __u16 search_flags
,
990 struct cifs_search_info
*srch_inf
)
992 return SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
993 fid
->volatile_fid
, 0, srch_inf
);
997 smb2_close_dir(const unsigned int xid
, struct cifs_tcon
*tcon
,
998 struct cifs_fid
*fid
)
1000 return SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1004 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
1005 * the number of credits and return true. Otherwise - return false.
1008 smb2_is_status_pending(char *buf
, struct TCP_Server_Info
*server
, int length
)
1010 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
1012 if (shdr
->Status
!= STATUS_PENDING
)
1016 spin_lock(&server
->req_lock
);
1017 server
->credits
+= le16_to_cpu(shdr
->CreditRequest
);
1018 spin_unlock(&server
->req_lock
);
1019 wake_up(&server
->request_q
);
1026 smb2_oplock_response(struct cifs_tcon
*tcon
, struct cifs_fid
*fid
,
1027 struct cifsInodeInfo
*cinode
)
1029 if (tcon
->ses
->server
->capabilities
& SMB2_GLOBAL_CAP_LEASING
)
1030 return SMB2_lease_break(0, tcon
, cinode
->lease_key
,
1031 smb2_get_lease_state(cinode
));
1033 return SMB2_oplock_break(0, tcon
, fid
->persistent_fid
,
1035 CIFS_CACHE_READ(cinode
) ? 1 : 0);
1039 smb2_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
1040 struct kstatfs
*buf
)
1043 __le16 srch_path
= 0; /* Null - open root of share */
1044 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1045 struct cifs_open_parms oparms
;
1046 struct cifs_fid fid
;
1049 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
1050 oparms
.disposition
= FILE_OPEN
;
1051 oparms
.create_options
= 0;
1053 oparms
.reconnect
= false;
1055 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
1058 buf
->f_type
= SMB2_MAGIC_NUMBER
;
1059 rc
= SMB2_QFS_info(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
1061 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
1066 smb2_compare_fids(struct cifsFileInfo
*ob1
, struct cifsFileInfo
*ob2
)
1068 return ob1
->fid
.persistent_fid
== ob2
->fid
.persistent_fid
&&
1069 ob1
->fid
.volatile_fid
== ob2
->fid
.volatile_fid
;
1073 smb2_mand_lock(const unsigned int xid
, struct cifsFileInfo
*cfile
, __u64 offset
,
1074 __u64 length
, __u32 type
, int lock
, int unlock
, bool wait
)
1076 if (unlock
&& !lock
)
1077 type
= SMB2_LOCKFLAG_UNLOCK
;
1078 return SMB2_lock(xid
, tlink_tcon(cfile
->tlink
),
1079 cfile
->fid
.persistent_fid
, cfile
->fid
.volatile_fid
,
1080 current
->tgid
, length
, offset
, type
, wait
);
1084 smb2_get_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
1086 memcpy(fid
->lease_key
, CIFS_I(inode
)->lease_key
, SMB2_LEASE_KEY_SIZE
);
1090 smb2_set_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
1092 memcpy(CIFS_I(inode
)->lease_key
, fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
1096 smb2_new_lease_key(struct cifs_fid
*fid
)
1098 generate_random_uuid(fid
->lease_key
);
1101 #define SMB2_SYMLINK_STRUCT_SIZE \
1102 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
1105 smb2_query_symlink(const unsigned int xid
, struct cifs_tcon
*tcon
,
1106 const char *full_path
, char **target_path
,
1107 struct cifs_sb_info
*cifs_sb
)
1111 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1112 struct cifs_open_parms oparms
;
1113 struct cifs_fid fid
;
1114 struct smb2_err_rsp
*err_buf
= NULL
;
1115 struct smb2_symlink_err_rsp
*symlink
;
1116 unsigned int sub_len
;
1117 unsigned int sub_offset
;
1118 unsigned int print_len
;
1119 unsigned int print_offset
;
1121 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, full_path
);
1123 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
1128 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
1129 oparms
.disposition
= FILE_OPEN
;
1130 oparms
.create_options
= 0;
1132 oparms
.reconnect
= false;
1134 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, &err_buf
);
1136 if (!rc
|| !err_buf
) {
1141 if (le32_to_cpu(err_buf
->ByteCount
) < sizeof(struct smb2_symlink_err_rsp
) ||
1142 get_rfc1002_length(err_buf
) + 4 < SMB2_SYMLINK_STRUCT_SIZE
) {
1147 /* open must fail on symlink - reset rc */
1149 symlink
= (struct smb2_symlink_err_rsp
*)err_buf
->ErrorData
;
1150 sub_len
= le16_to_cpu(symlink
->SubstituteNameLength
);
1151 sub_offset
= le16_to_cpu(symlink
->SubstituteNameOffset
);
1152 print_len
= le16_to_cpu(symlink
->PrintNameLength
);
1153 print_offset
= le16_to_cpu(symlink
->PrintNameOffset
);
1155 if (get_rfc1002_length(err_buf
) + 4 <
1156 SMB2_SYMLINK_STRUCT_SIZE
+ sub_offset
+ sub_len
) {
1161 if (get_rfc1002_length(err_buf
) + 4 <
1162 SMB2_SYMLINK_STRUCT_SIZE
+ print_offset
+ print_len
) {
1167 *target_path
= cifs_strndup_from_utf16(
1168 (char *)symlink
->PathBuffer
+ sub_offset
,
1169 sub_len
, true, cifs_sb
->local_nls
);
1170 if (!(*target_path
)) {
1174 convert_delimiter(*target_path
, '/');
1175 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
1180 static long smb3_zero_range(struct file
*file
, struct cifs_tcon
*tcon
,
1181 loff_t offset
, loff_t len
, bool keep_size
)
1183 struct inode
*inode
;
1184 struct cifsInodeInfo
*cifsi
;
1185 struct cifsFileInfo
*cfile
= file
->private_data
;
1186 struct file_zero_data_information fsctl_buf
;
1192 inode
= d_inode(cfile
->dentry
);
1193 cifsi
= CIFS_I(inode
);
1195 /* if file not oplocked can't be sure whether asking to extend size */
1196 if (!CIFS_CACHE_READ(cifsi
))
1197 if (keep_size
== false)
1201 * Must check if file sparse since fallocate -z (zero range) assumes
1202 * non-sparse allocation
1204 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
))
1208 * need to make sure we are not asked to extend the file since the SMB3
1209 * fsctl does not change the file size. In the future we could change
1210 * this to zero the first part of the range then set the file size
1211 * which for a non sparse file would zero the newly extended range
1213 if (keep_size
== false)
1214 if (i_size_read(inode
) < offset
+ len
)
1217 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1219 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1220 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1222 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1223 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1224 true /* is_fctl */, (char *)&fsctl_buf
,
1225 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1230 static long smb3_punch_hole(struct file
*file
, struct cifs_tcon
*tcon
,
1231 loff_t offset
, loff_t len
)
1233 struct inode
*inode
;
1234 struct cifsInodeInfo
*cifsi
;
1235 struct cifsFileInfo
*cfile
= file
->private_data
;
1236 struct file_zero_data_information fsctl_buf
;
1239 __u8 set_sparse
= 1;
1243 inode
= d_inode(cfile
->dentry
);
1244 cifsi
= CIFS_I(inode
);
1246 /* Need to make file sparse, if not already, before freeing range. */
1247 /* Consider adding equivalent for compressed since it could also work */
1248 if (!smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
))
1251 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1253 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1254 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1256 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1257 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1258 true /* is_fctl */, (char *)&fsctl_buf
,
1259 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1264 static long smb3_simple_falloc(struct file
*file
, struct cifs_tcon
*tcon
,
1265 loff_t off
, loff_t len
, bool keep_size
)
1267 struct inode
*inode
;
1268 struct cifsInodeInfo
*cifsi
;
1269 struct cifsFileInfo
*cfile
= file
->private_data
;
1270 long rc
= -EOPNOTSUPP
;
1275 inode
= d_inode(cfile
->dentry
);
1276 cifsi
= CIFS_I(inode
);
1278 /* if file not oplocked can't be sure whether asking to extend size */
1279 if (!CIFS_CACHE_READ(cifsi
))
1280 if (keep_size
== false)
1284 * Files are non-sparse by default so falloc may be a no-op
1285 * Must check if file sparse. If not sparse, and not extending
1286 * then no need to do anything since file already allocated
1288 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) == 0) {
1289 if (keep_size
== true)
1291 /* check if extending file */
1292 else if (i_size_read(inode
) >= off
+ len
)
1293 /* not extending file and already not sparse */
1295 /* BB: in future add else clause to extend file */
1300 if ((keep_size
== true) || (i_size_read(inode
) >= off
+ len
)) {
1302 * Check if falloc starts within first few pages of file
1303 * and ends within a few pages of the end of file to
1304 * ensure that most of file is being forced to be
1305 * fallocated now. If so then setting whole file sparse
1306 * ie potentially making a few extra pages at the beginning
1307 * or end of the file non-sparse via set_sparse is harmless.
1309 if ((off
> 8192) || (off
+ len
+ 8192 < i_size_read(inode
)))
1312 rc
= smb2_set_sparse(xid
, tcon
, cfile
, inode
, false);
1314 /* BB: else ... in future add code to extend file and set sparse */
1322 static long smb3_fallocate(struct file
*file
, struct cifs_tcon
*tcon
, int mode
,
1323 loff_t off
, loff_t len
)
1325 /* KEEP_SIZE already checked for by do_fallocate */
1326 if (mode
& FALLOC_FL_PUNCH_HOLE
)
1327 return smb3_punch_hole(file
, tcon
, off
, len
);
1328 else if (mode
& FALLOC_FL_ZERO_RANGE
) {
1329 if (mode
& FALLOC_FL_KEEP_SIZE
)
1330 return smb3_zero_range(file
, tcon
, off
, len
, true);
1331 return smb3_zero_range(file
, tcon
, off
, len
, false);
1332 } else if (mode
== FALLOC_FL_KEEP_SIZE
)
1333 return smb3_simple_falloc(file
, tcon
, off
, len
, true);
1335 return smb3_simple_falloc(file
, tcon
, off
, len
, false);
1341 smb2_downgrade_oplock(struct TCP_Server_Info
*server
,
1342 struct cifsInodeInfo
*cinode
, bool set_level2
)
1345 server
->ops
->set_oplock_level(cinode
, SMB2_OPLOCK_LEVEL_II
,
1348 server
->ops
->set_oplock_level(cinode
, 0, 0, NULL
);
1352 smb2_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1353 unsigned int epoch
, bool *purge_cache
)
1356 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1358 if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
) {
1359 cinode
->oplock
= CIFS_CACHE_RHW_FLG
;
1360 cifs_dbg(FYI
, "Batch Oplock granted on inode %p\n",
1361 &cinode
->vfs_inode
);
1362 } else if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
) {
1363 cinode
->oplock
= CIFS_CACHE_RW_FLG
;
1364 cifs_dbg(FYI
, "Exclusive Oplock granted on inode %p\n",
1365 &cinode
->vfs_inode
);
1366 } else if (oplock
== SMB2_OPLOCK_LEVEL_II
) {
1367 cinode
->oplock
= CIFS_CACHE_READ_FLG
;
1368 cifs_dbg(FYI
, "Level II Oplock granted on inode %p\n",
1369 &cinode
->vfs_inode
);
1375 smb21_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1376 unsigned int epoch
, bool *purge_cache
)
1378 char message
[5] = {0};
1381 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1385 if (oplock
& SMB2_LEASE_READ_CACHING_HE
) {
1386 cinode
->oplock
|= CIFS_CACHE_READ_FLG
;
1387 strcat(message
, "R");
1389 if (oplock
& SMB2_LEASE_HANDLE_CACHING_HE
) {
1390 cinode
->oplock
|= CIFS_CACHE_HANDLE_FLG
;
1391 strcat(message
, "H");
1393 if (oplock
& SMB2_LEASE_WRITE_CACHING_HE
) {
1394 cinode
->oplock
|= CIFS_CACHE_WRITE_FLG
;
1395 strcat(message
, "W");
1397 if (!cinode
->oplock
)
1398 strcat(message
, "None");
1399 cifs_dbg(FYI
, "%s Lease granted on inode %p\n", message
,
1400 &cinode
->vfs_inode
);
1404 smb3_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1405 unsigned int epoch
, bool *purge_cache
)
1407 unsigned int old_oplock
= cinode
->oplock
;
1409 smb21_set_oplock_level(cinode
, oplock
, epoch
, purge_cache
);
1412 *purge_cache
= false;
1413 if (old_oplock
== CIFS_CACHE_READ_FLG
) {
1414 if (cinode
->oplock
== CIFS_CACHE_READ_FLG
&&
1415 (epoch
- cinode
->epoch
> 0))
1416 *purge_cache
= true;
1417 else if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1418 (epoch
- cinode
->epoch
> 1))
1419 *purge_cache
= true;
1420 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1421 (epoch
- cinode
->epoch
> 1))
1422 *purge_cache
= true;
1423 else if (cinode
->oplock
== 0 &&
1424 (epoch
- cinode
->epoch
> 0))
1425 *purge_cache
= true;
1426 } else if (old_oplock
== CIFS_CACHE_RH_FLG
) {
1427 if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1428 (epoch
- cinode
->epoch
> 0))
1429 *purge_cache
= true;
1430 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1431 (epoch
- cinode
->epoch
> 1))
1432 *purge_cache
= true;
1434 cinode
->epoch
= epoch
;
1439 smb2_is_read_op(__u32 oplock
)
1441 return oplock
== SMB2_OPLOCK_LEVEL_II
;
1445 smb21_is_read_op(__u32 oplock
)
1447 return (oplock
& SMB2_LEASE_READ_CACHING_HE
) &&
1448 !(oplock
& SMB2_LEASE_WRITE_CACHING_HE
);
1452 map_oplock_to_lease(u8 oplock
)
1454 if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
)
1455 return SMB2_LEASE_WRITE_CACHING
| SMB2_LEASE_READ_CACHING
;
1456 else if (oplock
== SMB2_OPLOCK_LEVEL_II
)
1457 return SMB2_LEASE_READ_CACHING
;
1458 else if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
)
1459 return SMB2_LEASE_HANDLE_CACHING
| SMB2_LEASE_READ_CACHING
|
1460 SMB2_LEASE_WRITE_CACHING
;
1465 smb2_create_lease_buf(u8
*lease_key
, u8 oplock
)
1467 struct create_lease
*buf
;
1469 buf
= kzalloc(sizeof(struct create_lease
), GFP_KERNEL
);
1473 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1474 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1475 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1477 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1478 (struct create_lease
, lcontext
));
1479 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context
));
1480 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1481 (struct create_lease
, Name
));
1482 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1483 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1492 smb3_create_lease_buf(u8
*lease_key
, u8 oplock
)
1494 struct create_lease_v2
*buf
;
1496 buf
= kzalloc(sizeof(struct create_lease_v2
), GFP_KERNEL
);
1500 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1501 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1502 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1504 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1505 (struct create_lease_v2
, lcontext
));
1506 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context_v2
));
1507 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1508 (struct create_lease_v2
, Name
));
1509 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1510 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1519 smb2_parse_lease_buf(void *buf
, unsigned int *epoch
)
1521 struct create_lease
*lc
= (struct create_lease
*)buf
;
1523 *epoch
= 0; /* not used */
1524 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
1525 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
1526 return le32_to_cpu(lc
->lcontext
.LeaseState
);
1530 smb3_parse_lease_buf(void *buf
, unsigned int *epoch
)
1532 struct create_lease_v2
*lc
= (struct create_lease_v2
*)buf
;
1534 *epoch
= le16_to_cpu(lc
->lcontext
.Epoch
);
1535 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
1536 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
1537 return le32_to_cpu(lc
->lcontext
.LeaseState
);
1541 smb2_wp_retry_size(struct inode
*inode
)
1543 return min_t(unsigned int, CIFS_SB(inode
->i_sb
)->wsize
,
1544 SMB2_MAX_BUFFER_SIZE
);
1548 smb2_dir_needs_close(struct cifsFileInfo
*cfile
)
1550 return !cfile
->invalidHandle
;
1554 fill_transform_hdr(struct smb2_transform_hdr
*tr_hdr
, struct smb_rqst
*old_rq
)
1556 struct smb2_sync_hdr
*shdr
=
1557 (struct smb2_sync_hdr
*)old_rq
->rq_iov
[1].iov_base
;
1558 unsigned int orig_len
= get_rfc1002_length(old_rq
->rq_iov
[0].iov_base
);
1560 memset(tr_hdr
, 0, sizeof(struct smb2_transform_hdr
));
1561 tr_hdr
->ProtocolId
= SMB2_TRANSFORM_PROTO_NUM
;
1562 tr_hdr
->OriginalMessageSize
= cpu_to_le32(orig_len
);
1563 tr_hdr
->Flags
= cpu_to_le16(0x01);
1564 get_random_bytes(&tr_hdr
->Nonce
, SMB3_AES128CMM_NONCE
);
1565 memcpy(&tr_hdr
->SessionId
, &shdr
->SessionId
, 8);
1566 inc_rfc1001_len(tr_hdr
, sizeof(struct smb2_transform_hdr
) - 4);
1567 inc_rfc1001_len(tr_hdr
, orig_len
);
1570 static struct scatterlist
*
1571 init_sg(struct smb_rqst
*rqst
, u8
*sign
)
1573 unsigned int sg_len
= rqst
->rq_nvec
+ rqst
->rq_npages
+ 1;
1574 unsigned int assoc_data_len
= sizeof(struct smb2_transform_hdr
) - 24;
1575 struct scatterlist
*sg
;
1579 sg
= kmalloc_array(sg_len
, sizeof(struct scatterlist
), GFP_KERNEL
);
1583 sg_init_table(sg
, sg_len
);
1584 sg_set_buf(&sg
[0], rqst
->rq_iov
[0].iov_base
+ 24, assoc_data_len
);
1585 for (i
= 1; i
< rqst
->rq_nvec
; i
++)
1586 sg_set_buf(&sg
[i
], rqst
->rq_iov
[i
].iov_base
,
1587 rqst
->rq_iov
[i
].iov_len
);
1588 for (j
= 0; i
< sg_len
- 1; i
++, j
++) {
1589 unsigned int len
= (j
< rqst
->rq_npages
- 1) ? rqst
->rq_pagesz
1591 sg_set_page(&sg
[i
], rqst
->rq_pages
[j
], len
, 0);
1593 sg_set_buf(&sg
[sg_len
- 1], sign
, SMB2_SIGNATURE_SIZE
);
1597 struct cifs_crypt_result
{
1599 struct completion completion
;
1602 static void cifs_crypt_complete(struct crypto_async_request
*req
, int err
)
1604 struct cifs_crypt_result
*res
= req
->data
;
1606 if (err
== -EINPROGRESS
)
1610 complete(&res
->completion
);
1614 smb2_get_enc_key(struct TCP_Server_Info
*server
, __u64 ses_id
, int enc
, u8
*key
)
1616 struct cifs_ses
*ses
;
1619 spin_lock(&cifs_tcp_ses_lock
);
1620 list_for_each_entry(ses
, &server
->smb_ses_list
, smb_ses_list
) {
1621 if (ses
->Suid
!= ses_id
)
1623 ses_enc_key
= enc
? ses
->smb3encryptionkey
:
1624 ses
->smb3decryptionkey
;
1625 memcpy(key
, ses_enc_key
, SMB3_SIGN_KEY_SIZE
);
1626 spin_unlock(&cifs_tcp_ses_lock
);
1629 spin_unlock(&cifs_tcp_ses_lock
);
1634 * Encrypt or decrypt @rqst message. @rqst has the following format:
1635 * iov[0] - transform header (associate data),
1636 * iov[1-N] and pages - data to encrypt.
1637 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
1641 crypt_message(struct TCP_Server_Info
*server
, struct smb_rqst
*rqst
, int enc
)
1643 struct smb2_transform_hdr
*tr_hdr
=
1644 (struct smb2_transform_hdr
*)rqst
->rq_iov
[0].iov_base
;
1645 unsigned int assoc_data_len
= sizeof(struct smb2_transform_hdr
) - 24;
1647 struct scatterlist
*sg
;
1648 u8 sign
[SMB2_SIGNATURE_SIZE
] = {};
1649 u8 key
[SMB3_SIGN_KEY_SIZE
];
1650 struct aead_request
*req
;
1652 unsigned int iv_len
;
1653 struct cifs_crypt_result result
= {0, };
1654 struct crypto_aead
*tfm
;
1655 unsigned int crypt_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
1657 init_completion(&result
.completion
);
1659 rc
= smb2_get_enc_key(server
, tr_hdr
->SessionId
, enc
, key
);
1661 cifs_dbg(VFS
, "%s: Could not get %scryption key\n", __func__
,
1666 rc
= smb3_crypto_aead_allocate(server
);
1668 cifs_dbg(VFS
, "%s: crypto alloc failed\n", __func__
);
1672 tfm
= enc
? server
->secmech
.ccmaesencrypt
:
1673 server
->secmech
.ccmaesdecrypt
;
1674 rc
= crypto_aead_setkey(tfm
, key
, SMB3_SIGN_KEY_SIZE
);
1676 cifs_dbg(VFS
, "%s: Failed to set aead key %d\n", __func__
, rc
);
1680 rc
= crypto_aead_setauthsize(tfm
, SMB2_SIGNATURE_SIZE
);
1682 cifs_dbg(VFS
, "%s: Failed to set authsize %d\n", __func__
, rc
);
1686 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
1688 cifs_dbg(VFS
, "%s: Failed to alloc aead request", __func__
);
1693 memcpy(sign
, &tr_hdr
->Signature
, SMB2_SIGNATURE_SIZE
);
1694 crypt_len
+= SMB2_SIGNATURE_SIZE
;
1697 sg
= init_sg(rqst
, sign
);
1699 cifs_dbg(VFS
, "%s: Failed to init sg %d", __func__
, rc
);
1703 iv_len
= crypto_aead_ivsize(tfm
);
1704 iv
= kzalloc(iv_len
, GFP_KERNEL
);
1706 cifs_dbg(VFS
, "%s: Failed to alloc IV", __func__
);
1710 memcpy(iv
+ 1, (char *)tr_hdr
->Nonce
, SMB3_AES128CMM_NONCE
);
1712 aead_request_set_crypt(req
, sg
, sg
, crypt_len
, iv
);
1713 aead_request_set_ad(req
, assoc_data_len
);
1715 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
1716 cifs_crypt_complete
, &result
);
1718 rc
= enc
? crypto_aead_encrypt(req
) : crypto_aead_decrypt(req
);
1720 if (rc
== -EINPROGRESS
|| rc
== -EBUSY
) {
1721 wait_for_completion(&result
.completion
);
1726 memcpy(&tr_hdr
->Signature
, sign
, SMB2_SIGNATURE_SIZE
);
1737 smb3_init_transform_rq(struct TCP_Server_Info
*server
, struct smb_rqst
*new_rq
,
1738 struct smb_rqst
*old_rq
)
1741 struct page
**pages
;
1742 struct smb2_transform_hdr
*tr_hdr
;
1743 unsigned int npages
= old_rq
->rq_npages
;
1747 pages
= kmalloc_array(npages
, sizeof(struct page
*), GFP_KERNEL
);
1751 new_rq
->rq_pages
= pages
;
1752 new_rq
->rq_npages
= old_rq
->rq_npages
;
1753 new_rq
->rq_pagesz
= old_rq
->rq_pagesz
;
1754 new_rq
->rq_tailsz
= old_rq
->rq_tailsz
;
1756 for (i
= 0; i
< npages
; i
++) {
1757 pages
[i
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
1759 goto err_free_pages
;
1762 iov
= kmalloc_array(old_rq
->rq_nvec
, sizeof(struct kvec
), GFP_KERNEL
);
1764 goto err_free_pages
;
1766 /* copy all iovs from the old except the 1st one (rfc1002 length) */
1767 memcpy(&iov
[1], &old_rq
->rq_iov
[1],
1768 sizeof(struct kvec
) * (old_rq
->rq_nvec
- 1));
1769 new_rq
->rq_iov
= iov
;
1770 new_rq
->rq_nvec
= old_rq
->rq_nvec
;
1772 tr_hdr
= kmalloc(sizeof(struct smb2_transform_hdr
), GFP_KERNEL
);
1776 /* fill the 1st iov with a transform header */
1777 fill_transform_hdr(tr_hdr
, old_rq
);
1778 new_rq
->rq_iov
[0].iov_base
= tr_hdr
;
1779 new_rq
->rq_iov
[0].iov_len
= sizeof(struct smb2_transform_hdr
);
1781 /* copy pages form the old */
1782 for (i
= 0; i
< npages
; i
++) {
1783 char *dst
= kmap(new_rq
->rq_pages
[i
]);
1784 char *src
= kmap(old_rq
->rq_pages
[i
]);
1785 unsigned int len
= (i
< npages
- 1) ? new_rq
->rq_pagesz
:
1787 memcpy(dst
, src
, len
);
1788 kunmap(new_rq
->rq_pages
[i
]);
1789 kunmap(old_rq
->rq_pages
[i
]);
1792 rc
= crypt_message(server
, new_rq
, 1);
1793 cifs_dbg(FYI
, "encrypt message returned %d", rc
);
1795 goto err_free_tr_hdr
;
1804 for (i
= i
- 1; i
>= 0; i
--)
1811 smb3_free_transform_rq(struct smb_rqst
*rqst
)
1813 int i
= rqst
->rq_npages
- 1;
1816 put_page(rqst
->rq_pages
[i
]);
1817 kfree(rqst
->rq_pages
);
1818 /* free transform header */
1819 kfree(rqst
->rq_iov
[0].iov_base
);
1820 kfree(rqst
->rq_iov
);
1824 smb3_is_transform_hdr(void *buf
)
1826 struct smb2_transform_hdr
*trhdr
= buf
;
1828 return trhdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
;
1832 decrypt_raw_data(struct TCP_Server_Info
*server
, char *buf
,
1833 unsigned int buf_data_size
, struct page
**pages
,
1834 unsigned int npages
, unsigned int page_data_size
)
1837 struct smb_rqst rqst
= {NULL
};
1838 struct smb2_hdr
*hdr
;
1841 iov
[0].iov_base
= buf
;
1842 iov
[0].iov_len
= sizeof(struct smb2_transform_hdr
);
1843 iov
[1].iov_base
= buf
+ sizeof(struct smb2_transform_hdr
);
1844 iov
[1].iov_len
= buf_data_size
;
1848 rqst
.rq_pages
= pages
;
1849 rqst
.rq_npages
= npages
;
1850 rqst
.rq_pagesz
= PAGE_SIZE
;
1851 rqst
.rq_tailsz
= (page_data_size
% PAGE_SIZE
) ? : PAGE_SIZE
;
1853 rc
= crypt_message(server
, &rqst
, 0);
1854 cifs_dbg(FYI
, "decrypt message returned %d\n", rc
);
1859 memmove(buf
+ 4, iov
[1].iov_base
, buf_data_size
);
1860 hdr
= (struct smb2_hdr
*)buf
;
1861 hdr
->smb2_buf_length
= cpu_to_be32(buf_data_size
+ page_data_size
);
1862 server
->total_read
= buf_data_size
+ page_data_size
+ 4;
1868 read_data_into_pages(struct TCP_Server_Info
*server
, struct page
**pages
,
1869 unsigned int npages
, unsigned int len
)
1874 for (i
= 0; i
< npages
; i
++) {
1875 struct page
*page
= pages
[i
];
1879 if (len
>= PAGE_SIZE
) {
1880 /* enough data to fill the page */
1884 zero_user(page
, len
, PAGE_SIZE
- len
);
1887 length
= cifs_read_page_from_socket(server
, page
, n
);
1890 server
->total_read
+= length
;
1897 init_read_bvec(struct page
**pages
, unsigned int npages
, unsigned int data_size
,
1898 unsigned int cur_off
, struct bio_vec
**page_vec
)
1900 struct bio_vec
*bvec
;
1903 bvec
= kcalloc(npages
, sizeof(struct bio_vec
), GFP_KERNEL
);
1907 for (i
= 0; i
< npages
; i
++) {
1908 bvec
[i
].bv_page
= pages
[i
];
1909 bvec
[i
].bv_offset
= (i
== 0) ? cur_off
: 0;
1910 bvec
[i
].bv_len
= min_t(unsigned int, PAGE_SIZE
, data_size
);
1911 data_size
-= bvec
[i
].bv_len
;
1914 if (data_size
!= 0) {
1915 cifs_dbg(VFS
, "%s: something went wrong\n", __func__
);
1925 handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
,
1926 char *buf
, unsigned int buf_len
, struct page
**pages
,
1927 unsigned int npages
, unsigned int page_data_size
)
1929 unsigned int data_offset
;
1930 unsigned int data_len
;
1931 unsigned int cur_off
;
1932 unsigned int cur_page_idx
;
1933 unsigned int pad_len
;
1934 struct cifs_readdata
*rdata
= mid
->callback_data
;
1935 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
1936 struct bio_vec
*bvec
= NULL
;
1937 struct iov_iter iter
;
1941 if (shdr
->Command
!= SMB2_READ
) {
1942 cifs_dbg(VFS
, "only big read responses are supported\n");
1946 if (server
->ops
->is_status_pending
&&
1947 server
->ops
->is_status_pending(buf
, server
, 0))
1950 rdata
->result
= server
->ops
->map_error(buf
, false);
1951 if (rdata
->result
!= 0) {
1952 cifs_dbg(FYI
, "%s: server returned error %d\n",
1953 __func__
, rdata
->result
);
1954 dequeue_mid(mid
, rdata
->result
);
1958 data_offset
= server
->ops
->read_data_offset(buf
) + 4;
1959 data_len
= server
->ops
->read_data_length(buf
);
1961 if (data_offset
< server
->vals
->read_rsp_size
) {
1963 * win2k8 sometimes sends an offset of 0 when the read
1964 * is beyond the EOF. Treat it as if the data starts just after
1967 cifs_dbg(FYI
, "%s: data offset (%u) inside read response header\n",
1968 __func__
, data_offset
);
1969 data_offset
= server
->vals
->read_rsp_size
;
1970 } else if (data_offset
> MAX_CIFS_SMALL_BUFFER_SIZE
) {
1971 /* data_offset is beyond the end of smallbuf */
1972 cifs_dbg(FYI
, "%s: data offset (%u) beyond end of smallbuf\n",
1973 __func__
, data_offset
);
1974 rdata
->result
= -EIO
;
1975 dequeue_mid(mid
, rdata
->result
);
1979 pad_len
= data_offset
- server
->vals
->read_rsp_size
;
1981 if (buf_len
<= data_offset
) {
1982 /* read response payload is in pages */
1983 cur_page_idx
= pad_len
/ PAGE_SIZE
;
1984 cur_off
= pad_len
% PAGE_SIZE
;
1986 if (cur_page_idx
!= 0) {
1987 /* data offset is beyond the 1st page of response */
1988 cifs_dbg(FYI
, "%s: data offset (%u) beyond 1st page of response\n",
1989 __func__
, data_offset
);
1990 rdata
->result
= -EIO
;
1991 dequeue_mid(mid
, rdata
->result
);
1995 if (data_len
> page_data_size
- pad_len
) {
1996 /* data_len is corrupt -- discard frame */
1997 rdata
->result
= -EIO
;
1998 dequeue_mid(mid
, rdata
->result
);
2002 rdata
->result
= init_read_bvec(pages
, npages
, page_data_size
,
2004 if (rdata
->result
!= 0) {
2005 dequeue_mid(mid
, rdata
->result
);
2009 iov_iter_bvec(&iter
, WRITE
| ITER_BVEC
, bvec
, npages
, data_len
);
2010 } else if (buf_len
>= data_offset
+ data_len
) {
2011 /* read response payload is in buf */
2012 WARN_ONCE(npages
> 0, "read data can be either in buf or in pages");
2013 iov
.iov_base
= buf
+ data_offset
;
2014 iov
.iov_len
= data_len
;
2015 iov_iter_kvec(&iter
, WRITE
| ITER_KVEC
, &iov
, 1, data_len
);
2017 /* read response payload cannot be in both buf and pages */
2018 WARN_ONCE(1, "buf can not contain only a part of read data");
2019 rdata
->result
= -EIO
;
2020 dequeue_mid(mid
, rdata
->result
);
2024 /* set up first iov for signature check */
2025 rdata
->iov
[0].iov_base
= buf
;
2026 rdata
->iov
[0].iov_len
= 4;
2027 rdata
->iov
[1].iov_base
= buf
+ 4;
2028 rdata
->iov
[1].iov_len
= server
->vals
->read_rsp_size
- 4;
2029 cifs_dbg(FYI
, "0: iov_base=%p iov_len=%zu\n",
2030 rdata
->iov
[0].iov_base
, server
->vals
->read_rsp_size
);
2032 length
= rdata
->copy_into_pages(server
, rdata
, &iter
);
2039 dequeue_mid(mid
, false);
2044 receive_encrypted_read(struct TCP_Server_Info
*server
, struct mid_q_entry
**mid
)
2046 char *buf
= server
->smallbuf
;
2047 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
2048 unsigned int npages
;
2049 struct page
**pages
;
2051 unsigned int buflen
= get_rfc1002_length(buf
) + 4;
2055 len
= min_t(unsigned int, buflen
, server
->vals
->read_rsp_size
- 4 +
2056 sizeof(struct smb2_transform_hdr
)) - HEADER_SIZE(server
) + 1;
2058 rc
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1, len
);
2061 server
->total_read
+= rc
;
2063 len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
) + 4 -
2064 server
->vals
->read_rsp_size
;
2065 npages
= DIV_ROUND_UP(len
, PAGE_SIZE
);
2067 pages
= kmalloc_array(npages
, sizeof(struct page
*), GFP_KERNEL
);
2073 for (; i
< npages
; i
++) {
2074 pages
[i
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
2081 /* read read data into pages */
2082 rc
= read_data_into_pages(server
, pages
, npages
, len
);
2086 rc
= cifs_discard_remaining_data(server
);
2090 rc
= decrypt_raw_data(server
, buf
, server
->vals
->read_rsp_size
- 4,
2091 pages
, npages
, len
);
2095 *mid
= smb2_find_mid(server
, buf
);
2097 cifs_dbg(FYI
, "mid not found\n");
2099 cifs_dbg(FYI
, "mid found\n");
2100 (*mid
)->decrypted
= true;
2101 rc
= handle_read_data(server
, *mid
, buf
,
2102 server
->vals
->read_rsp_size
,
2103 pages
, npages
, len
);
2107 for (i
= i
- 1; i
>= 0; i
--)
2112 cifs_discard_remaining_data(server
);
2117 receive_encrypted_standard(struct TCP_Server_Info
*server
,
2118 struct mid_q_entry
**mid
)
2121 char *buf
= server
->smallbuf
;
2122 unsigned int pdu_length
= get_rfc1002_length(buf
);
2123 unsigned int buf_size
;
2124 struct mid_q_entry
*mid_entry
;
2126 /* switch to large buffer if too big for a small one */
2127 if (pdu_length
+ 4 > MAX_CIFS_SMALL_BUFFER_SIZE
) {
2128 server
->large_buf
= true;
2129 memcpy(server
->bigbuf
, buf
, server
->total_read
);
2130 buf
= server
->bigbuf
;
2133 /* now read the rest */
2134 length
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1,
2135 pdu_length
- HEADER_SIZE(server
) + 1 + 4);
2138 server
->total_read
+= length
;
2140 buf_size
= pdu_length
+ 4 - sizeof(struct smb2_transform_hdr
);
2141 length
= decrypt_raw_data(server
, buf
, buf_size
, NULL
, 0, 0);
2145 mid_entry
= smb2_find_mid(server
, buf
);
2146 if (mid_entry
== NULL
)
2147 cifs_dbg(FYI
, "mid not found\n");
2149 cifs_dbg(FYI
, "mid found\n");
2150 mid_entry
->decrypted
= true;
2155 if (mid_entry
&& mid_entry
->handle
)
2156 return mid_entry
->handle(server
, mid_entry
);
2158 return cifs_handle_standard(server
, mid_entry
);
2162 smb3_receive_transform(struct TCP_Server_Info
*server
, struct mid_q_entry
**mid
)
2164 char *buf
= server
->smallbuf
;
2165 unsigned int pdu_length
= get_rfc1002_length(buf
);
2166 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
2167 unsigned int orig_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
2169 if (pdu_length
+ 4 < sizeof(struct smb2_transform_hdr
) +
2170 sizeof(struct smb2_sync_hdr
)) {
2171 cifs_dbg(VFS
, "Transform message is too small (%u)\n",
2173 cifs_reconnect(server
);
2174 wake_up(&server
->response_q
);
2175 return -ECONNABORTED
;
2178 if (pdu_length
+ 4 < orig_len
+ sizeof(struct smb2_transform_hdr
)) {
2179 cifs_dbg(VFS
, "Transform message is broken\n");
2180 cifs_reconnect(server
);
2181 wake_up(&server
->response_q
);
2182 return -ECONNABORTED
;
2185 if (pdu_length
+ 4 > CIFSMaxBufSize
+ MAX_HEADER_SIZE(server
))
2186 return receive_encrypted_read(server
, mid
);
2188 return receive_encrypted_standard(server
, mid
);
2192 smb3_handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
)
2194 char *buf
= server
->large_buf
? server
->bigbuf
: server
->smallbuf
;
2196 return handle_read_data(server
, mid
, buf
, get_rfc1002_length(buf
) + 4,
2200 struct smb_version_operations smb20_operations
= {
2201 .compare_fids
= smb2_compare_fids
,
2202 .setup_request
= smb2_setup_request
,
2203 .setup_async_request
= smb2_setup_async_request
,
2204 .check_receive
= smb2_check_receive
,
2205 .add_credits
= smb2_add_credits
,
2206 .set_credits
= smb2_set_credits
,
2207 .get_credits_field
= smb2_get_credits_field
,
2208 .get_credits
= smb2_get_credits
,
2209 .wait_mtu_credits
= cifs_wait_mtu_credits
,
2210 .get_next_mid
= smb2_get_next_mid
,
2211 .read_data_offset
= smb2_read_data_offset
,
2212 .read_data_length
= smb2_read_data_length
,
2213 .map_error
= map_smb2_to_linux_error
,
2214 .find_mid
= smb2_find_mid
,
2215 .check_message
= smb2_check_message
,
2216 .dump_detail
= smb2_dump_detail
,
2217 .clear_stats
= smb2_clear_stats
,
2218 .print_stats
= smb2_print_stats
,
2219 .is_oplock_break
= smb2_is_valid_oplock_break
,
2220 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
2221 .downgrade_oplock
= smb2_downgrade_oplock
,
2222 .need_neg
= smb2_need_neg
,
2223 .negotiate
= smb2_negotiate
,
2224 .negotiate_wsize
= smb2_negotiate_wsize
,
2225 .negotiate_rsize
= smb2_negotiate_rsize
,
2226 .sess_setup
= SMB2_sess_setup
,
2227 .logoff
= SMB2_logoff
,
2228 .tree_connect
= SMB2_tcon
,
2229 .tree_disconnect
= SMB2_tdis
,
2230 .qfs_tcon
= smb2_qfs_tcon
,
2231 .is_path_accessible
= smb2_is_path_accessible
,
2232 .can_echo
= smb2_can_echo
,
2234 .query_path_info
= smb2_query_path_info
,
2235 .get_srv_inum
= smb2_get_srv_inum
,
2236 .query_file_info
= smb2_query_file_info
,
2237 .set_path_size
= smb2_set_path_size
,
2238 .set_file_size
= smb2_set_file_size
,
2239 .set_file_info
= smb2_set_file_info
,
2240 .set_compression
= smb2_set_compression
,
2241 .mkdir
= smb2_mkdir
,
2242 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2243 .rmdir
= smb2_rmdir
,
2244 .unlink
= smb2_unlink
,
2245 .rename
= smb2_rename_path
,
2246 .create_hardlink
= smb2_create_hardlink
,
2247 .query_symlink
= smb2_query_symlink
,
2248 .query_mf_symlink
= smb3_query_mf_symlink
,
2249 .create_mf_symlink
= smb3_create_mf_symlink
,
2250 .open
= smb2_open_file
,
2251 .set_fid
= smb2_set_fid
,
2252 .close
= smb2_close_file
,
2253 .flush
= smb2_flush_file
,
2254 .async_readv
= smb2_async_readv
,
2255 .async_writev
= smb2_async_writev
,
2256 .sync_read
= smb2_sync_read
,
2257 .sync_write
= smb2_sync_write
,
2258 .query_dir_first
= smb2_query_dir_first
,
2259 .query_dir_next
= smb2_query_dir_next
,
2260 .close_dir
= smb2_close_dir
,
2261 .calc_smb_size
= smb2_calc_size
,
2262 .is_status_pending
= smb2_is_status_pending
,
2263 .oplock_response
= smb2_oplock_response
,
2264 .queryfs
= smb2_queryfs
,
2265 .mand_lock
= smb2_mand_lock
,
2266 .mand_unlock_range
= smb2_unlock_range
,
2267 .push_mand_locks
= smb2_push_mandatory_locks
,
2268 .get_lease_key
= smb2_get_lease_key
,
2269 .set_lease_key
= smb2_set_lease_key
,
2270 .new_lease_key
= smb2_new_lease_key
,
2271 .calc_signature
= smb2_calc_signature
,
2272 .is_read_op
= smb2_is_read_op
,
2273 .set_oplock_level
= smb2_set_oplock_level
,
2274 .create_lease_buf
= smb2_create_lease_buf
,
2275 .parse_lease_buf
= smb2_parse_lease_buf
,
2276 .clone_range
= smb2_clone_range
,
2277 .wp_retry_size
= smb2_wp_retry_size
,
2278 .dir_needs_close
= smb2_dir_needs_close
,
2281 struct smb_version_operations smb21_operations
= {
2282 .compare_fids
= smb2_compare_fids
,
2283 .setup_request
= smb2_setup_request
,
2284 .setup_async_request
= smb2_setup_async_request
,
2285 .check_receive
= smb2_check_receive
,
2286 .add_credits
= smb2_add_credits
,
2287 .set_credits
= smb2_set_credits
,
2288 .get_credits_field
= smb2_get_credits_field
,
2289 .get_credits
= smb2_get_credits
,
2290 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2291 .get_next_mid
= smb2_get_next_mid
,
2292 .read_data_offset
= smb2_read_data_offset
,
2293 .read_data_length
= smb2_read_data_length
,
2294 .map_error
= map_smb2_to_linux_error
,
2295 .find_mid
= smb2_find_mid
,
2296 .check_message
= smb2_check_message
,
2297 .dump_detail
= smb2_dump_detail
,
2298 .clear_stats
= smb2_clear_stats
,
2299 .print_stats
= smb2_print_stats
,
2300 .is_oplock_break
= smb2_is_valid_oplock_break
,
2301 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
2302 .downgrade_oplock
= smb2_downgrade_oplock
,
2303 .need_neg
= smb2_need_neg
,
2304 .negotiate
= smb2_negotiate
,
2305 .negotiate_wsize
= smb2_negotiate_wsize
,
2306 .negotiate_rsize
= smb2_negotiate_rsize
,
2307 .sess_setup
= SMB2_sess_setup
,
2308 .logoff
= SMB2_logoff
,
2309 .tree_connect
= SMB2_tcon
,
2310 .tree_disconnect
= SMB2_tdis
,
2311 .qfs_tcon
= smb2_qfs_tcon
,
2312 .is_path_accessible
= smb2_is_path_accessible
,
2313 .can_echo
= smb2_can_echo
,
2315 .query_path_info
= smb2_query_path_info
,
2316 .get_srv_inum
= smb2_get_srv_inum
,
2317 .query_file_info
= smb2_query_file_info
,
2318 .set_path_size
= smb2_set_path_size
,
2319 .set_file_size
= smb2_set_file_size
,
2320 .set_file_info
= smb2_set_file_info
,
2321 .set_compression
= smb2_set_compression
,
2322 .mkdir
= smb2_mkdir
,
2323 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2324 .rmdir
= smb2_rmdir
,
2325 .unlink
= smb2_unlink
,
2326 .rename
= smb2_rename_path
,
2327 .create_hardlink
= smb2_create_hardlink
,
2328 .query_symlink
= smb2_query_symlink
,
2329 .query_mf_symlink
= smb3_query_mf_symlink
,
2330 .create_mf_symlink
= smb3_create_mf_symlink
,
2331 .open
= smb2_open_file
,
2332 .set_fid
= smb2_set_fid
,
2333 .close
= smb2_close_file
,
2334 .flush
= smb2_flush_file
,
2335 .async_readv
= smb2_async_readv
,
2336 .async_writev
= smb2_async_writev
,
2337 .sync_read
= smb2_sync_read
,
2338 .sync_write
= smb2_sync_write
,
2339 .query_dir_first
= smb2_query_dir_first
,
2340 .query_dir_next
= smb2_query_dir_next
,
2341 .close_dir
= smb2_close_dir
,
2342 .calc_smb_size
= smb2_calc_size
,
2343 .is_status_pending
= smb2_is_status_pending
,
2344 .oplock_response
= smb2_oplock_response
,
2345 .queryfs
= smb2_queryfs
,
2346 .mand_lock
= smb2_mand_lock
,
2347 .mand_unlock_range
= smb2_unlock_range
,
2348 .push_mand_locks
= smb2_push_mandatory_locks
,
2349 .get_lease_key
= smb2_get_lease_key
,
2350 .set_lease_key
= smb2_set_lease_key
,
2351 .new_lease_key
= smb2_new_lease_key
,
2352 .calc_signature
= smb2_calc_signature
,
2353 .is_read_op
= smb21_is_read_op
,
2354 .set_oplock_level
= smb21_set_oplock_level
,
2355 .create_lease_buf
= smb2_create_lease_buf
,
2356 .parse_lease_buf
= smb2_parse_lease_buf
,
2357 .clone_range
= smb2_clone_range
,
2358 .wp_retry_size
= smb2_wp_retry_size
,
2359 .dir_needs_close
= smb2_dir_needs_close
,
2360 .enum_snapshots
= smb3_enum_snapshots
,
2363 struct smb_version_operations smb30_operations
= {
2364 .compare_fids
= smb2_compare_fids
,
2365 .setup_request
= smb2_setup_request
,
2366 .setup_async_request
= smb2_setup_async_request
,
2367 .check_receive
= smb2_check_receive
,
2368 .add_credits
= smb2_add_credits
,
2369 .set_credits
= smb2_set_credits
,
2370 .get_credits_field
= smb2_get_credits_field
,
2371 .get_credits
= smb2_get_credits
,
2372 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2373 .get_next_mid
= smb2_get_next_mid
,
2374 .read_data_offset
= smb2_read_data_offset
,
2375 .read_data_length
= smb2_read_data_length
,
2376 .map_error
= map_smb2_to_linux_error
,
2377 .find_mid
= smb2_find_mid
,
2378 .check_message
= smb2_check_message
,
2379 .dump_detail
= smb2_dump_detail
,
2380 .clear_stats
= smb2_clear_stats
,
2381 .print_stats
= smb2_print_stats
,
2382 .dump_share_caps
= smb2_dump_share_caps
,
2383 .is_oplock_break
= smb2_is_valid_oplock_break
,
2384 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
2385 .downgrade_oplock
= smb2_downgrade_oplock
,
2386 .need_neg
= smb2_need_neg
,
2387 .negotiate
= smb2_negotiate
,
2388 .negotiate_wsize
= smb2_negotiate_wsize
,
2389 .negotiate_rsize
= smb2_negotiate_rsize
,
2390 .sess_setup
= SMB2_sess_setup
,
2391 .logoff
= SMB2_logoff
,
2392 .tree_connect
= SMB2_tcon
,
2393 .tree_disconnect
= SMB2_tdis
,
2394 .qfs_tcon
= smb3_qfs_tcon
,
2395 .is_path_accessible
= smb2_is_path_accessible
,
2396 .can_echo
= smb2_can_echo
,
2398 .query_path_info
= smb2_query_path_info
,
2399 .get_srv_inum
= smb2_get_srv_inum
,
2400 .query_file_info
= smb2_query_file_info
,
2401 .set_path_size
= smb2_set_path_size
,
2402 .set_file_size
= smb2_set_file_size
,
2403 .set_file_info
= smb2_set_file_info
,
2404 .set_compression
= smb2_set_compression
,
2405 .mkdir
= smb2_mkdir
,
2406 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2407 .rmdir
= smb2_rmdir
,
2408 .unlink
= smb2_unlink
,
2409 .rename
= smb2_rename_path
,
2410 .create_hardlink
= smb2_create_hardlink
,
2411 .query_symlink
= smb2_query_symlink
,
2412 .query_mf_symlink
= smb3_query_mf_symlink
,
2413 .create_mf_symlink
= smb3_create_mf_symlink
,
2414 .open
= smb2_open_file
,
2415 .set_fid
= smb2_set_fid
,
2416 .close
= smb2_close_file
,
2417 .flush
= smb2_flush_file
,
2418 .async_readv
= smb2_async_readv
,
2419 .async_writev
= smb2_async_writev
,
2420 .sync_read
= smb2_sync_read
,
2421 .sync_write
= smb2_sync_write
,
2422 .query_dir_first
= smb2_query_dir_first
,
2423 .query_dir_next
= smb2_query_dir_next
,
2424 .close_dir
= smb2_close_dir
,
2425 .calc_smb_size
= smb2_calc_size
,
2426 .is_status_pending
= smb2_is_status_pending
,
2427 .oplock_response
= smb2_oplock_response
,
2428 .queryfs
= smb2_queryfs
,
2429 .mand_lock
= smb2_mand_lock
,
2430 .mand_unlock_range
= smb2_unlock_range
,
2431 .push_mand_locks
= smb2_push_mandatory_locks
,
2432 .get_lease_key
= smb2_get_lease_key
,
2433 .set_lease_key
= smb2_set_lease_key
,
2434 .new_lease_key
= smb2_new_lease_key
,
2435 .generate_signingkey
= generate_smb30signingkey
,
2436 .calc_signature
= smb3_calc_signature
,
2437 .set_integrity
= smb3_set_integrity
,
2438 .is_read_op
= smb21_is_read_op
,
2439 .set_oplock_level
= smb3_set_oplock_level
,
2440 .create_lease_buf
= smb3_create_lease_buf
,
2441 .parse_lease_buf
= smb3_parse_lease_buf
,
2442 .clone_range
= smb2_clone_range
,
2443 .duplicate_extents
= smb2_duplicate_extents
,
2444 .validate_negotiate
= smb3_validate_negotiate
,
2445 .wp_retry_size
= smb2_wp_retry_size
,
2446 .dir_needs_close
= smb2_dir_needs_close
,
2447 .fallocate
= smb3_fallocate
,
2448 .enum_snapshots
= smb3_enum_snapshots
,
2449 .init_transform_rq
= smb3_init_transform_rq
,
2450 .free_transform_rq
= smb3_free_transform_rq
,
2451 .is_transform_hdr
= smb3_is_transform_hdr
,
2452 .receive_transform
= smb3_receive_transform
,
2455 #ifdef CONFIG_CIFS_SMB311
2456 struct smb_version_operations smb311_operations
= {
2457 .compare_fids
= smb2_compare_fids
,
2458 .setup_request
= smb2_setup_request
,
2459 .setup_async_request
= smb2_setup_async_request
,
2460 .check_receive
= smb2_check_receive
,
2461 .add_credits
= smb2_add_credits
,
2462 .set_credits
= smb2_set_credits
,
2463 .get_credits_field
= smb2_get_credits_field
,
2464 .get_credits
= smb2_get_credits
,
2465 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2466 .get_next_mid
= smb2_get_next_mid
,
2467 .read_data_offset
= smb2_read_data_offset
,
2468 .read_data_length
= smb2_read_data_length
,
2469 .map_error
= map_smb2_to_linux_error
,
2470 .find_mid
= smb2_find_mid
,
2471 .check_message
= smb2_check_message
,
2472 .dump_detail
= smb2_dump_detail
,
2473 .clear_stats
= smb2_clear_stats
,
2474 .print_stats
= smb2_print_stats
,
2475 .dump_share_caps
= smb2_dump_share_caps
,
2476 .is_oplock_break
= smb2_is_valid_oplock_break
,
2477 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
2478 .downgrade_oplock
= smb2_downgrade_oplock
,
2479 .need_neg
= smb2_need_neg
,
2480 .negotiate
= smb2_negotiate
,
2481 .negotiate_wsize
= smb2_negotiate_wsize
,
2482 .negotiate_rsize
= smb2_negotiate_rsize
,
2483 .sess_setup
= SMB2_sess_setup
,
2484 .logoff
= SMB2_logoff
,
2485 .tree_connect
= SMB2_tcon
,
2486 .tree_disconnect
= SMB2_tdis
,
2487 .qfs_tcon
= smb3_qfs_tcon
,
2488 .is_path_accessible
= smb2_is_path_accessible
,
2489 .can_echo
= smb2_can_echo
,
2491 .query_path_info
= smb2_query_path_info
,
2492 .get_srv_inum
= smb2_get_srv_inum
,
2493 .query_file_info
= smb2_query_file_info
,
2494 .set_path_size
= smb2_set_path_size
,
2495 .set_file_size
= smb2_set_file_size
,
2496 .set_file_info
= smb2_set_file_info
,
2497 .set_compression
= smb2_set_compression
,
2498 .mkdir
= smb2_mkdir
,
2499 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2500 .rmdir
= smb2_rmdir
,
2501 .unlink
= smb2_unlink
,
2502 .rename
= smb2_rename_path
,
2503 .create_hardlink
= smb2_create_hardlink
,
2504 .query_symlink
= smb2_query_symlink
,
2505 .query_mf_symlink
= smb3_query_mf_symlink
,
2506 .create_mf_symlink
= smb3_create_mf_symlink
,
2507 .open
= smb2_open_file
,
2508 .set_fid
= smb2_set_fid
,
2509 .close
= smb2_close_file
,
2510 .flush
= smb2_flush_file
,
2511 .async_readv
= smb2_async_readv
,
2512 .async_writev
= smb2_async_writev
,
2513 .sync_read
= smb2_sync_read
,
2514 .sync_write
= smb2_sync_write
,
2515 .query_dir_first
= smb2_query_dir_first
,
2516 .query_dir_next
= smb2_query_dir_next
,
2517 .close_dir
= smb2_close_dir
,
2518 .calc_smb_size
= smb2_calc_size
,
2519 .is_status_pending
= smb2_is_status_pending
,
2520 .oplock_response
= smb2_oplock_response
,
2521 .queryfs
= smb2_queryfs
,
2522 .mand_lock
= smb2_mand_lock
,
2523 .mand_unlock_range
= smb2_unlock_range
,
2524 .push_mand_locks
= smb2_push_mandatory_locks
,
2525 .get_lease_key
= smb2_get_lease_key
,
2526 .set_lease_key
= smb2_set_lease_key
,
2527 .new_lease_key
= smb2_new_lease_key
,
2528 .generate_signingkey
= generate_smb311signingkey
,
2529 .calc_signature
= smb3_calc_signature
,
2530 .set_integrity
= smb3_set_integrity
,
2531 .is_read_op
= smb21_is_read_op
,
2532 .set_oplock_level
= smb3_set_oplock_level
,
2533 .create_lease_buf
= smb3_create_lease_buf
,
2534 .parse_lease_buf
= smb3_parse_lease_buf
,
2535 .clone_range
= smb2_clone_range
,
2536 .duplicate_extents
= smb2_duplicate_extents
,
2537 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
2538 .wp_retry_size
= smb2_wp_retry_size
,
2539 .dir_needs_close
= smb2_dir_needs_close
,
2540 .fallocate
= smb3_fallocate
,
2541 .enum_snapshots
= smb3_enum_snapshots
,
2542 .init_transform_rq
= smb3_init_transform_rq
,
2543 .free_transform_rq
= smb3_free_transform_rq
,
2544 .is_transform_hdr
= smb3_is_transform_hdr
,
2545 .receive_transform
= smb3_receive_transform
,
2547 #endif /* CIFS_SMB311 */
2549 struct smb_version_values smb20_values
= {
2550 .version_string
= SMB20_VERSION_STRING
,
2551 .protocol_id
= SMB20_PROT_ID
,
2552 .req_capabilities
= 0, /* MBZ */
2553 .large_lock_type
= 0,
2554 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2555 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2556 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2557 .header_size
= sizeof(struct smb2_hdr
),
2558 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2559 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2560 .lock_cmd
= SMB2_LOCK
,
2562 .cap_nt_find
= SMB2_NT_FIND
,
2563 .cap_large_files
= SMB2_LARGE_FILES
,
2564 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2565 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2566 .create_lease_size
= sizeof(struct create_lease
),
2569 struct smb_version_values smb21_values
= {
2570 .version_string
= SMB21_VERSION_STRING
,
2571 .protocol_id
= SMB21_PROT_ID
,
2572 .req_capabilities
= 0, /* MBZ on negotiate req until SMB3 dialect */
2573 .large_lock_type
= 0,
2574 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2575 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2576 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2577 .header_size
= sizeof(struct smb2_hdr
),
2578 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2579 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2580 .lock_cmd
= SMB2_LOCK
,
2582 .cap_nt_find
= SMB2_NT_FIND
,
2583 .cap_large_files
= SMB2_LARGE_FILES
,
2584 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2585 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2586 .create_lease_size
= sizeof(struct create_lease
),
2589 struct smb_version_values smb30_values
= {
2590 .version_string
= SMB30_VERSION_STRING
,
2591 .protocol_id
= SMB30_PROT_ID
,
2592 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
2593 .large_lock_type
= 0,
2594 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2595 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2596 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2597 .header_size
= sizeof(struct smb2_hdr
),
2598 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2599 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2600 .lock_cmd
= SMB2_LOCK
,
2602 .cap_nt_find
= SMB2_NT_FIND
,
2603 .cap_large_files
= SMB2_LARGE_FILES
,
2604 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2605 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2606 .create_lease_size
= sizeof(struct create_lease_v2
),
2609 struct smb_version_values smb302_values
= {
2610 .version_string
= SMB302_VERSION_STRING
,
2611 .protocol_id
= SMB302_PROT_ID
,
2612 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
2613 .large_lock_type
= 0,
2614 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2615 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2616 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2617 .header_size
= sizeof(struct smb2_hdr
),
2618 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2619 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2620 .lock_cmd
= SMB2_LOCK
,
2622 .cap_nt_find
= SMB2_NT_FIND
,
2623 .cap_large_files
= SMB2_LARGE_FILES
,
2624 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2625 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2626 .create_lease_size
= sizeof(struct create_lease_v2
),
2629 #ifdef CONFIG_CIFS_SMB311
2630 struct smb_version_values smb311_values
= {
2631 .version_string
= SMB311_VERSION_STRING
,
2632 .protocol_id
= SMB311_PROT_ID
,
2633 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
,
2634 .large_lock_type
= 0,
2635 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2636 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2637 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2638 .header_size
= sizeof(struct smb2_hdr
),
2639 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2640 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2641 .lock_cmd
= SMB2_LOCK
,
2643 .cap_nt_find
= SMB2_NT_FIND
,
2644 .cap_large_files
= SMB2_LARGE_FILES
,
2645 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2646 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2647 .create_lease_size
= sizeof(struct create_lease_v2
),