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
)) {
934 if (ret_data_len
> snapshot_in
.snapshot_array_size
)
935 ret_data_len
= snapshot_in
.snapshot_array_size
;
937 if (copy_to_user(ioc_buf
, retbuf
, ret_data_len
))
946 smb2_query_dir_first(const unsigned int xid
, struct cifs_tcon
*tcon
,
947 const char *path
, struct cifs_sb_info
*cifs_sb
,
948 struct cifs_fid
*fid
, __u16 search_flags
,
949 struct cifs_search_info
*srch_inf
)
953 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
954 struct cifs_open_parms oparms
;
956 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
961 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| FILE_READ_DATA
;
962 oparms
.disposition
= FILE_OPEN
;
963 oparms
.create_options
= 0;
965 oparms
.reconnect
= false;
967 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
970 cifs_dbg(VFS
, "open dir failed\n");
974 srch_inf
->entries_in_buffer
= 0;
975 srch_inf
->index_of_last_entry
= 0;
977 rc
= SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
978 fid
->volatile_fid
, 0, srch_inf
);
980 cifs_dbg(VFS
, "query directory failed\n");
981 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
987 smb2_query_dir_next(const unsigned int xid
, struct cifs_tcon
*tcon
,
988 struct cifs_fid
*fid
, __u16 search_flags
,
989 struct cifs_search_info
*srch_inf
)
991 return SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
992 fid
->volatile_fid
, 0, srch_inf
);
996 smb2_close_dir(const unsigned int xid
, struct cifs_tcon
*tcon
,
997 struct cifs_fid
*fid
)
999 return SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1003 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
1004 * the number of credits and return true. Otherwise - return false.
1007 smb2_is_status_pending(char *buf
, struct TCP_Server_Info
*server
, int length
)
1009 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
1011 if (shdr
->Status
!= STATUS_PENDING
)
1015 spin_lock(&server
->req_lock
);
1016 server
->credits
+= le16_to_cpu(shdr
->CreditRequest
);
1017 spin_unlock(&server
->req_lock
);
1018 wake_up(&server
->request_q
);
1025 smb2_oplock_response(struct cifs_tcon
*tcon
, struct cifs_fid
*fid
,
1026 struct cifsInodeInfo
*cinode
)
1028 if (tcon
->ses
->server
->capabilities
& SMB2_GLOBAL_CAP_LEASING
)
1029 return SMB2_lease_break(0, tcon
, cinode
->lease_key
,
1030 smb2_get_lease_state(cinode
));
1032 return SMB2_oplock_break(0, tcon
, fid
->persistent_fid
,
1034 CIFS_CACHE_READ(cinode
) ? 1 : 0);
1038 smb2_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
1039 struct kstatfs
*buf
)
1042 __le16 srch_path
= 0; /* Null - open root of share */
1043 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1044 struct cifs_open_parms oparms
;
1045 struct cifs_fid fid
;
1048 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
1049 oparms
.disposition
= FILE_OPEN
;
1050 oparms
.create_options
= 0;
1052 oparms
.reconnect
= false;
1054 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
1057 buf
->f_type
= SMB2_MAGIC_NUMBER
;
1058 rc
= SMB2_QFS_info(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
1060 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
1065 smb2_compare_fids(struct cifsFileInfo
*ob1
, struct cifsFileInfo
*ob2
)
1067 return ob1
->fid
.persistent_fid
== ob2
->fid
.persistent_fid
&&
1068 ob1
->fid
.volatile_fid
== ob2
->fid
.volatile_fid
;
1072 smb2_mand_lock(const unsigned int xid
, struct cifsFileInfo
*cfile
, __u64 offset
,
1073 __u64 length
, __u32 type
, int lock
, int unlock
, bool wait
)
1075 if (unlock
&& !lock
)
1076 type
= SMB2_LOCKFLAG_UNLOCK
;
1077 return SMB2_lock(xid
, tlink_tcon(cfile
->tlink
),
1078 cfile
->fid
.persistent_fid
, cfile
->fid
.volatile_fid
,
1079 current
->tgid
, length
, offset
, type
, wait
);
1083 smb2_get_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
1085 memcpy(fid
->lease_key
, CIFS_I(inode
)->lease_key
, SMB2_LEASE_KEY_SIZE
);
1089 smb2_set_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
1091 memcpy(CIFS_I(inode
)->lease_key
, fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
1095 smb2_new_lease_key(struct cifs_fid
*fid
)
1097 generate_random_uuid(fid
->lease_key
);
1100 #define SMB2_SYMLINK_STRUCT_SIZE \
1101 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
1104 smb2_query_symlink(const unsigned int xid
, struct cifs_tcon
*tcon
,
1105 const char *full_path
, char **target_path
,
1106 struct cifs_sb_info
*cifs_sb
)
1110 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1111 struct cifs_open_parms oparms
;
1112 struct cifs_fid fid
;
1113 struct smb2_err_rsp
*err_buf
= NULL
;
1114 struct smb2_symlink_err_rsp
*symlink
;
1115 unsigned int sub_len
;
1116 unsigned int sub_offset
;
1117 unsigned int print_len
;
1118 unsigned int print_offset
;
1120 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, full_path
);
1122 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
1127 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
1128 oparms
.disposition
= FILE_OPEN
;
1129 oparms
.create_options
= 0;
1131 oparms
.reconnect
= false;
1133 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, &err_buf
);
1135 if (!rc
|| !err_buf
) {
1140 if (le32_to_cpu(err_buf
->ByteCount
) < sizeof(struct smb2_symlink_err_rsp
) ||
1141 get_rfc1002_length(err_buf
) + 4 < SMB2_SYMLINK_STRUCT_SIZE
) {
1146 /* open must fail on symlink - reset rc */
1148 symlink
= (struct smb2_symlink_err_rsp
*)err_buf
->ErrorData
;
1149 sub_len
= le16_to_cpu(symlink
->SubstituteNameLength
);
1150 sub_offset
= le16_to_cpu(symlink
->SubstituteNameOffset
);
1151 print_len
= le16_to_cpu(symlink
->PrintNameLength
);
1152 print_offset
= le16_to_cpu(symlink
->PrintNameOffset
);
1154 if (get_rfc1002_length(err_buf
) + 4 <
1155 SMB2_SYMLINK_STRUCT_SIZE
+ sub_offset
+ sub_len
) {
1160 if (get_rfc1002_length(err_buf
) + 4 <
1161 SMB2_SYMLINK_STRUCT_SIZE
+ print_offset
+ print_len
) {
1166 *target_path
= cifs_strndup_from_utf16(
1167 (char *)symlink
->PathBuffer
+ sub_offset
,
1168 sub_len
, true, cifs_sb
->local_nls
);
1169 if (!(*target_path
)) {
1173 convert_delimiter(*target_path
, '/');
1174 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
1179 static long smb3_zero_range(struct file
*file
, struct cifs_tcon
*tcon
,
1180 loff_t offset
, loff_t len
, bool keep_size
)
1182 struct inode
*inode
;
1183 struct cifsInodeInfo
*cifsi
;
1184 struct cifsFileInfo
*cfile
= file
->private_data
;
1185 struct file_zero_data_information fsctl_buf
;
1191 inode
= d_inode(cfile
->dentry
);
1192 cifsi
= CIFS_I(inode
);
1194 /* if file not oplocked can't be sure whether asking to extend size */
1195 if (!CIFS_CACHE_READ(cifsi
))
1196 if (keep_size
== false)
1200 * Must check if file sparse since fallocate -z (zero range) assumes
1201 * non-sparse allocation
1203 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
))
1207 * need to make sure we are not asked to extend the file since the SMB3
1208 * fsctl does not change the file size. In the future we could change
1209 * this to zero the first part of the range then set the file size
1210 * which for a non sparse file would zero the newly extended range
1212 if (keep_size
== false)
1213 if (i_size_read(inode
) < offset
+ len
)
1216 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1218 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1219 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1221 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1222 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1223 true /* is_fctl */, (char *)&fsctl_buf
,
1224 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1229 static long smb3_punch_hole(struct file
*file
, struct cifs_tcon
*tcon
,
1230 loff_t offset
, loff_t len
)
1232 struct inode
*inode
;
1233 struct cifsInodeInfo
*cifsi
;
1234 struct cifsFileInfo
*cfile
= file
->private_data
;
1235 struct file_zero_data_information fsctl_buf
;
1238 __u8 set_sparse
= 1;
1242 inode
= d_inode(cfile
->dentry
);
1243 cifsi
= CIFS_I(inode
);
1245 /* Need to make file sparse, if not already, before freeing range. */
1246 /* Consider adding equivalent for compressed since it could also work */
1247 if (!smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
))
1250 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1252 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1253 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1255 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1256 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1257 true /* is_fctl */, (char *)&fsctl_buf
,
1258 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1263 static long smb3_simple_falloc(struct file
*file
, struct cifs_tcon
*tcon
,
1264 loff_t off
, loff_t len
, bool keep_size
)
1266 struct inode
*inode
;
1267 struct cifsInodeInfo
*cifsi
;
1268 struct cifsFileInfo
*cfile
= file
->private_data
;
1269 long rc
= -EOPNOTSUPP
;
1274 inode
= d_inode(cfile
->dentry
);
1275 cifsi
= CIFS_I(inode
);
1277 /* if file not oplocked can't be sure whether asking to extend size */
1278 if (!CIFS_CACHE_READ(cifsi
))
1279 if (keep_size
== false)
1283 * Files are non-sparse by default so falloc may be a no-op
1284 * Must check if file sparse. If not sparse, and not extending
1285 * then no need to do anything since file already allocated
1287 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) == 0) {
1288 if (keep_size
== true)
1290 /* check if extending file */
1291 else if (i_size_read(inode
) >= off
+ len
)
1292 /* not extending file and already not sparse */
1294 /* BB: in future add else clause to extend file */
1299 if ((keep_size
== true) || (i_size_read(inode
) >= off
+ len
)) {
1301 * Check if falloc starts within first few pages of file
1302 * and ends within a few pages of the end of file to
1303 * ensure that most of file is being forced to be
1304 * fallocated now. If so then setting whole file sparse
1305 * ie potentially making a few extra pages at the beginning
1306 * or end of the file non-sparse via set_sparse is harmless.
1308 if ((off
> 8192) || (off
+ len
+ 8192 < i_size_read(inode
)))
1311 rc
= smb2_set_sparse(xid
, tcon
, cfile
, inode
, false);
1313 /* BB: else ... in future add code to extend file and set sparse */
1321 static long smb3_fallocate(struct file
*file
, struct cifs_tcon
*tcon
, int mode
,
1322 loff_t off
, loff_t len
)
1324 /* KEEP_SIZE already checked for by do_fallocate */
1325 if (mode
& FALLOC_FL_PUNCH_HOLE
)
1326 return smb3_punch_hole(file
, tcon
, off
, len
);
1327 else if (mode
& FALLOC_FL_ZERO_RANGE
) {
1328 if (mode
& FALLOC_FL_KEEP_SIZE
)
1329 return smb3_zero_range(file
, tcon
, off
, len
, true);
1330 return smb3_zero_range(file
, tcon
, off
, len
, false);
1331 } else if (mode
== FALLOC_FL_KEEP_SIZE
)
1332 return smb3_simple_falloc(file
, tcon
, off
, len
, true);
1334 return smb3_simple_falloc(file
, tcon
, off
, len
, false);
1340 smb2_downgrade_oplock(struct TCP_Server_Info
*server
,
1341 struct cifsInodeInfo
*cinode
, bool set_level2
)
1344 server
->ops
->set_oplock_level(cinode
, SMB2_OPLOCK_LEVEL_II
,
1347 server
->ops
->set_oplock_level(cinode
, 0, 0, NULL
);
1351 smb2_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1352 unsigned int epoch
, bool *purge_cache
)
1355 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1357 if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
) {
1358 cinode
->oplock
= CIFS_CACHE_RHW_FLG
;
1359 cifs_dbg(FYI
, "Batch Oplock granted on inode %p\n",
1360 &cinode
->vfs_inode
);
1361 } else if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
) {
1362 cinode
->oplock
= CIFS_CACHE_RW_FLG
;
1363 cifs_dbg(FYI
, "Exclusive Oplock granted on inode %p\n",
1364 &cinode
->vfs_inode
);
1365 } else if (oplock
== SMB2_OPLOCK_LEVEL_II
) {
1366 cinode
->oplock
= CIFS_CACHE_READ_FLG
;
1367 cifs_dbg(FYI
, "Level II Oplock granted on inode %p\n",
1368 &cinode
->vfs_inode
);
1374 smb21_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1375 unsigned int epoch
, bool *purge_cache
)
1377 char message
[5] = {0};
1380 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1384 if (oplock
& SMB2_LEASE_READ_CACHING_HE
) {
1385 cinode
->oplock
|= CIFS_CACHE_READ_FLG
;
1386 strcat(message
, "R");
1388 if (oplock
& SMB2_LEASE_HANDLE_CACHING_HE
) {
1389 cinode
->oplock
|= CIFS_CACHE_HANDLE_FLG
;
1390 strcat(message
, "H");
1392 if (oplock
& SMB2_LEASE_WRITE_CACHING_HE
) {
1393 cinode
->oplock
|= CIFS_CACHE_WRITE_FLG
;
1394 strcat(message
, "W");
1396 if (!cinode
->oplock
)
1397 strcat(message
, "None");
1398 cifs_dbg(FYI
, "%s Lease granted on inode %p\n", message
,
1399 &cinode
->vfs_inode
);
1403 smb3_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1404 unsigned int epoch
, bool *purge_cache
)
1406 unsigned int old_oplock
= cinode
->oplock
;
1408 smb21_set_oplock_level(cinode
, oplock
, epoch
, purge_cache
);
1411 *purge_cache
= false;
1412 if (old_oplock
== CIFS_CACHE_READ_FLG
) {
1413 if (cinode
->oplock
== CIFS_CACHE_READ_FLG
&&
1414 (epoch
- cinode
->epoch
> 0))
1415 *purge_cache
= true;
1416 else if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1417 (epoch
- cinode
->epoch
> 1))
1418 *purge_cache
= true;
1419 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1420 (epoch
- cinode
->epoch
> 1))
1421 *purge_cache
= true;
1422 else if (cinode
->oplock
== 0 &&
1423 (epoch
- cinode
->epoch
> 0))
1424 *purge_cache
= true;
1425 } else if (old_oplock
== CIFS_CACHE_RH_FLG
) {
1426 if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1427 (epoch
- cinode
->epoch
> 0))
1428 *purge_cache
= true;
1429 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1430 (epoch
- cinode
->epoch
> 1))
1431 *purge_cache
= true;
1433 cinode
->epoch
= epoch
;
1438 smb2_is_read_op(__u32 oplock
)
1440 return oplock
== SMB2_OPLOCK_LEVEL_II
;
1444 smb21_is_read_op(__u32 oplock
)
1446 return (oplock
& SMB2_LEASE_READ_CACHING_HE
) &&
1447 !(oplock
& SMB2_LEASE_WRITE_CACHING_HE
);
1451 map_oplock_to_lease(u8 oplock
)
1453 if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
)
1454 return SMB2_LEASE_WRITE_CACHING
| SMB2_LEASE_READ_CACHING
;
1455 else if (oplock
== SMB2_OPLOCK_LEVEL_II
)
1456 return SMB2_LEASE_READ_CACHING
;
1457 else if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
)
1458 return SMB2_LEASE_HANDLE_CACHING
| SMB2_LEASE_READ_CACHING
|
1459 SMB2_LEASE_WRITE_CACHING
;
1464 smb2_create_lease_buf(u8
*lease_key
, u8 oplock
)
1466 struct create_lease
*buf
;
1468 buf
= kzalloc(sizeof(struct create_lease
), GFP_KERNEL
);
1472 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1473 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1474 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1476 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1477 (struct create_lease
, lcontext
));
1478 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context
));
1479 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1480 (struct create_lease
, Name
));
1481 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1482 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1491 smb3_create_lease_buf(u8
*lease_key
, u8 oplock
)
1493 struct create_lease_v2
*buf
;
1495 buf
= kzalloc(sizeof(struct create_lease_v2
), GFP_KERNEL
);
1499 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1500 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1501 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1503 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1504 (struct create_lease_v2
, lcontext
));
1505 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context_v2
));
1506 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1507 (struct create_lease_v2
, Name
));
1508 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1509 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1518 smb2_parse_lease_buf(void *buf
, unsigned int *epoch
)
1520 struct create_lease
*lc
= (struct create_lease
*)buf
;
1522 *epoch
= 0; /* not used */
1523 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
1524 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
1525 return le32_to_cpu(lc
->lcontext
.LeaseState
);
1529 smb3_parse_lease_buf(void *buf
, unsigned int *epoch
)
1531 struct create_lease_v2
*lc
= (struct create_lease_v2
*)buf
;
1533 *epoch
= le16_to_cpu(lc
->lcontext
.Epoch
);
1534 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
1535 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
1536 return le32_to_cpu(lc
->lcontext
.LeaseState
);
1540 smb2_wp_retry_size(struct inode
*inode
)
1542 return min_t(unsigned int, CIFS_SB(inode
->i_sb
)->wsize
,
1543 SMB2_MAX_BUFFER_SIZE
);
1547 smb2_dir_needs_close(struct cifsFileInfo
*cfile
)
1549 return !cfile
->invalidHandle
;
1553 fill_transform_hdr(struct smb2_transform_hdr
*tr_hdr
, struct smb_rqst
*old_rq
)
1555 struct smb2_sync_hdr
*shdr
=
1556 (struct smb2_sync_hdr
*)old_rq
->rq_iov
[1].iov_base
;
1557 unsigned int orig_len
= get_rfc1002_length(old_rq
->rq_iov
[0].iov_base
);
1559 memset(tr_hdr
, 0, sizeof(struct smb2_transform_hdr
));
1560 tr_hdr
->ProtocolId
= SMB2_TRANSFORM_PROTO_NUM
;
1561 tr_hdr
->OriginalMessageSize
= cpu_to_le32(orig_len
);
1562 tr_hdr
->Flags
= cpu_to_le16(0x01);
1563 get_random_bytes(&tr_hdr
->Nonce
, SMB3_AES128CMM_NONCE
);
1564 memcpy(&tr_hdr
->SessionId
, &shdr
->SessionId
, 8);
1565 inc_rfc1001_len(tr_hdr
, sizeof(struct smb2_transform_hdr
) - 4);
1566 inc_rfc1001_len(tr_hdr
, orig_len
);
1569 static struct scatterlist
*
1570 init_sg(struct smb_rqst
*rqst
, u8
*sign
)
1572 unsigned int sg_len
= rqst
->rq_nvec
+ rqst
->rq_npages
+ 1;
1573 unsigned int assoc_data_len
= sizeof(struct smb2_transform_hdr
) - 24;
1574 struct scatterlist
*sg
;
1578 sg
= kmalloc_array(sg_len
, sizeof(struct scatterlist
), GFP_KERNEL
);
1582 sg_init_table(sg
, sg_len
);
1583 sg_set_buf(&sg
[0], rqst
->rq_iov
[0].iov_base
+ 24, assoc_data_len
);
1584 for (i
= 1; i
< rqst
->rq_nvec
; i
++)
1585 sg_set_buf(&sg
[i
], rqst
->rq_iov
[i
].iov_base
,
1586 rqst
->rq_iov
[i
].iov_len
);
1587 for (j
= 0; i
< sg_len
- 1; i
++, j
++) {
1588 unsigned int len
= (j
< rqst
->rq_npages
- 1) ? rqst
->rq_pagesz
1590 sg_set_page(&sg
[i
], rqst
->rq_pages
[j
], len
, 0);
1592 sg_set_buf(&sg
[sg_len
- 1], sign
, SMB2_SIGNATURE_SIZE
);
1596 struct cifs_crypt_result
{
1598 struct completion completion
;
1601 static void cifs_crypt_complete(struct crypto_async_request
*req
, int err
)
1603 struct cifs_crypt_result
*res
= req
->data
;
1605 if (err
== -EINPROGRESS
)
1609 complete(&res
->completion
);
1613 * Encrypt or decrypt @rqst message. @rqst has the following format:
1614 * iov[0] - transform header (associate data),
1615 * iov[1-N] and pages - data to encrypt.
1616 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
1620 crypt_message(struct TCP_Server_Info
*server
, struct smb_rqst
*rqst
, int enc
)
1622 struct smb2_transform_hdr
*tr_hdr
=
1623 (struct smb2_transform_hdr
*)rqst
->rq_iov
[0].iov_base
;
1624 unsigned int assoc_data_len
= sizeof(struct smb2_transform_hdr
) - 24;
1625 struct cifs_ses
*ses
;
1627 struct scatterlist
*sg
;
1628 u8 sign
[SMB2_SIGNATURE_SIZE
] = {};
1629 struct aead_request
*req
;
1631 unsigned int iv_len
;
1632 struct cifs_crypt_result result
= {0, };
1633 struct crypto_aead
*tfm
;
1634 unsigned int crypt_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
1636 init_completion(&result
.completion
);
1638 ses
= smb2_find_smb_ses(server
, tr_hdr
->SessionId
);
1640 cifs_dbg(VFS
, "%s: Could not find session\n", __func__
);
1644 rc
= smb3_crypto_aead_allocate(server
);
1646 cifs_dbg(VFS
, "%s: crypto alloc failed\n", __func__
);
1650 tfm
= enc
? server
->secmech
.ccmaesencrypt
:
1651 server
->secmech
.ccmaesdecrypt
;
1652 rc
= crypto_aead_setkey(tfm
, enc
? ses
->smb3encryptionkey
:
1653 ses
->smb3decryptionkey
, SMB3_SIGN_KEY_SIZE
);
1655 cifs_dbg(VFS
, "%s: Failed to set aead key %d\n", __func__
, rc
);
1659 rc
= crypto_aead_setauthsize(tfm
, SMB2_SIGNATURE_SIZE
);
1661 cifs_dbg(VFS
, "%s: Failed to set authsize %d\n", __func__
, rc
);
1665 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
1667 cifs_dbg(VFS
, "%s: Failed to alloc aead request", __func__
);
1672 memcpy(sign
, &tr_hdr
->Signature
, SMB2_SIGNATURE_SIZE
);
1673 crypt_len
+= SMB2_SIGNATURE_SIZE
;
1676 sg
= init_sg(rqst
, sign
);
1678 cifs_dbg(VFS
, "%s: Failed to init sg %d", __func__
, rc
);
1682 iv_len
= crypto_aead_ivsize(tfm
);
1683 iv
= kzalloc(iv_len
, GFP_KERNEL
);
1685 cifs_dbg(VFS
, "%s: Failed to alloc IV", __func__
);
1689 memcpy(iv
+ 1, (char *)tr_hdr
->Nonce
, SMB3_AES128CMM_NONCE
);
1691 aead_request_set_crypt(req
, sg
, sg
, crypt_len
, iv
);
1692 aead_request_set_ad(req
, assoc_data_len
);
1694 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
1695 cifs_crypt_complete
, &result
);
1697 rc
= enc
? crypto_aead_encrypt(req
) : crypto_aead_decrypt(req
);
1699 if (rc
== -EINPROGRESS
|| rc
== -EBUSY
) {
1700 wait_for_completion(&result
.completion
);
1705 memcpy(&tr_hdr
->Signature
, sign
, SMB2_SIGNATURE_SIZE
);
1716 smb3_init_transform_rq(struct TCP_Server_Info
*server
, struct smb_rqst
*new_rq
,
1717 struct smb_rqst
*old_rq
)
1720 struct page
**pages
;
1721 struct smb2_transform_hdr
*tr_hdr
;
1722 unsigned int npages
= old_rq
->rq_npages
;
1726 pages
= kmalloc_array(npages
, sizeof(struct page
*), GFP_KERNEL
);
1730 new_rq
->rq_pages
= pages
;
1731 new_rq
->rq_npages
= old_rq
->rq_npages
;
1732 new_rq
->rq_pagesz
= old_rq
->rq_pagesz
;
1733 new_rq
->rq_tailsz
= old_rq
->rq_tailsz
;
1735 for (i
= 0; i
< npages
; i
++) {
1736 pages
[i
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
1738 goto err_free_pages
;
1741 iov
= kmalloc_array(old_rq
->rq_nvec
, sizeof(struct kvec
), GFP_KERNEL
);
1743 goto err_free_pages
;
1745 /* copy all iovs from the old except the 1st one (rfc1002 length) */
1746 memcpy(&iov
[1], &old_rq
->rq_iov
[1],
1747 sizeof(struct kvec
) * (old_rq
->rq_nvec
- 1));
1748 new_rq
->rq_iov
= iov
;
1749 new_rq
->rq_nvec
= old_rq
->rq_nvec
;
1751 tr_hdr
= kmalloc(sizeof(struct smb2_transform_hdr
), GFP_KERNEL
);
1755 /* fill the 1st iov with a transform header */
1756 fill_transform_hdr(tr_hdr
, old_rq
);
1757 new_rq
->rq_iov
[0].iov_base
= tr_hdr
;
1758 new_rq
->rq_iov
[0].iov_len
= sizeof(struct smb2_transform_hdr
);
1760 /* copy pages form the old */
1761 for (i
= 0; i
< npages
; i
++) {
1762 char *dst
= kmap(new_rq
->rq_pages
[i
]);
1763 char *src
= kmap(old_rq
->rq_pages
[i
]);
1764 unsigned int len
= (i
< npages
- 1) ? new_rq
->rq_pagesz
:
1766 memcpy(dst
, src
, len
);
1767 kunmap(new_rq
->rq_pages
[i
]);
1768 kunmap(old_rq
->rq_pages
[i
]);
1771 rc
= crypt_message(server
, new_rq
, 1);
1772 cifs_dbg(FYI
, "encrypt message returned %d", rc
);
1774 goto err_free_tr_hdr
;
1783 for (i
= i
- 1; i
>= 0; i
--)
1790 smb3_free_transform_rq(struct smb_rqst
*rqst
)
1792 int i
= rqst
->rq_npages
- 1;
1795 put_page(rqst
->rq_pages
[i
]);
1796 kfree(rqst
->rq_pages
);
1797 /* free transform header */
1798 kfree(rqst
->rq_iov
[0].iov_base
);
1799 kfree(rqst
->rq_iov
);
1803 smb3_is_transform_hdr(void *buf
)
1805 struct smb2_transform_hdr
*trhdr
= buf
;
1807 return trhdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
;
1811 decrypt_raw_data(struct TCP_Server_Info
*server
, char *buf
,
1812 unsigned int buf_data_size
, struct page
**pages
,
1813 unsigned int npages
, unsigned int page_data_size
)
1816 struct smb_rqst rqst
= {NULL
};
1817 struct smb2_hdr
*hdr
;
1820 iov
[0].iov_base
= buf
;
1821 iov
[0].iov_len
= sizeof(struct smb2_transform_hdr
);
1822 iov
[1].iov_base
= buf
+ sizeof(struct smb2_transform_hdr
);
1823 iov
[1].iov_len
= buf_data_size
;
1827 rqst
.rq_pages
= pages
;
1828 rqst
.rq_npages
= npages
;
1829 rqst
.rq_pagesz
= PAGE_SIZE
;
1830 rqst
.rq_tailsz
= (page_data_size
% PAGE_SIZE
) ? : PAGE_SIZE
;
1832 rc
= crypt_message(server
, &rqst
, 0);
1833 cifs_dbg(FYI
, "decrypt message returned %d\n", rc
);
1838 memmove(buf
+ 4, iov
[1].iov_base
, buf_data_size
);
1839 hdr
= (struct smb2_hdr
*)buf
;
1840 hdr
->smb2_buf_length
= cpu_to_be32(buf_data_size
+ page_data_size
);
1841 server
->total_read
= buf_data_size
+ page_data_size
+ 4;
1847 read_data_into_pages(struct TCP_Server_Info
*server
, struct page
**pages
,
1848 unsigned int npages
, unsigned int len
)
1853 for (i
= 0; i
< npages
; i
++) {
1854 struct page
*page
= pages
[i
];
1858 if (len
>= PAGE_SIZE
) {
1859 /* enough data to fill the page */
1863 zero_user(page
, len
, PAGE_SIZE
- len
);
1866 length
= cifs_read_page_from_socket(server
, page
, n
);
1869 server
->total_read
+= length
;
1876 init_read_bvec(struct page
**pages
, unsigned int npages
, unsigned int data_size
,
1877 unsigned int cur_off
, struct bio_vec
**page_vec
)
1879 struct bio_vec
*bvec
;
1882 bvec
= kcalloc(npages
, sizeof(struct bio_vec
), GFP_KERNEL
);
1886 for (i
= 0; i
< npages
; i
++) {
1887 bvec
[i
].bv_page
= pages
[i
];
1888 bvec
[i
].bv_offset
= (i
== 0) ? cur_off
: 0;
1889 bvec
[i
].bv_len
= min_t(unsigned int, PAGE_SIZE
, data_size
);
1890 data_size
-= bvec
[i
].bv_len
;
1893 if (data_size
!= 0) {
1894 cifs_dbg(VFS
, "%s: something went wrong\n", __func__
);
1904 handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
,
1905 char *buf
, unsigned int buf_len
, struct page
**pages
,
1906 unsigned int npages
, unsigned int page_data_size
)
1908 unsigned int data_offset
;
1909 unsigned int data_len
;
1910 unsigned int cur_off
;
1911 unsigned int cur_page_idx
;
1912 unsigned int pad_len
;
1913 struct cifs_readdata
*rdata
= mid
->callback_data
;
1914 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
1915 struct bio_vec
*bvec
= NULL
;
1916 struct iov_iter iter
;
1920 if (shdr
->Command
!= SMB2_READ
) {
1921 cifs_dbg(VFS
, "only big read responses are supported\n");
1925 if (server
->ops
->is_status_pending
&&
1926 server
->ops
->is_status_pending(buf
, server
, 0))
1929 rdata
->result
= server
->ops
->map_error(buf
, false);
1930 if (rdata
->result
!= 0) {
1931 cifs_dbg(FYI
, "%s: server returned error %d\n",
1932 __func__
, rdata
->result
);
1933 dequeue_mid(mid
, rdata
->result
);
1937 data_offset
= server
->ops
->read_data_offset(buf
) + 4;
1938 data_len
= server
->ops
->read_data_length(buf
);
1940 if (data_offset
< server
->vals
->read_rsp_size
) {
1942 * win2k8 sometimes sends an offset of 0 when the read
1943 * is beyond the EOF. Treat it as if the data starts just after
1946 cifs_dbg(FYI
, "%s: data offset (%u) inside read response header\n",
1947 __func__
, data_offset
);
1948 data_offset
= server
->vals
->read_rsp_size
;
1949 } else if (data_offset
> MAX_CIFS_SMALL_BUFFER_SIZE
) {
1950 /* data_offset is beyond the end of smallbuf */
1951 cifs_dbg(FYI
, "%s: data offset (%u) beyond end of smallbuf\n",
1952 __func__
, data_offset
);
1953 rdata
->result
= -EIO
;
1954 dequeue_mid(mid
, rdata
->result
);
1958 pad_len
= data_offset
- server
->vals
->read_rsp_size
;
1960 if (buf_len
<= data_offset
) {
1961 /* read response payload is in pages */
1962 cur_page_idx
= pad_len
/ PAGE_SIZE
;
1963 cur_off
= pad_len
% PAGE_SIZE
;
1965 if (cur_page_idx
!= 0) {
1966 /* data offset is beyond the 1st page of response */
1967 cifs_dbg(FYI
, "%s: data offset (%u) beyond 1st page of response\n",
1968 __func__
, data_offset
);
1969 rdata
->result
= -EIO
;
1970 dequeue_mid(mid
, rdata
->result
);
1974 if (data_len
> page_data_size
- pad_len
) {
1975 /* data_len is corrupt -- discard frame */
1976 rdata
->result
= -EIO
;
1977 dequeue_mid(mid
, rdata
->result
);
1981 rdata
->result
= init_read_bvec(pages
, npages
, page_data_size
,
1983 if (rdata
->result
!= 0) {
1984 dequeue_mid(mid
, rdata
->result
);
1988 iov_iter_bvec(&iter
, WRITE
| ITER_BVEC
, bvec
, npages
, data_len
);
1989 } else if (buf_len
>= data_offset
+ data_len
) {
1990 /* read response payload is in buf */
1991 WARN_ONCE(npages
> 0, "read data can be either in buf or in pages");
1992 iov
.iov_base
= buf
+ data_offset
;
1993 iov
.iov_len
= data_len
;
1994 iov_iter_kvec(&iter
, WRITE
| ITER_KVEC
, &iov
, 1, data_len
);
1996 /* read response payload cannot be in both buf and pages */
1997 WARN_ONCE(1, "buf can not contain only a part of read data");
1998 rdata
->result
= -EIO
;
1999 dequeue_mid(mid
, rdata
->result
);
2003 /* set up first iov for signature check */
2004 rdata
->iov
[0].iov_base
= buf
;
2005 rdata
->iov
[0].iov_len
= 4;
2006 rdata
->iov
[1].iov_base
= buf
+ 4;
2007 rdata
->iov
[1].iov_len
= server
->vals
->read_rsp_size
- 4;
2008 cifs_dbg(FYI
, "0: iov_base=%p iov_len=%zu\n",
2009 rdata
->iov
[0].iov_base
, server
->vals
->read_rsp_size
);
2011 length
= rdata
->copy_into_pages(server
, rdata
, &iter
);
2018 dequeue_mid(mid
, false);
2023 receive_encrypted_read(struct TCP_Server_Info
*server
, struct mid_q_entry
**mid
)
2025 char *buf
= server
->smallbuf
;
2026 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
2027 unsigned int npages
;
2028 struct page
**pages
;
2030 unsigned int buflen
= get_rfc1002_length(buf
) + 4;
2034 len
= min_t(unsigned int, buflen
, server
->vals
->read_rsp_size
- 4 +
2035 sizeof(struct smb2_transform_hdr
)) - HEADER_SIZE(server
) + 1;
2037 rc
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1, len
);
2040 server
->total_read
+= rc
;
2042 len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
) + 4 -
2043 server
->vals
->read_rsp_size
;
2044 npages
= DIV_ROUND_UP(len
, PAGE_SIZE
);
2046 pages
= kmalloc_array(npages
, sizeof(struct page
*), GFP_KERNEL
);
2052 for (; i
< npages
; i
++) {
2053 pages
[i
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
2060 /* read read data into pages */
2061 rc
= read_data_into_pages(server
, pages
, npages
, len
);
2065 rc
= cifs_discard_remaining_data(server
);
2069 rc
= decrypt_raw_data(server
, buf
, server
->vals
->read_rsp_size
- 4,
2070 pages
, npages
, len
);
2074 *mid
= smb2_find_mid(server
, buf
);
2076 cifs_dbg(FYI
, "mid not found\n");
2078 cifs_dbg(FYI
, "mid found\n");
2079 (*mid
)->decrypted
= true;
2080 rc
= handle_read_data(server
, *mid
, buf
,
2081 server
->vals
->read_rsp_size
,
2082 pages
, npages
, len
);
2086 for (i
= i
- 1; i
>= 0; i
--)
2091 cifs_discard_remaining_data(server
);
2096 receive_encrypted_standard(struct TCP_Server_Info
*server
,
2097 struct mid_q_entry
**mid
)
2100 char *buf
= server
->smallbuf
;
2101 unsigned int pdu_length
= get_rfc1002_length(buf
);
2102 unsigned int buf_size
;
2103 struct mid_q_entry
*mid_entry
;
2105 /* switch to large buffer if too big for a small one */
2106 if (pdu_length
+ 4 > MAX_CIFS_SMALL_BUFFER_SIZE
) {
2107 server
->large_buf
= true;
2108 memcpy(server
->bigbuf
, buf
, server
->total_read
);
2109 buf
= server
->bigbuf
;
2112 /* now read the rest */
2113 length
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1,
2114 pdu_length
- HEADER_SIZE(server
) + 1 + 4);
2117 server
->total_read
+= length
;
2119 buf_size
= pdu_length
+ 4 - sizeof(struct smb2_transform_hdr
);
2120 length
= decrypt_raw_data(server
, buf
, buf_size
, NULL
, 0, 0);
2124 mid_entry
= smb2_find_mid(server
, buf
);
2125 if (mid_entry
== NULL
)
2126 cifs_dbg(FYI
, "mid not found\n");
2128 cifs_dbg(FYI
, "mid found\n");
2129 mid_entry
->decrypted
= true;
2134 if (mid_entry
&& mid_entry
->handle
)
2135 return mid_entry
->handle(server
, mid_entry
);
2137 return cifs_handle_standard(server
, mid_entry
);
2141 smb3_receive_transform(struct TCP_Server_Info
*server
, struct mid_q_entry
**mid
)
2143 char *buf
= server
->smallbuf
;
2144 unsigned int pdu_length
= get_rfc1002_length(buf
);
2145 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
2146 unsigned int orig_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
2148 if (pdu_length
+ 4 < sizeof(struct smb2_transform_hdr
) +
2149 sizeof(struct smb2_sync_hdr
)) {
2150 cifs_dbg(VFS
, "Transform message is too small (%u)\n",
2152 cifs_reconnect(server
);
2153 wake_up(&server
->response_q
);
2154 return -ECONNABORTED
;
2157 if (pdu_length
+ 4 < orig_len
+ sizeof(struct smb2_transform_hdr
)) {
2158 cifs_dbg(VFS
, "Transform message is broken\n");
2159 cifs_reconnect(server
);
2160 wake_up(&server
->response_q
);
2161 return -ECONNABORTED
;
2164 if (pdu_length
+ 4 > CIFSMaxBufSize
+ MAX_HEADER_SIZE(server
))
2165 return receive_encrypted_read(server
, mid
);
2167 return receive_encrypted_standard(server
, mid
);
2171 smb3_handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
)
2173 char *buf
= server
->large_buf
? server
->bigbuf
: server
->smallbuf
;
2175 return handle_read_data(server
, mid
, buf
, get_rfc1002_length(buf
) + 4,
2179 struct smb_version_operations smb20_operations
= {
2180 .compare_fids
= smb2_compare_fids
,
2181 .setup_request
= smb2_setup_request
,
2182 .setup_async_request
= smb2_setup_async_request
,
2183 .check_receive
= smb2_check_receive
,
2184 .add_credits
= smb2_add_credits
,
2185 .set_credits
= smb2_set_credits
,
2186 .get_credits_field
= smb2_get_credits_field
,
2187 .get_credits
= smb2_get_credits
,
2188 .wait_mtu_credits
= cifs_wait_mtu_credits
,
2189 .get_next_mid
= smb2_get_next_mid
,
2190 .read_data_offset
= smb2_read_data_offset
,
2191 .read_data_length
= smb2_read_data_length
,
2192 .map_error
= map_smb2_to_linux_error
,
2193 .find_mid
= smb2_find_mid
,
2194 .check_message
= smb2_check_message
,
2195 .dump_detail
= smb2_dump_detail
,
2196 .clear_stats
= smb2_clear_stats
,
2197 .print_stats
= smb2_print_stats
,
2198 .is_oplock_break
= smb2_is_valid_oplock_break
,
2199 .downgrade_oplock
= smb2_downgrade_oplock
,
2200 .need_neg
= smb2_need_neg
,
2201 .negotiate
= smb2_negotiate
,
2202 .negotiate_wsize
= smb2_negotiate_wsize
,
2203 .negotiate_rsize
= smb2_negotiate_rsize
,
2204 .sess_setup
= SMB2_sess_setup
,
2205 .logoff
= SMB2_logoff
,
2206 .tree_connect
= SMB2_tcon
,
2207 .tree_disconnect
= SMB2_tdis
,
2208 .qfs_tcon
= smb2_qfs_tcon
,
2209 .is_path_accessible
= smb2_is_path_accessible
,
2210 .can_echo
= smb2_can_echo
,
2212 .query_path_info
= smb2_query_path_info
,
2213 .get_srv_inum
= smb2_get_srv_inum
,
2214 .query_file_info
= smb2_query_file_info
,
2215 .set_path_size
= smb2_set_path_size
,
2216 .set_file_size
= smb2_set_file_size
,
2217 .set_file_info
= smb2_set_file_info
,
2218 .set_compression
= smb2_set_compression
,
2219 .mkdir
= smb2_mkdir
,
2220 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2221 .rmdir
= smb2_rmdir
,
2222 .unlink
= smb2_unlink
,
2223 .rename
= smb2_rename_path
,
2224 .create_hardlink
= smb2_create_hardlink
,
2225 .query_symlink
= smb2_query_symlink
,
2226 .query_mf_symlink
= smb3_query_mf_symlink
,
2227 .create_mf_symlink
= smb3_create_mf_symlink
,
2228 .open
= smb2_open_file
,
2229 .set_fid
= smb2_set_fid
,
2230 .close
= smb2_close_file
,
2231 .flush
= smb2_flush_file
,
2232 .async_readv
= smb2_async_readv
,
2233 .async_writev
= smb2_async_writev
,
2234 .sync_read
= smb2_sync_read
,
2235 .sync_write
= smb2_sync_write
,
2236 .query_dir_first
= smb2_query_dir_first
,
2237 .query_dir_next
= smb2_query_dir_next
,
2238 .close_dir
= smb2_close_dir
,
2239 .calc_smb_size
= smb2_calc_size
,
2240 .is_status_pending
= smb2_is_status_pending
,
2241 .oplock_response
= smb2_oplock_response
,
2242 .queryfs
= smb2_queryfs
,
2243 .mand_lock
= smb2_mand_lock
,
2244 .mand_unlock_range
= smb2_unlock_range
,
2245 .push_mand_locks
= smb2_push_mandatory_locks
,
2246 .get_lease_key
= smb2_get_lease_key
,
2247 .set_lease_key
= smb2_set_lease_key
,
2248 .new_lease_key
= smb2_new_lease_key
,
2249 .calc_signature
= smb2_calc_signature
,
2250 .is_read_op
= smb2_is_read_op
,
2251 .set_oplock_level
= smb2_set_oplock_level
,
2252 .create_lease_buf
= smb2_create_lease_buf
,
2253 .parse_lease_buf
= smb2_parse_lease_buf
,
2254 .clone_range
= smb2_clone_range
,
2255 .wp_retry_size
= smb2_wp_retry_size
,
2256 .dir_needs_close
= smb2_dir_needs_close
,
2259 struct smb_version_operations smb21_operations
= {
2260 .compare_fids
= smb2_compare_fids
,
2261 .setup_request
= smb2_setup_request
,
2262 .setup_async_request
= smb2_setup_async_request
,
2263 .check_receive
= smb2_check_receive
,
2264 .add_credits
= smb2_add_credits
,
2265 .set_credits
= smb2_set_credits
,
2266 .get_credits_field
= smb2_get_credits_field
,
2267 .get_credits
= smb2_get_credits
,
2268 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2269 .get_next_mid
= smb2_get_next_mid
,
2270 .read_data_offset
= smb2_read_data_offset
,
2271 .read_data_length
= smb2_read_data_length
,
2272 .map_error
= map_smb2_to_linux_error
,
2273 .find_mid
= smb2_find_mid
,
2274 .check_message
= smb2_check_message
,
2275 .dump_detail
= smb2_dump_detail
,
2276 .clear_stats
= smb2_clear_stats
,
2277 .print_stats
= smb2_print_stats
,
2278 .is_oplock_break
= smb2_is_valid_oplock_break
,
2279 .downgrade_oplock
= smb2_downgrade_oplock
,
2280 .need_neg
= smb2_need_neg
,
2281 .negotiate
= smb2_negotiate
,
2282 .negotiate_wsize
= smb2_negotiate_wsize
,
2283 .negotiate_rsize
= smb2_negotiate_rsize
,
2284 .sess_setup
= SMB2_sess_setup
,
2285 .logoff
= SMB2_logoff
,
2286 .tree_connect
= SMB2_tcon
,
2287 .tree_disconnect
= SMB2_tdis
,
2288 .qfs_tcon
= smb2_qfs_tcon
,
2289 .is_path_accessible
= smb2_is_path_accessible
,
2290 .can_echo
= smb2_can_echo
,
2292 .query_path_info
= smb2_query_path_info
,
2293 .get_srv_inum
= smb2_get_srv_inum
,
2294 .query_file_info
= smb2_query_file_info
,
2295 .set_path_size
= smb2_set_path_size
,
2296 .set_file_size
= smb2_set_file_size
,
2297 .set_file_info
= smb2_set_file_info
,
2298 .set_compression
= smb2_set_compression
,
2299 .mkdir
= smb2_mkdir
,
2300 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2301 .rmdir
= smb2_rmdir
,
2302 .unlink
= smb2_unlink
,
2303 .rename
= smb2_rename_path
,
2304 .create_hardlink
= smb2_create_hardlink
,
2305 .query_symlink
= smb2_query_symlink
,
2306 .query_mf_symlink
= smb3_query_mf_symlink
,
2307 .create_mf_symlink
= smb3_create_mf_symlink
,
2308 .open
= smb2_open_file
,
2309 .set_fid
= smb2_set_fid
,
2310 .close
= smb2_close_file
,
2311 .flush
= smb2_flush_file
,
2312 .async_readv
= smb2_async_readv
,
2313 .async_writev
= smb2_async_writev
,
2314 .sync_read
= smb2_sync_read
,
2315 .sync_write
= smb2_sync_write
,
2316 .query_dir_first
= smb2_query_dir_first
,
2317 .query_dir_next
= smb2_query_dir_next
,
2318 .close_dir
= smb2_close_dir
,
2319 .calc_smb_size
= smb2_calc_size
,
2320 .is_status_pending
= smb2_is_status_pending
,
2321 .oplock_response
= smb2_oplock_response
,
2322 .queryfs
= smb2_queryfs
,
2323 .mand_lock
= smb2_mand_lock
,
2324 .mand_unlock_range
= smb2_unlock_range
,
2325 .push_mand_locks
= smb2_push_mandatory_locks
,
2326 .get_lease_key
= smb2_get_lease_key
,
2327 .set_lease_key
= smb2_set_lease_key
,
2328 .new_lease_key
= smb2_new_lease_key
,
2329 .calc_signature
= smb2_calc_signature
,
2330 .is_read_op
= smb21_is_read_op
,
2331 .set_oplock_level
= smb21_set_oplock_level
,
2332 .create_lease_buf
= smb2_create_lease_buf
,
2333 .parse_lease_buf
= smb2_parse_lease_buf
,
2334 .clone_range
= smb2_clone_range
,
2335 .wp_retry_size
= smb2_wp_retry_size
,
2336 .dir_needs_close
= smb2_dir_needs_close
,
2337 .enum_snapshots
= smb3_enum_snapshots
,
2340 struct smb_version_operations smb30_operations
= {
2341 .compare_fids
= smb2_compare_fids
,
2342 .setup_request
= smb2_setup_request
,
2343 .setup_async_request
= smb2_setup_async_request
,
2344 .check_receive
= smb2_check_receive
,
2345 .add_credits
= smb2_add_credits
,
2346 .set_credits
= smb2_set_credits
,
2347 .get_credits_field
= smb2_get_credits_field
,
2348 .get_credits
= smb2_get_credits
,
2349 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2350 .get_next_mid
= smb2_get_next_mid
,
2351 .read_data_offset
= smb2_read_data_offset
,
2352 .read_data_length
= smb2_read_data_length
,
2353 .map_error
= map_smb2_to_linux_error
,
2354 .find_mid
= smb2_find_mid
,
2355 .check_message
= smb2_check_message
,
2356 .dump_detail
= smb2_dump_detail
,
2357 .clear_stats
= smb2_clear_stats
,
2358 .print_stats
= smb2_print_stats
,
2359 .dump_share_caps
= smb2_dump_share_caps
,
2360 .is_oplock_break
= smb2_is_valid_oplock_break
,
2361 .downgrade_oplock
= smb2_downgrade_oplock
,
2362 .need_neg
= smb2_need_neg
,
2363 .negotiate
= smb2_negotiate
,
2364 .negotiate_wsize
= smb2_negotiate_wsize
,
2365 .negotiate_rsize
= smb2_negotiate_rsize
,
2366 .sess_setup
= SMB2_sess_setup
,
2367 .logoff
= SMB2_logoff
,
2368 .tree_connect
= SMB2_tcon
,
2369 .tree_disconnect
= SMB2_tdis
,
2370 .qfs_tcon
= smb3_qfs_tcon
,
2371 .is_path_accessible
= smb2_is_path_accessible
,
2372 .can_echo
= smb2_can_echo
,
2374 .query_path_info
= smb2_query_path_info
,
2375 .get_srv_inum
= smb2_get_srv_inum
,
2376 .query_file_info
= smb2_query_file_info
,
2377 .set_path_size
= smb2_set_path_size
,
2378 .set_file_size
= smb2_set_file_size
,
2379 .set_file_info
= smb2_set_file_info
,
2380 .set_compression
= smb2_set_compression
,
2381 .mkdir
= smb2_mkdir
,
2382 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2383 .rmdir
= smb2_rmdir
,
2384 .unlink
= smb2_unlink
,
2385 .rename
= smb2_rename_path
,
2386 .create_hardlink
= smb2_create_hardlink
,
2387 .query_symlink
= smb2_query_symlink
,
2388 .query_mf_symlink
= smb3_query_mf_symlink
,
2389 .create_mf_symlink
= smb3_create_mf_symlink
,
2390 .open
= smb2_open_file
,
2391 .set_fid
= smb2_set_fid
,
2392 .close
= smb2_close_file
,
2393 .flush
= smb2_flush_file
,
2394 .async_readv
= smb2_async_readv
,
2395 .async_writev
= smb2_async_writev
,
2396 .sync_read
= smb2_sync_read
,
2397 .sync_write
= smb2_sync_write
,
2398 .query_dir_first
= smb2_query_dir_first
,
2399 .query_dir_next
= smb2_query_dir_next
,
2400 .close_dir
= smb2_close_dir
,
2401 .calc_smb_size
= smb2_calc_size
,
2402 .is_status_pending
= smb2_is_status_pending
,
2403 .oplock_response
= smb2_oplock_response
,
2404 .queryfs
= smb2_queryfs
,
2405 .mand_lock
= smb2_mand_lock
,
2406 .mand_unlock_range
= smb2_unlock_range
,
2407 .push_mand_locks
= smb2_push_mandatory_locks
,
2408 .get_lease_key
= smb2_get_lease_key
,
2409 .set_lease_key
= smb2_set_lease_key
,
2410 .new_lease_key
= smb2_new_lease_key
,
2411 .generate_signingkey
= generate_smb30signingkey
,
2412 .calc_signature
= smb3_calc_signature
,
2413 .set_integrity
= smb3_set_integrity
,
2414 .is_read_op
= smb21_is_read_op
,
2415 .set_oplock_level
= smb3_set_oplock_level
,
2416 .create_lease_buf
= smb3_create_lease_buf
,
2417 .parse_lease_buf
= smb3_parse_lease_buf
,
2418 .clone_range
= smb2_clone_range
,
2419 .duplicate_extents
= smb2_duplicate_extents
,
2420 .validate_negotiate
= smb3_validate_negotiate
,
2421 .wp_retry_size
= smb2_wp_retry_size
,
2422 .dir_needs_close
= smb2_dir_needs_close
,
2423 .fallocate
= smb3_fallocate
,
2424 .enum_snapshots
= smb3_enum_snapshots
,
2425 .init_transform_rq
= smb3_init_transform_rq
,
2426 .free_transform_rq
= smb3_free_transform_rq
,
2427 .is_transform_hdr
= smb3_is_transform_hdr
,
2428 .receive_transform
= smb3_receive_transform
,
2431 #ifdef CONFIG_CIFS_SMB311
2432 struct smb_version_operations smb311_operations
= {
2433 .compare_fids
= smb2_compare_fids
,
2434 .setup_request
= smb2_setup_request
,
2435 .setup_async_request
= smb2_setup_async_request
,
2436 .check_receive
= smb2_check_receive
,
2437 .add_credits
= smb2_add_credits
,
2438 .set_credits
= smb2_set_credits
,
2439 .get_credits_field
= smb2_get_credits_field
,
2440 .get_credits
= smb2_get_credits
,
2441 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2442 .get_next_mid
= smb2_get_next_mid
,
2443 .read_data_offset
= smb2_read_data_offset
,
2444 .read_data_length
= smb2_read_data_length
,
2445 .map_error
= map_smb2_to_linux_error
,
2446 .find_mid
= smb2_find_mid
,
2447 .check_message
= smb2_check_message
,
2448 .dump_detail
= smb2_dump_detail
,
2449 .clear_stats
= smb2_clear_stats
,
2450 .print_stats
= smb2_print_stats
,
2451 .dump_share_caps
= smb2_dump_share_caps
,
2452 .is_oplock_break
= smb2_is_valid_oplock_break
,
2453 .downgrade_oplock
= smb2_downgrade_oplock
,
2454 .need_neg
= smb2_need_neg
,
2455 .negotiate
= smb2_negotiate
,
2456 .negotiate_wsize
= smb2_negotiate_wsize
,
2457 .negotiate_rsize
= smb2_negotiate_rsize
,
2458 .sess_setup
= SMB2_sess_setup
,
2459 .logoff
= SMB2_logoff
,
2460 .tree_connect
= SMB2_tcon
,
2461 .tree_disconnect
= SMB2_tdis
,
2462 .qfs_tcon
= smb3_qfs_tcon
,
2463 .is_path_accessible
= smb2_is_path_accessible
,
2464 .can_echo
= smb2_can_echo
,
2466 .query_path_info
= smb2_query_path_info
,
2467 .get_srv_inum
= smb2_get_srv_inum
,
2468 .query_file_info
= smb2_query_file_info
,
2469 .set_path_size
= smb2_set_path_size
,
2470 .set_file_size
= smb2_set_file_size
,
2471 .set_file_info
= smb2_set_file_info
,
2472 .set_compression
= smb2_set_compression
,
2473 .mkdir
= smb2_mkdir
,
2474 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2475 .rmdir
= smb2_rmdir
,
2476 .unlink
= smb2_unlink
,
2477 .rename
= smb2_rename_path
,
2478 .create_hardlink
= smb2_create_hardlink
,
2479 .query_symlink
= smb2_query_symlink
,
2480 .query_mf_symlink
= smb3_query_mf_symlink
,
2481 .create_mf_symlink
= smb3_create_mf_symlink
,
2482 .open
= smb2_open_file
,
2483 .set_fid
= smb2_set_fid
,
2484 .close
= smb2_close_file
,
2485 .flush
= smb2_flush_file
,
2486 .async_readv
= smb2_async_readv
,
2487 .async_writev
= smb2_async_writev
,
2488 .sync_read
= smb2_sync_read
,
2489 .sync_write
= smb2_sync_write
,
2490 .query_dir_first
= smb2_query_dir_first
,
2491 .query_dir_next
= smb2_query_dir_next
,
2492 .close_dir
= smb2_close_dir
,
2493 .calc_smb_size
= smb2_calc_size
,
2494 .is_status_pending
= smb2_is_status_pending
,
2495 .oplock_response
= smb2_oplock_response
,
2496 .queryfs
= smb2_queryfs
,
2497 .mand_lock
= smb2_mand_lock
,
2498 .mand_unlock_range
= smb2_unlock_range
,
2499 .push_mand_locks
= smb2_push_mandatory_locks
,
2500 .get_lease_key
= smb2_get_lease_key
,
2501 .set_lease_key
= smb2_set_lease_key
,
2502 .new_lease_key
= smb2_new_lease_key
,
2503 .generate_signingkey
= generate_smb311signingkey
,
2504 .calc_signature
= smb3_calc_signature
,
2505 .set_integrity
= smb3_set_integrity
,
2506 .is_read_op
= smb21_is_read_op
,
2507 .set_oplock_level
= smb3_set_oplock_level
,
2508 .create_lease_buf
= smb3_create_lease_buf
,
2509 .parse_lease_buf
= smb3_parse_lease_buf
,
2510 .clone_range
= smb2_clone_range
,
2511 .duplicate_extents
= smb2_duplicate_extents
,
2512 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
2513 .wp_retry_size
= smb2_wp_retry_size
,
2514 .dir_needs_close
= smb2_dir_needs_close
,
2515 .fallocate
= smb3_fallocate
,
2516 .enum_snapshots
= smb3_enum_snapshots
,
2517 .init_transform_rq
= smb3_init_transform_rq
,
2518 .free_transform_rq
= smb3_free_transform_rq
,
2519 .is_transform_hdr
= smb3_is_transform_hdr
,
2520 .receive_transform
= smb3_receive_transform
,
2522 #endif /* CIFS_SMB311 */
2524 struct smb_version_values smb20_values
= {
2525 .version_string
= SMB20_VERSION_STRING
,
2526 .protocol_id
= SMB20_PROT_ID
,
2527 .req_capabilities
= 0, /* MBZ */
2528 .large_lock_type
= 0,
2529 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2530 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2531 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2532 .header_size
= sizeof(struct smb2_hdr
),
2533 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2534 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2535 .lock_cmd
= SMB2_LOCK
,
2537 .cap_nt_find
= SMB2_NT_FIND
,
2538 .cap_large_files
= SMB2_LARGE_FILES
,
2539 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2540 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2541 .create_lease_size
= sizeof(struct create_lease
),
2544 struct smb_version_values smb21_values
= {
2545 .version_string
= SMB21_VERSION_STRING
,
2546 .protocol_id
= SMB21_PROT_ID
,
2547 .req_capabilities
= 0, /* MBZ on negotiate req until SMB3 dialect */
2548 .large_lock_type
= 0,
2549 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2550 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2551 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2552 .header_size
= sizeof(struct smb2_hdr
),
2553 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2554 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2555 .lock_cmd
= SMB2_LOCK
,
2557 .cap_nt_find
= SMB2_NT_FIND
,
2558 .cap_large_files
= SMB2_LARGE_FILES
,
2559 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2560 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2561 .create_lease_size
= sizeof(struct create_lease
),
2564 struct smb_version_values smb30_values
= {
2565 .version_string
= SMB30_VERSION_STRING
,
2566 .protocol_id
= SMB30_PROT_ID
,
2567 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
2568 .large_lock_type
= 0,
2569 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2570 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2571 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2572 .header_size
= sizeof(struct smb2_hdr
),
2573 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2574 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2575 .lock_cmd
= SMB2_LOCK
,
2577 .cap_nt_find
= SMB2_NT_FIND
,
2578 .cap_large_files
= SMB2_LARGE_FILES
,
2579 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2580 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2581 .create_lease_size
= sizeof(struct create_lease_v2
),
2584 struct smb_version_values smb302_values
= {
2585 .version_string
= SMB302_VERSION_STRING
,
2586 .protocol_id
= SMB302_PROT_ID
,
2587 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
2588 .large_lock_type
= 0,
2589 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2590 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2591 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2592 .header_size
= sizeof(struct smb2_hdr
),
2593 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2594 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2595 .lock_cmd
= SMB2_LOCK
,
2597 .cap_nt_find
= SMB2_NT_FIND
,
2598 .cap_large_files
= SMB2_LARGE_FILES
,
2599 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2600 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2601 .create_lease_size
= sizeof(struct create_lease_v2
),
2604 #ifdef CONFIG_CIFS_SMB311
2605 struct smb_version_values smb311_values
= {
2606 .version_string
= SMB311_VERSION_STRING
,
2607 .protocol_id
= SMB311_PROT_ID
,
2608 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
,
2609 .large_lock_type
= 0,
2610 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2611 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2612 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2613 .header_size
= sizeof(struct smb2_hdr
),
2614 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2615 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2616 .lock_cmd
= SMB2_LOCK
,
2618 .cap_nt_find
= SMB2_NT_FIND
,
2619 .cap_large_files
= SMB2_LARGE_FILES
,
2620 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2621 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2622 .create_lease_size
= sizeof(struct create_lease_v2
),