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 */,
286 NULL
/* no data input */, 0 /* no data input */,
287 (char **)&out_buf
, &ret_data_len
);
289 cifs_dbg(VFS
, "error %d on ioctl to get interface list\n", rc
);
290 else if (ret_data_len
< sizeof(struct network_interface_info_ioctl_rsp
)) {
291 cifs_dbg(VFS
, "server returned bad net interface info buf\n");
294 /* Dump info on first interface */
295 cifs_dbg(FYI
, "Adapter Capability 0x%x\t",
296 le32_to_cpu(out_buf
->Capability
));
297 cifs_dbg(FYI
, "Link Speed %lld\n",
298 le64_to_cpu(out_buf
->LinkSpeed
));
306 smb3_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
309 __le16 srch_path
= 0; /* Null - open root of share */
310 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
311 struct cifs_open_parms oparms
;
315 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
316 oparms
.disposition
= FILE_OPEN
;
317 oparms
.create_options
= 0;
319 oparms
.reconnect
= false;
321 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
325 #ifdef CONFIG_CIFS_STATS2
326 SMB3_request_interfaces(xid
, tcon
);
329 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
330 FS_ATTRIBUTE_INFORMATION
);
331 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
332 FS_DEVICE_INFORMATION
);
333 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
334 FS_SECTOR_SIZE_INFORMATION
); /* SMB3 specific */
335 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
340 smb2_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
343 __le16 srch_path
= 0; /* Null - open root of share */
344 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
345 struct cifs_open_parms oparms
;
349 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
350 oparms
.disposition
= FILE_OPEN
;
351 oparms
.create_options
= 0;
353 oparms
.reconnect
= false;
355 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
359 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
360 FS_ATTRIBUTE_INFORMATION
);
361 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
362 FS_DEVICE_INFORMATION
);
363 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
368 smb2_is_path_accessible(const unsigned int xid
, struct cifs_tcon
*tcon
,
369 struct cifs_sb_info
*cifs_sb
, const char *full_path
)
373 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
374 struct cifs_open_parms oparms
;
377 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
382 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
383 oparms
.disposition
= FILE_OPEN
;
384 oparms
.create_options
= 0;
386 oparms
.reconnect
= false;
388 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
394 rc
= SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
400 smb2_get_srv_inum(const unsigned int xid
, struct cifs_tcon
*tcon
,
401 struct cifs_sb_info
*cifs_sb
, const char *full_path
,
402 u64
*uniqueid
, FILE_ALL_INFO
*data
)
404 *uniqueid
= le64_to_cpu(data
->IndexNumber
);
409 smb2_query_file_info(const unsigned int xid
, struct cifs_tcon
*tcon
,
410 struct cifs_fid
*fid
, FILE_ALL_INFO
*data
)
413 struct smb2_file_all_info
*smb2_data
;
415 smb2_data
= kzalloc(sizeof(struct smb2_file_all_info
) + PATH_MAX
* 2,
417 if (smb2_data
== NULL
)
420 rc
= SMB2_query_info(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
,
423 move_smb2_info_to_cifs(data
, smb2_data
);
429 smb2_can_echo(struct TCP_Server_Info
*server
)
431 return server
->echoes
;
435 smb2_clear_stats(struct cifs_tcon
*tcon
)
437 #ifdef CONFIG_CIFS_STATS
439 for (i
= 0; i
< NUMBER_OF_SMB2_COMMANDS
; i
++) {
440 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_sent
[i
], 0);
441 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_failed
[i
], 0);
447 smb2_dump_share_caps(struct seq_file
*m
, struct cifs_tcon
*tcon
)
449 seq_puts(m
, "\n\tShare Capabilities:");
450 if (tcon
->capabilities
& SMB2_SHARE_CAP_DFS
)
451 seq_puts(m
, " DFS,");
452 if (tcon
->capabilities
& SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY
)
453 seq_puts(m
, " CONTINUOUS AVAILABILITY,");
454 if (tcon
->capabilities
& SMB2_SHARE_CAP_SCALEOUT
)
455 seq_puts(m
, " SCALEOUT,");
456 if (tcon
->capabilities
& SMB2_SHARE_CAP_CLUSTER
)
457 seq_puts(m
, " CLUSTER,");
458 if (tcon
->capabilities
& SMB2_SHARE_CAP_ASYMMETRIC
)
459 seq_puts(m
, " ASYMMETRIC,");
460 if (tcon
->capabilities
== 0)
461 seq_puts(m
, " None");
462 if (tcon
->ss_flags
& SSINFO_FLAGS_ALIGNED_DEVICE
)
463 seq_puts(m
, " Aligned,");
464 if (tcon
->ss_flags
& SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE
)
465 seq_puts(m
, " Partition Aligned,");
466 if (tcon
->ss_flags
& SSINFO_FLAGS_NO_SEEK_PENALTY
)
467 seq_puts(m
, " SSD,");
468 if (tcon
->ss_flags
& SSINFO_FLAGS_TRIM_ENABLED
)
469 seq_puts(m
, " TRIM-support,");
471 seq_printf(m
, "\tShare Flags: 0x%x", tcon
->share_flags
);
472 if (tcon
->perf_sector_size
)
473 seq_printf(m
, "\tOptimal sector size: 0x%x",
474 tcon
->perf_sector_size
);
478 smb2_print_stats(struct seq_file
*m
, struct cifs_tcon
*tcon
)
480 #ifdef CONFIG_CIFS_STATS
481 atomic_t
*sent
= tcon
->stats
.smb2_stats
.smb2_com_sent
;
482 atomic_t
*failed
= tcon
->stats
.smb2_stats
.smb2_com_failed
;
483 seq_printf(m
, "\nNegotiates: %d sent %d failed",
484 atomic_read(&sent
[SMB2_NEGOTIATE_HE
]),
485 atomic_read(&failed
[SMB2_NEGOTIATE_HE
]));
486 seq_printf(m
, "\nSessionSetups: %d sent %d failed",
487 atomic_read(&sent
[SMB2_SESSION_SETUP_HE
]),
488 atomic_read(&failed
[SMB2_SESSION_SETUP_HE
]));
489 seq_printf(m
, "\nLogoffs: %d sent %d failed",
490 atomic_read(&sent
[SMB2_LOGOFF_HE
]),
491 atomic_read(&failed
[SMB2_LOGOFF_HE
]));
492 seq_printf(m
, "\nTreeConnects: %d sent %d failed",
493 atomic_read(&sent
[SMB2_TREE_CONNECT_HE
]),
494 atomic_read(&failed
[SMB2_TREE_CONNECT_HE
]));
495 seq_printf(m
, "\nTreeDisconnects: %d sent %d failed",
496 atomic_read(&sent
[SMB2_TREE_DISCONNECT_HE
]),
497 atomic_read(&failed
[SMB2_TREE_DISCONNECT_HE
]));
498 seq_printf(m
, "\nCreates: %d sent %d failed",
499 atomic_read(&sent
[SMB2_CREATE_HE
]),
500 atomic_read(&failed
[SMB2_CREATE_HE
]));
501 seq_printf(m
, "\nCloses: %d sent %d failed",
502 atomic_read(&sent
[SMB2_CLOSE_HE
]),
503 atomic_read(&failed
[SMB2_CLOSE_HE
]));
504 seq_printf(m
, "\nFlushes: %d sent %d failed",
505 atomic_read(&sent
[SMB2_FLUSH_HE
]),
506 atomic_read(&failed
[SMB2_FLUSH_HE
]));
507 seq_printf(m
, "\nReads: %d sent %d failed",
508 atomic_read(&sent
[SMB2_READ_HE
]),
509 atomic_read(&failed
[SMB2_READ_HE
]));
510 seq_printf(m
, "\nWrites: %d sent %d failed",
511 atomic_read(&sent
[SMB2_WRITE_HE
]),
512 atomic_read(&failed
[SMB2_WRITE_HE
]));
513 seq_printf(m
, "\nLocks: %d sent %d failed",
514 atomic_read(&sent
[SMB2_LOCK_HE
]),
515 atomic_read(&failed
[SMB2_LOCK_HE
]));
516 seq_printf(m
, "\nIOCTLs: %d sent %d failed",
517 atomic_read(&sent
[SMB2_IOCTL_HE
]),
518 atomic_read(&failed
[SMB2_IOCTL_HE
]));
519 seq_printf(m
, "\nCancels: %d sent %d failed",
520 atomic_read(&sent
[SMB2_CANCEL_HE
]),
521 atomic_read(&failed
[SMB2_CANCEL_HE
]));
522 seq_printf(m
, "\nEchos: %d sent %d failed",
523 atomic_read(&sent
[SMB2_ECHO_HE
]),
524 atomic_read(&failed
[SMB2_ECHO_HE
]));
525 seq_printf(m
, "\nQueryDirectories: %d sent %d failed",
526 atomic_read(&sent
[SMB2_QUERY_DIRECTORY_HE
]),
527 atomic_read(&failed
[SMB2_QUERY_DIRECTORY_HE
]));
528 seq_printf(m
, "\nChangeNotifies: %d sent %d failed",
529 atomic_read(&sent
[SMB2_CHANGE_NOTIFY_HE
]),
530 atomic_read(&failed
[SMB2_CHANGE_NOTIFY_HE
]));
531 seq_printf(m
, "\nQueryInfos: %d sent %d failed",
532 atomic_read(&sent
[SMB2_QUERY_INFO_HE
]),
533 atomic_read(&failed
[SMB2_QUERY_INFO_HE
]));
534 seq_printf(m
, "\nSetInfos: %d sent %d failed",
535 atomic_read(&sent
[SMB2_SET_INFO_HE
]),
536 atomic_read(&failed
[SMB2_SET_INFO_HE
]));
537 seq_printf(m
, "\nOplockBreaks: %d sent %d failed",
538 atomic_read(&sent
[SMB2_OPLOCK_BREAK_HE
]),
539 atomic_read(&failed
[SMB2_OPLOCK_BREAK_HE
]));
544 smb2_set_fid(struct cifsFileInfo
*cfile
, struct cifs_fid
*fid
, __u32 oplock
)
546 struct cifsInodeInfo
*cinode
= CIFS_I(d_inode(cfile
->dentry
));
547 struct TCP_Server_Info
*server
= tlink_tcon(cfile
->tlink
)->ses
->server
;
549 cfile
->fid
.persistent_fid
= fid
->persistent_fid
;
550 cfile
->fid
.volatile_fid
= fid
->volatile_fid
;
551 server
->ops
->set_oplock_level(cinode
, oplock
, fid
->epoch
,
553 cinode
->can_cache_brlcks
= CIFS_CACHE_WRITE(cinode
);
554 memcpy(cfile
->fid
.create_guid
, fid
->create_guid
, 16);
558 smb2_close_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
559 struct cifs_fid
*fid
)
561 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
565 SMB2_request_res_key(const unsigned int xid
, struct cifs_tcon
*tcon
,
566 u64 persistent_fid
, u64 volatile_fid
,
567 struct copychunk_ioctl
*pcchunk
)
570 unsigned int ret_data_len
;
571 struct resume_key_req
*res_key
;
573 rc
= SMB2_ioctl(xid
, tcon
, persistent_fid
, volatile_fid
,
574 FSCTL_SRV_REQUEST_RESUME_KEY
, true /* is_fsctl */,
576 NULL
, 0 /* no input */,
577 (char **)&res_key
, &ret_data_len
);
580 cifs_dbg(VFS
, "refcpy ioctl error %d getting resume key\n", rc
);
581 goto req_res_key_exit
;
583 if (ret_data_len
< sizeof(struct resume_key_req
)) {
584 cifs_dbg(VFS
, "Invalid refcopy resume key length\n");
586 goto req_res_key_exit
;
588 memcpy(pcchunk
->SourceKey
, res_key
->ResumeKey
, COPY_CHUNK_RES_KEY_SIZE
);
596 smb2_clone_range(const unsigned int xid
,
597 struct cifsFileInfo
*srcfile
,
598 struct cifsFileInfo
*trgtfile
, u64 src_off
,
599 u64 len
, u64 dest_off
)
602 unsigned int ret_data_len
;
603 struct copychunk_ioctl
*pcchunk
;
604 struct copychunk_ioctl_rsp
*retbuf
= NULL
;
605 struct cifs_tcon
*tcon
;
606 int chunks_copied
= 0;
607 bool chunk_sizes_updated
= false;
609 pcchunk
= kmalloc(sizeof(struct copychunk_ioctl
), GFP_KERNEL
);
614 cifs_dbg(FYI
, "in smb2_clone_range - about to call request res key\n");
615 /* Request a key from the server to identify the source of the copy */
616 rc
= SMB2_request_res_key(xid
, tlink_tcon(srcfile
->tlink
),
617 srcfile
->fid
.persistent_fid
,
618 srcfile
->fid
.volatile_fid
, pcchunk
);
620 /* Note: request_res_key sets res_key null only if rc !=0 */
624 /* For now array only one chunk long, will make more flexible later */
625 pcchunk
->ChunkCount
= cpu_to_le32(1);
626 pcchunk
->Reserved
= 0;
627 pcchunk
->Reserved2
= 0;
629 tcon
= tlink_tcon(trgtfile
->tlink
);
632 pcchunk
->SourceOffset
= cpu_to_le64(src_off
);
633 pcchunk
->TargetOffset
= cpu_to_le64(dest_off
);
635 cpu_to_le32(min_t(u32
, len
, tcon
->max_bytes_chunk
));
637 /* Request server copy to target from src identified by key */
638 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
639 trgtfile
->fid
.volatile_fid
, FSCTL_SRV_COPYCHUNK_WRITE
,
640 true /* is_fsctl */, false /* use_ipc */,
642 sizeof(struct copychunk_ioctl
), (char **)&retbuf
,
646 sizeof(struct copychunk_ioctl_rsp
)) {
647 cifs_dbg(VFS
, "invalid cchunk response size\n");
651 if (retbuf
->TotalBytesWritten
== 0) {
652 cifs_dbg(FYI
, "no bytes copied\n");
657 * Check if server claimed to write more than we asked
659 if (le32_to_cpu(retbuf
->TotalBytesWritten
) >
660 le32_to_cpu(pcchunk
->Length
)) {
661 cifs_dbg(VFS
, "invalid copy chunk response\n");
665 if (le32_to_cpu(retbuf
->ChunksWritten
) != 1) {
666 cifs_dbg(VFS
, "invalid num chunks written\n");
672 src_off
+= le32_to_cpu(retbuf
->TotalBytesWritten
);
673 dest_off
+= le32_to_cpu(retbuf
->TotalBytesWritten
);
674 len
-= le32_to_cpu(retbuf
->TotalBytesWritten
);
676 cifs_dbg(FYI
, "Chunks %d PartialChunk %d Total %d\n",
677 le32_to_cpu(retbuf
->ChunksWritten
),
678 le32_to_cpu(retbuf
->ChunkBytesWritten
),
679 le32_to_cpu(retbuf
->TotalBytesWritten
));
680 } else if (rc
== -EINVAL
) {
681 if (ret_data_len
!= sizeof(struct copychunk_ioctl_rsp
))
684 cifs_dbg(FYI
, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
685 le32_to_cpu(retbuf
->ChunksWritten
),
686 le32_to_cpu(retbuf
->ChunkBytesWritten
),
687 le32_to_cpu(retbuf
->TotalBytesWritten
));
690 * Check if this is the first request using these sizes,
691 * (ie check if copy succeed once with original sizes
692 * and check if the server gave us different sizes after
693 * we already updated max sizes on previous request).
694 * if not then why is the server returning an error now
696 if ((chunks_copied
!= 0) || chunk_sizes_updated
)
699 /* Check that server is not asking us to grow size */
700 if (le32_to_cpu(retbuf
->ChunkBytesWritten
) <
701 tcon
->max_bytes_chunk
)
702 tcon
->max_bytes_chunk
=
703 le32_to_cpu(retbuf
->ChunkBytesWritten
);
705 goto cchunk_out
; /* server gave us bogus size */
707 /* No need to change MaxChunks since already set to 1 */
708 chunk_sizes_updated
= true;
720 smb2_flush_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
721 struct cifs_fid
*fid
)
723 return SMB2_flush(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
727 smb2_read_data_offset(char *buf
)
729 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
730 return rsp
->DataOffset
;
734 smb2_read_data_length(char *buf
)
736 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
737 return le32_to_cpu(rsp
->DataLength
);
742 smb2_sync_read(const unsigned int xid
, struct cifs_fid
*pfid
,
743 struct cifs_io_parms
*parms
, unsigned int *bytes_read
,
744 char **buf
, int *buf_type
)
746 parms
->persistent_fid
= pfid
->persistent_fid
;
747 parms
->volatile_fid
= pfid
->volatile_fid
;
748 return SMB2_read(xid
, parms
, bytes_read
, buf
, buf_type
);
752 smb2_sync_write(const unsigned int xid
, struct cifs_fid
*pfid
,
753 struct cifs_io_parms
*parms
, unsigned int *written
,
754 struct kvec
*iov
, unsigned long nr_segs
)
757 parms
->persistent_fid
= pfid
->persistent_fid
;
758 parms
->volatile_fid
= pfid
->volatile_fid
;
759 return SMB2_write(xid
, parms
, written
, iov
, nr_segs
);
762 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
763 static bool smb2_set_sparse(const unsigned int xid
, struct cifs_tcon
*tcon
,
764 struct cifsFileInfo
*cfile
, struct inode
*inode
, __u8 setsparse
)
766 struct cifsInodeInfo
*cifsi
;
769 cifsi
= CIFS_I(inode
);
771 /* if file already sparse don't bother setting sparse again */
772 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && setsparse
)
773 return true; /* already sparse */
775 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && !setsparse
)
776 return true; /* already not sparse */
779 * Can't check for sparse support on share the usual way via the
780 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
781 * since Samba server doesn't set the flag on the share, yet
782 * supports the set sparse FSCTL and returns sparse correctly
783 * in the file attributes. If we fail setting sparse though we
784 * mark that server does not support sparse files for this share
785 * to avoid repeatedly sending the unsupported fsctl to server
786 * if the file is repeatedly extended.
788 if (tcon
->broken_sparse_sup
)
791 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
792 cfile
->fid
.volatile_fid
, FSCTL_SET_SPARSE
,
793 true /* is_fctl */, false /* use_ipc */,
794 &setsparse
, 1, NULL
, NULL
);
796 tcon
->broken_sparse_sup
= true;
797 cifs_dbg(FYI
, "set sparse rc = %d\n", rc
);
802 cifsi
->cifsAttrs
|= FILE_ATTRIBUTE_SPARSE_FILE
;
804 cifsi
->cifsAttrs
&= (~FILE_ATTRIBUTE_SPARSE_FILE
);
810 smb2_set_file_size(const unsigned int xid
, struct cifs_tcon
*tcon
,
811 struct cifsFileInfo
*cfile
, __u64 size
, bool set_alloc
)
813 __le64 eof
= cpu_to_le64(size
);
817 * If extending file more than one page make sparse. Many Linux fs
818 * make files sparse by default when extending via ftruncate
820 inode
= d_inode(cfile
->dentry
);
822 if (!set_alloc
&& (size
> inode
->i_size
+ 8192)) {
825 /* whether set sparse succeeds or not, extend the file */
826 smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
);
829 return SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
830 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
, false);
834 smb2_duplicate_extents(const unsigned int xid
,
835 struct cifsFileInfo
*srcfile
,
836 struct cifsFileInfo
*trgtfile
, u64 src_off
,
837 u64 len
, u64 dest_off
)
840 unsigned int ret_data_len
;
841 struct duplicate_extents_to_file dup_ext_buf
;
842 struct cifs_tcon
*tcon
= tlink_tcon(trgtfile
->tlink
);
844 /* server fileays advertise duplicate extent support with this flag */
845 if ((le32_to_cpu(tcon
->fsAttrInfo
.Attributes
) &
846 FILE_SUPPORTS_BLOCK_REFCOUNTING
) == 0)
849 dup_ext_buf
.VolatileFileHandle
= srcfile
->fid
.volatile_fid
;
850 dup_ext_buf
.PersistentFileHandle
= srcfile
->fid
.persistent_fid
;
851 dup_ext_buf
.SourceFileOffset
= cpu_to_le64(src_off
);
852 dup_ext_buf
.TargetFileOffset
= cpu_to_le64(dest_off
);
853 dup_ext_buf
.ByteCount
= cpu_to_le64(len
);
854 cifs_dbg(FYI
, "duplicate extents: src off %lld dst off %lld len %lld",
855 src_off
, dest_off
, len
);
857 rc
= smb2_set_file_size(xid
, tcon
, trgtfile
, dest_off
+ len
, false);
859 goto duplicate_extents_out
;
861 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
862 trgtfile
->fid
.volatile_fid
,
863 FSCTL_DUPLICATE_EXTENTS_TO_FILE
,
864 true /* is_fsctl */, false /* use_ipc */,
865 (char *)&dup_ext_buf
,
866 sizeof(struct duplicate_extents_to_file
),
870 if (ret_data_len
> 0)
871 cifs_dbg(FYI
, "non-zero response length in duplicate extents");
873 duplicate_extents_out
:
878 smb2_set_compression(const unsigned int xid
, struct cifs_tcon
*tcon
,
879 struct cifsFileInfo
*cfile
)
881 return SMB2_set_compression(xid
, tcon
, cfile
->fid
.persistent_fid
,
882 cfile
->fid
.volatile_fid
);
886 smb3_set_integrity(const unsigned int xid
, struct cifs_tcon
*tcon
,
887 struct cifsFileInfo
*cfile
)
889 struct fsctl_set_integrity_information_req integr_info
;
890 unsigned int ret_data_len
;
892 integr_info
.ChecksumAlgorithm
= cpu_to_le16(CHECKSUM_TYPE_UNCHANGED
);
893 integr_info
.Flags
= 0;
894 integr_info
.Reserved
= 0;
896 return SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
897 cfile
->fid
.volatile_fid
,
898 FSCTL_SET_INTEGRITY_INFORMATION
,
899 true /* is_fsctl */, false /* use_ipc */,
900 (char *)&integr_info
,
901 sizeof(struct fsctl_set_integrity_information_req
),
908 smb3_enum_snapshots(const unsigned int xid
, struct cifs_tcon
*tcon
,
909 struct cifsFileInfo
*cfile
, void __user
*ioc_buf
)
912 unsigned int ret_data_len
= 0;
914 struct smb_snapshot_array snapshot_in
;
916 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
917 cfile
->fid
.volatile_fid
,
918 FSCTL_SRV_ENUMERATE_SNAPSHOTS
,
919 true /* is_fsctl */, false /* use_ipc */,
920 NULL
, 0 /* no input data */,
923 cifs_dbg(FYI
, "enum snaphots ioctl returned %d and ret buflen is %d\n",
928 if (ret_data_len
&& (ioc_buf
!= NULL
) && (retbuf
!= NULL
)) {
930 if (copy_from_user(&snapshot_in
, ioc_buf
,
931 sizeof(struct smb_snapshot_array
))) {
936 if (snapshot_in
.snapshot_array_size
< sizeof(struct smb_snapshot_array
)) {
941 if (ret_data_len
> snapshot_in
.snapshot_array_size
)
942 ret_data_len
= snapshot_in
.snapshot_array_size
;
944 if (copy_to_user(ioc_buf
, retbuf
, ret_data_len
))
953 smb2_query_dir_first(const unsigned int xid
, struct cifs_tcon
*tcon
,
954 const char *path
, struct cifs_sb_info
*cifs_sb
,
955 struct cifs_fid
*fid
, __u16 search_flags
,
956 struct cifs_search_info
*srch_inf
)
960 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
961 struct cifs_open_parms oparms
;
963 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
968 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| FILE_READ_DATA
;
969 oparms
.disposition
= FILE_OPEN
;
970 oparms
.create_options
= 0;
972 oparms
.reconnect
= false;
974 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
977 cifs_dbg(VFS
, "open dir failed\n");
981 srch_inf
->entries_in_buffer
= 0;
982 srch_inf
->index_of_last_entry
= 0;
984 rc
= SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
985 fid
->volatile_fid
, 0, srch_inf
);
987 cifs_dbg(VFS
, "query directory failed\n");
988 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
994 smb2_query_dir_next(const unsigned int xid
, struct cifs_tcon
*tcon
,
995 struct cifs_fid
*fid
, __u16 search_flags
,
996 struct cifs_search_info
*srch_inf
)
998 return SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
999 fid
->volatile_fid
, 0, srch_inf
);
1003 smb2_close_dir(const unsigned int xid
, struct cifs_tcon
*tcon
,
1004 struct cifs_fid
*fid
)
1006 return SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1010 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
1011 * the number of credits and return true. Otherwise - return false.
1014 smb2_is_status_pending(char *buf
, struct TCP_Server_Info
*server
, int length
)
1016 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
1018 if (shdr
->Status
!= STATUS_PENDING
)
1022 spin_lock(&server
->req_lock
);
1023 server
->credits
+= le16_to_cpu(shdr
->CreditRequest
);
1024 spin_unlock(&server
->req_lock
);
1025 wake_up(&server
->request_q
);
1032 smb2_oplock_response(struct cifs_tcon
*tcon
, struct cifs_fid
*fid
,
1033 struct cifsInodeInfo
*cinode
)
1035 if (tcon
->ses
->server
->capabilities
& SMB2_GLOBAL_CAP_LEASING
)
1036 return SMB2_lease_break(0, tcon
, cinode
->lease_key
,
1037 smb2_get_lease_state(cinode
));
1039 return SMB2_oplock_break(0, tcon
, fid
->persistent_fid
,
1041 CIFS_CACHE_READ(cinode
) ? 1 : 0);
1045 smb2_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
1046 struct kstatfs
*buf
)
1049 __le16 srch_path
= 0; /* Null - open root of share */
1050 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1051 struct cifs_open_parms oparms
;
1052 struct cifs_fid fid
;
1055 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
1056 oparms
.disposition
= FILE_OPEN
;
1057 oparms
.create_options
= 0;
1059 oparms
.reconnect
= false;
1061 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
1064 buf
->f_type
= SMB2_MAGIC_NUMBER
;
1065 rc
= SMB2_QFS_info(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
1067 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
1072 smb2_compare_fids(struct cifsFileInfo
*ob1
, struct cifsFileInfo
*ob2
)
1074 return ob1
->fid
.persistent_fid
== ob2
->fid
.persistent_fid
&&
1075 ob1
->fid
.volatile_fid
== ob2
->fid
.volatile_fid
;
1079 smb2_mand_lock(const unsigned int xid
, struct cifsFileInfo
*cfile
, __u64 offset
,
1080 __u64 length
, __u32 type
, int lock
, int unlock
, bool wait
)
1082 if (unlock
&& !lock
)
1083 type
= SMB2_LOCKFLAG_UNLOCK
;
1084 return SMB2_lock(xid
, tlink_tcon(cfile
->tlink
),
1085 cfile
->fid
.persistent_fid
, cfile
->fid
.volatile_fid
,
1086 current
->tgid
, length
, offset
, type
, wait
);
1090 smb2_get_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
1092 memcpy(fid
->lease_key
, CIFS_I(inode
)->lease_key
, SMB2_LEASE_KEY_SIZE
);
1096 smb2_set_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
1098 memcpy(CIFS_I(inode
)->lease_key
, fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
1102 smb2_new_lease_key(struct cifs_fid
*fid
)
1104 generate_random_uuid(fid
->lease_key
);
1108 smb2_get_dfs_refer(const unsigned int xid
, struct cifs_ses
*ses
,
1109 const char *search_name
,
1110 struct dfs_info3_param
**target_nodes
,
1111 unsigned int *num_of_nodes
,
1112 const struct nls_table
*nls_codepage
, int remap
)
1115 __le16
*utf16_path
= NULL
;
1116 int utf16_path_len
= 0;
1117 struct cifs_tcon
*tcon
;
1118 struct fsctl_get_dfs_referral_req
*dfs_req
= NULL
;
1119 struct get_dfs_referral_rsp
*dfs_rsp
= NULL
;
1120 u32 dfs_req_size
= 0, dfs_rsp_size
= 0;
1122 cifs_dbg(FYI
, "smb2_get_dfs_refer path <%s>\n", search_name
);
1125 * Use any tcon from the current session. Here, the first one.
1127 spin_lock(&cifs_tcp_ses_lock
);
1128 tcon
= list_first_entry_or_null(&ses
->tcon_list
, struct cifs_tcon
,
1132 spin_unlock(&cifs_tcp_ses_lock
);
1135 cifs_dbg(VFS
, "session %p has no tcon available for a dfs referral request\n",
1141 utf16_path
= cifs_strndup_to_utf16(search_name
, PATH_MAX
,
1143 nls_codepage
, remap
);
1149 dfs_req_size
= sizeof(*dfs_req
) + utf16_path_len
;
1150 dfs_req
= kzalloc(dfs_req_size
, GFP_KERNEL
);
1156 /* Highest DFS referral version understood */
1157 dfs_req
->MaxReferralLevel
= DFS_VERSION
;
1159 /* Path to resolve in an UTF-16 null-terminated string */
1160 memcpy(dfs_req
->RequestFileName
, utf16_path
, utf16_path_len
);
1163 /* try first with IPC */
1164 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
1165 FSCTL_DFS_GET_REFERRALS
,
1166 true /* is_fsctl */, true /* use_ipc */,
1167 (char *)dfs_req
, dfs_req_size
,
1168 (char **)&dfs_rsp
, &dfs_rsp_size
);
1169 if (rc
== -ENOTCONN
) {
1170 /* try with normal tcon */
1171 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
1172 FSCTL_DFS_GET_REFERRALS
,
1173 true /* is_fsctl */, false /*use_ipc*/,
1174 (char *)dfs_req
, dfs_req_size
,
1175 (char **)&dfs_rsp
, &dfs_rsp_size
);
1177 } while (rc
== -EAGAIN
);
1180 cifs_dbg(VFS
, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc
);
1184 rc
= parse_dfs_referrals(dfs_rsp
, dfs_rsp_size
,
1185 num_of_nodes
, target_nodes
,
1186 nls_codepage
, remap
, search_name
,
1187 true /* is_unicode */);
1189 cifs_dbg(VFS
, "parse error in smb2_get_dfs_refer rc=%d\n", rc
);
1195 spin_lock(&cifs_tcp_ses_lock
);
1197 spin_unlock(&cifs_tcp_ses_lock
);
1204 #define SMB2_SYMLINK_STRUCT_SIZE \
1205 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
1208 smb2_query_symlink(const unsigned int xid
, struct cifs_tcon
*tcon
,
1209 const char *full_path
, char **target_path
,
1210 struct cifs_sb_info
*cifs_sb
)
1214 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1215 struct cifs_open_parms oparms
;
1216 struct cifs_fid fid
;
1217 struct smb2_err_rsp
*err_buf
= NULL
;
1218 struct smb2_symlink_err_rsp
*symlink
;
1219 unsigned int sub_len
;
1220 unsigned int sub_offset
;
1221 unsigned int print_len
;
1222 unsigned int print_offset
;
1224 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, full_path
);
1226 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
1231 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
1232 oparms
.disposition
= FILE_OPEN
;
1233 oparms
.create_options
= 0;
1235 oparms
.reconnect
= false;
1237 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, &err_buf
);
1239 if (!rc
|| !err_buf
) {
1244 if (le32_to_cpu(err_buf
->ByteCount
) < sizeof(struct smb2_symlink_err_rsp
) ||
1245 get_rfc1002_length(err_buf
) + 4 < SMB2_SYMLINK_STRUCT_SIZE
) {
1250 /* open must fail on symlink - reset rc */
1252 symlink
= (struct smb2_symlink_err_rsp
*)err_buf
->ErrorData
;
1253 sub_len
= le16_to_cpu(symlink
->SubstituteNameLength
);
1254 sub_offset
= le16_to_cpu(symlink
->SubstituteNameOffset
);
1255 print_len
= le16_to_cpu(symlink
->PrintNameLength
);
1256 print_offset
= le16_to_cpu(symlink
->PrintNameOffset
);
1258 if (get_rfc1002_length(err_buf
) + 4 <
1259 SMB2_SYMLINK_STRUCT_SIZE
+ sub_offset
+ sub_len
) {
1264 if (get_rfc1002_length(err_buf
) + 4 <
1265 SMB2_SYMLINK_STRUCT_SIZE
+ print_offset
+ print_len
) {
1270 *target_path
= cifs_strndup_from_utf16(
1271 (char *)symlink
->PathBuffer
+ sub_offset
,
1272 sub_len
, true, cifs_sb
->local_nls
);
1273 if (!(*target_path
)) {
1277 convert_delimiter(*target_path
, '/');
1278 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
1283 static long smb3_zero_range(struct file
*file
, struct cifs_tcon
*tcon
,
1284 loff_t offset
, loff_t len
, bool keep_size
)
1286 struct inode
*inode
;
1287 struct cifsInodeInfo
*cifsi
;
1288 struct cifsFileInfo
*cfile
= file
->private_data
;
1289 struct file_zero_data_information fsctl_buf
;
1295 inode
= d_inode(cfile
->dentry
);
1296 cifsi
= CIFS_I(inode
);
1298 /* if file not oplocked can't be sure whether asking to extend size */
1299 if (!CIFS_CACHE_READ(cifsi
))
1300 if (keep_size
== false)
1304 * Must check if file sparse since fallocate -z (zero range) assumes
1305 * non-sparse allocation
1307 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
))
1311 * need to make sure we are not asked to extend the file since the SMB3
1312 * fsctl does not change the file size. In the future we could change
1313 * this to zero the first part of the range then set the file size
1314 * which for a non sparse file would zero the newly extended range
1316 if (keep_size
== false)
1317 if (i_size_read(inode
) < offset
+ len
)
1320 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1322 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1323 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1325 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1326 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1327 true /* is_fctl */, false /* use_ipc */,
1329 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1334 static long smb3_punch_hole(struct file
*file
, struct cifs_tcon
*tcon
,
1335 loff_t offset
, loff_t len
)
1337 struct inode
*inode
;
1338 struct cifsInodeInfo
*cifsi
;
1339 struct cifsFileInfo
*cfile
= file
->private_data
;
1340 struct file_zero_data_information fsctl_buf
;
1343 __u8 set_sparse
= 1;
1347 inode
= d_inode(cfile
->dentry
);
1348 cifsi
= CIFS_I(inode
);
1350 /* Need to make file sparse, if not already, before freeing range. */
1351 /* Consider adding equivalent for compressed since it could also work */
1352 if (!smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
))
1355 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1357 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1358 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1360 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1361 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1362 true /* is_fctl */, false /* use_ipc */,
1364 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1369 static long smb3_simple_falloc(struct file
*file
, struct cifs_tcon
*tcon
,
1370 loff_t off
, loff_t len
, bool keep_size
)
1372 struct inode
*inode
;
1373 struct cifsInodeInfo
*cifsi
;
1374 struct cifsFileInfo
*cfile
= file
->private_data
;
1375 long rc
= -EOPNOTSUPP
;
1380 inode
= d_inode(cfile
->dentry
);
1381 cifsi
= CIFS_I(inode
);
1383 /* if file not oplocked can't be sure whether asking to extend size */
1384 if (!CIFS_CACHE_READ(cifsi
))
1385 if (keep_size
== false)
1389 * Files are non-sparse by default so falloc may be a no-op
1390 * Must check if file sparse. If not sparse, and not extending
1391 * then no need to do anything since file already allocated
1393 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) == 0) {
1394 if (keep_size
== true)
1396 /* check if extending file */
1397 else if (i_size_read(inode
) >= off
+ len
)
1398 /* not extending file and already not sparse */
1400 /* BB: in future add else clause to extend file */
1405 if ((keep_size
== true) || (i_size_read(inode
) >= off
+ len
)) {
1407 * Check if falloc starts within first few pages of file
1408 * and ends within a few pages of the end of file to
1409 * ensure that most of file is being forced to be
1410 * fallocated now. If so then setting whole file sparse
1411 * ie potentially making a few extra pages at the beginning
1412 * or end of the file non-sparse via set_sparse is harmless.
1414 if ((off
> 8192) || (off
+ len
+ 8192 < i_size_read(inode
)))
1417 rc
= smb2_set_sparse(xid
, tcon
, cfile
, inode
, false);
1419 /* BB: else ... in future add code to extend file and set sparse */
1427 static long smb3_fallocate(struct file
*file
, struct cifs_tcon
*tcon
, int mode
,
1428 loff_t off
, loff_t len
)
1430 /* KEEP_SIZE already checked for by do_fallocate */
1431 if (mode
& FALLOC_FL_PUNCH_HOLE
)
1432 return smb3_punch_hole(file
, tcon
, off
, len
);
1433 else if (mode
& FALLOC_FL_ZERO_RANGE
) {
1434 if (mode
& FALLOC_FL_KEEP_SIZE
)
1435 return smb3_zero_range(file
, tcon
, off
, len
, true);
1436 return smb3_zero_range(file
, tcon
, off
, len
, false);
1437 } else if (mode
== FALLOC_FL_KEEP_SIZE
)
1438 return smb3_simple_falloc(file
, tcon
, off
, len
, true);
1440 return smb3_simple_falloc(file
, tcon
, off
, len
, false);
1446 smb2_downgrade_oplock(struct TCP_Server_Info
*server
,
1447 struct cifsInodeInfo
*cinode
, bool set_level2
)
1450 server
->ops
->set_oplock_level(cinode
, SMB2_OPLOCK_LEVEL_II
,
1453 server
->ops
->set_oplock_level(cinode
, 0, 0, NULL
);
1457 smb2_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1458 unsigned int epoch
, bool *purge_cache
)
1461 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1463 if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
) {
1464 cinode
->oplock
= CIFS_CACHE_RHW_FLG
;
1465 cifs_dbg(FYI
, "Batch Oplock granted on inode %p\n",
1466 &cinode
->vfs_inode
);
1467 } else if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
) {
1468 cinode
->oplock
= CIFS_CACHE_RW_FLG
;
1469 cifs_dbg(FYI
, "Exclusive Oplock granted on inode %p\n",
1470 &cinode
->vfs_inode
);
1471 } else if (oplock
== SMB2_OPLOCK_LEVEL_II
) {
1472 cinode
->oplock
= CIFS_CACHE_READ_FLG
;
1473 cifs_dbg(FYI
, "Level II Oplock granted on inode %p\n",
1474 &cinode
->vfs_inode
);
1480 smb21_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1481 unsigned int epoch
, bool *purge_cache
)
1483 char message
[5] = {0};
1486 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1490 if (oplock
& SMB2_LEASE_READ_CACHING_HE
) {
1491 cinode
->oplock
|= CIFS_CACHE_READ_FLG
;
1492 strcat(message
, "R");
1494 if (oplock
& SMB2_LEASE_HANDLE_CACHING_HE
) {
1495 cinode
->oplock
|= CIFS_CACHE_HANDLE_FLG
;
1496 strcat(message
, "H");
1498 if (oplock
& SMB2_LEASE_WRITE_CACHING_HE
) {
1499 cinode
->oplock
|= CIFS_CACHE_WRITE_FLG
;
1500 strcat(message
, "W");
1502 if (!cinode
->oplock
)
1503 strcat(message
, "None");
1504 cifs_dbg(FYI
, "%s Lease granted on inode %p\n", message
,
1505 &cinode
->vfs_inode
);
1509 smb3_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1510 unsigned int epoch
, bool *purge_cache
)
1512 unsigned int old_oplock
= cinode
->oplock
;
1514 smb21_set_oplock_level(cinode
, oplock
, epoch
, purge_cache
);
1517 *purge_cache
= false;
1518 if (old_oplock
== CIFS_CACHE_READ_FLG
) {
1519 if (cinode
->oplock
== CIFS_CACHE_READ_FLG
&&
1520 (epoch
- cinode
->epoch
> 0))
1521 *purge_cache
= true;
1522 else if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1523 (epoch
- cinode
->epoch
> 1))
1524 *purge_cache
= true;
1525 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1526 (epoch
- cinode
->epoch
> 1))
1527 *purge_cache
= true;
1528 else if (cinode
->oplock
== 0 &&
1529 (epoch
- cinode
->epoch
> 0))
1530 *purge_cache
= true;
1531 } else if (old_oplock
== CIFS_CACHE_RH_FLG
) {
1532 if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1533 (epoch
- cinode
->epoch
> 0))
1534 *purge_cache
= true;
1535 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1536 (epoch
- cinode
->epoch
> 1))
1537 *purge_cache
= true;
1539 cinode
->epoch
= epoch
;
1544 smb2_is_read_op(__u32 oplock
)
1546 return oplock
== SMB2_OPLOCK_LEVEL_II
;
1550 smb21_is_read_op(__u32 oplock
)
1552 return (oplock
& SMB2_LEASE_READ_CACHING_HE
) &&
1553 !(oplock
& SMB2_LEASE_WRITE_CACHING_HE
);
1557 map_oplock_to_lease(u8 oplock
)
1559 if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
)
1560 return SMB2_LEASE_WRITE_CACHING
| SMB2_LEASE_READ_CACHING
;
1561 else if (oplock
== SMB2_OPLOCK_LEVEL_II
)
1562 return SMB2_LEASE_READ_CACHING
;
1563 else if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
)
1564 return SMB2_LEASE_HANDLE_CACHING
| SMB2_LEASE_READ_CACHING
|
1565 SMB2_LEASE_WRITE_CACHING
;
1570 smb2_create_lease_buf(u8
*lease_key
, u8 oplock
)
1572 struct create_lease
*buf
;
1574 buf
= kzalloc(sizeof(struct create_lease
), GFP_KERNEL
);
1578 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1579 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1580 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1582 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1583 (struct create_lease
, lcontext
));
1584 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context
));
1585 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1586 (struct create_lease
, Name
));
1587 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1588 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1597 smb3_create_lease_buf(u8
*lease_key
, u8 oplock
)
1599 struct create_lease_v2
*buf
;
1601 buf
= kzalloc(sizeof(struct create_lease_v2
), GFP_KERNEL
);
1605 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1606 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1607 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1609 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1610 (struct create_lease_v2
, lcontext
));
1611 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context_v2
));
1612 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1613 (struct create_lease_v2
, Name
));
1614 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1615 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1624 smb2_parse_lease_buf(void *buf
, unsigned int *epoch
)
1626 struct create_lease
*lc
= (struct create_lease
*)buf
;
1628 *epoch
= 0; /* not used */
1629 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
1630 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
1631 return le32_to_cpu(lc
->lcontext
.LeaseState
);
1635 smb3_parse_lease_buf(void *buf
, unsigned int *epoch
)
1637 struct create_lease_v2
*lc
= (struct create_lease_v2
*)buf
;
1639 *epoch
= le16_to_cpu(lc
->lcontext
.Epoch
);
1640 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
1641 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
1642 return le32_to_cpu(lc
->lcontext
.LeaseState
);
1646 smb2_wp_retry_size(struct inode
*inode
)
1648 return min_t(unsigned int, CIFS_SB(inode
->i_sb
)->wsize
,
1649 SMB2_MAX_BUFFER_SIZE
);
1653 smb2_dir_needs_close(struct cifsFileInfo
*cfile
)
1655 return !cfile
->invalidHandle
;
1659 fill_transform_hdr(struct smb2_transform_hdr
*tr_hdr
, struct smb_rqst
*old_rq
)
1661 struct smb2_sync_hdr
*shdr
=
1662 (struct smb2_sync_hdr
*)old_rq
->rq_iov
[1].iov_base
;
1663 unsigned int orig_len
= get_rfc1002_length(old_rq
->rq_iov
[0].iov_base
);
1665 memset(tr_hdr
, 0, sizeof(struct smb2_transform_hdr
));
1666 tr_hdr
->ProtocolId
= SMB2_TRANSFORM_PROTO_NUM
;
1667 tr_hdr
->OriginalMessageSize
= cpu_to_le32(orig_len
);
1668 tr_hdr
->Flags
= cpu_to_le16(0x01);
1669 get_random_bytes(&tr_hdr
->Nonce
, SMB3_AES128CMM_NONCE
);
1670 memcpy(&tr_hdr
->SessionId
, &shdr
->SessionId
, 8);
1671 inc_rfc1001_len(tr_hdr
, sizeof(struct smb2_transform_hdr
) - 4);
1672 inc_rfc1001_len(tr_hdr
, orig_len
);
1675 static struct scatterlist
*
1676 init_sg(struct smb_rqst
*rqst
, u8
*sign
)
1678 unsigned int sg_len
= rqst
->rq_nvec
+ rqst
->rq_npages
+ 1;
1679 unsigned int assoc_data_len
= sizeof(struct smb2_transform_hdr
) - 24;
1680 struct scatterlist
*sg
;
1684 sg
= kmalloc_array(sg_len
, sizeof(struct scatterlist
), GFP_KERNEL
);
1688 sg_init_table(sg
, sg_len
);
1689 sg_set_buf(&sg
[0], rqst
->rq_iov
[0].iov_base
+ 24, assoc_data_len
);
1690 for (i
= 1; i
< rqst
->rq_nvec
; i
++)
1691 sg_set_buf(&sg
[i
], rqst
->rq_iov
[i
].iov_base
,
1692 rqst
->rq_iov
[i
].iov_len
);
1693 for (j
= 0; i
< sg_len
- 1; i
++, j
++) {
1694 unsigned int len
= (j
< rqst
->rq_npages
- 1) ? rqst
->rq_pagesz
1696 sg_set_page(&sg
[i
], rqst
->rq_pages
[j
], len
, 0);
1698 sg_set_buf(&sg
[sg_len
- 1], sign
, SMB2_SIGNATURE_SIZE
);
1702 struct cifs_crypt_result
{
1704 struct completion completion
;
1707 static void cifs_crypt_complete(struct crypto_async_request
*req
, int err
)
1709 struct cifs_crypt_result
*res
= req
->data
;
1711 if (err
== -EINPROGRESS
)
1715 complete(&res
->completion
);
1719 smb2_get_enc_key(struct TCP_Server_Info
*server
, __u64 ses_id
, int enc
, u8
*key
)
1721 struct cifs_ses
*ses
;
1724 spin_lock(&cifs_tcp_ses_lock
);
1725 list_for_each_entry(ses
, &server
->smb_ses_list
, smb_ses_list
) {
1726 if (ses
->Suid
!= ses_id
)
1728 ses_enc_key
= enc
? ses
->smb3encryptionkey
:
1729 ses
->smb3decryptionkey
;
1730 memcpy(key
, ses_enc_key
, SMB3_SIGN_KEY_SIZE
);
1731 spin_unlock(&cifs_tcp_ses_lock
);
1734 spin_unlock(&cifs_tcp_ses_lock
);
1739 * Encrypt or decrypt @rqst message. @rqst has the following format:
1740 * iov[0] - transform header (associate data),
1741 * iov[1-N] and pages - data to encrypt.
1742 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
1746 crypt_message(struct TCP_Server_Info
*server
, struct smb_rqst
*rqst
, int enc
)
1748 struct smb2_transform_hdr
*tr_hdr
=
1749 (struct smb2_transform_hdr
*)rqst
->rq_iov
[0].iov_base
;
1750 unsigned int assoc_data_len
= sizeof(struct smb2_transform_hdr
) - 24;
1752 struct scatterlist
*sg
;
1753 u8 sign
[SMB2_SIGNATURE_SIZE
] = {};
1754 u8 key
[SMB3_SIGN_KEY_SIZE
];
1755 struct aead_request
*req
;
1757 unsigned int iv_len
;
1758 struct cifs_crypt_result result
= {0, };
1759 struct crypto_aead
*tfm
;
1760 unsigned int crypt_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
1762 init_completion(&result
.completion
);
1764 rc
= smb2_get_enc_key(server
, tr_hdr
->SessionId
, enc
, key
);
1766 cifs_dbg(VFS
, "%s: Could not get %scryption key\n", __func__
,
1771 rc
= smb3_crypto_aead_allocate(server
);
1773 cifs_dbg(VFS
, "%s: crypto alloc failed\n", __func__
);
1777 tfm
= enc
? server
->secmech
.ccmaesencrypt
:
1778 server
->secmech
.ccmaesdecrypt
;
1779 rc
= crypto_aead_setkey(tfm
, key
, SMB3_SIGN_KEY_SIZE
);
1781 cifs_dbg(VFS
, "%s: Failed to set aead key %d\n", __func__
, rc
);
1785 rc
= crypto_aead_setauthsize(tfm
, SMB2_SIGNATURE_SIZE
);
1787 cifs_dbg(VFS
, "%s: Failed to set authsize %d\n", __func__
, rc
);
1791 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
1793 cifs_dbg(VFS
, "%s: Failed to alloc aead request", __func__
);
1798 memcpy(sign
, &tr_hdr
->Signature
, SMB2_SIGNATURE_SIZE
);
1799 crypt_len
+= SMB2_SIGNATURE_SIZE
;
1802 sg
= init_sg(rqst
, sign
);
1804 cifs_dbg(VFS
, "%s: Failed to init sg %d", __func__
, rc
);
1808 iv_len
= crypto_aead_ivsize(tfm
);
1809 iv
= kzalloc(iv_len
, GFP_KERNEL
);
1811 cifs_dbg(VFS
, "%s: Failed to alloc IV", __func__
);
1815 memcpy(iv
+ 1, (char *)tr_hdr
->Nonce
, SMB3_AES128CMM_NONCE
);
1817 aead_request_set_crypt(req
, sg
, sg
, crypt_len
, iv
);
1818 aead_request_set_ad(req
, assoc_data_len
);
1820 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
1821 cifs_crypt_complete
, &result
);
1823 rc
= enc
? crypto_aead_encrypt(req
) : crypto_aead_decrypt(req
);
1825 if (rc
== -EINPROGRESS
|| rc
== -EBUSY
) {
1826 wait_for_completion(&result
.completion
);
1831 memcpy(&tr_hdr
->Signature
, sign
, SMB2_SIGNATURE_SIZE
);
1842 smb3_init_transform_rq(struct TCP_Server_Info
*server
, struct smb_rqst
*new_rq
,
1843 struct smb_rqst
*old_rq
)
1846 struct page
**pages
;
1847 struct smb2_transform_hdr
*tr_hdr
;
1848 unsigned int npages
= old_rq
->rq_npages
;
1852 pages
= kmalloc_array(npages
, sizeof(struct page
*), GFP_KERNEL
);
1856 new_rq
->rq_pages
= pages
;
1857 new_rq
->rq_npages
= old_rq
->rq_npages
;
1858 new_rq
->rq_pagesz
= old_rq
->rq_pagesz
;
1859 new_rq
->rq_tailsz
= old_rq
->rq_tailsz
;
1861 for (i
= 0; i
< npages
; i
++) {
1862 pages
[i
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
1864 goto err_free_pages
;
1867 iov
= kmalloc_array(old_rq
->rq_nvec
, sizeof(struct kvec
), GFP_KERNEL
);
1869 goto err_free_pages
;
1871 /* copy all iovs from the old except the 1st one (rfc1002 length) */
1872 memcpy(&iov
[1], &old_rq
->rq_iov
[1],
1873 sizeof(struct kvec
) * (old_rq
->rq_nvec
- 1));
1874 new_rq
->rq_iov
= iov
;
1875 new_rq
->rq_nvec
= old_rq
->rq_nvec
;
1877 tr_hdr
= kmalloc(sizeof(struct smb2_transform_hdr
), GFP_KERNEL
);
1881 /* fill the 1st iov with a transform header */
1882 fill_transform_hdr(tr_hdr
, old_rq
);
1883 new_rq
->rq_iov
[0].iov_base
= tr_hdr
;
1884 new_rq
->rq_iov
[0].iov_len
= sizeof(struct smb2_transform_hdr
);
1886 /* copy pages form the old */
1887 for (i
= 0; i
< npages
; i
++) {
1888 char *dst
= kmap(new_rq
->rq_pages
[i
]);
1889 char *src
= kmap(old_rq
->rq_pages
[i
]);
1890 unsigned int len
= (i
< npages
- 1) ? new_rq
->rq_pagesz
:
1892 memcpy(dst
, src
, len
);
1893 kunmap(new_rq
->rq_pages
[i
]);
1894 kunmap(old_rq
->rq_pages
[i
]);
1897 rc
= crypt_message(server
, new_rq
, 1);
1898 cifs_dbg(FYI
, "encrypt message returned %d", rc
);
1900 goto err_free_tr_hdr
;
1909 for (i
= i
- 1; i
>= 0; i
--)
1916 smb3_free_transform_rq(struct smb_rqst
*rqst
)
1918 int i
= rqst
->rq_npages
- 1;
1921 put_page(rqst
->rq_pages
[i
]);
1922 kfree(rqst
->rq_pages
);
1923 /* free transform header */
1924 kfree(rqst
->rq_iov
[0].iov_base
);
1925 kfree(rqst
->rq_iov
);
1929 smb3_is_transform_hdr(void *buf
)
1931 struct smb2_transform_hdr
*trhdr
= buf
;
1933 return trhdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
;
1937 decrypt_raw_data(struct TCP_Server_Info
*server
, char *buf
,
1938 unsigned int buf_data_size
, struct page
**pages
,
1939 unsigned int npages
, unsigned int page_data_size
)
1942 struct smb_rqst rqst
= {NULL
};
1943 struct smb2_hdr
*hdr
;
1946 iov
[0].iov_base
= buf
;
1947 iov
[0].iov_len
= sizeof(struct smb2_transform_hdr
);
1948 iov
[1].iov_base
= buf
+ sizeof(struct smb2_transform_hdr
);
1949 iov
[1].iov_len
= buf_data_size
;
1953 rqst
.rq_pages
= pages
;
1954 rqst
.rq_npages
= npages
;
1955 rqst
.rq_pagesz
= PAGE_SIZE
;
1956 rqst
.rq_tailsz
= (page_data_size
% PAGE_SIZE
) ? : PAGE_SIZE
;
1958 rc
= crypt_message(server
, &rqst
, 0);
1959 cifs_dbg(FYI
, "decrypt message returned %d\n", rc
);
1964 memmove(buf
+ 4, iov
[1].iov_base
, buf_data_size
);
1965 hdr
= (struct smb2_hdr
*)buf
;
1966 hdr
->smb2_buf_length
= cpu_to_be32(buf_data_size
+ page_data_size
);
1967 server
->total_read
= buf_data_size
+ page_data_size
+ 4;
1973 read_data_into_pages(struct TCP_Server_Info
*server
, struct page
**pages
,
1974 unsigned int npages
, unsigned int len
)
1979 for (i
= 0; i
< npages
; i
++) {
1980 struct page
*page
= pages
[i
];
1984 if (len
>= PAGE_SIZE
) {
1985 /* enough data to fill the page */
1989 zero_user(page
, len
, PAGE_SIZE
- len
);
1992 length
= cifs_read_page_from_socket(server
, page
, n
);
1995 server
->total_read
+= length
;
2002 init_read_bvec(struct page
**pages
, unsigned int npages
, unsigned int data_size
,
2003 unsigned int cur_off
, struct bio_vec
**page_vec
)
2005 struct bio_vec
*bvec
;
2008 bvec
= kcalloc(npages
, sizeof(struct bio_vec
), GFP_KERNEL
);
2012 for (i
= 0; i
< npages
; i
++) {
2013 bvec
[i
].bv_page
= pages
[i
];
2014 bvec
[i
].bv_offset
= (i
== 0) ? cur_off
: 0;
2015 bvec
[i
].bv_len
= min_t(unsigned int, PAGE_SIZE
, data_size
);
2016 data_size
-= bvec
[i
].bv_len
;
2019 if (data_size
!= 0) {
2020 cifs_dbg(VFS
, "%s: something went wrong\n", __func__
);
2030 handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
,
2031 char *buf
, unsigned int buf_len
, struct page
**pages
,
2032 unsigned int npages
, unsigned int page_data_size
)
2034 unsigned int data_offset
;
2035 unsigned int data_len
;
2036 unsigned int cur_off
;
2037 unsigned int cur_page_idx
;
2038 unsigned int pad_len
;
2039 struct cifs_readdata
*rdata
= mid
->callback_data
;
2040 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
2041 struct bio_vec
*bvec
= NULL
;
2042 struct iov_iter iter
;
2046 if (shdr
->Command
!= SMB2_READ
) {
2047 cifs_dbg(VFS
, "only big read responses are supported\n");
2051 if (server
->ops
->is_status_pending
&&
2052 server
->ops
->is_status_pending(buf
, server
, 0))
2055 rdata
->result
= server
->ops
->map_error(buf
, false);
2056 if (rdata
->result
!= 0) {
2057 cifs_dbg(FYI
, "%s: server returned error %d\n",
2058 __func__
, rdata
->result
);
2059 dequeue_mid(mid
, rdata
->result
);
2063 data_offset
= server
->ops
->read_data_offset(buf
) + 4;
2064 data_len
= server
->ops
->read_data_length(buf
);
2066 if (data_offset
< server
->vals
->read_rsp_size
) {
2068 * win2k8 sometimes sends an offset of 0 when the read
2069 * is beyond the EOF. Treat it as if the data starts just after
2072 cifs_dbg(FYI
, "%s: data offset (%u) inside read response header\n",
2073 __func__
, data_offset
);
2074 data_offset
= server
->vals
->read_rsp_size
;
2075 } else if (data_offset
> MAX_CIFS_SMALL_BUFFER_SIZE
) {
2076 /* data_offset is beyond the end of smallbuf */
2077 cifs_dbg(FYI
, "%s: data offset (%u) beyond end of smallbuf\n",
2078 __func__
, data_offset
);
2079 rdata
->result
= -EIO
;
2080 dequeue_mid(mid
, rdata
->result
);
2084 pad_len
= data_offset
- server
->vals
->read_rsp_size
;
2086 if (buf_len
<= data_offset
) {
2087 /* read response payload is in pages */
2088 cur_page_idx
= pad_len
/ PAGE_SIZE
;
2089 cur_off
= pad_len
% PAGE_SIZE
;
2091 if (cur_page_idx
!= 0) {
2092 /* data offset is beyond the 1st page of response */
2093 cifs_dbg(FYI
, "%s: data offset (%u) beyond 1st page of response\n",
2094 __func__
, data_offset
);
2095 rdata
->result
= -EIO
;
2096 dequeue_mid(mid
, rdata
->result
);
2100 if (data_len
> page_data_size
- pad_len
) {
2101 /* data_len is corrupt -- discard frame */
2102 rdata
->result
= -EIO
;
2103 dequeue_mid(mid
, rdata
->result
);
2107 rdata
->result
= init_read_bvec(pages
, npages
, page_data_size
,
2109 if (rdata
->result
!= 0) {
2110 dequeue_mid(mid
, rdata
->result
);
2114 iov_iter_bvec(&iter
, WRITE
| ITER_BVEC
, bvec
, npages
, data_len
);
2115 } else if (buf_len
>= data_offset
+ data_len
) {
2116 /* read response payload is in buf */
2117 WARN_ONCE(npages
> 0, "read data can be either in buf or in pages");
2118 iov
.iov_base
= buf
+ data_offset
;
2119 iov
.iov_len
= data_len
;
2120 iov_iter_kvec(&iter
, WRITE
| ITER_KVEC
, &iov
, 1, data_len
);
2122 /* read response payload cannot be in both buf and pages */
2123 WARN_ONCE(1, "buf can not contain only a part of read data");
2124 rdata
->result
= -EIO
;
2125 dequeue_mid(mid
, rdata
->result
);
2129 /* set up first iov for signature check */
2130 rdata
->iov
[0].iov_base
= buf
;
2131 rdata
->iov
[0].iov_len
= 4;
2132 rdata
->iov
[1].iov_base
= buf
+ 4;
2133 rdata
->iov
[1].iov_len
= server
->vals
->read_rsp_size
- 4;
2134 cifs_dbg(FYI
, "0: iov_base=%p iov_len=%zu\n",
2135 rdata
->iov
[0].iov_base
, server
->vals
->read_rsp_size
);
2137 length
= rdata
->copy_into_pages(server
, rdata
, &iter
);
2144 dequeue_mid(mid
, false);
2149 receive_encrypted_read(struct TCP_Server_Info
*server
, struct mid_q_entry
**mid
)
2151 char *buf
= server
->smallbuf
;
2152 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
2153 unsigned int npages
;
2154 struct page
**pages
;
2156 unsigned int buflen
= get_rfc1002_length(buf
) + 4;
2160 len
= min_t(unsigned int, buflen
, server
->vals
->read_rsp_size
- 4 +
2161 sizeof(struct smb2_transform_hdr
)) - HEADER_SIZE(server
) + 1;
2163 rc
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1, len
);
2166 server
->total_read
+= rc
;
2168 len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
) + 4 -
2169 server
->vals
->read_rsp_size
;
2170 npages
= DIV_ROUND_UP(len
, PAGE_SIZE
);
2172 pages
= kmalloc_array(npages
, sizeof(struct page
*), GFP_KERNEL
);
2178 for (; i
< npages
; i
++) {
2179 pages
[i
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
2186 /* read read data into pages */
2187 rc
= read_data_into_pages(server
, pages
, npages
, len
);
2191 rc
= cifs_discard_remaining_data(server
);
2195 rc
= decrypt_raw_data(server
, buf
, server
->vals
->read_rsp_size
- 4,
2196 pages
, npages
, len
);
2200 *mid
= smb2_find_mid(server
, buf
);
2202 cifs_dbg(FYI
, "mid not found\n");
2204 cifs_dbg(FYI
, "mid found\n");
2205 (*mid
)->decrypted
= true;
2206 rc
= handle_read_data(server
, *mid
, buf
,
2207 server
->vals
->read_rsp_size
,
2208 pages
, npages
, len
);
2212 for (i
= i
- 1; i
>= 0; i
--)
2217 cifs_discard_remaining_data(server
);
2222 receive_encrypted_standard(struct TCP_Server_Info
*server
,
2223 struct mid_q_entry
**mid
)
2226 char *buf
= server
->smallbuf
;
2227 unsigned int pdu_length
= get_rfc1002_length(buf
);
2228 unsigned int buf_size
;
2229 struct mid_q_entry
*mid_entry
;
2231 /* switch to large buffer if too big for a small one */
2232 if (pdu_length
+ 4 > MAX_CIFS_SMALL_BUFFER_SIZE
) {
2233 server
->large_buf
= true;
2234 memcpy(server
->bigbuf
, buf
, server
->total_read
);
2235 buf
= server
->bigbuf
;
2238 /* now read the rest */
2239 length
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1,
2240 pdu_length
- HEADER_SIZE(server
) + 1 + 4);
2243 server
->total_read
+= length
;
2245 buf_size
= pdu_length
+ 4 - sizeof(struct smb2_transform_hdr
);
2246 length
= decrypt_raw_data(server
, buf
, buf_size
, NULL
, 0, 0);
2250 mid_entry
= smb2_find_mid(server
, buf
);
2251 if (mid_entry
== NULL
)
2252 cifs_dbg(FYI
, "mid not found\n");
2254 cifs_dbg(FYI
, "mid found\n");
2255 mid_entry
->decrypted
= true;
2260 if (mid_entry
&& mid_entry
->handle
)
2261 return mid_entry
->handle(server
, mid_entry
);
2263 return cifs_handle_standard(server
, mid_entry
);
2267 smb3_receive_transform(struct TCP_Server_Info
*server
, struct mid_q_entry
**mid
)
2269 char *buf
= server
->smallbuf
;
2270 unsigned int pdu_length
= get_rfc1002_length(buf
);
2271 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
2272 unsigned int orig_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
2274 if (pdu_length
+ 4 < sizeof(struct smb2_transform_hdr
) +
2275 sizeof(struct smb2_sync_hdr
)) {
2276 cifs_dbg(VFS
, "Transform message is too small (%u)\n",
2278 cifs_reconnect(server
);
2279 wake_up(&server
->response_q
);
2280 return -ECONNABORTED
;
2283 if (pdu_length
+ 4 < orig_len
+ sizeof(struct smb2_transform_hdr
)) {
2284 cifs_dbg(VFS
, "Transform message is broken\n");
2285 cifs_reconnect(server
);
2286 wake_up(&server
->response_q
);
2287 return -ECONNABORTED
;
2290 if (pdu_length
+ 4 > CIFSMaxBufSize
+ MAX_HEADER_SIZE(server
))
2291 return receive_encrypted_read(server
, mid
);
2293 return receive_encrypted_standard(server
, mid
);
2297 smb3_handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
)
2299 char *buf
= server
->large_buf
? server
->bigbuf
: server
->smallbuf
;
2301 return handle_read_data(server
, mid
, buf
, get_rfc1002_length(buf
) + 4,
2305 struct smb_version_operations smb20_operations
= {
2306 .compare_fids
= smb2_compare_fids
,
2307 .setup_request
= smb2_setup_request
,
2308 .setup_async_request
= smb2_setup_async_request
,
2309 .check_receive
= smb2_check_receive
,
2310 .add_credits
= smb2_add_credits
,
2311 .set_credits
= smb2_set_credits
,
2312 .get_credits_field
= smb2_get_credits_field
,
2313 .get_credits
= smb2_get_credits
,
2314 .wait_mtu_credits
= cifs_wait_mtu_credits
,
2315 .get_next_mid
= smb2_get_next_mid
,
2316 .read_data_offset
= smb2_read_data_offset
,
2317 .read_data_length
= smb2_read_data_length
,
2318 .map_error
= map_smb2_to_linux_error
,
2319 .find_mid
= smb2_find_mid
,
2320 .check_message
= smb2_check_message
,
2321 .dump_detail
= smb2_dump_detail
,
2322 .clear_stats
= smb2_clear_stats
,
2323 .print_stats
= smb2_print_stats
,
2324 .is_oplock_break
= smb2_is_valid_oplock_break
,
2325 .downgrade_oplock
= smb2_downgrade_oplock
,
2326 .need_neg
= smb2_need_neg
,
2327 .negotiate
= smb2_negotiate
,
2328 .negotiate_wsize
= smb2_negotiate_wsize
,
2329 .negotiate_rsize
= smb2_negotiate_rsize
,
2330 .sess_setup
= SMB2_sess_setup
,
2331 .logoff
= SMB2_logoff
,
2332 .tree_connect
= SMB2_tcon
,
2333 .tree_disconnect
= SMB2_tdis
,
2334 .qfs_tcon
= smb2_qfs_tcon
,
2335 .is_path_accessible
= smb2_is_path_accessible
,
2336 .can_echo
= smb2_can_echo
,
2338 .query_path_info
= smb2_query_path_info
,
2339 .get_srv_inum
= smb2_get_srv_inum
,
2340 .query_file_info
= smb2_query_file_info
,
2341 .set_path_size
= smb2_set_path_size
,
2342 .set_file_size
= smb2_set_file_size
,
2343 .set_file_info
= smb2_set_file_info
,
2344 .set_compression
= smb2_set_compression
,
2345 .mkdir
= smb2_mkdir
,
2346 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2347 .rmdir
= smb2_rmdir
,
2348 .unlink
= smb2_unlink
,
2349 .rename
= smb2_rename_path
,
2350 .create_hardlink
= smb2_create_hardlink
,
2351 .query_symlink
= smb2_query_symlink
,
2352 .query_mf_symlink
= smb3_query_mf_symlink
,
2353 .create_mf_symlink
= smb3_create_mf_symlink
,
2354 .open
= smb2_open_file
,
2355 .set_fid
= smb2_set_fid
,
2356 .close
= smb2_close_file
,
2357 .flush
= smb2_flush_file
,
2358 .async_readv
= smb2_async_readv
,
2359 .async_writev
= smb2_async_writev
,
2360 .sync_read
= smb2_sync_read
,
2361 .sync_write
= smb2_sync_write
,
2362 .query_dir_first
= smb2_query_dir_first
,
2363 .query_dir_next
= smb2_query_dir_next
,
2364 .close_dir
= smb2_close_dir
,
2365 .calc_smb_size
= smb2_calc_size
,
2366 .is_status_pending
= smb2_is_status_pending
,
2367 .oplock_response
= smb2_oplock_response
,
2368 .queryfs
= smb2_queryfs
,
2369 .mand_lock
= smb2_mand_lock
,
2370 .mand_unlock_range
= smb2_unlock_range
,
2371 .push_mand_locks
= smb2_push_mandatory_locks
,
2372 .get_lease_key
= smb2_get_lease_key
,
2373 .set_lease_key
= smb2_set_lease_key
,
2374 .new_lease_key
= smb2_new_lease_key
,
2375 .calc_signature
= smb2_calc_signature
,
2376 .is_read_op
= smb2_is_read_op
,
2377 .set_oplock_level
= smb2_set_oplock_level
,
2378 .create_lease_buf
= smb2_create_lease_buf
,
2379 .parse_lease_buf
= smb2_parse_lease_buf
,
2380 .clone_range
= smb2_clone_range
,
2381 .wp_retry_size
= smb2_wp_retry_size
,
2382 .dir_needs_close
= smb2_dir_needs_close
,
2383 .get_dfs_refer
= smb2_get_dfs_refer
,
2386 struct smb_version_operations smb21_operations
= {
2387 .compare_fids
= smb2_compare_fids
,
2388 .setup_request
= smb2_setup_request
,
2389 .setup_async_request
= smb2_setup_async_request
,
2390 .check_receive
= smb2_check_receive
,
2391 .add_credits
= smb2_add_credits
,
2392 .set_credits
= smb2_set_credits
,
2393 .get_credits_field
= smb2_get_credits_field
,
2394 .get_credits
= smb2_get_credits
,
2395 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2396 .get_next_mid
= smb2_get_next_mid
,
2397 .read_data_offset
= smb2_read_data_offset
,
2398 .read_data_length
= smb2_read_data_length
,
2399 .map_error
= map_smb2_to_linux_error
,
2400 .find_mid
= smb2_find_mid
,
2401 .check_message
= smb2_check_message
,
2402 .dump_detail
= smb2_dump_detail
,
2403 .clear_stats
= smb2_clear_stats
,
2404 .print_stats
= smb2_print_stats
,
2405 .is_oplock_break
= smb2_is_valid_oplock_break
,
2406 .downgrade_oplock
= smb2_downgrade_oplock
,
2407 .need_neg
= smb2_need_neg
,
2408 .negotiate
= smb2_negotiate
,
2409 .negotiate_wsize
= smb2_negotiate_wsize
,
2410 .negotiate_rsize
= smb2_negotiate_rsize
,
2411 .sess_setup
= SMB2_sess_setup
,
2412 .logoff
= SMB2_logoff
,
2413 .tree_connect
= SMB2_tcon
,
2414 .tree_disconnect
= SMB2_tdis
,
2415 .qfs_tcon
= smb2_qfs_tcon
,
2416 .is_path_accessible
= smb2_is_path_accessible
,
2417 .can_echo
= smb2_can_echo
,
2419 .query_path_info
= smb2_query_path_info
,
2420 .get_srv_inum
= smb2_get_srv_inum
,
2421 .query_file_info
= smb2_query_file_info
,
2422 .set_path_size
= smb2_set_path_size
,
2423 .set_file_size
= smb2_set_file_size
,
2424 .set_file_info
= smb2_set_file_info
,
2425 .set_compression
= smb2_set_compression
,
2426 .mkdir
= smb2_mkdir
,
2427 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2428 .rmdir
= smb2_rmdir
,
2429 .unlink
= smb2_unlink
,
2430 .rename
= smb2_rename_path
,
2431 .create_hardlink
= smb2_create_hardlink
,
2432 .query_symlink
= smb2_query_symlink
,
2433 .query_mf_symlink
= smb3_query_mf_symlink
,
2434 .create_mf_symlink
= smb3_create_mf_symlink
,
2435 .open
= smb2_open_file
,
2436 .set_fid
= smb2_set_fid
,
2437 .close
= smb2_close_file
,
2438 .flush
= smb2_flush_file
,
2439 .async_readv
= smb2_async_readv
,
2440 .async_writev
= smb2_async_writev
,
2441 .sync_read
= smb2_sync_read
,
2442 .sync_write
= smb2_sync_write
,
2443 .query_dir_first
= smb2_query_dir_first
,
2444 .query_dir_next
= smb2_query_dir_next
,
2445 .close_dir
= smb2_close_dir
,
2446 .calc_smb_size
= smb2_calc_size
,
2447 .is_status_pending
= smb2_is_status_pending
,
2448 .oplock_response
= smb2_oplock_response
,
2449 .queryfs
= smb2_queryfs
,
2450 .mand_lock
= smb2_mand_lock
,
2451 .mand_unlock_range
= smb2_unlock_range
,
2452 .push_mand_locks
= smb2_push_mandatory_locks
,
2453 .get_lease_key
= smb2_get_lease_key
,
2454 .set_lease_key
= smb2_set_lease_key
,
2455 .new_lease_key
= smb2_new_lease_key
,
2456 .calc_signature
= smb2_calc_signature
,
2457 .is_read_op
= smb21_is_read_op
,
2458 .set_oplock_level
= smb21_set_oplock_level
,
2459 .create_lease_buf
= smb2_create_lease_buf
,
2460 .parse_lease_buf
= smb2_parse_lease_buf
,
2461 .clone_range
= smb2_clone_range
,
2462 .wp_retry_size
= smb2_wp_retry_size
,
2463 .dir_needs_close
= smb2_dir_needs_close
,
2464 .enum_snapshots
= smb3_enum_snapshots
,
2465 .get_dfs_refer
= smb2_get_dfs_refer
,
2468 struct smb_version_operations smb30_operations
= {
2469 .compare_fids
= smb2_compare_fids
,
2470 .setup_request
= smb2_setup_request
,
2471 .setup_async_request
= smb2_setup_async_request
,
2472 .check_receive
= smb2_check_receive
,
2473 .add_credits
= smb2_add_credits
,
2474 .set_credits
= smb2_set_credits
,
2475 .get_credits_field
= smb2_get_credits_field
,
2476 .get_credits
= smb2_get_credits
,
2477 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2478 .get_next_mid
= smb2_get_next_mid
,
2479 .read_data_offset
= smb2_read_data_offset
,
2480 .read_data_length
= smb2_read_data_length
,
2481 .map_error
= map_smb2_to_linux_error
,
2482 .find_mid
= smb2_find_mid
,
2483 .check_message
= smb2_check_message
,
2484 .dump_detail
= smb2_dump_detail
,
2485 .clear_stats
= smb2_clear_stats
,
2486 .print_stats
= smb2_print_stats
,
2487 .dump_share_caps
= smb2_dump_share_caps
,
2488 .is_oplock_break
= smb2_is_valid_oplock_break
,
2489 .downgrade_oplock
= smb2_downgrade_oplock
,
2490 .need_neg
= smb2_need_neg
,
2491 .negotiate
= smb2_negotiate
,
2492 .negotiate_wsize
= smb2_negotiate_wsize
,
2493 .negotiate_rsize
= smb2_negotiate_rsize
,
2494 .sess_setup
= SMB2_sess_setup
,
2495 .logoff
= SMB2_logoff
,
2496 .tree_connect
= SMB2_tcon
,
2497 .tree_disconnect
= SMB2_tdis
,
2498 .qfs_tcon
= smb3_qfs_tcon
,
2499 .is_path_accessible
= smb2_is_path_accessible
,
2500 .can_echo
= smb2_can_echo
,
2502 .query_path_info
= smb2_query_path_info
,
2503 .get_srv_inum
= smb2_get_srv_inum
,
2504 .query_file_info
= smb2_query_file_info
,
2505 .set_path_size
= smb2_set_path_size
,
2506 .set_file_size
= smb2_set_file_size
,
2507 .set_file_info
= smb2_set_file_info
,
2508 .set_compression
= smb2_set_compression
,
2509 .mkdir
= smb2_mkdir
,
2510 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2511 .rmdir
= smb2_rmdir
,
2512 .unlink
= smb2_unlink
,
2513 .rename
= smb2_rename_path
,
2514 .create_hardlink
= smb2_create_hardlink
,
2515 .query_symlink
= smb2_query_symlink
,
2516 .query_mf_symlink
= smb3_query_mf_symlink
,
2517 .create_mf_symlink
= smb3_create_mf_symlink
,
2518 .open
= smb2_open_file
,
2519 .set_fid
= smb2_set_fid
,
2520 .close
= smb2_close_file
,
2521 .flush
= smb2_flush_file
,
2522 .async_readv
= smb2_async_readv
,
2523 .async_writev
= smb2_async_writev
,
2524 .sync_read
= smb2_sync_read
,
2525 .sync_write
= smb2_sync_write
,
2526 .query_dir_first
= smb2_query_dir_first
,
2527 .query_dir_next
= smb2_query_dir_next
,
2528 .close_dir
= smb2_close_dir
,
2529 .calc_smb_size
= smb2_calc_size
,
2530 .is_status_pending
= smb2_is_status_pending
,
2531 .oplock_response
= smb2_oplock_response
,
2532 .queryfs
= smb2_queryfs
,
2533 .mand_lock
= smb2_mand_lock
,
2534 .mand_unlock_range
= smb2_unlock_range
,
2535 .push_mand_locks
= smb2_push_mandatory_locks
,
2536 .get_lease_key
= smb2_get_lease_key
,
2537 .set_lease_key
= smb2_set_lease_key
,
2538 .new_lease_key
= smb2_new_lease_key
,
2539 .generate_signingkey
= generate_smb30signingkey
,
2540 .calc_signature
= smb3_calc_signature
,
2541 .set_integrity
= smb3_set_integrity
,
2542 .is_read_op
= smb21_is_read_op
,
2543 .set_oplock_level
= smb3_set_oplock_level
,
2544 .create_lease_buf
= smb3_create_lease_buf
,
2545 .parse_lease_buf
= smb3_parse_lease_buf
,
2546 .clone_range
= smb2_clone_range
,
2547 .duplicate_extents
= smb2_duplicate_extents
,
2548 .validate_negotiate
= smb3_validate_negotiate
,
2549 .wp_retry_size
= smb2_wp_retry_size
,
2550 .dir_needs_close
= smb2_dir_needs_close
,
2551 .fallocate
= smb3_fallocate
,
2552 .enum_snapshots
= smb3_enum_snapshots
,
2553 .init_transform_rq
= smb3_init_transform_rq
,
2554 .free_transform_rq
= smb3_free_transform_rq
,
2555 .is_transform_hdr
= smb3_is_transform_hdr
,
2556 .receive_transform
= smb3_receive_transform
,
2557 .get_dfs_refer
= smb2_get_dfs_refer
,
2560 #ifdef CONFIG_CIFS_SMB311
2561 struct smb_version_operations smb311_operations
= {
2562 .compare_fids
= smb2_compare_fids
,
2563 .setup_request
= smb2_setup_request
,
2564 .setup_async_request
= smb2_setup_async_request
,
2565 .check_receive
= smb2_check_receive
,
2566 .add_credits
= smb2_add_credits
,
2567 .set_credits
= smb2_set_credits
,
2568 .get_credits_field
= smb2_get_credits_field
,
2569 .get_credits
= smb2_get_credits
,
2570 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2571 .get_next_mid
= smb2_get_next_mid
,
2572 .read_data_offset
= smb2_read_data_offset
,
2573 .read_data_length
= smb2_read_data_length
,
2574 .map_error
= map_smb2_to_linux_error
,
2575 .find_mid
= smb2_find_mid
,
2576 .check_message
= smb2_check_message
,
2577 .dump_detail
= smb2_dump_detail
,
2578 .clear_stats
= smb2_clear_stats
,
2579 .print_stats
= smb2_print_stats
,
2580 .dump_share_caps
= smb2_dump_share_caps
,
2581 .is_oplock_break
= smb2_is_valid_oplock_break
,
2582 .downgrade_oplock
= smb2_downgrade_oplock
,
2583 .need_neg
= smb2_need_neg
,
2584 .negotiate
= smb2_negotiate
,
2585 .negotiate_wsize
= smb2_negotiate_wsize
,
2586 .negotiate_rsize
= smb2_negotiate_rsize
,
2587 .sess_setup
= SMB2_sess_setup
,
2588 .logoff
= SMB2_logoff
,
2589 .tree_connect
= SMB2_tcon
,
2590 .tree_disconnect
= SMB2_tdis
,
2591 .qfs_tcon
= smb3_qfs_tcon
,
2592 .is_path_accessible
= smb2_is_path_accessible
,
2593 .can_echo
= smb2_can_echo
,
2595 .query_path_info
= smb2_query_path_info
,
2596 .get_srv_inum
= smb2_get_srv_inum
,
2597 .query_file_info
= smb2_query_file_info
,
2598 .set_path_size
= smb2_set_path_size
,
2599 .set_file_size
= smb2_set_file_size
,
2600 .set_file_info
= smb2_set_file_info
,
2601 .set_compression
= smb2_set_compression
,
2602 .mkdir
= smb2_mkdir
,
2603 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2604 .rmdir
= smb2_rmdir
,
2605 .unlink
= smb2_unlink
,
2606 .rename
= smb2_rename_path
,
2607 .create_hardlink
= smb2_create_hardlink
,
2608 .query_symlink
= smb2_query_symlink
,
2609 .query_mf_symlink
= smb3_query_mf_symlink
,
2610 .create_mf_symlink
= smb3_create_mf_symlink
,
2611 .open
= smb2_open_file
,
2612 .set_fid
= smb2_set_fid
,
2613 .close
= smb2_close_file
,
2614 .flush
= smb2_flush_file
,
2615 .async_readv
= smb2_async_readv
,
2616 .async_writev
= smb2_async_writev
,
2617 .sync_read
= smb2_sync_read
,
2618 .sync_write
= smb2_sync_write
,
2619 .query_dir_first
= smb2_query_dir_first
,
2620 .query_dir_next
= smb2_query_dir_next
,
2621 .close_dir
= smb2_close_dir
,
2622 .calc_smb_size
= smb2_calc_size
,
2623 .is_status_pending
= smb2_is_status_pending
,
2624 .oplock_response
= smb2_oplock_response
,
2625 .queryfs
= smb2_queryfs
,
2626 .mand_lock
= smb2_mand_lock
,
2627 .mand_unlock_range
= smb2_unlock_range
,
2628 .push_mand_locks
= smb2_push_mandatory_locks
,
2629 .get_lease_key
= smb2_get_lease_key
,
2630 .set_lease_key
= smb2_set_lease_key
,
2631 .new_lease_key
= smb2_new_lease_key
,
2632 .generate_signingkey
= generate_smb311signingkey
,
2633 .calc_signature
= smb3_calc_signature
,
2634 .set_integrity
= smb3_set_integrity
,
2635 .is_read_op
= smb21_is_read_op
,
2636 .set_oplock_level
= smb3_set_oplock_level
,
2637 .create_lease_buf
= smb3_create_lease_buf
,
2638 .parse_lease_buf
= smb3_parse_lease_buf
,
2639 .clone_range
= smb2_clone_range
,
2640 .duplicate_extents
= smb2_duplicate_extents
,
2641 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
2642 .wp_retry_size
= smb2_wp_retry_size
,
2643 .dir_needs_close
= smb2_dir_needs_close
,
2644 .fallocate
= smb3_fallocate
,
2645 .enum_snapshots
= smb3_enum_snapshots
,
2646 .init_transform_rq
= smb3_init_transform_rq
,
2647 .free_transform_rq
= smb3_free_transform_rq
,
2648 .is_transform_hdr
= smb3_is_transform_hdr
,
2649 .receive_transform
= smb3_receive_transform
,
2650 .get_dfs_refer
= smb2_get_dfs_refer
,
2652 #endif /* CIFS_SMB311 */
2654 struct smb_version_values smb20_values
= {
2655 .version_string
= SMB20_VERSION_STRING
,
2656 .protocol_id
= SMB20_PROT_ID
,
2657 .req_capabilities
= 0, /* MBZ */
2658 .large_lock_type
= 0,
2659 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2660 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2661 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2662 .header_size
= sizeof(struct smb2_hdr
),
2663 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2664 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2665 .lock_cmd
= SMB2_LOCK
,
2667 .cap_nt_find
= SMB2_NT_FIND
,
2668 .cap_large_files
= SMB2_LARGE_FILES
,
2669 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2670 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2671 .create_lease_size
= sizeof(struct create_lease
),
2674 struct smb_version_values smb21_values
= {
2675 .version_string
= SMB21_VERSION_STRING
,
2676 .protocol_id
= SMB21_PROT_ID
,
2677 .req_capabilities
= 0, /* MBZ on negotiate req until SMB3 dialect */
2678 .large_lock_type
= 0,
2679 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2680 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2681 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2682 .header_size
= sizeof(struct smb2_hdr
),
2683 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2684 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2685 .lock_cmd
= SMB2_LOCK
,
2687 .cap_nt_find
= SMB2_NT_FIND
,
2688 .cap_large_files
= SMB2_LARGE_FILES
,
2689 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2690 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2691 .create_lease_size
= sizeof(struct create_lease
),
2694 struct smb_version_values smb30_values
= {
2695 .version_string
= SMB30_VERSION_STRING
,
2696 .protocol_id
= SMB30_PROT_ID
,
2697 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
2698 .large_lock_type
= 0,
2699 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2700 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2701 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2702 .header_size
= sizeof(struct smb2_hdr
),
2703 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2704 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2705 .lock_cmd
= SMB2_LOCK
,
2707 .cap_nt_find
= SMB2_NT_FIND
,
2708 .cap_large_files
= SMB2_LARGE_FILES
,
2709 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2710 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2711 .create_lease_size
= sizeof(struct create_lease_v2
),
2714 struct smb_version_values smb302_values
= {
2715 .version_string
= SMB302_VERSION_STRING
,
2716 .protocol_id
= SMB302_PROT_ID
,
2717 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
2718 .large_lock_type
= 0,
2719 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2720 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2721 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2722 .header_size
= sizeof(struct smb2_hdr
),
2723 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2724 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2725 .lock_cmd
= SMB2_LOCK
,
2727 .cap_nt_find
= SMB2_NT_FIND
,
2728 .cap_large_files
= SMB2_LARGE_FILES
,
2729 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2730 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2731 .create_lease_size
= sizeof(struct create_lease_v2
),
2734 #ifdef CONFIG_CIFS_SMB311
2735 struct smb_version_values smb311_values
= {
2736 .version_string
= SMB311_VERSION_STRING
,
2737 .protocol_id
= SMB311_PROT_ID
,
2738 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
,
2739 .large_lock_type
= 0,
2740 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2741 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2742 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2743 .header_size
= sizeof(struct smb2_hdr
),
2744 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2745 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2746 .lock_cmd
= SMB2_LOCK
,
2748 .cap_nt_find
= SMB2_NT_FIND
,
2749 .cap_large_files
= SMB2_LARGE_FILES
,
2750 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2751 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2752 .create_lease_size
= sizeof(struct create_lease_v2
),