Merge branch 'for-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetoot...
[deliverable/linux.git] / fs / cifs / smb2ops.c
CommitLineData
1080ef75
SF
1/*
2 * SMB2 version specific operations
3 *
4 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
5 *
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.
9 *
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.
14 *
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
18 */
19
3a3bab50 20#include <linux/pagemap.h>
6fc05c25 21#include <linux/vfs.h>
1080ef75 22#include "cifsglob.h"
2dc7e1c0
PS
23#include "smb2pdu.h"
24#include "smb2proto.h"
28ea5290
PS
25#include "cifsproto.h"
26#include "cifs_debug.h"
b42bf888 27#include "cifs_unicode.h"
2e44b288 28#include "smb2status.h"
6fc05c25 29#include "smb2glob.h"
28ea5290
PS
30
31static int
32change_conf(struct TCP_Server_Info *server)
33{
34 server->credits += server->echo_credits + server->oplock_credits;
35 server->oplock_credits = server->echo_credits = 0;
36 switch (server->credits) {
37 case 0:
38 return -1;
39 case 1:
40 server->echoes = false;
41 server->oplocks = false;
f96637be 42 cifs_dbg(VFS, "disabling echoes and oplocks\n");
28ea5290
PS
43 break;
44 case 2:
45 server->echoes = true;
46 server->oplocks = false;
47 server->echo_credits = 1;
f96637be 48 cifs_dbg(FYI, "disabling oplocks\n");
28ea5290
PS
49 break;
50 default:
51 server->echoes = true;
52 server->oplocks = true;
53 server->echo_credits = 1;
54 server->oplock_credits = 1;
55 }
56 server->credits -= server->echo_credits + server->oplock_credits;
57 return 0;
58}
59
60static void
61smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
62 const int optype)
63{
64 int *val, rc = 0;
65 spin_lock(&server->req_lock);
66 val = server->ops->get_credits_field(server, optype);
67 *val += add;
68 server->in_flight--;
ec2e4523 69 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
28ea5290 70 rc = change_conf(server);
983c88a4
PS
71 /*
72 * Sometimes server returns 0 credits on oplock break ack - we need to
73 * rebalance credits in this case.
74 */
75 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
76 server->oplocks) {
77 if (server->credits > 1) {
78 server->credits--;
79 server->oplock_credits++;
80 }
81 }
28ea5290
PS
82 spin_unlock(&server->req_lock);
83 wake_up(&server->request_q);
84 if (rc)
85 cifs_reconnect(server);
86}
87
88static void
89smb2_set_credits(struct TCP_Server_Info *server, const int val)
90{
91 spin_lock(&server->req_lock);
92 server->credits = val;
93 spin_unlock(&server->req_lock);
94}
95
96static int *
97smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
98{
99 switch (optype) {
100 case CIFS_ECHO_OP:
101 return &server->echo_credits;
102 case CIFS_OBREAK_OP:
103 return &server->oplock_credits;
104 default:
105 return &server->credits;
106 }
107}
108
109static unsigned int
110smb2_get_credits(struct mid_q_entry *mid)
111{
112 return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest);
113}
2dc7e1c0
PS
114
115static __u64
116smb2_get_next_mid(struct TCP_Server_Info *server)
117{
118 __u64 mid;
119 /* for SMB2 we need the current value */
120 spin_lock(&GlobalMid_Lock);
121 mid = server->CurrentMid++;
122 spin_unlock(&GlobalMid_Lock);
123 return mid;
124}
1080ef75 125
093b2bda
PS
126static struct mid_q_entry *
127smb2_find_mid(struct TCP_Server_Info *server, char *buf)
128{
129 struct mid_q_entry *mid;
130 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
131
132 spin_lock(&GlobalMid_Lock);
133 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
134 if ((mid->mid == hdr->MessageId) &&
135 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
136 (mid->command == hdr->Command)) {
137 spin_unlock(&GlobalMid_Lock);
138 return mid;
139 }
140 }
141 spin_unlock(&GlobalMid_Lock);
142 return NULL;
143}
144
145static void
146smb2_dump_detail(void *buf)
147{
148#ifdef CONFIG_CIFS_DEBUG2
149 struct smb2_hdr *smb = (struct smb2_hdr *)buf;
150
f96637be
JP
151 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
152 smb->Command, smb->Status, smb->Flags, smb->MessageId,
153 smb->ProcessId);
154 cifs_dbg(VFS, "smb buf %p len %u\n", smb, smb2_calc_size(smb));
093b2bda
PS
155#endif
156}
157
ec2e4523
PS
158static bool
159smb2_need_neg(struct TCP_Server_Info *server)
160{
161 return server->max_read == 0;
162}
163
164static int
165smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
166{
167 int rc;
168 ses->server->CurrentMid = 0;
169 rc = SMB2_negotiate(xid, ses);
170 /* BB we probably don't need to retry with modern servers */
171 if (rc == -EAGAIN)
172 rc = -EHOSTDOWN;
173 return rc;
174}
175
3a3bab50
PS
176static unsigned int
177smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
178{
179 struct TCP_Server_Info *server = tcon->ses->server;
180 unsigned int wsize;
181
182 /* start with specified wsize, or default */
183 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
184 wsize = min_t(unsigned int, wsize, server->max_write);
185 /*
186 * limit write size to 2 ** 16, because we don't support multicredit
187 * requests now.
188 */
189 wsize = min_t(unsigned int, wsize, 2 << 15);
190
3a3bab50
PS
191 return wsize;
192}
193
194static unsigned int
195smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
196{
197 struct TCP_Server_Info *server = tcon->ses->server;
198 unsigned int rsize;
199
200 /* start with specified rsize, or default */
201 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
202 rsize = min_t(unsigned int, rsize, server->max_read);
203 /*
204 * limit write size to 2 ** 16, because we don't support multicredit
205 * requests now.
206 */
207 rsize = min_t(unsigned int, rsize, 2 << 15);
208
3a3bab50
PS
209 return rsize;
210}
211
c481e9fe
SF
212#ifdef CONFIG_CIFS_STATS2
213static int
214SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
215{
216 int rc;
217 unsigned int ret_data_len = 0;
218 struct network_interface_info_ioctl_rsp *out_buf;
219
220 rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
221 FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
222 NULL /* no data input */, 0 /* no data input */,
223 (char **)&out_buf, &ret_data_len);
224
225 if ((rc == 0) && (ret_data_len > 0)) {
226 /* Dump info on first interface */
227 cifs_dbg(FYI, "Adapter Capability 0x%x\t",
228 le32_to_cpu(out_buf->Capability));
229 cifs_dbg(FYI, "Link Speed %lld\n",
230 le64_to_cpu(out_buf->LinkSpeed));
231 } else
232 cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
233
234 return rc;
235}
236#endif /* STATS2 */
237
af6a12ea
SF
238static void
239smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
240{
241 int rc;
242 __le16 srch_path = 0; /* Null - open root of share */
243 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
244 struct cifs_open_parms oparms;
245 struct cifs_fid fid;
246
247 oparms.tcon = tcon;
248 oparms.desired_access = FILE_READ_ATTRIBUTES;
249 oparms.disposition = FILE_OPEN;
250 oparms.create_options = 0;
251 oparms.fid = &fid;
252 oparms.reconnect = false;
253
254 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
255 if (rc)
256 return;
257
c481e9fe
SF
258#ifdef CONFIG_CIFS_STATS2
259 SMB3_request_interfaces(xid, tcon);
260#endif /* STATS2 */
261
af6a12ea
SF
262 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
263 FS_ATTRIBUTE_INFORMATION);
264 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
265 FS_DEVICE_INFORMATION);
266 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
267 FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
268 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
269 return;
270}
271
34f62640
SF
272static void
273smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
274{
275 int rc;
276 __le16 srch_path = 0; /* Null - open root of share */
277 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
278 struct cifs_open_parms oparms;
279 struct cifs_fid fid;
280
281 oparms.tcon = tcon;
282 oparms.desired_access = FILE_READ_ATTRIBUTES;
283 oparms.disposition = FILE_OPEN;
284 oparms.create_options = 0;
285 oparms.fid = &fid;
286 oparms.reconnect = false;
287
288 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
289 if (rc)
290 return;
291
2167114c
SF
292 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
293 FS_ATTRIBUTE_INFORMATION);
294 SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
295 FS_DEVICE_INFORMATION);
34f62640
SF
296 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
297 return;
298}
299
2503a0db
PS
300static int
301smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
302 struct cifs_sb_info *cifs_sb, const char *full_path)
303{
304 int rc;
2503a0db 305 __le16 *utf16_path;
2e44b288 306 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
064f6047
PS
307 struct cifs_open_parms oparms;
308 struct cifs_fid fid;
2503a0db
PS
309
310 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
311 if (!utf16_path)
312 return -ENOMEM;
313
064f6047
PS
314 oparms.tcon = tcon;
315 oparms.desired_access = FILE_READ_ATTRIBUTES;
316 oparms.disposition = FILE_OPEN;
317 oparms.create_options = 0;
318 oparms.fid = &fid;
9cbc0b73 319 oparms.reconnect = false;
064f6047 320
b42bf888 321 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
2503a0db
PS
322 if (rc) {
323 kfree(utf16_path);
324 return rc;
325 }
326
064f6047 327 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2503a0db
PS
328 kfree(utf16_path);
329 return rc;
330}
331
be4cb9e3
PS
332static int
333smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
334 struct cifs_sb_info *cifs_sb, const char *full_path,
335 u64 *uniqueid, FILE_ALL_INFO *data)
336{
337 *uniqueid = le64_to_cpu(data->IndexNumber);
338 return 0;
339}
340
b7546bc5
PS
341static int
342smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
343 struct cifs_fid *fid, FILE_ALL_INFO *data)
344{
345 int rc;
346 struct smb2_file_all_info *smb2_data;
347
348 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2,
349 GFP_KERNEL);
350 if (smb2_data == NULL)
351 return -ENOMEM;
352
353 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
354 smb2_data);
355 if (!rc)
356 move_smb2_info_to_cifs(data, smb2_data);
357 kfree(smb2_data);
358 return rc;
359}
360
9094fad1
PS
361static bool
362smb2_can_echo(struct TCP_Server_Info *server)
363{
364 return server->echoes;
365}
366
d60622eb
PS
367static void
368smb2_clear_stats(struct cifs_tcon *tcon)
369{
370#ifdef CONFIG_CIFS_STATS
371 int i;
372 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
373 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
374 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
375 }
376#endif
377}
378
769ee6a4
SF
379static void
380smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
381{
382 seq_puts(m, "\n\tShare Capabilities:");
383 if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
384 seq_puts(m, " DFS,");
385 if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
386 seq_puts(m, " CONTINUOUS AVAILABILITY,");
387 if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
388 seq_puts(m, " SCALEOUT,");
389 if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
390 seq_puts(m, " CLUSTER,");
391 if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
392 seq_puts(m, " ASYMMETRIC,");
393 if (tcon->capabilities == 0)
394 seq_puts(m, " None");
af6a12ea
SF
395 if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
396 seq_puts(m, " Aligned,");
397 if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
398 seq_puts(m, " Partition Aligned,");
399 if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
400 seq_puts(m, " SSD,");
401 if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
402 seq_puts(m, " TRIM-support,");
403
769ee6a4 404 seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
af6a12ea
SF
405 if (tcon->perf_sector_size)
406 seq_printf(m, "\tOptimal sector size: 0x%x",
407 tcon->perf_sector_size);
769ee6a4
SF
408}
409
d60622eb
PS
410static void
411smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
412{
413#ifdef CONFIG_CIFS_STATS
414 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
415 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
416 seq_printf(m, "\nNegotiates: %d sent %d failed",
417 atomic_read(&sent[SMB2_NEGOTIATE_HE]),
418 atomic_read(&failed[SMB2_NEGOTIATE_HE]));
419 seq_printf(m, "\nSessionSetups: %d sent %d failed",
420 atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
421 atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
d60622eb
PS
422 seq_printf(m, "\nLogoffs: %d sent %d failed",
423 atomic_read(&sent[SMB2_LOGOFF_HE]),
424 atomic_read(&failed[SMB2_LOGOFF_HE]));
425 seq_printf(m, "\nTreeConnects: %d sent %d failed",
426 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
427 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
428 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
429 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
430 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
431 seq_printf(m, "\nCreates: %d sent %d failed",
432 atomic_read(&sent[SMB2_CREATE_HE]),
433 atomic_read(&failed[SMB2_CREATE_HE]));
434 seq_printf(m, "\nCloses: %d sent %d failed",
435 atomic_read(&sent[SMB2_CLOSE_HE]),
436 atomic_read(&failed[SMB2_CLOSE_HE]));
437 seq_printf(m, "\nFlushes: %d sent %d failed",
438 atomic_read(&sent[SMB2_FLUSH_HE]),
439 atomic_read(&failed[SMB2_FLUSH_HE]));
440 seq_printf(m, "\nReads: %d sent %d failed",
441 atomic_read(&sent[SMB2_READ_HE]),
442 atomic_read(&failed[SMB2_READ_HE]));
443 seq_printf(m, "\nWrites: %d sent %d failed",
444 atomic_read(&sent[SMB2_WRITE_HE]),
445 atomic_read(&failed[SMB2_WRITE_HE]));
446 seq_printf(m, "\nLocks: %d sent %d failed",
447 atomic_read(&sent[SMB2_LOCK_HE]),
448 atomic_read(&failed[SMB2_LOCK_HE]));
449 seq_printf(m, "\nIOCTLs: %d sent %d failed",
450 atomic_read(&sent[SMB2_IOCTL_HE]),
451 atomic_read(&failed[SMB2_IOCTL_HE]));
452 seq_printf(m, "\nCancels: %d sent %d failed",
453 atomic_read(&sent[SMB2_CANCEL_HE]),
454 atomic_read(&failed[SMB2_CANCEL_HE]));
455 seq_printf(m, "\nEchos: %d sent %d failed",
456 atomic_read(&sent[SMB2_ECHO_HE]),
457 atomic_read(&failed[SMB2_ECHO_HE]));
458 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
459 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
460 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
461 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
462 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
463 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
464 seq_printf(m, "\nQueryInfos: %d sent %d failed",
465 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
466 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
467 seq_printf(m, "\nSetInfos: %d sent %d failed",
468 atomic_read(&sent[SMB2_SET_INFO_HE]),
469 atomic_read(&failed[SMB2_SET_INFO_HE]));
470 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
471 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
472 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
473#endif
474}
475
f0df737e
PS
476static void
477smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
478{
2e44b288 479 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
53ef1016
PS
480 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
481
f0df737e
PS
482 cfile->fid.persistent_fid = fid->persistent_fid;
483 cfile->fid.volatile_fid = fid->volatile_fid;
42873b0a
PS
484 server->ops->set_oplock_level(cinode, oplock, fid->epoch,
485 &fid->purge_cache);
18cceb6a 486 cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
f0df737e
PS
487}
488
760ad0ca 489static void
f0df737e
PS
490smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
491 struct cifs_fid *fid)
492{
760ad0ca 493 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
f0df737e
PS
494}
495
41c1358e
SF
496static int
497SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
498 u64 persistent_fid, u64 volatile_fid,
499 struct copychunk_ioctl *pcchunk)
500{
501 int rc;
502 unsigned int ret_data_len;
503 struct resume_key_req *res_key;
504
505 rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
506 FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
507 NULL, 0 /* no input */,
508 (char **)&res_key, &ret_data_len);
509
510 if (rc) {
511 cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
512 goto req_res_key_exit;
513 }
514 if (ret_data_len < sizeof(struct resume_key_req)) {
515 cifs_dbg(VFS, "Invalid refcopy resume key length\n");
516 rc = -EINVAL;
517 goto req_res_key_exit;
518 }
519 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
520
521req_res_key_exit:
522 kfree(res_key);
523 return rc;
524}
525
526static int
527smb2_clone_range(const unsigned int xid,
528 struct cifsFileInfo *srcfile,
529 struct cifsFileInfo *trgtfile, u64 src_off,
530 u64 len, u64 dest_off)
531{
532 int rc;
533 unsigned int ret_data_len;
534 struct copychunk_ioctl *pcchunk;
535 char *retbuf = NULL;
536
537 pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
538
539 if (pcchunk == NULL)
540 return -ENOMEM;
541
542 cifs_dbg(FYI, "in smb2_clone_range - about to call request res key\n");
543 /* Request a key from the server to identify the source of the copy */
544 rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
545 srcfile->fid.persistent_fid,
546 srcfile->fid.volatile_fid, pcchunk);
547
548 /* Note: request_res_key sets res_key null only if rc !=0 */
549 if (rc)
550 return rc;
551
552 /* For now array only one chunk long, will make more flexible later */
553 pcchunk->ChunkCount = __constant_cpu_to_le32(1);
554 pcchunk->Reserved = 0;
555 pcchunk->SourceOffset = cpu_to_le64(src_off);
556 pcchunk->TargetOffset = cpu_to_le64(dest_off);
557 pcchunk->Length = cpu_to_le32(len);
558 pcchunk->Reserved2 = 0;
559
560 /* Request that server copy to target from src file identified by key */
561 rc = SMB2_ioctl(xid, tlink_tcon(trgtfile->tlink),
562 trgtfile->fid.persistent_fid,
563 trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
564 true /* is_fsctl */, (char *)pcchunk,
565 sizeof(struct copychunk_ioctl), &retbuf, &ret_data_len);
566
567 /* BB need to special case rc = EINVAL to alter chunk size */
568
569 cifs_dbg(FYI, "rc %d data length out %d\n", rc, ret_data_len);
570
571 kfree(pcchunk);
572 return rc;
573}
574
7a5cfb19
PS
575static int
576smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
577 struct cifs_fid *fid)
578{
579 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
580}
581
09a4707e
PS
582static unsigned int
583smb2_read_data_offset(char *buf)
584{
585 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
586 return rsp->DataOffset;
587}
588
589static unsigned int
590smb2_read_data_length(char *buf)
591{
592 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
593 return le32_to_cpu(rsp->DataLength);
594}
595
d8e05039
PS
596
597static int
598smb2_sync_read(const unsigned int xid, struct cifsFileInfo *cfile,
599 struct cifs_io_parms *parms, unsigned int *bytes_read,
600 char **buf, int *buf_type)
601{
602 parms->persistent_fid = cfile->fid.persistent_fid;
603 parms->volatile_fid = cfile->fid.volatile_fid;
604 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
605}
606
009d3443
PS
607static int
608smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile,
609 struct cifs_io_parms *parms, unsigned int *written,
610 struct kvec *iov, unsigned long nr_segs)
611{
612
613 parms->persistent_fid = cfile->fid.persistent_fid;
614 parms->volatile_fid = cfile->fid.volatile_fid;
615 return SMB2_write(xid, parms, written, iov, nr_segs);
616}
617
c839ff24
PS
618static int
619smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
620 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
621{
622 __le64 eof = cpu_to_le64(size);
623 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
624 cfile->fid.volatile_fid, cfile->pid, &eof);
625}
626
64a5cfa6
SF
627static int
628smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
629 struct cifsFileInfo *cfile)
630{
631 return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
632 cfile->fid.volatile_fid);
633}
634
d324f08d
PS
635static int
636smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
637 const char *path, struct cifs_sb_info *cifs_sb,
638 struct cifs_fid *fid, __u16 search_flags,
639 struct cifs_search_info *srch_inf)
640{
641 __le16 *utf16_path;
642 int rc;
2e44b288 643 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
064f6047 644 struct cifs_open_parms oparms;
d324f08d
PS
645
646 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
647 if (!utf16_path)
648 return -ENOMEM;
649
064f6047
PS
650 oparms.tcon = tcon;
651 oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
652 oparms.disposition = FILE_OPEN;
653 oparms.create_options = 0;
654 oparms.fid = fid;
9cbc0b73 655 oparms.reconnect = false;
064f6047 656
b42bf888 657 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
d324f08d
PS
658 kfree(utf16_path);
659 if (rc) {
f96637be 660 cifs_dbg(VFS, "open dir failed\n");
d324f08d
PS
661 return rc;
662 }
663
664 srch_inf->entries_in_buffer = 0;
665 srch_inf->index_of_last_entry = 0;
d324f08d 666
064f6047
PS
667 rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
668 fid->volatile_fid, 0, srch_inf);
d324f08d 669 if (rc) {
f96637be 670 cifs_dbg(VFS, "query directory failed\n");
064f6047 671 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
d324f08d
PS
672 }
673 return rc;
674}
675
676static int
677smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
678 struct cifs_fid *fid, __u16 search_flags,
679 struct cifs_search_info *srch_inf)
680{
681 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
682 fid->volatile_fid, 0, srch_inf);
683}
684
685static int
686smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
687 struct cifs_fid *fid)
688{
689 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
690}
691
2e44b288
PS
692/*
693* If we negotiate SMB2 protocol and get STATUS_PENDING - update
694* the number of credits and return true. Otherwise - return false.
695*/
696static bool
697smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
698{
699 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
700
12e8a208 701 if (hdr->Status != STATUS_PENDING)
2e44b288
PS
702 return false;
703
704 if (!length) {
705 spin_lock(&server->req_lock);
706 server->credits += le16_to_cpu(hdr->CreditRequest);
707 spin_unlock(&server->req_lock);
708 wake_up(&server->request_q);
709 }
710
711 return true;
712}
713
983c88a4
PS
714static int
715smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
716 struct cifsInodeInfo *cinode)
717{
0822f514
PS
718 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
719 return SMB2_lease_break(0, tcon, cinode->lease_key,
720 smb2_get_lease_state(cinode));
721
983c88a4
PS
722 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
723 fid->volatile_fid,
18cceb6a 724 CIFS_CACHE_READ(cinode) ? 1 : 0);
983c88a4
PS
725}
726
6fc05c25
PS
727static int
728smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
729 struct kstatfs *buf)
730{
731 int rc;
6fc05c25
PS
732 __le16 srch_path = 0; /* Null - open root of share */
733 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
064f6047
PS
734 struct cifs_open_parms oparms;
735 struct cifs_fid fid;
736
737 oparms.tcon = tcon;
738 oparms.desired_access = FILE_READ_ATTRIBUTES;
739 oparms.disposition = FILE_OPEN;
740 oparms.create_options = 0;
741 oparms.fid = &fid;
9cbc0b73 742 oparms.reconnect = false;
6fc05c25 743
b42bf888 744 rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
6fc05c25
PS
745 if (rc)
746 return rc;
747 buf->f_type = SMB2_MAGIC_NUMBER;
064f6047
PS
748 rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
749 buf);
750 SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
6fc05c25
PS
751 return rc;
752}
753
027e8eec
PS
754static bool
755smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
756{
757 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
758 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
759}
760
f7ba7fe6
PS
761static int
762smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
763 __u64 length, __u32 type, int lock, int unlock, bool wait)
764{
765 if (unlock && !lock)
766 type = SMB2_LOCKFLAG_UNLOCK;
767 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
768 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
769 current->tgid, length, offset, type, wait);
770}
771
b8c32dbb
PS
772static void
773smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
774{
775 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
776}
777
778static void
779smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
780{
781 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
782}
783
784static void
785smb2_new_lease_key(struct cifs_fid *fid)
786{
787 get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
788}
789
b42bf888
PS
790static int
791smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
792 const char *full_path, char **target_path,
793 struct cifs_sb_info *cifs_sb)
794{
795 int rc;
796 __le16 *utf16_path;
797 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
798 struct cifs_open_parms oparms;
799 struct cifs_fid fid;
800 struct smb2_err_rsp *err_buf = NULL;
801 struct smb2_symlink_err_rsp *symlink;
802 unsigned int sub_len, sub_offset;
803
804 cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
805
806 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
807 if (!utf16_path)
808 return -ENOMEM;
809
810 oparms.tcon = tcon;
811 oparms.desired_access = FILE_READ_ATTRIBUTES;
812 oparms.disposition = FILE_OPEN;
813 oparms.create_options = 0;
814 oparms.fid = &fid;
815 oparms.reconnect = false;
816
817 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
818
819 if (!rc || !err_buf) {
820 kfree(utf16_path);
821 return -ENOENT;
822 }
823 /* open must fail on symlink - reset rc */
824 rc = 0;
825 symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
826 sub_len = le16_to_cpu(symlink->SubstituteNameLength);
827 sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
828 *target_path = cifs_strndup_from_utf16(
829 (char *)symlink->PathBuffer + sub_offset,
830 sub_len, true, cifs_sb->local_nls);
831 if (!(*target_path)) {
832 kfree(utf16_path);
833 return -ENOMEM;
834 }
835 convert_delimiter(*target_path, '/');
836 cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
837 kfree(utf16_path);
838 return rc;
839}
840
53ef1016 841static void
42873b0a
PS
842smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
843 unsigned int epoch, bool *purge_cache)
53ef1016
PS
844{
845 oplock &= 0xFF;
846 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
847 return;
848 if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
42873b0a 849 cinode->oplock = CIFS_CACHE_RHW_FLG;
53ef1016
PS
850 cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
851 &cinode->vfs_inode);
852 } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
42873b0a 853 cinode->oplock = CIFS_CACHE_RW_FLG;
53ef1016
PS
854 cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
855 &cinode->vfs_inode);
856 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
857 cinode->oplock = CIFS_CACHE_READ_FLG;
858 cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
859 &cinode->vfs_inode);
860 } else
861 cinode->oplock = 0;
862}
863
864static void
42873b0a
PS
865smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
866 unsigned int epoch, bool *purge_cache)
53ef1016
PS
867{
868 char message[5] = {0};
869
870 oplock &= 0xFF;
871 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
872 return;
873
874 cinode->oplock = 0;
875 if (oplock & SMB2_LEASE_READ_CACHING_HE) {
876 cinode->oplock |= CIFS_CACHE_READ_FLG;
877 strcat(message, "R");
878 }
879 if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
880 cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
881 strcat(message, "H");
882 }
883 if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
884 cinode->oplock |= CIFS_CACHE_WRITE_FLG;
885 strcat(message, "W");
886 }
887 if (!cinode->oplock)
888 strcat(message, "None");
889 cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
890 &cinode->vfs_inode);
891}
892
42873b0a
PS
893static void
894smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
895 unsigned int epoch, bool *purge_cache)
896{
897 unsigned int old_oplock = cinode->oplock;
898
899 smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
900
901 if (purge_cache) {
902 *purge_cache = false;
903 if (old_oplock == CIFS_CACHE_READ_FLG) {
904 if (cinode->oplock == CIFS_CACHE_READ_FLG &&
905 (epoch - cinode->epoch > 0))
906 *purge_cache = true;
907 else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
908 (epoch - cinode->epoch > 1))
909 *purge_cache = true;
910 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
911 (epoch - cinode->epoch > 1))
912 *purge_cache = true;
913 else if (cinode->oplock == 0 &&
914 (epoch - cinode->epoch > 0))
915 *purge_cache = true;
916 } else if (old_oplock == CIFS_CACHE_RH_FLG) {
917 if (cinode->oplock == CIFS_CACHE_RH_FLG &&
918 (epoch - cinode->epoch > 0))
919 *purge_cache = true;
920 else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
921 (epoch - cinode->epoch > 1))
922 *purge_cache = true;
923 }
924 cinode->epoch = epoch;
925 }
926}
927
53ef1016
PS
928static bool
929smb2_is_read_op(__u32 oplock)
930{
931 return oplock == SMB2_OPLOCK_LEVEL_II;
932}
933
934static bool
935smb21_is_read_op(__u32 oplock)
936{
937 return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
938 !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
939}
940
f047390a
PS
941static __le32
942map_oplock_to_lease(u8 oplock)
943{
944 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
945 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
946 else if (oplock == SMB2_OPLOCK_LEVEL_II)
947 return SMB2_LEASE_READ_CACHING;
948 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
949 return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
950 SMB2_LEASE_WRITE_CACHING;
951 return 0;
952}
953
a41a28bd
PS
954static char *
955smb2_create_lease_buf(u8 *lease_key, u8 oplock)
956{
957 struct create_lease *buf;
958
959 buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
960 if (!buf)
961 return NULL;
962
963 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
964 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
f047390a 965 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
a41a28bd
PS
966
967 buf->ccontext.DataOffset = cpu_to_le16(offsetof
968 (struct create_lease, lcontext));
969 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
970 buf->ccontext.NameOffset = cpu_to_le16(offsetof
971 (struct create_lease, Name));
972 buf->ccontext.NameLength = cpu_to_le16(4);
973 buf->Name[0] = 'R';
974 buf->Name[1] = 'q';
975 buf->Name[2] = 'L';
976 buf->Name[3] = 's';
977 return (char *)buf;
978}
979
f047390a
PS
980static char *
981smb3_create_lease_buf(u8 *lease_key, u8 oplock)
982{
983 struct create_lease_v2 *buf;
984
985 buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
986 if (!buf)
987 return NULL;
988
989 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
990 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
991 buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
992
993 buf->ccontext.DataOffset = cpu_to_le16(offsetof
994 (struct create_lease_v2, lcontext));
995 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
996 buf->ccontext.NameOffset = cpu_to_le16(offsetof
997 (struct create_lease_v2, Name));
998 buf->ccontext.NameLength = cpu_to_le16(4);
999 buf->Name[0] = 'R';
1000 buf->Name[1] = 'q';
1001 buf->Name[2] = 'L';
1002 buf->Name[3] = 's';
1003 return (char *)buf;
1004}
1005
b5c7cde3 1006static __u8
42873b0a 1007smb2_parse_lease_buf(void *buf, unsigned int *epoch)
b5c7cde3
PS
1008{
1009 struct create_lease *lc = (struct create_lease *)buf;
1010
42873b0a 1011 *epoch = 0; /* not used */
b5c7cde3
PS
1012 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
1013 return SMB2_OPLOCK_LEVEL_NOCHANGE;
1014 return le32_to_cpu(lc->lcontext.LeaseState);
1015}
1016
f047390a 1017static __u8
42873b0a 1018smb3_parse_lease_buf(void *buf, unsigned int *epoch)
f047390a
PS
1019{
1020 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
1021
42873b0a 1022 *epoch = le16_to_cpu(lc->lcontext.Epoch);
f047390a
PS
1023 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
1024 return SMB2_OPLOCK_LEVEL_NOCHANGE;
1025 return le32_to_cpu(lc->lcontext.LeaseState);
1026}
1027
53ef1016 1028struct smb_version_operations smb20_operations = {
027e8eec 1029 .compare_fids = smb2_compare_fids,
2dc7e1c0 1030 .setup_request = smb2_setup_request,
c95b8eed 1031 .setup_async_request = smb2_setup_async_request,
2dc7e1c0 1032 .check_receive = smb2_check_receive,
28ea5290
PS
1033 .add_credits = smb2_add_credits,
1034 .set_credits = smb2_set_credits,
1035 .get_credits_field = smb2_get_credits_field,
1036 .get_credits = smb2_get_credits,
2dc7e1c0 1037 .get_next_mid = smb2_get_next_mid,
09a4707e
PS
1038 .read_data_offset = smb2_read_data_offset,
1039 .read_data_length = smb2_read_data_length,
1040 .map_error = map_smb2_to_linux_error,
093b2bda
PS
1041 .find_mid = smb2_find_mid,
1042 .check_message = smb2_check_message,
1043 .dump_detail = smb2_dump_detail,
d60622eb
PS
1044 .clear_stats = smb2_clear_stats,
1045 .print_stats = smb2_print_stats,
983c88a4 1046 .is_oplock_break = smb2_is_valid_oplock_break,
ec2e4523
PS
1047 .need_neg = smb2_need_neg,
1048 .negotiate = smb2_negotiate,
3a3bab50
PS
1049 .negotiate_wsize = smb2_negotiate_wsize,
1050 .negotiate_rsize = smb2_negotiate_rsize,
5478f9ba
PS
1051 .sess_setup = SMB2_sess_setup,
1052 .logoff = SMB2_logoff,
faaf946a
PS
1053 .tree_connect = SMB2_tcon,
1054 .tree_disconnect = SMB2_tdis,
34f62640 1055 .qfs_tcon = smb2_qfs_tcon,
2503a0db 1056 .is_path_accessible = smb2_is_path_accessible,
9094fad1
PS
1057 .can_echo = smb2_can_echo,
1058 .echo = SMB2_echo,
be4cb9e3
PS
1059 .query_path_info = smb2_query_path_info,
1060 .get_srv_inum = smb2_get_srv_inum,
b7546bc5 1061 .query_file_info = smb2_query_file_info,
c839ff24
PS
1062 .set_path_size = smb2_set_path_size,
1063 .set_file_size = smb2_set_file_size,
1feeaac7 1064 .set_file_info = smb2_set_file_info,
64a5cfa6 1065 .set_compression = smb2_set_compression,
a0e73183
PS
1066 .mkdir = smb2_mkdir,
1067 .mkdir_setinfo = smb2_mkdir_setinfo,
1a500f01 1068 .rmdir = smb2_rmdir,
cbe6f439 1069 .unlink = smb2_unlink,
35143eb5 1070 .rename = smb2_rename_path,
568798cc 1071 .create_hardlink = smb2_create_hardlink,
b42bf888 1072 .query_symlink = smb2_query_symlink,
f0df737e
PS
1073 .open = smb2_open_file,
1074 .set_fid = smb2_set_fid,
1075 .close = smb2_close_file,
7a5cfb19 1076 .flush = smb2_flush_file,
09a4707e 1077 .async_readv = smb2_async_readv,
33319141 1078 .async_writev = smb2_async_writev,
d8e05039 1079 .sync_read = smb2_sync_read,
009d3443 1080 .sync_write = smb2_sync_write,
d324f08d
PS
1081 .query_dir_first = smb2_query_dir_first,
1082 .query_dir_next = smb2_query_dir_next,
1083 .close_dir = smb2_close_dir,
1084 .calc_smb_size = smb2_calc_size,
2e44b288 1085 .is_status_pending = smb2_is_status_pending,
983c88a4 1086 .oplock_response = smb2_oplock_response,
6fc05c25 1087 .queryfs = smb2_queryfs,
f7ba7fe6
PS
1088 .mand_lock = smb2_mand_lock,
1089 .mand_unlock_range = smb2_unlock_range,
b140799a 1090 .push_mand_locks = smb2_push_mandatory_locks,
b8c32dbb
PS
1091 .get_lease_key = smb2_get_lease_key,
1092 .set_lease_key = smb2_set_lease_key,
1093 .new_lease_key = smb2_new_lease_key,
38107d45 1094 .calc_signature = smb2_calc_signature,
53ef1016
PS
1095 .is_read_op = smb2_is_read_op,
1096 .set_oplock_level = smb2_set_oplock_level,
a41a28bd 1097 .create_lease_buf = smb2_create_lease_buf,
b5c7cde3 1098 .parse_lease_buf = smb2_parse_lease_buf,
41c1358e 1099 .clone_range = smb2_clone_range,
38107d45
SF
1100};
1101
53ef1016
PS
1102struct smb_version_operations smb21_operations = {
1103 .compare_fids = smb2_compare_fids,
1104 .setup_request = smb2_setup_request,
1105 .setup_async_request = smb2_setup_async_request,
1106 .check_receive = smb2_check_receive,
1107 .add_credits = smb2_add_credits,
1108 .set_credits = smb2_set_credits,
1109 .get_credits_field = smb2_get_credits_field,
1110 .get_credits = smb2_get_credits,
1111 .get_next_mid = smb2_get_next_mid,
1112 .read_data_offset = smb2_read_data_offset,
1113 .read_data_length = smb2_read_data_length,
1114 .map_error = map_smb2_to_linux_error,
1115 .find_mid = smb2_find_mid,
1116 .check_message = smb2_check_message,
1117 .dump_detail = smb2_dump_detail,
1118 .clear_stats = smb2_clear_stats,
1119 .print_stats = smb2_print_stats,
1120 .is_oplock_break = smb2_is_valid_oplock_break,
1121 .need_neg = smb2_need_neg,
1122 .negotiate = smb2_negotiate,
1123 .negotiate_wsize = smb2_negotiate_wsize,
1124 .negotiate_rsize = smb2_negotiate_rsize,
1125 .sess_setup = SMB2_sess_setup,
1126 .logoff = SMB2_logoff,
1127 .tree_connect = SMB2_tcon,
1128 .tree_disconnect = SMB2_tdis,
34f62640 1129 .qfs_tcon = smb2_qfs_tcon,
53ef1016
PS
1130 .is_path_accessible = smb2_is_path_accessible,
1131 .can_echo = smb2_can_echo,
1132 .echo = SMB2_echo,
1133 .query_path_info = smb2_query_path_info,
1134 .get_srv_inum = smb2_get_srv_inum,
1135 .query_file_info = smb2_query_file_info,
1136 .set_path_size = smb2_set_path_size,
1137 .set_file_size = smb2_set_file_size,
1138 .set_file_info = smb2_set_file_info,
64a5cfa6 1139 .set_compression = smb2_set_compression,
53ef1016
PS
1140 .mkdir = smb2_mkdir,
1141 .mkdir_setinfo = smb2_mkdir_setinfo,
1142 .rmdir = smb2_rmdir,
1143 .unlink = smb2_unlink,
1144 .rename = smb2_rename_path,
1145 .create_hardlink = smb2_create_hardlink,
1146 .query_symlink = smb2_query_symlink,
1147 .open = smb2_open_file,
1148 .set_fid = smb2_set_fid,
1149 .close = smb2_close_file,
1150 .flush = smb2_flush_file,
1151 .async_readv = smb2_async_readv,
1152 .async_writev = smb2_async_writev,
1153 .sync_read = smb2_sync_read,
1154 .sync_write = smb2_sync_write,
1155 .query_dir_first = smb2_query_dir_first,
1156 .query_dir_next = smb2_query_dir_next,
1157 .close_dir = smb2_close_dir,
1158 .calc_smb_size = smb2_calc_size,
1159 .is_status_pending = smb2_is_status_pending,
1160 .oplock_response = smb2_oplock_response,
1161 .queryfs = smb2_queryfs,
1162 .mand_lock = smb2_mand_lock,
1163 .mand_unlock_range = smb2_unlock_range,
1164 .push_mand_locks = smb2_push_mandatory_locks,
1165 .get_lease_key = smb2_get_lease_key,
1166 .set_lease_key = smb2_set_lease_key,
1167 .new_lease_key = smb2_new_lease_key,
1168 .calc_signature = smb2_calc_signature,
1169 .is_read_op = smb21_is_read_op,
1170 .set_oplock_level = smb21_set_oplock_level,
a41a28bd 1171 .create_lease_buf = smb2_create_lease_buf,
b5c7cde3 1172 .parse_lease_buf = smb2_parse_lease_buf,
41c1358e 1173 .clone_range = smb2_clone_range,
53ef1016 1174};
38107d45
SF
1175
1176struct smb_version_operations smb30_operations = {
1177 .compare_fids = smb2_compare_fids,
1178 .setup_request = smb2_setup_request,
1179 .setup_async_request = smb2_setup_async_request,
1180 .check_receive = smb2_check_receive,
1181 .add_credits = smb2_add_credits,
1182 .set_credits = smb2_set_credits,
1183 .get_credits_field = smb2_get_credits_field,
1184 .get_credits = smb2_get_credits,
1185 .get_next_mid = smb2_get_next_mid,
1186 .read_data_offset = smb2_read_data_offset,
1187 .read_data_length = smb2_read_data_length,
1188 .map_error = map_smb2_to_linux_error,
1189 .find_mid = smb2_find_mid,
1190 .check_message = smb2_check_message,
1191 .dump_detail = smb2_dump_detail,
1192 .clear_stats = smb2_clear_stats,
1193 .print_stats = smb2_print_stats,
769ee6a4 1194 .dump_share_caps = smb2_dump_share_caps,
38107d45
SF
1195 .is_oplock_break = smb2_is_valid_oplock_break,
1196 .need_neg = smb2_need_neg,
1197 .negotiate = smb2_negotiate,
1198 .negotiate_wsize = smb2_negotiate_wsize,
1199 .negotiate_rsize = smb2_negotiate_rsize,
1200 .sess_setup = SMB2_sess_setup,
1201 .logoff = SMB2_logoff,
1202 .tree_connect = SMB2_tcon,
1203 .tree_disconnect = SMB2_tdis,
af6a12ea 1204 .qfs_tcon = smb3_qfs_tcon,
38107d45
SF
1205 .is_path_accessible = smb2_is_path_accessible,
1206 .can_echo = smb2_can_echo,
1207 .echo = SMB2_echo,
1208 .query_path_info = smb2_query_path_info,
1209 .get_srv_inum = smb2_get_srv_inum,
1210 .query_file_info = smb2_query_file_info,
1211 .set_path_size = smb2_set_path_size,
1212 .set_file_size = smb2_set_file_size,
1213 .set_file_info = smb2_set_file_info,
64a5cfa6 1214 .set_compression = smb2_set_compression,
38107d45
SF
1215 .mkdir = smb2_mkdir,
1216 .mkdir_setinfo = smb2_mkdir_setinfo,
1217 .rmdir = smb2_rmdir,
1218 .unlink = smb2_unlink,
1219 .rename = smb2_rename_path,
1220 .create_hardlink = smb2_create_hardlink,
b42bf888 1221 .query_symlink = smb2_query_symlink,
38107d45
SF
1222 .open = smb2_open_file,
1223 .set_fid = smb2_set_fid,
1224 .close = smb2_close_file,
1225 .flush = smb2_flush_file,
1226 .async_readv = smb2_async_readv,
1227 .async_writev = smb2_async_writev,
1228 .sync_read = smb2_sync_read,
1229 .sync_write = smb2_sync_write,
1230 .query_dir_first = smb2_query_dir_first,
1231 .query_dir_next = smb2_query_dir_next,
1232 .close_dir = smb2_close_dir,
1233 .calc_smb_size = smb2_calc_size,
1234 .is_status_pending = smb2_is_status_pending,
1235 .oplock_response = smb2_oplock_response,
1236 .queryfs = smb2_queryfs,
1237 .mand_lock = smb2_mand_lock,
1238 .mand_unlock_range = smb2_unlock_range,
1239 .push_mand_locks = smb2_push_mandatory_locks,
1240 .get_lease_key = smb2_get_lease_key,
1241 .set_lease_key = smb2_set_lease_key,
1242 .new_lease_key = smb2_new_lease_key,
e65a5cb4 1243 .generate_signingkey = generate_smb3signingkey,
38107d45 1244 .calc_signature = smb3_calc_signature,
53ef1016 1245 .is_read_op = smb21_is_read_op,
42873b0a 1246 .set_oplock_level = smb3_set_oplock_level,
f047390a
PS
1247 .create_lease_buf = smb3_create_lease_buf,
1248 .parse_lease_buf = smb3_parse_lease_buf,
41c1358e 1249 .clone_range = smb2_clone_range,
1080ef75
SF
1250};
1251
dd446b16
SF
1252struct smb_version_values smb20_values = {
1253 .version_string = SMB20_VERSION_STRING,
1254 .protocol_id = SMB20_PROT_ID,
1255 .req_capabilities = 0, /* MBZ */
1256 .large_lock_type = 0,
1257 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1258 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1259 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1260 .header_size = sizeof(struct smb2_hdr),
1261 .max_header_size = MAX_SMB2_HDR_SIZE,
1262 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1263 .lock_cmd = SMB2_LOCK,
1264 .cap_unix = 0,
1265 .cap_nt_find = SMB2_NT_FIND,
1266 .cap_large_files = SMB2_LARGE_FILES,
50285882
JL
1267 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1268 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
a41a28bd 1269 .create_lease_size = sizeof(struct create_lease),
dd446b16
SF
1270};
1271
1080ef75
SF
1272struct smb_version_values smb21_values = {
1273 .version_string = SMB21_VERSION_STRING,
e4aa25e7
SF
1274 .protocol_id = SMB21_PROT_ID,
1275 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
1276 .large_lock_type = 0,
1277 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1278 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1279 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1280 .header_size = sizeof(struct smb2_hdr),
1281 .max_header_size = MAX_SMB2_HDR_SIZE,
1282 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1283 .lock_cmd = SMB2_LOCK,
1284 .cap_unix = 0,
1285 .cap_nt_find = SMB2_NT_FIND,
1286 .cap_large_files = SMB2_LARGE_FILES,
50285882
JL
1287 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1288 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
a41a28bd 1289 .create_lease_size = sizeof(struct create_lease),
e4aa25e7
SF
1290};
1291
1292struct smb_version_values smb30_values = {
1293 .version_string = SMB30_VERSION_STRING,
1294 .protocol_id = SMB30_PROT_ID,
1295 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
027e8eec
PS
1296 .large_lock_type = 0,
1297 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1298 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1299 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
093b2bda
PS
1300 .header_size = sizeof(struct smb2_hdr),
1301 .max_header_size = MAX_SMB2_HDR_SIZE,
09a4707e 1302 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
2dc7e1c0 1303 .lock_cmd = SMB2_LOCK,
29e20f9c
PS
1304 .cap_unix = 0,
1305 .cap_nt_find = SMB2_NT_FIND,
1306 .cap_large_files = SMB2_LARGE_FILES,
50285882
JL
1307 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1308 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
f047390a 1309 .create_lease_size = sizeof(struct create_lease_v2),
1080ef75 1310};
20b6d8b4
SF
1311
1312struct smb_version_values smb302_values = {
1313 .version_string = SMB302_VERSION_STRING,
1314 .protocol_id = SMB302_PROT_ID,
1315 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
1316 .large_lock_type = 0,
1317 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
1318 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
1319 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
1320 .header_size = sizeof(struct smb2_hdr),
1321 .max_header_size = MAX_SMB2_HDR_SIZE,
1322 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
1323 .lock_cmd = SMB2_LOCK,
1324 .cap_unix = 0,
1325 .cap_nt_find = SMB2_NT_FIND,
1326 .cap_large_files = SMB2_LARGE_FILES,
50285882
JL
1327 .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
1328 .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
f047390a 1329 .create_lease_size = sizeof(struct create_lease_v2),
20b6d8b4 1330};
This page took 0.195301 seconds and 5 git commands to generate.