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;
54 server
->oplocks
= true;
55 server
->oplock_credits
= 1;
57 server
->oplocks
= false;
59 server
->echo_credits
= 1;
61 server
->credits
-= server
->echo_credits
+ server
->oplock_credits
;
66 smb2_add_credits(struct TCP_Server_Info
*server
, const unsigned int add
,
70 spin_lock(&server
->req_lock
);
71 val
= server
->ops
->get_credits_field(server
, optype
);
74 if (server
->in_flight
== 0 && (optype
& CIFS_OP_MASK
) != CIFS_NEG_OP
)
75 rc
= change_conf(server
);
77 * Sometimes server returns 0 credits on oplock break ack - we need to
78 * rebalance credits in this case.
80 else if (server
->in_flight
> 0 && server
->oplock_credits
== 0 &&
82 if (server
->credits
> 1) {
84 server
->oplock_credits
++;
87 spin_unlock(&server
->req_lock
);
88 wake_up(&server
->request_q
);
90 cifs_reconnect(server
);
94 smb2_set_credits(struct TCP_Server_Info
*server
, const int val
)
96 spin_lock(&server
->req_lock
);
97 server
->credits
= val
;
98 spin_unlock(&server
->req_lock
);
102 smb2_get_credits_field(struct TCP_Server_Info
*server
, const int optype
)
106 return &server
->echo_credits
;
108 return &server
->oplock_credits
;
110 return &server
->credits
;
115 smb2_get_credits(struct mid_q_entry
*mid
)
117 return le16_to_cpu(((struct smb2_hdr
*)mid
->resp_buf
)->CreditRequest
);
121 smb2_wait_mtu_credits(struct TCP_Server_Info
*server
, unsigned int size
,
122 unsigned int *num
, unsigned int *credits
)
125 unsigned int scredits
;
127 spin_lock(&server
->req_lock
);
129 if (server
->credits
<= 0) {
130 spin_unlock(&server
->req_lock
);
131 cifs_num_waiters_inc(server
);
132 rc
= wait_event_killable(server
->request_q
,
133 has_credits(server
, &server
->credits
));
134 cifs_num_waiters_dec(server
);
137 spin_lock(&server
->req_lock
);
139 if (server
->tcpStatus
== CifsExiting
) {
140 spin_unlock(&server
->req_lock
);
144 scredits
= server
->credits
;
145 /* can deadlock with reopen */
147 *num
= SMB2_MAX_BUFFER_SIZE
;
152 /* leave one credit for a possible reopen */
154 *num
= min_t(unsigned int, size
,
155 scredits
* SMB2_MAX_BUFFER_SIZE
);
157 *credits
= DIV_ROUND_UP(*num
, SMB2_MAX_BUFFER_SIZE
);
158 server
->credits
-= *credits
;
163 spin_unlock(&server
->req_lock
);
168 smb2_get_next_mid(struct TCP_Server_Info
*server
)
171 /* for SMB2 we need the current value */
172 spin_lock(&GlobalMid_Lock
);
173 mid
= server
->CurrentMid
++;
174 spin_unlock(&GlobalMid_Lock
);
178 static struct mid_q_entry
*
179 smb2_find_mid(struct TCP_Server_Info
*server
, char *buf
)
181 struct mid_q_entry
*mid
;
182 struct smb2_hdr
*hdr
= (struct smb2_hdr
*)buf
;
183 __u64 wire_mid
= le64_to_cpu(hdr
->MessageId
);
185 spin_lock(&GlobalMid_Lock
);
186 list_for_each_entry(mid
, &server
->pending_mid_q
, qhead
) {
187 if ((mid
->mid
== wire_mid
) &&
188 (mid
->mid_state
== MID_REQUEST_SUBMITTED
) &&
189 (mid
->command
== hdr
->Command
)) {
190 spin_unlock(&GlobalMid_Lock
);
194 spin_unlock(&GlobalMid_Lock
);
199 smb2_dump_detail(void *buf
)
201 #ifdef CONFIG_CIFS_DEBUG2
202 struct smb2_hdr
*smb
= (struct smb2_hdr
*)buf
;
204 cifs_dbg(VFS
, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
205 smb
->Command
, smb
->Status
, smb
->Flags
, smb
->MessageId
,
207 cifs_dbg(VFS
, "smb buf %p len %u\n", smb
, smb2_calc_size(smb
));
212 smb2_need_neg(struct TCP_Server_Info
*server
)
214 return server
->max_read
== 0;
218 smb2_negotiate(const unsigned int xid
, struct cifs_ses
*ses
)
221 ses
->server
->CurrentMid
= 0;
222 rc
= SMB2_negotiate(xid
, ses
);
223 /* BB we probably don't need to retry with modern servers */
230 smb2_negotiate_wsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
232 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
235 /* start with specified wsize, or default */
236 wsize
= volume_info
->wsize
? volume_info
->wsize
: CIFS_DEFAULT_IOSIZE
;
237 wsize
= min_t(unsigned int, wsize
, server
->max_write
);
239 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
240 wsize
= min_t(unsigned int, wsize
, SMB2_MAX_BUFFER_SIZE
);
246 smb2_negotiate_rsize(struct cifs_tcon
*tcon
, struct smb_vol
*volume_info
)
248 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
251 /* start with specified rsize, or default */
252 rsize
= volume_info
->rsize
? volume_info
->rsize
: CIFS_DEFAULT_IOSIZE
;
253 rsize
= min_t(unsigned int, rsize
, server
->max_read
);
255 if (!(server
->capabilities
& SMB2_GLOBAL_CAP_LARGE_MTU
))
256 rsize
= min_t(unsigned int, rsize
, SMB2_MAX_BUFFER_SIZE
);
261 #ifdef CONFIG_CIFS_STATS2
263 SMB3_request_interfaces(const unsigned int xid
, struct cifs_tcon
*tcon
)
266 unsigned int ret_data_len
= 0;
267 struct network_interface_info_ioctl_rsp
*out_buf
;
269 rc
= SMB2_ioctl(xid
, tcon
, NO_FILE_ID
, NO_FILE_ID
,
270 FSCTL_QUERY_NETWORK_INTERFACE_INFO
, true /* is_fsctl */,
271 NULL
/* no data input */, 0 /* no data input */,
272 (char **)&out_buf
, &ret_data_len
);
274 cifs_dbg(VFS
, "error %d on ioctl to get interface list\n", rc
);
275 else if (ret_data_len
< sizeof(struct network_interface_info_ioctl_rsp
)) {
276 cifs_dbg(VFS
, "server returned bad net interface info buf\n");
279 /* Dump info on first interface */
280 cifs_dbg(FYI
, "Adapter Capability 0x%x\t",
281 le32_to_cpu(out_buf
->Capability
));
282 cifs_dbg(FYI
, "Link Speed %lld\n",
283 le64_to_cpu(out_buf
->LinkSpeed
));
291 smb3_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
294 __le16 srch_path
= 0; /* Null - open root of share */
295 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
296 struct cifs_open_parms oparms
;
300 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
301 oparms
.disposition
= FILE_OPEN
;
302 oparms
.create_options
= 0;
304 oparms
.reconnect
= false;
306 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
310 #ifdef CONFIG_CIFS_STATS2
311 SMB3_request_interfaces(xid
, tcon
);
314 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
315 FS_ATTRIBUTE_INFORMATION
);
316 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
317 FS_DEVICE_INFORMATION
);
318 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
319 FS_SECTOR_SIZE_INFORMATION
); /* SMB3 specific */
320 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
325 smb2_qfs_tcon(const unsigned int xid
, struct cifs_tcon
*tcon
)
328 __le16 srch_path
= 0; /* Null - open root of share */
329 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
330 struct cifs_open_parms oparms
;
334 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
335 oparms
.disposition
= FILE_OPEN
;
336 oparms
.create_options
= 0;
338 oparms
.reconnect
= false;
340 rc
= SMB2_open(xid
, &oparms
, &srch_path
, &oplock
, NULL
, NULL
);
344 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
345 FS_ATTRIBUTE_INFORMATION
);
346 SMB2_QFS_attr(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
347 FS_DEVICE_INFORMATION
);
348 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
353 smb2_is_path_accessible(const unsigned int xid
, struct cifs_tcon
*tcon
,
354 struct cifs_sb_info
*cifs_sb
, const char *full_path
)
358 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
359 struct cifs_open_parms oparms
;
362 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
367 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
368 oparms
.disposition
= FILE_OPEN
;
369 oparms
.create_options
= 0;
371 oparms
.reconnect
= false;
373 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
379 rc
= SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
385 smb2_get_srv_inum(const unsigned int xid
, struct cifs_tcon
*tcon
,
386 struct cifs_sb_info
*cifs_sb
, const char *full_path
,
387 u64
*uniqueid
, FILE_ALL_INFO
*data
)
389 *uniqueid
= le64_to_cpu(data
->IndexNumber
);
394 smb2_query_file_info(const unsigned int xid
, struct cifs_tcon
*tcon
,
395 struct cifs_fid
*fid
, FILE_ALL_INFO
*data
)
398 struct smb2_file_all_info
*smb2_data
;
400 smb2_data
= kzalloc(sizeof(struct smb2_file_all_info
) + PATH_MAX
* 2,
402 if (smb2_data
== NULL
)
405 rc
= SMB2_query_info(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
,
408 move_smb2_info_to_cifs(data
, smb2_data
);
414 smb2_can_echo(struct TCP_Server_Info
*server
)
416 return server
->echoes
;
420 smb2_clear_stats(struct cifs_tcon
*tcon
)
422 #ifdef CONFIG_CIFS_STATS
424 for (i
= 0; i
< NUMBER_OF_SMB2_COMMANDS
; i
++) {
425 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_sent
[i
], 0);
426 atomic_set(&tcon
->stats
.smb2_stats
.smb2_com_failed
[i
], 0);
432 smb2_dump_share_caps(struct seq_file
*m
, struct cifs_tcon
*tcon
)
434 seq_puts(m
, "\n\tShare Capabilities:");
435 if (tcon
->capabilities
& SMB2_SHARE_CAP_DFS
)
436 seq_puts(m
, " DFS,");
437 if (tcon
->capabilities
& SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY
)
438 seq_puts(m
, " CONTINUOUS AVAILABILITY,");
439 if (tcon
->capabilities
& SMB2_SHARE_CAP_SCALEOUT
)
440 seq_puts(m
, " SCALEOUT,");
441 if (tcon
->capabilities
& SMB2_SHARE_CAP_CLUSTER
)
442 seq_puts(m
, " CLUSTER,");
443 if (tcon
->capabilities
& SMB2_SHARE_CAP_ASYMMETRIC
)
444 seq_puts(m
, " ASYMMETRIC,");
445 if (tcon
->capabilities
== 0)
446 seq_puts(m
, " None");
447 if (tcon
->ss_flags
& SSINFO_FLAGS_ALIGNED_DEVICE
)
448 seq_puts(m
, " Aligned,");
449 if (tcon
->ss_flags
& SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE
)
450 seq_puts(m
, " Partition Aligned,");
451 if (tcon
->ss_flags
& SSINFO_FLAGS_NO_SEEK_PENALTY
)
452 seq_puts(m
, " SSD,");
453 if (tcon
->ss_flags
& SSINFO_FLAGS_TRIM_ENABLED
)
454 seq_puts(m
, " TRIM-support,");
456 seq_printf(m
, "\tShare Flags: 0x%x", tcon
->share_flags
);
457 if (tcon
->perf_sector_size
)
458 seq_printf(m
, "\tOptimal sector size: 0x%x",
459 tcon
->perf_sector_size
);
463 smb2_print_stats(struct seq_file
*m
, struct cifs_tcon
*tcon
)
465 #ifdef CONFIG_CIFS_STATS
466 atomic_t
*sent
= tcon
->stats
.smb2_stats
.smb2_com_sent
;
467 atomic_t
*failed
= tcon
->stats
.smb2_stats
.smb2_com_failed
;
468 seq_printf(m
, "\nNegotiates: %d sent %d failed",
469 atomic_read(&sent
[SMB2_NEGOTIATE_HE
]),
470 atomic_read(&failed
[SMB2_NEGOTIATE_HE
]));
471 seq_printf(m
, "\nSessionSetups: %d sent %d failed",
472 atomic_read(&sent
[SMB2_SESSION_SETUP_HE
]),
473 atomic_read(&failed
[SMB2_SESSION_SETUP_HE
]));
474 seq_printf(m
, "\nLogoffs: %d sent %d failed",
475 atomic_read(&sent
[SMB2_LOGOFF_HE
]),
476 atomic_read(&failed
[SMB2_LOGOFF_HE
]));
477 seq_printf(m
, "\nTreeConnects: %d sent %d failed",
478 atomic_read(&sent
[SMB2_TREE_CONNECT_HE
]),
479 atomic_read(&failed
[SMB2_TREE_CONNECT_HE
]));
480 seq_printf(m
, "\nTreeDisconnects: %d sent %d failed",
481 atomic_read(&sent
[SMB2_TREE_DISCONNECT_HE
]),
482 atomic_read(&failed
[SMB2_TREE_DISCONNECT_HE
]));
483 seq_printf(m
, "\nCreates: %d sent %d failed",
484 atomic_read(&sent
[SMB2_CREATE_HE
]),
485 atomic_read(&failed
[SMB2_CREATE_HE
]));
486 seq_printf(m
, "\nCloses: %d sent %d failed",
487 atomic_read(&sent
[SMB2_CLOSE_HE
]),
488 atomic_read(&failed
[SMB2_CLOSE_HE
]));
489 seq_printf(m
, "\nFlushes: %d sent %d failed",
490 atomic_read(&sent
[SMB2_FLUSH_HE
]),
491 atomic_read(&failed
[SMB2_FLUSH_HE
]));
492 seq_printf(m
, "\nReads: %d sent %d failed",
493 atomic_read(&sent
[SMB2_READ_HE
]),
494 atomic_read(&failed
[SMB2_READ_HE
]));
495 seq_printf(m
, "\nWrites: %d sent %d failed",
496 atomic_read(&sent
[SMB2_WRITE_HE
]),
497 atomic_read(&failed
[SMB2_WRITE_HE
]));
498 seq_printf(m
, "\nLocks: %d sent %d failed",
499 atomic_read(&sent
[SMB2_LOCK_HE
]),
500 atomic_read(&failed
[SMB2_LOCK_HE
]));
501 seq_printf(m
, "\nIOCTLs: %d sent %d failed",
502 atomic_read(&sent
[SMB2_IOCTL_HE
]),
503 atomic_read(&failed
[SMB2_IOCTL_HE
]));
504 seq_printf(m
, "\nCancels: %d sent %d failed",
505 atomic_read(&sent
[SMB2_CANCEL_HE
]),
506 atomic_read(&failed
[SMB2_CANCEL_HE
]));
507 seq_printf(m
, "\nEchos: %d sent %d failed",
508 atomic_read(&sent
[SMB2_ECHO_HE
]),
509 atomic_read(&failed
[SMB2_ECHO_HE
]));
510 seq_printf(m
, "\nQueryDirectories: %d sent %d failed",
511 atomic_read(&sent
[SMB2_QUERY_DIRECTORY_HE
]),
512 atomic_read(&failed
[SMB2_QUERY_DIRECTORY_HE
]));
513 seq_printf(m
, "\nChangeNotifies: %d sent %d failed",
514 atomic_read(&sent
[SMB2_CHANGE_NOTIFY_HE
]),
515 atomic_read(&failed
[SMB2_CHANGE_NOTIFY_HE
]));
516 seq_printf(m
, "\nQueryInfos: %d sent %d failed",
517 atomic_read(&sent
[SMB2_QUERY_INFO_HE
]),
518 atomic_read(&failed
[SMB2_QUERY_INFO_HE
]));
519 seq_printf(m
, "\nSetInfos: %d sent %d failed",
520 atomic_read(&sent
[SMB2_SET_INFO_HE
]),
521 atomic_read(&failed
[SMB2_SET_INFO_HE
]));
522 seq_printf(m
, "\nOplockBreaks: %d sent %d failed",
523 atomic_read(&sent
[SMB2_OPLOCK_BREAK_HE
]),
524 atomic_read(&failed
[SMB2_OPLOCK_BREAK_HE
]));
529 smb2_set_fid(struct cifsFileInfo
*cfile
, struct cifs_fid
*fid
, __u32 oplock
)
531 struct cifsInodeInfo
*cinode
= CIFS_I(d_inode(cfile
->dentry
));
532 struct TCP_Server_Info
*server
= tlink_tcon(cfile
->tlink
)->ses
->server
;
534 cfile
->fid
.persistent_fid
= fid
->persistent_fid
;
535 cfile
->fid
.volatile_fid
= fid
->volatile_fid
;
536 server
->ops
->set_oplock_level(cinode
, oplock
, fid
->epoch
,
538 cinode
->can_cache_brlcks
= CIFS_CACHE_WRITE(cinode
);
542 smb2_close_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
543 struct cifs_fid
*fid
)
545 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
549 SMB2_request_res_key(const unsigned int xid
, struct cifs_tcon
*tcon
,
550 u64 persistent_fid
, u64 volatile_fid
,
551 struct copychunk_ioctl
*pcchunk
)
554 unsigned int ret_data_len
;
555 struct resume_key_req
*res_key
;
557 rc
= SMB2_ioctl(xid
, tcon
, persistent_fid
, volatile_fid
,
558 FSCTL_SRV_REQUEST_RESUME_KEY
, true /* is_fsctl */,
559 NULL
, 0 /* no input */,
560 (char **)&res_key
, &ret_data_len
);
563 cifs_dbg(VFS
, "refcpy ioctl error %d getting resume key\n", rc
);
564 goto req_res_key_exit
;
566 if (ret_data_len
< sizeof(struct resume_key_req
)) {
567 cifs_dbg(VFS
, "Invalid refcopy resume key length\n");
569 goto req_res_key_exit
;
571 memcpy(pcchunk
->SourceKey
, res_key
->ResumeKey
, COPY_CHUNK_RES_KEY_SIZE
);
579 smb2_clone_range(const unsigned int xid
,
580 struct cifsFileInfo
*srcfile
,
581 struct cifsFileInfo
*trgtfile
, u64 src_off
,
582 u64 len
, u64 dest_off
)
585 unsigned int ret_data_len
;
586 struct copychunk_ioctl
*pcchunk
;
587 struct copychunk_ioctl_rsp
*retbuf
= NULL
;
588 struct cifs_tcon
*tcon
;
589 int chunks_copied
= 0;
590 bool chunk_sizes_updated
= false;
592 pcchunk
= kmalloc(sizeof(struct copychunk_ioctl
), GFP_KERNEL
);
597 cifs_dbg(FYI
, "in smb2_clone_range - about to call request res key\n");
598 /* Request a key from the server to identify the source of the copy */
599 rc
= SMB2_request_res_key(xid
, tlink_tcon(srcfile
->tlink
),
600 srcfile
->fid
.persistent_fid
,
601 srcfile
->fid
.volatile_fid
, pcchunk
);
603 /* Note: request_res_key sets res_key null only if rc !=0 */
607 /* For now array only one chunk long, will make more flexible later */
608 pcchunk
->ChunkCount
= cpu_to_le32(1);
609 pcchunk
->Reserved
= 0;
610 pcchunk
->Reserved2
= 0;
612 tcon
= tlink_tcon(trgtfile
->tlink
);
615 pcchunk
->SourceOffset
= cpu_to_le64(src_off
);
616 pcchunk
->TargetOffset
= cpu_to_le64(dest_off
);
618 cpu_to_le32(min_t(u32
, len
, tcon
->max_bytes_chunk
));
620 /* Request server copy to target from src identified by key */
621 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
622 trgtfile
->fid
.volatile_fid
, FSCTL_SRV_COPYCHUNK_WRITE
,
623 true /* is_fsctl */, (char *)pcchunk
,
624 sizeof(struct copychunk_ioctl
), (char **)&retbuf
,
628 sizeof(struct copychunk_ioctl_rsp
)) {
629 cifs_dbg(VFS
, "invalid cchunk response size\n");
633 if (retbuf
->TotalBytesWritten
== 0) {
634 cifs_dbg(FYI
, "no bytes copied\n");
639 * Check if server claimed to write more than we asked
641 if (le32_to_cpu(retbuf
->TotalBytesWritten
) >
642 le32_to_cpu(pcchunk
->Length
)) {
643 cifs_dbg(VFS
, "invalid copy chunk response\n");
647 if (le32_to_cpu(retbuf
->ChunksWritten
) != 1) {
648 cifs_dbg(VFS
, "invalid num chunks written\n");
654 src_off
+= le32_to_cpu(retbuf
->TotalBytesWritten
);
655 dest_off
+= le32_to_cpu(retbuf
->TotalBytesWritten
);
656 len
-= le32_to_cpu(retbuf
->TotalBytesWritten
);
658 cifs_dbg(FYI
, "Chunks %d PartialChunk %d Total %d\n",
659 le32_to_cpu(retbuf
->ChunksWritten
),
660 le32_to_cpu(retbuf
->ChunkBytesWritten
),
661 le32_to_cpu(retbuf
->TotalBytesWritten
));
662 } else if (rc
== -EINVAL
) {
663 if (ret_data_len
!= sizeof(struct copychunk_ioctl_rsp
))
666 cifs_dbg(FYI
, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
667 le32_to_cpu(retbuf
->ChunksWritten
),
668 le32_to_cpu(retbuf
->ChunkBytesWritten
),
669 le32_to_cpu(retbuf
->TotalBytesWritten
));
672 * Check if this is the first request using these sizes,
673 * (ie check if copy succeed once with original sizes
674 * and check if the server gave us different sizes after
675 * we already updated max sizes on previous request).
676 * if not then why is the server returning an error now
678 if ((chunks_copied
!= 0) || chunk_sizes_updated
)
681 /* Check that server is not asking us to grow size */
682 if (le32_to_cpu(retbuf
->ChunkBytesWritten
) <
683 tcon
->max_bytes_chunk
)
684 tcon
->max_bytes_chunk
=
685 le32_to_cpu(retbuf
->ChunkBytesWritten
);
687 goto cchunk_out
; /* server gave us bogus size */
689 /* No need to change MaxChunks since already set to 1 */
690 chunk_sizes_updated
= true;
701 smb2_flush_file(const unsigned int xid
, struct cifs_tcon
*tcon
,
702 struct cifs_fid
*fid
)
704 return SMB2_flush(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
708 smb2_read_data_offset(char *buf
)
710 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
711 return rsp
->DataOffset
;
715 smb2_read_data_length(char *buf
)
717 struct smb2_read_rsp
*rsp
= (struct smb2_read_rsp
*)buf
;
718 return le32_to_cpu(rsp
->DataLength
);
723 smb2_sync_read(const unsigned int xid
, struct cifs_fid
*pfid
,
724 struct cifs_io_parms
*parms
, unsigned int *bytes_read
,
725 char **buf
, int *buf_type
)
727 parms
->persistent_fid
= pfid
->persistent_fid
;
728 parms
->volatile_fid
= pfid
->volatile_fid
;
729 return SMB2_read(xid
, parms
, bytes_read
, buf
, buf_type
);
733 smb2_sync_write(const unsigned int xid
, struct cifs_fid
*pfid
,
734 struct cifs_io_parms
*parms
, unsigned int *written
,
735 struct kvec
*iov
, unsigned long nr_segs
)
738 parms
->persistent_fid
= pfid
->persistent_fid
;
739 parms
->volatile_fid
= pfid
->volatile_fid
;
740 return SMB2_write(xid
, parms
, written
, iov
, nr_segs
);
743 /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
744 static bool smb2_set_sparse(const unsigned int xid
, struct cifs_tcon
*tcon
,
745 struct cifsFileInfo
*cfile
, struct inode
*inode
, __u8 setsparse
)
747 struct cifsInodeInfo
*cifsi
;
750 cifsi
= CIFS_I(inode
);
752 /* if file already sparse don't bother setting sparse again */
753 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && setsparse
)
754 return true; /* already sparse */
756 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) && !setsparse
)
757 return true; /* already not sparse */
760 * Can't check for sparse support on share the usual way via the
761 * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
762 * since Samba server doesn't set the flag on the share, yet
763 * supports the set sparse FSCTL and returns sparse correctly
764 * in the file attributes. If we fail setting sparse though we
765 * mark that server does not support sparse files for this share
766 * to avoid repeatedly sending the unsupported fsctl to server
767 * if the file is repeatedly extended.
769 if (tcon
->broken_sparse_sup
)
772 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
773 cfile
->fid
.volatile_fid
, FSCTL_SET_SPARSE
,
774 true /* is_fctl */, &setsparse
, 1, NULL
, NULL
);
776 tcon
->broken_sparse_sup
= true;
777 cifs_dbg(FYI
, "set sparse rc = %d\n", rc
);
782 cifsi
->cifsAttrs
|= FILE_ATTRIBUTE_SPARSE_FILE
;
784 cifsi
->cifsAttrs
&= (~FILE_ATTRIBUTE_SPARSE_FILE
);
790 smb2_set_file_size(const unsigned int xid
, struct cifs_tcon
*tcon
,
791 struct cifsFileInfo
*cfile
, __u64 size
, bool set_alloc
)
793 __le64 eof
= cpu_to_le64(size
);
797 * If extending file more than one page make sparse. Many Linux fs
798 * make files sparse by default when extending via ftruncate
800 inode
= d_inode(cfile
->dentry
);
802 if (!set_alloc
&& (size
> inode
->i_size
+ 8192)) {
805 /* whether set sparse succeeds or not, extend the file */
806 smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
);
809 return SMB2_set_eof(xid
, tcon
, cfile
->fid
.persistent_fid
,
810 cfile
->fid
.volatile_fid
, cfile
->pid
, &eof
, false);
813 #ifdef CONFIG_CIFS_SMB311
815 smb2_duplicate_extents(const unsigned int xid
,
816 struct cifsFileInfo
*srcfile
,
817 struct cifsFileInfo
*trgtfile
, u64 src_off
,
818 u64 len
, u64 dest_off
)
821 unsigned int ret_data_len
;
823 struct duplicate_extents_to_file dup_ext_buf
;
824 struct cifs_tcon
*tcon
= tlink_tcon(trgtfile
->tlink
);
826 /* server fileays advertise duplicate extent support with this flag */
827 if ((le32_to_cpu(tcon
->fsAttrInfo
.Attributes
) &
828 FILE_SUPPORTS_BLOCK_REFCOUNTING
) == 0)
831 dup_ext_buf
.VolatileFileHandle
= srcfile
->fid
.volatile_fid
;
832 dup_ext_buf
.PersistentFileHandle
= srcfile
->fid
.persistent_fid
;
833 dup_ext_buf
.SourceFileOffset
= cpu_to_le64(src_off
);
834 dup_ext_buf
.TargetFileOffset
= cpu_to_le64(dest_off
);
835 dup_ext_buf
.ByteCount
= cpu_to_le64(len
);
836 cifs_dbg(FYI
, "duplicate extents: src off %lld dst off %lld len %lld",
837 src_off
, dest_off
, len
);
839 rc
= smb2_set_file_size(xid
, tcon
, trgtfile
, dest_off
+ len
, false);
841 goto duplicate_extents_out
;
843 rc
= SMB2_ioctl(xid
, tcon
, trgtfile
->fid
.persistent_fid
,
844 trgtfile
->fid
.volatile_fid
,
845 FSCTL_DUPLICATE_EXTENTS_TO_FILE
,
846 true /* is_fsctl */, (char *)&dup_ext_buf
,
847 sizeof(struct duplicate_extents_to_file
),
851 if (ret_data_len
> 0)
852 cifs_dbg(FYI
, "non-zero response length in duplicate extents");
854 duplicate_extents_out
:
857 #endif /* CONFIG_CIFS_SMB311 */
861 smb2_set_compression(const unsigned int xid
, struct cifs_tcon
*tcon
,
862 struct cifsFileInfo
*cfile
)
864 return SMB2_set_compression(xid
, tcon
, cfile
->fid
.persistent_fid
,
865 cfile
->fid
.volatile_fid
);
869 smb3_set_integrity(const unsigned int xid
, struct cifs_tcon
*tcon
,
870 struct cifsFileInfo
*cfile
)
872 struct fsctl_set_integrity_information_req integr_info
;
874 unsigned int ret_data_len
;
876 integr_info
.ChecksumAlgorithm
= cpu_to_le16(CHECKSUM_TYPE_UNCHANGED
);
877 integr_info
.Flags
= 0;
878 integr_info
.Reserved
= 0;
880 return SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
881 cfile
->fid
.volatile_fid
,
882 FSCTL_SET_INTEGRITY_INFORMATION
,
883 true /* is_fsctl */, (char *)&integr_info
,
884 sizeof(struct fsctl_set_integrity_information_req
),
891 smb2_query_dir_first(const unsigned int xid
, struct cifs_tcon
*tcon
,
892 const char *path
, struct cifs_sb_info
*cifs_sb
,
893 struct cifs_fid
*fid
, __u16 search_flags
,
894 struct cifs_search_info
*srch_inf
)
898 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
899 struct cifs_open_parms oparms
;
901 utf16_path
= cifs_convert_path_to_utf16(path
, cifs_sb
);
906 oparms
.desired_access
= FILE_READ_ATTRIBUTES
| FILE_READ_DATA
;
907 oparms
.disposition
= FILE_OPEN
;
908 oparms
.create_options
= 0;
910 oparms
.reconnect
= false;
912 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, NULL
);
915 cifs_dbg(VFS
, "open dir failed\n");
919 srch_inf
->entries_in_buffer
= 0;
920 srch_inf
->index_of_last_entry
= 0;
922 rc
= SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
923 fid
->volatile_fid
, 0, srch_inf
);
925 cifs_dbg(VFS
, "query directory failed\n");
926 SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
932 smb2_query_dir_next(const unsigned int xid
, struct cifs_tcon
*tcon
,
933 struct cifs_fid
*fid
, __u16 search_flags
,
934 struct cifs_search_info
*srch_inf
)
936 return SMB2_query_directory(xid
, tcon
, fid
->persistent_fid
,
937 fid
->volatile_fid
, 0, srch_inf
);
941 smb2_close_dir(const unsigned int xid
, struct cifs_tcon
*tcon
,
942 struct cifs_fid
*fid
)
944 return SMB2_close(xid
, tcon
, fid
->persistent_fid
, fid
->volatile_fid
);
948 * If we negotiate SMB2 protocol and get STATUS_PENDING - update
949 * the number of credits and return true. Otherwise - return false.
952 smb2_is_status_pending(char *buf
, struct TCP_Server_Info
*server
, int length
)
954 struct smb2_hdr
*hdr
= (struct smb2_hdr
*)buf
;
956 if (hdr
->Status
!= STATUS_PENDING
)
960 spin_lock(&server
->req_lock
);
961 server
->credits
+= le16_to_cpu(hdr
->CreditRequest
);
962 spin_unlock(&server
->req_lock
);
963 wake_up(&server
->request_q
);
970 smb2_oplock_response(struct cifs_tcon
*tcon
, struct cifs_fid
*fid
,
971 struct cifsInodeInfo
*cinode
)
973 if (tcon
->ses
->server
->capabilities
& SMB2_GLOBAL_CAP_LEASING
)
974 return SMB2_lease_break(0, tcon
, cinode
->lease_key
,
975 smb2_get_lease_state(cinode
));
977 return SMB2_oplock_break(0, tcon
, fid
->persistent_fid
,
979 CIFS_CACHE_READ(cinode
) ? 1 : 0);
983 smb2_queryfs(const unsigned int xid
, struct cifs_tcon
*tcon
,
987 __le16 srch_path
= 0; /* Null - open root of share */
988 u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
989 struct cifs_open_parms oparms
;
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
, &srch_path
, &oplock
, NULL
, NULL
);
1002 buf
->f_type
= SMB2_MAGIC_NUMBER
;
1003 rc
= SMB2_QFS_info(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
,
1005 SMB2_close(xid
, tcon
, fid
.persistent_fid
, fid
.volatile_fid
);
1010 smb2_compare_fids(struct cifsFileInfo
*ob1
, struct cifsFileInfo
*ob2
)
1012 return ob1
->fid
.persistent_fid
== ob2
->fid
.persistent_fid
&&
1013 ob1
->fid
.volatile_fid
== ob2
->fid
.volatile_fid
;
1017 smb2_mand_lock(const unsigned int xid
, struct cifsFileInfo
*cfile
, __u64 offset
,
1018 __u64 length
, __u32 type
, int lock
, int unlock
, bool wait
)
1020 if (unlock
&& !lock
)
1021 type
= SMB2_LOCKFLAG_UNLOCK
;
1022 return SMB2_lock(xid
, tlink_tcon(cfile
->tlink
),
1023 cfile
->fid
.persistent_fid
, cfile
->fid
.volatile_fid
,
1024 current
->tgid
, length
, offset
, type
, wait
);
1028 smb2_get_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
1030 memcpy(fid
->lease_key
, CIFS_I(inode
)->lease_key
, SMB2_LEASE_KEY_SIZE
);
1034 smb2_set_lease_key(struct inode
*inode
, struct cifs_fid
*fid
)
1036 memcpy(CIFS_I(inode
)->lease_key
, fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
1040 smb2_new_lease_key(struct cifs_fid
*fid
)
1042 get_random_bytes(fid
->lease_key
, SMB2_LEASE_KEY_SIZE
);
1046 smb2_query_symlink(const unsigned int xid
, struct cifs_tcon
*tcon
,
1047 const char *full_path
, char **target_path
,
1048 struct cifs_sb_info
*cifs_sb
)
1052 __u8 oplock
= SMB2_OPLOCK_LEVEL_NONE
;
1053 struct cifs_open_parms oparms
;
1054 struct cifs_fid fid
;
1055 struct smb2_err_rsp
*err_buf
= NULL
;
1056 struct smb2_symlink_err_rsp
*symlink
;
1057 unsigned int sub_len
, sub_offset
;
1059 cifs_dbg(FYI
, "%s: path: %s\n", __func__
, full_path
);
1061 utf16_path
= cifs_convert_path_to_utf16(full_path
, cifs_sb
);
1066 oparms
.desired_access
= FILE_READ_ATTRIBUTES
;
1067 oparms
.disposition
= FILE_OPEN
;
1068 oparms
.create_options
= 0;
1070 oparms
.reconnect
= false;
1072 rc
= SMB2_open(xid
, &oparms
, utf16_path
, &oplock
, NULL
, &err_buf
);
1074 if (!rc
|| !err_buf
) {
1078 /* open must fail on symlink - reset rc */
1080 symlink
= (struct smb2_symlink_err_rsp
*)err_buf
->ErrorData
;
1081 sub_len
= le16_to_cpu(symlink
->SubstituteNameLength
);
1082 sub_offset
= le16_to_cpu(symlink
->SubstituteNameOffset
);
1083 *target_path
= cifs_strndup_from_utf16(
1084 (char *)symlink
->PathBuffer
+ sub_offset
,
1085 sub_len
, true, cifs_sb
->local_nls
);
1086 if (!(*target_path
)) {
1090 convert_delimiter(*target_path
, '/');
1091 cifs_dbg(FYI
, "%s: target path: %s\n", __func__
, *target_path
);
1096 static long smb3_zero_range(struct file
*file
, struct cifs_tcon
*tcon
,
1097 loff_t offset
, loff_t len
, bool keep_size
)
1099 struct inode
*inode
;
1100 struct cifsInodeInfo
*cifsi
;
1101 struct cifsFileInfo
*cfile
= file
->private_data
;
1102 struct file_zero_data_information fsctl_buf
;
1108 inode
= d_inode(cfile
->dentry
);
1109 cifsi
= CIFS_I(inode
);
1111 /* if file not oplocked can't be sure whether asking to extend size */
1112 if (!CIFS_CACHE_READ(cifsi
))
1113 if (keep_size
== false)
1117 * Must check if file sparse since fallocate -z (zero range) assumes
1118 * non-sparse allocation
1120 if (!(cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
))
1124 * need to make sure we are not asked to extend the file since the SMB3
1125 * fsctl does not change the file size. In the future we could change
1126 * this to zero the first part of the range then set the file size
1127 * which for a non sparse file would zero the newly extended range
1129 if (keep_size
== false)
1130 if (i_size_read(inode
) < offset
+ len
)
1133 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1135 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1136 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1138 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1139 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1140 true /* is_fctl */, (char *)&fsctl_buf
,
1141 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1146 static long smb3_punch_hole(struct file
*file
, struct cifs_tcon
*tcon
,
1147 loff_t offset
, loff_t len
)
1149 struct inode
*inode
;
1150 struct cifsInodeInfo
*cifsi
;
1151 struct cifsFileInfo
*cfile
= file
->private_data
;
1152 struct file_zero_data_information fsctl_buf
;
1155 __u8 set_sparse
= 1;
1159 inode
= d_inode(cfile
->dentry
);
1160 cifsi
= CIFS_I(inode
);
1162 /* Need to make file sparse, if not already, before freeing range. */
1163 /* Consider adding equivalent for compressed since it could also work */
1164 if (!smb2_set_sparse(xid
, tcon
, cfile
, inode
, set_sparse
))
1167 cifs_dbg(FYI
, "offset %lld len %lld", offset
, len
);
1169 fsctl_buf
.FileOffset
= cpu_to_le64(offset
);
1170 fsctl_buf
.BeyondFinalZero
= cpu_to_le64(offset
+ len
);
1172 rc
= SMB2_ioctl(xid
, tcon
, cfile
->fid
.persistent_fid
,
1173 cfile
->fid
.volatile_fid
, FSCTL_SET_ZERO_DATA
,
1174 true /* is_fctl */, (char *)&fsctl_buf
,
1175 sizeof(struct file_zero_data_information
), NULL
, NULL
);
1180 static long smb3_simple_falloc(struct file
*file
, struct cifs_tcon
*tcon
,
1181 loff_t off
, loff_t len
, bool keep_size
)
1183 struct inode
*inode
;
1184 struct cifsInodeInfo
*cifsi
;
1185 struct cifsFileInfo
*cfile
= file
->private_data
;
1186 long rc
= -EOPNOTSUPP
;
1191 inode
= d_inode(cfile
->dentry
);
1192 cifsi
= CIFS_I(inode
);
1194 /* if file not oplocked can't be sure whether asking to extend size */
1195 if (!CIFS_CACHE_READ(cifsi
))
1196 if (keep_size
== false)
1200 * Files are non-sparse by default so falloc may be a no-op
1201 * Must check if file sparse. If not sparse, and not extending
1202 * then no need to do anything since file already allocated
1204 if ((cifsi
->cifsAttrs
& FILE_ATTRIBUTE_SPARSE_FILE
) == 0) {
1205 if (keep_size
== true)
1207 /* check if extending file */
1208 else if (i_size_read(inode
) >= off
+ len
)
1209 /* not extending file and already not sparse */
1211 /* BB: in future add else clause to extend file */
1216 if ((keep_size
== true) || (i_size_read(inode
) >= off
+ len
)) {
1218 * Check if falloc starts within first few pages of file
1219 * and ends within a few pages of the end of file to
1220 * ensure that most of file is being forced to be
1221 * fallocated now. If so then setting whole file sparse
1222 * ie potentially making a few extra pages at the beginning
1223 * or end of the file non-sparse via set_sparse is harmless.
1225 if ((off
> 8192) || (off
+ len
+ 8192 < i_size_read(inode
)))
1228 rc
= smb2_set_sparse(xid
, tcon
, cfile
, inode
, false);
1230 /* BB: else ... in future add code to extend file and set sparse */
1238 static long smb3_fallocate(struct file
*file
, struct cifs_tcon
*tcon
, int mode
,
1239 loff_t off
, loff_t len
)
1241 /* KEEP_SIZE already checked for by do_fallocate */
1242 if (mode
& FALLOC_FL_PUNCH_HOLE
)
1243 return smb3_punch_hole(file
, tcon
, off
, len
);
1244 else if (mode
& FALLOC_FL_ZERO_RANGE
) {
1245 if (mode
& FALLOC_FL_KEEP_SIZE
)
1246 return smb3_zero_range(file
, tcon
, off
, len
, true);
1247 return smb3_zero_range(file
, tcon
, off
, len
, false);
1248 } else if (mode
== FALLOC_FL_KEEP_SIZE
)
1249 return smb3_simple_falloc(file
, tcon
, off
, len
, true);
1251 return smb3_simple_falloc(file
, tcon
, off
, len
, false);
1257 smb2_downgrade_oplock(struct TCP_Server_Info
*server
,
1258 struct cifsInodeInfo
*cinode
, bool set_level2
)
1261 server
->ops
->set_oplock_level(cinode
, SMB2_OPLOCK_LEVEL_II
,
1264 server
->ops
->set_oplock_level(cinode
, 0, 0, NULL
);
1268 smb2_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1269 unsigned int epoch
, bool *purge_cache
)
1272 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1274 if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
) {
1275 cinode
->oplock
= CIFS_CACHE_RHW_FLG
;
1276 cifs_dbg(FYI
, "Batch Oplock granted on inode %p\n",
1277 &cinode
->vfs_inode
);
1278 } else if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
) {
1279 cinode
->oplock
= CIFS_CACHE_RW_FLG
;
1280 cifs_dbg(FYI
, "Exclusive Oplock granted on inode %p\n",
1281 &cinode
->vfs_inode
);
1282 } else if (oplock
== SMB2_OPLOCK_LEVEL_II
) {
1283 cinode
->oplock
= CIFS_CACHE_READ_FLG
;
1284 cifs_dbg(FYI
, "Level II Oplock granted on inode %p\n",
1285 &cinode
->vfs_inode
);
1291 smb21_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1292 unsigned int epoch
, bool *purge_cache
)
1294 char message
[5] = {0};
1297 if (oplock
== SMB2_OPLOCK_LEVEL_NOCHANGE
)
1301 if (oplock
& SMB2_LEASE_READ_CACHING_HE
) {
1302 cinode
->oplock
|= CIFS_CACHE_READ_FLG
;
1303 strcat(message
, "R");
1305 if (oplock
& SMB2_LEASE_HANDLE_CACHING_HE
) {
1306 cinode
->oplock
|= CIFS_CACHE_HANDLE_FLG
;
1307 strcat(message
, "H");
1309 if (oplock
& SMB2_LEASE_WRITE_CACHING_HE
) {
1310 cinode
->oplock
|= CIFS_CACHE_WRITE_FLG
;
1311 strcat(message
, "W");
1313 if (!cinode
->oplock
)
1314 strcat(message
, "None");
1315 cifs_dbg(FYI
, "%s Lease granted on inode %p\n", message
,
1316 &cinode
->vfs_inode
);
1320 smb3_set_oplock_level(struct cifsInodeInfo
*cinode
, __u32 oplock
,
1321 unsigned int epoch
, bool *purge_cache
)
1323 unsigned int old_oplock
= cinode
->oplock
;
1325 smb21_set_oplock_level(cinode
, oplock
, epoch
, purge_cache
);
1328 *purge_cache
= false;
1329 if (old_oplock
== CIFS_CACHE_READ_FLG
) {
1330 if (cinode
->oplock
== CIFS_CACHE_READ_FLG
&&
1331 (epoch
- cinode
->epoch
> 0))
1332 *purge_cache
= true;
1333 else if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1334 (epoch
- cinode
->epoch
> 1))
1335 *purge_cache
= true;
1336 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1337 (epoch
- cinode
->epoch
> 1))
1338 *purge_cache
= true;
1339 else if (cinode
->oplock
== 0 &&
1340 (epoch
- cinode
->epoch
> 0))
1341 *purge_cache
= true;
1342 } else if (old_oplock
== CIFS_CACHE_RH_FLG
) {
1343 if (cinode
->oplock
== CIFS_CACHE_RH_FLG
&&
1344 (epoch
- cinode
->epoch
> 0))
1345 *purge_cache
= true;
1346 else if (cinode
->oplock
== CIFS_CACHE_RHW_FLG
&&
1347 (epoch
- cinode
->epoch
> 1))
1348 *purge_cache
= true;
1350 cinode
->epoch
= epoch
;
1355 smb2_is_read_op(__u32 oplock
)
1357 return oplock
== SMB2_OPLOCK_LEVEL_II
;
1361 smb21_is_read_op(__u32 oplock
)
1363 return (oplock
& SMB2_LEASE_READ_CACHING_HE
) &&
1364 !(oplock
& SMB2_LEASE_WRITE_CACHING_HE
);
1368 map_oplock_to_lease(u8 oplock
)
1370 if (oplock
== SMB2_OPLOCK_LEVEL_EXCLUSIVE
)
1371 return SMB2_LEASE_WRITE_CACHING
| SMB2_LEASE_READ_CACHING
;
1372 else if (oplock
== SMB2_OPLOCK_LEVEL_II
)
1373 return SMB2_LEASE_READ_CACHING
;
1374 else if (oplock
== SMB2_OPLOCK_LEVEL_BATCH
)
1375 return SMB2_LEASE_HANDLE_CACHING
| SMB2_LEASE_READ_CACHING
|
1376 SMB2_LEASE_WRITE_CACHING
;
1381 smb2_create_lease_buf(u8
*lease_key
, u8 oplock
)
1383 struct create_lease
*buf
;
1385 buf
= kzalloc(sizeof(struct create_lease
), GFP_KERNEL
);
1389 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1390 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1391 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1393 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1394 (struct create_lease
, lcontext
));
1395 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context
));
1396 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1397 (struct create_lease
, Name
));
1398 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1399 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1408 smb3_create_lease_buf(u8
*lease_key
, u8 oplock
)
1410 struct create_lease_v2
*buf
;
1412 buf
= kzalloc(sizeof(struct create_lease_v2
), GFP_KERNEL
);
1416 buf
->lcontext
.LeaseKeyLow
= cpu_to_le64(*((u64
*)lease_key
));
1417 buf
->lcontext
.LeaseKeyHigh
= cpu_to_le64(*((u64
*)(lease_key
+ 8)));
1418 buf
->lcontext
.LeaseState
= map_oplock_to_lease(oplock
);
1420 buf
->ccontext
.DataOffset
= cpu_to_le16(offsetof
1421 (struct create_lease_v2
, lcontext
));
1422 buf
->ccontext
.DataLength
= cpu_to_le32(sizeof(struct lease_context_v2
));
1423 buf
->ccontext
.NameOffset
= cpu_to_le16(offsetof
1424 (struct create_lease_v2
, Name
));
1425 buf
->ccontext
.NameLength
= cpu_to_le16(4);
1426 /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
1435 smb2_parse_lease_buf(void *buf
, unsigned int *epoch
)
1437 struct create_lease
*lc
= (struct create_lease
*)buf
;
1439 *epoch
= 0; /* not used */
1440 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
1441 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
1442 return le32_to_cpu(lc
->lcontext
.LeaseState
);
1446 smb3_parse_lease_buf(void *buf
, unsigned int *epoch
)
1448 struct create_lease_v2
*lc
= (struct create_lease_v2
*)buf
;
1450 *epoch
= le16_to_cpu(lc
->lcontext
.Epoch
);
1451 if (lc
->lcontext
.LeaseFlags
& SMB2_LEASE_FLAG_BREAK_IN_PROGRESS
)
1452 return SMB2_OPLOCK_LEVEL_NOCHANGE
;
1453 return le32_to_cpu(lc
->lcontext
.LeaseState
);
1457 smb2_wp_retry_size(struct inode
*inode
)
1459 return min_t(unsigned int, CIFS_SB(inode
->i_sb
)->wsize
,
1460 SMB2_MAX_BUFFER_SIZE
);
1464 smb2_dir_needs_close(struct cifsFileInfo
*cfile
)
1466 return !cfile
->invalidHandle
;
1469 struct smb_version_operations smb20_operations
= {
1470 .compare_fids
= smb2_compare_fids
,
1471 .setup_request
= smb2_setup_request
,
1472 .setup_async_request
= smb2_setup_async_request
,
1473 .check_receive
= smb2_check_receive
,
1474 .add_credits
= smb2_add_credits
,
1475 .set_credits
= smb2_set_credits
,
1476 .get_credits_field
= smb2_get_credits_field
,
1477 .get_credits
= smb2_get_credits
,
1478 .wait_mtu_credits
= cifs_wait_mtu_credits
,
1479 .get_next_mid
= smb2_get_next_mid
,
1480 .read_data_offset
= smb2_read_data_offset
,
1481 .read_data_length
= smb2_read_data_length
,
1482 .map_error
= map_smb2_to_linux_error
,
1483 .find_mid
= smb2_find_mid
,
1484 .check_message
= smb2_check_message
,
1485 .dump_detail
= smb2_dump_detail
,
1486 .clear_stats
= smb2_clear_stats
,
1487 .print_stats
= smb2_print_stats
,
1488 .is_oplock_break
= smb2_is_valid_oplock_break
,
1489 .downgrade_oplock
= smb2_downgrade_oplock
,
1490 .need_neg
= smb2_need_neg
,
1491 .negotiate
= smb2_negotiate
,
1492 .negotiate_wsize
= smb2_negotiate_wsize
,
1493 .negotiate_rsize
= smb2_negotiate_rsize
,
1494 .sess_setup
= SMB2_sess_setup
,
1495 .logoff
= SMB2_logoff
,
1496 .tree_connect
= SMB2_tcon
,
1497 .tree_disconnect
= SMB2_tdis
,
1498 .qfs_tcon
= smb2_qfs_tcon
,
1499 .is_path_accessible
= smb2_is_path_accessible
,
1500 .can_echo
= smb2_can_echo
,
1502 .query_path_info
= smb2_query_path_info
,
1503 .get_srv_inum
= smb2_get_srv_inum
,
1504 .query_file_info
= smb2_query_file_info
,
1505 .set_path_size
= smb2_set_path_size
,
1506 .set_file_size
= smb2_set_file_size
,
1507 .set_file_info
= smb2_set_file_info
,
1508 .set_compression
= smb2_set_compression
,
1509 .mkdir
= smb2_mkdir
,
1510 .mkdir_setinfo
= smb2_mkdir_setinfo
,
1511 .rmdir
= smb2_rmdir
,
1512 .unlink
= smb2_unlink
,
1513 .rename
= smb2_rename_path
,
1514 .create_hardlink
= smb2_create_hardlink
,
1515 .query_symlink
= smb2_query_symlink
,
1516 .open
= smb2_open_file
,
1517 .set_fid
= smb2_set_fid
,
1518 .close
= smb2_close_file
,
1519 .flush
= smb2_flush_file
,
1520 .async_readv
= smb2_async_readv
,
1521 .async_writev
= smb2_async_writev
,
1522 .sync_read
= smb2_sync_read
,
1523 .sync_write
= smb2_sync_write
,
1524 .query_dir_first
= smb2_query_dir_first
,
1525 .query_dir_next
= smb2_query_dir_next
,
1526 .close_dir
= smb2_close_dir
,
1527 .calc_smb_size
= smb2_calc_size
,
1528 .is_status_pending
= smb2_is_status_pending
,
1529 .oplock_response
= smb2_oplock_response
,
1530 .queryfs
= smb2_queryfs
,
1531 .mand_lock
= smb2_mand_lock
,
1532 .mand_unlock_range
= smb2_unlock_range
,
1533 .push_mand_locks
= smb2_push_mandatory_locks
,
1534 .get_lease_key
= smb2_get_lease_key
,
1535 .set_lease_key
= smb2_set_lease_key
,
1536 .new_lease_key
= smb2_new_lease_key
,
1537 .calc_signature
= smb2_calc_signature
,
1538 .is_read_op
= smb2_is_read_op
,
1539 .set_oplock_level
= smb2_set_oplock_level
,
1540 .create_lease_buf
= smb2_create_lease_buf
,
1541 .parse_lease_buf
= smb2_parse_lease_buf
,
1542 .clone_range
= smb2_clone_range
,
1543 .wp_retry_size
= smb2_wp_retry_size
,
1544 .dir_needs_close
= smb2_dir_needs_close
,
1547 struct smb_version_operations smb21_operations
= {
1548 .compare_fids
= smb2_compare_fids
,
1549 .setup_request
= smb2_setup_request
,
1550 .setup_async_request
= smb2_setup_async_request
,
1551 .check_receive
= smb2_check_receive
,
1552 .add_credits
= smb2_add_credits
,
1553 .set_credits
= smb2_set_credits
,
1554 .get_credits_field
= smb2_get_credits_field
,
1555 .get_credits
= smb2_get_credits
,
1556 .wait_mtu_credits
= smb2_wait_mtu_credits
,
1557 .get_next_mid
= smb2_get_next_mid
,
1558 .read_data_offset
= smb2_read_data_offset
,
1559 .read_data_length
= smb2_read_data_length
,
1560 .map_error
= map_smb2_to_linux_error
,
1561 .find_mid
= smb2_find_mid
,
1562 .check_message
= smb2_check_message
,
1563 .dump_detail
= smb2_dump_detail
,
1564 .clear_stats
= smb2_clear_stats
,
1565 .print_stats
= smb2_print_stats
,
1566 .is_oplock_break
= smb2_is_valid_oplock_break
,
1567 .downgrade_oplock
= smb2_downgrade_oplock
,
1568 .need_neg
= smb2_need_neg
,
1569 .negotiate
= smb2_negotiate
,
1570 .negotiate_wsize
= smb2_negotiate_wsize
,
1571 .negotiate_rsize
= smb2_negotiate_rsize
,
1572 .sess_setup
= SMB2_sess_setup
,
1573 .logoff
= SMB2_logoff
,
1574 .tree_connect
= SMB2_tcon
,
1575 .tree_disconnect
= SMB2_tdis
,
1576 .qfs_tcon
= smb2_qfs_tcon
,
1577 .is_path_accessible
= smb2_is_path_accessible
,
1578 .can_echo
= smb2_can_echo
,
1580 .query_path_info
= smb2_query_path_info
,
1581 .get_srv_inum
= smb2_get_srv_inum
,
1582 .query_file_info
= smb2_query_file_info
,
1583 .set_path_size
= smb2_set_path_size
,
1584 .set_file_size
= smb2_set_file_size
,
1585 .set_file_info
= smb2_set_file_info
,
1586 .set_compression
= smb2_set_compression
,
1587 .mkdir
= smb2_mkdir
,
1588 .mkdir_setinfo
= smb2_mkdir_setinfo
,
1589 .rmdir
= smb2_rmdir
,
1590 .unlink
= smb2_unlink
,
1591 .rename
= smb2_rename_path
,
1592 .create_hardlink
= smb2_create_hardlink
,
1593 .query_symlink
= smb2_query_symlink
,
1594 .query_mf_symlink
= smb3_query_mf_symlink
,
1595 .create_mf_symlink
= smb3_create_mf_symlink
,
1596 .open
= smb2_open_file
,
1597 .set_fid
= smb2_set_fid
,
1598 .close
= smb2_close_file
,
1599 .flush
= smb2_flush_file
,
1600 .async_readv
= smb2_async_readv
,
1601 .async_writev
= smb2_async_writev
,
1602 .sync_read
= smb2_sync_read
,
1603 .sync_write
= smb2_sync_write
,
1604 .query_dir_first
= smb2_query_dir_first
,
1605 .query_dir_next
= smb2_query_dir_next
,
1606 .close_dir
= smb2_close_dir
,
1607 .calc_smb_size
= smb2_calc_size
,
1608 .is_status_pending
= smb2_is_status_pending
,
1609 .oplock_response
= smb2_oplock_response
,
1610 .queryfs
= smb2_queryfs
,
1611 .mand_lock
= smb2_mand_lock
,
1612 .mand_unlock_range
= smb2_unlock_range
,
1613 .push_mand_locks
= smb2_push_mandatory_locks
,
1614 .get_lease_key
= smb2_get_lease_key
,
1615 .set_lease_key
= smb2_set_lease_key
,
1616 .new_lease_key
= smb2_new_lease_key
,
1617 .calc_signature
= smb2_calc_signature
,
1618 .is_read_op
= smb21_is_read_op
,
1619 .set_oplock_level
= smb21_set_oplock_level
,
1620 .create_lease_buf
= smb2_create_lease_buf
,
1621 .parse_lease_buf
= smb2_parse_lease_buf
,
1622 .clone_range
= smb2_clone_range
,
1623 .wp_retry_size
= smb2_wp_retry_size
,
1624 .dir_needs_close
= smb2_dir_needs_close
,
1627 struct smb_version_operations smb30_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
= smb2_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 .dump_share_caps
= smb2_dump_share_caps
,
1647 .is_oplock_break
= smb2_is_valid_oplock_break
,
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
= smb3_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 .oplock_response
= smb2_oplock_response
,
1691 .queryfs
= smb2_queryfs
,
1692 .mand_lock
= smb2_mand_lock
,
1693 .mand_unlock_range
= smb2_unlock_range
,
1694 .push_mand_locks
= smb2_push_mandatory_locks
,
1695 .get_lease_key
= smb2_get_lease_key
,
1696 .set_lease_key
= smb2_set_lease_key
,
1697 .new_lease_key
= smb2_new_lease_key
,
1698 .generate_signingkey
= generate_smb3signingkey
,
1699 .calc_signature
= smb3_calc_signature
,
1700 .set_integrity
= smb3_set_integrity
,
1701 .is_read_op
= smb21_is_read_op
,
1702 .set_oplock_level
= smb3_set_oplock_level
,
1703 .create_lease_buf
= smb3_create_lease_buf
,
1704 .parse_lease_buf
= smb3_parse_lease_buf
,
1705 .clone_range
= smb2_clone_range
,
1706 .validate_negotiate
= smb3_validate_negotiate
,
1707 .wp_retry_size
= smb2_wp_retry_size
,
1708 .dir_needs_close
= smb2_dir_needs_close
,
1709 .fallocate
= smb3_fallocate
,
1712 #ifdef CONFIG_CIFS_SMB311
1713 struct smb_version_operations smb311_operations
= {
1714 .compare_fids
= smb2_compare_fids
,
1715 .setup_request
= smb2_setup_request
,
1716 .setup_async_request
= smb2_setup_async_request
,
1717 .check_receive
= smb2_check_receive
,
1718 .add_credits
= smb2_add_credits
,
1719 .set_credits
= smb2_set_credits
,
1720 .get_credits_field
= smb2_get_credits_field
,
1721 .get_credits
= smb2_get_credits
,
1722 .wait_mtu_credits
= smb2_wait_mtu_credits
,
1723 .get_next_mid
= smb2_get_next_mid
,
1724 .read_data_offset
= smb2_read_data_offset
,
1725 .read_data_length
= smb2_read_data_length
,
1726 .map_error
= map_smb2_to_linux_error
,
1727 .find_mid
= smb2_find_mid
,
1728 .check_message
= smb2_check_message
,
1729 .dump_detail
= smb2_dump_detail
,
1730 .clear_stats
= smb2_clear_stats
,
1731 .print_stats
= smb2_print_stats
,
1732 .dump_share_caps
= smb2_dump_share_caps
,
1733 .is_oplock_break
= smb2_is_valid_oplock_break
,
1734 .downgrade_oplock
= smb2_downgrade_oplock
,
1735 .need_neg
= smb2_need_neg
,
1736 .negotiate
= smb2_negotiate
,
1737 .negotiate_wsize
= smb2_negotiate_wsize
,
1738 .negotiate_rsize
= smb2_negotiate_rsize
,
1739 .sess_setup
= SMB2_sess_setup
,
1740 .logoff
= SMB2_logoff
,
1741 .tree_connect
= SMB2_tcon
,
1742 .tree_disconnect
= SMB2_tdis
,
1743 .qfs_tcon
= smb3_qfs_tcon
,
1744 .is_path_accessible
= smb2_is_path_accessible
,
1745 .can_echo
= smb2_can_echo
,
1747 .query_path_info
= smb2_query_path_info
,
1748 .get_srv_inum
= smb2_get_srv_inum
,
1749 .query_file_info
= smb2_query_file_info
,
1750 .set_path_size
= smb2_set_path_size
,
1751 .set_file_size
= smb2_set_file_size
,
1752 .set_file_info
= smb2_set_file_info
,
1753 .set_compression
= smb2_set_compression
,
1754 .mkdir
= smb2_mkdir
,
1755 .mkdir_setinfo
= smb2_mkdir_setinfo
,
1756 .rmdir
= smb2_rmdir
,
1757 .unlink
= smb2_unlink
,
1758 .rename
= smb2_rename_path
,
1759 .create_hardlink
= smb2_create_hardlink
,
1760 .query_symlink
= smb2_query_symlink
,
1761 .query_mf_symlink
= smb3_query_mf_symlink
,
1762 .create_mf_symlink
= smb3_create_mf_symlink
,
1763 .open
= smb2_open_file
,
1764 .set_fid
= smb2_set_fid
,
1765 .close
= smb2_close_file
,
1766 .flush
= smb2_flush_file
,
1767 .async_readv
= smb2_async_readv
,
1768 .async_writev
= smb2_async_writev
,
1769 .sync_read
= smb2_sync_read
,
1770 .sync_write
= smb2_sync_write
,
1771 .query_dir_first
= smb2_query_dir_first
,
1772 .query_dir_next
= smb2_query_dir_next
,
1773 .close_dir
= smb2_close_dir
,
1774 .calc_smb_size
= smb2_calc_size
,
1775 .is_status_pending
= smb2_is_status_pending
,
1776 .oplock_response
= smb2_oplock_response
,
1777 .queryfs
= smb2_queryfs
,
1778 .mand_lock
= smb2_mand_lock
,
1779 .mand_unlock_range
= smb2_unlock_range
,
1780 .push_mand_locks
= smb2_push_mandatory_locks
,
1781 .get_lease_key
= smb2_get_lease_key
,
1782 .set_lease_key
= smb2_set_lease_key
,
1783 .new_lease_key
= smb2_new_lease_key
,
1784 .generate_signingkey
= generate_smb3signingkey
,
1785 .calc_signature
= smb3_calc_signature
,
1786 .set_integrity
= smb3_set_integrity
,
1787 .is_read_op
= smb21_is_read_op
,
1788 .set_oplock_level
= smb3_set_oplock_level
,
1789 .create_lease_buf
= smb3_create_lease_buf
,
1790 .parse_lease_buf
= smb3_parse_lease_buf
,
1791 .clone_range
= smb2_clone_range
,
1792 .duplicate_extents
= smb2_duplicate_extents
,
1793 /* .validate_negotiate = smb3_validate_negotiate, */ /* not used in 3.11 */
1794 .wp_retry_size
= smb2_wp_retry_size
,
1795 .dir_needs_close
= smb2_dir_needs_close
,
1796 .fallocate
= smb3_fallocate
,
1798 #endif /* CIFS_SMB311 */
1800 struct smb_version_values smb20_values
= {
1801 .version_string
= SMB20_VERSION_STRING
,
1802 .protocol_id
= SMB20_PROT_ID
,
1803 .req_capabilities
= 0, /* MBZ */
1804 .large_lock_type
= 0,
1805 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1806 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1807 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1808 .header_size
= sizeof(struct smb2_hdr
),
1809 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1810 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1811 .lock_cmd
= SMB2_LOCK
,
1813 .cap_nt_find
= SMB2_NT_FIND
,
1814 .cap_large_files
= SMB2_LARGE_FILES
,
1815 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1816 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1817 .create_lease_size
= sizeof(struct create_lease
),
1820 struct smb_version_values smb21_values
= {
1821 .version_string
= SMB21_VERSION_STRING
,
1822 .protocol_id
= SMB21_PROT_ID
,
1823 .req_capabilities
= 0, /* MBZ on negotiate req until SMB3 dialect */
1824 .large_lock_type
= 0,
1825 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1826 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1827 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1828 .header_size
= sizeof(struct smb2_hdr
),
1829 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1830 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1831 .lock_cmd
= SMB2_LOCK
,
1833 .cap_nt_find
= SMB2_NT_FIND
,
1834 .cap_large_files
= SMB2_LARGE_FILES
,
1835 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1836 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1837 .create_lease_size
= sizeof(struct create_lease
),
1840 struct smb_version_values smb30_values
= {
1841 .version_string
= SMB30_VERSION_STRING
,
1842 .protocol_id
= SMB30_PROT_ID
,
1843 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
,
1844 .large_lock_type
= 0,
1845 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1846 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1847 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1848 .header_size
= sizeof(struct smb2_hdr
),
1849 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1850 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1851 .lock_cmd
= SMB2_LOCK
,
1853 .cap_nt_find
= SMB2_NT_FIND
,
1854 .cap_large_files
= SMB2_LARGE_FILES
,
1855 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1856 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1857 .create_lease_size
= sizeof(struct create_lease_v2
),
1860 struct smb_version_values smb302_values
= {
1861 .version_string
= SMB302_VERSION_STRING
,
1862 .protocol_id
= SMB302_PROT_ID
,
1863 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
,
1864 .large_lock_type
= 0,
1865 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1866 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1867 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1868 .header_size
= sizeof(struct smb2_hdr
),
1869 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1870 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1871 .lock_cmd
= SMB2_LOCK
,
1873 .cap_nt_find
= SMB2_NT_FIND
,
1874 .cap_large_files
= SMB2_LARGE_FILES
,
1875 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1876 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1877 .create_lease_size
= sizeof(struct create_lease_v2
),
1880 #ifdef CONFIG_CIFS_SMB311
1881 struct smb_version_values smb311_values
= {
1882 .version_string
= SMB311_VERSION_STRING
,
1883 .protocol_id
= SMB311_PROT_ID
,
1884 .req_capabilities
= SMB2_GLOBAL_CAP_DFS
| SMB2_GLOBAL_CAP_LEASING
| SMB2_GLOBAL_CAP_LARGE_MTU
,
1885 .large_lock_type
= 0,
1886 .exclusive_lock_type
= SMB2_LOCKFLAG_EXCLUSIVE_LOCK
,
1887 .shared_lock_type
= SMB2_LOCKFLAG_SHARED_LOCK
,
1888 .unlock_lock_type
= SMB2_LOCKFLAG_UNLOCK
,
1889 .header_size
= sizeof(struct smb2_hdr
),
1890 .max_header_size
= MAX_SMB2_HDR_SIZE
,
1891 .read_rsp_size
= sizeof(struct smb2_read_rsp
) - 1,
1892 .lock_cmd
= SMB2_LOCK
,
1894 .cap_nt_find
= SMB2_NT_FIND
,
1895 .cap_large_files
= SMB2_LARGE_FILES
,
1896 .signing_enabled
= SMB2_NEGOTIATE_SIGNING_ENABLED
| SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1897 .signing_required
= SMB2_NEGOTIATE_SIGNING_REQUIRED
,
1898 .create_lease_size
= sizeof(struct create_lease_v2
),