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 some credits for reopen and other ops */
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 */
634 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
635 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
636 true /* is_fsctl */, (char *)pcchunk,
637 sizeof(struct copychunk_ioctl), (char **)&retbuf,
641 sizeof(struct copychunk_ioctl_rsp)) {
642 cifs_dbg(VFS, "invalid cchunk response size\n");
646 if (retbuf->TotalBytesWritten == 0) {
647 cifs_dbg(FYI, "no bytes copied\n");
652 * Check if server claimed to write more than we asked
654 if (le32_to_cpu(retbuf->TotalBytesWritten) >
655 le32_to_cpu(pcchunk->Length)) {
656 cifs_dbg(VFS, "invalid copy chunk response\n");
660 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
661 cifs_dbg(VFS, "invalid num chunks written\n");
667 src_off += le32_to_cpu(retbuf->TotalBytesWritten);
668 dest_off += le32_to_cpu(retbuf->TotalBytesWritten);
669 len -= le32_to_cpu(retbuf->TotalBytesWritten);
671 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %d\n",
672 le32_to_cpu(retbuf->ChunksWritten),
673 le32_to_cpu(retbuf->ChunkBytesWritten),
674 le32_to_cpu(retbuf->TotalBytesWritten));
675 } else if (rc == -EINVAL) {
676 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
679 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
680 le32_to_cpu(retbuf->ChunksWritten),
681 le32_to_cpu(retbuf->ChunkBytesWritten),
682 le32_to_cpu(retbuf->TotalBytesWritten));
685 * Check if this is the first request using these sizes,
686 * (ie check if copy succeed once with original sizes
687 * and check if the server gave us different sizes after
688 * we already updated max sizes on previous request).
689 * if not then why is the server returning an error now
691 if ((chunks_copied != 0) || chunk_sizes_updated)
694 /* Check that server is not asking us to grow size */
695 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
696 tcon->max_bytes_chunk)
697 tcon->max_bytes_chunk =
698 le32_to_cpu(retbuf->ChunkBytesWritten);
700 goto cchunk_out; /* server gave us bogus size */
702 /* No need to change MaxChunks since already set to 1 */
703 chunk_sizes_updated = true;
715 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
716 struct cifs_fid *fid)
718 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
722 smb2_read_data_offset(char *buf)
724 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
725 return rsp->DataOffset;
729 smb2_read_data_length(char *buf)
731 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
732 return le32_to_cpu(rsp->DataLength);
737 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
738 struct cifs_io_parms *parms, unsigned int *bytes_read,
739 char **buf, int *buf_type)
741 parms->persistent_fid = pfid->persistent_fid;
742 parms->volatile_fid = pfid->volatile_fid;
743 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
747 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
748 struct cifs_io_parms *parms, unsigned int *written,
749 struct kvec *iov, unsigned long nr_segs)
752 parms->persistent_fid = pfid->persistent_fid;
753 parms->volatile_fid = pfid->volatile_fid;
754 return SMB2_write(xid, parms, written, iov, nr_segs);
757 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
758 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
759 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
761 struct cifsInodeInfo *cifsi;
764 cifsi = CIFS_I(inode);
766 /* if file already sparse don't bother setting sparse again */
767 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
768 return true; /* already sparse */
770 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
771 return true; /* already not sparse */
774 * Can't check for sparse support on share the usual way via the
775 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
776 * since Samba server doesn't set the flag on the share, yet
777 * supports the set sparse FSCTL and returns sparse correctly
778 * in the file attributes. If we fail setting sparse though we
779 * mark that server does not support sparse files for this share
780 * to avoid repeatedly sending the unsupported fsctl to server
781 * if the file is repeatedly extended.
783 if (tcon->broken_sparse_sup)
786 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
787 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
788 true /* is_fctl */, &setsparse, 1, NULL, NULL);
790 tcon->broken_sparse_sup = true;
791 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
796 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
798 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
804 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
805 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
807 __le64 eof = cpu_to_le64(size);
811 * If extending file more than one page make sparse. Many Linux fs
812 * make files sparse by default when extending via ftruncate
814 inode = d_inode(cfile->dentry);
816 if (!set_alloc && (size > inode->i_size + 8192)) {
819 /* whether set sparse succeeds or not, extend the file */
820 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
823 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
824 cfile->fid.volatile_fid, cfile->pid, &eof, false);
828 smb2_duplicate_extents(const unsigned int xid,
829 struct cifsFileInfo *srcfile,
830 struct cifsFileInfo *trgtfile, u64 src_off,
831 u64 len, u64 dest_off)
834 unsigned int ret_data_len;
835 struct duplicate_extents_to_file dup_ext_buf;
836 struct cifs_tcon *tcon = tlink_tcon(trgtfile->tlink);
838 /* server fileays advertise duplicate extent support with this flag */
839 if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) &
840 FILE_SUPPORTS_BLOCK_REFCOUNTING) == 0)
843 dup_ext_buf.VolatileFileHandle = srcfile->fid.volatile_fid;
844 dup_ext_buf.PersistentFileHandle = srcfile->fid.persistent_fid;
845 dup_ext_buf.SourceFileOffset = cpu_to_le64(src_off);
846 dup_ext_buf.TargetFileOffset = cpu_to_le64(dest_off);
847 dup_ext_buf.ByteCount = cpu_to_le64(len);
848 cifs_dbg(FYI, "duplicate extents: src off %lld dst off %lld len %lld",
849 src_off, dest_off, len);
851 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
853 goto duplicate_extents_out;
855 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
856 trgtfile->fid.volatile_fid,
857 FSCTL_DUPLICATE_EXTENTS_TO_FILE,
858 true /* is_fsctl */, (char *)&dup_ext_buf,
859 sizeof(struct duplicate_extents_to_file),
863 if (ret_data_len > 0)
864 cifs_dbg(FYI, "non-zero response length in duplicate extents");
866 duplicate_extents_out:
871 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
872 struct cifsFileInfo *cfile)
874 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
875 cfile->fid.volatile_fid);
879 smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
880 struct cifsFileInfo *cfile)
882 struct fsctl_set_integrity_information_req integr_info;
883 unsigned int ret_data_len;
885 integr_info.ChecksumAlgorithm = cpu_to_le16(CHECKSUM_TYPE_UNCHANGED);
886 integr_info.Flags = 0;
887 integr_info.Reserved = 0;
889 return SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
890 cfile->fid.volatile_fid,
891 FSCTL_SET_INTEGRITY_INFORMATION,
892 true /* is_fsctl */, (char *)&integr_info,
893 sizeof(struct fsctl_set_integrity_information_req),
899 /* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */
900 #define GMT_TOKEN_SIZE 50
903 * Input buffer contains (empty) struct smb_snapshot array with size filled in
904 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2
907 smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
908 struct cifsFileInfo *cfile, void __user *ioc_buf)
911 unsigned int ret_data_len = 0;
913 struct smb_snapshot_array snapshot_in;
915 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
916 cfile->fid.volatile_fid,
917 FSCTL_SRV_ENUMERATE_SNAPSHOTS,
918 true /* is_fsctl */, NULL, 0 /* no input data */,
921 cifs_dbg(FYI, "enum snaphots ioctl returned %d and ret buflen is %d\n",
926 if (ret_data_len && (ioc_buf != NULL) && (retbuf != NULL)) {
928 if (copy_from_user(&snapshot_in, ioc_buf,
929 sizeof(struct smb_snapshot_array))) {
936 * Check for min size, ie not large enough to fit even one GMT
937 * token (snapshot). On the first ioctl some users may pass in
938 * smaller size (or zero) to simply get the size of the array
939 * so the user space caller can allocate sufficient memory
940 * and retry the ioctl again with larger array size sufficient
941 * to hold all of the snapshot GMT tokens on the second try.
943 if (snapshot_in.snapshot_array_size < GMT_TOKEN_SIZE)
944 ret_data_len = sizeof(struct smb_snapshot_array);
947 * We return struct SRV_SNAPSHOT_ARRAY, followed by
948 * the snapshot array (of 50 byte GMT tokens) each
949 * representing an available previous version of the data
951 if (ret_data_len > (snapshot_in.snapshot_array_size +
952 sizeof(struct smb_snapshot_array)))
953 ret_data_len = snapshot_in.snapshot_array_size +
954 sizeof(struct smb_snapshot_array);
956 if (copy_to_user(ioc_buf, retbuf, ret_data_len))
965 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
966 const char *path, struct cifs_sb_info *cifs_sb,
967 struct cifs_fid *fid, __u16 search_flags,
968 struct cifs_search_info *srch_inf)
972 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
973 struct cifs_open_parms oparms;
975 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
980 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
981 oparms.disposition = FILE_OPEN;
982 oparms.create_options = 0;
984 oparms.reconnect = false;
986 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
989 cifs_dbg(FYI, "open dir failed rc=%d\n", rc);
993 srch_inf->entries_in_buffer = 0;
994 srch_inf->index_of_last_entry = 2;
996 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
997 fid->volatile_fid, 0, srch_inf);
999 cifs_dbg(FYI, "query directory failed rc=%d\n", rc);
1000 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1006 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
1007 struct cifs_fid *fid, __u16 search_flags,
1008 struct cifs_search_info *srch_inf)
1010 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
1011 fid->volatile_fid, 0, srch_inf);
1015 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
1016 struct cifs_fid *fid)
1018 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
1022 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
1023 * the number of credits and return true. Otherwise - return false.
1026 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
1028 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
1030 if (hdr->Status != STATUS_PENDING)
1034 spin_lock(&server->req_lock);
1035 server->credits += le16_to_cpu(hdr->CreditRequest);
1036 spin_unlock(&server->req_lock);
1037 wake_up(&server->request_q);
1044 smb2_is_session_expired(char *buf)
1046 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
1048 if (hdr->Status != STATUS_NETWORK_SESSION_EXPIRED)
1051 cifs_dbg(FYI, "Session expired\n");
1056 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
1057 struct cifsInodeInfo *cinode)
1059 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
1060 return SMB2_lease_break(0, tcon, cinode->lease_key,
1061 smb2_get_lease_state(cinode));
1063 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
1065 CIFS_CACHE_READ(cinode) ? 1 : 0);
1069 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
1070 struct kstatfs *buf)
1073 __le16 srch_path = 0; /* Null - open root of share */
1074 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1075 struct cifs_open_parms oparms;
1076 struct cifs_fid fid;
1079 oparms.desired_access = FILE_READ_ATTRIBUTES;
1080 oparms.disposition = FILE_OPEN;
1081 oparms.create_options = 0;
1083 oparms.reconnect = false;
1085 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
1088 buf->f_type = SMB2_MAGIC_NUMBER;
1089 rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
1091 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
1096 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
1098 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
1099 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
1103 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
1104 __u64 length, __u32 type, int lock, int unlock, bool wait)
1106 if (unlock && !lock)
1107 type = SMB2_LOCKFLAG_UNLOCK;
1108 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
1109 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
1110 current->tgid, length, offset, type, wait);
1114 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
1116 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
1120 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
1122 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
1126 smb2_new_lease_key(struct cifs_fid *fid)
1128 generate_random_uuid(fid->lease_key);
1131 #define SMB2_SYMLINK_STRUCT_SIZE \
1132 (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
1135 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
1136 const char *full_path, char **target_path,
1137 struct cifs_sb_info *cifs_sb)
1141 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
1142 struct cifs_open_parms oparms;
1143 struct cifs_fid fid;
1144 struct smb2_err_rsp *err_buf = NULL;
1145 struct smb2_symlink_err_rsp *symlink;
1146 unsigned int sub_len;
1147 unsigned int sub_offset;
1148 unsigned int print_len;
1149 unsigned int print_offset;
1151 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
1153 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
1158 oparms.desired_access = FILE_READ_ATTRIBUTES;
1159 oparms.disposition = FILE_OPEN;
1160 oparms.create_options = 0;
1162 oparms.reconnect = false;
1164 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
1166 if (!rc || !err_buf) {
1171 if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
1172 get_rfc1002_length(err_buf) + 4 < SMB2_SYMLINK_STRUCT_SIZE) {
1177 /* open must fail on symlink - reset rc */
1179 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
1180 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
1181 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
1182 print_len = le16_to_cpu(symlink->PrintNameLength);
1183 print_offset = le16_to_cpu(symlink->PrintNameOffset);
1185 if (get_rfc1002_length(err_buf) + 4 <
1186 SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
1191 if (get_rfc1002_length(err_buf) + 4 <
1192 SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
1197 *target_path = cifs_strndup_from_utf16(
1198 (char *)symlink->PathBuffer + sub_offset,
1199 sub_len, true, cifs_sb->local_nls);
1200 if (!(*target_path)) {
1204 convert_delimiter(*target_path, '/');
1205 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
1210 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
1211 loff_t offset, loff_t len, bool keep_size)
1213 struct inode *inode;
1214 struct cifsInodeInfo *cifsi;
1215 struct cifsFileInfo *cfile = file->private_data;
1216 struct file_zero_data_information fsctl_buf;
1222 inode = d_inode(cfile->dentry);
1223 cifsi = CIFS_I(inode);
1226 * We zero the range through ioctl, so we need remove the page caches
1227 * first, otherwise the data may be inconsistent with the server.
1229 truncate_pagecache_range(inode, offset, offset + len - 1);
1231 /* if file not oplocked can't be sure whether asking to extend size */
1232 if (!CIFS_CACHE_READ(cifsi))
1233 if (keep_size == false)
1237 * Must check if file sparse since fallocate -z (zero range) assumes
1238 * non-sparse allocation
1240 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE))
1244 * need to make sure we are not asked to extend the file since the SMB3
1245 * fsctl does not change the file size. In the future we could change
1246 * this to zero the first part of the range then set the file size
1247 * which for a non sparse file would zero the newly extended range
1249 if (keep_size == false)
1250 if (i_size_read(inode) < offset + len)
1253 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1255 fsctl_buf.FileOffset = cpu_to_le64(offset);
1256 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1258 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1259 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
1260 true /* is_fctl */, (char *)&fsctl_buf,
1261 sizeof(struct file_zero_data_information), NULL, NULL);
1266 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
1267 loff_t offset, loff_t len)
1269 struct inode *inode;
1270 struct cifsInodeInfo *cifsi;
1271 struct cifsFileInfo *cfile = file->private_data;
1272 struct file_zero_data_information fsctl_buf;
1275 __u8 set_sparse = 1;
1279 inode = d_inode(cfile->dentry);
1280 cifsi = CIFS_I(inode);
1282 /* Need to make file sparse, if not already, before freeing range. */
1283 /* Consider adding equivalent for compressed since it could also work */
1284 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse))
1288 * We implement the punch hole through ioctl, so we need remove the page
1289 * caches first, otherwise the data may be inconsistent with the server.
1291 truncate_pagecache_range(inode, offset, offset + len - 1);
1293 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1295 fsctl_buf.FileOffset = cpu_to_le64(offset);
1296 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1298 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1299 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
1300 true /* is_fctl */, (char *)&fsctl_buf,
1301 sizeof(struct file_zero_data_information), NULL, NULL);
1306 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
1307 loff_t off, loff_t len, bool keep_size)
1309 struct inode *inode;
1310 struct cifsInodeInfo *cifsi;
1311 struct cifsFileInfo *cfile = file->private_data;
1312 long rc = -EOPNOTSUPP;
1317 inode = d_inode(cfile->dentry);
1318 cifsi = CIFS_I(inode);
1320 /* if file not oplocked can't be sure whether asking to extend size */
1321 if (!CIFS_CACHE_READ(cifsi))
1322 if (keep_size == false)
1326 * Files are non-sparse by default so falloc may be a no-op
1327 * Must check if file sparse. If not sparse, and not extending
1328 * then no need to do anything since file already allocated
1330 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
1331 if (keep_size == true)
1333 /* check if extending file */
1334 else if (i_size_read(inode) >= off + len)
1335 /* not extending file and already not sparse */
1337 /* BB: in future add else clause to extend file */
1342 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
1344 * Check if falloc starts within first few pages of file
1345 * and ends within a few pages of the end of file to
1346 * ensure that most of file is being forced to be
1347 * fallocated now. If so then setting whole file sparse
1348 * ie potentially making a few extra pages at the beginning
1349 * or end of the file non-sparse via set_sparse is harmless.
1351 if ((off > 8192) || (off + len + 8192 < i_size_read(inode)))
1354 rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
1356 /* BB: else ... in future add code to extend file and set sparse */
1364 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
1365 loff_t off, loff_t len)
1367 /* KEEP_SIZE already checked for by do_fallocate */
1368 if (mode & FALLOC_FL_PUNCH_HOLE)
1369 return smb3_punch_hole(file, tcon, off, len);
1370 else if (mode & FALLOC_FL_ZERO_RANGE) {
1371 if (mode & FALLOC_FL_KEEP_SIZE)
1372 return smb3_zero_range(file, tcon, off, len, true);
1373 return smb3_zero_range(file, tcon, off, len, false);
1374 } else if (mode == FALLOC_FL_KEEP_SIZE)
1375 return smb3_simple_falloc(file, tcon, off, len, true);
1377 return smb3_simple_falloc(file, tcon, off, len, false);
1383 smb2_downgrade_oplock(struct TCP_Server_Info *server,
1384 struct cifsInodeInfo *cinode, __u32 oplock,
1385 unsigned int epoch, bool *purge_cache)
1387 server->ops->set_oplock_level(cinode, oplock, 0, NULL);
1391 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1392 unsigned int epoch, bool *purge_cache);
1395 smb3_downgrade_oplock(struct TCP_Server_Info *server,
1396 struct cifsInodeInfo *cinode, __u32 oplock,
1397 unsigned int epoch, bool *purge_cache)
1399 unsigned int old_state = cinode->oplock;
1400 unsigned int old_epoch = cinode->epoch;
1401 unsigned int new_state;
1403 if (epoch > old_epoch) {
1404 smb21_set_oplock_level(cinode, oplock, 0, NULL);
1405 cinode->epoch = epoch;
1408 new_state = cinode->oplock;
1409 *purge_cache = false;
1411 if ((old_state & CIFS_CACHE_READ_FLG) != 0 &&
1412 (new_state & CIFS_CACHE_READ_FLG) == 0)
1413 *purge_cache = true;
1414 else if (old_state == new_state && (epoch - old_epoch > 1))
1415 *purge_cache = true;
1419 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1420 unsigned int epoch, bool *purge_cache)
1423 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1425 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
1426 cinode->oplock = CIFS_CACHE_RHW_FLG;
1427 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
1428 &cinode->vfs_inode);
1429 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
1430 cinode->oplock = CIFS_CACHE_RW_FLG;
1431 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
1432 &cinode->vfs_inode);
1433 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
1434 cinode->oplock = CIFS_CACHE_READ_FLG;
1435 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
1436 &cinode->vfs_inode);
1442 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1443 unsigned int epoch, bool *purge_cache)
1445 char message[5] = {0};
1446 unsigned int new_oplock = 0;
1449 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1452 /* Check if the server granted an oplock rather than a lease */
1453 if (oplock & SMB2_OPLOCK_LEVEL_EXCLUSIVE)
1454 return smb2_set_oplock_level(cinode, oplock, epoch,
1457 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
1458 new_oplock |= CIFS_CACHE_READ_FLG;
1459 strcat(message, "R");
1461 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
1462 new_oplock |= CIFS_CACHE_HANDLE_FLG;
1463 strcat(message, "H");
1465 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
1466 new_oplock |= CIFS_CACHE_WRITE_FLG;
1467 strcat(message, "W");
1470 strncpy(message, "None", sizeof(message));
1472 cinode->oplock = new_oplock;
1473 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
1474 &cinode->vfs_inode);
1478 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1479 unsigned int epoch, bool *purge_cache)
1481 unsigned int old_oplock = cinode->oplock;
1483 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
1486 *purge_cache = false;
1487 if (old_oplock == CIFS_CACHE_READ_FLG) {
1488 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
1489 (epoch - cinode->epoch > 0))
1490 *purge_cache = true;
1491 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1492 (epoch - cinode->epoch > 1))
1493 *purge_cache = true;
1494 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1495 (epoch - cinode->epoch > 1))
1496 *purge_cache = true;
1497 else if (cinode->oplock == 0 &&
1498 (epoch - cinode->epoch > 0))
1499 *purge_cache = true;
1500 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
1501 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1502 (epoch - cinode->epoch > 0))
1503 *purge_cache = true;
1504 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1505 (epoch - cinode->epoch > 1))
1506 *purge_cache = true;
1508 cinode->epoch = epoch;
1513 smb2_is_read_op(__u32 oplock)
1515 return oplock == SMB2_OPLOCK_LEVEL_II;
1519 smb21_is_read_op(__u32 oplock)
1521 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
1522 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
1526 map_oplock_to_lease(u8 oplock)
1528 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
1529 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
1530 else if (oplock == SMB2_OPLOCK_LEVEL_II)
1531 return SMB2_LEASE_READ_CACHING;
1532 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
1533 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
1534 SMB2_LEASE_WRITE_CACHING;
1539 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
1541 struct create_lease *buf;
1543 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
1547 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
1548 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
1549 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
1551 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1552 (struct create_lease, lcontext));
1553 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
1554 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1555 (struct create_lease, Name));
1556 buf->ccontext.NameLength = cpu_to_le16(4);
1557 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1566 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
1568 struct create_lease_v2 *buf;
1570 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
1574 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
1575 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
1576 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
1578 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1579 (struct create_lease_v2, lcontext));
1580 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
1581 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1582 (struct create_lease_v2, Name));
1583 buf->ccontext.NameLength = cpu_to_le16(4);
1584 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1593 smb2_parse_lease_buf(void *buf, unsigned int *epoch)
1595 struct create_lease *lc = (struct create_lease *)buf;
1597 *epoch = 0; /* not used */
1598 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
1599 return SMB2_OPLOCK_LEVEL_NOCHANGE;
1600 return le32_to_cpu(lc->lcontext.LeaseState);
1604 smb3_parse_lease_buf(void *buf, unsigned int *epoch)
1606 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
1608 *epoch = le16_to_cpu(lc->lcontext.Epoch);
1609 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
1610 return SMB2_OPLOCK_LEVEL_NOCHANGE;
1611 return le32_to_cpu(lc->lcontext.LeaseState);
1615 smb2_wp_retry_size(struct inode *inode)
1617 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
1618 SMB2_MAX_BUFFER_SIZE);
1622 smb2_dir_needs_close(struct cifsFileInfo *cfile)
1624 return !cfile->invalidHandle;
1627 struct smb_version_operations smb20_operations = {
1628 .compare_fids = smb2_compare_fids,
1629 .setup_request = smb2_setup_request,
1630 .setup_async_request = smb2_setup_async_request,
1631 .check_receive = smb2_check_receive,
1632 .add_credits = smb2_add_credits,
1633 .set_credits = smb2_set_credits,
1634 .get_credits_field = smb2_get_credits_field,
1635 .get_credits = smb2_get_credits,
1636 .wait_mtu_credits = cifs_wait_mtu_credits,
1637 .get_next_mid = smb2_get_next_mid,
1638 .read_data_offset = smb2_read_data_offset,
1639 .read_data_length = smb2_read_data_length,
1640 .map_error = map_smb2_to_linux_error,
1641 .find_mid = smb2_find_mid,
1642 .check_message = smb2_check_message,
1643 .dump_detail = smb2_dump_detail,
1644 .clear_stats = smb2_clear_stats,
1645 .print_stats = smb2_print_stats,
1646 .is_oplock_break = smb2_is_valid_oplock_break,
1647 .handle_cancelled_mid = smb2_handle_cancelled_mid,
1648 .downgrade_oplock = smb2_downgrade_oplock,
1649 .need_neg = smb2_need_neg,
1650 .negotiate = smb2_negotiate,
1651 .negotiate_wsize = smb2_negotiate_wsize,
1652 .negotiate_rsize = smb2_negotiate_rsize,
1653 .sess_setup = SMB2_sess_setup,
1654 .logoff = SMB2_logoff,
1655 .tree_connect = SMB2_tcon,
1656 .tree_disconnect = SMB2_tdis,
1657 .qfs_tcon = smb2_qfs_tcon,
1658 .is_path_accessible = smb2_is_path_accessible,
1659 .can_echo = smb2_can_echo,
1661 .query_path_info = smb2_query_path_info,
1662 .get_srv_inum = smb2_get_srv_inum,
1663 .query_file_info = smb2_query_file_info,
1664 .set_path_size = smb2_set_path_size,
1665 .set_file_size = smb2_set_file_size,
1666 .set_file_info = smb2_set_file_info,
1667 .set_compression = smb2_set_compression,
1668 .mkdir = smb2_mkdir,
1669 .mkdir_setinfo = smb2_mkdir_setinfo,
1670 .rmdir = smb2_rmdir,
1671 .unlink = smb2_unlink,
1672 .rename = smb2_rename_path,
1673 .create_hardlink = smb2_create_hardlink,
1674 .query_symlink = smb2_query_symlink,
1675 .query_mf_symlink = smb3_query_mf_symlink,
1676 .create_mf_symlink = smb3_create_mf_symlink,
1677 .open = smb2_open_file,
1678 .set_fid = smb2_set_fid,
1679 .close = smb2_close_file,
1680 .flush = smb2_flush_file,
1681 .async_readv = smb2_async_readv,
1682 .async_writev = smb2_async_writev,
1683 .sync_read = smb2_sync_read,
1684 .sync_write = smb2_sync_write,
1685 .query_dir_first = smb2_query_dir_first,
1686 .query_dir_next = smb2_query_dir_next,
1687 .close_dir = smb2_close_dir,
1688 .calc_smb_size = smb2_calc_size,
1689 .is_status_pending = smb2_is_status_pending,
1690 .is_session_expired = smb2_is_session_expired,
1691 .oplock_response = smb2_oplock_response,
1692 .queryfs = smb2_queryfs,
1693 .mand_lock = smb2_mand_lock,
1694 .mand_unlock_range = smb2_unlock_range,
1695 .push_mand_locks = smb2_push_mandatory_locks,
1696 .get_lease_key = smb2_get_lease_key,
1697 .set_lease_key = smb2_set_lease_key,
1698 .new_lease_key = smb2_new_lease_key,
1699 .calc_signature = smb2_calc_signature,
1700 .is_read_op = smb2_is_read_op,
1701 .set_oplock_level = smb2_set_oplock_level,
1702 .create_lease_buf = smb2_create_lease_buf,
1703 .parse_lease_buf = smb2_parse_lease_buf,
1704 .clone_range = smb2_clone_range,
1705 .wp_retry_size = smb2_wp_retry_size,
1706 .dir_needs_close = smb2_dir_needs_close,
1709 struct smb_version_operations smb21_operations = {
1710 .compare_fids = smb2_compare_fids,
1711 .setup_request = smb2_setup_request,
1712 .setup_async_request = smb2_setup_async_request,
1713 .check_receive = smb2_check_receive,
1714 .add_credits = smb2_add_credits,
1715 .set_credits = smb2_set_credits,
1716 .get_credits_field = smb2_get_credits_field,
1717 .get_credits = smb2_get_credits,
1718 .wait_mtu_credits = smb2_wait_mtu_credits,
1719 .get_next_mid = smb2_get_next_mid,
1720 .read_data_offset = smb2_read_data_offset,
1721 .read_data_length = smb2_read_data_length,
1722 .map_error = map_smb2_to_linux_error,
1723 .find_mid = smb2_find_mid,
1724 .check_message = smb2_check_message,
1725 .dump_detail = smb2_dump_detail,
1726 .clear_stats = smb2_clear_stats,
1727 .print_stats = smb2_print_stats,
1728 .is_oplock_break = smb2_is_valid_oplock_break,
1729 .handle_cancelled_mid = smb2_handle_cancelled_mid,
1730 .downgrade_oplock = smb2_downgrade_oplock,
1731 .need_neg = smb2_need_neg,
1732 .negotiate = smb2_negotiate,
1733 .negotiate_wsize = smb2_negotiate_wsize,
1734 .negotiate_rsize = smb2_negotiate_rsize,
1735 .sess_setup = SMB2_sess_setup,
1736 .logoff = SMB2_logoff,
1737 .tree_connect = SMB2_tcon,
1738 .tree_disconnect = SMB2_tdis,
1739 .qfs_tcon = smb2_qfs_tcon,
1740 .is_path_accessible = smb2_is_path_accessible,
1741 .can_echo = smb2_can_echo,
1743 .query_path_info = smb2_query_path_info,
1744 .get_srv_inum = smb2_get_srv_inum,
1745 .query_file_info = smb2_query_file_info,
1746 .set_path_size = smb2_set_path_size,
1747 .set_file_size = smb2_set_file_size,
1748 .set_file_info = smb2_set_file_info,
1749 .set_compression = smb2_set_compression,
1750 .mkdir = smb2_mkdir,
1751 .mkdir_setinfo = smb2_mkdir_setinfo,
1752 .rmdir = smb2_rmdir,
1753 .unlink = smb2_unlink,
1754 .rename = smb2_rename_path,
1755 .create_hardlink = smb2_create_hardlink,
1756 .query_symlink = smb2_query_symlink,
1757 .query_mf_symlink = smb3_query_mf_symlink,
1758 .create_mf_symlink = smb3_create_mf_symlink,
1759 .open = smb2_open_file,
1760 .set_fid = smb2_set_fid,
1761 .close = smb2_close_file,
1762 .flush = smb2_flush_file,
1763 .async_readv = smb2_async_readv,
1764 .async_writev = smb2_async_writev,
1765 .sync_read = smb2_sync_read,
1766 .sync_write = smb2_sync_write,
1767 .query_dir_first = smb2_query_dir_first,
1768 .query_dir_next = smb2_query_dir_next,
1769 .close_dir = smb2_close_dir,
1770 .calc_smb_size = smb2_calc_size,
1771 .is_status_pending = smb2_is_status_pending,
1772 .is_session_expired = smb2_is_session_expired,
1773 .oplock_response = smb2_oplock_response,
1774 .queryfs = smb2_queryfs,
1775 .mand_lock = smb2_mand_lock,
1776 .mand_unlock_range = smb2_unlock_range,
1777 .push_mand_locks = smb2_push_mandatory_locks,
1778 .get_lease_key = smb2_get_lease_key,
1779 .set_lease_key = smb2_set_lease_key,
1780 .new_lease_key = smb2_new_lease_key,
1781 .calc_signature = smb2_calc_signature,
1782 .is_read_op = smb21_is_read_op,
1783 .set_oplock_level = smb21_set_oplock_level,
1784 .create_lease_buf = smb2_create_lease_buf,
1785 .parse_lease_buf = smb2_parse_lease_buf,
1786 .clone_range = smb2_clone_range,
1787 .wp_retry_size = smb2_wp_retry_size,
1788 .dir_needs_close = smb2_dir_needs_close,
1789 .enum_snapshots = smb3_enum_snapshots,
1792 struct smb_version_operations smb30_operations = {
1793 .compare_fids = smb2_compare_fids,
1794 .setup_request = smb2_setup_request,
1795 .setup_async_request = smb2_setup_async_request,
1796 .check_receive = smb2_check_receive,
1797 .add_credits = smb2_add_credits,
1798 .set_credits = smb2_set_credits,
1799 .get_credits_field = smb2_get_credits_field,
1800 .get_credits = smb2_get_credits,
1801 .wait_mtu_credits = smb2_wait_mtu_credits,
1802 .get_next_mid = smb2_get_next_mid,
1803 .read_data_offset = smb2_read_data_offset,
1804 .read_data_length = smb2_read_data_length,
1805 .map_error = map_smb2_to_linux_error,
1806 .find_mid = smb2_find_mid,
1807 .check_message = smb2_check_message,
1808 .dump_detail = smb2_dump_detail,
1809 .clear_stats = smb2_clear_stats,
1810 .print_stats = smb2_print_stats,
1811 .dump_share_caps = smb2_dump_share_caps,
1812 .is_oplock_break = smb2_is_valid_oplock_break,
1813 .handle_cancelled_mid = smb2_handle_cancelled_mid,
1814 .downgrade_oplock = smb3_downgrade_oplock,
1815 .need_neg = smb2_need_neg,
1816 .negotiate = smb2_negotiate,
1817 .negotiate_wsize = smb2_negotiate_wsize,
1818 .negotiate_rsize = smb2_negotiate_rsize,
1819 .sess_setup = SMB2_sess_setup,
1820 .logoff = SMB2_logoff,
1821 .tree_connect = SMB2_tcon,
1822 .tree_disconnect = SMB2_tdis,
1823 .qfs_tcon = smb3_qfs_tcon,
1824 .is_path_accessible = smb2_is_path_accessible,
1825 .can_echo = smb2_can_echo,
1827 .query_path_info = smb2_query_path_info,
1828 .get_srv_inum = smb2_get_srv_inum,
1829 .query_file_info = smb2_query_file_info,
1830 .set_path_size = smb2_set_path_size,
1831 .set_file_size = smb2_set_file_size,
1832 .set_file_info = smb2_set_file_info,
1833 .set_compression = smb2_set_compression,
1834 .mkdir = smb2_mkdir,
1835 .mkdir_setinfo = smb2_mkdir_setinfo,
1836 .rmdir = smb2_rmdir,
1837 .unlink = smb2_unlink,
1838 .rename = smb2_rename_path,
1839 .create_hardlink = smb2_create_hardlink,
1840 .query_symlink = smb2_query_symlink,
1841 .query_mf_symlink = smb3_query_mf_symlink,
1842 .create_mf_symlink = smb3_create_mf_symlink,
1843 .open = smb2_open_file,
1844 .set_fid = smb2_set_fid,
1845 .close = smb2_close_file,
1846 .flush = smb2_flush_file,
1847 .async_readv = smb2_async_readv,
1848 .async_writev = smb2_async_writev,
1849 .sync_read = smb2_sync_read,
1850 .sync_write = smb2_sync_write,
1851 .query_dir_first = smb2_query_dir_first,
1852 .query_dir_next = smb2_query_dir_next,
1853 .close_dir = smb2_close_dir,
1854 .calc_smb_size = smb2_calc_size,
1855 .is_status_pending = smb2_is_status_pending,
1856 .is_session_expired = smb2_is_session_expired,
1857 .oplock_response = smb2_oplock_response,
1858 .queryfs = smb2_queryfs,
1859 .mand_lock = smb2_mand_lock,
1860 .mand_unlock_range = smb2_unlock_range,
1861 .push_mand_locks = smb2_push_mandatory_locks,
1862 .get_lease_key = smb2_get_lease_key,
1863 .set_lease_key = smb2_set_lease_key,
1864 .new_lease_key = smb2_new_lease_key,
1865 .generate_signingkey = generate_smb30signingkey,
1866 .calc_signature = smb3_calc_signature,
1867 .set_integrity = smb3_set_integrity,
1868 .is_read_op = smb21_is_read_op,
1869 .set_oplock_level = smb3_set_oplock_level,
1870 .create_lease_buf = smb3_create_lease_buf,
1871 .parse_lease_buf = smb3_parse_lease_buf,
1872 .clone_range = smb2_clone_range,
1873 .duplicate_extents = smb2_duplicate_extents,
1874 .validate_negotiate = smb3_validate_negotiate,
1875 .wp_retry_size = smb2_wp_retry_size,
1876 .dir_needs_close = smb2_dir_needs_close,
1877 .fallocate = smb3_fallocate,
1878 .enum_snapshots = smb3_enum_snapshots,
1881 #ifdef CONFIG_CIFS_SMB311
1882 struct smb_version_operations smb311_operations = {
1883 .compare_fids = smb2_compare_fids,
1884 .setup_request = smb2_setup_request,
1885 .setup_async_request = smb2_setup_async_request,
1886 .check_receive = smb2_check_receive,
1887 .add_credits = smb2_add_credits,
1888 .set_credits = smb2_set_credits,
1889 .get_credits_field = smb2_get_credits_field,
1890 .get_credits = smb2_get_credits,
1891 .wait_mtu_credits = smb2_wait_mtu_credits,
1892 .get_next_mid = smb2_get_next_mid,
1893 .read_data_offset = smb2_read_data_offset,
1894 .read_data_length = smb2_read_data_length,
1895 .map_error = map_smb2_to_linux_error,
1896 .find_mid = smb2_find_mid,
1897 .check_message = smb2_check_message,
1898 .dump_detail = smb2_dump_detail,
1899 .clear_stats = smb2_clear_stats,
1900 .print_stats = smb2_print_stats,
1901 .dump_share_caps = smb2_dump_share_caps,
1902 .is_oplock_break = smb2_is_valid_oplock_break,
1903 .handle_cancelled_mid = smb2_handle_cancelled_mid,
1904 .downgrade_oplock = smb3_downgrade_oplock,
1905 .need_neg = smb2_need_neg,
1906 .negotiate = smb2_negotiate,
1907 .negotiate_wsize = smb2_negotiate_wsize,
1908 .negotiate_rsize = smb2_negotiate_rsize,
1909 .sess_setup = SMB2_sess_setup,
1910 .logoff = SMB2_logoff,
1911 .tree_connect = SMB2_tcon,
1912 .tree_disconnect = SMB2_tdis,
1913 .qfs_tcon = smb3_qfs_tcon,
1914 .is_path_accessible = smb2_is_path_accessible,
1915 .can_echo = smb2_can_echo,
1917 .query_path_info = smb2_query_path_info,
1918 .get_srv_inum = smb2_get_srv_inum,
1919 .query_file_info = smb2_query_file_info,
1920 .set_path_size = smb2_set_path_size,
1921 .set_file_size = smb2_set_file_size,
1922 .set_file_info = smb2_set_file_info,
1923 .set_compression = smb2_set_compression,
1924 .mkdir = smb2_mkdir,
1925 .mkdir_setinfo = smb2_mkdir_setinfo,
1926 .rmdir = smb2_rmdir,
1927 .unlink = smb2_unlink,
1928 .rename = smb2_rename_path,
1929 .create_hardlink = smb2_create_hardlink,
1930 .query_symlink = smb2_query_symlink,
1931 .query_mf_symlink = smb3_query_mf_symlink,
1932 .create_mf_symlink = smb3_create_mf_symlink,
1933 .open = smb2_open_file,
1934 .set_fid = smb2_set_fid,
1935 .close = smb2_close_file,
1936 .flush = smb2_flush_file,
1937 .async_readv = smb2_async_readv,
1938 .async_writev = smb2_async_writev,
1939 .sync_read = smb2_sync_read,
1940 .sync_write = smb2_sync_write,
1941 .query_dir_first = smb2_query_dir_first,
1942 .query_dir_next = smb2_query_dir_next,
1943 .close_dir = smb2_close_dir,
1944 .calc_smb_size = smb2_calc_size,
1945 .is_status_pending = smb2_is_status_pending,
1946 .is_session_expired = smb2_is_session_expired,
1947 .oplock_response = smb2_oplock_response,
1948 .queryfs = smb2_queryfs,
1949 .mand_lock = smb2_mand_lock,
1950 .mand_unlock_range = smb2_unlock_range,
1951 .push_mand_locks = smb2_push_mandatory_locks,
1952 .get_lease_key = smb2_get_lease_key,
1953 .set_lease_key = smb2_set_lease_key,
1954 .new_lease_key = smb2_new_lease_key,
1955 .generate_signingkey = generate_smb311signingkey,
1956 .calc_signature = smb3_calc_signature,
1957 .set_integrity = smb3_set_integrity,
1958 .is_read_op = smb21_is_read_op,
1959 .set_oplock_level = smb3_set_oplock_level,
1960 .create_lease_buf = smb3_create_lease_buf,
1961 .parse_lease_buf = smb3_parse_lease_buf,
1962 .clone_range = smb2_clone_range,
1963 .duplicate_extents = smb2_duplicate_extents,
1964 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
1965 .wp_retry_size = smb2_wp_retry_size,
1966 .dir_needs_close = smb2_dir_needs_close,
1967 .fallocate = smb3_fallocate,
1968 .enum_snapshots = smb3_enum_snapshots,
1970 #endif /* CIFS_SMB311 */
1972 struct smb_version_values smb20_values = {
1973 .version_string = SMB20_VERSION_STRING,
1974 .protocol_id = SMB20_PROT_ID,
1975 .req_capabilities = 0, /* MBZ */
1976 .large_lock_type = 0,
1977 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1978 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1979 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1980 .header_size = sizeof(struct smb2_hdr),
1981 .max_header_size = MAX_SMB2_HDR_SIZE,
1982 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1983 .lock_cmd = SMB2_LOCK,
1985 .cap_nt_find = SMB2_NT_FIND,
1986 .cap_large_files = SMB2_LARGE_FILES,
1987 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1988 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
1989 .create_lease_size = sizeof(struct create_lease),
1992 struct smb_version_values smb21_values = {
1993 .version_string = SMB21_VERSION_STRING,
1994 .protocol_id = SMB21_PROT_ID,
1995 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
1996 .large_lock_type = 0,
1997 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1998 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1999 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
2000 .header_size = sizeof(struct smb2_hdr),
2001 .max_header_size = MAX_SMB2_HDR_SIZE,
2002 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
2003 .lock_cmd = SMB2_LOCK,
2005 .cap_nt_find = SMB2_NT_FIND,
2006 .cap_large_files = SMB2_LARGE_FILES,
2007 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
2008 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
2009 .create_lease_size = sizeof(struct create_lease),
2012 struct smb_version_values smb30_values = {
2013 .version_string = SMB30_VERSION_STRING,
2014 .protocol_id = SMB30_PROT_ID,
2015 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
2016 .large_lock_type = 0,
2017 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
2018 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
2019 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
2020 .header_size = sizeof(struct smb2_hdr),
2021 .max_header_size = MAX_SMB2_HDR_SIZE,
2022 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
2023 .lock_cmd = SMB2_LOCK,
2025 .cap_nt_find = SMB2_NT_FIND,
2026 .cap_large_files = SMB2_LARGE_FILES,
2027 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
2028 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
2029 .create_lease_size = sizeof(struct create_lease_v2),
2032 struct smb_version_values smb302_values = {
2033 .version_string = SMB302_VERSION_STRING,
2034 .protocol_id = SMB302_PROT_ID,
2035 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES | SMB2_GLOBAL_CAP_ENCRYPTION,
2036 .large_lock_type = 0,
2037 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
2038 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
2039 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
2040 .header_size = sizeof(struct smb2_hdr),
2041 .max_header_size = MAX_SMB2_HDR_SIZE,
2042 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
2043 .lock_cmd = SMB2_LOCK,
2045 .cap_nt_find = SMB2_NT_FIND,
2046 .cap_large_files = SMB2_LARGE_FILES,
2047 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
2048 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
2049 .create_lease_size = sizeof(struct create_lease_v2),
2052 #ifdef CONFIG_CIFS_SMB311
2053 struct smb_version_values smb311_values = {
2054 .version_string = SMB311_VERSION_STRING,
2055 .protocol_id = SMB311_PROT_ID,
2056 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU | SMB2_GLOBAL_CAP_PERSISTENT_HANDLES,
2057 .large_lock_type = 0,
2058 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
2059 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
2060 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
2061 .header_size = sizeof(struct smb2_hdr),
2062 .max_header_size = MAX_SMB2_HDR_SIZE,
2063 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
2064 .lock_cmd = SMB2_LOCK,
2066 .cap_nt_find = SMB2_NT_FIND,
2067 .cap_large_files = SMB2_LARGE_FILES,
2068 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
2069 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
2070 .create_lease_size = sizeof(struct create_lease_v2),