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>
25 #include "smb2proto.h"
26 #include "cifsproto.h"
27 #include "cifs_debug.h"
28 #include "cifs_unicode.h"
29 #include "smb2status.h"
31 #include "cifs_ioctl.h"
34 change_conf(struct TCP_Server_Info
*server
)
36 server
->credits
+= server
->echo_credits
+ server
->oplock_credits
;
37 server
->oplock_credits
= server
->echo_credits
= 0;
38 switch (server
->credits
) {
42 server
->echoes
= false;
43 server
->oplocks
= false;
44 cifs_dbg(VFS
, "disabling echoes and oplocks\n");
47 server
->echoes
= true;
48 server
->oplocks
= false;
49 server
->echo_credits
= 1;
50 cifs_dbg(FYI
, "disabling oplocks\n");
53 server
->echoes
= true;
55 server
->oplocks
= true;
56 server
->oplock_credits
= 1;
58 server
->oplocks
= false;
60 server
->echo_credits
= 1;
62 server
->credits
-= server
->echo_credits
+ server
->oplock_credits
;
67 smb2_add_credits(struct TCP_Server_Info
*server
, const unsigned int add
,
71 spin_lock(&server
->req_lock
);
72 val
= server
->ops
->get_credits_field(server
, optype
);
75 *val
= 65000; /* Don't get near 64K credits, avoid srv bugs */
76 printk_once(KERN_WARNING
"server overflowed SMB3 credits\n");
79 if (server
->in_flight
== 0 && (optype
& CIFS_OP_MASK
) != CIFS_NEG_OP
)
80 rc
= change_conf(server
);
82 * Sometimes server returns 0 credits on oplock break ack - we need to
83 * rebalance credits in this case.
85 else if (server
->in_flight
> 0 && server
->oplock_credits
== 0 &&
87 if (server
->credits
> 1) {
89 server
->oplock_credits
++;
92 spin_unlock(&server
->req_lock
);
93 wake_up(&server
->request_q
);
95 cifs_reconnect(server
);
99 smb2_set_credits(struct TCP_Server_Info
*server
, const int val
)
101 spin_lock(&server
->req_lock
);
102 server
->credits
= val
;
103 spin_unlock(&server
->req_lock
);
107 smb2_get_credits_field(struct TCP_Server_Info
*server
, const int optype
)
111 return &server
->echo_credits
;
113 return &server
->oplock_credits
;
115 return &server
->credits
;
120 smb2_get_credits(struct mid_q_entry
*mid
)
122 return le16_to_cpu(((struct smb2_hdr
*)mid
->resp_buf
)->CreditRequest
);
126 smb2_wait_mtu_credits(struct TCP_Server_Info
*server
, unsigned int size
,
127 unsigned int *num
, unsigned int *credits
)
130 unsigned int scredits
;
132 spin_lock(&server
->req_lock
);
134 if (server
->credits
<= 0) {
135 spin_unlock(&server
->req_lock
);
136 cifs_num_waiters_inc(server
);
137 rc
= wait_event_killable(server
->request_q
,
138 has_credits(server
, &server
->credits
));
139 cifs_num_waiters_dec(server
);
142 spin_lock(&server
->req_lock
);
144 if (server
->tcpStatus
== CifsExiting
) {
145 spin_unlock(&server
->req_lock
);
149 scredits
= server
->credits
;
150 /* can deadlock with reopen */
152 *num
= SMB2_MAX_BUFFER_SIZE
;
157 /* leave one credit for a possible reopen */
159 *num
= min_t(unsigned int, size
,
160 scredits
* SMB2_MAX_BUFFER_SIZE
);
162 *credits
= DIV_ROUND_UP(*num
, SMB2_MAX_BUFFER_SIZE
);
163 server
->credits
-= *credits
;
168 spin_unlock(&server
->req_lock
);
173 smb2_get_next_mid(struct TCP_Server_Info
*server
)
176 /* for SMB2 we need the current value */
177 spin_lock(&GlobalMid_Lock
);
178 mid
= server
->CurrentMid
++;
179 spin_unlock(&GlobalMid_Lock
);
183 static struct mid_q_entry
*
184 smb2_find_mid(struct TCP_Server_Info
*server
, char *buf
)
186 struct mid_q_entry
*mid
;
187 struct smb2_hdr
*hdr
= (struct smb2_hdr
*)buf
;
188 __u64 wire_mid
= le64_to_cpu(hdr
->MessageId
);
190 if (hdr
->ProtocolId
== SMB2_TRANSFORM_PROTO_NUM
) {
191 cifs_dbg(VFS
, "encrypted frame parsing not supported yet");
195 spin_lock(&GlobalMid_Lock
);
196 list_for_each_entry(mid
, &server
->pending_mid_q
, qhead
) {
197 if ((mid
->mid
== wire_mid
) &&
198 (mid
->mid_state
== MID_REQUEST_SUBMITTED
) &&
199 (mid
->command
== hdr
->Command
)) {
200 spin_unlock(&GlobalMid_Lock
);
204 spin_unlock(&GlobalMid_Lock
);
209 smb2_dump_detail(void *buf
)
211 #ifdef CONFIG_CIFS_DEBUG2
212 struct smb2_hdr
*smb
= (struct smb2_hdr
*)buf
;
214 cifs_dbg(VFS
, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
215 smb
->Command
, smb
->Status
, smb
->Flags
, smb
->MessageId
,
217 cifs_dbg(VFS
, "smb buf %p len %u\n", smb
, smb2_calc_size(smb
));
222 smb2_need_neg(struct TCP_Server_Info
*server
)
224 return server
->max_read
== 0;
228 smb2_negotiate(const unsigned int xid
, struct cifs_ses
*ses
)
231 ses
->server
->CurrentMid
= 0;
232 rc
= SMB2_negotiate(xid
, ses
);
233 /* BB we probably don't need to retry with modern servers */
240 smb2_negotiate_wsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
242 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
245 /* start with specified wsize, or default */
246 wsize
= volume_info
->wsize
? volume_info
->wsize
: CIFS_DEFAULT_IOSIZE
;
247 wsize
= min_t(unsigned int, wsize
, server
->max_write
);
249 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
250 wsize
= min_t(unsigned int, wsize
, SMB2_MAX_BUFFER_SIZE
);
256 smb2_negotiate_rsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
258 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
261 /* start with specified rsize, or default */
262 rsize
= volume_info
->rsize
? volume_info
->rsize
: CIFS_DEFAULT_IOSIZE
;
263 rsize
= min_t(unsigned int, rsize
, server
->max_read
);
265 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
266 rsize
= min_t(unsigned int, rsize
, SMB2_MAX_BUFFER_SIZE
);
271 #ifdef CONFIG_CIFS_STATS2
273 SMB3_request_interfaces(const unsigned int xid
, struct cifs_tcon
*tcon
)
276 unsigned int ret_data_len
= 0;
277 struct network_interface_info_ioctl_rsp
*out_buf
;
279 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
280 FSCTL_QUERY_NETWORK_INTERFACE_INFO
, true /* is_fsctl */,
281 NULL
/* no data input */, 0 /* no data input */,
282 (char **)&out_buf
, &ret_data_len
);
284 cifs_dbg(VFS
, "error %d on ioctl to get interface list\n", rc
);
285 else if (ret_data_len
< sizeof(struct network_interface_info_ioctl_rsp
)) {
286 cifs_dbg(VFS
, "server returned bad net interface info buf\n");
289 /* Dump info on first interface */
290 cifs_dbg(FYI
, "Adapter Capability 0x%x\t",
291 le32_to_cpu(out_buf
->Capability
));
292 cifs_dbg(FYI
, "Link Speed %lld\n",
293 le64_to_cpu(out_buf
->LinkSpeed
));
301 smb3_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
304 __le16 srch_path
= 0; /* Null - open root of share */
305 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
306 struct cifs_open_parms oparms
;
310 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
311 oparms
.disposition
= FILE_OPEN
;
312 oparms
.create_options
= 0;
314 oparms
.reconnect
= false;
316 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
320 #ifdef CONFIG_CIFS_STATS2
321 SMB3_request_interfaces(xid
, tcon
);
324 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
325 FS_ATTRIBUTE_INFORMATION
);
326 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
327 FS_DEVICE_INFORMATION
);
328 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
329 FS_SECTOR_SIZE_INFORMATION
); /* SMB3 specific */
330 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
335 smb2_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
338 __le16 srch_path
= 0; /* Null - open root of share */
339 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
340 struct cifs_open_parms oparms
;
344 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
345 oparms
.disposition
= FILE_OPEN
;
346 oparms
.create_options
= 0;
348 oparms
.reconnect
= false;
350 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
354 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
355 FS_ATTRIBUTE_INFORMATION
);
356 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
357 FS_DEVICE_INFORMATION
);
358 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
363 smb2_is_path_accessible(const unsigned int xid
, struct cifs_tcon
*tcon
,
364 struct cifs_sb_info
*cifs_sb
, const char *full_path
)
368 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
369 struct cifs_open_parms oparms
;
372 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
377 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
378 oparms
.disposition
= FILE_OPEN
;
379 oparms
.create_options
= 0;
381 oparms
.reconnect
= false;
383 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
389 rc
= SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
395 smb2_get_srv_inum(const unsigned int xid
, struct cifs_tcon
*tcon
,
396 struct cifs_sb_info
*cifs_sb
, const char *full_path
,
397 u64
*uniqueid
, FILE_ALL_INFO
*data
)
399 *uniqueid
= le64_to_cpu(data
->IndexNumber
);
404 smb2_query_file_info(const unsigned int xid
, struct cifs_tcon
*tcon
,
405 struct cifs_fid
*fid
, FILE_ALL_INFO
*data
)
408 struct smb2_file_all_info
*smb2_data
;
410 smb2_data
= kzalloc(sizeof(struct smb2_file_all_info
) + PATH_MAX
* 2,
412 if (smb2_data
== NULL
)
415 rc
= SMB2_query_info(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
,
418 move_smb2_info_to_cifs(data
, smb2_data
);
424 smb2_can_echo(struct TCP_Server_Info
*server
)
426 return server
->echoes
;
430 smb2_clear_stats(struct cifs_tcon
*tcon
)
432 #ifdef CONFIG_CIFS_STATS
434 for (i
= 0; i
< NUMBER_OF_SMB2_COMMANDS
; i
++) {
435 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_sent
[i
], 0);
436 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_failed
[i
], 0);
442 smb2_dump_share_caps(struct seq_file
*m
, struct cifs_tcon
*tcon
)
444 seq_puts(m
, "\n\tShare Capabilities:");
445 if (tcon
->capabilities
& SMB2_SHARE_CAP_DFS
)
446 seq_puts(m
, " DFS,");
447 if (tcon
->capabilities
& SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY
)
448 seq_puts(m
, " CONTINUOUS AVAILABILITY,");
449 if (tcon
->capabilities
& SMB2_SHARE_CAP_SCALEOUT
)
450 seq_puts(m
, " SCALEOUT,");
451 if (tcon
->capabilities
& SMB2_SHARE_CAP_CLUSTER
)
452 seq_puts(m
, " CLUSTER,");
453 if (tcon
->capabilities
& SMB2_SHARE_CAP_ASYMMETRIC
)
454 seq_puts(m
, " ASYMMETRIC,");
455 if (tcon
->capabilities
== 0)
456 seq_puts(m
, " None");
457 if (tcon
->ss_flags
& SSINFO_FLAGS_ALIGNED_DEVICE
)
458 seq_puts(m
, " Aligned,");
459 if (tcon
->ss_flags
& SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE
)
460 seq_puts(m
, " Partition Aligned,");
461 if (tcon
->ss_flags
& SSINFO_FLAGS_NO_SEEK_PENALTY
)
462 seq_puts(m
, " SSD,");
463 if (tcon
->ss_flags
& SSINFO_FLAGS_TRIM_ENABLED
)
464 seq_puts(m
, " TRIM-support,");
466 seq_printf(m
, "\tShare Flags: 0x%x", tcon
->share_flags
);
467 if (tcon
->perf_sector_size
)
468 seq_printf(m
, "\tOptimal sector size: 0x%x",
469 tcon
->perf_sector_size
);
473 smb2_print_stats(struct seq_file
*m
, struct cifs_tcon
*tcon
)
475 #ifdef CONFIG_CIFS_STATS
476 atomic_t
*sent
= tcon
->stats
.smb2_stats
.smb2_com_sent
;
477 atomic_t
*failed
= tcon
->stats
.smb2_stats
.smb2_com_failed
;
478 seq_printf(m
, "\nNegotiates: %d sent %d failed",
479 atomic_read(&sent
[SMB2_NEGOTIATE_HE
]),
480 atomic_read(&failed
[SMB2_NEGOTIATE_HE
]));
481 seq_printf(m
, "\nSessionSetups: %d sent %d failed",
482 atomic_read(&sent
[SMB2_SESSION_SETUP_HE
]),
483 atomic_read(&failed
[SMB2_SESSION_SETUP_HE
]));
484 seq_printf(m
, "\nLogoffs: %d sent %d failed",
485 atomic_read(&sent
[SMB2_LOGOFF_HE
]),
486 atomic_read(&failed
[SMB2_LOGOFF_HE
]));
487 seq_printf(m
, "\nTreeConnects: %d sent %d failed",
488 atomic_read(&sent
[SMB2_TREE_CONNECT_HE
]),
489 atomic_read(&failed
[SMB2_TREE_CONNECT_HE
]));
490 seq_printf(m
, "\nTreeDisconnects: %d sent %d failed",
491 atomic_read(&sent
[SMB2_TREE_DISCONNECT_HE
]),
492 atomic_read(&failed
[SMB2_TREE_DISCONNECT_HE
]));
493 seq_printf(m
, "\nCreates: %d sent %d failed",
494 atomic_read(&sent
[SMB2_CREATE_HE
]),
495 atomic_read(&failed
[SMB2_CREATE_HE
]));
496 seq_printf(m
, "\nCloses: %d sent %d failed",
497 atomic_read(&sent
[SMB2_CLOSE_HE
]),
498 atomic_read(&failed
[SMB2_CLOSE_HE
]));
499 seq_printf(m
, "\nFlushes: %d sent %d failed",
500 atomic_read(&sent
[SMB2_FLUSH_HE
]),
501 atomic_read(&failed
[SMB2_FLUSH_HE
]));
502 seq_printf(m
, "\nReads: %d sent %d failed",
503 atomic_read(&sent
[SMB2_READ_HE
]),
504 atomic_read(&failed
[SMB2_READ_HE
]));
505 seq_printf(m
, "\nWrites: %d sent %d failed",
506 atomic_read(&sent
[SMB2_WRITE_HE
]),
507 atomic_read(&failed
[SMB2_WRITE_HE
]));
508 seq_printf(m
, "\nLocks: %d sent %d failed",
509 atomic_read(&sent
[SMB2_LOCK_HE
]),
510 atomic_read(&failed
[SMB2_LOCK_HE
]));
511 seq_printf(m
, "\nIOCTLs: %d sent %d failed",
512 atomic_read(&sent
[SMB2_IOCTL_HE
]),
513 atomic_read(&failed
[SMB2_IOCTL_HE
]));
514 seq_printf(m
, "\nCancels: %d sent %d failed",
515 atomic_read(&sent
[SMB2_CANCEL_HE
]),
516 atomic_read(&failed
[SMB2_CANCEL_HE
]));
517 seq_printf(m
, "\nEchos: %d sent %d failed",
518 atomic_read(&sent
[SMB2_ECHO_HE
]),
519 atomic_read(&failed
[SMB2_ECHO_HE
]));
520 seq_printf(m
, "\nQueryDirectories: %d sent %d failed",
521 atomic_read(&sent
[SMB2_QUERY_DIRECTORY_HE
]),
522 atomic_read(&failed
[SMB2_QUERY_DIRECTORY_HE
]));
523 seq_printf(m
, "\nChangeNotifies: %d sent %d failed",
524 atomic_read(&sent
[SMB2_CHANGE_NOTIFY_HE
]),
525 atomic_read(&failed
[SMB2_CHANGE_NOTIFY_HE
]));
526 seq_printf(m
, "\nQueryInfos: %d sent %d failed",
527 atomic_read(&sent
[SMB2_QUERY_INFO_HE
]),
528 atomic_read(&failed
[SMB2_QUERY_INFO_HE
]));
529 seq_printf(m
, "\nSetInfos: %d sent %d failed",
530 atomic_read(&sent
[SMB2_SET_INFO_HE
]),
531 atomic_read(&failed
[SMB2_SET_INFO_HE
]));
532 seq_printf(m
, "\nOplockBreaks: %d sent %d failed",
533 atomic_read(&sent
[SMB2_OPLOCK_BREAK_HE
]),
534 atomic_read(&failed
[SMB2_OPLOCK_BREAK_HE
]));
539 smb2_set_fid(struct cifsFileInfo
*cfile
, struct cifs_fid
*fid
, __u32 oplock
)
541 struct cifsInodeInfo
*cinode
= CIFS_I(d_inode(cfile
->dentry
));
542 struct TCP_Server_Info
*server
= tlink_tcon(cfile
->tlink
)->ses
->server
;
544 cfile
->fid
.persistent_fid
= fid
->persistent_fid
;
545 cfile
->fid
.volatile_fid
= fid
->volatile_fid
;
546 server
->ops
->set_oplock_level(cinode
, oplock
, fid
->epoch
,
548 cinode
->can_cache_brlcks
= CIFS_CACHE_WRITE(cinode
);
549 memcpy(cfile
->fid
.create_guid
, fid
->create_guid
, 16);
553 smb2_close_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
554 struct cifs_fid
*fid
)
556 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
560 SMB2_request_res_key(const unsigned int xid
, struct cifs_tcon
*tcon
,
561 u64 persistent_fid
, u64 volatile_fid
,
562 struct copychunk_ioctl
*pcchunk
)
565 unsigned int ret_data_len
;
566 struct resume_key_req
*res_key
;
568 rc
= SMB2_ioctl(xid
, tcon
, persistent_fid
, volatile_fid
,
569 FSCTL_SRV_REQUEST_RESUME_KEY
, true /* is_fsctl */,
570 NULL
, 0 /* no input */,
571 (char **)&res_key
, &ret_data_len
);
574 cifs_dbg(VFS
, "refcpy ioctl error %d getting resume key\n", rc
);
575 goto req_res_key_exit
;
577 if (ret_data_len
< sizeof(struct resume_key_req
)) {
578 cifs_dbg(VFS
, "Invalid refcopy resume key length\n");
580 goto req_res_key_exit
;
582 memcpy(pcchunk
->SourceKey
, res_key
->ResumeKey
, COPY_CHUNK_RES_KEY_SIZE
);
590 smb2_clone_range(const unsigned int xid
,
591 struct cifsFileInfo
*srcfile
,
592 struct cifsFileInfo
*trgtfile
, u64 src_off
,
593 u64 len
, u64 dest_off
)
596 unsigned int ret_data_len
;
597 struct copychunk_ioctl
*pcchunk
;
598 struct copychunk_ioctl_rsp
*retbuf
= NULL
;
599 struct cifs_tcon
*tcon
;
600 int chunks_copied
= 0;
601 bool chunk_sizes_updated
= false;
603 pcchunk
= kmalloc(sizeof(struct copychunk_ioctl
), GFP_KERNEL
);
608 cifs_dbg(FYI
, "in smb2_clone_range - about to call request res key\n");
609 /* Request a key from the server to identify the source of the copy */
610 rc
= SMB2_request_res_key(xid
, tlink_tcon(srcfile
->tlink
),
611 srcfile
->fid
.persistent_fid
,
612 srcfile
->fid
.volatile_fid
, pcchunk
);
614 /* Note: request_res_key sets res_key null only if rc !=0 */
618 /* For now array only one chunk long, will make more flexible later */
619 pcchunk
->ChunkCount
= cpu_to_le32(1);
620 pcchunk
->Reserved
= 0;
621 pcchunk
->Reserved2
= 0;
623 tcon
= tlink_tcon(trgtfile
->tlink
);
626 pcchunk
->SourceOffset
= cpu_to_le64(src_off
);
627 pcchunk
->TargetOffset
= cpu_to_le64(dest_off
);
629 cpu_to_le32(min_t(u32
, len
, tcon
->max_bytes_chunk
));
631 /* Request server copy to target from src identified by key */
632 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
633 trgtfile
->fid
.volatile_fid
, FSCTL_SRV_COPYCHUNK_WRITE
,
634 true /* is_fsctl */, (char *)pcchunk
,
635 sizeof(struct copychunk_ioctl
), (char **)&retbuf
,
639 sizeof(struct copychunk_ioctl_rsp
)) {
640 cifs_dbg(VFS
, "invalid cchunk response size\n");
644 if (retbuf
->TotalBytesWritten
== 0) {
645 cifs_dbg(FYI
, "no bytes copied\n");
650 * Check if server claimed to write more than we asked
652 if (le32_to_cpu(retbuf
->TotalBytesWritten
) >
653 le32_to_cpu(pcchunk
->Length
)) {
654 cifs_dbg(VFS
, "invalid copy chunk response\n");
658 if (le32_to_cpu(retbuf
->ChunksWritten
) != 1) {
659 cifs_dbg(VFS
, "invalid num chunks written\n");
665 src_off
+= le32_to_cpu(retbuf
->TotalBytesWritten
);
666 dest_off
+= le32_to_cpu(retbuf
->TotalBytesWritten
);
667 len
-= le32_to_cpu(retbuf
->TotalBytesWritten
);
669 cifs_dbg(FYI
, "Chunks %d PartialChunk %d Total %d\n",
670 le32_to_cpu(retbuf
->ChunksWritten
),
671 le32_to_cpu(retbuf
->ChunkBytesWritten
),
672 le32_to_cpu(retbuf
->TotalBytesWritten
));
673 } else if (rc
== -EINVAL
) {
674 if (ret_data_len
!= sizeof(struct copychunk_ioctl_rsp
))
677 cifs_dbg(FYI
, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
678 le32_to_cpu(retbuf
->ChunksWritten
),
679 le32_to_cpu(retbuf
->ChunkBytesWritten
),
680 le32_to_cpu(retbuf
->TotalBytesWritten
));
683 * Check if this is the first request using these sizes,
684 * (ie check if copy succeed once with original sizes
685 * and check if the server gave us different sizes after
686 * we already updated max sizes on previous request).
687 * if not then why is the server returning an error now
689 if ((chunks_copied
!= 0) || chunk_sizes_updated
)
692 /* Check that server is not asking us to grow size */
693 if (le32_to_cpu(retbuf
->ChunkBytesWritten
) <
694 tcon
->max_bytes_chunk
)
695 tcon
->max_bytes_chunk
=
696 le32_to_cpu(retbuf
->ChunkBytesWritten
);
698 goto cchunk_out
; /* server gave us bogus size */
700 /* No need to change MaxChunks since already set to 1 */
701 chunk_sizes_updated
= true;
713 smb2_flush_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
714 struct cifs_fid
*fid
)
716 return SMB2_flush(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
720 smb2_read_data_offset(char *buf
)
722 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
723 return rsp
->DataOffset
;
727 smb2_read_data_length(char *buf
)
729 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
730 return le32_to_cpu(rsp
->DataLength
);
735 smb2_sync_read(const unsigned int xid
, struct cifs_fid
*pfid
,
736 struct cifs_io_parms
*parms
, unsigned int *bytes_read
,
737 char **buf
, int *buf_type
)
739 parms
->persistent_fid
= pfid
->persistent_fid
;
740 parms
->volatile_fid
= pfid
->volatile_fid
;
741 return SMB2_read(xid
, parms
, bytes_read
, buf
, buf_type
);
745 smb2_sync_write(const unsigned int xid
, struct cifs_fid
*pfid
,
746 struct cifs_io_parms
*parms
, unsigned int *written
,
747 struct kvec
*iov
, unsigned long nr_segs
)
750 parms
->persistent_fid
= pfid
->persistent_fid
;
751 parms
->volatile_fid
= pfid
->volatile_fid
;
752 return SMB2_write(xid
, parms
, written
, iov
, nr_segs
);
755 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
756 static bool smb2_set_sparse(const unsigned int xid
, struct cifs_tcon
*tcon
,
757 struct cifsFileInfo
*cfile
, struct inode
*inode
, __u8 setsparse
)
759 struct cifsInodeInfo
*cifsi
;
762 cifsi
= CIFS_I(inode
);
764 /* if file already sparse don't bother setting sparse again */
765 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && setsparse
)
766 return true; /* already sparse */
768 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && !setsparse
)
769 return true; /* already not sparse */
772 * Can't check for sparse support on share the usual way via the
773 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
774 * since Samba server doesn't set the flag on the share, yet
775 * supports the set sparse FSCTL and returns sparse correctly
776 * in the file attributes. If we fail setting sparse though we
777 * mark that server does not support sparse files for this share
778 * to avoid repeatedly sending the unsupported fsctl to server
779 * if the file is repeatedly extended.
781 if (tcon
->broken_sparse_sup
)
784 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
785 cfile
->fid
.volatile_fid
, FSCTL_SET_SPARSE
,
786 true /* is_fctl */, &setsparse
, 1, NULL
, NULL
);
788 tcon
->broken_sparse_sup
= true;
789 cifs_dbg(FYI
, "set sparse rc = %d\n", rc
);
794 cifsi
->cifsAttrs
|= FILE_ATTRIBUTE_SPARSE_FILE
;
796 cifsi
->cifsAttrs
&= (~FILE_ATTRIBUTE_SPARSE_FILE
);
802 smb2_set_file_size(const unsigned int xid
, struct cifs_tcon
*tcon
,
803 struct cifsFileInfo
*cfile
, __u64 size
, bool set_alloc
)
805 __le64 eof
= cpu_to_le64(size
);
809 * If extending file more than one page make sparse. Many Linux fs
810 * make files sparse by default when extending via ftruncate
812 inode
= d_inode(cfile
->dentry
);
814 if (!set_alloc
&& (size
> inode
->i_size
+ 8192)) {
817 /* whether set sparse succeeds or not, extend the file */
818 smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
);
821 return SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
822 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
, false);
826 smb2_duplicate_extents(const unsigned int xid
,
827 struct cifsFileInfo
*srcfile
,
828 struct cifsFileInfo
*trgtfile
, u64 src_off
,
829 u64 len
, u64 dest_off
)
832 unsigned int ret_data_len
;
833 struct duplicate_extents_to_file dup_ext_buf
;
834 struct cifs_tcon
*tcon
= tlink_tcon(trgtfile
->tlink
);
836 /* server fileays advertise duplicate extent support with this flag */
837 if ((le32_to_cpu(tcon
->fsAttrInfo
.Attributes
) &
838 FILE_SUPPORTS_BLOCK_REFCOUNTING
) == 0)
841 dup_ext_buf
.VolatileFileHandle
= srcfile
->fid
.volatile_fid
;
842 dup_ext_buf
.PersistentFileHandle
= srcfile
->fid
.persistent_fid
;
843 dup_ext_buf
.SourceFileOffset
= cpu_to_le64(src_off
);
844 dup_ext_buf
.TargetFileOffset
= cpu_to_le64(dest_off
);
845 dup_ext_buf
.ByteCount
= cpu_to_le64(len
);
846 cifs_dbg(FYI
, "duplicate extents: src off %lld dst off %lld len %lld",
847 src_off
, dest_off
, len
);
849 rc
= smb2_set_file_size(xid
, tcon
, trgtfile
, dest_off
+ len
, false);
851 goto duplicate_extents_out
;
853 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
854 trgtfile
->fid
.volatile_fid
,
855 FSCTL_DUPLICATE_EXTENTS_TO_FILE
,
856 true /* is_fsctl */, (char *)&dup_ext_buf
,
857 sizeof(struct duplicate_extents_to_file
),
861 if (ret_data_len
> 0)
862 cifs_dbg(FYI
, "non-zero response length in duplicate extents");
864 duplicate_extents_out
:
869 smb2_set_compression(const unsigned int xid
, struct cifs_tcon
*tcon
,
870 struct cifsFileInfo
*cfile
)
872 return SMB2_set_compression(xid
, tcon
, cfile
->fid
.persistent_fid
,
873 cfile
->fid
.volatile_fid
);
877 smb3_set_integrity(const unsigned int xid
, struct cifs_tcon
*tcon
,
878 struct cifsFileInfo
*cfile
)
880 struct fsctl_set_integrity_information_req integr_info
;
881 unsigned int ret_data_len
;
883 integr_info
.ChecksumAlgorithm
= cpu_to_le16(CHECKSUM_TYPE_UNCHANGED
);
884 integr_info
.Flags
= 0;
885 integr_info
.Reserved
= 0;
887 return SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
888 cfile
->fid
.volatile_fid
,
889 FSCTL_SET_INTEGRITY_INFORMATION
,
890 true /* is_fsctl */, (char *)&integr_info
,
891 sizeof(struct fsctl_set_integrity_information_req
),
898 smb3_enum_snapshots(const unsigned int xid
, struct cifs_tcon
*tcon
,
899 struct cifsFileInfo
*cfile
, void __user
*ioc_buf
)
902 unsigned int ret_data_len
= 0;
904 struct smb_snapshot_array snapshot_in
;
906 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
907 cfile
->fid
.volatile_fid
,
908 FSCTL_SRV_ENUMERATE_SNAPSHOTS
,
909 true /* is_fsctl */, NULL
, 0 /* no input data */,
912 cifs_dbg(FYI
, "enum snaphots ioctl returned %d and ret buflen is %d\n",
917 if (ret_data_len
&& (ioc_buf
!= NULL
) && (retbuf
!= NULL
)) {
919 if (copy_from_user(&snapshot_in
, ioc_buf
,
920 sizeof(struct smb_snapshot_array
))) {
925 if (snapshot_in
.snapshot_array_size
< sizeof(struct smb_snapshot_array
)) {
931 if (ret_data_len
> snapshot_in
.snapshot_array_size
)
932 ret_data_len
= snapshot_in
.snapshot_array_size
;
934 if (copy_to_user(ioc_buf
, retbuf
, ret_data_len
))
943 smb2_query_dir_first(const unsigned int xid
, struct cifs_tcon
*tcon
,
944 const char *path
, struct cifs_sb_info
*cifs_sb
,
945 struct cifs_fid
*fid
, __u16 search_flags
,
946 struct cifs_search_info
*srch_inf
)
950 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
951 struct cifs_open_parms oparms
;
953 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
958 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| FILE_READ_DATA
;
959 oparms
.disposition
= FILE_OPEN
;
960 oparms
.create_options
= 0;
962 oparms
.reconnect
= false;
964 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
967 cifs_dbg(FYI
, "open dir failed rc=%d\n", rc
);
971 srch_inf
->entries_in_buffer
= 0;
972 srch_inf
->index_of_last_entry
= 0;
974 rc
= SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
975 fid
->volatile_fid
, 0, srch_inf
);
977 cifs_dbg(FYI
, "query directory failed rc=%d\n", rc
);
978 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
984 smb2_query_dir_next(const unsigned int xid
, struct cifs_tcon
*tcon
,
985 struct cifs_fid
*fid
, __u16 search_flags
,
986 struct cifs_search_info
*srch_inf
)
988 return SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
989 fid
->volatile_fid
, 0, srch_inf
);
993 smb2_close_dir(const unsigned int xid
, struct cifs_tcon
*tcon
,
994 struct cifs_fid
*fid
)
996 return SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
1000 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
1001 * the number of credits and return true. Otherwise - return false.
1004 smb2_is_status_pending(char *buf
, struct TCP_Server_Info
*server
, int length
)
1006 struct smb2_hdr
*hdr
= (struct smb2_hdr
*)buf
;
1008 if (hdr
->Status
!= STATUS_PENDING
)
1012 spin_lock(&server
->req_lock
);
1013 server
->credits
+= le16_to_cpu(hdr
->CreditRequest
);
1014 spin_unlock(&server
->req_lock
);
1015 wake_up(&server
->request_q
);
1022 smb2_oplock_response(struct cifs_tcon
*tcon
, struct cifs_fid
*fid
,
1023 struct cifsInodeInfo
*cinode
)
1025 if (tcon
->ses
->server
->capabilities
& SMB2_GLOBAL_CAP_LEASING
)
1026 return SMB2_lease_break(0, tcon
, cinode
->lease_key
,
1027 smb2_get_lease_state(cinode
));
1029 return SMB2_oplock_break(0, tcon
, fid
->persistent_fid
,
1031 CIFS_CACHE_READ(cinode
) ? 1 : 0);
1035 smb2_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
1036 struct kstatfs
*buf
)
1039 __le16 srch_path
= 0; /* Null - open root of share */
1040 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1041 struct cifs_open_parms oparms
;
1042 struct cifs_fid fid
;
1045 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
1046 oparms
.disposition
= FILE_OPEN
;
1047 oparms
.create_options
= 0;
1049 oparms
.reconnect
= false;
1051 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
1054 buf
->f_type
= SMB2_MAGIC_NUMBER
;
1055 rc
= SMB2_QFS_info(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
1057 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
1062 smb2_compare_fids(struct cifsFileInfo
*ob1
, struct cifsFileInfo
*ob2
)
1064 return ob1
->fid
.persistent_fid
== ob2
->fid
.persistent_fid
&&
1065 ob1
->fid
.volatile_fid
== ob2
->fid
.volatile_fid
;
1069 smb2_mand_lock(const unsigned int xid
, struct cifsFileInfo
*cfile
, __u64 offset
,
1070 __u64 length
, __u32 type
, int lock
, int unlock
, bool wait
)
1072 if (unlock
&& !lock
)
1073 type
= SMB2_LOCKFLAG_UNLOCK
;
1074 return SMB2_lock(xid
, tlink_tcon(cfile
->tlink
),
1075 cfile
->fid
.persistent_fid
, cfile
->fid
.volatile_fid
,
1076 current
->tgid
, length
, offset
, type
, wait
);
1080 smb2_get_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
1082 memcpy(fid
->lease_key
, CIFS_I(inode
)->lease_key
, SMB2_LEASE_KEY_SIZE
);
1086 smb2_set_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
1088 memcpy(CIFS_I(inode
)->lease_key
, fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
1092 smb2_new_lease_key(struct cifs_fid
*fid
)
1094 generate_random_uuid(fid
->lease_key
);
1097 #define SMB2_SYMLINK_STRUCT_SIZE \
1098 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
1101 smb2_query_symlink(const unsigned int xid
, struct cifs_tcon
*tcon
,
1102 const char *full_path
, char **target_path
,
1103 struct cifs_sb_info
*cifs_sb
)
1107 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1108 struct cifs_open_parms oparms
;
1109 struct cifs_fid fid
;
1110 struct smb2_err_rsp
*err_buf
= NULL
;
1111 struct smb2_symlink_err_rsp
*symlink
;
1112 unsigned int sub_len
;
1113 unsigned int sub_offset
;
1114 unsigned int print_len
;
1115 unsigned int print_offset
;
1117 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, full_path
);
1119 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
1124 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
1125 oparms
.disposition
= FILE_OPEN
;
1126 oparms
.create_options
= 0;
1128 oparms
.reconnect
= false;
1130 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, &err_buf
);
1132 if (!rc
|| !err_buf
) {
1137 if (le32_to_cpu(err_buf
->ByteCount
) < sizeof(struct smb2_symlink_err_rsp
) ||
1138 get_rfc1002_length(err_buf
) + 4 < SMB2_SYMLINK_STRUCT_SIZE
) {
1143 /* open must fail on symlink - reset rc */
1145 symlink
= (struct smb2_symlink_err_rsp
*)err_buf
->ErrorData
;
1146 sub_len
= le16_to_cpu(symlink
->SubstituteNameLength
);
1147 sub_offset
= le16_to_cpu(symlink
->SubstituteNameOffset
);
1148 print_len
= le16_to_cpu(symlink
->PrintNameLength
);
1149 print_offset
= le16_to_cpu(symlink
->PrintNameOffset
);
1151 if (get_rfc1002_length(err_buf
) + 4 <
1152 SMB2_SYMLINK_STRUCT_SIZE
+ sub_offset
+ sub_len
) {
1157 if (get_rfc1002_length(err_buf
) + 4 <
1158 SMB2_SYMLINK_STRUCT_SIZE
+ print_offset
+ print_len
) {
1163 *target_path
= cifs_strndup_from_utf16(
1164 (char *)symlink
->PathBuffer
+ sub_offset
,
1165 sub_len
, true, cifs_sb
->local_nls
);
1166 if (!(*target_path
)) {
1170 convert_delimiter(*target_path
, '/');
1171 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
1176 static long smb3_zero_range(struct file
*file
, struct cifs_tcon
*tcon
,
1177 loff_t offset
, loff_t len
, bool keep_size
)
1179 struct inode
*inode
;
1180 struct cifsInodeInfo
*cifsi
;
1181 struct cifsFileInfo
*cfile
= file
->private_data
;
1182 struct file_zero_data_information fsctl_buf
;
1188 inode
= d_inode(cfile
->dentry
);
1189 cifsi
= CIFS_I(inode
);
1191 /* if file not oplocked can't be sure whether asking to extend size */
1192 if (!CIFS_CACHE_READ(cifsi
))
1193 if (keep_size
== false)
1197 * Must check if file sparse since fallocate -z (zero range) assumes
1198 * non-sparse allocation
1200 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
))
1204 * need to make sure we are not asked to extend the file since the SMB3
1205 * fsctl does not change the file size. In the future we could change
1206 * this to zero the first part of the range then set the file size
1207 * which for a non sparse file would zero the newly extended range
1209 if (keep_size
== false)
1210 if (i_size_read(inode
) < offset
+ len
)
1213 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1215 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1216 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1218 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1219 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1220 true /* is_fctl */, (char *)&fsctl_buf
,
1221 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1226 static long smb3_punch_hole(struct file
*file
, struct cifs_tcon
*tcon
,
1227 loff_t offset
, loff_t len
)
1229 struct inode
*inode
;
1230 struct cifsInodeInfo
*cifsi
;
1231 struct cifsFileInfo
*cfile
= file
->private_data
;
1232 struct file_zero_data_information fsctl_buf
;
1235 __u8 set_sparse
= 1;
1239 inode
= d_inode(cfile
->dentry
);
1240 cifsi
= CIFS_I(inode
);
1242 /* Need to make file sparse, if not already, before freeing range. */
1243 /* Consider adding equivalent for compressed since it could also work */
1244 if (!smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
))
1247 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1249 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1250 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1252 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1253 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1254 true /* is_fctl */, (char *)&fsctl_buf
,
1255 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1260 static long smb3_simple_falloc(struct file
*file
, struct cifs_tcon
*tcon
,
1261 loff_t off
, loff_t len
, bool keep_size
)
1263 struct inode
*inode
;
1264 struct cifsInodeInfo
*cifsi
;
1265 struct cifsFileInfo
*cfile
= file
->private_data
;
1266 long rc
= -EOPNOTSUPP
;
1271 inode
= d_inode(cfile
->dentry
);
1272 cifsi
= CIFS_I(inode
);
1274 /* if file not oplocked can't be sure whether asking to extend size */
1275 if (!CIFS_CACHE_READ(cifsi
))
1276 if (keep_size
== false)
1280 * Files are non-sparse by default so falloc may be a no-op
1281 * Must check if file sparse. If not sparse, and not extending
1282 * then no need to do anything since file already allocated
1284 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) == 0) {
1285 if (keep_size
== true)
1287 /* check if extending file */
1288 else if (i_size_read(inode
) >= off
+ len
)
1289 /* not extending file and already not sparse */
1291 /* BB: in future add else clause to extend file */
1296 if ((keep_size
== true) || (i_size_read(inode
) >= off
+ len
)) {
1298 * Check if falloc starts within first few pages of file
1299 * and ends within a few pages of the end of file to
1300 * ensure that most of file is being forced to be
1301 * fallocated now. If so then setting whole file sparse
1302 * ie potentially making a few extra pages at the beginning
1303 * or end of the file non-sparse via set_sparse is harmless.
1305 if ((off
> 8192) || (off
+ len
+ 8192 < i_size_read(inode
)))
1308 rc
= smb2_set_sparse(xid
, tcon
, cfile
, inode
, false);
1310 /* BB: else ... in future add code to extend file and set sparse */
1318 static long smb3_fallocate(struct file
*file
, struct cifs_tcon
*tcon
, int mode
,
1319 loff_t off
, loff_t len
)
1321 /* KEEP_SIZE already checked for by do_fallocate */
1322 if (mode
& FALLOC_FL_PUNCH_HOLE
)
1323 return smb3_punch_hole(file
, tcon
, off
, len
);
1324 else if (mode
& FALLOC_FL_ZERO_RANGE
) {
1325 if (mode
& FALLOC_FL_KEEP_SIZE
)
1326 return smb3_zero_range(file
, tcon
, off
, len
, true);
1327 return smb3_zero_range(file
, tcon
, off
, len
, false);
1328 } else if (mode
== FALLOC_FL_KEEP_SIZE
)
1329 return smb3_simple_falloc(file
, tcon
, off
, len
, true);
1331 return smb3_simple_falloc(file
, tcon
, off
, len
, false);
1337 smb2_downgrade_oplock(struct TCP_Server_Info
*server
,
1338 struct cifsInodeInfo
*cinode
, bool set_level2
)
1341 server
->ops
->set_oplock_level(cinode
, SMB2_OPLOCK_LEVEL_II
,
1344 server
->ops
->set_oplock_level(cinode
, 0, 0, NULL
);
1348 smb2_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1349 unsigned int epoch
, bool *purge_cache
)
1352 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1354 if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
) {
1355 cinode
->oplock
= CIFS_CACHE_RHW_FLG
;
1356 cifs_dbg(FYI
, "Batch Oplock granted on inode %p\n",
1357 &cinode
->vfs_inode
);
1358 } else if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
) {
1359 cinode
->oplock
= CIFS_CACHE_RW_FLG
;
1360 cifs_dbg(FYI
, "Exclusive Oplock granted on inode %p\n",
1361 &cinode
->vfs_inode
);
1362 } else if (oplock
== SMB2_OPLOCK_LEVEL_II
) {
1363 cinode
->oplock
= CIFS_CACHE_READ_FLG
;
1364 cifs_dbg(FYI
, "Level II Oplock granted on inode %p\n",
1365 &cinode
->vfs_inode
);
1371 smb21_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1372 unsigned int epoch
, bool *purge_cache
)
1374 char message
[5] = {0};
1377 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1381 if (oplock
& SMB2_LEASE_READ_CACHING_HE
) {
1382 cinode
->oplock
|= CIFS_CACHE_READ_FLG
;
1383 strcat(message
, "R");
1385 if (oplock
& SMB2_LEASE_HANDLE_CACHING_HE
) {
1386 cinode
->oplock
|= CIFS_CACHE_HANDLE_FLG
;
1387 strcat(message
, "H");
1389 if (oplock
& SMB2_LEASE_WRITE_CACHING_HE
) {
1390 cinode
->oplock
|= CIFS_CACHE_WRITE_FLG
;
1391 strcat(message
, "W");
1393 if (!cinode
->oplock
)
1394 strcat(message
, "None");
1395 cifs_dbg(FYI
, "%s Lease granted on inode %p\n", message
,
1396 &cinode
->vfs_inode
);
1400 smb3_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1401 unsigned int epoch
, bool *purge_cache
)
1403 unsigned int old_oplock
= cinode
->oplock
;
1405 smb21_set_oplock_level(cinode
, oplock
, epoch
, purge_cache
);
1408 *purge_cache
= false;
1409 if (old_oplock
== CIFS_CACHE_READ_FLG
) {
1410 if (cinode
->oplock
== CIFS_CACHE_READ_FLG
&&
1411 (epoch
- cinode
->epoch
> 0))
1412 *purge_cache
= true;
1413 else if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1414 (epoch
- cinode
->epoch
> 1))
1415 *purge_cache
= true;
1416 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1417 (epoch
- cinode
->epoch
> 1))
1418 *purge_cache
= true;
1419 else if (cinode
->oplock
== 0 &&
1420 (epoch
- cinode
->epoch
> 0))
1421 *purge_cache
= true;
1422 } else if (old_oplock
== CIFS_CACHE_RH_FLG
) {
1423 if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1424 (epoch
- cinode
->epoch
> 0))
1425 *purge_cache
= true;
1426 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1427 (epoch
- cinode
->epoch
> 1))
1428 *purge_cache
= true;
1430 cinode
->epoch
= epoch
;
1435 smb2_is_read_op(__u32 oplock
)
1437 return oplock
== SMB2_OPLOCK_LEVEL_II
;
1441 smb21_is_read_op(__u32 oplock
)
1443 return (oplock
& SMB2_LEASE_READ_CACHING_HE
) &&
1444 !(oplock
& SMB2_LEASE_WRITE_CACHING_HE
);
1448 map_oplock_to_lease(u8 oplock
)
1450 if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
)
1451 return SMB2_LEASE_WRITE_CACHING
| SMB2_LEASE_READ_CACHING
;
1452 else if (oplock
== SMB2_OPLOCK_LEVEL_II
)
1453 return SMB2_LEASE_READ_CACHING
;
1454 else if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
)
1455 return SMB2_LEASE_HANDLE_CACHING
| SMB2_LEASE_READ_CACHING
|
1456 SMB2_LEASE_WRITE_CACHING
;
1461 smb2_create_lease_buf(u8
*lease_key
, u8 oplock
)
1463 struct create_lease
*buf
;
1465 buf
= kzalloc(sizeof(struct create_lease
), GFP_KERNEL
);
1469 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1470 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1471 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1473 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1474 (struct create_lease
, lcontext
));
1475 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context
));
1476 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1477 (struct create_lease
, Name
));
1478 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1479 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1488 smb3_create_lease_buf(u8
*lease_key
, u8 oplock
)
1490 struct create_lease_v2
*buf
;
1492 buf
= kzalloc(sizeof(struct create_lease_v2
), GFP_KERNEL
);
1496 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1497 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1498 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1500 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1501 (struct create_lease_v2
, lcontext
));
1502 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context_v2
));
1503 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1504 (struct create_lease_v2
, Name
));
1505 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1506 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1515 smb2_parse_lease_buf(void *buf
, unsigned int *epoch
)
1517 struct create_lease
*lc
= (struct create_lease
*)buf
;
1519 *epoch
= 0; /* not used */
1520 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
1521 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
1522 return le32_to_cpu(lc
->lcontext
.LeaseState
);
1526 smb3_parse_lease_buf(void *buf
, unsigned int *epoch
)
1528 struct create_lease_v2
*lc
= (struct create_lease_v2
*)buf
;
1530 *epoch
= le16_to_cpu(lc
->lcontext
.Epoch
);
1531 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
1532 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
1533 return le32_to_cpu(lc
->lcontext
.LeaseState
);
1537 smb2_wp_retry_size(struct inode
*inode
)
1539 return min_t(unsigned int, CIFS_SB(inode
->i_sb
)->wsize
,
1540 SMB2_MAX_BUFFER_SIZE
);
1544 smb2_dir_needs_close(struct cifsFileInfo
*cfile
)
1546 return !cfile
->invalidHandle
;
1549 struct smb_version_operations smb20_operations
= {
1550 .compare_fids
= smb2_compare_fids
,
1551 .setup_request
= smb2_setup_request
,
1552 .setup_async_request
= smb2_setup_async_request
,
1553 .check_receive
= smb2_check_receive
,
1554 .add_credits
= smb2_add_credits
,
1555 .set_credits
= smb2_set_credits
,
1556 .get_credits_field
= smb2_get_credits_field
,
1557 .get_credits
= smb2_get_credits
,
1558 .wait_mtu_credits
= cifs_wait_mtu_credits
,
1559 .get_next_mid
= smb2_get_next_mid
,
1560 .read_data_offset
= smb2_read_data_offset
,
1561 .read_data_length
= smb2_read_data_length
,
1562 .map_error
= map_smb2_to_linux_error
,
1563 .find_mid
= smb2_find_mid
,
1564 .check_message
= smb2_check_message
,
1565 .dump_detail
= smb2_dump_detail
,
1566 .clear_stats
= smb2_clear_stats
,
1567 .print_stats
= smb2_print_stats
,
1568 .is_oplock_break
= smb2_is_valid_oplock_break
,
1569 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
1570 .downgrade_oplock
= smb2_downgrade_oplock
,
1571 .need_neg
= smb2_need_neg
,
1572 .negotiate
= smb2_negotiate
,
1573 .negotiate_wsize
= smb2_negotiate_wsize
,
1574 .negotiate_rsize
= smb2_negotiate_rsize
,
1575 .sess_setup
= SMB2_sess_setup
,
1576 .logoff
= SMB2_logoff
,
1577 .tree_connect
= SMB2_tcon
,
1578 .tree_disconnect
= SMB2_tdis
,
1579 .qfs_tcon
= smb2_qfs_tcon
,
1580 .is_path_accessible
= smb2_is_path_accessible
,
1581 .can_echo
= smb2_can_echo
,
1583 .query_path_info
= smb2_query_path_info
,
1584 .get_srv_inum
= smb2_get_srv_inum
,
1585 .query_file_info
= smb2_query_file_info
,
1586 .set_path_size
= smb2_set_path_size
,
1587 .set_file_size
= smb2_set_file_size
,
1588 .set_file_info
= smb2_set_file_info
,
1589 .set_compression
= smb2_set_compression
,
1590 .mkdir
= smb2_mkdir
,
1591 .mkdir_setinfo
= smb2_mkdir_setinfo
,
1592 .rmdir
= smb2_rmdir
,
1593 .unlink
= smb2_unlink
,
1594 .rename
= smb2_rename_path
,
1595 .create_hardlink
= smb2_create_hardlink
,
1596 .query_symlink
= smb2_query_symlink
,
1597 .query_mf_symlink
= smb3_query_mf_symlink
,
1598 .create_mf_symlink
= smb3_create_mf_symlink
,
1599 .open
= smb2_open_file
,
1600 .set_fid
= smb2_set_fid
,
1601 .close
= smb2_close_file
,
1602 .flush
= smb2_flush_file
,
1603 .async_readv
= smb2_async_readv
,
1604 .async_writev
= smb2_async_writev
,
1605 .sync_read
= smb2_sync_read
,
1606 .sync_write
= smb2_sync_write
,
1607 .query_dir_first
= smb2_query_dir_first
,
1608 .query_dir_next
= smb2_query_dir_next
,
1609 .close_dir
= smb2_close_dir
,
1610 .calc_smb_size
= smb2_calc_size
,
1611 .is_status_pending
= smb2_is_status_pending
,
1612 .oplock_response
= smb2_oplock_response
,
1613 .queryfs
= smb2_queryfs
,
1614 .mand_lock
= smb2_mand_lock
,
1615 .mand_unlock_range
= smb2_unlock_range
,
1616 .push_mand_locks
= smb2_push_mandatory_locks
,
1617 .get_lease_key
= smb2_get_lease_key
,
1618 .set_lease_key
= smb2_set_lease_key
,
1619 .new_lease_key
= smb2_new_lease_key
,
1620 .calc_signature
= smb2_calc_signature
,
1621 .is_read_op
= smb2_is_read_op
,
1622 .set_oplock_level
= smb2_set_oplock_level
,
1623 .create_lease_buf
= smb2_create_lease_buf
,
1624 .parse_lease_buf
= smb2_parse_lease_buf
,
1625 .clone_range
= smb2_clone_range
,
1626 .wp_retry_size
= smb2_wp_retry_size
,
1627 .dir_needs_close
= smb2_dir_needs_close
,
1630 struct smb_version_operations smb21_operations
= {
1631 .compare_fids
= smb2_compare_fids
,
1632 .setup_request
= smb2_setup_request
,
1633 .setup_async_request
= smb2_setup_async_request
,
1634 .check_receive
= smb2_check_receive
,
1635 .add_credits
= smb2_add_credits
,
1636 .set_credits
= smb2_set_credits
,
1637 .get_credits_field
= smb2_get_credits_field
,
1638 .get_credits
= smb2_get_credits
,
1639 .wait_mtu_credits
= smb2_wait_mtu_credits
,
1640 .get_next_mid
= smb2_get_next_mid
,
1641 .read_data_offset
= smb2_read_data_offset
,
1642 .read_data_length
= smb2_read_data_length
,
1643 .map_error
= map_smb2_to_linux_error
,
1644 .find_mid
= smb2_find_mid
,
1645 .check_message
= smb2_check_message
,
1646 .dump_detail
= smb2_dump_detail
,
1647 .clear_stats
= smb2_clear_stats
,
1648 .print_stats
= smb2_print_stats
,
1649 .is_oplock_break
= smb2_is_valid_oplock_break
,
1650 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
1651 .downgrade_oplock
= smb2_downgrade_oplock
,
1652 .need_neg
= smb2_need_neg
,
1653 .negotiate
= smb2_negotiate
,
1654 .negotiate_wsize
= smb2_negotiate_wsize
,
1655 .negotiate_rsize
= smb2_negotiate_rsize
,
1656 .sess_setup
= SMB2_sess_setup
,
1657 .logoff
= SMB2_logoff
,
1658 .tree_connect
= SMB2_tcon
,
1659 .tree_disconnect
= SMB2_tdis
,
1660 .qfs_tcon
= smb2_qfs_tcon
,
1661 .is_path_accessible
= smb2_is_path_accessible
,
1662 .can_echo
= smb2_can_echo
,
1664 .query_path_info
= smb2_query_path_info
,
1665 .get_srv_inum
= smb2_get_srv_inum
,
1666 .query_file_info
= smb2_query_file_info
,
1667 .set_path_size
= smb2_set_path_size
,
1668 .set_file_size
= smb2_set_file_size
,
1669 .set_file_info
= smb2_set_file_info
,
1670 .set_compression
= smb2_set_compression
,
1671 .mkdir
= smb2_mkdir
,
1672 .mkdir_setinfo
= smb2_mkdir_setinfo
,
1673 .rmdir
= smb2_rmdir
,
1674 .unlink
= smb2_unlink
,
1675 .rename
= smb2_rename_path
,
1676 .create_hardlink
= smb2_create_hardlink
,
1677 .query_symlink
= smb2_query_symlink
,
1678 .query_mf_symlink
= smb3_query_mf_symlink
,
1679 .create_mf_symlink
= smb3_create_mf_symlink
,
1680 .open
= smb2_open_file
,
1681 .set_fid
= smb2_set_fid
,
1682 .close
= smb2_close_file
,
1683 .flush
= smb2_flush_file
,
1684 .async_readv
= smb2_async_readv
,
1685 .async_writev
= smb2_async_writev
,
1686 .sync_read
= smb2_sync_read
,
1687 .sync_write
= smb2_sync_write
,
1688 .query_dir_first
= smb2_query_dir_first
,
1689 .query_dir_next
= smb2_query_dir_next
,
1690 .close_dir
= smb2_close_dir
,
1691 .calc_smb_size
= smb2_calc_size
,
1692 .is_status_pending
= smb2_is_status_pending
,
1693 .oplock_response
= smb2_oplock_response
,
1694 .queryfs
= smb2_queryfs
,
1695 .mand_lock
= smb2_mand_lock
,
1696 .mand_unlock_range
= smb2_unlock_range
,
1697 .push_mand_locks
= smb2_push_mandatory_locks
,
1698 .get_lease_key
= smb2_get_lease_key
,
1699 .set_lease_key
= smb2_set_lease_key
,
1700 .new_lease_key
= smb2_new_lease_key
,
1701 .calc_signature
= smb2_calc_signature
,
1702 .is_read_op
= smb21_is_read_op
,
1703 .set_oplock_level
= smb21_set_oplock_level
,
1704 .create_lease_buf
= smb2_create_lease_buf
,
1705 .parse_lease_buf
= smb2_parse_lease_buf
,
1706 .clone_range
= smb2_clone_range
,
1707 .wp_retry_size
= smb2_wp_retry_size
,
1708 .dir_needs_close
= smb2_dir_needs_close
,
1709 .enum_snapshots
= smb3_enum_snapshots
,
1712 struct smb_version_operations smb30_operations
= {
1713 .compare_fids
= smb2_compare_fids
,
1714 .setup_request
= smb2_setup_request
,
1715 .setup_async_request
= smb2_setup_async_request
,
1716 .check_receive
= smb2_check_receive
,
1717 .add_credits
= smb2_add_credits
,
1718 .set_credits
= smb2_set_credits
,
1719 .get_credits_field
= smb2_get_credits_field
,
1720 .get_credits
= smb2_get_credits
,
1721 .wait_mtu_credits
= smb2_wait_mtu_credits
,
1722 .get_next_mid
= smb2_get_next_mid
,
1723 .read_data_offset
= smb2_read_data_offset
,
1724 .read_data_length
= smb2_read_data_length
,
1725 .map_error
= map_smb2_to_linux_error
,
1726 .find_mid
= smb2_find_mid
,
1727 .check_message
= smb2_check_message
,
1728 .dump_detail
= smb2_dump_detail
,
1729 .clear_stats
= smb2_clear_stats
,
1730 .print_stats
= smb2_print_stats
,
1731 .dump_share_caps
= smb2_dump_share_caps
,
1732 .is_oplock_break
= smb2_is_valid_oplock_break
,
1733 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
1734 .downgrade_oplock
= smb2_downgrade_oplock
,
1735 .need_neg
= smb2_need_neg
,
1736 .negotiate
= smb2_negotiate
,
1737 .negotiate_wsize
= smb2_negotiate_wsize
,
1738 .negotiate_rsize
= smb2_negotiate_rsize
,
1739 .sess_setup
= SMB2_sess_setup
,
1740 .logoff
= SMB2_logoff
,
1741 .tree_connect
= SMB2_tcon
,
1742 .tree_disconnect
= SMB2_tdis
,
1743 .qfs_tcon
= smb3_qfs_tcon
,
1744 .is_path_accessible
= smb2_is_path_accessible
,
1745 .can_echo
= smb2_can_echo
,
1747 .query_path_info
= smb2_query_path_info
,
1748 .get_srv_inum
= smb2_get_srv_inum
,
1749 .query_file_info
= smb2_query_file_info
,
1750 .set_path_size
= smb2_set_path_size
,
1751 .set_file_size
= smb2_set_file_size
,
1752 .set_file_info
= smb2_set_file_info
,
1753 .set_compression
= smb2_set_compression
,
1754 .mkdir
= smb2_mkdir
,
1755 .mkdir_setinfo
= smb2_mkdir_setinfo
,
1756 .rmdir
= smb2_rmdir
,
1757 .unlink
= smb2_unlink
,
1758 .rename
= smb2_rename_path
,
1759 .create_hardlink
= smb2_create_hardlink
,
1760 .query_symlink
= smb2_query_symlink
,
1761 .query_mf_symlink
= smb3_query_mf_symlink
,
1762 .create_mf_symlink
= smb3_create_mf_symlink
,
1763 .open
= smb2_open_file
,
1764 .set_fid
= smb2_set_fid
,
1765 .close
= smb2_close_file
,
1766 .flush
= smb2_flush_file
,
1767 .async_readv
= smb2_async_readv
,
1768 .async_writev
= smb2_async_writev
,
1769 .sync_read
= smb2_sync_read
,
1770 .sync_write
= smb2_sync_write
,
1771 .query_dir_first
= smb2_query_dir_first
,
1772 .query_dir_next
= smb2_query_dir_next
,
1773 .close_dir
= smb2_close_dir
,
1774 .calc_smb_size
= smb2_calc_size
,
1775 .is_status_pending
= smb2_is_status_pending
,
1776 .oplock_response
= smb2_oplock_response
,
1777 .queryfs
= smb2_queryfs
,
1778 .mand_lock
= smb2_mand_lock
,
1779 .mand_unlock_range
= smb2_unlock_range
,
1780 .push_mand_locks
= smb2_push_mandatory_locks
,
1781 .get_lease_key
= smb2_get_lease_key
,
1782 .set_lease_key
= smb2_set_lease_key
,
1783 .new_lease_key
= smb2_new_lease_key
,
1784 .generate_signingkey
= generate_smb30signingkey
,
1785 .calc_signature
= smb3_calc_signature
,
1786 .set_integrity
= smb3_set_integrity
,
1787 .is_read_op
= smb21_is_read_op
,
1788 .set_oplock_level
= smb3_set_oplock_level
,
1789 .create_lease_buf
= smb3_create_lease_buf
,
1790 .parse_lease_buf
= smb3_parse_lease_buf
,
1791 .clone_range
= smb2_clone_range
,
1792 .duplicate_extents
= smb2_duplicate_extents
,
1793 .validate_negotiate
= smb3_validate_negotiate
,
1794 .wp_retry_size
= smb2_wp_retry_size
,
1795 .dir_needs_close
= smb2_dir_needs_close
,
1796 .fallocate
= smb3_fallocate
,
1797 .enum_snapshots
= smb3_enum_snapshots
,
1800 #ifdef CONFIG_CIFS_SMB311
1801 struct smb_version_operations smb311_operations
= {
1802 .compare_fids
= smb2_compare_fids
,
1803 .setup_request
= smb2_setup_request
,
1804 .setup_async_request
= smb2_setup_async_request
,
1805 .check_receive
= smb2_check_receive
,
1806 .add_credits
= smb2_add_credits
,
1807 .set_credits
= smb2_set_credits
,
1808 .get_credits_field
= smb2_get_credits_field
,
1809 .get_credits
= smb2_get_credits
,
1810 .wait_mtu_credits
= smb2_wait_mtu_credits
,
1811 .get_next_mid
= smb2_get_next_mid
,
1812 .read_data_offset
= smb2_read_data_offset
,
1813 .read_data_length
= smb2_read_data_length
,
1814 .map_error
= map_smb2_to_linux_error
,
1815 .find_mid
= smb2_find_mid
,
1816 .check_message
= smb2_check_message
,
1817 .dump_detail
= smb2_dump_detail
,
1818 .clear_stats
= smb2_clear_stats
,
1819 .print_stats
= smb2_print_stats
,
1820 .dump_share_caps
= smb2_dump_share_caps
,
1821 .is_oplock_break
= smb2_is_valid_oplock_break
,
1822 .handle_cancelled_mid
= smb2_handle_cancelled_mid
,
1823 .downgrade_oplock
= smb2_downgrade_oplock
,
1824 .need_neg
= smb2_need_neg
,
1825 .negotiate
= smb2_negotiate
,
1826 .negotiate_wsize
= smb2_negotiate_wsize
,
1827 .negotiate_rsize
= smb2_negotiate_rsize
,
1828 .sess_setup
= SMB2_sess_setup
,
1829 .logoff
= SMB2_logoff
,
1830 .tree_connect
= SMB2_tcon
,
1831 .tree_disconnect
= SMB2_tdis
,
1832 .qfs_tcon
= smb3_qfs_tcon
,
1833 .is_path_accessible
= smb2_is_path_accessible
,
1834 .can_echo
= smb2_can_echo
,
1836 .query_path_info
= smb2_query_path_info
,
1837 .get_srv_inum
= smb2_get_srv_inum
,
1838 .query_file_info
= smb2_query_file_info
,
1839 .set_path_size
= smb2_set_path_size
,
1840 .set_file_size
= smb2_set_file_size
,
1841 .set_file_info
= smb2_set_file_info
,
1842 .set_compression
= smb2_set_compression
,
1843 .mkdir
= smb2_mkdir
,
1844 .mkdir_setinfo
= smb2_mkdir_setinfo
,
1845 .rmdir
= smb2_rmdir
,
1846 .unlink
= smb2_unlink
,
1847 .rename
= smb2_rename_path
,
1848 .create_hardlink
= smb2_create_hardlink
,
1849 .query_symlink
= smb2_query_symlink
,
1850 .query_mf_symlink
= smb3_query_mf_symlink
,
1851 .create_mf_symlink
= smb3_create_mf_symlink
,
1852 .open
= smb2_open_file
,
1853 .set_fid
= smb2_set_fid
,
1854 .close
= smb2_close_file
,
1855 .flush
= smb2_flush_file
,
1856 .async_readv
= smb2_async_readv
,
1857 .async_writev
= smb2_async_writev
,
1858 .sync_read
= smb2_sync_read
,
1859 .sync_write
= smb2_sync_write
,
1860 .query_dir_first
= smb2_query_dir_first
,
1861 .query_dir_next
= smb2_query_dir_next
,
1862 .close_dir
= smb2_close_dir
,
1863 .calc_smb_size
= smb2_calc_size
,
1864 .is_status_pending
= smb2_is_status_pending
,
1865 .oplock_response
= smb2_oplock_response
,
1866 .queryfs
= smb2_queryfs
,
1867 .mand_lock
= smb2_mand_lock
,
1868 .mand_unlock_range
= smb2_unlock_range
,
1869 .push_mand_locks
= smb2_push_mandatory_locks
,
1870 .get_lease_key
= smb2_get_lease_key
,
1871 .set_lease_key
= smb2_set_lease_key
,
1872 .new_lease_key
= smb2_new_lease_key
,
1873 .generate_signingkey
= generate_smb311signingkey
,
1874 .calc_signature
= smb3_calc_signature
,
1875 .set_integrity
= smb3_set_integrity
,
1876 .is_read_op
= smb21_is_read_op
,
1877 .set_oplock_level
= smb3_set_oplock_level
,
1878 .create_lease_buf
= smb3_create_lease_buf
,
1879 .parse_lease_buf
= smb3_parse_lease_buf
,
1880 .clone_range
= smb2_clone_range
,
1881 .duplicate_extents
= smb2_duplicate_extents
,
1882 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
1883 .wp_retry_size
= smb2_wp_retry_size
,
1884 .dir_needs_close
= smb2_dir_needs_close
,
1885 .fallocate
= smb3_fallocate
,
1886 .enum_snapshots
= smb3_enum_snapshots
,
1888 #endif /* CIFS_SMB311 */
1890 struct smb_version_values smb20_values
= {
1891 .version_string
= SMB20_VERSION_STRING
,
1892 .protocol_id
= SMB20_PROT_ID
,
1893 .req_capabilities
= 0, /* MBZ */
1894 .large_lock_type
= 0,
1895 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1896 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1897 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1898 .header_size
= sizeof(struct smb2_hdr
),
1899 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1900 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1901 .lock_cmd
= SMB2_LOCK
,
1903 .cap_nt_find
= SMB2_NT_FIND
,
1904 .cap_large_files
= SMB2_LARGE_FILES
,
1905 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1906 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1907 .create_lease_size
= sizeof(struct create_lease
),
1910 struct smb_version_values smb21_values
= {
1911 .version_string
= SMB21_VERSION_STRING
,
1912 .protocol_id
= SMB21_PROT_ID
,
1913 .req_capabilities
= 0, /* MBZ on negotiate req until SMB3 dialect */
1914 .large_lock_type
= 0,
1915 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1916 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1917 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1918 .header_size
= sizeof(struct smb2_hdr
),
1919 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1920 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1921 .lock_cmd
= SMB2_LOCK
,
1923 .cap_nt_find
= SMB2_NT_FIND
,
1924 .cap_large_files
= SMB2_LARGE_FILES
,
1925 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1926 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1927 .create_lease_size
= sizeof(struct create_lease
),
1930 struct smb_version_values smb30_values
= {
1931 .version_string
= SMB30_VERSION_STRING
,
1932 .protocol_id
= SMB30_PROT_ID
,
1933 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
1934 .large_lock_type
= 0,
1935 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1936 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1937 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1938 .header_size
= sizeof(struct smb2_hdr
),
1939 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1940 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1941 .lock_cmd
= SMB2_LOCK
,
1943 .cap_nt_find
= SMB2_NT_FIND
,
1944 .cap_large_files
= SMB2_LARGE_FILES
,
1945 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1946 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1947 .create_lease_size
= sizeof(struct create_lease_v2
),
1950 struct smb_version_values smb302_values
= {
1951 .version_string
= SMB302_VERSION_STRING
,
1952 .protocol_id
= SMB302_PROT_ID
,
1953 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
| SMB2_GLOBAL_CAP_ENCRYPTION
,
1954 .large_lock_type
= 0,
1955 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1956 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1957 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1958 .header_size
= sizeof(struct smb2_hdr
),
1959 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1960 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1961 .lock_cmd
= SMB2_LOCK
,
1963 .cap_nt_find
= SMB2_NT_FIND
,
1964 .cap_large_files
= SMB2_LARGE_FILES
,
1965 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1966 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1967 .create_lease_size
= sizeof(struct create_lease_v2
),
1970 #ifdef CONFIG_CIFS_SMB311
1971 struct smb_version_values smb311_values
= {
1972 .version_string
= SMB311_VERSION_STRING
,
1973 .protocol_id
= SMB311_PROT_ID
,
1974 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
| SMB2_GLOBAL_CAP_PERSISTENT_HANDLES
,
1975 .large_lock_type
= 0,
1976 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1977 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1978 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1979 .header_size
= sizeof(struct smb2_hdr
),
1980 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1981 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1982 .lock_cmd
= SMB2_LOCK
,
1984 .cap_nt_find
= SMB2_NT_FIND
,
1985 .cap_large_files
= SMB2_LARGE_FILES
,
1986 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1987 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1988 .create_lease_size
= sizeof(struct create_lease_v2
),