2 * SMB2 version specific operations
4 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
6 * This library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License v2 as published
8 * by the Free Software Foundation.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/pagemap.h>
21 #include <linux/vfs.h>
22 #include <linux/falloc.h>
23 #include <linux/scatterlist.h>
24 #include <linux/uuid.h>
25 #include <crypto/aead.h>
28 #include "smb2proto.h"
29 #include "cifsproto.h"
30 #include "cifs_debug.h"
31 #include "cifs_unicode.h"
32 #include "smb2status.h"
34 #include "cifs_ioctl.h"
37 change_conf(struct TCP_Server_Info
*server
)
39 server
->credits
+= server
->echo_credits
+ server
->oplock_credits
;
40 server
->oplock_credits
= server
->echo_credits
= 0;
41 switch (server
->credits
) {
45 server
->echoes
= false;
46 server
->oplocks
= false;
47 cifs_dbg(VFS
, "disabling echoes and oplocks\n");
50 server
->echoes
= true;
51 server
->oplocks
= false;
52 server
->echo_credits
= 1;
53 cifs_dbg(FYI
, "disabling oplocks\n");
56 server
->echoes
= true;
58 server
->oplocks
= true;
59 server
->oplock_credits
= 1;
61 server
->oplocks
= false;
63 server
->echo_credits
= 1;
65 server
->credits
-= server
->echo_credits
+ server
->oplock_credits
;
70 smb2_add_credits(struct TCP_Server_Info
*server
, const unsigned int add
,
74 spin_lock(&server
->req_lock
);
75 val
= server
->ops
->get_credits_field(server
, optype
);
78 *val
= 65000; /* Don't get near 64K credits, avoid srv bugs */
79 printk_once(KERN_WARNING
"server overflowed SMB3 credits\n");
82 if (server
->in_flight
== 0 && (optype
& CIFS_OP_MASK
) != CIFS_NEG_OP
)
83 rc
= change_conf(server
);
85 * Sometimes server returns 0 credits on oplock break ack - we need to
86 * rebalance credits in this case.
88 else if (server
->in_flight
> 0 && server
->oplock_credits
== 0 &&
90 if (server
->credits
> 1) {
92 server
->oplock_credits
++;
95 spin_unlock(&server
->req_lock
);
96 wake_up(&server
->request_q
);
98 cifs_reconnect(server
);
102 smb2_set_credits(struct TCP_Server_Info
*server
, const int val
)
104 spin_lock(&server
->req_lock
);
105 server
->credits
= val
;
106 spin_unlock(&server
->req_lock
);
110 smb2_get_credits_field(struct TCP_Server_Info
*server
, const int optype
)
114 return &server
->echo_credits
;
116 return &server
->oplock_credits
;
118 return &server
->credits
;
123 smb2_get_credits(struct mid_q_entry
*mid
)
125 struct smb2_sync_hdr
*shdr
= get_sync_hdr(mid
->resp_buf
);
127 return le16_to_cpu(shdr
->CreditRequest
);
131 smb2_wait_mtu_credits(struct TCP_Server_Info
*server
, unsigned int size
,
132 unsigned int *num
, unsigned int *credits
)
135 unsigned int scredits
;
137 spin_lock(&server
->req_lock
);
139 if (server
->credits
<= 0) {
140 spin_unlock(&server
->req_lock
);
141 cifs_num_waiters_inc(server
);
142 rc
= wait_event_killable(server
->request_q
,
143 has_credits(server
, &server
->credits
));
144 cifs_num_waiters_dec(server
);
147 spin_lock(&server
->req_lock
);
149 if (server
->tcpStatus
== CifsExiting
) {
150 spin_unlock(&server
->req_lock
);
154 scredits
= server
->credits
;
155 /* can deadlock with reopen */
157 *num
= SMB2_MAX_BUFFER_SIZE
;
162 /* leave one credit for a possible reopen */
164 *num
= min_t(unsigned int, size
,
165 scredits
* SMB2_MAX_BUFFER_SIZE
);
167 *credits
= DIV_ROUND_UP(*num
, SMB2_MAX_BUFFER_SIZE
);
168 server
->credits
-= *credits
;
173 spin_unlock(&server
->req_lock
);
178 smb2_get_next_mid(struct TCP_Server_Info
*server
)
181 /* for SMB2 we need the current value */
182 spin_lock(&GlobalMid_Lock
);
183 mid
= server
->CurrentMid
++;
184 spin_unlock(&GlobalMid_Lock
);
188 static struct mid_q_entry
*
189 smb2_find_mid(struct TCP_Server_Info
*server
, char *buf
)
191 struct mid_q_entry
*mid
;
192 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
193 __u64 wire_mid
= le64_to_cpu(shdr
->MessageId
);
195 if (shdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
) {
196 cifs_dbg(VFS
, "encrypted frame parsing not supported yet");
200 spin_lock(&GlobalMid_Lock
);
201 list_for_each_entry(mid
, &server
->pending_mid_q
, qhead
) {
202 if ((mid
->mid
== wire_mid
) &&
203 (mid
->mid_state
== MID_REQUEST_SUBMITTED
) &&
204 (mid
->command
== shdr
->Command
)) {
205 spin_unlock(&GlobalMid_Lock
);
209 spin_unlock(&GlobalMid_Lock
);
214 smb2_dump_detail(void *buf
)
216 #ifdef CONFIG_CIFS_DEBUG2
217 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
219 cifs_dbg(VFS
, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
220 shdr
->Command
, shdr
->Status
, shdr
->Flags
, shdr
->MessageId
,
222 cifs_dbg(VFS
, "smb buf %p len %u\n", buf
, smb2_calc_size(buf
));
227 smb2_need_neg(struct TCP_Server_Info
*server
)
229 return server
->max_read
== 0;
233 smb2_negotiate(const unsigned int xid
, struct cifs_ses
*ses
)
236 ses
->server
->CurrentMid
= 0;
237 rc
= SMB2_negotiate(xid
, ses
);
238 /* BB we probably don't need to retry with modern servers */
245 smb2_negotiate_wsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
247 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
250 /* start with specified wsize, or default */
251 wsize
= volume_info
->wsize
? volume_info
->wsize
: CIFS_DEFAULT_IOSIZE
;
252 wsize
= min_t(unsigned int, wsize
, server
->max_write
);
254 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
255 wsize
= min_t(unsigned int, wsize
, SMB2_MAX_BUFFER_SIZE
);
261 smb2_negotiate_rsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
263 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
266 /* start with specified rsize, or default */
267 rsize
= volume_info
->rsize
? volume_info
->rsize
: CIFS_DEFAULT_IOSIZE
;
268 rsize
= min_t(unsigned int, rsize
, server
->max_read
);
270 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
271 rsize
= min_t(unsigned int, rsize
, SMB2_MAX_BUFFER_SIZE
);
276 #ifdef CONFIG_CIFS_STATS2
278 SMB3_request_interfaces(const unsigned int xid
, struct cifs_tcon
*tcon
)
281 unsigned int ret_data_len
= 0;
282 struct network_interface_info_ioctl_rsp
*out_buf
;
284 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
285 FSCTL_QUERY_NETWORK_INTERFACE_INFO
, true /* is_fsctl */,
287 NULL
/* no data input */, 0 /* no data input */,
288 (char **)&out_buf
, &ret_data_len
);
290 cifs_dbg(VFS
, "error %d on ioctl to get interface list\n", rc
);
291 else if (ret_data_len
< sizeof(struct network_interface_info_ioctl_rsp
)) {
292 cifs_dbg(VFS
, "server returned bad net interface info buf\n");
295 /* Dump info on first interface */
296 cifs_dbg(FYI
, "Adapter Capability 0x%x\t",
297 le32_to_cpu(out_buf
->Capability
));
298 cifs_dbg(FYI
, "Link Speed %lld\n",
299 le64_to_cpu(out_buf
->LinkSpeed
));
307 smb3_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
310 __le16 srch_path
= 0; /* Null - open root of share */
311 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
312 struct cifs_open_parms oparms
;
316 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
317 oparms
.disposition
= FILE_OPEN
;
318 oparms
.create_options
= 0;
320 oparms
.reconnect
= false;
322 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
326 #ifdef CONFIG_CIFS_STATS2
327 SMB3_request_interfaces(xid
, tcon
);
330 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
331 FS_ATTRIBUTE_INFORMATION
);
332 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
333 FS_DEVICE_INFORMATION
);
334 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
335 FS_SECTOR_SIZE_INFORMATION
); /* SMB3 specific */
336 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
341 smb2_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
344 __le16 srch_path
= 0; /* Null - open root of share */
345 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
346 struct cifs_open_parms oparms
;
350 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
351 oparms
.disposition
= FILE_OPEN
;
352 oparms
.create_options
= 0;
354 oparms
.reconnect
= false;
356 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
360 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
361 FS_ATTRIBUTE_INFORMATION
);
362 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
363 FS_DEVICE_INFORMATION
);
364 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
369 smb2_is_path_accessible(const unsigned int xid
, struct cifs_tcon
*tcon
,
370 struct cifs_sb_info
*cifs_sb
, const char *full_path
)
374 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
375 struct cifs_open_parms oparms
;
378 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
383 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
384 oparms
.disposition
= FILE_OPEN
;
385 oparms
.create_options
= 0;
387 oparms
.reconnect
= false;
389 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
395 rc
= SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
401 smb2_get_srv_inum(const unsigned int xid
, struct cifs_tcon
*tcon
,
402 struct cifs_sb_info
*cifs_sb
, const char *full_path
,
403 u64
*uniqueid
, FILE_ALL_INFO
*data
)
405 *uniqueid
= le64_to_cpu(data
->IndexNumber
);
410 smb2_query_file_info(const unsigned int xid
, struct cifs_tcon
*tcon
,
411 struct cifs_fid
*fid
, FILE_ALL_INFO
*data
)
414 struct smb2_file_all_info
*smb2_data
;
416 smb2_data
= kzalloc(sizeof(struct smb2_file_all_info
) + PATH_MAX
* 2,
418 if (smb2_data
== NULL
)
421 rc
= SMB2_query_info(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
,
424 move_smb2_info_to_cifs(data
, smb2_data
);
430 smb2_can_echo(struct TCP_Server_Info
*server
)
432 return server
->echoes
;
436 smb2_clear_stats(struct cifs_tcon
*tcon
)
438 #ifdef CONFIG_CIFS_STATS
440 for (i
= 0; i
< NUMBER_OF_SMB2_COMMANDS
; i
++) {
441 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_sent
[i
], 0);
442 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_failed
[i
], 0);
448 smb2_dump_share_caps(struct seq_file
*m
, struct cifs_tcon
*tcon
)
450 seq_puts(m
, "\n\tShare Capabilities:");
451 if (tcon
->capabilities
& SMB2_SHARE_CAP_DFS
)
452 seq_puts(m
, " DFS,");
453 if (tcon
->capabilities
& SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY
)
454 seq_puts(m
, " CONTINUOUS AVAILABILITY,");
455 if (tcon
->capabilities
& SMB2_SHARE_CAP_SCALEOUT
)
456 seq_puts(m
, " SCALEOUT,");
457 if (tcon
->capabilities
& SMB2_SHARE_CAP_CLUSTER
)
458 seq_puts(m
, " CLUSTER,");
459 if (tcon
->capabilities
& SMB2_SHARE_CAP_ASYMMETRIC
)
460 seq_puts(m
, " ASYMMETRIC,");
461 if (tcon
->capabilities
== 0)
462 seq_puts(m
, " None");
463 if (tcon
->ss_flags
& SSINFO_FLAGS_ALIGNED_DEVICE
)
464 seq_puts(m
, " Aligned,");
465 if (tcon
->ss_flags
& SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE
)
466 seq_puts(m
, " Partition Aligned,");
467 if (tcon
->ss_flags
& SSINFO_FLAGS_NO_SEEK_PENALTY
)
468 seq_puts(m
, " SSD,");
469 if (tcon
->ss_flags
& SSINFO_FLAGS_TRIM_ENABLED
)
470 seq_puts(m
, " TRIM-support,");
472 seq_printf(m
, "\tShare Flags: 0x%x", tcon
->share_flags
);
473 if (tcon
->perf_sector_size
)
474 seq_printf(m
, "\tOptimal sector size: 0x%x",
475 tcon
->perf_sector_size
);
479 smb2_print_stats(struct seq_file
*m
, struct cifs_tcon
*tcon
)
481 #ifdef CONFIG_CIFS_STATS
482 atomic_t
*sent
= tcon
->stats
.smb2_stats
.smb2_com_sent
;
483 atomic_t
*failed
= tcon
->stats
.smb2_stats
.smb2_com_failed
;
484 seq_printf(m
, "\nNegotiates: %d sent %d failed",
485 atomic_read(&sent
[SMB2_NEGOTIATE_HE
]),
486 atomic_read(&failed
[SMB2_NEGOTIATE_HE
]));
487 seq_printf(m
, "\nSessionSetups: %d sent %d failed",
488 atomic_read(&sent
[SMB2_SESSION_SETUP_HE
]),
489 atomic_read(&failed
[SMB2_SESSION_SETUP_HE
]));
490 seq_printf(m
, "\nLogoffs: %d sent %d failed",
491 atomic_read(&sent
[SMB2_LOGOFF_HE
]),
492 atomic_read(&failed
[SMB2_LOGOFF_HE
]));
493 seq_printf(m
, "\nTreeConnects: %d sent %d failed",
494 atomic_read(&sent
[SMB2_TREE_CONNECT_HE
]),
495 atomic_read(&failed
[SMB2_TREE_CONNECT_HE
]));
496 seq_printf(m
, "\nTreeDisconnects: %d sent %d failed",
497 atomic_read(&sent
[SMB2_TREE_DISCONNECT_HE
]),
498 atomic_read(&failed
[SMB2_TREE_DISCONNECT_HE
]));
499 seq_printf(m
, "\nCreates: %d sent %d failed",
500 atomic_read(&sent
[SMB2_CREATE_HE
]),
501 atomic_read(&failed
[SMB2_CREATE_HE
]));
502 seq_printf(m
, "\nCloses: %d sent %d failed",
503 atomic_read(&sent
[SMB2_CLOSE_HE
]),
504 atomic_read(&failed
[SMB2_CLOSE_HE
]));
505 seq_printf(m
, "\nFlushes: %d sent %d failed",
506 atomic_read(&sent
[SMB2_FLUSH_HE
]),
507 atomic_read(&failed
[SMB2_FLUSH_HE
]));
508 seq_printf(m
, "\nReads: %d sent %d failed",
509 atomic_read(&sent
[SMB2_READ_HE
]),
510 atomic_read(&failed
[SMB2_READ_HE
]));
511 seq_printf(m
, "\nWrites: %d sent %d failed",
512 atomic_read(&sent
[SMB2_WRITE_HE
]),
513 atomic_read(&failed
[SMB2_WRITE_HE
]));
514 seq_printf(m
, "\nLocks: %d sent %d failed",
515 atomic_read(&sent
[SMB2_LOCK_HE
]),
516 atomic_read(&failed
[SMB2_LOCK_HE
]));
517 seq_printf(m
, "\nIOCTLs: %d sent %d failed",
518 atomic_read(&sent
[SMB2_IOCTL_HE
]),
519 atomic_read(&failed
[SMB2_IOCTL_HE
]));
520 seq_printf(m
, "\nCancels: %d sent %d failed",
521 atomic_read(&sent
[SMB2_CANCEL_HE
]),
522 atomic_read(&failed
[SMB2_CANCEL_HE
]));
523 seq_printf(m
, "\nEchos: %d sent %d failed",
524 atomic_read(&sent
[SMB2_ECHO_HE
]),
525 atomic_read(&failed
[SMB2_ECHO_HE
]));
526 seq_printf(m
, "\nQueryDirectories: %d sent %d failed",
527 atomic_read(&sent
[SMB2_QUERY_DIRECTORY_HE
]),
528 atomic_read(&failed
[SMB2_QUERY_DIRECTORY_HE
]));
529 seq_printf(m
, "\nChangeNotifies: %d sent %d failed",
530 atomic_read(&sent
[SMB2_CHANGE_NOTIFY_HE
]),
531 atomic_read(&failed
[SMB2_CHANGE_NOTIFY_HE
]));
532 seq_printf(m
, "\nQueryInfos: %d sent %d failed",
533 atomic_read(&sent
[SMB2_QUERY_INFO_HE
]),
534 atomic_read(&failed
[SMB2_QUERY_INFO_HE
]));
535 seq_printf(m
, "\nSetInfos: %d sent %d failed",
536 atomic_read(&sent
[SMB2_SET_INFO_HE
]),
537 atomic_read(&failed
[SMB2_SET_INFO_HE
]));
538 seq_printf(m
, "\nOplockBreaks: %d sent %d failed",
539 atomic_read(&sent
[SMB2_OPLOCK_BREAK_HE
]),
540 atomic_read(&failed
[SMB2_OPLOCK_BREAK_HE
]));
545 smb2_set_fid(struct cifsFileInfo
*cfile
, struct cifs_fid
*fid
, __u32 oplock
)
547 struct cifsInodeInfo
*cinode
= CIFS_I(d_inode(cfile
->dentry
));
548 struct TCP_Server_Info
*server
= tlink_tcon(cfile
->tlink
)->ses
->server
;
550 cfile
->fid
.persistent_fid
= fid
->persistent_fid
;
551 cfile
->fid
.volatile_fid
= fid
->volatile_fid
;
552 server
->ops
->set_oplock_level(cinode
, oplock
, fid
->epoch
,
554 cinode
->can_cache_brlcks
= CIFS_CACHE_WRITE(cinode
);
555 memcpy(cfile
->fid
.create_guid
, fid
->create_guid
, 16);
559 smb2_close_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
560 struct cifs_fid
*fid
)
562 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
566 SMB2_request_res_key(const unsigned int xid
, struct cifs_tcon
*tcon
,
567 u64 persistent_fid
, u64 volatile_fid
,
568 struct copychunk_ioctl
*pcchunk
)
571 unsigned int ret_data_len
;
572 struct resume_key_req
*res_key
;
574 rc
= SMB2_ioctl(xid
, tcon
, persistent_fid
, volatile_fid
,
575 FSCTL_SRV_REQUEST_RESUME_KEY
, true /* is_fsctl */,
577 NULL
, 0 /* no input */,
578 (char **)&res_key
, &ret_data_len
);
581 cifs_dbg(VFS
, "refcpy ioctl error %d getting resume key\n", rc
);
582 goto req_res_key_exit
;
584 if (ret_data_len
< sizeof(struct resume_key_req
)) {
585 cifs_dbg(VFS
, "Invalid refcopy resume key length\n");
587 goto req_res_key_exit
;
589 memcpy(pcchunk
->SourceKey
, res_key
->ResumeKey
, COPY_CHUNK_RES_KEY_SIZE
);
597 smb2_copychunk_range(const unsigned int xid
,
598 struct cifsFileInfo
*srcfile
,
599 struct cifsFileInfo
*trgtfile
, u64 src_off
,
600 u64 len
, u64 dest_off
)
603 unsigned int ret_data_len
;
604 struct copychunk_ioctl
*pcchunk
;
605 struct copychunk_ioctl_rsp
*retbuf
= NULL
;
606 struct cifs_tcon
*tcon
;
607 int chunks_copied
= 0;
608 bool chunk_sizes_updated
= false;
609 ssize_t bytes_written
, total_bytes_written
= 0;
611 pcchunk
= kmalloc(sizeof(struct copychunk_ioctl
), GFP_KERNEL
);
616 cifs_dbg(FYI
, "in smb2_copychunk_range - about to call request res key\n");
617 /* Request a key from the server to identify the source of the copy */
618 rc
= SMB2_request_res_key(xid
, tlink_tcon(srcfile
->tlink
),
619 srcfile
->fid
.persistent_fid
,
620 srcfile
->fid
.volatile_fid
, pcchunk
);
622 /* Note: request_res_key sets res_key null only if rc !=0 */
626 /* For now array only one chunk long, will make more flexible later */
627 pcchunk
->ChunkCount
= cpu_to_le32(1);
628 pcchunk
->Reserved
= 0;
629 pcchunk
->Reserved2
= 0;
631 tcon
= tlink_tcon(trgtfile
->tlink
);
634 pcchunk
->SourceOffset
= cpu_to_le64(src_off
);
635 pcchunk
->TargetOffset
= cpu_to_le64(dest_off
);
637 cpu_to_le32(min_t(u32
, len
, tcon
->max_bytes_chunk
));
639 /* Request server copy to target from src identified by key */
640 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
641 trgtfile
->fid
.volatile_fid
, FSCTL_SRV_COPYCHUNK_WRITE
,
642 true /* is_fsctl */, false /* use_ipc */,
644 sizeof(struct copychunk_ioctl
), (char **)&retbuf
,
648 sizeof(struct copychunk_ioctl_rsp
)) {
649 cifs_dbg(VFS
, "invalid cchunk response size\n");
653 if (retbuf
->TotalBytesWritten
== 0) {
654 cifs_dbg(FYI
, "no bytes copied\n");
659 * Check if server claimed to write more than we asked
661 if (le32_to_cpu(retbuf
->TotalBytesWritten
) >
662 le32_to_cpu(pcchunk
->Length
)) {
663 cifs_dbg(VFS
, "invalid copy chunk response\n");
667 if (le32_to_cpu(retbuf
->ChunksWritten
) != 1) {
668 cifs_dbg(VFS
, "invalid num chunks written\n");
674 bytes_written
= le32_to_cpu(retbuf
->TotalBytesWritten
);
675 src_off
+= bytes_written
;
676 dest_off
+= bytes_written
;
677 len
-= bytes_written
;
678 total_bytes_written
+= bytes_written
;
680 cifs_dbg(FYI
, "Chunks %d PartialChunk %d Total %zu\n",
681 le32_to_cpu(retbuf
->ChunksWritten
),
682 le32_to_cpu(retbuf
->ChunkBytesWritten
),
684 } else if (rc
== -EINVAL
) {
685 if (ret_data_len
!= sizeof(struct copychunk_ioctl_rsp
))
688 cifs_dbg(FYI
, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
689 le32_to_cpu(retbuf
->ChunksWritten
),
690 le32_to_cpu(retbuf
->ChunkBytesWritten
),
691 le32_to_cpu(retbuf
->TotalBytesWritten
));
694 * Check if this is the first request using these sizes,
695 * (ie check if copy succeed once with original sizes
696 * and check if the server gave us different sizes after
697 * we already updated max sizes on previous request).
698 * if not then why is the server returning an error now
700 if ((chunks_copied
!= 0) || chunk_sizes_updated
)
703 /* Check that server is not asking us to grow size */
704 if (le32_to_cpu(retbuf
->ChunkBytesWritten
) <
705 tcon
->max_bytes_chunk
)
706 tcon
->max_bytes_chunk
=
707 le32_to_cpu(retbuf
->ChunkBytesWritten
);
709 goto cchunk_out
; /* server gave us bogus size */
711 /* No need to change MaxChunks since already set to 1 */
712 chunk_sizes_updated
= true;
723 return total_bytes_written
;
727 smb2_flush_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
728 struct cifs_fid
*fid
)
730 return SMB2_flush(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
734 smb2_read_data_offset(char *buf
)
736 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
737 return rsp
->DataOffset
;
741 smb2_read_data_length(char *buf
)
743 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
744 return le32_to_cpu(rsp
->DataLength
);
749 smb2_sync_read(const unsigned int xid
, struct cifs_fid
*pfid
,
750 struct cifs_io_parms
*parms
, unsigned int *bytes_read
,
751 char **buf
, int *buf_type
)
753 parms
->persistent_fid
= pfid
->persistent_fid
;
754 parms
->volatile_fid
= pfid
->volatile_fid
;
755 return SMB2_read(xid
, parms
, bytes_read
, buf
, buf_type
);
759 smb2_sync_write(const unsigned int xid
, struct cifs_fid
*pfid
,
760 struct cifs_io_parms
*parms
, unsigned int *written
,
761 struct kvec
*iov
, unsigned long nr_segs
)
764 parms
->persistent_fid
= pfid
->persistent_fid
;
765 parms
->volatile_fid
= pfid
->volatile_fid
;
766 return SMB2_write(xid
, parms
, written
, iov
, nr_segs
);
769 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
770 static bool smb2_set_sparse(const unsigned int xid
, struct cifs_tcon
*tcon
,
771 struct cifsFileInfo
*cfile
, struct inode
*inode
, __u8 setsparse
)
773 struct cifsInodeInfo
*cifsi
;
776 cifsi
= CIFS_I(inode
);
778 /* if file already sparse don't bother setting sparse again */
779 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && setsparse
)
780 return true; /* already sparse */
782 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && !setsparse
)
783 return true; /* already not sparse */
786 * Can't check for sparse support on share the usual way via the
787 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
788 * since Samba server doesn't set the flag on the share, yet
789 * supports the set sparse FSCTL and returns sparse correctly
790 * in the file attributes. If we fail setting sparse though we
791 * mark that server does not support sparse files for this share
792 * to avoid repeatedly sending the unsupported fsctl to server
793 * if the file is repeatedly extended.
795 if (tcon
->broken_sparse_sup
)
798 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
799 cfile
->fid
.volatile_fid
, FSCTL_SET_SPARSE
,
800 true /* is_fctl */, false /* use_ipc */,
801 &setsparse
, 1, NULL
, NULL
);
803 tcon
->broken_sparse_sup
= true;
804 cifs_dbg(FYI
, "set sparse rc = %d\n", rc
);
809 cifsi
->cifsAttrs
|= FILE_ATTRIBUTE_SPARSE_FILE
;
811 cifsi
->cifsAttrs
&= (~FILE_ATTRIBUTE_SPARSE_FILE
);
817 smb2_set_file_size(const unsigned int xid
, struct cifs_tcon
*tcon
,
818 struct cifsFileInfo
*cfile
, __u64 size
, bool set_alloc
)
820 __le64 eof
= cpu_to_le64(size
);
824 * If extending file more than one page make sparse. Many Linux fs
825 * make files sparse by default when extending via ftruncate
827 inode
= d_inode(cfile
->dentry
);
829 if (!set_alloc
&& (size
> inode
->i_size
+ 8192)) {
832 /* whether set sparse succeeds or not, extend the file */
833 smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
);
836 return SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
837 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
, false);
841 smb2_duplicate_extents(const unsigned int xid
,
842 struct cifsFileInfo
*srcfile
,
843 struct cifsFileInfo
*trgtfile
, u64 src_off
,
844 u64 len
, u64 dest_off
)
847 unsigned int ret_data_len
;
848 struct duplicate_extents_to_file dup_ext_buf
;
849 struct cifs_tcon
*tcon
= tlink_tcon(trgtfile
->tlink
);
851 /* server fileays advertise duplicate extent support with this flag */
852 if ((le32_to_cpu(tcon
->fsAttrInfo
.Attributes
) &
853 FILE_SUPPORTS_BLOCK_REFCOUNTING
) == 0)
856 dup_ext_buf
.VolatileFileHandle
= srcfile
->fid
.volatile_fid
;
857 dup_ext_buf
.PersistentFileHandle
= srcfile
->fid
.persistent_fid
;
858 dup_ext_buf
.SourceFileOffset
= cpu_to_le64(src_off
);
859 dup_ext_buf
.TargetFileOffset
= cpu_to_le64(dest_off
);
860 dup_ext_buf
.ByteCount
= cpu_to_le64(len
);
861 cifs_dbg(FYI
, "duplicate extents: src off %lld dst off %lld len %lld",
862 src_off
, dest_off
, len
);
864 rc
= smb2_set_file_size(xid
, tcon
, trgtfile
, dest_off
+ len
, false);
866 goto duplicate_extents_out
;
868 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
869 trgtfile
->fid
.volatile_fid
,
870 FSCTL_DUPLICATE_EXTENTS_TO_FILE
,
871 true /* is_fsctl */, false /* use_ipc */,
872 (char *)&dup_ext_buf
,
873 sizeof(struct duplicate_extents_to_file
),
877 if (ret_data_len
> 0)
878 cifs_dbg(FYI
, "non-zero response length in duplicate extents");
880 duplicate_extents_out
:
885 smb2_set_compression(const unsigned int xid
, struct cifs_tcon
*tcon
,
886 struct cifsFileInfo
*cfile
)
888 return SMB2_set_compression(xid
, tcon
, cfile
->fid
.persistent_fid
,
889 cfile
->fid
.volatile_fid
);
893 smb3_set_integrity(const unsigned int xid
, struct cifs_tcon
*tcon
,
894 struct cifsFileInfo
*cfile
)
896 struct fsctl_set_integrity_information_req integr_info
;
897 unsigned int ret_data_len
;
899 integr_info
.ChecksumAlgorithm
= cpu_to_le16(CHECKSUM_TYPE_UNCHANGED
);
900 integr_info
.Flags
= 0;
901 integr_info
.Reserved
= 0;
903 return SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
904 cfile
->fid
.volatile_fid
,
905 FSCTL_SET_INTEGRITY_INFORMATION
,
906 true /* is_fsctl */, false /* use_ipc */,
907 (char *)&integr_info
,
908 sizeof(struct fsctl_set_integrity_information_req
),
915 smb3_enum_snapshots(const unsigned int xid
, struct cifs_tcon
*tcon
,
916 struct cifsFileInfo
*cfile
, void __user
*ioc_buf
)
919 unsigned int ret_data_len
= 0;
921 struct smb_snapshot_array snapshot_in
;
923 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
924 cfile
->fid
.volatile_fid
,
925 FSCTL_SRV_ENUMERATE_SNAPSHOTS
,
926 true /* is_fsctl */, false /* use_ipc */,
927 NULL
, 0 /* no input data */,
930 cifs_dbg(FYI
, "enum snaphots ioctl returned %d and ret buflen is %d\n",
935 if (ret_data_len
&& (ioc_buf
!= NULL
) && (retbuf
!= NULL
)) {
937 if (copy_from_user(&snapshot_in
, ioc_buf
,
938 sizeof(struct smb_snapshot_array
))) {
943 if (snapshot_in
.snapshot_array_size
< sizeof(struct smb_snapshot_array
)) {
949 if (ret_data_len
> snapshot_in
.snapshot_array_size
)
950 ret_data_len
= snapshot_in
.snapshot_array_size
;
952 if (copy_to_user(ioc_buf
, retbuf
, ret_data_len
))
961 smb2_query_dir_first(const unsigned int xid
, struct cifs_tcon
*tcon
,
962 const char *path
, struct cifs_sb_info
*cifs_sb
,
963 struct cifs_fid
*fid
, __u16 search_flags
,
964 struct cifs_search_info
*srch_inf
)
968 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
969 struct cifs_open_parms oparms
;
971 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
976 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| FILE_READ_DATA
;
977 oparms
.disposition
= FILE_OPEN
;
978 oparms
.create_options
= 0;
980 oparms
.reconnect
= false;
982 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
985 cifs_dbg(FYI
, "open dir failed rc=%d\n", rc
);
989 srch_inf
->entries_in_buffer
= 0;
990 srch_inf
->index_of_last_entry
= 0;
992 rc
= SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
993 fid
->volatile_fid
, 0, srch_inf
);
995 cifs_dbg(FYI
, "query directory failed rc=%d\n", rc
);
996 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1002 smb2_query_dir_next(const unsigned int xid
, struct cifs_tcon
*tcon
,
1003 struct cifs_fid
*fid
, __u16 search_flags
,
1004 struct cifs_search_info
*srch_inf
)
1006 return SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
1007 fid
->volatile_fid
, 0, srch_inf
);
1011 smb2_close_dir(const unsigned int xid
, struct cifs_tcon
*tcon
,
1012 struct cifs_fid
*fid
)
1014 return SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1018 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
1019 * the number of credits and return true. Otherwise - return false.
1022 smb2_is_status_pending(char *buf
, struct TCP_Server_Info
*server
, int length
)
1024 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
1026 if (shdr
->Status
!= STATUS_PENDING
)
1030 spin_lock(&server
->req_lock
);
1031 server
->credits
+= le16_to_cpu(shdr
->CreditRequest
);
1032 spin_unlock(&server
->req_lock
);
1033 wake_up(&server
->request_q
);
1040 smb2_is_session_expired(char *buf
)
1042 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
1044 if (shdr
->Status
!= STATUS_NETWORK_SESSION_EXPIRED
)
1047 cifs_dbg(FYI
, "Session expired\n");
1052 smb2_oplock_response(struct cifs_tcon
*tcon
, struct cifs_fid
*fid
,
1053 struct cifsInodeInfo
*cinode
)
1055 if (tcon
->ses
->server
->capabilities
& SMB2_GLOBAL_CAP_LEASING
)
1056 return SMB2_lease_break(0, tcon
, cinode
->lease_key
,
1057 smb2_get_lease_state(cinode
));
1059 return SMB2_oplock_break(0, tcon
, fid
->persistent_fid
,
1061 CIFS_CACHE_READ(cinode
) ? 1 : 0);
1065 smb2_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
1066 struct kstatfs
*buf
)
1069 __le16 srch_path
= 0; /* Null - open root of share */
1070 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1071 struct cifs_open_parms oparms
;
1072 struct cifs_fid fid
;
1075 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
1076 oparms
.disposition
= FILE_OPEN
;
1077 oparms
.create_options
= 0;
1079 oparms
.reconnect
= false;
1081 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
1084 buf
->f_type
= SMB2_MAGIC_NUMBER
;
1085 rc
= SMB2_QFS_info(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
1087 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
1092 smb2_compare_fids(struct cifsFileInfo
*ob1
, struct cifsFileInfo
*ob2
)
1094 return ob1
->fid
.persistent_fid
== ob2
->fid
.persistent_fid
&&
1095 ob1
->fid
.volatile_fid
== ob2
->fid
.volatile_fid
;
1099 smb2_mand_lock(const unsigned int xid
, struct cifsFileInfo
*cfile
, __u64 offset
,
1100 __u64 length
, __u32 type
, int lock
, int unlock
, bool wait
)
1102 if (unlock
&& !lock
)
1103 type
= SMB2_LOCKFLAG_UNLOCK
;
1104 return SMB2_lock(xid
, tlink_tcon(cfile
->tlink
),
1105 cfile
->fid
.persistent_fid
, cfile
->fid
.volatile_fid
,
1106 current
->tgid
, length
, offset
, type
, wait
);
1110 smb2_get_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
1112 memcpy(fid
->lease_key
, CIFS_I(inode
)->lease_key
, SMB2_LEASE_KEY_SIZE
);
1116 smb2_set_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
1118 memcpy(CIFS_I(inode
)->lease_key
, fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
1122 smb2_new_lease_key(struct cifs_fid
*fid
)
1124 generate_random_uuid(fid
->lease_key
);
1128 smb2_get_dfs_refer(const unsigned int xid
, struct cifs_ses
*ses
,
1129 const char *search_name
,
1130 struct dfs_info3_param
**target_nodes
,
1131 unsigned int *num_of_nodes
,
1132 const struct nls_table
*nls_codepage
, int remap
)
1135 __le16
*utf16_path
= NULL
;
1136 int utf16_path_len
= 0;
1137 struct cifs_tcon
*tcon
;
1138 struct fsctl_get_dfs_referral_req
*dfs_req
= NULL
;
1139 struct get_dfs_referral_rsp
*dfs_rsp
= NULL
;
1140 u32 dfs_req_size
= 0, dfs_rsp_size
= 0;
1142 cifs_dbg(FYI
, "smb2_get_dfs_refer path <%s>\n", search_name
);
1145 * Use any tcon from the current session. Here, the first one.
1147 spin_lock(&cifs_tcp_ses_lock
);
1148 tcon
= list_first_entry_or_null(&ses
->tcon_list
, struct cifs_tcon
,
1152 spin_unlock(&cifs_tcp_ses_lock
);
1155 cifs_dbg(VFS
, "session %p has no tcon available for a dfs referral request\n",
1161 utf16_path
= cifs_strndup_to_utf16(search_name
, PATH_MAX
,
1163 nls_codepage
, remap
);
1169 dfs_req_size
= sizeof(*dfs_req
) + utf16_path_len
;
1170 dfs_req
= kzalloc(dfs_req_size
, GFP_KERNEL
);
1176 /* Highest DFS referral version understood */
1177 dfs_req
->MaxReferralLevel
= DFS_VERSION
;
1179 /* Path to resolve in an UTF-16 null-terminated string */
1180 memcpy(dfs_req
->RequestFileName
, utf16_path
, utf16_path_len
);
1183 /* try first with IPC */
1184 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
1185 FSCTL_DFS_GET_REFERRALS
,
1186 true /* is_fsctl */, true /* use_ipc */,
1187 (char *)dfs_req
, dfs_req_size
,
1188 (char **)&dfs_rsp
, &dfs_rsp_size
);
1189 if (rc
== -ENOTCONN
) {
1190 /* try with normal tcon */
1191 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
1192 FSCTL_DFS_GET_REFERRALS
,
1193 true /* is_fsctl */, false /*use_ipc*/,
1194 (char *)dfs_req
, dfs_req_size
,
1195 (char **)&dfs_rsp
, &dfs_rsp_size
);
1197 } while (rc
== -EAGAIN
);
1200 cifs_dbg(VFS
, "ioctl error in smb2_get_dfs_refer rc=%d\n", rc
);
1204 rc
= parse_dfs_referrals(dfs_rsp
, dfs_rsp_size
,
1205 num_of_nodes
, target_nodes
,
1206 nls_codepage
, remap
, search_name
,
1207 true /* is_unicode */);
1209 cifs_dbg(VFS
, "parse error in smb2_get_dfs_refer rc=%d\n", rc
);
1215 spin_lock(&cifs_tcp_ses_lock
);
1217 spin_unlock(&cifs_tcp_ses_lock
);
1224 #define SMB2_SYMLINK_STRUCT_SIZE \
1225 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
1228 smb2_query_symlink(const unsigned int xid
, struct cifs_tcon
*tcon
,
1229 const char *full_path
, char **target_path
,
1230 struct cifs_sb_info
*cifs_sb
)
1234 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1235 struct cifs_open_parms oparms
;
1236 struct cifs_fid fid
;
1237 struct smb2_err_rsp
*err_buf
= NULL
;
1238 struct smb2_symlink_err_rsp
*symlink
;
1239 unsigned int sub_len
;
1240 unsigned int sub_offset
;
1241 unsigned int print_len
;
1242 unsigned int print_offset
;
1244 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, full_path
);
1246 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
1251 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
1252 oparms
.disposition
= FILE_OPEN
;
1253 oparms
.create_options
= 0;
1255 oparms
.reconnect
= false;
1257 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, &err_buf
);
1259 if (!rc
|| !err_buf
) {
1264 if (le32_to_cpu(err_buf
->ByteCount
) < sizeof(struct smb2_symlink_err_rsp
) ||
1265 get_rfc1002_length(err_buf
) + 4 < SMB2_SYMLINK_STRUCT_SIZE
) {
1270 /* open must fail on symlink - reset rc */
1272 symlink
= (struct smb2_symlink_err_rsp
*)err_buf
->ErrorData
;
1273 sub_len
= le16_to_cpu(symlink
->SubstituteNameLength
);
1274 sub_offset
= le16_to_cpu(symlink
->SubstituteNameOffset
);
1275 print_len
= le16_to_cpu(symlink
->PrintNameLength
);
1276 print_offset
= le16_to_cpu(symlink
->PrintNameOffset
);
1278 if (get_rfc1002_length(err_buf
) + 4 <
1279 SMB2_SYMLINK_STRUCT_SIZE
+ sub_offset
+ sub_len
) {
1284 if (get_rfc1002_length(err_buf
) + 4 <
1285 SMB2_SYMLINK_STRUCT_SIZE
+ print_offset
+ print_len
) {
1290 *target_path
= cifs_strndup_from_utf16(
1291 (char *)symlink
->PathBuffer
+ sub_offset
,
1292 sub_len
, true, cifs_sb
->local_nls
);
1293 if (!(*target_path
)) {
1297 convert_delimiter(*target_path
, '/');
1298 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
1303 #ifdef CONFIG_CIFS_ACL
1304 static struct cifs_ntsd
*
1305 get_smb2_acl_by_fid(struct cifs_sb_info
*cifs_sb
,
1306 const struct cifs_fid
*cifsfid
, u32
*pacllen
)
1308 struct cifs_ntsd
*pntsd
= NULL
;
1310 int rc
= -EOPNOTSUPP
;
1311 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
1314 return ERR_CAST(tlink
);
1317 cifs_dbg(FYI
, "trying to get acl\n");
1319 rc
= SMB2_query_acl(xid
, tlink_tcon(tlink
), cifsfid
->persistent_fid
,
1320 cifsfid
->volatile_fid
, (void **)&pntsd
, pacllen
);
1323 cifs_put_tlink(tlink
);
1325 cifs_dbg(FYI
, "%s: rc = %d ACL len %d\n", __func__
, rc
, *pacllen
);
1332 static struct cifs_ntsd
*
1333 get_smb2_acl_by_path(struct cifs_sb_info
*cifs_sb
,
1334 const char *path
, u32
*pacllen
)
1336 struct cifs_ntsd
*pntsd
= NULL
;
1337 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1340 struct cifs_tcon
*tcon
;
1341 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
1342 struct cifs_fid fid
;
1343 struct cifs_open_parms oparms
;
1346 cifs_dbg(FYI
, "get smb3 acl for path %s\n", path
);
1348 return ERR_CAST(tlink
);
1350 tcon
= tlink_tcon(tlink
);
1353 if (backup_cred(cifs_sb
))
1354 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
1356 oparms
.create_options
= 0;
1358 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
1360 return ERR_PTR(-ENOMEM
);
1363 oparms
.desired_access
= READ_CONTROL
;
1364 oparms
.disposition
= FILE_OPEN
;
1366 oparms
.reconnect
= false;
1368 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
1371 rc
= SMB2_query_acl(xid
, tlink_tcon(tlink
), fid
.persistent_fid
,
1372 fid
.volatile_fid
, (void **)&pntsd
, pacllen
);
1373 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
1376 cifs_put_tlink(tlink
);
1379 cifs_dbg(FYI
, "%s: rc = %d ACL len %d\n", __func__
, rc
, *pacllen
);
1385 #ifdef CONFIG_CIFS_ACL
1387 set_smb2_acl(struct cifs_ntsd
*pnntsd
, __u32 acllen
,
1388 struct inode
*inode
, const char *path
, int aclflag
)
1390 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1392 int rc
, access_flags
= 0;
1393 struct cifs_tcon
*tcon
;
1394 struct cifs_sb_info
*cifs_sb
= CIFS_SB(inode
->i_sb
);
1395 struct tcon_link
*tlink
= cifs_sb_tlink(cifs_sb
);
1396 struct cifs_fid fid
;
1397 struct cifs_open_parms oparms
;
1400 cifs_dbg(FYI
, "set smb3 acl for path %s\n", path
);
1402 return PTR_ERR(tlink
);
1404 tcon
= tlink_tcon(tlink
);
1407 if (backup_cred(cifs_sb
))
1408 oparms
.create_options
= CREATE_OPEN_BACKUP_INTENT
;
1410 oparms
.create_options
= 0;
1412 if (aclflag
== CIFS_ACL_OWNER
|| aclflag
== CIFS_ACL_GROUP
)
1413 access_flags
= WRITE_OWNER
;
1415 access_flags
= WRITE_DAC
;
1417 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
1422 oparms
.desired_access
= access_flags
;
1423 oparms
.disposition
= FILE_OPEN
;
1426 oparms
.reconnect
= false;
1428 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
1431 rc
= SMB2_set_acl(xid
, tlink_tcon(tlink
), fid
.persistent_fid
,
1432 fid
.volatile_fid
, pnntsd
, acllen
, aclflag
);
1433 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
1436 cifs_put_tlink(tlink
);
1440 #endif /* CIFS_ACL */
1442 /* Retrieve an ACL from the server */
1443 static struct cifs_ntsd
*
1444 get_smb2_acl(struct cifs_sb_info
*cifs_sb
,
1445 struct inode
*inode
, const char *path
,
1448 struct cifs_ntsd
*pntsd
= NULL
;
1449 struct cifsFileInfo
*open_file
= NULL
;
1452 open_file
= find_readable_file(CIFS_I(inode
), true);
1454 return get_smb2_acl_by_path(cifs_sb
, path
, pacllen
);
1456 pntsd
= get_smb2_acl_by_fid(cifs_sb
, &open_file
->fid
, pacllen
);
1457 cifsFileInfo_put(open_file
);
1462 static long smb3_zero_range(struct file
*file
, struct cifs_tcon
*tcon
,
1463 loff_t offset
, loff_t len
, bool keep_size
)
1465 struct inode
*inode
;
1466 struct cifsInodeInfo
*cifsi
;
1467 struct cifsFileInfo
*cfile
= file
->private_data
;
1468 struct file_zero_data_information fsctl_buf
;
1474 inode
= d_inode(cfile
->dentry
);
1475 cifsi
= CIFS_I(inode
);
1477 /* if file not oplocked can't be sure whether asking to extend size */
1478 if (!CIFS_CACHE_READ(cifsi
))
1479 if (keep_size
== false)
1483 * Must check if file sparse since fallocate -z (zero range) assumes
1484 * non-sparse allocation
1486 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
))
1490 * need to make sure we are not asked to extend the file since the SMB3
1491 * fsctl does not change the file size. In the future we could change
1492 * this to zero the first part of the range then set the file size
1493 * which for a non sparse file would zero the newly extended range
1495 if (keep_size
== false)
1496 if (i_size_read(inode
) < offset
+ len
)
1499 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1501 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1502 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1504 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1505 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1506 true /* is_fctl */, false /* use_ipc */,
1508 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1513 static long smb3_punch_hole(struct file
*file
, struct cifs_tcon
*tcon
,
1514 loff_t offset
, loff_t len
)
1516 struct inode
*inode
;
1517 struct cifsInodeInfo
*cifsi
;
1518 struct cifsFileInfo
*cfile
= file
->private_data
;
1519 struct file_zero_data_information fsctl_buf
;
1522 __u8 set_sparse
= 1;
1526 inode
= d_inode(cfile
->dentry
);
1527 cifsi
= CIFS_I(inode
);
1529 /* Need to make file sparse, if not already, before freeing range. */
1530 /* Consider adding equivalent for compressed since it could also work */
1531 if (!smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
))
1534 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1536 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1537 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1539 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1540 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1541 true /* is_fctl */, false /* use_ipc */,
1543 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1548 static long smb3_simple_falloc(struct file
*file
, struct cifs_tcon
*tcon
,
1549 loff_t off
, loff_t len
, bool keep_size
)
1551 struct inode
*inode
;
1552 struct cifsInodeInfo
*cifsi
;
1553 struct cifsFileInfo
*cfile
= file
->private_data
;
1554 long rc
= -EOPNOTSUPP
;
1559 inode
= d_inode(cfile
->dentry
);
1560 cifsi
= CIFS_I(inode
);
1562 /* if file not oplocked can't be sure whether asking to extend size */
1563 if (!CIFS_CACHE_READ(cifsi
))
1564 if (keep_size
== false)
1568 * Files are non-sparse by default so falloc may be a no-op
1569 * Must check if file sparse. If not sparse, and not extending
1570 * then no need to do anything since file already allocated
1572 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) == 0) {
1573 if (keep_size
== true)
1575 /* check if extending file */
1576 else if (i_size_read(inode
) >= off
+ len
)
1577 /* not extending file and already not sparse */
1579 /* BB: in future add else clause to extend file */
1584 if ((keep_size
== true) || (i_size_read(inode
) >= off
+ len
)) {
1586 * Check if falloc starts within first few pages of file
1587 * and ends within a few pages of the end of file to
1588 * ensure that most of file is being forced to be
1589 * fallocated now. If so then setting whole file sparse
1590 * ie potentially making a few extra pages at the beginning
1591 * or end of the file non-sparse via set_sparse is harmless.
1593 if ((off
> 8192) || (off
+ len
+ 8192 < i_size_read(inode
)))
1596 rc
= smb2_set_sparse(xid
, tcon
, cfile
, inode
, false);
1598 /* BB: else ... in future add code to extend file and set sparse */
1606 static long smb3_fallocate(struct file
*file
, struct cifs_tcon
*tcon
, int mode
,
1607 loff_t off
, loff_t len
)
1609 /* KEEP_SIZE already checked for by do_fallocate */
1610 if (mode
& FALLOC_FL_PUNCH_HOLE
)
1611 return smb3_punch_hole(file
, tcon
, off
, len
);
1612 else if (mode
& FALLOC_FL_ZERO_RANGE
) {
1613 if (mode
& FALLOC_FL_KEEP_SIZE
)
1614 return smb3_zero_range(file
, tcon
, off
, len
, true);
1615 return smb3_zero_range(file
, tcon
, off
, len
, false);
1616 } else if (mode
== FALLOC_FL_KEEP_SIZE
)
1617 return smb3_simple_falloc(file
, tcon
, off
, len
, true);
1619 return smb3_simple_falloc(file
, tcon
, off
, len
, false);
1625 smb2_downgrade_oplock(struct TCP_Server_Info
*server
,
1626 struct cifsInodeInfo
*cinode
, bool set_level2
)
1629 server
->ops
->set_oplock_level(cinode
, SMB2_OPLOCK_LEVEL_II
,
1632 server
->ops
->set_oplock_level(cinode
, 0, 0, NULL
);
1636 smb2_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1637 unsigned int epoch
, bool *purge_cache
)
1640 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1642 if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
) {
1643 cinode
->oplock
= CIFS_CACHE_RHW_FLG
;
1644 cifs_dbg(FYI
, "Batch Oplock granted on inode %p\n",
1645 &cinode
->vfs_inode
);
1646 } else if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
) {
1647 cinode
->oplock
= CIFS_CACHE_RW_FLG
;
1648 cifs_dbg(FYI
, "Exclusive Oplock granted on inode %p\n",
1649 &cinode
->vfs_inode
);
1650 } else if (oplock
== SMB2_OPLOCK_LEVEL_II
) {
1651 cinode
->oplock
= CIFS_CACHE_READ_FLG
;
1652 cifs_dbg(FYI
, "Level II Oplock granted on inode %p\n",
1653 &cinode
->vfs_inode
);
1659 smb21_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1660 unsigned int epoch
, bool *purge_cache
)
1662 char message
[5] = {0};
1665 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1669 if (oplock
& SMB2_LEASE_READ_CACHING_HE
) {
1670 cinode
->oplock
|= CIFS_CACHE_READ_FLG
;
1671 strcat(message
, "R");
1673 if (oplock
& SMB2_LEASE_HANDLE_CACHING_HE
) {
1674 cinode
->oplock
|= CIFS_CACHE_HANDLE_FLG
;
1675 strcat(message
, "H");
1677 if (oplock
& SMB2_LEASE_WRITE_CACHING_HE
) {
1678 cinode
->oplock
|= CIFS_CACHE_WRITE_FLG
;
1679 strcat(message
, "W");
1681 if (!cinode
->oplock
)
1682 strcat(message
, "None");
1683 cifs_dbg(FYI
, "%s Lease granted on inode %p\n", message
,
1684 &cinode
->vfs_inode
);
1688 smb3_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1689 unsigned int epoch
, bool *purge_cache
)
1691 unsigned int old_oplock
= cinode
->oplock
;
1693 smb21_set_oplock_level(cinode
, oplock
, epoch
, purge_cache
);
1696 *purge_cache
= false;
1697 if (old_oplock
== CIFS_CACHE_READ_FLG
) {
1698 if (cinode
->oplock
== CIFS_CACHE_READ_FLG
&&
1699 (epoch
- cinode
->epoch
> 0))
1700 *purge_cache
= true;
1701 else if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1702 (epoch
- cinode
->epoch
> 1))
1703 *purge_cache
= true;
1704 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1705 (epoch
- cinode
->epoch
> 1))
1706 *purge_cache
= true;
1707 else if (cinode
->oplock
== 0 &&
1708 (epoch
- cinode
->epoch
> 0))
1709 *purge_cache
= true;
1710 } else if (old_oplock
== CIFS_CACHE_RH_FLG
) {
1711 if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1712 (epoch
- cinode
->epoch
> 0))
1713 *purge_cache
= true;
1714 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1715 (epoch
- cinode
->epoch
> 1))
1716 *purge_cache
= true;
1718 cinode
->epoch
= epoch
;
1723 smb2_is_read_op(__u32 oplock
)
1725 return oplock
== SMB2_OPLOCK_LEVEL_II
;
1729 smb21_is_read_op(__u32 oplock
)
1731 return (oplock
& SMB2_LEASE_READ_CACHING_HE
) &&
1732 !(oplock
& SMB2_LEASE_WRITE_CACHING_HE
);
1736 map_oplock_to_lease(u8 oplock
)
1738 if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
)
1739 return SMB2_LEASE_WRITE_CACHING
| SMB2_LEASE_READ_CACHING
;
1740 else if (oplock
== SMB2_OPLOCK_LEVEL_II
)
1741 return SMB2_LEASE_READ_CACHING
;
1742 else if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
)
1743 return SMB2_LEASE_HANDLE_CACHING
| SMB2_LEASE_READ_CACHING
|
1744 SMB2_LEASE_WRITE_CACHING
;
1749 smb2_create_lease_buf(u8
*lease_key
, u8 oplock
)
1751 struct create_lease
*buf
;
1753 buf
= kzalloc(sizeof(struct create_lease
), GFP_KERNEL
);
1757 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1758 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1759 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1761 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1762 (struct create_lease
, lcontext
));
1763 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context
));
1764 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1765 (struct create_lease
, Name
));
1766 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1767 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1776 smb3_create_lease_buf(u8
*lease_key
, u8 oplock
)
1778 struct create_lease_v2
*buf
;
1780 buf
= kzalloc(sizeof(struct create_lease_v2
), GFP_KERNEL
);
1784 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1785 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1786 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1788 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1789 (struct create_lease_v2
, lcontext
));
1790 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context_v2
));
1791 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1792 (struct create_lease_v2
, Name
));
1793 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1794 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1803 smb2_parse_lease_buf(void *buf
, unsigned int *epoch
)
1805 struct create_lease
*lc
= (struct create_lease
*)buf
;
1807 *epoch
= 0; /* not used */
1808 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
1809 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
1810 return le32_to_cpu(lc
->lcontext
.LeaseState
);
1814 smb3_parse_lease_buf(void *buf
, unsigned int *epoch
)
1816 struct create_lease_v2
*lc
= (struct create_lease_v2
*)buf
;
1818 *epoch
= le16_to_cpu(lc
->lcontext
.Epoch
);
1819 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
1820 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
1821 return le32_to_cpu(lc
->lcontext
.LeaseState
);
1825 smb2_wp_retry_size(struct inode
*inode
)
1827 return min_t(unsigned int, CIFS_SB(inode
->i_sb
)->wsize
,
1828 SMB2_MAX_BUFFER_SIZE
);
1832 smb2_dir_needs_close(struct cifsFileInfo
*cfile
)
1834 return !cfile
->invalidHandle
;
1838 fill_transform_hdr(struct smb2_transform_hdr
*tr_hdr
, struct smb_rqst
*old_rq
)
1840 struct smb2_sync_hdr
*shdr
=
1841 (struct smb2_sync_hdr
*)old_rq
->rq_iov
[1].iov_base
;
1842 unsigned int orig_len
= get_rfc1002_length(old_rq
->rq_iov
[0].iov_base
);
1844 memset(tr_hdr
, 0, sizeof(struct smb2_transform_hdr
));
1845 tr_hdr
->ProtocolId
= SMB2_TRANSFORM_PROTO_NUM
;
1846 tr_hdr
->OriginalMessageSize
= cpu_to_le32(orig_len
);
1847 tr_hdr
->Flags
= cpu_to_le16(0x01);
1848 get_random_bytes(&tr_hdr
->Nonce
, SMB3_AES128CMM_NONCE
);
1849 memcpy(&tr_hdr
->SessionId
, &shdr
->SessionId
, 8);
1850 inc_rfc1001_len(tr_hdr
, sizeof(struct smb2_transform_hdr
) - 4);
1851 inc_rfc1001_len(tr_hdr
, orig_len
);
1854 static struct scatterlist
*
1855 init_sg(struct smb_rqst
*rqst
, u8
*sign
)
1857 unsigned int sg_len
= rqst
->rq_nvec
+ rqst
->rq_npages
+ 1;
1858 unsigned int assoc_data_len
= sizeof(struct smb2_transform_hdr
) - 24;
1859 struct scatterlist
*sg
;
1863 sg
= kmalloc_array(sg_len
, sizeof(struct scatterlist
), GFP_KERNEL
);
1867 sg_init_table(sg
, sg_len
);
1868 sg_set_buf(&sg
[0], rqst
->rq_iov
[0].iov_base
+ 24, assoc_data_len
);
1869 for (i
= 1; i
< rqst
->rq_nvec
; i
++)
1870 sg_set_buf(&sg
[i
], rqst
->rq_iov
[i
].iov_base
,
1871 rqst
->rq_iov
[i
].iov_len
);
1872 for (j
= 0; i
< sg_len
- 1; i
++, j
++) {
1873 unsigned int len
= (j
< rqst
->rq_npages
- 1) ? rqst
->rq_pagesz
1875 sg_set_page(&sg
[i
], rqst
->rq_pages
[j
], len
, 0);
1877 sg_set_buf(&sg
[sg_len
- 1], sign
, SMB2_SIGNATURE_SIZE
);
1881 struct cifs_crypt_result
{
1883 struct completion completion
;
1886 static void cifs_crypt_complete(struct crypto_async_request
*req
, int err
)
1888 struct cifs_crypt_result
*res
= req
->data
;
1890 if (err
== -EINPROGRESS
)
1894 complete(&res
->completion
);
1898 smb2_get_enc_key(struct TCP_Server_Info
*server
, __u64 ses_id
, int enc
, u8
*key
)
1900 struct cifs_ses
*ses
;
1903 spin_lock(&cifs_tcp_ses_lock
);
1904 list_for_each_entry(ses
, &server
->smb_ses_list
, smb_ses_list
) {
1905 if (ses
->Suid
!= ses_id
)
1907 ses_enc_key
= enc
? ses
->smb3encryptionkey
:
1908 ses
->smb3decryptionkey
;
1909 memcpy(key
, ses_enc_key
, SMB3_SIGN_KEY_SIZE
);
1910 spin_unlock(&cifs_tcp_ses_lock
);
1913 spin_unlock(&cifs_tcp_ses_lock
);
1918 * Encrypt or decrypt @rqst message. @rqst has the following format:
1919 * iov[0] - transform header (associate data),
1920 * iov[1-N] and pages - data to encrypt.
1921 * On success return encrypted data in iov[1-N] and pages, leave iov[0]
1925 crypt_message(struct TCP_Server_Info
*server
, struct smb_rqst
*rqst
, int enc
)
1927 struct smb2_transform_hdr
*tr_hdr
=
1928 (struct smb2_transform_hdr
*)rqst
->rq_iov
[0].iov_base
;
1929 unsigned int assoc_data_len
= sizeof(struct smb2_transform_hdr
) - 24;
1931 struct scatterlist
*sg
;
1932 u8 sign
[SMB2_SIGNATURE_SIZE
] = {};
1933 u8 key
[SMB3_SIGN_KEY_SIZE
];
1934 struct aead_request
*req
;
1936 unsigned int iv_len
;
1937 struct cifs_crypt_result result
= {0, };
1938 struct crypto_aead
*tfm
;
1939 unsigned int crypt_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
1941 init_completion(&result
.completion
);
1943 rc
= smb2_get_enc_key(server
, tr_hdr
->SessionId
, enc
, key
);
1945 cifs_dbg(VFS
, "%s: Could not get %scryption key\n", __func__
,
1950 rc
= smb3_crypto_aead_allocate(server
);
1952 cifs_dbg(VFS
, "%s: crypto alloc failed\n", __func__
);
1956 tfm
= enc
? server
->secmech
.ccmaesencrypt
:
1957 server
->secmech
.ccmaesdecrypt
;
1958 rc
= crypto_aead_setkey(tfm
, key
, SMB3_SIGN_KEY_SIZE
);
1960 cifs_dbg(VFS
, "%s: Failed to set aead key %d\n", __func__
, rc
);
1964 rc
= crypto_aead_setauthsize(tfm
, SMB2_SIGNATURE_SIZE
);
1966 cifs_dbg(VFS
, "%s: Failed to set authsize %d\n", __func__
, rc
);
1970 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
1972 cifs_dbg(VFS
, "%s: Failed to alloc aead request", __func__
);
1977 memcpy(sign
, &tr_hdr
->Signature
, SMB2_SIGNATURE_SIZE
);
1978 crypt_len
+= SMB2_SIGNATURE_SIZE
;
1981 sg
= init_sg(rqst
, sign
);
1983 cifs_dbg(VFS
, "%s: Failed to init sg", __func__
);
1988 iv_len
= crypto_aead_ivsize(tfm
);
1989 iv
= kzalloc(iv_len
, GFP_KERNEL
);
1991 cifs_dbg(VFS
, "%s: Failed to alloc IV", __func__
);
1996 memcpy(iv
+ 1, (char *)tr_hdr
->Nonce
, SMB3_AES128CMM_NONCE
);
1998 aead_request_set_crypt(req
, sg
, sg
, crypt_len
, iv
);
1999 aead_request_set_ad(req
, assoc_data_len
);
2001 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
2002 cifs_crypt_complete
, &result
);
2004 rc
= enc
? crypto_aead_encrypt(req
) : crypto_aead_decrypt(req
);
2006 if (rc
== -EINPROGRESS
|| rc
== -EBUSY
) {
2007 wait_for_completion(&result
.completion
);
2012 memcpy(&tr_hdr
->Signature
, sign
, SMB2_SIGNATURE_SIZE
);
2023 smb3_init_transform_rq(struct TCP_Server_Info
*server
, struct smb_rqst
*new_rq
,
2024 struct smb_rqst
*old_rq
)
2027 struct page
**pages
;
2028 struct smb2_transform_hdr
*tr_hdr
;
2029 unsigned int npages
= old_rq
->rq_npages
;
2033 pages
= kmalloc_array(npages
, sizeof(struct page
*), GFP_KERNEL
);
2037 new_rq
->rq_pages
= pages
;
2038 new_rq
->rq_npages
= old_rq
->rq_npages
;
2039 new_rq
->rq_pagesz
= old_rq
->rq_pagesz
;
2040 new_rq
->rq_tailsz
= old_rq
->rq_tailsz
;
2042 for (i
= 0; i
< npages
; i
++) {
2043 pages
[i
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
2045 goto err_free_pages
;
2048 iov
= kmalloc_array(old_rq
->rq_nvec
, sizeof(struct kvec
), GFP_KERNEL
);
2050 goto err_free_pages
;
2052 /* copy all iovs from the old except the 1st one (rfc1002 length) */
2053 memcpy(&iov
[1], &old_rq
->rq_iov
[1],
2054 sizeof(struct kvec
) * (old_rq
->rq_nvec
- 1));
2055 new_rq
->rq_iov
= iov
;
2056 new_rq
->rq_nvec
= old_rq
->rq_nvec
;
2058 tr_hdr
= kmalloc(sizeof(struct smb2_transform_hdr
), GFP_KERNEL
);
2062 /* fill the 1st iov with a transform header */
2063 fill_transform_hdr(tr_hdr
, old_rq
);
2064 new_rq
->rq_iov
[0].iov_base
= tr_hdr
;
2065 new_rq
->rq_iov
[0].iov_len
= sizeof(struct smb2_transform_hdr
);
2067 /* copy pages form the old */
2068 for (i
= 0; i
< npages
; i
++) {
2069 char *dst
= kmap(new_rq
->rq_pages
[i
]);
2070 char *src
= kmap(old_rq
->rq_pages
[i
]);
2071 unsigned int len
= (i
< npages
- 1) ? new_rq
->rq_pagesz
:
2073 memcpy(dst
, src
, len
);
2074 kunmap(new_rq
->rq_pages
[i
]);
2075 kunmap(old_rq
->rq_pages
[i
]);
2078 rc
= crypt_message(server
, new_rq
, 1);
2079 cifs_dbg(FYI
, "encrypt message returned %d", rc
);
2081 goto err_free_tr_hdr
;
2090 for (i
= i
- 1; i
>= 0; i
--)
2097 smb3_free_transform_rq(struct smb_rqst
*rqst
)
2099 int i
= rqst
->rq_npages
- 1;
2102 put_page(rqst
->rq_pages
[i
]);
2103 kfree(rqst
->rq_pages
);
2104 /* free transform header */
2105 kfree(rqst
->rq_iov
[0].iov_base
);
2106 kfree(rqst
->rq_iov
);
2110 smb3_is_transform_hdr(void *buf
)
2112 struct smb2_transform_hdr
*trhdr
= buf
;
2114 return trhdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
;
2118 decrypt_raw_data(struct TCP_Server_Info
*server
, char *buf
,
2119 unsigned int buf_data_size
, struct page
**pages
,
2120 unsigned int npages
, unsigned int page_data_size
)
2123 struct smb_rqst rqst
= {NULL
};
2124 struct smb2_hdr
*hdr
;
2127 iov
[0].iov_base
= buf
;
2128 iov
[0].iov_len
= sizeof(struct smb2_transform_hdr
);
2129 iov
[1].iov_base
= buf
+ sizeof(struct smb2_transform_hdr
);
2130 iov
[1].iov_len
= buf_data_size
;
2134 rqst
.rq_pages
= pages
;
2135 rqst
.rq_npages
= npages
;
2136 rqst
.rq_pagesz
= PAGE_SIZE
;
2137 rqst
.rq_tailsz
= (page_data_size
% PAGE_SIZE
) ? : PAGE_SIZE
;
2139 rc
= crypt_message(server
, &rqst
, 0);
2140 cifs_dbg(FYI
, "decrypt message returned %d\n", rc
);
2145 memmove(buf
+ 4, iov
[1].iov_base
, buf_data_size
);
2146 hdr
= (struct smb2_hdr
*)buf
;
2147 hdr
->smb2_buf_length
= cpu_to_be32(buf_data_size
+ page_data_size
);
2148 server
->total_read
= buf_data_size
+ page_data_size
+ 4;
2154 read_data_into_pages(struct TCP_Server_Info
*server
, struct page
**pages
,
2155 unsigned int npages
, unsigned int len
)
2160 for (i
= 0; i
< npages
; i
++) {
2161 struct page
*page
= pages
[i
];
2165 if (len
>= PAGE_SIZE
) {
2166 /* enough data to fill the page */
2170 zero_user(page
, len
, PAGE_SIZE
- len
);
2173 length
= cifs_read_page_from_socket(server
, page
, n
);
2176 server
->total_read
+= length
;
2183 init_read_bvec(struct page
**pages
, unsigned int npages
, unsigned int data_size
,
2184 unsigned int cur_off
, struct bio_vec
**page_vec
)
2186 struct bio_vec
*bvec
;
2189 bvec
= kcalloc(npages
, sizeof(struct bio_vec
), GFP_KERNEL
);
2193 for (i
= 0; i
< npages
; i
++) {
2194 bvec
[i
].bv_page
= pages
[i
];
2195 bvec
[i
].bv_offset
= (i
== 0) ? cur_off
: 0;
2196 bvec
[i
].bv_len
= min_t(unsigned int, PAGE_SIZE
, data_size
);
2197 data_size
-= bvec
[i
].bv_len
;
2200 if (data_size
!= 0) {
2201 cifs_dbg(VFS
, "%s: something went wrong\n", __func__
);
2211 handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
,
2212 char *buf
, unsigned int buf_len
, struct page
**pages
,
2213 unsigned int npages
, unsigned int page_data_size
)
2215 unsigned int data_offset
;
2216 unsigned int data_len
;
2217 unsigned int cur_off
;
2218 unsigned int cur_page_idx
;
2219 unsigned int pad_len
;
2220 struct cifs_readdata
*rdata
= mid
->callback_data
;
2221 struct smb2_sync_hdr
*shdr
= get_sync_hdr(buf
);
2222 struct bio_vec
*bvec
= NULL
;
2223 struct iov_iter iter
;
2227 if (shdr
->Command
!= SMB2_READ
) {
2228 cifs_dbg(VFS
, "only big read responses are supported\n");
2232 if (server
->ops
->is_session_expired
&&
2233 server
->ops
->is_session_expired(buf
)) {
2234 cifs_reconnect(server
);
2235 wake_up(&server
->response_q
);
2239 if (server
->ops
->is_status_pending
&&
2240 server
->ops
->is_status_pending(buf
, server
, 0))
2243 rdata
->result
= server
->ops
->map_error(buf
, false);
2244 if (rdata
->result
!= 0) {
2245 cifs_dbg(FYI
, "%s: server returned error %d\n",
2246 __func__
, rdata
->result
);
2247 dequeue_mid(mid
, rdata
->result
);
2251 data_offset
= server
->ops
->read_data_offset(buf
) + 4;
2252 data_len
= server
->ops
->read_data_length(buf
);
2254 if (data_offset
< server
->vals
->read_rsp_size
) {
2256 * win2k8 sometimes sends an offset of 0 when the read
2257 * is beyond the EOF. Treat it as if the data starts just after
2260 cifs_dbg(FYI
, "%s: data offset (%u) inside read response header\n",
2261 __func__
, data_offset
);
2262 data_offset
= server
->vals
->read_rsp_size
;
2263 } else if (data_offset
> MAX_CIFS_SMALL_BUFFER_SIZE
) {
2264 /* data_offset is beyond the end of smallbuf */
2265 cifs_dbg(FYI
, "%s: data offset (%u) beyond end of smallbuf\n",
2266 __func__
, data_offset
);
2267 rdata
->result
= -EIO
;
2268 dequeue_mid(mid
, rdata
->result
);
2272 pad_len
= data_offset
- server
->vals
->read_rsp_size
;
2274 if (buf_len
<= data_offset
) {
2275 /* read response payload is in pages */
2276 cur_page_idx
= pad_len
/ PAGE_SIZE
;
2277 cur_off
= pad_len
% PAGE_SIZE
;
2279 if (cur_page_idx
!= 0) {
2280 /* data offset is beyond the 1st page of response */
2281 cifs_dbg(FYI
, "%s: data offset (%u) beyond 1st page of response\n",
2282 __func__
, data_offset
);
2283 rdata
->result
= -EIO
;
2284 dequeue_mid(mid
, rdata
->result
);
2288 if (data_len
> page_data_size
- pad_len
) {
2289 /* data_len is corrupt -- discard frame */
2290 rdata
->result
= -EIO
;
2291 dequeue_mid(mid
, rdata
->result
);
2295 rdata
->result
= init_read_bvec(pages
, npages
, page_data_size
,
2297 if (rdata
->result
!= 0) {
2298 dequeue_mid(mid
, rdata
->result
);
2302 iov_iter_bvec(&iter
, WRITE
| ITER_BVEC
, bvec
, npages
, data_len
);
2303 } else if (buf_len
>= data_offset
+ data_len
) {
2304 /* read response payload is in buf */
2305 WARN_ONCE(npages
> 0, "read data can be either in buf or in pages");
2306 iov
.iov_base
= buf
+ data_offset
;
2307 iov
.iov_len
= data_len
;
2308 iov_iter_kvec(&iter
, WRITE
| ITER_KVEC
, &iov
, 1, data_len
);
2310 /* read response payload cannot be in both buf and pages */
2311 WARN_ONCE(1, "buf can not contain only a part of read data");
2312 rdata
->result
= -EIO
;
2313 dequeue_mid(mid
, rdata
->result
);
2317 /* set up first iov for signature check */
2318 rdata
->iov
[0].iov_base
= buf
;
2319 rdata
->iov
[0].iov_len
= 4;
2320 rdata
->iov
[1].iov_base
= buf
+ 4;
2321 rdata
->iov
[1].iov_len
= server
->vals
->read_rsp_size
- 4;
2322 cifs_dbg(FYI
, "0: iov_base=%p iov_len=%zu\n",
2323 rdata
->iov
[0].iov_base
, server
->vals
->read_rsp_size
);
2325 length
= rdata
->copy_into_pages(server
, rdata
, &iter
);
2332 dequeue_mid(mid
, false);
2337 receive_encrypted_read(struct TCP_Server_Info
*server
, struct mid_q_entry
**mid
)
2339 char *buf
= server
->smallbuf
;
2340 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
2341 unsigned int npages
;
2342 struct page
**pages
;
2344 unsigned int buflen
= get_rfc1002_length(buf
) + 4;
2348 len
= min_t(unsigned int, buflen
, server
->vals
->read_rsp_size
- 4 +
2349 sizeof(struct smb2_transform_hdr
)) - HEADER_SIZE(server
) + 1;
2351 rc
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1, len
);
2354 server
->total_read
+= rc
;
2356 len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
) + 4 -
2357 server
->vals
->read_rsp_size
;
2358 npages
= DIV_ROUND_UP(len
, PAGE_SIZE
);
2360 pages
= kmalloc_array(npages
, sizeof(struct page
*), GFP_KERNEL
);
2366 for (; i
< npages
; i
++) {
2367 pages
[i
] = alloc_page(GFP_KERNEL
|__GFP_HIGHMEM
);
2374 /* read read data into pages */
2375 rc
= read_data_into_pages(server
, pages
, npages
, len
);
2379 rc
= cifs_discard_remaining_data(server
);
2383 rc
= decrypt_raw_data(server
, buf
, server
->vals
->read_rsp_size
- 4,
2384 pages
, npages
, len
);
2388 *mid
= smb2_find_mid(server
, buf
);
2390 cifs_dbg(FYI
, "mid not found\n");
2392 cifs_dbg(FYI
, "mid found\n");
2393 (*mid
)->decrypted
= true;
2394 rc
= handle_read_data(server
, *mid
, buf
,
2395 server
->vals
->read_rsp_size
,
2396 pages
, npages
, len
);
2400 for (i
= i
- 1; i
>= 0; i
--)
2405 cifs_discard_remaining_data(server
);
2410 receive_encrypted_standard(struct TCP_Server_Info
*server
,
2411 struct mid_q_entry
**mid
)
2414 char *buf
= server
->smallbuf
;
2415 unsigned int pdu_length
= get_rfc1002_length(buf
);
2416 unsigned int buf_size
;
2417 struct mid_q_entry
*mid_entry
;
2419 /* switch to large buffer if too big for a small one */
2420 if (pdu_length
+ 4 > MAX_CIFS_SMALL_BUFFER_SIZE
) {
2421 server
->large_buf
= true;
2422 memcpy(server
->bigbuf
, buf
, server
->total_read
);
2423 buf
= server
->bigbuf
;
2426 /* now read the rest */
2427 length
= cifs_read_from_socket(server
, buf
+ HEADER_SIZE(server
) - 1,
2428 pdu_length
- HEADER_SIZE(server
) + 1 + 4);
2431 server
->total_read
+= length
;
2433 buf_size
= pdu_length
+ 4 - sizeof(struct smb2_transform_hdr
);
2434 length
= decrypt_raw_data(server
, buf
, buf_size
, NULL
, 0, 0);
2438 mid_entry
= smb2_find_mid(server
, buf
);
2439 if (mid_entry
== NULL
)
2440 cifs_dbg(FYI
, "mid not found\n");
2442 cifs_dbg(FYI
, "mid found\n");
2443 mid_entry
->decrypted
= true;
2448 if (mid_entry
&& mid_entry
->handle
)
2449 return mid_entry
->handle(server
, mid_entry
);
2451 return cifs_handle_standard(server
, mid_entry
);
2455 smb3_receive_transform(struct TCP_Server_Info
*server
, struct mid_q_entry
**mid
)
2457 char *buf
= server
->smallbuf
;
2458 unsigned int pdu_length
= get_rfc1002_length(buf
);
2459 struct smb2_transform_hdr
*tr_hdr
= (struct smb2_transform_hdr
*)buf
;
2460 unsigned int orig_len
= le32_to_cpu(tr_hdr
->OriginalMessageSize
);
2462 if (pdu_length
+ 4 < sizeof(struct smb2_transform_hdr
) +
2463 sizeof(struct smb2_sync_hdr
)) {
2464 cifs_dbg(VFS
, "Transform message is too small (%u)\n",
2466 cifs_reconnect(server
);
2467 wake_up(&server
->response_q
);
2468 return -ECONNABORTED
;
2471 if (pdu_length
+ 4 < orig_len
+ sizeof(struct smb2_transform_hdr
)) {
2472 cifs_dbg(VFS
, "Transform message is broken\n");
2473 cifs_reconnect(server
);
2474 wake_up(&server
->response_q
);
2475 return -ECONNABORTED
;
2478 if (pdu_length
+ 4 > CIFSMaxBufSize
+ MAX_HEADER_SIZE(server
))
2479 return receive_encrypted_read(server
, mid
);
2481 return receive_encrypted_standard(server
, mid
);
2485 smb3_handle_read_data(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
)
2487 char *buf
= server
->large_buf
? server
->bigbuf
: server
->smallbuf
;
2489 return handle_read_data(server
, mid
, buf
, get_rfc1002_length(buf
) + 4,
2493 struct smb_version_operations smb20_operations
= {
2494 .compare_fids
= smb2_compare_fids
,
2495 .setup_request
= smb2_setup_request
,
2496 .setup_async_request
= smb2_setup_async_request
,
2497 .check_receive
= smb2_check_receive
,
2498 .add_credits
= smb2_add_credits
,
2499 .set_credits
= smb2_set_credits
,
2500 .get_credits_field
= smb2_get_credits_field
,
2501 .get_credits
= smb2_get_credits
,
2502 .wait_mtu_credits
= cifs_wait_mtu_credits
,
2503 .get_next_mid
= smb2_get_next_mid
,
2504 .read_data_offset
= smb2_read_data_offset
,
2505 .read_data_length
= smb2_read_data_length
,
2506 .map_error
= map_smb2_to_linux_error
,
2507 .find_mid
= smb2_find_mid
,
2508 .check_message
= smb2_check_message
,
2509 .dump_detail
= smb2_dump_detail
,
2510 .clear_stats
= smb2_clear_stats
,
2511 .print_stats
= smb2_print_stats
,
2512 .is_oplock_break
= smb2_is_valid_oplock_break
,
2513 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
2514 .downgrade_oplock
= smb2_downgrade_oplock
,
2515 .need_neg
= smb2_need_neg
,
2516 .negotiate
= smb2_negotiate
,
2517 .negotiate_wsize
= smb2_negotiate_wsize
,
2518 .negotiate_rsize
= smb2_negotiate_rsize
,
2519 .sess_setup
= SMB2_sess_setup
,
2520 .logoff
= SMB2_logoff
,
2521 .tree_connect
= SMB2_tcon
,
2522 .tree_disconnect
= SMB2_tdis
,
2523 .qfs_tcon
= smb2_qfs_tcon
,
2524 .is_path_accessible
= smb2_is_path_accessible
,
2525 .can_echo
= smb2_can_echo
,
2527 .query_path_info
= smb2_query_path_info
,
2528 .get_srv_inum
= smb2_get_srv_inum
,
2529 .query_file_info
= smb2_query_file_info
,
2530 .set_path_size
= smb2_set_path_size
,
2531 .set_file_size
= smb2_set_file_size
,
2532 .set_file_info
= smb2_set_file_info
,
2533 .set_compression
= smb2_set_compression
,
2534 .mkdir
= smb2_mkdir
,
2535 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2536 .rmdir
= smb2_rmdir
,
2537 .unlink
= smb2_unlink
,
2538 .rename
= smb2_rename_path
,
2539 .create_hardlink
= smb2_create_hardlink
,
2540 .query_symlink
= smb2_query_symlink
,
2541 .query_mf_symlink
= smb3_query_mf_symlink
,
2542 .create_mf_symlink
= smb3_create_mf_symlink
,
2543 .open
= smb2_open_file
,
2544 .set_fid
= smb2_set_fid
,
2545 .close
= smb2_close_file
,
2546 .flush
= smb2_flush_file
,
2547 .async_readv
= smb2_async_readv
,
2548 .async_writev
= smb2_async_writev
,
2549 .sync_read
= smb2_sync_read
,
2550 .sync_write
= smb2_sync_write
,
2551 .query_dir_first
= smb2_query_dir_first
,
2552 .query_dir_next
= smb2_query_dir_next
,
2553 .close_dir
= smb2_close_dir
,
2554 .calc_smb_size
= smb2_calc_size
,
2555 .is_status_pending
= smb2_is_status_pending
,
2556 .is_session_expired
= smb2_is_session_expired
,
2557 .oplock_response
= smb2_oplock_response
,
2558 .queryfs
= smb2_queryfs
,
2559 .mand_lock
= smb2_mand_lock
,
2560 .mand_unlock_range
= smb2_unlock_range
,
2561 .push_mand_locks
= smb2_push_mandatory_locks
,
2562 .get_lease_key
= smb2_get_lease_key
,
2563 .set_lease_key
= smb2_set_lease_key
,
2564 .new_lease_key
= smb2_new_lease_key
,
2565 .calc_signature
= smb2_calc_signature
,
2566 .is_read_op
= smb2_is_read_op
,
2567 .set_oplock_level
= smb2_set_oplock_level
,
2568 .create_lease_buf
= smb2_create_lease_buf
,
2569 .parse_lease_buf
= smb2_parse_lease_buf
,
2570 .copychunk_range
= smb2_copychunk_range
,
2571 .wp_retry_size
= smb2_wp_retry_size
,
2572 .dir_needs_close
= smb2_dir_needs_close
,
2573 .get_dfs_refer
= smb2_get_dfs_refer
,
2574 .select_sectype
= smb2_select_sectype
,
2575 #ifdef CONFIG_CIFS_ACL
2576 .get_acl
= get_smb2_acl
,
2577 .get_acl_by_fid
= get_smb2_acl_by_fid
,
2578 .set_acl
= set_smb2_acl
,
2579 #endif /* CIFS_ACL */
2582 struct smb_version_operations smb21_operations
= {
2583 .compare_fids
= smb2_compare_fids
,
2584 .setup_request
= smb2_setup_request
,
2585 .setup_async_request
= smb2_setup_async_request
,
2586 .check_receive
= smb2_check_receive
,
2587 .add_credits
= smb2_add_credits
,
2588 .set_credits
= smb2_set_credits
,
2589 .get_credits_field
= smb2_get_credits_field
,
2590 .get_credits
= smb2_get_credits
,
2591 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2592 .get_next_mid
= smb2_get_next_mid
,
2593 .read_data_offset
= smb2_read_data_offset
,
2594 .read_data_length
= smb2_read_data_length
,
2595 .map_error
= map_smb2_to_linux_error
,
2596 .find_mid
= smb2_find_mid
,
2597 .check_message
= smb2_check_message
,
2598 .dump_detail
= smb2_dump_detail
,
2599 .clear_stats
= smb2_clear_stats
,
2600 .print_stats
= smb2_print_stats
,
2601 .is_oplock_break
= smb2_is_valid_oplock_break
,
2602 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
2603 .downgrade_oplock
= smb2_downgrade_oplock
,
2604 .need_neg
= smb2_need_neg
,
2605 .negotiate
= smb2_negotiate
,
2606 .negotiate_wsize
= smb2_negotiate_wsize
,
2607 .negotiate_rsize
= smb2_negotiate_rsize
,
2608 .sess_setup
= SMB2_sess_setup
,
2609 .logoff
= SMB2_logoff
,
2610 .tree_connect
= SMB2_tcon
,
2611 .tree_disconnect
= SMB2_tdis
,
2612 .qfs_tcon
= smb2_qfs_tcon
,
2613 .is_path_accessible
= smb2_is_path_accessible
,
2614 .can_echo
= smb2_can_echo
,
2616 .query_path_info
= smb2_query_path_info
,
2617 .get_srv_inum
= smb2_get_srv_inum
,
2618 .query_file_info
= smb2_query_file_info
,
2619 .set_path_size
= smb2_set_path_size
,
2620 .set_file_size
= smb2_set_file_size
,
2621 .set_file_info
= smb2_set_file_info
,
2622 .set_compression
= smb2_set_compression
,
2623 .mkdir
= smb2_mkdir
,
2624 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2625 .rmdir
= smb2_rmdir
,
2626 .unlink
= smb2_unlink
,
2627 .rename
= smb2_rename_path
,
2628 .create_hardlink
= smb2_create_hardlink
,
2629 .query_symlink
= smb2_query_symlink
,
2630 .query_mf_symlink
= smb3_query_mf_symlink
,
2631 .create_mf_symlink
= smb3_create_mf_symlink
,
2632 .open
= smb2_open_file
,
2633 .set_fid
= smb2_set_fid
,
2634 .close
= smb2_close_file
,
2635 .flush
= smb2_flush_file
,
2636 .async_readv
= smb2_async_readv
,
2637 .async_writev
= smb2_async_writev
,
2638 .sync_read
= smb2_sync_read
,
2639 .sync_write
= smb2_sync_write
,
2640 .query_dir_first
= smb2_query_dir_first
,
2641 .query_dir_next
= smb2_query_dir_next
,
2642 .close_dir
= smb2_close_dir
,
2643 .calc_smb_size
= smb2_calc_size
,
2644 .is_status_pending
= smb2_is_status_pending
,
2645 .is_session_expired
= smb2_is_session_expired
,
2646 .oplock_response
= smb2_oplock_response
,
2647 .queryfs
= smb2_queryfs
,
2648 .mand_lock
= smb2_mand_lock
,
2649 .mand_unlock_range
= smb2_unlock_range
,
2650 .push_mand_locks
= smb2_push_mandatory_locks
,
2651 .get_lease_key
= smb2_get_lease_key
,
2652 .set_lease_key
= smb2_set_lease_key
,
2653 .new_lease_key
= smb2_new_lease_key
,
2654 .calc_signature
= smb2_calc_signature
,
2655 .is_read_op
= smb21_is_read_op
,
2656 .set_oplock_level
= smb21_set_oplock_level
,
2657 .create_lease_buf
= smb2_create_lease_buf
,
2658 .parse_lease_buf
= smb2_parse_lease_buf
,
2659 .copychunk_range
= smb2_copychunk_range
,
2660 .wp_retry_size
= smb2_wp_retry_size
,
2661 .dir_needs_close
= smb2_dir_needs_close
,
2662 .enum_snapshots
= smb3_enum_snapshots
,
2663 .get_dfs_refer
= smb2_get_dfs_refer
,
2664 .select_sectype
= smb2_select_sectype
,
2665 #ifdef CONFIG_CIFS_ACL
2666 .get_acl
= get_smb2_acl
,
2667 .get_acl_by_fid
= get_smb2_acl_by_fid
,
2668 .set_acl
= set_smb2_acl
,
2669 #endif /* CIFS_ACL */
2672 struct smb_version_operations smb30_operations
= {
2673 .compare_fids
= smb2_compare_fids
,
2674 .setup_request
= smb2_setup_request
,
2675 .setup_async_request
= smb2_setup_async_request
,
2676 .check_receive
= smb2_check_receive
,
2677 .add_credits
= smb2_add_credits
,
2678 .set_credits
= smb2_set_credits
,
2679 .get_credits_field
= smb2_get_credits_field
,
2680 .get_credits
= smb2_get_credits
,
2681 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2682 .get_next_mid
= smb2_get_next_mid
,
2683 .read_data_offset
= smb2_read_data_offset
,
2684 .read_data_length
= smb2_read_data_length
,
2685 .map_error
= map_smb2_to_linux_error
,
2686 .find_mid
= smb2_find_mid
,
2687 .check_message
= smb2_check_message
,
2688 .dump_detail
= smb2_dump_detail
,
2689 .clear_stats
= smb2_clear_stats
,
2690 .print_stats
= smb2_print_stats
,
2691 .dump_share_caps
= smb2_dump_share_caps
,
2692 .is_oplock_break
= smb2_is_valid_oplock_break
,
2693 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
2694 .downgrade_oplock
= smb2_downgrade_oplock
,
2695 .need_neg
= smb2_need_neg
,
2696 .negotiate
= smb2_negotiate
,
2697 .negotiate_wsize
= smb2_negotiate_wsize
,
2698 .negotiate_rsize
= smb2_negotiate_rsize
,
2699 .sess_setup
= SMB2_sess_setup
,
2700 .logoff
= SMB2_logoff
,
2701 .tree_connect
= SMB2_tcon
,
2702 .tree_disconnect
= SMB2_tdis
,
2703 .qfs_tcon
= smb3_qfs_tcon
,
2704 .is_path_accessible
= smb2_is_path_accessible
,
2705 .can_echo
= smb2_can_echo
,
2707 .query_path_info
= smb2_query_path_info
,
2708 .get_srv_inum
= smb2_get_srv_inum
,
2709 .query_file_info
= smb2_query_file_info
,
2710 .set_path_size
= smb2_set_path_size
,
2711 .set_file_size
= smb2_set_file_size
,
2712 .set_file_info
= smb2_set_file_info
,
2713 .set_compression
= smb2_set_compression
,
2714 .mkdir
= smb2_mkdir
,
2715 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2716 .rmdir
= smb2_rmdir
,
2717 .unlink
= smb2_unlink
,
2718 .rename
= smb2_rename_path
,
2719 .create_hardlink
= smb2_create_hardlink
,
2720 .query_symlink
= smb2_query_symlink
,
2721 .query_mf_symlink
= smb3_query_mf_symlink
,
2722 .create_mf_symlink
= smb3_create_mf_symlink
,
2723 .open
= smb2_open_file
,
2724 .set_fid
= smb2_set_fid
,
2725 .close
= smb2_close_file
,
2726 .flush
= smb2_flush_file
,
2727 .async_readv
= smb2_async_readv
,
2728 .async_writev
= smb2_async_writev
,
2729 .sync_read
= smb2_sync_read
,
2730 .sync_write
= smb2_sync_write
,
2731 .query_dir_first
= smb2_query_dir_first
,
2732 .query_dir_next
= smb2_query_dir_next
,
2733 .close_dir
= smb2_close_dir
,
2734 .calc_smb_size
= smb2_calc_size
,
2735 .is_status_pending
= smb2_is_status_pending
,
2736 .is_session_expired
= smb2_is_session_expired
,
2737 .oplock_response
= smb2_oplock_response
,
2738 .queryfs
= smb2_queryfs
,
2739 .mand_lock
= smb2_mand_lock
,
2740 .mand_unlock_range
= smb2_unlock_range
,
2741 .push_mand_locks
= smb2_push_mandatory_locks
,
2742 .get_lease_key
= smb2_get_lease_key
,
2743 .set_lease_key
= smb2_set_lease_key
,
2744 .new_lease_key
= smb2_new_lease_key
,
2745 .generate_signingkey
= generate_smb30signingkey
,
2746 .calc_signature
= smb3_calc_signature
,
2747 .set_integrity
= smb3_set_integrity
,
2748 .is_read_op
= smb21_is_read_op
,
2749 .set_oplock_level
= smb3_set_oplock_level
,
2750 .create_lease_buf
= smb3_create_lease_buf
,
2751 .parse_lease_buf
= smb3_parse_lease_buf
,
2752 .copychunk_range
= smb2_copychunk_range
,
2753 .duplicate_extents
= smb2_duplicate_extents
,
2754 .validate_negotiate
= smb3_validate_negotiate
,
2755 .wp_retry_size
= smb2_wp_retry_size
,
2756 .dir_needs_close
= smb2_dir_needs_close
,
2757 .fallocate
= smb3_fallocate
,
2758 .enum_snapshots
= smb3_enum_snapshots
,
2759 .init_transform_rq
= smb3_init_transform_rq
,
2760 .free_transform_rq
= smb3_free_transform_rq
,
2761 .is_transform_hdr
= smb3_is_transform_hdr
,
2762 .receive_transform
= smb3_receive_transform
,
2763 .get_dfs_refer
= smb2_get_dfs_refer
,
2764 .select_sectype
= smb2_select_sectype
,
2765 #ifdef CONFIG_CIFS_ACL
2766 .get_acl
= get_smb2_acl
,
2767 .get_acl_by_fid
= get_smb2_acl_by_fid
,
2768 .set_acl
= set_smb2_acl
,
2769 #endif /* CIFS_ACL */
2772 #ifdef CONFIG_CIFS_SMB311
2773 struct smb_version_operations smb311_operations
= {
2774 .compare_fids
= smb2_compare_fids
,
2775 .setup_request
= smb2_setup_request
,
2776 .setup_async_request
= smb2_setup_async_request
,
2777 .check_receive
= smb2_check_receive
,
2778 .add_credits
= smb2_add_credits
,
2779 .set_credits
= smb2_set_credits
,
2780 .get_credits_field
= smb2_get_credits_field
,
2781 .get_credits
= smb2_get_credits
,
2782 .wait_mtu_credits
= smb2_wait_mtu_credits
,
2783 .get_next_mid
= smb2_get_next_mid
,
2784 .read_data_offset
= smb2_read_data_offset
,
2785 .read_data_length
= smb2_read_data_length
,
2786 .map_error
= map_smb2_to_linux_error
,
2787 .find_mid
= smb2_find_mid
,
2788 .check_message
= smb2_check_message
,
2789 .dump_detail
= smb2_dump_detail
,
2790 .clear_stats
= smb2_clear_stats
,
2791 .print_stats
= smb2_print_stats
,
2792 .dump_share_caps
= smb2_dump_share_caps
,
2793 .is_oplock_break
= smb2_is_valid_oplock_break
,
2794 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
2795 .downgrade_oplock
= smb2_downgrade_oplock
,
2796 .need_neg
= smb2_need_neg
,
2797 .negotiate
= smb2_negotiate
,
2798 .negotiate_wsize
= smb2_negotiate_wsize
,
2799 .negotiate_rsize
= smb2_negotiate_rsize
,
2800 .sess_setup
= SMB2_sess_setup
,
2801 .logoff
= SMB2_logoff
,
2802 .tree_connect
= SMB2_tcon
,
2803 .tree_disconnect
= SMB2_tdis
,
2804 .qfs_tcon
= smb3_qfs_tcon
,
2805 .is_path_accessible
= smb2_is_path_accessible
,
2806 .can_echo
= smb2_can_echo
,
2808 .query_path_info
= smb2_query_path_info
,
2809 .get_srv_inum
= smb2_get_srv_inum
,
2810 .query_file_info
= smb2_query_file_info
,
2811 .set_path_size
= smb2_set_path_size
,
2812 .set_file_size
= smb2_set_file_size
,
2813 .set_file_info
= smb2_set_file_info
,
2814 .set_compression
= smb2_set_compression
,
2815 .mkdir
= smb2_mkdir
,
2816 .mkdir_setinfo
= smb2_mkdir_setinfo
,
2817 .rmdir
= smb2_rmdir
,
2818 .unlink
= smb2_unlink
,
2819 .rename
= smb2_rename_path
,
2820 .create_hardlink
= smb2_create_hardlink
,
2821 .query_symlink
= smb2_query_symlink
,
2822 .query_mf_symlink
= smb3_query_mf_symlink
,
2823 .create_mf_symlink
= smb3_create_mf_symlink
,
2824 .open
= smb2_open_file
,
2825 .set_fid
= smb2_set_fid
,
2826 .close
= smb2_close_file
,
2827 .flush
= smb2_flush_file
,
2828 .async_readv
= smb2_async_readv
,
2829 .async_writev
= smb2_async_writev
,
2830 .sync_read
= smb2_sync_read
,
2831 .sync_write
= smb2_sync_write
,
2832 .query_dir_first
= smb2_query_dir_first
,
2833 .query_dir_next
= smb2_query_dir_next
,
2834 .close_dir
= smb2_close_dir
,
2835 .calc_smb_size
= smb2_calc_size
,
2836 .is_status_pending
= smb2_is_status_pending
,
2837 .is_session_expired
= smb2_is_session_expired
,
2838 .oplock_response
= smb2_oplock_response
,
2839 .queryfs
= smb2_queryfs
,
2840 .mand_lock
= smb2_mand_lock
,
2841 .mand_unlock_range
= smb2_unlock_range
,
2842 .push_mand_locks
= smb2_push_mandatory_locks
,
2843 .get_lease_key
= smb2_get_lease_key
,
2844 .set_lease_key
= smb2_set_lease_key
,
2845 .new_lease_key
= smb2_new_lease_key
,
2846 .generate_signingkey
= generate_smb311signingkey
,
2847 .calc_signature
= smb3_calc_signature
,
2848 .set_integrity
= smb3_set_integrity
,
2849 .is_read_op
= smb21_is_read_op
,
2850 .set_oplock_level
= smb3_set_oplock_level
,
2851 .create_lease_buf
= smb3_create_lease_buf
,
2852 .parse_lease_buf
= smb3_parse_lease_buf
,
2853 .copychunk_range
= smb2_copychunk_range
,
2854 .duplicate_extents
= smb2_duplicate_extents
,
2855 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
2856 .wp_retry_size
= smb2_wp_retry_size
,
2857 .dir_needs_close
= smb2_dir_needs_close
,
2858 .fallocate
= smb3_fallocate
,
2859 .enum_snapshots
= smb3_enum_snapshots
,
2860 .init_transform_rq
= smb3_init_transform_rq
,
2861 .free_transform_rq
= smb3_free_transform_rq
,
2862 .is_transform_hdr
= smb3_is_transform_hdr
,
2863 .receive_transform
= smb3_receive_transform
,
2864 .get_dfs_refer
= smb2_get_dfs_refer
,
2865 .select_sectype
= smb2_select_sectype
,
2867 #endif /* CIFS_SMB311 */
2869 struct smb_version_values smb20_values
= {
2870 .version_string
= SMB20_VERSION_STRING
,
2871 .protocol_id
= SMB20_PROT_ID
,
2872 .req_capabilities
= 0, /* MBZ */
2873 .large_lock_type
= 0,
2874 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2875 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2876 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2877 .header_size
= sizeof(struct smb2_hdr
),
2878 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2879 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2880 .lock_cmd
= SMB2_LOCK
,
2882 .cap_nt_find
= SMB2_NT_FIND
,
2883 .cap_large_files
= SMB2_LARGE_FILES
,
2884 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2885 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2886 .create_lease_size
= sizeof(struct create_lease
),
2889 struct smb_version_values smb21_values
= {
2890 .version_string
= SMB21_VERSION_STRING
,
2891 .protocol_id
= SMB21_PROT_ID
,
2892 .req_capabilities
= 0, /* MBZ on negotiate req until SMB3 dialect */
2893 .large_lock_type
= 0,
2894 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2895 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2896 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2897 .header_size
= sizeof(struct smb2_hdr
),
2898 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2899 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2900 .lock_cmd
= SMB2_LOCK
,
2902 .cap_nt_find
= SMB2_NT_FIND
,
2903 .cap_large_files
= SMB2_LARGE_FILES
,
2904 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2905 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2906 .create_lease_size
= sizeof(struct create_lease
),
2909 struct smb_version_values smb30_values
= {
2910 .version_string
= SMB30_VERSION_STRING
,
2911 .protocol_id
= SMB30_PROT_ID
,
2912 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
2913 .large_lock_type
= 0,
2914 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2915 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2916 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2917 .header_size
= sizeof(struct smb2_hdr
),
2918 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2919 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2920 .lock_cmd
= SMB2_LOCK
,
2922 .cap_nt_find
= SMB2_NT_FIND
,
2923 .cap_large_files
= SMB2_LARGE_FILES
,
2924 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2925 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2926 .create_lease_size
= sizeof(struct create_lease_v2
),
2929 struct smb_version_values smb302_values
= {
2930 .version_string
= SMB302_VERSION_STRING
,
2931 .protocol_id
= SMB302_PROT_ID
,
2932 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
2933 .large_lock_type
= 0,
2934 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2935 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2936 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2937 .header_size
= sizeof(struct smb2_hdr
),
2938 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2939 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2940 .lock_cmd
= SMB2_LOCK
,
2942 .cap_nt_find
= SMB2_NT_FIND
,
2943 .cap_large_files
= SMB2_LARGE_FILES
,
2944 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2945 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2946 .create_lease_size
= sizeof(struct create_lease_v2
),
2949 #ifdef CONFIG_CIFS_SMB311
2950 struct smb_version_values smb311_values
= {
2951 .version_string
= SMB311_VERSION_STRING
,
2952 .protocol_id
= SMB311_PROT_ID
,
2953 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
2954 .large_lock_type
= 0,
2955 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
2956 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
2957 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
2958 .header_size
= sizeof(struct smb2_hdr
),
2959 .max_header_size
= MAX_SMB2_HDR_SIZE
,
2960 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
2961 .lock_cmd
= SMB2_LOCK
,
2963 .cap_nt_find
= SMB2_NT_FIND
,
2964 .cap_large_files
= SMB2_LARGE_FILES
,
2965 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2966 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
2967 .create_lease_size
= sizeof(struct create_lease_v2
),