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>
24 #include "smb2proto.h"
25 #include "cifsproto.h"
26 #include "cifs_debug.h"
27 #include "cifs_unicode.h"
28 #include "smb2status.h"
32 change_conf(struct TCP_Server_Info
*server
)
34 server
->credits
+= server
->echo_credits
+ server
->oplock_credits
;
35 server
->oplock_credits
= server
->echo_credits
= 0;
36 switch (server
->credits
) {
40 server
->echoes
= false;
41 server
->oplocks
= false;
42 cifs_dbg(VFS
, "disabling echoes and oplocks\n");
45 server
->echoes
= true;
46 server
->oplocks
= false;
47 server
->echo_credits
= 1;
48 cifs_dbg(FYI
, "disabling oplocks\n");
51 server
->echoes
= true;
52 server
->oplocks
= true;
53 server
->echo_credits
= 1;
54 server
->oplock_credits
= 1;
56 server
->credits
-= server
->echo_credits
+ server
->oplock_credits
;
61 smb2_add_credits(struct TCP_Server_Info
*server
, const unsigned int add
,
65 spin_lock(&server
->req_lock
);
66 val
= server
->ops
->get_credits_field(server
, optype
);
69 if (server
->in_flight
== 0 && (optype
& CIFS_OP_MASK
) != CIFS_NEG_OP
)
70 rc
= change_conf(server
);
72 * Sometimes server returns 0 credits on oplock break ack - we need to
73 * rebalance credits in this case.
75 else if (server
->in_flight
> 0 && server
->oplock_credits
== 0 &&
77 if (server
->credits
> 1) {
79 server
->oplock_credits
++;
82 spin_unlock(&server
->req_lock
);
83 wake_up(&server
->request_q
);
85 cifs_reconnect(server
);
89 smb2_set_credits(struct TCP_Server_Info
*server
, const int val
)
91 spin_lock(&server
->req_lock
);
92 server
->credits
= val
;
93 spin_unlock(&server
->req_lock
);
97 smb2_get_credits_field(struct TCP_Server_Info
*server
, const int optype
)
101 return &server
->echo_credits
;
103 return &server
->oplock_credits
;
105 return &server
->credits
;
110 smb2_get_credits(struct mid_q_entry
*mid
)
112 return le16_to_cpu(((struct smb2_hdr
*)mid
->resp_buf
)->CreditRequest
);
116 smb2_get_next_mid(struct TCP_Server_Info
*server
)
119 /* for SMB2 we need the current value */
120 spin_lock(&GlobalMid_Lock
);
121 mid
= server
->CurrentMid
++;
122 spin_unlock(&GlobalMid_Lock
);
126 static struct mid_q_entry
*
127 smb2_find_mid(struct TCP_Server_Info
*server
, char *buf
)
129 struct mid_q_entry
*mid
;
130 struct smb2_hdr
*hdr
= (struct smb2_hdr
*)buf
;
132 spin_lock(&GlobalMid_Lock
);
133 list_for_each_entry(mid
, &server
->pending_mid_q
, qhead
) {
134 if ((mid
->mid
== hdr
->MessageId
) &&
135 (mid
->mid_state
== MID_REQUEST_SUBMITTED
) &&
136 (mid
->command
== hdr
->Command
)) {
137 spin_unlock(&GlobalMid_Lock
);
141 spin_unlock(&GlobalMid_Lock
);
146 smb2_dump_detail(void *buf
)
148 #ifdef CONFIG_CIFS_DEBUG2
149 struct smb2_hdr
*smb
= (struct smb2_hdr
*)buf
;
151 cifs_dbg(VFS
, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
152 smb
->Command
, smb
->Status
, smb
->Flags
, smb
->MessageId
,
154 cifs_dbg(VFS
, "smb buf %p len %u\n", smb
, smb2_calc_size(smb
));
159 smb2_need_neg(struct TCP_Server_Info
*server
)
161 return server
->max_read
== 0;
165 smb2_negotiate(const unsigned int xid
, struct cifs_ses
*ses
)
168 ses
->server
->CurrentMid
= 0;
169 rc
= SMB2_negotiate(xid
, ses
);
170 /* BB we probably don't need to retry with modern servers */
177 smb2_negotiate_wsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
179 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
182 /* start with specified wsize, or default */
183 wsize
= volume_info
->wsize
? volume_info
->wsize
: CIFS_DEFAULT_IOSIZE
;
184 wsize
= min_t(unsigned int, wsize
, server
->max_write
);
185 /* set it to the maximum buffer size value we can send with 1 credit */
186 wsize
= min_t(unsigned int, wsize
, SMB2_MAX_BUFFER_SIZE
);
192 smb2_negotiate_rsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
194 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
197 /* start with specified rsize, or default */
198 rsize
= volume_info
->rsize
? volume_info
->rsize
: CIFS_DEFAULT_IOSIZE
;
199 rsize
= min_t(unsigned int, rsize
, server
->max_read
);
200 /* set it to the maximum buffer size value we can send with 1 credit */
201 rsize
= min_t(unsigned int, rsize
, SMB2_MAX_BUFFER_SIZE
);
206 #ifdef CONFIG_CIFS_STATS2
208 SMB3_request_interfaces(const unsigned int xid
, struct cifs_tcon
*tcon
)
211 unsigned int ret_data_len
= 0;
212 struct network_interface_info_ioctl_rsp
*out_buf
;
214 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
215 FSCTL_QUERY_NETWORK_INTERFACE_INFO
, true /* is_fsctl */,
216 NULL
/* no data input */, 0 /* no data input */,
217 (char **)&out_buf
, &ret_data_len
);
219 if ((rc
== 0) && (ret_data_len
> 0)) {
220 /* Dump info on first interface */
221 cifs_dbg(FYI
, "Adapter Capability 0x%x\t",
222 le32_to_cpu(out_buf
->Capability
));
223 cifs_dbg(FYI
, "Link Speed %lld\n",
224 le64_to_cpu(out_buf
->LinkSpeed
));
226 cifs_dbg(VFS
, "error %d on ioctl to get interface list\n", rc
);
233 smb3_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
236 __le16 srch_path
= 0; /* Null - open root of share */
237 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
238 struct cifs_open_parms oparms
;
242 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
243 oparms
.disposition
= FILE_OPEN
;
244 oparms
.create_options
= 0;
246 oparms
.reconnect
= false;
248 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
252 #ifdef CONFIG_CIFS_STATS2
253 SMB3_request_interfaces(xid
, tcon
);
256 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
257 FS_ATTRIBUTE_INFORMATION
);
258 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
259 FS_DEVICE_INFORMATION
);
260 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
261 FS_SECTOR_SIZE_INFORMATION
); /* SMB3 specific */
262 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
267 smb2_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
270 __le16 srch_path
= 0; /* Null - open root of share */
271 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
272 struct cifs_open_parms oparms
;
276 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
277 oparms
.disposition
= FILE_OPEN
;
278 oparms
.create_options
= 0;
280 oparms
.reconnect
= false;
282 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
286 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
287 FS_ATTRIBUTE_INFORMATION
);
288 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
289 FS_DEVICE_INFORMATION
);
290 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
295 smb2_is_path_accessible(const unsigned int xid
, struct cifs_tcon
*tcon
,
296 struct cifs_sb_info
*cifs_sb
, const char *full_path
)
300 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
301 struct cifs_open_parms oparms
;
304 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
309 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
310 oparms
.disposition
= FILE_OPEN
;
311 oparms
.create_options
= 0;
313 oparms
.reconnect
= false;
315 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
321 rc
= SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
327 smb2_get_srv_inum(const unsigned int xid
, struct cifs_tcon
*tcon
,
328 struct cifs_sb_info
*cifs_sb
, const char *full_path
,
329 u64
*uniqueid
, FILE_ALL_INFO
*data
)
331 *uniqueid
= le64_to_cpu(data
->IndexNumber
);
336 smb2_query_file_info(const unsigned int xid
, struct cifs_tcon
*tcon
,
337 struct cifs_fid
*fid
, FILE_ALL_INFO
*data
)
340 struct smb2_file_all_info
*smb2_data
;
342 smb2_data
= kzalloc(sizeof(struct smb2_file_all_info
) + MAX_NAME
* 2,
344 if (smb2_data
== NULL
)
347 rc
= SMB2_query_info(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
,
350 move_smb2_info_to_cifs(data
, smb2_data
);
356 smb2_can_echo(struct TCP_Server_Info
*server
)
358 return server
->echoes
;
362 smb2_clear_stats(struct cifs_tcon
*tcon
)
364 #ifdef CONFIG_CIFS_STATS
366 for (i
= 0; i
< NUMBER_OF_SMB2_COMMANDS
; i
++) {
367 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_sent
[i
], 0);
368 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_failed
[i
], 0);
374 smb2_dump_share_caps(struct seq_file
*m
, struct cifs_tcon
*tcon
)
376 seq_puts(m
, "\n\tShare Capabilities:");
377 if (tcon
->capabilities
& SMB2_SHARE_CAP_DFS
)
378 seq_puts(m
, " DFS,");
379 if (tcon
->capabilities
& SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY
)
380 seq_puts(m
, " CONTINUOUS AVAILABILITY,");
381 if (tcon
->capabilities
& SMB2_SHARE_CAP_SCALEOUT
)
382 seq_puts(m
, " SCALEOUT,");
383 if (tcon
->capabilities
& SMB2_SHARE_CAP_CLUSTER
)
384 seq_puts(m
, " CLUSTER,");
385 if (tcon
->capabilities
& SMB2_SHARE_CAP_ASYMMETRIC
)
386 seq_puts(m
, " ASYMMETRIC,");
387 if (tcon
->capabilities
== 0)
388 seq_puts(m
, " None");
389 if (tcon
->ss_flags
& SSINFO_FLAGS_ALIGNED_DEVICE
)
390 seq_puts(m
, " Aligned,");
391 if (tcon
->ss_flags
& SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE
)
392 seq_puts(m
, " Partition Aligned,");
393 if (tcon
->ss_flags
& SSINFO_FLAGS_NO_SEEK_PENALTY
)
394 seq_puts(m
, " SSD,");
395 if (tcon
->ss_flags
& SSINFO_FLAGS_TRIM_ENABLED
)
396 seq_puts(m
, " TRIM-support,");
398 seq_printf(m
, "\tShare Flags: 0x%x", tcon
->share_flags
);
399 if (tcon
->perf_sector_size
)
400 seq_printf(m
, "\tOptimal sector size: 0x%x",
401 tcon
->perf_sector_size
);
405 smb2_print_stats(struct seq_file
*m
, struct cifs_tcon
*tcon
)
407 #ifdef CONFIG_CIFS_STATS
408 atomic_t
*sent
= tcon
->stats
.smb2_stats
.smb2_com_sent
;
409 atomic_t
*failed
= tcon
->stats
.smb2_stats
.smb2_com_failed
;
410 seq_printf(m
, "\nNegotiates: %d sent %d failed",
411 atomic_read(&sent
[SMB2_NEGOTIATE_HE
]),
412 atomic_read(&failed
[SMB2_NEGOTIATE_HE
]));
413 seq_printf(m
, "\nSessionSetups: %d sent %d failed",
414 atomic_read(&sent
[SMB2_SESSION_SETUP_HE
]),
415 atomic_read(&failed
[SMB2_SESSION_SETUP_HE
]));
416 seq_printf(m
, "\nLogoffs: %d sent %d failed",
417 atomic_read(&sent
[SMB2_LOGOFF_HE
]),
418 atomic_read(&failed
[SMB2_LOGOFF_HE
]));
419 seq_printf(m
, "\nTreeConnects: %d sent %d failed",
420 atomic_read(&sent
[SMB2_TREE_CONNECT_HE
]),
421 atomic_read(&failed
[SMB2_TREE_CONNECT_HE
]));
422 seq_printf(m
, "\nTreeDisconnects: %d sent %d failed",
423 atomic_read(&sent
[SMB2_TREE_DISCONNECT_HE
]),
424 atomic_read(&failed
[SMB2_TREE_DISCONNECT_HE
]));
425 seq_printf(m
, "\nCreates: %d sent %d failed",
426 atomic_read(&sent
[SMB2_CREATE_HE
]),
427 atomic_read(&failed
[SMB2_CREATE_HE
]));
428 seq_printf(m
, "\nCloses: %d sent %d failed",
429 atomic_read(&sent
[SMB2_CLOSE_HE
]),
430 atomic_read(&failed
[SMB2_CLOSE_HE
]));
431 seq_printf(m
, "\nFlushes: %d sent %d failed",
432 atomic_read(&sent
[SMB2_FLUSH_HE
]),
433 atomic_read(&failed
[SMB2_FLUSH_HE
]));
434 seq_printf(m
, "\nReads: %d sent %d failed",
435 atomic_read(&sent
[SMB2_READ_HE
]),
436 atomic_read(&failed
[SMB2_READ_HE
]));
437 seq_printf(m
, "\nWrites: %d sent %d failed",
438 atomic_read(&sent
[SMB2_WRITE_HE
]),
439 atomic_read(&failed
[SMB2_WRITE_HE
]));
440 seq_printf(m
, "\nLocks: %d sent %d failed",
441 atomic_read(&sent
[SMB2_LOCK_HE
]),
442 atomic_read(&failed
[SMB2_LOCK_HE
]));
443 seq_printf(m
, "\nIOCTLs: %d sent %d failed",
444 atomic_read(&sent
[SMB2_IOCTL_HE
]),
445 atomic_read(&failed
[SMB2_IOCTL_HE
]));
446 seq_printf(m
, "\nCancels: %d sent %d failed",
447 atomic_read(&sent
[SMB2_CANCEL_HE
]),
448 atomic_read(&failed
[SMB2_CANCEL_HE
]));
449 seq_printf(m
, "\nEchos: %d sent %d failed",
450 atomic_read(&sent
[SMB2_ECHO_HE
]),
451 atomic_read(&failed
[SMB2_ECHO_HE
]));
452 seq_printf(m
, "\nQueryDirectories: %d sent %d failed",
453 atomic_read(&sent
[SMB2_QUERY_DIRECTORY_HE
]),
454 atomic_read(&failed
[SMB2_QUERY_DIRECTORY_HE
]));
455 seq_printf(m
, "\nChangeNotifies: %d sent %d failed",
456 atomic_read(&sent
[SMB2_CHANGE_NOTIFY_HE
]),
457 atomic_read(&failed
[SMB2_CHANGE_NOTIFY_HE
]));
458 seq_printf(m
, "\nQueryInfos: %d sent %d failed",
459 atomic_read(&sent
[SMB2_QUERY_INFO_HE
]),
460 atomic_read(&failed
[SMB2_QUERY_INFO_HE
]));
461 seq_printf(m
, "\nSetInfos: %d sent %d failed",
462 atomic_read(&sent
[SMB2_SET_INFO_HE
]),
463 atomic_read(&failed
[SMB2_SET_INFO_HE
]));
464 seq_printf(m
, "\nOplockBreaks: %d sent %d failed",
465 atomic_read(&sent
[SMB2_OPLOCK_BREAK_HE
]),
466 atomic_read(&failed
[SMB2_OPLOCK_BREAK_HE
]));
471 smb2_set_fid(struct cifsFileInfo
*cfile
, struct cifs_fid
*fid
, __u32 oplock
)
473 struct cifsInodeInfo
*cinode
= CIFS_I(cfile
->dentry
->d_inode
);
474 struct TCP_Server_Info
*server
= tlink_tcon(cfile
->tlink
)->ses
->server
;
476 cfile
->fid
.persistent_fid
= fid
->persistent_fid
;
477 cfile
->fid
.volatile_fid
= fid
->volatile_fid
;
478 server
->ops
->set_oplock_level(cinode
, oplock
, fid
->epoch
,
480 cinode
->can_cache_brlcks
= CIFS_CACHE_WRITE(cinode
);
484 smb2_close_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
485 struct cifs_fid
*fid
)
487 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
491 SMB2_request_res_key(const unsigned int xid
, struct cifs_tcon
*tcon
,
492 u64 persistent_fid
, u64 volatile_fid
,
493 struct copychunk_ioctl
*pcchunk
)
496 unsigned int ret_data_len
;
497 struct resume_key_req
*res_key
;
499 rc
= SMB2_ioctl(xid
, tcon
, persistent_fid
, volatile_fid
,
500 FSCTL_SRV_REQUEST_RESUME_KEY
, true /* is_fsctl */,
501 NULL
, 0 /* no input */,
502 (char **)&res_key
, &ret_data_len
);
505 cifs_dbg(VFS
, "refcpy ioctl error %d getting resume key\n", rc
);
506 goto req_res_key_exit
;
508 if (ret_data_len
< sizeof(struct resume_key_req
)) {
509 cifs_dbg(VFS
, "Invalid refcopy resume key length\n");
511 goto req_res_key_exit
;
513 memcpy(pcchunk
->SourceKey
, res_key
->ResumeKey
, COPY_CHUNK_RES_KEY_SIZE
);
521 smb2_clone_range(const unsigned int xid
,
522 struct cifsFileInfo
*srcfile
,
523 struct cifsFileInfo
*trgtfile
, u64 src_off
,
524 u64 len
, u64 dest_off
)
527 unsigned int ret_data_len
;
528 struct copychunk_ioctl
*pcchunk
;
529 struct copychunk_ioctl_rsp
*retbuf
= NULL
;
530 struct cifs_tcon
*tcon
;
531 int chunks_copied
= 0;
532 bool chunk_sizes_updated
= false;
534 pcchunk
= kmalloc(sizeof(struct copychunk_ioctl
), GFP_KERNEL
);
539 cifs_dbg(FYI
, "in smb2_clone_range - about to call request res key\n");
540 /* Request a key from the server to identify the source of the copy */
541 rc
= SMB2_request_res_key(xid
, tlink_tcon(srcfile
->tlink
),
542 srcfile
->fid
.persistent_fid
,
543 srcfile
->fid
.volatile_fid
, pcchunk
);
545 /* Note: request_res_key sets res_key null only if rc !=0 */
549 /* For now array only one chunk long, will make more flexible later */
550 pcchunk
->ChunkCount
= __constant_cpu_to_le32(1);
551 pcchunk
->Reserved
= 0;
552 pcchunk
->Reserved2
= 0;
554 tcon
= tlink_tcon(trgtfile
->tlink
);
557 pcchunk
->SourceOffset
= cpu_to_le64(src_off
);
558 pcchunk
->TargetOffset
= cpu_to_le64(dest_off
);
560 cpu_to_le32(min_t(u32
, len
, tcon
->max_bytes_chunk
));
562 /* Request server copy to target from src identified by key */
563 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
564 trgtfile
->fid
.volatile_fid
, FSCTL_SRV_COPYCHUNK_WRITE
,
565 true /* is_fsctl */, (char *)pcchunk
,
566 sizeof(struct copychunk_ioctl
), (char **)&retbuf
,
570 sizeof(struct copychunk_ioctl_rsp
)) {
571 cifs_dbg(VFS
, "invalid cchunk response size\n");
575 if (retbuf
->TotalBytesWritten
== 0) {
576 cifs_dbg(FYI
, "no bytes copied\n");
581 * Check if server claimed to write more than we asked
583 if (le32_to_cpu(retbuf
->TotalBytesWritten
) >
584 le32_to_cpu(pcchunk
->Length
)) {
585 cifs_dbg(VFS
, "invalid copy chunk response\n");
589 if (le32_to_cpu(retbuf
->ChunksWritten
) != 1) {
590 cifs_dbg(VFS
, "invalid num chunks written\n");
596 src_off
+= le32_to_cpu(retbuf
->TotalBytesWritten
);
597 dest_off
+= le32_to_cpu(retbuf
->TotalBytesWritten
);
598 len
-= le32_to_cpu(retbuf
->TotalBytesWritten
);
600 cifs_dbg(FYI
, "Chunks %d PartialChunk %d Total %d\n",
601 le32_to_cpu(retbuf
->ChunksWritten
),
602 le32_to_cpu(retbuf
->ChunkBytesWritten
),
603 le32_to_cpu(retbuf
->TotalBytesWritten
));
604 } else if (rc
== -EINVAL
) {
605 if (ret_data_len
!= sizeof(struct copychunk_ioctl_rsp
))
608 cifs_dbg(FYI
, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
609 le32_to_cpu(retbuf
->ChunksWritten
),
610 le32_to_cpu(retbuf
->ChunkBytesWritten
),
611 le32_to_cpu(retbuf
->TotalBytesWritten
));
614 * Check if this is the first request using these sizes,
615 * (ie check if copy succeed once with original sizes
616 * and check if the server gave us different sizes after
617 * we already updated max sizes on previous request).
618 * if not then why is the server returning an error now
620 if ((chunks_copied
!= 0) || chunk_sizes_updated
)
623 /* Check that server is not asking us to grow size */
624 if (le32_to_cpu(retbuf
->ChunkBytesWritten
) <
625 tcon
->max_bytes_chunk
)
626 tcon
->max_bytes_chunk
=
627 le32_to_cpu(retbuf
->ChunkBytesWritten
);
629 goto cchunk_out
; /* server gave us bogus size */
631 /* No need to change MaxChunks since already set to 1 */
632 chunk_sizes_updated
= true;
642 smb2_flush_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
643 struct cifs_fid
*fid
)
645 return SMB2_flush(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
649 smb2_read_data_offset(char *buf
)
651 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
652 return rsp
->DataOffset
;
656 smb2_read_data_length(char *buf
)
658 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
659 return le32_to_cpu(rsp
->DataLength
);
664 smb2_sync_read(const unsigned int xid
, struct cifsFileInfo
*cfile
,
665 struct cifs_io_parms
*parms
, unsigned int *bytes_read
,
666 char **buf
, int *buf_type
)
668 parms
->persistent_fid
= cfile
->fid
.persistent_fid
;
669 parms
->volatile_fid
= cfile
->fid
.volatile_fid
;
670 return SMB2_read(xid
, parms
, bytes_read
, buf
, buf_type
);
674 smb2_sync_write(const unsigned int xid
, struct cifsFileInfo
*cfile
,
675 struct cifs_io_parms
*parms
, unsigned int *written
,
676 struct kvec
*iov
, unsigned long nr_segs
)
679 parms
->persistent_fid
= cfile
->fid
.persistent_fid
;
680 parms
->volatile_fid
= cfile
->fid
.volatile_fid
;
681 return SMB2_write(xid
, parms
, written
, iov
, nr_segs
);
685 smb2_set_file_size(const unsigned int xid
, struct cifs_tcon
*tcon
,
686 struct cifsFileInfo
*cfile
, __u64 size
, bool set_alloc
)
688 __le64 eof
= cpu_to_le64(size
);
689 return SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
690 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
);
694 smb2_set_compression(const unsigned int xid
, struct cifs_tcon
*tcon
,
695 struct cifsFileInfo
*cfile
)
697 return SMB2_set_compression(xid
, tcon
, cfile
->fid
.persistent_fid
,
698 cfile
->fid
.volatile_fid
);
702 smb2_query_dir_first(const unsigned int xid
, struct cifs_tcon
*tcon
,
703 const char *path
, struct cifs_sb_info
*cifs_sb
,
704 struct cifs_fid
*fid
, __u16 search_flags
,
705 struct cifs_search_info
*srch_inf
)
709 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
710 struct cifs_open_parms oparms
;
712 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
717 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| FILE_READ_DATA
;
718 oparms
.disposition
= FILE_OPEN
;
719 oparms
.create_options
= 0;
721 oparms
.reconnect
= false;
723 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
726 cifs_dbg(VFS
, "open dir failed\n");
730 srch_inf
->entries_in_buffer
= 0;
731 srch_inf
->index_of_last_entry
= 0;
733 rc
= SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
734 fid
->volatile_fid
, 0, srch_inf
);
736 cifs_dbg(VFS
, "query directory failed\n");
737 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
743 smb2_query_dir_next(const unsigned int xid
, struct cifs_tcon
*tcon
,
744 struct cifs_fid
*fid
, __u16 search_flags
,
745 struct cifs_search_info
*srch_inf
)
747 return SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
748 fid
->volatile_fid
, 0, srch_inf
);
752 smb2_close_dir(const unsigned int xid
, struct cifs_tcon
*tcon
,
753 struct cifs_fid
*fid
)
755 return SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
759 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
760 * the number of credits and return true. Otherwise - return false.
763 smb2_is_status_pending(char *buf
, struct TCP_Server_Info
*server
, int length
)
765 struct smb2_hdr
*hdr
= (struct smb2_hdr
*)buf
;
767 if (hdr
->Status
!= STATUS_PENDING
)
771 spin_lock(&server
->req_lock
);
772 server
->credits
+= le16_to_cpu(hdr
->CreditRequest
);
773 spin_unlock(&server
->req_lock
);
774 wake_up(&server
->request_q
);
781 smb2_oplock_response(struct cifs_tcon
*tcon
, struct cifs_fid
*fid
,
782 struct cifsInodeInfo
*cinode
)
784 if (tcon
->ses
->server
->capabilities
& SMB2_GLOBAL_CAP_LEASING
)
785 return SMB2_lease_break(0, tcon
, cinode
->lease_key
,
786 smb2_get_lease_state(cinode
));
788 return SMB2_oplock_break(0, tcon
, fid
->persistent_fid
,
790 CIFS_CACHE_READ(cinode
) ? 1 : 0);
794 smb2_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
798 __le16 srch_path
= 0; /* Null - open root of share */
799 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
800 struct cifs_open_parms oparms
;
804 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
805 oparms
.disposition
= FILE_OPEN
;
806 oparms
.create_options
= 0;
808 oparms
.reconnect
= false;
810 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
813 buf
->f_type
= SMB2_MAGIC_NUMBER
;
814 rc
= SMB2_QFS_info(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
816 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
821 smb2_compare_fids(struct cifsFileInfo
*ob1
, struct cifsFileInfo
*ob2
)
823 return ob1
->fid
.persistent_fid
== ob2
->fid
.persistent_fid
&&
824 ob1
->fid
.volatile_fid
== ob2
->fid
.volatile_fid
;
828 smb2_mand_lock(const unsigned int xid
, struct cifsFileInfo
*cfile
, __u64 offset
,
829 __u64 length
, __u32 type
, int lock
, int unlock
, bool wait
)
832 type
= SMB2_LOCKFLAG_UNLOCK
;
833 return SMB2_lock(xid
, tlink_tcon(cfile
->tlink
),
834 cfile
->fid
.persistent_fid
, cfile
->fid
.volatile_fid
,
835 current
->tgid
, length
, offset
, type
, wait
);
839 smb2_get_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
841 memcpy(fid
->lease_key
, CIFS_I(inode
)->lease_key
, SMB2_LEASE_KEY_SIZE
);
845 smb2_set_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
847 memcpy(CIFS_I(inode
)->lease_key
, fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
851 smb2_new_lease_key(struct cifs_fid
*fid
)
853 get_random_bytes(fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
857 smb2_query_symlink(const unsigned int xid
, struct cifs_tcon
*tcon
,
858 const char *full_path
, char **target_path
,
859 struct cifs_sb_info
*cifs_sb
)
863 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
864 struct cifs_open_parms oparms
;
866 struct smb2_err_rsp
*err_buf
= NULL
;
867 struct smb2_symlink_err_rsp
*symlink
;
868 unsigned int sub_len
, sub_offset
;
870 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, full_path
);
872 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
877 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
878 oparms
.disposition
= FILE_OPEN
;
879 oparms
.create_options
= 0;
881 oparms
.reconnect
= false;
883 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, &err_buf
);
885 if (!rc
|| !err_buf
) {
889 /* open must fail on symlink - reset rc */
891 symlink
= (struct smb2_symlink_err_rsp
*)err_buf
->ErrorData
;
892 sub_len
= le16_to_cpu(symlink
->SubstituteNameLength
);
893 sub_offset
= le16_to_cpu(symlink
->SubstituteNameOffset
);
894 *target_path
= cifs_strndup_from_utf16(
895 (char *)symlink
->PathBuffer
+ sub_offset
,
896 sub_len
, true, cifs_sb
->local_nls
);
897 if (!(*target_path
)) {
901 convert_delimiter(*target_path
, '/');
902 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
908 smb2_downgrade_oplock(struct TCP_Server_Info
*server
,
909 struct cifsInodeInfo
*cinode
, bool set_level2
)
912 server
->ops
->set_oplock_level(cinode
, SMB2_OPLOCK_LEVEL_II
,
915 server
->ops
->set_oplock_level(cinode
, 0, 0, NULL
);
919 smb2_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
920 unsigned int epoch
, bool *purge_cache
)
923 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
925 if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
) {
926 cinode
->oplock
= CIFS_CACHE_RHW_FLG
;
927 cifs_dbg(FYI
, "Batch Oplock granted on inode %p\n",
929 } else if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
) {
930 cinode
->oplock
= CIFS_CACHE_RW_FLG
;
931 cifs_dbg(FYI
, "Exclusive Oplock granted on inode %p\n",
933 } else if (oplock
== SMB2_OPLOCK_LEVEL_II
) {
934 cinode
->oplock
= CIFS_CACHE_READ_FLG
;
935 cifs_dbg(FYI
, "Level II Oplock granted on inode %p\n",
942 smb21_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
943 unsigned int epoch
, bool *purge_cache
)
945 char message
[5] = {0};
948 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
952 if (oplock
& SMB2_LEASE_READ_CACHING_HE
) {
953 cinode
->oplock
|= CIFS_CACHE_READ_FLG
;
954 strcat(message
, "R");
956 if (oplock
& SMB2_LEASE_HANDLE_CACHING_HE
) {
957 cinode
->oplock
|= CIFS_CACHE_HANDLE_FLG
;
958 strcat(message
, "H");
960 if (oplock
& SMB2_LEASE_WRITE_CACHING_HE
) {
961 cinode
->oplock
|= CIFS_CACHE_WRITE_FLG
;
962 strcat(message
, "W");
965 strcat(message
, "None");
966 cifs_dbg(FYI
, "%s Lease granted on inode %p\n", message
,
971 smb3_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
972 unsigned int epoch
, bool *purge_cache
)
974 unsigned int old_oplock
= cinode
->oplock
;
976 smb21_set_oplock_level(cinode
, oplock
, epoch
, purge_cache
);
979 *purge_cache
= false;
980 if (old_oplock
== CIFS_CACHE_READ_FLG
) {
981 if (cinode
->oplock
== CIFS_CACHE_READ_FLG
&&
982 (epoch
- cinode
->epoch
> 0))
984 else if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
985 (epoch
- cinode
->epoch
> 1))
987 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
988 (epoch
- cinode
->epoch
> 1))
990 else if (cinode
->oplock
== 0 &&
991 (epoch
- cinode
->epoch
> 0))
993 } else if (old_oplock
== CIFS_CACHE_RH_FLG
) {
994 if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
995 (epoch
- cinode
->epoch
> 0))
997 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
998 (epoch
- cinode
->epoch
> 1))
1001 cinode
->epoch
= epoch
;
1006 smb2_is_read_op(__u32 oplock
)
1008 return oplock
== SMB2_OPLOCK_LEVEL_II
;
1012 smb21_is_read_op(__u32 oplock
)
1014 return (oplock
& SMB2_LEASE_READ_CACHING_HE
) &&
1015 !(oplock
& SMB2_LEASE_WRITE_CACHING_HE
);
1019 map_oplock_to_lease(u8 oplock
)
1021 if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
)
1022 return SMB2_LEASE_WRITE_CACHING
| SMB2_LEASE_READ_CACHING
;
1023 else if (oplock
== SMB2_OPLOCK_LEVEL_II
)
1024 return SMB2_LEASE_READ_CACHING
;
1025 else if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
)
1026 return SMB2_LEASE_HANDLE_CACHING
| SMB2_LEASE_READ_CACHING
|
1027 SMB2_LEASE_WRITE_CACHING
;
1032 smb2_create_lease_buf(u8
*lease_key
, u8 oplock
)
1034 struct create_lease
*buf
;
1036 buf
= kzalloc(sizeof(struct create_lease
), GFP_KERNEL
);
1040 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1041 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1042 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1044 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1045 (struct create_lease
, lcontext
));
1046 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context
));
1047 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1048 (struct create_lease
, Name
));
1049 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1050 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1059 smb3_create_lease_buf(u8
*lease_key
, u8 oplock
)
1061 struct create_lease_v2
*buf
;
1063 buf
= kzalloc(sizeof(struct create_lease_v2
), GFP_KERNEL
);
1067 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1068 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1069 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1071 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1072 (struct create_lease_v2
, lcontext
));
1073 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context_v2
));
1074 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1075 (struct create_lease_v2
, Name
));
1076 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1077 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1086 smb2_parse_lease_buf(void *buf
, unsigned int *epoch
)
1088 struct create_lease
*lc
= (struct create_lease
*)buf
;
1090 *epoch
= 0; /* not used */
1091 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
1092 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
1093 return le32_to_cpu(lc
->lcontext
.LeaseState
);
1097 smb3_parse_lease_buf(void *buf
, unsigned int *epoch
)
1099 struct create_lease_v2
*lc
= (struct create_lease_v2
*)buf
;
1101 *epoch
= le16_to_cpu(lc
->lcontext
.Epoch
);
1102 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
1103 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
1104 return le32_to_cpu(lc
->lcontext
.LeaseState
);
1107 struct smb_version_operations smb20_operations
= {
1108 .compare_fids
= smb2_compare_fids
,
1109 .setup_request
= smb2_setup_request
,
1110 .setup_async_request
= smb2_setup_async_request
,
1111 .check_receive
= smb2_check_receive
,
1112 .add_credits
= smb2_add_credits
,
1113 .set_credits
= smb2_set_credits
,
1114 .get_credits_field
= smb2_get_credits_field
,
1115 .get_credits
= smb2_get_credits
,
1116 .get_next_mid
= smb2_get_next_mid
,
1117 .read_data_offset
= smb2_read_data_offset
,
1118 .read_data_length
= smb2_read_data_length
,
1119 .map_error
= map_smb2_to_linux_error
,
1120 .find_mid
= smb2_find_mid
,
1121 .check_message
= smb2_check_message
,
1122 .dump_detail
= smb2_dump_detail
,
1123 .clear_stats
= smb2_clear_stats
,
1124 .print_stats
= smb2_print_stats
,
1125 .is_oplock_break
= smb2_is_valid_oplock_break
,
1126 .downgrade_oplock
= smb2_downgrade_oplock
,
1127 .need_neg
= smb2_need_neg
,
1128 .negotiate
= smb2_negotiate
,
1129 .negotiate_wsize
= smb2_negotiate_wsize
,
1130 .negotiate_rsize
= smb2_negotiate_rsize
,
1131 .sess_setup
= SMB2_sess_setup
,
1132 .logoff
= SMB2_logoff
,
1133 .tree_connect
= SMB2_tcon
,
1134 .tree_disconnect
= SMB2_tdis
,
1135 .qfs_tcon
= smb2_qfs_tcon
,
1136 .is_path_accessible
= smb2_is_path_accessible
,
1137 .can_echo
= smb2_can_echo
,
1139 .query_path_info
= smb2_query_path_info
,
1140 .get_srv_inum
= smb2_get_srv_inum
,
1141 .query_file_info
= smb2_query_file_info
,
1142 .set_path_size
= smb2_set_path_size
,
1143 .set_file_size
= smb2_set_file_size
,
1144 .set_file_info
= smb2_set_file_info
,
1145 .set_compression
= smb2_set_compression
,
1146 .mkdir
= smb2_mkdir
,
1147 .mkdir_setinfo
= smb2_mkdir_setinfo
,
1148 .rmdir
= smb2_rmdir
,
1149 .unlink
= smb2_unlink
,
1150 .rename
= smb2_rename_path
,
1151 .create_hardlink
= smb2_create_hardlink
,
1152 .query_symlink
= smb2_query_symlink
,
1153 .open
= smb2_open_file
,
1154 .set_fid
= smb2_set_fid
,
1155 .close
= smb2_close_file
,
1156 .flush
= smb2_flush_file
,
1157 .async_readv
= smb2_async_readv
,
1158 .async_writev
= smb2_async_writev
,
1159 .sync_read
= smb2_sync_read
,
1160 .sync_write
= smb2_sync_write
,
1161 .query_dir_first
= smb2_query_dir_first
,
1162 .query_dir_next
= smb2_query_dir_next
,
1163 .close_dir
= smb2_close_dir
,
1164 .calc_smb_size
= smb2_calc_size
,
1165 .is_status_pending
= smb2_is_status_pending
,
1166 .oplock_response
= smb2_oplock_response
,
1167 .queryfs
= smb2_queryfs
,
1168 .mand_lock
= smb2_mand_lock
,
1169 .mand_unlock_range
= smb2_unlock_range
,
1170 .push_mand_locks
= smb2_push_mandatory_locks
,
1171 .get_lease_key
= smb2_get_lease_key
,
1172 .set_lease_key
= smb2_set_lease_key
,
1173 .new_lease_key
= smb2_new_lease_key
,
1174 .calc_signature
= smb2_calc_signature
,
1175 .is_read_op
= smb2_is_read_op
,
1176 .set_oplock_level
= smb2_set_oplock_level
,
1177 .create_lease_buf
= smb2_create_lease_buf
,
1178 .parse_lease_buf
= smb2_parse_lease_buf
,
1179 .clone_range
= smb2_clone_range
,
1182 struct smb_version_operations smb21_operations
= {
1183 .compare_fids
= smb2_compare_fids
,
1184 .setup_request
= smb2_setup_request
,
1185 .setup_async_request
= smb2_setup_async_request
,
1186 .check_receive
= smb2_check_receive
,
1187 .add_credits
= smb2_add_credits
,
1188 .set_credits
= smb2_set_credits
,
1189 .get_credits_field
= smb2_get_credits_field
,
1190 .get_credits
= smb2_get_credits
,
1191 .get_next_mid
= smb2_get_next_mid
,
1192 .read_data_offset
= smb2_read_data_offset
,
1193 .read_data_length
= smb2_read_data_length
,
1194 .map_error
= map_smb2_to_linux_error
,
1195 .find_mid
= smb2_find_mid
,
1196 .check_message
= smb2_check_message
,
1197 .dump_detail
= smb2_dump_detail
,
1198 .clear_stats
= smb2_clear_stats
,
1199 .print_stats
= smb2_print_stats
,
1200 .is_oplock_break
= smb2_is_valid_oplock_break
,
1201 .downgrade_oplock
= smb2_downgrade_oplock
,
1202 .need_neg
= smb2_need_neg
,
1203 .negotiate
= smb2_negotiate
,
1204 .negotiate_wsize
= smb2_negotiate_wsize
,
1205 .negotiate_rsize
= smb2_negotiate_rsize
,
1206 .sess_setup
= SMB2_sess_setup
,
1207 .logoff
= SMB2_logoff
,
1208 .tree_connect
= SMB2_tcon
,
1209 .tree_disconnect
= SMB2_tdis
,
1210 .qfs_tcon
= smb2_qfs_tcon
,
1211 .is_path_accessible
= smb2_is_path_accessible
,
1212 .can_echo
= smb2_can_echo
,
1214 .query_path_info
= smb2_query_path_info
,
1215 .get_srv_inum
= smb2_get_srv_inum
,
1216 .query_file_info
= smb2_query_file_info
,
1217 .set_path_size
= smb2_set_path_size
,
1218 .set_file_size
= smb2_set_file_size
,
1219 .set_file_info
= smb2_set_file_info
,
1220 .set_compression
= smb2_set_compression
,
1221 .mkdir
= smb2_mkdir
,
1222 .mkdir_setinfo
= smb2_mkdir_setinfo
,
1223 .rmdir
= smb2_rmdir
,
1224 .unlink
= smb2_unlink
,
1225 .rename
= smb2_rename_path
,
1226 .create_hardlink
= smb2_create_hardlink
,
1227 .query_symlink
= smb2_query_symlink
,
1228 .open
= smb2_open_file
,
1229 .set_fid
= smb2_set_fid
,
1230 .close
= smb2_close_file
,
1231 .flush
= smb2_flush_file
,
1232 .async_readv
= smb2_async_readv
,
1233 .async_writev
= smb2_async_writev
,
1234 .sync_read
= smb2_sync_read
,
1235 .sync_write
= smb2_sync_write
,
1236 .query_dir_first
= smb2_query_dir_first
,
1237 .query_dir_next
= smb2_query_dir_next
,
1238 .close_dir
= smb2_close_dir
,
1239 .calc_smb_size
= smb2_calc_size
,
1240 .is_status_pending
= smb2_is_status_pending
,
1241 .oplock_response
= smb2_oplock_response
,
1242 .queryfs
= smb2_queryfs
,
1243 .mand_lock
= smb2_mand_lock
,
1244 .mand_unlock_range
= smb2_unlock_range
,
1245 .push_mand_locks
= smb2_push_mandatory_locks
,
1246 .get_lease_key
= smb2_get_lease_key
,
1247 .set_lease_key
= smb2_set_lease_key
,
1248 .new_lease_key
= smb2_new_lease_key
,
1249 .calc_signature
= smb2_calc_signature
,
1250 .is_read_op
= smb21_is_read_op
,
1251 .set_oplock_level
= smb21_set_oplock_level
,
1252 .create_lease_buf
= smb2_create_lease_buf
,
1253 .parse_lease_buf
= smb2_parse_lease_buf
,
1254 .clone_range
= smb2_clone_range
,
1257 struct smb_version_operations smb30_operations
= {
1258 .compare_fids
= smb2_compare_fids
,
1259 .setup_request
= smb2_setup_request
,
1260 .setup_async_request
= smb2_setup_async_request
,
1261 .check_receive
= smb2_check_receive
,
1262 .add_credits
= smb2_add_credits
,
1263 .set_credits
= smb2_set_credits
,
1264 .get_credits_field
= smb2_get_credits_field
,
1265 .get_credits
= smb2_get_credits
,
1266 .get_next_mid
= smb2_get_next_mid
,
1267 .read_data_offset
= smb2_read_data_offset
,
1268 .read_data_length
= smb2_read_data_length
,
1269 .map_error
= map_smb2_to_linux_error
,
1270 .find_mid
= smb2_find_mid
,
1271 .check_message
= smb2_check_message
,
1272 .dump_detail
= smb2_dump_detail
,
1273 .clear_stats
= smb2_clear_stats
,
1274 .print_stats
= smb2_print_stats
,
1275 .dump_share_caps
= smb2_dump_share_caps
,
1276 .is_oplock_break
= smb2_is_valid_oplock_break
,
1277 .downgrade_oplock
= smb2_downgrade_oplock
,
1278 .need_neg
= smb2_need_neg
,
1279 .negotiate
= smb2_negotiate
,
1280 .negotiate_wsize
= smb2_negotiate_wsize
,
1281 .negotiate_rsize
= smb2_negotiate_rsize
,
1282 .sess_setup
= SMB2_sess_setup
,
1283 .logoff
= SMB2_logoff
,
1284 .tree_connect
= SMB2_tcon
,
1285 .tree_disconnect
= SMB2_tdis
,
1286 .qfs_tcon
= smb3_qfs_tcon
,
1287 .is_path_accessible
= smb2_is_path_accessible
,
1288 .can_echo
= smb2_can_echo
,
1290 .query_path_info
= smb2_query_path_info
,
1291 .get_srv_inum
= smb2_get_srv_inum
,
1292 .query_file_info
= smb2_query_file_info
,
1293 .set_path_size
= smb2_set_path_size
,
1294 .set_file_size
= smb2_set_file_size
,
1295 .set_file_info
= smb2_set_file_info
,
1296 .set_compression
= smb2_set_compression
,
1297 .mkdir
= smb2_mkdir
,
1298 .mkdir_setinfo
= smb2_mkdir_setinfo
,
1299 .rmdir
= smb2_rmdir
,
1300 .unlink
= smb2_unlink
,
1301 .rename
= smb2_rename_path
,
1302 .create_hardlink
= smb2_create_hardlink
,
1303 .query_symlink
= smb2_query_symlink
,
1304 .open
= smb2_open_file
,
1305 .set_fid
= smb2_set_fid
,
1306 .close
= smb2_close_file
,
1307 .flush
= smb2_flush_file
,
1308 .async_readv
= smb2_async_readv
,
1309 .async_writev
= smb2_async_writev
,
1310 .sync_read
= smb2_sync_read
,
1311 .sync_write
= smb2_sync_write
,
1312 .query_dir_first
= smb2_query_dir_first
,
1313 .query_dir_next
= smb2_query_dir_next
,
1314 .close_dir
= smb2_close_dir
,
1315 .calc_smb_size
= smb2_calc_size
,
1316 .is_status_pending
= smb2_is_status_pending
,
1317 .oplock_response
= smb2_oplock_response
,
1318 .queryfs
= smb2_queryfs
,
1319 .mand_lock
= smb2_mand_lock
,
1320 .mand_unlock_range
= smb2_unlock_range
,
1321 .push_mand_locks
= smb2_push_mandatory_locks
,
1322 .get_lease_key
= smb2_get_lease_key
,
1323 .set_lease_key
= smb2_set_lease_key
,
1324 .new_lease_key
= smb2_new_lease_key
,
1325 .generate_signingkey
= generate_smb3signingkey
,
1326 .calc_signature
= smb3_calc_signature
,
1327 .is_read_op
= smb21_is_read_op
,
1328 .set_oplock_level
= smb3_set_oplock_level
,
1329 .create_lease_buf
= smb3_create_lease_buf
,
1330 .parse_lease_buf
= smb3_parse_lease_buf
,
1331 .clone_range
= smb2_clone_range
,
1332 .validate_negotiate
= smb3_validate_negotiate
,
1335 struct smb_version_values smb20_values
= {
1336 .version_string
= SMB20_VERSION_STRING
,
1337 .protocol_id
= SMB20_PROT_ID
,
1338 .req_capabilities
= 0, /* MBZ */
1339 .large_lock_type
= 0,
1340 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1341 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1342 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1343 .header_size
= sizeof(struct smb2_hdr
),
1344 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1345 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1346 .lock_cmd
= SMB2_LOCK
,
1348 .cap_nt_find
= SMB2_NT_FIND
,
1349 .cap_large_files
= SMB2_LARGE_FILES
,
1350 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1351 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1352 .create_lease_size
= sizeof(struct create_lease
),
1355 struct smb_version_values smb21_values
= {
1356 .version_string
= SMB21_VERSION_STRING
,
1357 .protocol_id
= SMB21_PROT_ID
,
1358 .req_capabilities
= 0, /* MBZ on negotiate req until SMB3 dialect */
1359 .large_lock_type
= 0,
1360 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1361 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1362 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1363 .header_size
= sizeof(struct smb2_hdr
),
1364 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1365 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1366 .lock_cmd
= SMB2_LOCK
,
1368 .cap_nt_find
= SMB2_NT_FIND
,
1369 .cap_large_files
= SMB2_LARGE_FILES
,
1370 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1371 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1372 .create_lease_size
= sizeof(struct create_lease
),
1375 struct smb_version_values smb30_values
= {
1376 .version_string
= SMB30_VERSION_STRING
,
1377 .protocol_id
= SMB30_PROT_ID
,
1378 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
,
1379 .large_lock_type
= 0,
1380 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1381 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1382 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1383 .header_size
= sizeof(struct smb2_hdr
),
1384 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1385 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1386 .lock_cmd
= SMB2_LOCK
,
1388 .cap_nt_find
= SMB2_NT_FIND
,
1389 .cap_large_files
= SMB2_LARGE_FILES
,
1390 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1391 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1392 .create_lease_size
= sizeof(struct create_lease_v2
),
1395 struct smb_version_values smb302_values
= {
1396 .version_string
= SMB302_VERSION_STRING
,
1397 .protocol_id
= SMB302_PROT_ID
,
1398 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
,
1399 .large_lock_type
= 0,
1400 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1401 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1402 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1403 .header_size
= sizeof(struct smb2_hdr
),
1404 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1405 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1406 .lock_cmd
= SMB2_LOCK
,
1408 .cap_nt_find
= SMB2_NT_FIND
,
1409 .cap_large_files
= SMB2_LARGE_FILES
,
1410 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1411 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1412 .create_lease_size
= sizeof(struct create_lease_v2
),