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"
33 change_conf(struct TCP_Server_Info *server)
35 server->credits += server->echo_credits + server->oplock_credits;
36 server->oplock_credits = server->echo_credits = 0;
37 switch (server->credits) {
41 server->echoes = false;
42 server->oplocks = false;
43 cifs_dbg(VFS, "disabling echoes and oplocks\n");
46 server->echoes = true;
47 server->oplocks = false;
48 server->echo_credits = 1;
49 cifs_dbg(FYI, "disabling oplocks\n");
52 server->echoes = true;
53 server->oplocks = true;
54 server->echo_credits = 1;
55 server->oplock_credits = 1;
57 server->credits -= server->echo_credits + server->oplock_credits;
62 smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
66 spin_lock(&server->req_lock);
67 val = server->ops->get_credits_field(server, optype);
70 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
71 rc = change_conf(server);
73 * Sometimes server returns 0 credits on oplock break ack - we need to
74 * rebalance credits in this case.
76 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
78 if (server->credits > 1) {
80 server->oplock_credits++;
83 spin_unlock(&server->req_lock);
84 wake_up(&server->request_q);
86 cifs_reconnect(server);
90 smb2_set_credits(struct TCP_Server_Info *server, const int val)
92 spin_lock(&server->req_lock);
93 server->credits = val;
94 spin_unlock(&server->req_lock);
98 smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
102 return &server->echo_credits;
104 return &server->oplock_credits;
106 return &server->credits;
111 smb2_get_credits(struct mid_q_entry *mid)
113 return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest);
117 smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
118 unsigned int *num, unsigned int *credits)
121 unsigned int scredits;
123 spin_lock(&server->req_lock);
125 if (server->credits <= 0) {
126 spin_unlock(&server->req_lock);
127 cifs_num_waiters_inc(server);
128 rc = wait_event_killable(server->request_q,
129 has_credits(server, &server->credits));
130 cifs_num_waiters_dec(server);
133 spin_lock(&server->req_lock);
135 if (server->tcpStatus == CifsExiting) {
136 spin_unlock(&server->req_lock);
140 scredits = server->credits;
141 /* can deadlock with reopen */
143 *num = SMB2_MAX_BUFFER_SIZE;
148 /* leave one credit for a possible reopen */
150 *num = min_t(unsigned int, size,
151 scredits * SMB2_MAX_BUFFER_SIZE);
153 *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
154 server->credits -= *credits;
159 spin_unlock(&server->req_lock);
164 smb2_get_next_mid(struct TCP_Server_Info *server)
167 /* for SMB2 we need the current value */
168 spin_lock(&GlobalMid_Lock);
169 mid = server->CurrentMid++;
170 spin_unlock(&GlobalMid_Lock);
174 static struct mid_q_entry *
175 smb2_find_mid(struct TCP_Server_Info *server, char *buf)
177 struct mid_q_entry *mid;
178 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
179 __u64 wire_mid = le64_to_cpu(hdr->MessageId);
181 spin_lock(&GlobalMid_Lock);
182 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
183 if ((mid->mid == wire_mid) &&
184 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
185 (mid->command == hdr->Command)) {
186 spin_unlock(&GlobalMid_Lock);
190 spin_unlock(&GlobalMid_Lock);
195 smb2_dump_detail(void *buf)
197 #ifdef CONFIG_CIFS_DEBUG2
198 struct smb2_hdr *smb = (struct smb2_hdr *)buf;
200 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
201 smb->Command, smb->Status, smb->Flags, smb->MessageId,
203 cifs_dbg(VFS, "smb buf %p len %u\n", smb, smb2_calc_size(smb));
208 smb2_need_neg(struct TCP_Server_Info *server)
210 return server->max_read == 0;
214 smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
217 ses->server->CurrentMid = 0;
218 rc = SMB2_negotiate(xid, ses);
219 /* BB we probably don't need to retry with modern servers */
226 smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
228 struct TCP_Server_Info *server = tcon->ses->server;
231 /* start with specified wsize, or default */
232 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
233 wsize = min_t(unsigned int, wsize, server->max_write);
235 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
236 wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
242 smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
244 struct TCP_Server_Info *server = tcon->ses->server;
247 /* start with specified rsize, or default */
248 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
249 rsize = min_t(unsigned int, rsize, server->max_read);
251 if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
252 rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
257 #ifdef CONFIG_CIFS_STATS2
259 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
262 unsigned int ret_data_len = 0;
263 struct network_interface_info_ioctl_rsp *out_buf;
265 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
266 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
267 NULL /* no data input */, 0 /* no data input */,
268 (char **)&out_buf, &ret_data_len);
270 cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
271 else if (ret_data_len < sizeof(struct network_interface_info_ioctl_rsp)) {
272 cifs_dbg(VFS, "server returned bad net interface info buf\n");
275 /* Dump info on first interface */
276 cifs_dbg(FYI, "Adapter Capability 0x%x\t",
277 le32_to_cpu(out_buf->Capability));
278 cifs_dbg(FYI, "Link Speed %lld\n",
279 le64_to_cpu(out_buf->LinkSpeed));
287 smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
290 __le16 srch_path = 0; /* Null - open root of share */
291 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
292 struct cifs_open_parms oparms;
296 oparms.desired_access = FILE_READ_ATTRIBUTES;
297 oparms.disposition = FILE_OPEN;
298 oparms.create_options = 0;
300 oparms.reconnect = false;
302 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
306 #ifdef CONFIG_CIFS_STATS2
307 SMB3_request_interfaces(xid, tcon);
310 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
311 FS_ATTRIBUTE_INFORMATION);
312 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
313 FS_DEVICE_INFORMATION);
314 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
315 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
316 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
321 smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
324 __le16 srch_path = 0; /* Null - open root of share */
325 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
326 struct cifs_open_parms oparms;
330 oparms.desired_access = FILE_READ_ATTRIBUTES;
331 oparms.disposition = FILE_OPEN;
332 oparms.create_options = 0;
334 oparms.reconnect = false;
336 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
340 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
341 FS_ATTRIBUTE_INFORMATION);
342 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
343 FS_DEVICE_INFORMATION);
344 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
349 smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
350 struct cifs_sb_info *cifs_sb, const char *full_path)
354 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
355 struct cifs_open_parms oparms;
358 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
363 oparms.desired_access = FILE_READ_ATTRIBUTES;
364 oparms.disposition = FILE_OPEN;
365 oparms.create_options = 0;
367 oparms.reconnect = false;
369 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
375 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
381 smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
382 struct cifs_sb_info *cifs_sb, const char *full_path,
383 u64 *uniqueid, FILE_ALL_INFO *data)
385 *uniqueid = le64_to_cpu(data->IndexNumber);
390 smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
391 struct cifs_fid *fid, FILE_ALL_INFO *data)
394 struct smb2_file_all_info *smb2_data;
396 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
398 if (smb2_data == NULL)
401 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
404 move_smb2_info_to_cifs(data, smb2_data);
410 smb2_can_echo(struct TCP_Server_Info *server)
412 return server->echoes;
416 smb2_clear_stats(struct cifs_tcon *tcon)
418 #ifdef CONFIG_CIFS_STATS
420 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
421 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
422 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
428 smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
430 seq_puts(m, "\n\tShare Capabilities:");
431 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
432 seq_puts(m, " DFS,");
433 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
434 seq_puts(m, " CONTINUOUS AVAILABILITY,");
435 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
436 seq_puts(m, " SCALEOUT,");
437 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
438 seq_puts(m, " CLUSTER,");
439 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
440 seq_puts(m, " ASYMMETRIC,");
441 if (tcon->capabilities == 0)
442 seq_puts(m, " None");
443 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
444 seq_puts(m, " Aligned,");
445 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
446 seq_puts(m, " Partition Aligned,");
447 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
448 seq_puts(m, " SSD,");
449 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
450 seq_puts(m, " TRIM-support,");
452 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
453 if (tcon->perf_sector_size)
454 seq_printf(m, "\tOptimal sector size: 0x%x",
455 tcon->perf_sector_size);
459 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
461 #ifdef CONFIG_CIFS_STATS
462 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
463 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
464 seq_printf(m, "\nNegotiates: %d sent %d failed",
465 atomic_read(&sent[SMB2_NEGOTIATE_HE]),
466 atomic_read(&failed[SMB2_NEGOTIATE_HE]));
467 seq_printf(m, "\nSessionSetups: %d sent %d failed",
468 atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
469 atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
470 seq_printf(m, "\nLogoffs: %d sent %d failed",
471 atomic_read(&sent[SMB2_LOGOFF_HE]),
472 atomic_read(&failed[SMB2_LOGOFF_HE]));
473 seq_printf(m, "\nTreeConnects: %d sent %d failed",
474 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
475 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
476 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
477 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
478 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
479 seq_printf(m, "\nCreates: %d sent %d failed",
480 atomic_read(&sent[SMB2_CREATE_HE]),
481 atomic_read(&failed[SMB2_CREATE_HE]));
482 seq_printf(m, "\nCloses: %d sent %d failed",
483 atomic_read(&sent[SMB2_CLOSE_HE]),
484 atomic_read(&failed[SMB2_CLOSE_HE]));
485 seq_printf(m, "\nFlushes: %d sent %d failed",
486 atomic_read(&sent[SMB2_FLUSH_HE]),
487 atomic_read(&failed[SMB2_FLUSH_HE]));
488 seq_printf(m, "\nReads: %d sent %d failed",
489 atomic_read(&sent[SMB2_READ_HE]),
490 atomic_read(&failed[SMB2_READ_HE]));
491 seq_printf(m, "\nWrites: %d sent %d failed",
492 atomic_read(&sent[SMB2_WRITE_HE]),
493 atomic_read(&failed[SMB2_WRITE_HE]));
494 seq_printf(m, "\nLocks: %d sent %d failed",
495 atomic_read(&sent[SMB2_LOCK_HE]),
496 atomic_read(&failed[SMB2_LOCK_HE]));
497 seq_printf(m, "\nIOCTLs: %d sent %d failed",
498 atomic_read(&sent[SMB2_IOCTL_HE]),
499 atomic_read(&failed[SMB2_IOCTL_HE]));
500 seq_printf(m, "\nCancels: %d sent %d failed",
501 atomic_read(&sent[SMB2_CANCEL_HE]),
502 atomic_read(&failed[SMB2_CANCEL_HE]));
503 seq_printf(m, "\nEchos: %d sent %d failed",
504 atomic_read(&sent[SMB2_ECHO_HE]),
505 atomic_read(&failed[SMB2_ECHO_HE]));
506 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
507 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
508 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
509 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
510 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
511 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
512 seq_printf(m, "\nQueryInfos: %d sent %d failed",
513 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
514 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
515 seq_printf(m, "\nSetInfos: %d sent %d failed",
516 atomic_read(&sent[SMB2_SET_INFO_HE]),
517 atomic_read(&failed[SMB2_SET_INFO_HE]));
518 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
519 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
520 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
525 smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
527 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
528 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
530 cfile->fid.persistent_fid = fid->persistent_fid;
531 cfile->fid.volatile_fid = fid->volatile_fid;
532 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
534 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
538 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
539 struct cifs_fid *fid)
541 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
545 SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
546 u64 persistent_fid, u64 volatile_fid,
547 struct copychunk_ioctl *pcchunk)
550 unsigned int ret_data_len;
551 struct resume_key_req *res_key;
553 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
554 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
555 NULL, 0 /* no input */,
556 (char **)&res_key, &ret_data_len);
559 cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
560 goto req_res_key_exit;
562 if (ret_data_len < sizeof(struct resume_key_req)) {
563 cifs_dbg(VFS, "Invalid refcopy resume key length\n");
565 goto req_res_key_exit;
567 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
575 smb2_clone_range(const unsigned int xid,
576 struct cifsFileInfo *srcfile,
577 struct cifsFileInfo *trgtfile, u64 src_off,
578 u64 len, u64 dest_off)
581 unsigned int ret_data_len;
582 struct copychunk_ioctl *pcchunk;
583 struct copychunk_ioctl_rsp *retbuf = NULL;
584 struct cifs_tcon *tcon;
585 int chunks_copied = 0;
586 bool chunk_sizes_updated = false;
588 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
593 cifs_dbg(FYI, "in smb2_clone_range - about to call request res key\n");
594 /* Request a key from the server to identify the source of the copy */
595 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
596 srcfile->fid.persistent_fid,
597 srcfile->fid.volatile_fid, pcchunk);
599 /* Note: request_res_key sets res_key null only if rc !=0 */
603 /* For now array only one chunk long, will make more flexible later */
604 pcchunk->ChunkCount = cpu_to_le32(1);
605 pcchunk->Reserved = 0;
606 pcchunk->Reserved2 = 0;
608 tcon = tlink_tcon(trgtfile->tlink);
611 pcchunk->SourceOffset = cpu_to_le64(src_off);
612 pcchunk->TargetOffset = cpu_to_le64(dest_off);
614 cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
616 /* Request server copy to target from src identified by key */
617 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
618 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
619 true /* is_fsctl */, (char *)pcchunk,
620 sizeof(struct copychunk_ioctl), (char **)&retbuf,
624 sizeof(struct copychunk_ioctl_rsp)) {
625 cifs_dbg(VFS, "invalid cchunk response size\n");
629 if (retbuf->TotalBytesWritten == 0) {
630 cifs_dbg(FYI, "no bytes copied\n");
635 * Check if server claimed to write more than we asked
637 if (le32_to_cpu(retbuf->TotalBytesWritten) >
638 le32_to_cpu(pcchunk->Length)) {
639 cifs_dbg(VFS, "invalid copy chunk response\n");
643 if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
644 cifs_dbg(VFS, "invalid num chunks written\n");
650 src_off += le32_to_cpu(retbuf->TotalBytesWritten);
651 dest_off += le32_to_cpu(retbuf->TotalBytesWritten);
652 len -= le32_to_cpu(retbuf->TotalBytesWritten);
654 cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %d\n",
655 le32_to_cpu(retbuf->ChunksWritten),
656 le32_to_cpu(retbuf->ChunkBytesWritten),
657 le32_to_cpu(retbuf->TotalBytesWritten));
658 } else if (rc == -EINVAL) {
659 if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
662 cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
663 le32_to_cpu(retbuf->ChunksWritten),
664 le32_to_cpu(retbuf->ChunkBytesWritten),
665 le32_to_cpu(retbuf->TotalBytesWritten));
668 * Check if this is the first request using these sizes,
669 * (ie check if copy succeed once with original sizes
670 * and check if the server gave us different sizes after
671 * we already updated max sizes on previous request).
672 * if not then why is the server returning an error now
674 if ((chunks_copied != 0) || chunk_sizes_updated)
677 /* Check that server is not asking us to grow size */
678 if (le32_to_cpu(retbuf->ChunkBytesWritten) <
679 tcon->max_bytes_chunk)
680 tcon->max_bytes_chunk =
681 le32_to_cpu(retbuf->ChunkBytesWritten);
683 goto cchunk_out; /* server gave us bogus size */
685 /* No need to change MaxChunks since already set to 1 */
686 chunk_sizes_updated = true;
697 smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
698 struct cifs_fid *fid)
700 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
704 smb2_read_data_offset(char *buf)
706 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
707 return rsp->DataOffset;
711 smb2_read_data_length(char *buf)
713 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
714 return le32_to_cpu(rsp->DataLength);
719 smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
720 struct cifs_io_parms *parms, unsigned int *bytes_read,
721 char **buf, int *buf_type)
723 parms->persistent_fid = pfid->persistent_fid;
724 parms->volatile_fid = pfid->volatile_fid;
725 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
729 smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
730 struct cifs_io_parms *parms, unsigned int *written,
731 struct kvec *iov, unsigned long nr_segs)
734 parms->persistent_fid = pfid->persistent_fid;
735 parms->volatile_fid = pfid->volatile_fid;
736 return SMB2_write(xid, parms, written, iov, nr_segs);
739 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
740 static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
741 struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
743 struct cifsInodeInfo *cifsi;
746 cifsi = CIFS_I(inode);
748 /* if file already sparse don't bother setting sparse again */
749 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
750 return true; /* already sparse */
752 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
753 return true; /* already not sparse */
756 * Can't check for sparse support on share the usual way via the
757 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
758 * since Samba server doesn't set the flag on the share, yet
759 * supports the set sparse FSCTL and returns sparse correctly
760 * in the file attributes. If we fail setting sparse though we
761 * mark that server does not support sparse files for this share
762 * to avoid repeatedly sending the unsupported fsctl to server
763 * if the file is repeatedly extended.
765 if (tcon->broken_sparse_sup)
768 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
769 cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
770 true /* is_fctl */, &setsparse, 1, NULL, NULL);
772 tcon->broken_sparse_sup = true;
773 cifs_dbg(FYI, "set sparse rc = %d\n", rc);
778 cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
780 cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
786 smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
787 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
789 __le64 eof = cpu_to_le64(size);
793 * If extending file more than one page make sparse. Many Linux fs
794 * make files sparse by default when extending via ftruncate
796 inode = cfile->dentry->d_inode;
798 if (!set_alloc && (size > inode->i_size + 8192)) {
801 /* whether set sparse succeeds or not, extend the file */
802 smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
805 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
806 cfile->fid.volatile_fid, cfile->pid, &eof, false);
810 smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
811 struct cifsFileInfo *cfile)
813 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
814 cfile->fid.volatile_fid);
818 smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
819 const char *path, struct cifs_sb_info *cifs_sb,
820 struct cifs_fid *fid, __u16 search_flags,
821 struct cifs_search_info *srch_inf)
825 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
826 struct cifs_open_parms oparms;
828 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
833 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
834 oparms.disposition = FILE_OPEN;
835 oparms.create_options = 0;
837 oparms.reconnect = false;
839 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
842 cifs_dbg(VFS, "open dir failed\n");
846 srch_inf->entries_in_buffer = 0;
847 srch_inf->index_of_last_entry = 0;
849 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
850 fid->volatile_fid, 0, srch_inf);
852 cifs_dbg(VFS, "query directory failed\n");
853 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
859 smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
860 struct cifs_fid *fid, __u16 search_flags,
861 struct cifs_search_info *srch_inf)
863 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
864 fid->volatile_fid, 0, srch_inf);
868 smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
869 struct cifs_fid *fid)
871 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
875 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
876 * the number of credits and return true. Otherwise - return false.
879 smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
881 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
883 if (hdr->Status != STATUS_PENDING)
887 spin_lock(&server->req_lock);
888 server->credits += le16_to_cpu(hdr->CreditRequest);
889 spin_unlock(&server->req_lock);
890 wake_up(&server->request_q);
897 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
898 struct cifsInodeInfo *cinode)
900 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
901 return SMB2_lease_break(0, tcon, cinode->lease_key,
902 smb2_get_lease_state(cinode));
904 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
906 CIFS_CACHE_READ(cinode) ? 1 : 0);
910 smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
914 __le16 srch_path = 0; /* Null - open root of share */
915 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
916 struct cifs_open_parms oparms;
920 oparms.desired_access = FILE_READ_ATTRIBUTES;
921 oparms.disposition = FILE_OPEN;
922 oparms.create_options = 0;
924 oparms.reconnect = false;
926 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
929 buf->f_type = SMB2_MAGIC_NUMBER;
930 rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
932 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
937 smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
939 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
940 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
944 smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
945 __u64 length, __u32 type, int lock, int unlock, bool wait)
948 type = SMB2_LOCKFLAG_UNLOCK;
949 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
950 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
951 current->tgid, length, offset, type, wait);
955 smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
957 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
961 smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
963 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
967 smb2_new_lease_key(struct cifs_fid *fid)
969 get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
973 smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
974 const char *full_path, char **target_path,
975 struct cifs_sb_info *cifs_sb)
979 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
980 struct cifs_open_parms oparms;
982 struct smb2_err_rsp *err_buf = NULL;
983 struct smb2_symlink_err_rsp *symlink;
984 unsigned int sub_len, sub_offset;
986 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
988 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
993 oparms.desired_access = FILE_READ_ATTRIBUTES;
994 oparms.disposition = FILE_OPEN;
995 oparms.create_options = 0;
997 oparms.reconnect = false;
999 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
1001 if (!rc || !err_buf) {
1005 /* open must fail on symlink - reset rc */
1007 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
1008 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
1009 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
1010 *target_path = cifs_strndup_from_utf16(
1011 (char *)symlink->PathBuffer + sub_offset,
1012 sub_len, true, cifs_sb->local_nls);
1013 if (!(*target_path)) {
1017 convert_delimiter(*target_path, '/');
1018 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
1023 static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
1024 loff_t offset, loff_t len, bool keep_size)
1026 struct inode *inode;
1027 struct cifsInodeInfo *cifsi;
1028 struct cifsFileInfo *cfile = file->private_data;
1029 struct file_zero_data_information fsctl_buf;
1035 inode = cfile->dentry->d_inode;
1036 cifsi = CIFS_I(inode);
1038 /* if file not oplocked can't be sure whether asking to extend size */
1039 if (!CIFS_CACHE_READ(cifsi))
1040 if (keep_size == false)
1044 * Must check if file sparse since fallocate -z (zero range) assumes
1045 * non-sparse allocation
1047 if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE))
1051 * need to make sure we are not asked to extend the file since the SMB3
1052 * fsctl does not change the file size. In the future we could change
1053 * this to zero the first part of the range then set the file size
1054 * which for a non sparse file would zero the newly extended range
1056 if (keep_size == false)
1057 if (i_size_read(inode) < offset + len)
1060 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1062 fsctl_buf.FileOffset = cpu_to_le64(offset);
1063 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1065 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1066 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
1067 true /* is_fctl */, (char *)&fsctl_buf,
1068 sizeof(struct file_zero_data_information), NULL, NULL);
1073 static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
1074 loff_t offset, loff_t len)
1076 struct inode *inode;
1077 struct cifsInodeInfo *cifsi;
1078 struct cifsFileInfo *cfile = file->private_data;
1079 struct file_zero_data_information fsctl_buf;
1082 __u8 set_sparse = 1;
1086 inode = cfile->dentry->d_inode;
1087 cifsi = CIFS_I(inode);
1089 /* Need to make file sparse, if not already, before freeing range. */
1090 /* Consider adding equivalent for compressed since it could also work */
1091 if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse))
1094 cifs_dbg(FYI, "offset %lld len %lld", offset, len);
1096 fsctl_buf.FileOffset = cpu_to_le64(offset);
1097 fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
1099 rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
1100 cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
1101 true /* is_fctl */, (char *)&fsctl_buf,
1102 sizeof(struct file_zero_data_information), NULL, NULL);
1107 static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
1108 loff_t off, loff_t len, bool keep_size)
1110 struct inode *inode;
1111 struct cifsInodeInfo *cifsi;
1112 struct cifsFileInfo *cfile = file->private_data;
1113 long rc = -EOPNOTSUPP;
1118 inode = cfile->dentry->d_inode;
1119 cifsi = CIFS_I(inode);
1121 /* if file not oplocked can't be sure whether asking to extend size */
1122 if (!CIFS_CACHE_READ(cifsi))
1123 if (keep_size == false)
1127 * Files are non-sparse by default so falloc may be a no-op
1128 * Must check if file sparse. If not sparse, and not extending
1129 * then no need to do anything since file already allocated
1131 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
1132 if (keep_size == true)
1134 /* check if extending file */
1135 else if (i_size_read(inode) >= off + len)
1136 /* not extending file and already not sparse */
1138 /* BB: in future add else clause to extend file */
1143 if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
1145 * Check if falloc starts within first few pages of file
1146 * and ends within a few pages of the end of file to
1147 * ensure that most of file is being forced to be
1148 * fallocated now. If so then setting whole file sparse
1149 * ie potentially making a few extra pages at the beginning
1150 * or end of the file non-sparse via set_sparse is harmless.
1152 if ((off > 8192) || (off + len + 8192 < i_size_read(inode)))
1155 rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
1157 /* BB: else ... in future add code to extend file and set sparse */
1165 static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
1166 loff_t off, loff_t len)
1168 /* KEEP_SIZE already checked for by do_fallocate */
1169 if (mode & FALLOC_FL_PUNCH_HOLE)
1170 return smb3_punch_hole(file, tcon, off, len);
1171 else if (mode & FALLOC_FL_ZERO_RANGE) {
1172 if (mode & FALLOC_FL_KEEP_SIZE)
1173 return smb3_zero_range(file, tcon, off, len, true);
1174 return smb3_zero_range(file, tcon, off, len, false);
1175 } else if (mode == FALLOC_FL_KEEP_SIZE)
1176 return smb3_simple_falloc(file, tcon, off, len, true);
1178 return smb3_simple_falloc(file, tcon, off, len, false);
1184 smb2_downgrade_oplock(struct TCP_Server_Info *server,
1185 struct cifsInodeInfo *cinode, bool set_level2)
1188 server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
1191 server->ops->set_oplock_level(cinode, 0, 0, NULL);
1195 smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1196 unsigned int epoch, bool *purge_cache)
1199 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1201 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
1202 cinode->oplock = CIFS_CACHE_RHW_FLG;
1203 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
1204 &cinode->vfs_inode);
1205 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
1206 cinode->oplock = CIFS_CACHE_RW_FLG;
1207 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
1208 &cinode->vfs_inode);
1209 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
1210 cinode->oplock = CIFS_CACHE_READ_FLG;
1211 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
1212 &cinode->vfs_inode);
1218 smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1219 unsigned int epoch, bool *purge_cache)
1221 char message[5] = {0};
1224 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
1228 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
1229 cinode->oplock |= CIFS_CACHE_READ_FLG;
1230 strcat(message, "R");
1232 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
1233 cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
1234 strcat(message, "H");
1236 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
1237 cinode->oplock |= CIFS_CACHE_WRITE_FLG;
1238 strcat(message, "W");
1240 if (!cinode->oplock)
1241 strcat(message, "None");
1242 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
1243 &cinode->vfs_inode);
1247 smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
1248 unsigned int epoch, bool *purge_cache)
1250 unsigned int old_oplock = cinode->oplock;
1252 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
1255 *purge_cache = false;
1256 if (old_oplock == CIFS_CACHE_READ_FLG) {
1257 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
1258 (epoch - cinode->epoch > 0))
1259 *purge_cache = true;
1260 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1261 (epoch - cinode->epoch > 1))
1262 *purge_cache = true;
1263 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1264 (epoch - cinode->epoch > 1))
1265 *purge_cache = true;
1266 else if (cinode->oplock == 0 &&
1267 (epoch - cinode->epoch > 0))
1268 *purge_cache = true;
1269 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
1270 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
1271 (epoch - cinode->epoch > 0))
1272 *purge_cache = true;
1273 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
1274 (epoch - cinode->epoch > 1))
1275 *purge_cache = true;
1277 cinode->epoch = epoch;
1282 smb2_is_read_op(__u32 oplock)
1284 return oplock == SMB2_OPLOCK_LEVEL_II;
1288 smb21_is_read_op(__u32 oplock)
1290 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
1291 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
1295 map_oplock_to_lease(u8 oplock)
1297 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
1298 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
1299 else if (oplock == SMB2_OPLOCK_LEVEL_II)
1300 return SMB2_LEASE_READ_CACHING;
1301 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
1302 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
1303 SMB2_LEASE_WRITE_CACHING;
1308 smb2_create_lease_buf(u8 *lease_key, u8 oplock)
1310 struct create_lease *buf;
1312 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
1316 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
1317 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
1318 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
1320 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1321 (struct create_lease, lcontext));
1322 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
1323 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1324 (struct create_lease, Name));
1325 buf->ccontext.NameLength = cpu_to_le16(4);
1326 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1335 smb3_create_lease_buf(u8 *lease_key, u8 oplock)
1337 struct create_lease_v2 *buf;
1339 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
1343 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
1344 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
1345 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
1347 buf->ccontext.DataOffset = cpu_to_le16(offsetof
1348 (struct create_lease_v2, lcontext));
1349 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
1350 buf->ccontext.NameOffset = cpu_to_le16(offsetof
1351 (struct create_lease_v2, Name));
1352 buf->ccontext.NameLength = cpu_to_le16(4);
1353 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1362 smb2_parse_lease_buf(void *buf, unsigned int *epoch)
1364 struct create_lease *lc = (struct create_lease *)buf;
1366 *epoch = 0; /* not used */
1367 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
1368 return SMB2_OPLOCK_LEVEL_NOCHANGE;
1369 return le32_to_cpu(lc->lcontext.LeaseState);
1373 smb3_parse_lease_buf(void *buf, unsigned int *epoch)
1375 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
1377 *epoch = le16_to_cpu(lc->lcontext.Epoch);
1378 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
1379 return SMB2_OPLOCK_LEVEL_NOCHANGE;
1380 return le32_to_cpu(lc->lcontext.LeaseState);
1384 smb2_wp_retry_size(struct inode *inode)
1386 return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
1387 SMB2_MAX_BUFFER_SIZE);
1391 smb2_dir_needs_close(struct cifsFileInfo *cfile)
1393 return !cfile->invalidHandle;
1396 struct smb_version_operations smb20_operations = {
1397 .compare_fids = smb2_compare_fids,
1398 .setup_request = smb2_setup_request,
1399 .setup_async_request = smb2_setup_async_request,
1400 .check_receive = smb2_check_receive,
1401 .add_credits = smb2_add_credits,
1402 .set_credits = smb2_set_credits,
1403 .get_credits_field = smb2_get_credits_field,
1404 .get_credits = smb2_get_credits,
1405 .wait_mtu_credits = cifs_wait_mtu_credits,
1406 .get_next_mid = smb2_get_next_mid,
1407 .read_data_offset = smb2_read_data_offset,
1408 .read_data_length = smb2_read_data_length,
1409 .map_error = map_smb2_to_linux_error,
1410 .find_mid = smb2_find_mid,
1411 .check_message = smb2_check_message,
1412 .dump_detail = smb2_dump_detail,
1413 .clear_stats = smb2_clear_stats,
1414 .print_stats = smb2_print_stats,
1415 .is_oplock_break = smb2_is_valid_oplock_break,
1416 .downgrade_oplock = smb2_downgrade_oplock,
1417 .need_neg = smb2_need_neg,
1418 .negotiate = smb2_negotiate,
1419 .negotiate_wsize = smb2_negotiate_wsize,
1420 .negotiate_rsize = smb2_negotiate_rsize,
1421 .sess_setup = SMB2_sess_setup,
1422 .logoff = SMB2_logoff,
1423 .tree_connect = SMB2_tcon,
1424 .tree_disconnect = SMB2_tdis,
1425 .qfs_tcon = smb2_qfs_tcon,
1426 .is_path_accessible = smb2_is_path_accessible,
1427 .can_echo = smb2_can_echo,
1429 .query_path_info = smb2_query_path_info,
1430 .get_srv_inum = smb2_get_srv_inum,
1431 .query_file_info = smb2_query_file_info,
1432 .set_path_size = smb2_set_path_size,
1433 .set_file_size = smb2_set_file_size,
1434 .set_file_info = smb2_set_file_info,
1435 .set_compression = smb2_set_compression,
1436 .mkdir = smb2_mkdir,
1437 .mkdir_setinfo = smb2_mkdir_setinfo,
1438 .rmdir = smb2_rmdir,
1439 .unlink = smb2_unlink,
1440 .rename = smb2_rename_path,
1441 .create_hardlink = smb2_create_hardlink,
1442 .query_symlink = smb2_query_symlink,
1443 .open = smb2_open_file,
1444 .set_fid = smb2_set_fid,
1445 .close = smb2_close_file,
1446 .flush = smb2_flush_file,
1447 .async_readv = smb2_async_readv,
1448 .async_writev = smb2_async_writev,
1449 .sync_read = smb2_sync_read,
1450 .sync_write = smb2_sync_write,
1451 .query_dir_first = smb2_query_dir_first,
1452 .query_dir_next = smb2_query_dir_next,
1453 .close_dir = smb2_close_dir,
1454 .calc_smb_size = smb2_calc_size,
1455 .is_status_pending = smb2_is_status_pending,
1456 .oplock_response = smb2_oplock_response,
1457 .queryfs = smb2_queryfs,
1458 .mand_lock = smb2_mand_lock,
1459 .mand_unlock_range = smb2_unlock_range,
1460 .push_mand_locks = smb2_push_mandatory_locks,
1461 .get_lease_key = smb2_get_lease_key,
1462 .set_lease_key = smb2_set_lease_key,
1463 .new_lease_key = smb2_new_lease_key,
1464 .calc_signature = smb2_calc_signature,
1465 .is_read_op = smb2_is_read_op,
1466 .set_oplock_level = smb2_set_oplock_level,
1467 .create_lease_buf = smb2_create_lease_buf,
1468 .parse_lease_buf = smb2_parse_lease_buf,
1469 .clone_range = smb2_clone_range,
1470 .wp_retry_size = smb2_wp_retry_size,
1471 .dir_needs_close = smb2_dir_needs_close,
1474 struct smb_version_operations smb21_operations = {
1475 .compare_fids = smb2_compare_fids,
1476 .setup_request = smb2_setup_request,
1477 .setup_async_request = smb2_setup_async_request,
1478 .check_receive = smb2_check_receive,
1479 .add_credits = smb2_add_credits,
1480 .set_credits = smb2_set_credits,
1481 .get_credits_field = smb2_get_credits_field,
1482 .get_credits = smb2_get_credits,
1483 .wait_mtu_credits = smb2_wait_mtu_credits,
1484 .get_next_mid = smb2_get_next_mid,
1485 .read_data_offset = smb2_read_data_offset,
1486 .read_data_length = smb2_read_data_length,
1487 .map_error = map_smb2_to_linux_error,
1488 .find_mid = smb2_find_mid,
1489 .check_message = smb2_check_message,
1490 .dump_detail = smb2_dump_detail,
1491 .clear_stats = smb2_clear_stats,
1492 .print_stats = smb2_print_stats,
1493 .is_oplock_break = smb2_is_valid_oplock_break,
1494 .downgrade_oplock = smb2_downgrade_oplock,
1495 .need_neg = smb2_need_neg,
1496 .negotiate = smb2_negotiate,
1497 .negotiate_wsize = smb2_negotiate_wsize,
1498 .negotiate_rsize = smb2_negotiate_rsize,
1499 .sess_setup = SMB2_sess_setup,
1500 .logoff = SMB2_logoff,
1501 .tree_connect = SMB2_tcon,
1502 .tree_disconnect = SMB2_tdis,
1503 .qfs_tcon = smb2_qfs_tcon,
1504 .is_path_accessible = smb2_is_path_accessible,
1505 .can_echo = smb2_can_echo,
1507 .query_path_info = smb2_query_path_info,
1508 .get_srv_inum = smb2_get_srv_inum,
1509 .query_file_info = smb2_query_file_info,
1510 .set_path_size = smb2_set_path_size,
1511 .set_file_size = smb2_set_file_size,
1512 .set_file_info = smb2_set_file_info,
1513 .set_compression = smb2_set_compression,
1514 .mkdir = smb2_mkdir,
1515 .mkdir_setinfo = smb2_mkdir_setinfo,
1516 .rmdir = smb2_rmdir,
1517 .unlink = smb2_unlink,
1518 .rename = smb2_rename_path,
1519 .create_hardlink = smb2_create_hardlink,
1520 .query_symlink = smb2_query_symlink,
1521 .query_mf_symlink = smb3_query_mf_symlink,
1522 .create_mf_symlink = smb3_create_mf_symlink,
1523 .open = smb2_open_file,
1524 .set_fid = smb2_set_fid,
1525 .close = smb2_close_file,
1526 .flush = smb2_flush_file,
1527 .async_readv = smb2_async_readv,
1528 .async_writev = smb2_async_writev,
1529 .sync_read = smb2_sync_read,
1530 .sync_write = smb2_sync_write,
1531 .query_dir_first = smb2_query_dir_first,
1532 .query_dir_next = smb2_query_dir_next,
1533 .close_dir = smb2_close_dir,
1534 .calc_smb_size = smb2_calc_size,
1535 .is_status_pending = smb2_is_status_pending,
1536 .oplock_response = smb2_oplock_response,
1537 .queryfs = smb2_queryfs,
1538 .mand_lock = smb2_mand_lock,
1539 .mand_unlock_range = smb2_unlock_range,
1540 .push_mand_locks = smb2_push_mandatory_locks,
1541 .get_lease_key = smb2_get_lease_key,
1542 .set_lease_key = smb2_set_lease_key,
1543 .new_lease_key = smb2_new_lease_key,
1544 .calc_signature = smb2_calc_signature,
1545 .is_read_op = smb21_is_read_op,
1546 .set_oplock_level = smb21_set_oplock_level,
1547 .create_lease_buf = smb2_create_lease_buf,
1548 .parse_lease_buf = smb2_parse_lease_buf,
1549 .clone_range = smb2_clone_range,
1550 .wp_retry_size = smb2_wp_retry_size,
1551 .dir_needs_close = smb2_dir_needs_close,
1554 struct smb_version_operations smb30_operations = {
1555 .compare_fids = smb2_compare_fids,
1556 .setup_request = smb2_setup_request,
1557 .setup_async_request = smb2_setup_async_request,
1558 .check_receive = smb2_check_receive,
1559 .add_credits = smb2_add_credits,
1560 .set_credits = smb2_set_credits,
1561 .get_credits_field = smb2_get_credits_field,
1562 .get_credits = smb2_get_credits,
1563 .wait_mtu_credits = smb2_wait_mtu_credits,
1564 .get_next_mid = smb2_get_next_mid,
1565 .read_data_offset = smb2_read_data_offset,
1566 .read_data_length = smb2_read_data_length,
1567 .map_error = map_smb2_to_linux_error,
1568 .find_mid = smb2_find_mid,
1569 .check_message = smb2_check_message,
1570 .dump_detail = smb2_dump_detail,
1571 .clear_stats = smb2_clear_stats,
1572 .print_stats = smb2_print_stats,
1573 .dump_share_caps = smb2_dump_share_caps,
1574 .is_oplock_break = smb2_is_valid_oplock_break,
1575 .downgrade_oplock = smb2_downgrade_oplock,
1576 .need_neg = smb2_need_neg,
1577 .negotiate = smb2_negotiate,
1578 .negotiate_wsize = smb2_negotiate_wsize,
1579 .negotiate_rsize = smb2_negotiate_rsize,
1580 .sess_setup = SMB2_sess_setup,
1581 .logoff = SMB2_logoff,
1582 .tree_connect = SMB2_tcon,
1583 .tree_disconnect = SMB2_tdis,
1584 .qfs_tcon = smb3_qfs_tcon,
1585 .is_path_accessible = smb2_is_path_accessible,
1586 .can_echo = smb2_can_echo,
1588 .query_path_info = smb2_query_path_info,
1589 .get_srv_inum = smb2_get_srv_inum,
1590 .query_file_info = smb2_query_file_info,
1591 .set_path_size = smb2_set_path_size,
1592 .set_file_size = smb2_set_file_size,
1593 .set_file_info = smb2_set_file_info,
1594 .set_compression = smb2_set_compression,
1595 .mkdir = smb2_mkdir,
1596 .mkdir_setinfo = smb2_mkdir_setinfo,
1597 .rmdir = smb2_rmdir,
1598 .unlink = smb2_unlink,
1599 .rename = smb2_rename_path,
1600 .create_hardlink = smb2_create_hardlink,
1601 .query_symlink = smb2_query_symlink,
1602 .query_mf_symlink = smb3_query_mf_symlink,
1603 .create_mf_symlink = smb3_create_mf_symlink,
1604 .open = smb2_open_file,
1605 .set_fid = smb2_set_fid,
1606 .close = smb2_close_file,
1607 .flush = smb2_flush_file,
1608 .async_readv = smb2_async_readv,
1609 .async_writev = smb2_async_writev,
1610 .sync_read = smb2_sync_read,
1611 .sync_write = smb2_sync_write,
1612 .query_dir_first = smb2_query_dir_first,
1613 .query_dir_next = smb2_query_dir_next,
1614 .close_dir = smb2_close_dir,
1615 .calc_smb_size = smb2_calc_size,
1616 .is_status_pending = smb2_is_status_pending,
1617 .oplock_response = smb2_oplock_response,
1618 .queryfs = smb2_queryfs,
1619 .mand_lock = smb2_mand_lock,
1620 .mand_unlock_range = smb2_unlock_range,
1621 .push_mand_locks = smb2_push_mandatory_locks,
1622 .get_lease_key = smb2_get_lease_key,
1623 .set_lease_key = smb2_set_lease_key,
1624 .new_lease_key = smb2_new_lease_key,
1625 .generate_signingkey = generate_smb3signingkey,
1626 .calc_signature = smb3_calc_signature,
1627 .is_read_op = smb21_is_read_op,
1628 .set_oplock_level = smb3_set_oplock_level,
1629 .create_lease_buf = smb3_create_lease_buf,
1630 .parse_lease_buf = smb3_parse_lease_buf,
1631 .clone_range = smb2_clone_range,
1632 .validate_negotiate = smb3_validate_negotiate,
1633 .wp_retry_size = smb2_wp_retry_size,
1634 .dir_needs_close = smb2_dir_needs_close,
1635 .fallocate = smb3_fallocate,
1638 struct smb_version_values smb20_values = {
1639 .version_string = SMB20_VERSION_STRING,
1640 .protocol_id = SMB20_PROT_ID,
1641 .req_capabilities = 0, /* MBZ */
1642 .large_lock_type = 0,
1643 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1644 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1645 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1646 .header_size = sizeof(struct smb2_hdr),
1647 .max_header_size = MAX_SMB2_HDR_SIZE,
1648 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1649 .lock_cmd = SMB2_LOCK,
1651 .cap_nt_find = SMB2_NT_FIND,
1652 .cap_large_files = SMB2_LARGE_FILES,
1653 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1654 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
1655 .create_lease_size = sizeof(struct create_lease),
1658 struct smb_version_values smb21_values = {
1659 .version_string = SMB21_VERSION_STRING,
1660 .protocol_id = SMB21_PROT_ID,
1661 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
1662 .large_lock_type = 0,
1663 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1664 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1665 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1666 .header_size = sizeof(struct smb2_hdr),
1667 .max_header_size = MAX_SMB2_HDR_SIZE,
1668 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1669 .lock_cmd = SMB2_LOCK,
1671 .cap_nt_find = SMB2_NT_FIND,
1672 .cap_large_files = SMB2_LARGE_FILES,
1673 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1674 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
1675 .create_lease_size = sizeof(struct create_lease),
1678 struct smb_version_values smb30_values = {
1679 .version_string = SMB30_VERSION_STRING,
1680 .protocol_id = SMB30_PROT_ID,
1681 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
1682 .large_lock_type = 0,
1683 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1684 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1685 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1686 .header_size = sizeof(struct smb2_hdr),
1687 .max_header_size = MAX_SMB2_HDR_SIZE,
1688 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1689 .lock_cmd = SMB2_LOCK,
1691 .cap_nt_find = SMB2_NT_FIND,
1692 .cap_large_files = SMB2_LARGE_FILES,
1693 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1694 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
1695 .create_lease_size = sizeof(struct create_lease_v2),
1698 struct smb_version_values smb302_values = {
1699 .version_string = SMB302_VERSION_STRING,
1700 .protocol_id = SMB302_PROT_ID,
1701 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
1702 .large_lock_type = 0,
1703 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1704 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1705 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1706 .header_size = sizeof(struct smb2_hdr),
1707 .max_header_size = MAX_SMB2_HDR_SIZE,
1708 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1709 .lock_cmd = SMB2_LOCK,
1711 .cap_nt_find = SMB2_NT_FIND,
1712 .cap_large_files = SMB2_LARGE_FILES,
1713 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1714 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
1715 .create_lease_size = sizeof(struct create_lease_v2),